Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit c279948

Browse files
author
Søren Ernst
authored
Merge pull request #6 from Alxmerino/master
Added module loader resolves #4
2 parents e51f8d6 + 11bbc3c commit c279948

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

.DS_Store

6 KB
Binary file not shown.

lib/moment-timer.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
(function () {
1+
(function (root, factory) {
2+
if (typeof define === 'function' && define.amd) {
3+
// AMD.
4+
define(['moment'], factory);
5+
} else if (typeof module === 'object' && module.exports) {
6+
// CommonJS-like
7+
module.exports = factory(require('moment'));
8+
} else {
9+
// Browser globals (root is window)
10+
factory(root.moment);
11+
}
12+
}(this, function(moment) {
213

314
function Timer(duration, attributes, callback) {
415
this.timerDuration = duration;
@@ -8,7 +19,7 @@
819
this.stopped = false; // If stop() is called this variable will be used to finish the paused duration once it's started again.
920
this.timer;
1021
this.startTick;
11-
this.endTick;
22+
this.endTick;
1223

1324
if (attributes.start) {
1425
if (attributes.wait > 0) {
@@ -52,7 +63,7 @@
5263
return self.callback();
5364
}, this.timerDuration);
5465
}
55-
66+
5667
this.updateStartEndTickFromDuration(self.timerDuration);
5768
this.started = true;
5869

@@ -102,7 +113,7 @@
102113
this.start();
103114
return true;
104115
}
105-
116+
106117
return false;
107118
}
108119

@@ -125,14 +136,14 @@
125136
Timer.prototype.isStopped = function () {
126137
return this.stopped;
127138
}
128-
139+
129140
// define internal moment reference
130141
var moment;
131142

132143
if (typeof require === "function") {
133-
try { moment = require('moment'); }
144+
try { moment = require('moment'); }
134145
catch (e) {}
135-
}
146+
}
136147

137148
if (!moment && this.moment) {
138149
moment = this.moment;
@@ -157,8 +168,10 @@
157168
} else {
158169
throw new Error("First argument must be of type function or object.");
159170
}
160-
161-
return new Timer(this.asMilliseconds(), attributes, callback);
171+
172+
return (function() {
173+
return new Timer(this.asMilliseconds(), attributes, callback);
174+
}.bind(this))();
162175
};
163176

164-
})(this);
177+
}));

0 commit comments

Comments
 (0)