From fe7bc5b2fa63f4b8562a961cf3910db1f3b8f7a1 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 15 Mar 2014 15:07:03 -0300 Subject: Squashed 'mod/infinite_scroll/' content from commit 68db72a git-subtree-dir: mod/infinite_scroll git-subtree-split: 68db72a726e9ccd3603acbf59914c2017276b0ed --- views/default/js/infinite_scroll/new_items.php | 62 ++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 views/default/js/infinite_scroll/new_items.php (limited to 'views/default/js/infinite_scroll/new_items.php') diff --git a/views/default/js/infinite_scroll/new_items.php b/views/default/js/infinite_scroll/new_items.php new file mode 100644 index 000000000..f686b8c3f --- /dev/null +++ b/views/default/js/infinite_scroll/new_items.php @@ -0,0 +1,62 @@ + + +elgg.provide('elgg.infinite_scroll.new_items'); + +elgg.infinite_scroll.new_items.prepend = function(data) { + var $list = $('.elgg-pagination').siblings('.elgg-list, .elgg-gallery').filter(':not(.elgg-module *)'); + if (data) { + var n = $list.children(":hidden").length + $(data).children().length; + $list.prepend($(data).children().hide()); + $('.elgg-infinite-scroll-top').find('.elgg-button').text( + elgg.echo('infinite_scroll:new_items', [n]) + ).end().show(); + } + $list.trigger('prepend', data); +}; + +elgg.infinite_scroll.new_items.check = function() { + // Select all paginated .elgg-list or .elgg-gallery witch aren't into widgets + var $list = $('.elgg-pagination').siblings('.elgg-list, .elgg-gallery').filter(':not(.elgg-module *)'); + + elgg.infinite_scroll.load($list, 0, function(data){ + elgg.infinite_scroll.new_items.prepend(data); + setTimeout(elgg.infinite_scroll.new_items.check, 30000); + }); +}; + +elgg.infinite_scroll.new_items.init = function() { + + // Select all paginated .elgg-list or .elgg-gallery witch aren't into widgets + $list = $('.elgg-pagination').siblings('.elgg-list, .elgg-gallery').filter(':not(.elgg-module *)') + + // Add new items button at the begining of the list + .before( + $('
') + .append( + $(' '', + 'href' => '', + 'class' => 'elgg-button', + )); + ?>').click(function(){ + $list.children().slideDown({ + duration: 700, + easing: 'easeInCubic', + }); + $(this).parent().hide(); + return false; + }) + ).hide() + ); + // Check for new items each 30s. + setTimeout(elgg.infinite_scroll.new_items.check, 0); +}; + +elgg.register_hook_handler('init', 'system', elgg.infinite_scroll.new_items.init); -- cgit v1.2.3