This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* Automatically convert multiline `code` to a full `pre` block. */ | ||
$(function () { | ||
/* globals hljs */ | ||
'use strict'; | ||
var processedFlag = 'js-hljs'; | ||
|
||
function renderCode () { | ||
$('code:not(.hljs,.'+ processedFlag +')').each(function (i, el) { | ||
var $el = $(el); | ||
var html = $el.html(); | ||
var render = false; | ||
|
||
if ($el.parent().is('pre')) { | ||
render = true; | ||
} else if (html.indexOf('\n') !== -1) { | ||
$('<pre>') | ||
.insertBefore($el) | ||
.append($el); | ||
$el.html(html.trim()); | ||
render = true; | ||
} | ||
|
||
if (render) { | ||
hljs.highlightBlock(el); | ||
} | ||
|
||
$el.addClass(processedFlag); | ||
}); | ||
} | ||
|
||
renderCode(); | ||
setTimeout(renderCode, 5000); | ||
|
||
// if current tab is active, re-scan for un-processed code tags. | ||
// In-case of isso loading comments slowly. | ||
var renderHandle; | ||
var prevType; | ||
$(window).on("blur focus", function(e) { | ||
if (prevType !== e.type) { | ||
switch (e.type) { | ||
case "blur": | ||
clearInterval(renderHandle); | ||
break; | ||
case "focus": | ||
setInterval(renderCode, 15000); | ||
break; | ||
} | ||
} | ||
|
||
prevType = e.type; | ||
}); | ||
}); |