Blame view

sources/apps/activity/js/script.js 4.44 KB
d1bafeea1   Kload   [fix] Upgrade to ...
1
  $(function(){
6d9380f96   Cédric Dupont   Update sources OC...
2
  	var OCActivity={};
d1bafeea1   Kload   [fix] Upgrade to ...
3

6d9380f96   Cédric Dupont   Update sources OC...
4
5
6
7
  	OCActivity.Filter = {
  		filter: undefined,
  		currentPage: 0,
  		navigation: $('#app-navigation'),
d1bafeea1   Kload   [fix] Upgrade to ...
8

6d9380f96   Cédric Dupont   Update sources OC...
9
10
11
12
  		setFilter: function (filter) {
  			if (filter === this.filter) {
  				return;
  			}
d1bafeea1   Kload   [fix] Upgrade to ...
13

6d9380f96   Cédric Dupont   Update sources OC...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  			this.navigation.find('a[data-navigation=' + this.filter + ']').removeClass('active');
  			this.currentPage = 0;
  
  			this.filter = filter;
  			OC.Util.History.pushState('filter=' + filter);
  
  			OCActivity.InfinitScrolling.container.animate({ scrollTop: 0 }, 'slow');
  			OCActivity.InfinitScrolling.container.children().remove();
  			$('#no_activities').addClass('hidden');
  			$('#no_more_activities').addClass('hidden');
  			$('#loading_activities').removeClass('hidden');
  			OCActivity.InfinitScrolling.ignoreScroll = false;
  
  			this.navigation.find('a[data-navigation=' + filter + ']').addClass('active');
  
  			OCActivity.InfinitScrolling.prefill();
  		}
  	};
d1bafeea1   Kload   [fix] Upgrade to ...
32

6d9380f96   Cédric Dupont   Update sources OC...
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
  	OCActivity.InfinitScrolling = {
  		ignoreScroll: false,
  		container: $('#container'),
  		content: $('#app-content'),
  
  		prefill: function () {
  			if (this.content.scrollTop() + this.content.height() > this.container.height() - 100) {
  				OCActivity.Filter.currentPage++;
  
  				$.get(
  					OC.filePath('activity', 'ajax', 'fetch.php'),
  					'filter=' + OCActivity.Filter.filter + '&page=' + OCActivity.Filter.currentPage,
  					function(data) {
  						if (data.length) {
  							OCActivity.InfinitScrolling.appendContent(data);
  
  							// Continue prefill
  							OCActivity.InfinitScrolling.prefill();
  						}
  						else if (OCActivity.Filter.currentPage == 1) {
  							// First page is empty - No activities :(
  							$('#no_activities').removeClass('hidden');
  							$('#loading_activities').addClass('hidden');
  						}
  						else {
  							// Page is empty - No more activities :(
  							$('#no_more_activities').removeClass('hidden');
  							$('#loading_activities').addClass('hidden');
  						}
  					}
  				);
d1bafeea1   Kload   [fix] Upgrade to ...
64
65
  			}
  		},
6d9380f96   Cédric Dupont   Update sources OC...
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  
  		onScroll: function () {
  			if (!OCActivity.InfinitScrolling.ignoreScroll && OCActivity.InfinitScrolling.content.scrollTop() +
  			 OCActivity.InfinitScrolling.content.height() > OCActivity.InfinitScrolling.container.height() - 100) {
  				OCActivity.Filter.currentPage++;
  
  				OCActivity.InfinitScrolling.ignoreScroll = true;
  				$.get(
  					OC.filePath('activity', 'ajax', 'fetch.php'),
  					'filter=' + OCActivity.Filter.filter + '&page=' + OCActivity.Filter.currentPage,
  					function(data) {
  						OCActivity.InfinitScrolling.appendContent(data);
  						OCActivity.InfinitScrolling.ignoreScroll = false;
  
  						if (!data.length) {
  							// Page is empty - No more activities :(
  							$('#no_more_activities').removeClass('hidden');
  							$('#loading_activities').addClass('hidden');
  							OCActivity.InfinitScrolling.ignoreScroll = true;
  						}
  					}
  				);
d1bafeea1   Kload   [fix] Upgrade to ...
88
  			}
6d9380f96   Cédric Dupont   Update sources OC...
89
90
91
92
93
  		},
  
  		appendContent: function (content) {
  			var firstNewGroup = $(content).first(),
  				lastGroup = this.container.children().last();
d1bafeea1   Kload   [fix] Upgrade to ...
94

6d9380f96   Cédric Dupont   Update sources OC...
95
96
97
98
  			// Is the first new container the same as the last one?
  			if (lastGroup && lastGroup.data('date') === firstNewGroup.data('date')) {
  				var appendedBoxes = firstNewGroup.find('.box'),
  					lastBoxContainer = lastGroup.find('.boxcontainer');
d1bafeea1   Kload   [fix] Upgrade to ...
99

6d9380f96   Cédric Dupont   Update sources OC...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  				// Move content into the last box
  				OCActivity.InfinitScrolling.processElements(appendedBoxes);
  				lastBoxContainer.append(appendedBoxes);
  
  				// Remove the first box, so it's not duplicated
  				content = $(content).slice(1);
  			} else {
  				content = $(content);
  			}
  
  			OCActivity.InfinitScrolling.processElements(content);
  			this.container.append(content);
  		},
  
  		processElements: function (parentElement) {
  			$(parentElement).find('.avatar').each(function() {
  				var element = $(this);
  				element.avatar(element.data('user'), 28);
  			});
  
  			$(parentElement).find('.tooltip').tipsy({
  				gravity:	's',
  				fade:		true
d1bafeea1   Kload   [fix] Upgrade to ...
123
124
  			});
  		}
6d9380f96   Cédric Dupont   Update sources OC...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  	};
  
  	OCActivity.Filter.setFilter(OCActivity.InfinitScrolling.container.attr('data-activity-filter'));
  	OCActivity.InfinitScrolling.content.on('scroll', OCActivity.InfinitScrolling.onScroll);
  
  	OCActivity.Filter.navigation.find('a[data-navigation]').on('click', function (event) {
  		OCActivity.Filter.setFilter($(this).attr('data-navigation'));
  		event.preventDefault();
  	});
  
  	$('#enable_rss').change(function () {
  		if (this.checked) {
  			$('#rssurl').removeClass('hidden');
  		} else {
  			$('#rssurl').addClass('hidden');
  		}
  		$.post(OC.filePath('activity', 'ajax', 'rssfeed.php'), 'enable=' + this.checked, function(data) {
  			$('#rssurl').val(data.data.rsslink);
  		});
  	});
  
  	$('#rssurl').on('click', function () {
  		$('#rssurl').select();
  	});
d1bafeea1   Kload   [fix] Upgrade to ...
149
  });