diff options
author | jeffreytse <jeffreytse.mail@gmail.com> | 2020-10-03 12:23:29 +0800 |
---|---|---|
committer | jeffreytse <jeffreytse.mail@gmail.com> | 2020-10-03 12:23:29 +0800 |
commit | 023ba51a08acba9a46e201a8f6ebd29bc1b51c53 (patch) | |
tree | 51f3dda04c6113d04e8cf688caee6b062df7084e | |
parent | ba1db7db3e7bf97de56909b1f13592172d550552 (diff) |
perfect: improve browser compatibility
-rw-r--r-- | _includes/extensions/hashlocate.html | 2 | ||||
-rw-r--r-- | _includes/sidebar/article-menu.html | 6 | ||||
-rw-r--r-- | assets/js/main.js | 12 |
3 files changed, 15 insertions, 5 deletions
diff --git a/_includes/extensions/hashlocate.html b/_includes/extensions/hashlocate.html index 5194273..fd4a3d6 100644 --- a/_includes/extensions/hashlocate.html +++ b/_includes/extensions/hashlocate.html @@ -36,7 +36,7 @@ // The first event occurred window.addEventListener('click', function(event) { - if (event.target.matches('a')) { + if (event.target.tagName.toLowerCase() == 'a') { hashLocate(event.target.getAttribute('href')); } }); diff --git a/_includes/sidebar/article-menu.html b/_includes/sidebar/article-menu.html index 2e273de..3e618ff 100644 --- a/_includes/sidebar/article-menu.html +++ b/_includes/sidebar/article-menu.html @@ -36,9 +36,13 @@ // The header element var header = document.querySelector('header.site-header'); - function doMenuCollapse(index, over_items=20) { + function doMenuCollapse(index, over_items) { var items = menuContent.firstChild.children; + if (over_items == undefined) { + over_items = 20; + } + if (items.length < over_items) { return; } diff --git a/assets/js/main.js b/assets/js/main.js index 01c0ca5..ff3f2a3 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -58,10 +58,12 @@ function smoothScrollTo(y, time) { // Init highlight js document.addEventListener('DOMContentLoaded', function(event) { - document.querySelectorAll('pre code').forEach((block) => { + var els = document.querySelectorAll('pre code') + function handle(block) { var outer = block.parentElement.parentElement.parentElement; var lang = block.getAttribute('data-lang'); - for (var cls of outer.classList) { + for (var i = 0; i < outer.classList.length; i++) { + var cls = outer.classList[i]; if (cls.startsWith('language-')) { lang = cls; break; @@ -77,5 +79,9 @@ document.addEventListener('DOMContentLoaded', function(event) { block.setAttribute('class', 'hljs ' + lang); block.parentNode.setAttribute('data-lang', lang); hljs.highlightBlock(block); - }); + } + for (var i = 0; i < els.length; i++) { + var el = els[i]; + handle(el); + } }); |