9 lines
3.7 KiB
JavaScript
9 lines
3.7 KiB
JavaScript
/*
|
|
* Kendo UI v2015.3.1111 (http://www.telerik.com/kendo-ui)
|
|
* Copyright 2015 Telerik AD. All rights reserved.
|
|
*
|
|
* Kendo UI commercial licenses may be obtained at
|
|
* http://www.telerik.com/purchase/license-agreement/kendo-ui-complete
|
|
* If you do not own a commercial license, this file shall be governed by the trial license terms.
|
|
*/
|
|
!function(e,define){define(["./kendo.fx.min","./kendo.userevents.min"],e)}(function(){return function(e,t){function n(e,t,n){return Math.max(t,Math.min(n,e))}var i=window.kendo,o=i.mobile.ui,r=o.Widget,s=i.support,a="change",l="km-switch-on",c="km-switch-off",u="margin-left",d="km-state-active",h="km-state-disabled",f="disabled",p=s.transitions.css+"transform",g=e.proxy,m='<span class="km-switch km-widget"> <span class="km-switch-wrapper"><span class="km-switch-background"></span></span> <span class="km-switch-container"><span class="km-switch-handle" > <span class="km-switch-label-on">{0}</span> <span class="km-switch-label-off">{1}</span> </span> </span>',v=r.extend({init:function(t,n){var o,s=this;r.fn.init.call(s,t,n),n=s.options,s.wrapper=e(i.format(m,n.onLabel,n.offLabel)),s.handle=s.wrapper.find(".km-switch-handle"),s.background=s.wrapper.find(".km-switch-background"),s.wrapper.insertBefore(s.element).prepend(s.element),s._drag(),s.origin=parseInt(s.background.css(u),10),s.constrain=0,s.snapPoint=0,t=s.element[0],t.type="checkbox",s._animateBackground=!0,o=s.options.checked,null===o&&(o=t.checked),s.check(o),s.options.enable=s.options.enable&&!s.element.attr(f),s.enable(s.options.enable),s.refresh(),i.notify(s,i.mobile.ui)},refresh:function(){var e=this,t=e.handle.outerWidth(!0);e.width=e.wrapper.width(),e.constrain=e.width-t,e.snapPoint=e.constrain/2,"number"!=typeof e.origin&&(e.origin=parseInt(e.background.css(u),10)),e.background.data("origin",e.origin),e.check(e.element[0].checked)},events:[a],options:{name:"Switch",onLabel:"on",offLabel:"off",checked:null,enable:!0},check:function(e){var n=this,i=n.element[0];return e===t?i.checked:(n._position(e?n.constrain:0),i.checked=e,n.wrapper.toggleClass(l,e).toggleClass(c,!e),t)},value:function(){return this.check.apply(this,arguments)},destroy:function(){r.fn.destroy.call(this),this.userEvents.destroy()},toggle:function(){var e=this;e.check(!e.element[0].checked)},enable:function(e){var n=this.element,i=this.wrapper;t===e&&(e=!0),this.options.enable=e,e?n.removeAttr(f):n.attr(f,f),i.toggleClass(h,!e)},_resize:function(){this.refresh()},_move:function(e){var t=this;e.preventDefault(),t._position(n(t.position+e.x.delta,0,t.width-t.handle.outerWidth(!0)))},_position:function(e){var t=this;t.position=e,t.handle.css(p,"translatex("+e+"px)"),t._animateBackground&&t.background.css(u,t.origin+e)},_start:function(){this.options.enable?(this.userEvents.capture(),this.handle.addClass(d)):this.userEvents.cancel()},_stop:function(){var e=this;e.handle.removeClass(d),e._toggle(e.position>e.snapPoint)},_toggle:function(e){var t,n=this,o=n.handle,r=n.element[0],s=r.checked,u=i.mobile.application&&i.mobile.application.os.wp?100:200;n.wrapper.toggleClass(l,e).toggleClass(c,!e),n.position=t=e*n.constrain,n._animateBackground&&n.background.kendoStop(!0,!0).kendoAnimate({effects:"slideMargin",offset:t,reset:!0,reverse:!e,axis:"left",duration:u}),o.kendoStop(!0,!0).kendoAnimate({effects:"slideTo",duration:u,offset:t+"px,0",reset:!0,complete:function(){s!==e&&(r.checked=e,n.trigger(a,{checked:e}))}})},_drag:function(){var e=this;e.userEvents=new i.UserEvents(e.wrapper,{tap:function(){e.options.enable&&e._toggle(!e.element[0].checked)},start:g(e._start,e),move:g(e._move,e),end:g(e._stop,e)})}});o.plugin(v)}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()}); |