mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-08-16 13:44:31 +02:00
updated the hash resolver for disqus links
This commit is contained in:
40
lib/hash-resolver.js
Normal file
40
lib/hash-resolver.js
Normal file
@@ -0,0 +1,40 @@
|
||||
function scrollToHash() {
|
||||
window.location = window.location.hash;
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
if (typeof window === "undefined") return;
|
||||
|
||||
if (window.location) {
|
||||
var h = window.location.hash;
|
||||
if (h) {
|
||||
// is this a comment hash, or a section hash?
|
||||
if (h.match(/comment-\d+/)) {
|
||||
var MutationObserver =
|
||||
window.MutationObserver || window.WebKitMutationObserver;
|
||||
|
||||
div = document.getElementById("disqus_thread");
|
||||
|
||||
var mObject = new MutationObserver(function(changes, observer) {
|
||||
var limit = 10;
|
||||
(function waitForCommentToLoad() {
|
||||
if (document.querySelector(h)) {
|
||||
return scrollToHash();
|
||||
}
|
||||
if (limit-- < 0) return;
|
||||
setTimeout(waitForCommentToLoad, 200);
|
||||
})();
|
||||
mObject.disconnect();
|
||||
});
|
||||
|
||||
mObject.observe(div, { childList: true, subtree: true });
|
||||
|
||||
// kick off disqus loading
|
||||
comments = document.getElementById("comments");
|
||||
comments.scrollIntoView();
|
||||
} else {
|
||||
scrollToHash();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user