forked from luxigo/rmllnow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_rmllnow.js
173 lines (150 loc) · 4.14 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
var lang="fr";
$(document).bind('pagecreate',function(e){
if ($(e.target).attr('id')=='index') {
updateList();
}
});
$(document).bind('pageshow',function(e){
if ($(e.target).attr('id')!='index') {
getNextPage();
}
});
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;
} else {
$('#moreless').data('icon','minus').find('.ui-icon').removeClass('ui-icon-plus').addClass('ui-icon-minus');
showall=true;
}
updateList();
}
var _date;
var date;
var hours;
var minutes;
var now;
function updateTime() {
_date=new Date;
date=_date.getFullYear()+'-'+twoDigits(_date.getMonth()+1)+'-'+twoDigits(_date.getDate());
hours=_date.getHours();
minutes=_date.getMinutes();
now=_date.getDate()*1440+hours*60+minutes;
/////uncomment for testing (same date must be set in rmllnow.js)
//date='2012-07-09';
//now=10*1440+11*60;
}
var today_start=[];
var today_stop=[];
function updateList(){
if (updateListTimeout) {
clearTimeout(updateListTimeout);
updateListTimeout=null;
}
updateTime();
if (date!=prevdate) {
$('li[data-date!='+date+']').addClass('hidden');
today=$('li[data-date='+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);
if (now>=today_start[i] && now<=today_stop[i]) {
li.removeClass('notnow');
if (!li.hasClass('ui-screen-hidden')) {
li.removeClass('hidden');
++count;
}
} else {
li.addClass('notnow');
if (showall) {
if (!li.hasClass('ui-screen-hidden')) {
li.removeClass('hidden');
++count;
}
} else {
li.addClass('hidden');
}
}
});
if (count==0) {
$('#nothing').removeClass('hidden');
} else {
$('#nothing').addClass('hidden');
}
updateListTimeout=setTimeout(updateList,60*1000);
}
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);
}
});