Skip to content

Commit

Permalink
masonry-integration mit vanilla js, set masonry options via template
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Jun 29, 2018
1 parent 608d0c1 commit 25abeeb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
50 changes: 33 additions & 17 deletions src/Resources/public/js/jquery.list-bundle.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,44 @@ let jQuery = require('jquery');
});
},
initMasonry: function() {
if ($('.huh-list .wrapper[data-add-masonry="1"]').length < 1)
if (document.querySelectorAll('.huh-list .wrapper[data-add-masonry="1"]').length < 1)
{
return;
}

import(/* webpackChunkName: "masonry-layout" */ 'masonry-layout').then(function() {
import(/* webpackChunkName: "imagesloaded" */ 'imagesloaded').then(function() {
$('.huh-list .wrapper[data-add-masonry="1"]').each(function() {
let $this = $(this).find('.items'),
options = $(this).data('masonry-options');

let $grid = $this.imagesLoaded(function() {
$grid.masonry({
// fitWidth: true,
itemSelector: '.item',
stamp: '.stamp-item'
});

// update due to stamps
$grid.masonry();
});
import(/* webpackChunkName: "masonry-layout" */ 'masonry-layout').then(function(Masonry) {
import(/* webpackChunkName: "imagesloaded" */ 'imagesloaded').then(function(imagesLoaded) {
document.querySelectorAll('.huh-list .wrapper[data-add-masonry="1"]').forEach(function(elem, index, list) {
let items = elem.querySelector('.items');
let options = {
itemSelector: '.item',
stamp: '.stamp-item'
};
let listOptions = elem.getAttribute('data-masonry');
if (listOptions !== null && listOptions !== '') {
options = Object.assign({}, options, JSON.parse(listOptions));
}
let grid = imagesLoaded(items, function(instance) {
let msnry = new Masonry(items, options);
msnry.layout();
})
});

// $('.huh-list .wrapper[data-add-masonry="1"]').each(function() {
// let $this = $(this).find('.items'),
// options = $(this).data('masonry-options');
//
// let $grid = $this.imagesLoaded(function() {
// $grid.masonry({
// // fitWidth: true,
// itemSelector: '.item',
// stamp: '.stamp-item'
// });
//
// // update due to stamps
// $grid.masonry();
// });
// });
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/list/list_default.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="wrapper" id="{{ wrapperId }}"{{ dataAttributes|default()|raw }}>
<div {% block attributes %}class="wrapper" id="{{ wrapperId }}"{{ dataAttributes|default()|raw }}{% endblock %}>
{% if showInitialResults or submitted %}
{% if showItemCount %}
<p class="count">{{ itemsFoundText|raw }}</p>
Expand Down

0 comments on commit 25abeeb

Please sign in to comment.