forked from cgarvis/angular-toggle-switch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-toggle-switch.js
More file actions
27 lines (27 loc) · 1.02 KB
/
angular-toggle-switch.js
File metadata and controls
27 lines (27 loc) · 1.02 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
angular.module('toggle-switch', ['ng']).directive('toggleSwitch', function () {
return {
restrict: 'EA',
replace: true,
scope: {
model: '=',
disabled: '@',
onLabel: '@',
offLabel: '@',
knobLabel: '@'
},
template: '<div class="switch" ng-click="toggle()" ng-class="{ \'disabled\': disabled }"><div class="switch-animate" ng-class="{\'switch-off\': !model, \'switch-on\': model}"><span class="switch-left" ng-bind="onLabel"></span><span class="knob" ng-bind="knobLabel"></span><span class="switch-right" ng-bind="offLabel"></span></div></div>',
controller: function($scope) {
$scope.toggle = function toggle() {
if(!$scope.disabled) {
$scope.model = !$scope.model;
}
};
},
compile: function(element, attrs) {
if (!attrs.onLabel) { attrs.onLabel = 'On'; }
if (!attrs.offLabel) { attrs.offLabel = 'Off'; }
if (!attrs.knobLabel) { attrs.knobLabel = '\u00a0'; }
if (!attrs.disabled) { attrs.disabled = false; }
},
};
});