-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-dimmer.js
80 lines (74 loc) · 2.76 KB
/
angular-dimmer.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
77
78
79
80
/**
* angular-dimmer v1.0
*
* Copyright (c) 2014 Yuthasak Tanruengsri [email protected]
* https://github.com/ytanruengsri/angular-dimmer
*
* License: MIT
*/
'use strict';
angular.module('dimmerModule', [])
.constant('$dimmerConstant', {
'defaultZIndex': 20000,
'defaultOption': {
lines: 13, // The number of lines to draw
length: 20, // The length of each line
width: 10, // The line thickness
radius: 30, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 0, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#FFF', // #rgb or #rrggbb or array of colors
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: '50%', // Top position relative to parent
left: '50%' // Left position relative to parent
}
})
.factory('$dimmer', [function () {
var elem = null;
return {
/* ============ SETTER FN ============*/
setElement: function(element) {
elem = element;
},
show: function() {
elem.css('display', 'block');
},
hide: function() {
elem.css('display', 'none');
}
};
}])
.directive('dimmer', ['$dimmerConstant', '$dimmer',
function($dimmerConstant, $dimmer) {
return {
restrict: 'E',
replace: true,
scope: {
zIndex: '='
},
template:
'<div class="dimmer">' +
' <div class="content">' +
' <div class="center">' +
' <div class="loading"></div>' +
' </div>' +
' </div>' +
'</div>',
link: function(scope, elem) {
$dimmer.setElement(elem);
var zIndex = angular.isDefined(scope.zIndex) ? scope.zIndex : $dimmerConstant.defaultZIndex;
elem.css('zIndex', zIndex);
var spinner = new Spinner($dimmerConstant.defaultOption).spin(elem[0]);
scope.$on('$destroy', function() {
spinner.stop();
elem.remove();
});
}
};
}]);