forked from xpepermint/angular-ui-switch
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathangular-ui-switch.min.js
More file actions
1 lines (1 loc) · 1.3 KB
/
angular-ui-switch.min.js
File metadata and controls
1 lines (1 loc) · 1.3 KB
1
angular.module("uiSwitch",[]).directive("switch",function(){return{require:"ngModel",restrict:"AE",replace:!0,transclude:!0,scope:{isDisabled:"@",ngModel:"=",ngChange:"@"},controller:function($scope){$scope.updateSwitch=function(element){$scope.setElementStyle(element)},$scope.setElementStyle=function(element){$scope.ngModel?element.addClass("checked"):element.removeClass("checked")}},template:function(element,attrs){var html="";return html+="<span",html+=' class="switch'+(attrs["class"]?" "+attrs["class"]:"")+'"',html+=">",html+="<small></small>",html+='<input type="checkbox"',html+=attrs.id?' id="'+attrs.id+'"':"",html+=attrs.name?' name="'+attrs.name+'"':"",html+=attrs.ngModel?' ng-model="'+attrs.ngModel+'"':"",html+=' style="display:none" />',html+='<span class="switch-text">',html+=attrs.on?'<span class="on">'+attrs.on+"</span>":"",html+=attrs.off?'<span class="off">'+attrs.off+"</span>":" ",html+="</span>"},link:function($scope,element,attrs){$scope.setElementStyle(element),angular.isDefined(attrs.isDisabled)&&"false"!=attrs.isDisabled||(element.bind("click",function(){$scope.$apply(function(){$scope.ngModel=!$scope.ngModel}),$scope.ngChange&&$scope.$parent[$scope.ngChange]()}),$scope.$watch(function(){return $scope.ngModel},function(newValue,oldValue){newValue!=oldValue&&$scope.updateSwitch(element)}))}}});