Last active
April 24, 2016 19:03
-
-
Save englishextra/5e423ff34f67982f017b to your computer and use it in GitHub Desktop.
Rebuild Masonry / Packery after Disqus is ready
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read difference Masonry / Packery
http://fusioncharts.com/blog/2014/09/comparing-jquery-grid-plugins-masonry-vs-isotope-vs-packery-vs-gridster-vs-shapeshift-vs-shuffle-js/
Deps:
https://github.com/desandro/masonry
https://github.com/metafizzy/packery
https://github.com/g4code/evento
https://github.com/filamentgroup/loadJS