Skip to content

Commit

Permalink
added contao-encore-bundle support
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Patzer committed Mar 21, 2018
1 parent cf30e68 commit afb5fdb
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,24 @@ public function getBundles(ParserInterface $parser)
*/
public function getExtensionConfig($extensionName, array $extensionConfigs, ContainerBuilder $container)
{
return ContainerUtil::mergeConfigFile(
$extensionConfigs = ContainerUtil::mergeConfigFile(
'huh_list',
$extensionName,
$extensionConfigs,
$container->getParameter('kernel.project_dir').'/vendor/heimrichhannot/contao-list-bundle/src/Resources/config/config.yml'
);

if (in_array(
'HeimrichHannot\EncoreBundle\HeimrichHannotContaoEncoreBundle',
$container->getParameter('kernel.bundles'), true)) {
$extensionConfigs = ContainerUtil::mergeConfigFile(
'huh_encore',
$extensionName,
$extensionConfigs,
$container->getParameter('kernel.project_dir').'/vendor/heimrichhannot/contao-list-bundle/src/Resources/config/config_encore.yml'
);
}

return $extensionConfigs;
}
}
4 changes: 4 additions & 0 deletions src/Resources/config/config_encore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
huh:
encore:
entries:
- { name: contao-list-bundle, file: "vendor/heimrichhannot/contao-list-bundle/src/Resources/public/js/jquery.list-bundle.es6.js" }
114 changes: 114 additions & 0 deletions src/Resources/public/js/jquery.list-bundle.es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
var jQuery = require('jquery');

(function($)
{
window.LIST_BUNDLE = {
init: function()
{
this.initPagination();
this.initMasonry();
},
initPagination: function()
{
$('.huh-list .ajax-pagination').each(function()
{
var $list = $(this).closest('.huh-list'),
$items = $list.find('.items'),
$wrapper = $list.find('.wrapper'),
id = '#' + $wrapper.attr('id');

$wrapper.jscroll({
loadingHtml: '<div class="loading"><span class="text">Lade...</span></div>',
nextSelector: '.ajax-pagination a.next',
autoTrigger: $wrapper.data('add-infinite-scroll') == 1,
contentSelector: id,
callback: function()
{
var $jscrollAdded = $(this),
$newItems = $jscrollAdded.find('.item');

$newItems.hide();

$jscrollAdded.imagesLoaded(function()
{
$items.append($newItems.fadeIn(300));

if ($wrapper.attr('data-add-masonry') === "1") {
$items.masonry('appended', $newItems);
$items.masonry();
}

// remove item counters...
$items.find('.item').removeClass(function(index, cssClass)
{
var matches = cssClass.match(/item_\d+/g);

if (matches instanceof Array && matches.length > 0)
{
return matches[0];
}
});

//... and readd them again
$items.find('.item').each(function(index)
{
var $item = $(this),
itemIndex = index + 1;

$(this).addClass('item_' + itemIndex).removeClass('odd even first last');

// odd/even
if (itemIndex % 2 == 0)
{
$item.addClass('even');
}
else
{
$item.addClass('odd');
}

// add first and last
if (itemIndex == 1)
{
$item.addClass('first');
}

if (itemIndex == $items.find('.item').length)
{
$item.addClass('last');
}
});

$jscrollAdded.find('.ajax-pagination').appendTo($jscrollAdded.closest('.jscroll-inner'));
$jscrollAdded.remove();
});
}
});
});
},
initMasonry: function()
{
$('.huh-list .wrapper[data-add-masonry="1"]').each(function()
{
var $this = $(this).find('.items'),
options = $(this).data('masonry-options');

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

// update due to stamps
$grid.masonry();
});
});
}
};

$(document).ready(function() {
LIST_BUNDLE.init();
});
})(jQuery);
5 changes: 2 additions & 3 deletions src/Resources/public/js/jquery.list-bundle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function($)
{
LIST_BUNDLE = {
window.LIST_BUNDLE = {
init: function()
{
this.initPagination();
Expand Down Expand Up @@ -106,8 +106,7 @@
}
};

$(document).ready(function()
{
$(document).ready(function() {
LIST_BUNDLE.init();
});
})(jQuery);
2 changes: 1 addition & 1 deletion src/Resources/public/js/jquery.list-bundle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit afb5fdb

Please sign in to comment.