-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathferjeruta.js
231 lines (208 loc) · 5.04 KB
/
ferjeruta.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
/**
* ferjeruta.no
* ferjeruta.js - main js code for init and minor functions
* (c) 2014 Jon Tungland ([email protected]) - http://runnane.no/
* Released under the GNU General Public License 2.0
* See gpl-2.0.txt
*
* Project page: https://github.com/runnane/ferjeruta
*
*/
/**
*
* @param fm
* @param fs
* @param lm
* @param ls
* @returns {number}
* @constructor
*/
var TimeBetweenTwoTimes = function(fm, fs, lm, ls) {
"use strict";
var date1 = new Date(2000, 0, 1, fm, fs);
var date2 = new Date(2000, 0, 1, lm, ls);
if(date2 < date1) {
date2.setDate(date2.getDate() + 1);
}
var diff = date2 - date1;
return(diff / 60000);
};
/**
*
* @param secs
* @returns {string}
* @constructor
*/
var SecsToString = function(secs) {
"use strict";
var hours = Math.floor(secs / 60 / 60);
secs -= hours * 60 * 60;
var minutes = Math.floor(secs / 60);
secs -= minutes * 60;
var seconds = Math.floor(secs);
return hours + " t, " + minutes + " m, " + seconds + " s";
};
/**
*
* @param minutes
* @returns {string}
* @constructor
*/
var MinsToString = function(minutes) {
"use strict";
var hours = Math.floor(minutes / 60);
minutes -= hours * 60;
if(hours >= 1) {
return hours + ":" + strpad(minutes,2) + " min";
} else {
return minutes + " min";
}
};
/**
* Get weekday name by dayOfWeek int
* @param dayOfWeek
* @param isjsdate
* @returns {any}
* @constructor
*/
var GetDayName = function (dayOfWeek, isjsdate) {
"use strict";
var weekday = new Array(7);
weekday[0] = "Søndag";
weekday[1] = "Mandag";
weekday[2] = "Tirsdag";
weekday[3] = "Onsdag";
weekday[4] = "Torsdag";
weekday[5] = "Fredag";
weekday[6] = "Lørdag";
if(isjsdate != 1) {
dayOfWeek--;
}
return weekday[dayOfWeek];
};
/**
*
* @param str
* @param maxCharacters
* @returns {string}
*/
var strpad = function (str, maxCharacters) {
"use strict";
var outStr = str.toString();
return outStr.length < maxCharacters ? strpad("0" + outStr, maxCharacters) : outStr;
};
/**
*
* @param h1
* @param m1
* @param h2
* @param m2
* @returns {boolean}
*/
var isEarlier = function (h1, m1, h2, m2) {
"use strict";
if(h1 < h2 || (h1 == h2 && m1 < m2)) {
return true;
}
return false;
};
/**
* Extend internal date object
* @returns {string}
*/
Date.prototype.toNorwString = function () {
"use strict";
return this.getDate() + "." + (this.getMonth() + 1) + "." + this.getFullYear();
};
/**
* Helper function for creating headers, breadcrumbs etc
* @param str
* @param header
* @returns {jQuery|HTMLElement|*|Promise<string>|string}
* @constructor
*/
var CreateSimpleLi = function(str, header){
"use strict";
if(header == undefined){
return $('<li />').text(str);
}
var li = $('<li />');
li.append($('<h1 />').html(header));
li.append($('<p />').html(str));
return li
};
////// Start webpage
$.ajaxSetup({ cache: false });
var _fr;
var _paq = _paq || [];
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
$(document)
.ready(function (e) {
"use strict";
// Load main page if hash is set when loading page (cannot refresh inactive page)
if(window.location.hash){
$.mobile.changePage("#pageMainview", {transition: "none"});
}
// Set up page
_fr = new coreFerjeruta();
_fr.Initialize(true, function(){
_fr.RefreshNotifications(function(success){
var interval = setInterval(function(s){
$.mobile.loading('hide');
clearInterval(interval);
},1);
});
});
// Init route refresh button
$("#btnRefresh")
.click(function (f) {
_fr.RefreshServices();
});
// Init notification refresh button
$("#btnRefreshNotifications")
.click(function (f) {
_fr.RefreshNotifications();
});
// Add refresh when showing main page
$( "#pageMainview" )
.on( "pagebeforeshow", function( event ) {
_fr.RefreshServices();
});
// Update count on settings page
$( "#pageSettings" )
.on( "pagebeforeshow", function( event ) {
var HiddenServices = _fr.GetSetting("HiddenServices");
var len = $.map(HiddenServices, function(n, i) { return i; }).length;
if(len > 0 ){
$("#btnResetHiddenServices").closest('.ui-btn').show();
$("#btnResetHiddenServices").prop("value", "Gjennopprett " + len + " skjulte ruter");
$("#btnResetHiddenServices").button("refresh");
}else{
$("#btnResetHiddenServices").closest('.ui-btn').hide();
}
});
$("#btnResetHiddenServices").click(function(){
_fr.ResetHiddenServices();
});
// Set hooks and default values to usersettings elements
$.each(_fr.userSettings, function(settingName, settingOptions) {
var el = $("#s_" + settingName);
el.change(function (f) {
var val = (el.prop('checked') === true);
_fr.SetSetting(settingName, val);
});
el.prop('checked', _fr.GetSetting(settingName)).checkboxradio('refresh');
});
});
$(document).on('pagebeforecreate', '#pageMainview', function(){
"use strict";
var interval = setInterval(function(){
$.mobile.loading('show', {
text: 'Laster ferjeruta',
textVisible: true,
html: ""
});
clearInterval(interval);
},1);
});