Skip to content

Commit

Permalink
perfect: improve browser compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreytse committed Oct 3, 2020
1 parent ba1db7d commit 023ba51
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion _includes/extensions/hashlocate.html
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
});
Expand Down
6 changes: 5 additions & 1 deletion _includes/sidebar/article-menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 9 additions & 3 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
});

0 comments on commit 023ba51

Please sign in to comment.