-
Notifications
You must be signed in to change notification settings - Fork 2
/
_rmllnow.js
315 lines (278 loc) · 7.36 KB
/
_rmllnow.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
var lang="fr";
var firstPageShow=true;
$(document).bind('pagecreate',function(e){
if ($(e.target).attr('id')=='index') {
updateList();
}
});
$(document).bind('pageshow',function(e){
if ($(e.target).attr('id')!='index') {
getNextPage();
}
if (firstPageShow) {
updateFull();
searchInputSetup();
firstPageShow=false;
}
});
function searchInputSetup() {
if (!_FULL) return;
$(document).bind('keydown',function(e){
var input=$('input[data-type=search]:visible');
if (e.keyCode==27) {
if (input.length && input.val().length) {
input.val('').trigger('change');
}
input.focus();
}
});
var input=$('input[data-type=search]');
if (!input.val().length) {
input.val(getNameOfDay(_date.getDay()));
input.trigger('change');
}
input.attr('title',t('Recherche - touche Esc pour effacer/modifier'));
}
function updateFull() {
if (!_FULL || (_FULL && !showall)) {
$('li[data-date!='+date+'], .full').addClass('hidden');
} else if (_FULL) {
$('li[data-date], .full').removeClass('hidden');
}
}
var nextPageLI;
function getNextPage() {
var url;
var li=$('a[href=#'+$('.ui-page-active').attr('id')+']').closest('li').next('li');
updateTime();
while (li.size() && (li.now<parseInt(li.attr('data-start'),10) || now>parseInt(li.attr('data-end'),10) || li.hasClass('hidden') || li.hasClass('ui-screen-hidden'))) {
li=li.next();
}
if (li.size()) {
$('#next','*').show();
} else {
$('#next','*').hide();
}
nextPageLI=li;
}
function next() {
url=nextPageLI.find('a').attr('href');
if (url.length) {
document.location.assign(url);
}
}
function twoDigits(a) {
return (parseInt(a,10)>9)?a:'0'+a;
}
var today;
var prevdate;
var updateListTimeout;
var showall=false;
function moreless(){
if ($('#moreless').data('icon')=='minus') {
$('#moreless').data('icon','plus').find('.ui-icon').removeClass('ui-icon-minus').addClass('ui-icon-plus');
showall=false;
updateFull();
} else {
$('#moreless').data('icon','minus').find('.ui-icon').removeClass('ui-icon-plus').addClass('ui-icon-minus');
showall=true;
updateFull();
}
updateList();
showFirst();
}
function showFirst() {
//setTimeout(function(){
var li=$('li[data-date]:not(.notnow):first');
if (li.length) {
$(document).scrollTop(li.offset().top-44);
}
//},1);
}
var _date;
var date;
var hours;
var minutes;
var now;
var date_human;
var nameOfDay=[
'dimanche',
'lundi',
'mardi',
'mercredi',
'jeudi',
'vendredi',
'samedi'
];
var nameOfMonth=[
'Janvier',
'Février',
'Mars',
'Avril',
'Mai',
'Juin',
'Juillet',
'Août',
'Septembre',
'Octobre',
'Novembre',
'Décembre'
];
function getNameOfDay(d) {
return nameOfDay[d].substr(0,1).toUpperCase()+nameOfDay[d].substr(1);
}
function param(name) {
var QUERY_STRING=document.location.search||'';
// console.log('QUERY_STRING',QUERY_STRING);
var re=new RegExp('.*[\?&]'+name+'=([^&]+).*');
var matches=QUERY_STRING.match(re);
return matches?decodeURIComponent(matches[1]):null;
}
//var FULL=param('full');
var _FULL;
function updateTime() {
var d=param('d');
_date=(d)?new Date(d):new Date;
date=_date.getFullYear()+'-'+twoDigits(_date.getMonth()+1)+'-'+twoDigits(_date.getDate());
hours=_date.getHours();
minutes=_date.getMinutes();
var _t=param('t');
if (_t || (!hours && !minutes)) {
_t=_t.split(':');
hours=parseInt(_t[0],10);
minutes=parseInt(_t[1],10);
} else if (d && !d.match(/:/)) {
var __date=new Date();
hours=_date.getHours();
minutes=_date.getMinutes();
}
now=_date.getDate()*1440+hours*60+minutes;
tomorrow=_date.getDate()*1440+23*60+59;
date_human=t(getNameOfDay(_date.getDay()))+' '+_date.getDate()+' '+t(nameOfMonth[_date.getMonth()]);
}
function updateSearchInput() {
var input=$('input[data-type=search]:visible');
if (!input.length || !input.val().length) {
return;
}
var prevDay=_nameOfDay.indexOf(input.val().toLowerCase().trim());
if (prevDay<0) {
return;
}
var today=_date.getDay();
if ((prevDay+1)%7 == today) {
input.val(getNameOfDay(today)).trigger('change');
}
}
var today_start=[];
var today_stop=[];
function updateList(){
if (updateListTimeout) {
clearTimeout(updateListTimeout);
updateListTimeout=null;
}
updateTime();
if (date!=prevdate) {
updateSearchInput();
if (_FULL==undefined) {
_FULL=$('.full').length;
}
today=$('li[data-date'+(_FULL?'':'='+date)+']')
.each(function(i,li){
li=$(li);
today_start[i]=parseInt(li.attr('data-start'),10);
today_stop[i]=parseInt(li.attr('data-end'),10);
});
prevdate=date;
}
var count=0;
today.each(function(i,li){
li=$(li);
//console.log(i,now,today_start[i]);
if (now>=today_start[i] && now<=today_stop[i]) {
li.removeClass('notnow next');
if (!li.hasClass('ui-screen-hidden')) {
li.removeClass('hidden');
++count;
}
} else {
li.removeClass('next');
li.addClass('notnow');
if (showall) {
if (!li.hasClass('ui-screen-hidden')) {
li.removeClass('hidden');
++count;
}
} else {
li.addClass('hidden');
}
}
});
count=nextEvents(today,count);
if (count==0) {
$('#nothing').removeClass('hidden');
} else {
$('#nothing').addClass('hidden');
}
//$('.today').text(_FULL?date+' '+twoDigits(hours)+':'+twoDigits(minutes):date);
$('.today').text(date_human);
updateListTimeout=setTimeout(updateList,60*1000);
}
function nextEvents(today,count) {
var delta=0;
while(true) {
delta+=60;
today.each(function(i,li){
li=$(li);
if ((now+delta>=today_start[i] && today_start[i]<tomorrow && now<=today_stop[i]) && li.hasClass('notnow')) {
li.removeClass('notnow').addClass('next');
if (!li.hasClass('ui-screen-hidden')) {
li.removeClass('hidden');
++count;
}
}
});
if (count!=0 || now+delta>tomorrow) break;
}
return count;
}
var en={
'Filtrer la liste...': 'Filter list...'
};
function t(txt){
if (lang=="fr") return txt;
return en[txt]?en[txt]:txt;
}
function updateNothing() {
if ($('li:visible').size()==0) {
$('#nothing').removeClass('hidden');
} else {
$('#nothing').addClass('hidden');
}
}
var filterCallback;
var filterCallbackTimeout;
$(document).bind("mobileinit", function(){
$.mobile.defaultPageTransition='none';
// Page
$.mobile.page.prototype.options.headerTheme="a";
$.mobile.page.prototype.options.contentTheme="a";
$.mobile.page.prototype.options.footerTheme="a";
$.mobile.page.prototype.options.theme="a";
// Listviews
$.mobile.listview.prototype.options.headerTheme="a";
$.mobile.listview.prototype.options.theme="a";
$.mobile.listview.prototype.options.dividerTheme="a";
$.mobile.listview.prototype.options.splitTheme="a";
$.mobile.listview.prototype.options.countTheme="a";
$.mobile.listview.prototype.options.filterTheme="a";
$.mobile.listview.prototype.options.filterPlaceholder=t("Filtrer la liste...");
filterCallback=$.mobile.listview.prototype.options.filterCallback;
$.mobile.listview.prototype.options.filterCallback=function(text,searchValue) {
if (filterCallbackTimeout) {
clearTimeout(filterCallbackTimeout);
}
filterCallbackTimeout=setTimeout(updateNothing,100);
return filterCallback(text.toLowerCase(),searchValue);
}
});