-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.spin.js
76 lines (62 loc) · 1.58 KB
/
jquery.spin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Generated by CoffeeScript 1.6.3
/*
jQuery Spin
Copyright 2014 Kevin Sylvestre
1.1.6
*/
(function() {
"use strict";
var $, Spinner;
$ = jQuery;
Spinner = (function() {
Spinner.prototype.defaults = {
petals: 9
};
function Spinner($element, options) {
this.$element = $element;
this.options = $.extend({}, this.defaults, options);
this.configure();
}
Spinner.prototype.show = function() {
return this.$element.animate({
opacity: 1.0
});
};
Spinner.prototype.hide = function() {
return this.$element.animate({
opacity: 0.0
});
};
Spinner.prototype.destroy = function() {
this.$element.empty();
return this.$element.data('spin', void 0);
};
Spinner.prototype.configure = function() {
var $petal, i, _i, _ref, _results;
this.$element.empty();
_results = [];
for (i = _i = 0, _ref = this.options.petals; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
$petal = $("<div />");
_results.push(this.$element.append($petal));
}
return _results;
};
return Spinner;
})();
$.fn.spin = function(options) {
return $(this).each(function() {
var $this, spinner;
$this = $(this);
spinner = $this.data('spinner');
if (spinner == null) {
$this.data('spinner', spinner = new Spinner($this, options));
}
if (typeof options === 'string') {
return spinner[options]();
}
});
};
$(function() {
return $('[data-spin]').spin();
});
}).call(this);