Skip to content

Commit

Permalink
task #3: No highlight in view-source mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Chmaj committed Sep 16, 2015
1 parent fece080 commit d8e8191
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions assets/javascripts/loader.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
function updateCodes() {
function updateCodes(file_class) {

$('table.syntaxhl th.line-num').remove();
$('table.syntaxhl').each(
function(i, block) {
var parentBlock = $(this).parent()
var code = '';
var line = 0;
$(this).find('td pre').each(
function(i, block) {
line++;
$(this).find('td pre').each(function(i, block) {
line++;

var html = $(this).html()
if (!html.trim()) html = "\n"
code += html
// code += '<span class="lineNumber">' + line
// + '</span>' + $(this).html()
})
var html = $(this).html()
if (!html.trim())
html = "\n"
code += html
})
$(this).remove()
parentBlock.append('<pre class="block rounded"><code>' + code
+ '</code></pre>')
if (file_class) {
var header = '<pre class="block rounded"><code class="'
+ file_class + '">'
} else {
var header = '<pre class="block rounded"><code>';
}
parentBlock.append(header + code + '</code></pre>')
});
$('pre code:not(.hljs)').each(function(i, block) {
if (!$(this).hasClass('nohighlight')) {
$(this).html($.trim($(this).html()));
hljs.highlightBlock($(this)[0]);
// numberLines($(this).parent()[0])
$(this).parent().show();
}
});
Expand All @@ -38,9 +41,15 @@ function updateCodes() {
}

$(document).ready(function() {
updateCodes();

var file_class = ''
if ($('body').hasClass('controller-attachments')) {
file_class = document.location.toString().split('.').pop()
}

updateCodes(file_class);
setInterval(function() {
updateCodes();
updateCodes(file_class);
}, 5000);
$(document).ajaxComplete(function() {
updateCodes();
Expand Down

0 comments on commit d8e8191

Please sign in to comment.