Skip to content

Instantly share code, notes, and snippets.

@ibanner
Created December 21, 2016 10:31
Show Gist options
  • Save ibanner/5d18983d9c4da40b6339c69ed0d9b64f to your computer and use it in GitHub Desktop.
Save ibanner/5d18983d9c4da40b6339c69ed0d9b64f to your computer and use it in GitHub Desktop.
This is what I'm trying to use now, but still I get the same layout in RTL as in LTR.
var x = document.getElementsByTagName("html")[0].getAttribute("dir");
jQuery(function() {
var masonryInit = true; // set Masonry init flag
jQuery.fn.almComplete = function(alm){ // Ajax Load More callback function
if(jQuery('#masonry-grid').length){
var $container = jQuery('#masonry-grid ul'); // our container
if(masonryInit){
// initialize Masonry only once
masonryInit = false;
if ( x == 'rtl') {
$container.masonry({
itemSelector: '.grid-item',
columnWidth: '.grid-item',
percentPosition: true,
resizesContainer: true,
originLeft: false,
isRTL: true
});
console.log('RTL detected');
} else {
$container.masonry({
itemSelector: '.grid-item',
columnWidth: '.grid-item',
percentPosition: true,
resizesContainer: true
});
console.log('RTL not detected');
}
}else{
$container.masonry('reloadItems'); // Reload masonry items after callback
}
$container.imagesLoaded( function() { // When images are loaded, fire masonry again.
$container.masonry();
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment