I'm using a custom masonry type layout jQuery plugin and it works amazing, i'm trying to get it to work in Angular, here is the code so far:
app.directive('coursegridjs', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
initCourseGrid();
$(window).on('resize', function(){
initCourseGrid();
});
} // end jQuery
};
});
Here is the initCourseGrid()
function initCourseGrid() {
// Initialize Responsive Grid
var conWidth = $('.courseGrid').width();
var col = 4;
col = Math.floor(conWidth/540);
if(col==0) {col=1;}
$('.courseGrid').BlocksIt({
numOfCol: Math.floor(col),
offsetX: 3,
offsetY: 5,
blockElement: '.courseGridItem'
});
}
When the page initially loads it looks all messed up, i'm guessing because it doesn't have time to correctly calculate the height of each element.
When I resize the browser window, everything renders as it should, but on initial page load it doesn't. I need a way to detect that all the directives have loaded on the page before I call the initCourseGrid()
I tried $timeout() but that didn't do anything.
Also here is how the coursegridjs
content is being activated:
<div class="courseGrid" coursegridjs>
<div class="courseGridItem"><coursegriditem title="Course Title" studentcount="342" author="Course Author" imageurl="images/courseBanner.jpg"></coursegriditem></div>
<div class="courseGridItem"><coursegriditem title="Course Title 2" studentcount="432" author="GTD" imageurl="images/courseBanner2.jpg"></coursegriditem></div>
</div>
As you can see the grid elements are being generated by another directive called coursegriditem