Blame view

sources/apps/activity/js/script.js 2.46 KB
d1bafeea1   Kload   [fix] Upgrade to ...
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  $(function(){
  
  	function processElements($elem){
  		$elem.find('.avatar').each(function(){
  			var $this = $(this);
  			$this.avatar($this.data('user'), 32);
  		});
  		$elem.find('.tooltip').tipsy({gravity:'s', fade:true});
  	}
  
  	var $container = $('#container');
  	processElements($container);
  
  	$container.imagesLoaded(function(){
  		$container.find('.boxcontainer').masonry({
  			itemSelector: '.box',
  			isAnimated: true
  		});
  	});
  
  	$container.infinitescroll({
  			navSelector  : '#page-nav',    // selector for the paged navigation
  			nextSelector : '#page-nav a',  // selector for the NEXT link (to page 2)
  			itemSelector : '.group',     // selector for all items you'll retrieve
  			pixelsFromNavToBottom: 150,
  			extraScrollPx: 50,
  			prefill: true,
  			path : function(page){
  				return OC.filePath('activity', 'ajax', 'fetch.php') + '?page=' + page;
  			},
  			loading: {
  				finishedMsg: t('activity', 'No more activities to load.'),
  				msgText: t('activity', 'Loading older activities'),
  				img: OC.filePath('core', 'img', 'loading-small.gif')
  			}
  		},
  		// trigger Masonry as a callback
  		function( newGroups ) {
  			// hide new items while they are loading
  			var $newGroups = $( newGroups );
  			var $newBoxes;
  
  			// check whether first new group has the same date
  			// as the last group we had before
  			// If that's the case, we'll merge its boxes into the last group's
  			// container.
  			var $firstNewGroup = $newGroups.first();
  			var $lastGroup = $firstNewGroup.prevAll('.group:first');
  			var $appendedBoxes;
  			if ( $lastGroup.data('date') === $firstNewGroup.data('date') ){
  				// append the boxes
  				$appendedBoxes = $firstNewGroup.find('.box').addClass('loading');
  				var $lastBoxContainer = $lastGroup.find('.boxcontainer');
  
  				$lastBoxContainer.append($appendedBoxes);
  				processElements($appendedBoxes);
  				$lastBoxContainer.masonry('appended', $appendedBoxes, true);
  				$appendedBoxes.imagesLoaded(function(){
  					// append the boxes into the last group
  					$appendedBoxes.toggleClass('loading loaded');
  				});
  				// remove from list to process
  				$newGroups.slice(1);
  				// discard the ajax-returned header
  				$firstNewGroup.remove();
  			}
  
  			$newBoxes = $newGroups.find('.box').addClass('loading');
  
  			processElements($newBoxes);
  			$newGroups.find('.boxcontainer').masonry();
  			// ensure that images load before adding to masonry layout
  			$newBoxes.imagesLoaded(function(){
  				// show elems now they're ready
  				$newBoxes.toggleClass('loading loaded');
  			});
  		}
  	);
  });