1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<?php
/**
* Load new items of a list through ajax when a button clicked
*
* @package ElggInfiniteScroll
*/
?>
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(
$('<div class="elgg-infinite-scroll-top"></div>')
.append(
$('<?php
echo elgg_view('output/url', array(
'text' => '',
'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);
|