From 11e839decc5ee16f21b7527976c3029ee0cd5692 Mon Sep 17 00:00:00 2001 From: olOwOlo <26087907+olOwOlo@users.noreply.github.com> Date: Sun, 17 Sep 2017 21:52:46 +0800 Subject: fix: compatibility in IE(9+) and Edge (#8) - add classList shim for IE9 - refactor: for...of --- src/js/even.js | 19 ++++++++++--------- src/js/main.js | 6 +++--- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/js/even.js b/src/js/even.js index 4ebe165..8aa8459 100644 --- a/src/js/even.js +++ b/src/js/even.js @@ -127,8 +127,8 @@ Even.fancybox = function () { Even.highlight = function () { const blocks = document.querySelectorAll('pre code') - for (const block of blocks) { - const classList = block.classList + for (let i = 0; i < blocks.length; i++) { + const block = blocks[i] const rootElement = block.parentElement const lineCodes = block.innerHTML.split(/\n/).slice(0, -1) const lineLength = lineCodes.length @@ -139,13 +139,13 @@ Even.highlight = function () { } let codeHtml = '' - for (const lineCode of lineCodes) { - codeHtml += `
${lineCode}
` + for (let i = 0; i < lineLength; i++) { + codeHtml += `
${lineCodes[i]}
` } - classList.add('highlight') + block.className += ' highlight' const figure = document.createElement('figure') - figure.classList = classList + figure.className = block.className figure.innerHTML = `
${codeLineHtml}
${codeHtml}
` rootElement.parentElement.replaceChild(figure, rootElement) @@ -154,11 +154,12 @@ Even.highlight = function () { Even.beforeToc = function () { const links = document.querySelectorAll('#TableOfContents a') - for (const link of links) link.classList.add('toc-link') + for (let i = 0; i < links.length; i++) links[i].className += ' toc-link' - for (const num of [1, 2, 3, 4, 5, 6]) { + for (let num = 1; num <= 6; num++) { const headers = document.querySelectorAll('.post-content>h' + num) - for (const header of headers) { + for (let i = 0; i < headers.length; i++) { + const header = headers[i] header.innerHTML = `${header.innerHTML}` } } diff --git a/src/js/main.js b/src/js/main.js index f3531b7..6539cf2 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -2,9 +2,6 @@ import {Even} from './even.js' import '../css/style.scss' -hljs.initHighlighting() -Even.highlight() - $(document).ready(function () { Even.backToTop() Even.mobileNavbar() @@ -12,3 +9,6 @@ $(document).ready(function () { Even.toc() Even.fancybox() }) + +hljs.initHighlighting() +Even.highlight() -- cgit v1.2.3