aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_docgen/priv/js/highlight.js
diff options
context:
space:
mode:
authorMariano Guerra <[email protected]>2016-10-21 21:22:52 +0100
committerMariano Guerra <[email protected]>2017-03-13 11:51:52 +0100
commit2887ebb0cd748f60cfe410f414ad27acfc7a3cb5 (patch)
tree4b1caa1e7aebada7aead827599b3ef80dab148cd /lib/erl_docgen/priv/js/highlight.js
parent1f0689526a75e776bb4486da55cd48cb2e2efb15 (diff)
downloadotp-2887ebb0cd748f60cfe410f414ad27acfc7a3cb5.tar.gz
otp-2887ebb0cd748f60cfe410f414ad27acfc7a3cb5.tar.bz2
otp-2887ebb0cd748f60cfe410f414ad27acfc7a3cb5.zip
add progressive enhanced syntax highlighter
it loads a script at the end of the page that loads the required resources and initializes the syntax highlighter. if js is disabled or blocked nothing happens, the code blocks will display with the style they had until now
Diffstat (limited to 'lib/erl_docgen/priv/js/highlight.js')
-rw-r--r--lib/erl_docgen/priv/js/highlight.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/erl_docgen/priv/js/highlight.js b/lib/erl_docgen/priv/js/highlight.js
new file mode 100644
index 0000000000..0594b42aa3
--- /dev/null
+++ b/lib/erl_docgen/priv/js/highlight.js
@@ -0,0 +1,39 @@
+/*globals document, window*/
+window.addEventListener("load", function () {
+ "use strict";
+ var body = document.body,
+ base = window.__otpTopDocDir || "/doc/js/",
+ cssLink = document.createElement('link'),
+ script = document.createElement('script'),
+ intervalId, attempts = 0;
+
+ cssLink.rel = "stylesheet";
+ cssLink.href = base + "../highlight.css";
+ script.src = base + "highlight.pack.js";
+
+ body.appendChild(cssLink);
+ body.appendChild(script);
+
+ function doHighlight() {
+ attempts += 1;
+
+ if (attempts > 20) {
+ window.clearInterval(intervalId);
+ return;
+ }
+
+ if (!window.hljs) {
+ return;
+ }
+
+ window.clearInterval(intervalId);
+
+ var i, len, nodes = document.querySelectorAll('.example');
+ for (i = 0, len = nodes.length; i < len; i += 1) {
+ window.hljs.highlightBlock(nodes[i]);
+ }
+
+ }
+
+ intervalId = window.setInterval(doHighlight, 50);
+});