Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
56
gaia/shared/js/advanced_timer.js
Executable file
56
gaia/shared/js/advanced_timer.js
Executable file
|
|
@ -0,0 +1,56 @@
|
|||
/* exported advanced_timer */
|
||||
|
||||
'use strict';
|
||||
|
||||
var advanced_timer = {
|
||||
/**
|
||||
* Maps between user Ids and navigator ones
|
||||
*/
|
||||
timers: {},
|
||||
|
||||
/**
|
||||
* Register a new timer with the user's timerId
|
||||
*/
|
||||
start: function(timerId, timeout, callback) {
|
||||
if (typeof(callback) != 'function') {
|
||||
callback = function() {};
|
||||
}
|
||||
|
||||
var self = this;
|
||||
var _id = setTimeout(function advTimer() {
|
||||
var realUsedTime = new Date().getTime() - self.timers[timerId].timestamp;
|
||||
delete(self.timers[timerId]);
|
||||
callback(realUsedTime);
|
||||
}, timeout);
|
||||
this.timers[timerId] = {
|
||||
'timeout': timeout,
|
||||
'internalTimerId': _id,
|
||||
'timestamp': new Date().getTime()
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Stops timer and returns the pending time
|
||||
*/
|
||||
stop: function(timerId) {
|
||||
var timer = this.timers[timerId];
|
||||
if (!timer) {
|
||||
return 0;
|
||||
}
|
||||
clearTimeout(timer.internalTimerId);
|
||||
var pendingTime = this.queryPendingTime();
|
||||
delete(this.timers[timerId]);
|
||||
return pendingTime;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the pending time to timeout the timer
|
||||
*/
|
||||
queryPendingTime: function(timerId) {
|
||||
var timer = this.timers[timerId];
|
||||
if (!timer) {
|
||||
return 0;
|
||||
}
|
||||
return timer.timeout - (new Date().getTime() - timer.timestamp);
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue