You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
1.0 KiB
25 lines
1.0 KiB
angular.module('uiSwitch', [])
|
|
|
|
.directive('switch', function(){
|
|
return {
|
|
restrict: 'AE'
|
|
, replace: true
|
|
, transclude: true
|
|
, template: function(element, attrs) {
|
|
var html = '';
|
|
html += '<span';
|
|
html += ' class="switch' + (attrs.class ? ' ' + attrs.class : '') + '"';
|
|
html += attrs.ngModel ? ' ng-click="' + attrs.disabled + ' ? ' + attrs.ngModel + ' : ' + (attrs.ngModel+ '!=' +attrs.on+ '?' +attrs.ngModel+ '=' +attrs.on+ ':' +attrs.ngModel+ '=' +attrs.off )+ (attrs.ngChange ? '; ' + attrs.ngChange + '()"' : '"') : '';
|
|
html += ' ng-class="{ checked:' + attrs.ngModel+'=='+attrs.on + ', disabled:' + attrs.disabled + ' }"';
|
|
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" />';
|
|
|
|
return html;
|
|
}
|
|
}
|
|
});
|