mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-12 23:09:03 +01:00
9 lines
2.9 KiB
JavaScript
9 lines
2.9 KiB
JavaScript
/**
|
|
* angular-bootstrap-switch
|
|
* @version v0.4.0 - 2015-04-13
|
|
* @author Francesco Pontillo (francescopontillo@gmail.com)
|
|
* @link https://github.com/frapontillo/angular-bootstrap-switch
|
|
* @license Apache License 2.0(http://www.apache.org/licenses/LICENSE-2.0.html)
|
|
**/
|
|
|
|
!function(){"use strict";angular.module("frapontillo.bootstrap-switch",[]),angular.module("frapontillo.bootstrap-switch").directive("bsSwitch",["$parse","$timeout",function(a,b){return{restrict:"A",require:"ngModel",link:function(c,d,e,f){var g=!1,h=function(){if("radio"===e.type)return e.value||a(e.ngValue)(c)||!0;var b=a(e.ngTrueValue)(c);return angular.isString(b)||(b=!0),b},i=function(a){return c.$eval(a)===!0},j=function(a){return a===!0||"true"===a||!a},k=function(a){return a?a:void 0},l=function(a){var b={switchRadioOff:j,switchActive:function(a){return!j(a)},switchAnimate:j,switchLabel:function(a){return a?a:" "},switchIcon:function(a){return a?"<span class='"+a+"'></span>":void 0},switchWrapper:function(a){return a||"wrapper"},switchInverse:i,switchReadonly:i},c=b[a]||k;return c(e[a])},m=function(a,b,c){if(g){var d=l(c);a.bootstrapSwitch(b,d)}},n=function(){m(d,"disabled","switchActive")},o=function(){if(!g){var a=f.$modelValue===h();g=!g,d.bootstrapSwitch({radioAllOff:l("switchRadioOff"),disabled:l("switchActive"),state:a,onText:l("switchOnText"),offText:l("switchOffText"),onColor:l("switchOnColor"),offColor:l("switchOffColor"),animate:l("switchAnimate"),size:l("switchSize"),labelText:l(e.switchLabel?"switchLabel":"switchIcon"),wrapperClass:l("switchWrapper"),handleWidth:l("switchHandleWidth"),labelWidth:l("switchLabelWidth"),inverse:l("switchInverse"),readonly:l("switchReadonly")}),f.$setViewValue("radio"===e.type?f.$modelValue:a)}},p=function(){function a(){return f.$modelValue}e.$observe("switchActive",function(a){var c=j(a);c?n(c):b(function(){n(c)})}),c.$watch(a,function(a){o(),void 0!==a&&d.bootstrapSwitch("state",a===h(),!1)},!0);var g={switchRadioOff:"radioAllOff",switchOnText:"onText",switchOffText:"offText",switchOnColor:"onColor",switchOffColor:"offColor",switchAnimate:"animate",switchSize:"size",switchLabel:"labelText",switchIcon:"labelText",switchWrapper:"wrapperClass",switchHandleWidth:"handleWidth",switchLabelWidth:"labelWidth",switchInverse:"inverse",switchReadonly:"readonly"},i=function(a,b){return function(){e.$observe(a,function(){m(d,b[a],a)})}};for(var k in g)e.$observe(k,i(k,g))},q=function(){"radio"===e.type?d.on("change.bootstrapSwitch",function(a){f.$modelValue===f.$viewValue&&a.target.checked!==$(a.target).bootstrapSwitch("state")&&(a.target.checked?f.$setViewValue(h()):h()===f.$viewValue&&f.$setViewValue(void 0))}):d.on("switchChange.bootstrapSwitch",function(a){f.$setViewValue(a.target.checked)})};q(),p(),c.$on("$destroy",function(){d.bootstrapSwitch("destroy")})}}}]).directive("bsSwitch",function(){return{restrict:"E",require:"ngModel",template:"<input bs-switch>",replace:!0}})}(); |