|
30 | 30 | }(function($, window, document, undefined) {
|
31 | 31 |
|
32 | 32 | var timer;
|
33 |
| - var _options = {}; |
34 | 33 |
|
35 | 34 | var Timer = function(targetElement){
|
| 35 | + this._options = {}; |
36 | 36 | this.targetElement = targetElement;
|
37 | 37 | return this;
|
38 | 38 | };
|
39 | 39 |
|
40 | 40 | Timer.start = function(userOptions, targetElement){
|
41 | 41 | timer = new Timer(targetElement);
|
42 |
| - mergeOptions(userOptions); |
| 42 | + mergeOptions(timer, userOptions); |
43 | 43 | return timer.start(userOptions);
|
44 | 44 | };
|
45 | 45 |
|
46 |
| - // Writes to `_options` object so that other |
| 46 | + // Writes to `this._options` object so that other |
47 | 47 | // functions can access it without having to
|
48 | 48 | // pass this object as argument multiple times.
|
49 |
| - function mergeOptions(opts) { |
| 49 | + function mergeOptions(timer, opts) { |
50 | 50 | opts = opts || {};
|
51 | 51 | var classNames = opts.classNames || {};
|
52 | 52 |
|
53 |
| - _options.classNameSeconds = classNames.seconds || 'jst-seconds' |
54 |
| - , _options.classNameMinutes = classNames.minutes || 'jst-minutes' |
55 |
| - , _options.classNameHours = classNames.hours || 'jst-hours' |
56 |
| - , _options.classNameClearDiv = classNames.clearDiv || 'jst-clearDiv' |
57 |
| - , _options.classNameTimeout = classNames.timeout || 'jst-timeout'; |
| 53 | + timer._options.classNameSeconds = classNames.seconds || 'jst-seconds' |
| 54 | + , timer._options.classNameMinutes = classNames.minutes || 'jst-minutes' |
| 55 | + , timer._options.classNameHours = classNames.hours || 'jst-hours' |
| 56 | + , timer._options.classNameClearDiv = classNames.clearDiv || 'jst-clearDiv' |
| 57 | + , timer._options.classNameTimeout = classNames.timeout || 'jst-timeout'; |
58 | 58 | }
|
59 | 59 |
|
60 | 60 | Timer.prototype.start = function(options) {
|
61 | 61 |
|
| 62 | + var that = this; |
| 63 | + |
62 | 64 | var createSubDivs = function(timerBoxElement){
|
63 | 65 | var seconds = document.createElement('div');
|
64 |
| - seconds.className = _options.classNameSeconds; |
| 66 | + seconds.className = that._options.classNameSeconds; |
65 | 67 |
|
66 | 68 | var minutes = document.createElement('div');
|
67 |
| - minutes.className = _options.classNameMinutes; |
| 69 | + minutes.className = that._options.classNameMinutes; |
68 | 70 |
|
69 | 71 | var hours = document.createElement('div');
|
70 |
| - hours.className = _options.classNameHours; |
| 72 | + hours.className = that._options.classNameHours; |
71 | 73 |
|
72 | 74 | var clearDiv = document.createElement('div');
|
73 |
| - clearDiv.className = _options.classNameClearDiv; |
| 75 | + clearDiv.className = that._options.classNameClearDiv; |
74 | 76 |
|
75 | 77 | return timerBoxElement.
|
76 | 78 | append(hours).
|
|
93 | 95 | });
|
94 | 96 |
|
95 | 97 | timerBoxElement.on('complete', function(){
|
96 |
| - timerBoxElement.addClass(_options.classNameTimeout); |
| 98 | + timerBoxElement.addClass(that._options.classNameTimeout); |
97 | 99 | });
|
98 | 100 |
|
99 | 101 | timerBoxElement.on('complete', function(){
|
|
241 | 243 | return false;
|
242 | 244 | }
|
243 | 245 |
|
244 |
| - element.find('.' + _options.classNameSeconds).text(finalValues.pop()); |
245 |
| - element.find('.' + _options.classNameMinutes).text(finalValues.pop() + ':'); |
246 |
| - element.find('.' + _options.classNameHours).text(finalValues.pop() + ':'); |
| 246 | + element.find('.' + this._options.classNameSeconds).text(finalValues.pop()); |
| 247 | + element.find('.' + this._options.classNameMinutes).text(finalValues.pop() + ':'); |
| 248 | + element.find('.' + this._options.classNameHours).text(finalValues.pop() + ':'); |
247 | 249 | };
|
248 | 250 |
|
249 | 251 |
|
|
0 commit comments