-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfui-switch.js
48 lines (40 loc) · 1.35 KB
/
fui-switch.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
'use strict';
/**
* @ngdoc directive
* @name fui.switch.directive:fuiSwitch
* @description
* # fuiSwitch
*/
angular.module('fui.switch',[])
.directive('fuiSwitch', function () {
return {
restrict: 'E',
templateUrl: 'views/directive_templates/fui-switch.html',
replace: true,
scope: {
ngModel: '=',
ngValue: '=',
ngDisabled: '=',
ngRequired: '='
},
link: function (scope, element, attrs) {
scope.toggle = function toggle() {
return (scope.ngModel = scope.ngDisabled && scope.ngModel || !scope.ngDisabled && !scope.ngModel);
};
scope.name = attrs.name;
scope.onText = attrs.onText || 'ON';
scope.offText = attrs.offText || 'OFF';
scope.switchOnColor = 'bootstrap-switch-warning';
if (!!attrs.onColor) {
scope.switchOnColor = 'bootstrap-switch-'+attrs.onColor;
} else {
scope.switchOnColor = 'bootstrap-switch-primary';
}
if (!!attrs.offColor) {
scope.switchOffColor = 'bootstrap-switch-'+attrs.offColor;
} else {
scope.switchOffColor = 'bootstrap-switch-default';
}
}
};
});