app.js
1.46 KB
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
/**
* INSPINIA - Responsive Admin Theme
*
*/
(function () {
angular.module('inspinia', [
'ui.router', // Routing
'ui.bootstrap', // Bootstrap
'ngFileUpload' // File Upload
])
.directive('icheck', ['$timeout', '$parse', function($timeout, $parse) {
return {
restrict: 'A',
require: '?ngModel',
link: function(scope, element, attr, ngModel) {
$timeout(function() {
var value = attr.value;
function update(checked) {
if(attr.type==='radio') {
ngModel.$setViewValue(value);
} else {
ngModel.$setViewValue(checked);
}
}
$(element).iCheck({
checkboxClass: attr.checkboxClass || 'icheckbox_square-green',
radioClass: attr.radioClass || 'iradio_square-green'
}).on('ifChanged', function(e) {
scope.$apply(function() {
update(e.target.checked);
});
});
scope.$watch(attr.ngChecked, function(checked) {
if(typeof checked === 'undefined') checked = !!ngModel.$viewValue;
update(checked)
}, true);
scope.$watch(attr.ngModel, function(model) {
$(element).iCheck('update');
}, true);
})
}
}
}])
})();