comparison geotemco/lib/slider/js/timer.js @ 0:b12c99b7c3f0

commit for previous development
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 19 Jan 2015 17:13:49 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b12c99b7c3f0
1 /*----------------------------------------------------------------------------\
2 | Timer Class |
3 |-----------------------------------------------------------------------------|
4 | Created by Erik Arvidsson |
5 | (http://webfx.eae.net/contact.html#erik) |
6 | For WebFX (http://webfx.eae.net/) |
7 |-----------------------------------------------------------------------------|
8 | Object Oriented Encapsulation of setTimeout fires ontimer when the timer |
9 | is triggered. Does not work in IE 5.00 |
10 |-----------------------------------------------------------------------------|
11 | Copyright (c) 2002, 2006 Erik Arvidsson |
12 |-----------------------------------------------------------------------------|
13 | Licensed under the Apache License, Version 2.0 (the "License"); you may not |
14 | use this file except in compliance with the License. You may obtain a copy |
15 | of the License at http://www.apache.org/licenses/LICENSE-2.0 |
16 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
17 | Unless required by applicable law or agreed to in writing, software |
18 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
19 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
20 | License for the specific language governing permissions and limitations |
21 | under the License. |
22 |-----------------------------------------------------------------------------|
23 | 2002-10-14 | Original version released |
24 | 2006-05-28 | Changed license to Apache Software License 2.0. |
25 |-----------------------------------------------------------------------------|
26 | Created 2002-10-14 | All changes are in the log above. | Updated 2006-05-28 |
27 \----------------------------------------------------------------------------*/
28
29 function Timer(nPauseTime) {
30 this._pauseTime = typeof nPauseTime == "undefined" ? 1000 : nPauseTime;
31 this._timer = null;
32 this._isStarted = false;
33 }
34
35 Timer.prototype.start = function () {
36 if (this.isStarted())
37 this.stop();
38 var oThis = this;
39 this._timer = window.setTimeout(function () {
40 if (typeof oThis.ontimer == "function")
41 oThis.ontimer();
42 }, this._pauseTime);
43 this._isStarted = false;
44 };
45
46 Timer.prototype.stop = function () {
47 if (this._timer != null)
48 window.clearTimeout(this._timer);
49 this._isStarted = false;
50 };
51
52 Timer.prototype.isStarted = function () {
53 return this._isStarted;
54 };
55
56 Timer.prototype.getPauseTime = function () {
57 return this._pauseTime;
58 };
59
60 Timer.prototype.setPauseTime = function (nPauseTime) {
61 this._pauseTime = nPauseTime;
62 };