16 lines
4.0 KiB
JavaScript
16 lines
4.0 KiB
JavaScript
/**
|
|
* Copyright 2014 Telerik AD
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
!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,r=i.mobile.ui,o=r.Widget,a=i.support,s="change",l="km-switch-on",d="km-switch-off",c="margin-left",u="km-state-active",h="km-state-disabled",p="disabled",f=a.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=o.extend({init:function(t,n){var r,a=this;o.fn.init.call(a,t,n),n=a.options,a.wrapper=e(i.format(m,n.onLabel,n.offLabel)),a.handle=a.wrapper.find(".km-switch-handle"),a.background=a.wrapper.find(".km-switch-background"),a.wrapper.insertBefore(a.element).prepend(a.element),a._drag(),a.origin=parseInt(a.background.css(c),10),a.constrain=0,a.snapPoint=0,t=a.element[0],t.type="checkbox",a._animateBackground=!0,r=a.options.checked,null===r&&(r=t.checked),a.check(r),a.options.enable=a.options.enable&&!a.element.attr(p),a.enable(a.options.enable),a.refresh(),i.notify(a,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(c),10)),e.background.data("origin",e.origin),e.check(e.element[0].checked)},events:[s],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(d,!e),t)},value:function(){return this.check.apply(this,arguments)},destroy:function(){o.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(p):n.attr(p,p),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(f,"translatex("+e+"px)"),t._animateBackground&&t.background.css(c,t.origin+e)},_start:function(){this.options.enable?(this.userEvents.capture(),this.handle.addClass(u)):this.userEvents.cancel()},_stop:function(){var e=this;e.handle.removeClass(u),e._toggle(e.position>e.snapPoint)},_toggle:function(e){var t,n=this,r=n.handle,o=n.element[0],a=o.checked,c=i.mobile.application&&i.mobile.application.os.wp?100:200;n.wrapper.toggleClass(l,e).toggleClass(d,!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:c}),r.kendoStop(!0,!0).kendoAnimate({effects:"slideTo",duration:c,offset:t+"px,0",reset:!0,complete:function(){a!==e&&(o.checked=e,n.trigger(s,{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)})}});r.plugin(v)}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()}); |