Skip to content

Instantly share code, notes, and snippets.

@englishextra
Last active April 24, 2016 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save englishextra/5e423ff34f67982f017b to your computer and use it in GitHub Desktop.
Save englishextra/5e423ff34f67982f017b to your computer and use it in GitHub Desktop.
Rebuild Masonry / Packery after Disqus is ready
evento.add(window, "load", function () {
var w = window,
d = document,
disqus_thread = d.getElementById("disqus_thread") || "",
disqus_shortname = disqus_thread ? (disqus_thread.dataset.shortname || "") : "",
embed_js_src = ("https:" == w.location.protocol ? "https" : "http") + "://" + disqus_shortname + ".disqus.com/embed.js",
g = ".grid",
h = ".grid-item",
k = ".grid-sizer",
grid = d.querySelector(g) || "",
grid_item = d.querySelector(h) || "";
if (grid && grid_item) {
if (w.Packery) {
var pckry = new Packery(grid, {
itemSelector : h,
columnWidth : k,
gutter : 0
});
if (w.Draggabilly) {
var grid_items = d.querySelectorAll(h) || "",
draggies = [];
for (var i = 0; i < grid_items.length; i++) {
var draggableElem = grid_items[i];
var draggie = new Draggabilly(draggableElem, {});
draggies.push(draggie);
}
pckry.bindDraggabillyEvents(draggie);
}
} else if (w.Masonry) {
var msnry = new Masonry(grid, {
itemSelector : h,
columnWidth : k
});
}
if (disqus_thread && disqus_shortname) {
scriptIsLoaded(embed_js_src) || loadJS(embed_js_src, function () {
var f = !1,
si = setInterval(function () {
var disqus_thread_height = disqus_thread.clientHeight || disqus_thread.offsetHeight || "";
if (108 < disqus_thread_height && !1 === f) {
if ("undefined" !== typeof msnry && msnry) {
msnry.layout();
} else {
"undefined" !== typeof pckry && pckry && pckry.layout();
}
f = !0;
clearInterval(si);
}
}, 100);
});
}
}
});