Skip to content

Commit 082057a

Browse files
committed
added AMD
1 parent c4b2d07 commit 082057a

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "jQuery.counter",
3+
"author": "sophilabs <contact@sophilabs.com>",
4+
"homepage": "http://sophilabs.github.com/jquery-counter/",
5+
"version": "0.2",
6+
"description": "A jQuery Counter Plugin.",
7+
"keywords": [
8+
"countdown",
9+
"counter"
10+
],
11+
"licenses": [
12+
{
13+
"type": "MIT",
14+
"url": "http://www.opensource.org/licenses/mit-license.php"
15+
}
16+
],
17+
"repository": {
18+
"type": "git",
19+
"url": "https://github.com/sophilabs/jquery-counter.git"
20+
},
21+
"dependencies": {
22+
"jquery": ">= 1.7"
23+
},
24+
"devDependencies": {}
25+
}

src/jquery.counter.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
* Copyright (c) 2012 Sophilabs <contact@sophilabs.com>
55
* MIT License
66
*/
7+
8+
!(function (context, definition) {
9+
if (typeof define == 'function' && typeof define.amd == 'object') define(['jquery'], definition);
10+
else definition(context['$']);
11+
}(this, function ($) {
712

8-
(function($){
913
$.fn.counter = function(options) {
1014

1115
options = options || {};
@@ -29,8 +33,8 @@
2933
part.value += data.down ? -1 : 1;
3034
if (data.down && part.value < 0) {
3135
part.value = part.limit;
32-
} else if (!data.down && part.value > part.limit) {
33-
part.value = 0;
36+
} else if (!data.down && part.value > part.limit) {
37+
part.value = 0;
3438
} else {
3539
break;
3640
}
@@ -53,14 +57,14 @@
5357
digits = '0' + digits;
5458
}
5559
$.each(digits.split(''), function(j, digit) {
56-
animate(e, i, j, digit)
60+
animate(e, i, j, digit);
5761
});
5862
i--;
5963
}
6064
};
6165

6266
var animate = function(e, ipart, idigit, digit) {
63-
var edigit = $($(e.children().get(ipart)).find('span.digit').get(idigit));
67+
var edigit = $($(e.children('span.part').get(ipart)).find('span.digit').get(idigit));
6468
edigit.attr('class', 'digit digit' + digit + ' digit' + edigit.text() + digit).text(digit);
6569
};
6670

@@ -72,7 +76,7 @@
7276
data.parts = [];
7377
var initial = (options.initial || e.text()).split(/([^0-9]+)/);
7478
//WARN: Use attr() no data()
75-
var format = (options.format || e.attr('data-format') ||"23:59:59").split(/([^0-9]+)/);
79+
var format = (options.format || e.attr('data-format') || "23:59:59").split(/([^0-9]+)/);
7680
var stop = options.stop || e.attr('data-stop');
7781
if (stop) {
7882
stop = stop.split(/([^0-9]+)/);
@@ -112,4 +116,4 @@
112116
return this;
113117
});
114118
};
115-
})(jQuery);
119+
}));

0 commit comments

Comments
 (0)