forked from ericpanorel/indicated-angular-button
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindiClick.js
46 lines (44 loc) · 1.77 KB
/
indiClick.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
(function (Spinner) {
'use strict';
var directiveId = 'indiClick';
app.directive(directiveId, ['$parse', function ($parse) {
var directive = {
link: link,
restrict: 'A'
};
return directive;
function link(scope, element, attr) {
var fn = $parse(attr[directiveId]),
target = element[0];
element.on('click', function (event) {
scope.$apply(function () {
var height = element.height(),
oldWidth = element.width(),
opts = {
length: Math.round(height / 3),
radius: Math.round(height / 5),
width: Math.round(height / 10),
color: element.css("color"),
left: -5
}; // customize this "resizing and coloring" algorithm
attr.$set('disabled', true);
element.width(oldWidth + oldWidth / 2); // make room for spinner
var spinner = new Spinner(opts).spin(target);
// expects a promise
// http://docs.angularjs.org/api/ng.$q
fn(scope, { $event: event })
.then(function (res) {
element.width(oldWidth); // restore size
attr.$set('disabled', false);
spinner.stop();
return res;
}, function (res) {
element.width(oldWidth); // restore size
attr.$set('disabled', false);
spinner.stop();
});
});
});
}
}]);
})(Spinner);