(function(){"use strict";var t={transformend:"touch",touchdrag:"drag",touch:"touch",transformstart:"transform"};function s(s,i){function n(t,s){this._$el=t;i.extend(this,n.defaults,s);if(this.zone=="this"){this._$zone=this._$el}else{this._$zone=this.zone||this._$el.parent()}this._defaults=this.get();this._update=this._update.bind(this);this.update(this.get());this._$zone.on("mousewheel.transformable",this._onMouseWheel.bind(this)).on("transformstart.transformable",{options:{prevent_default:true,stop_browser_behavior:{touchAction:"pinch-zoom"}}},this._onTransformStart.bind(this)).on("touch.transformable",this._onTouch.bind(this)).on("release.transformable",this._onRelease.bind(this));$$(this._$zone[0].ownerDocument).on("touchdrag.transformable",this._onDrag.bind(this));this._disabled=false}n.defaults={scale:1,x:0,y:0,rotate:0,canTranslate:true,canScale:true,canRotate:true};i.extend(n.prototype,{dispose:function(){if(this._isDisposed){return}this._isDisposed=true;this._unbind();this._$zone.off(".transformable")},get:function(){return{x:this.x,y:this.y,scale:this.scale,rotate:this.rotate}},update:function(t){if(typeof t=="string"){var i=this[t];if(typeof i=="function"){var n=Array.prototype.slice.call(arguments,1);return i.apply(this,n)}return i}else if(t&&typeof t=="object"){var e=t.scale;if(!isNaN(e)&&this.canScale){e=Math.max(this.minScale||0,e);if("maxScale"in this){e=Math.min(this.maxScale,e)}this.scale=e}if(!isNaN(t.x)&&(this.canTranslate===true||this.canTranslate==="x")){this.x=t.x||0}if(!isNaN(t.y)&&(this.canTranslate===true||this.canTranslate==="y")){this.y=t.y||0}if(!isNaN(t.rotate)&&this.canRotate){this.rotate=t.rotate||0}if(!this._isUpdating){this._isUpdating=true;s.requestAnimationFrame(this._update.bind(this))}}},reset:function(){this.update(this._defaults)},start:function(){this._disabled=false},stop:function(){this._disabled=true},_bind:function(){if(this._isBound){return}this._$zone.on("transform.transforming",this._onTransform.bind(this)).on("transformend.transforming",this._onTransformEnd.bind(this));this._isBound=true},_unbind:function(){if(!this._isBound){return}this._isBound=false;this._$zone.off(".transforming",this._onTransform.bind(this))},_buildTransform:function(){return"translate("+this.x+"px,"+this.y+"px) scale("+this.scale+") rotate("+this.rotate+"deg)"},_update:function(){var t=this._buildTransform();this._$el.css("transform",t);if(typeof this.change=="function"){this.change(this)}this._isUpdating=false},_updateTransform:function(s){var i=this._transforming;var n=t[s.type]||"??";if(!i){i=this._transforming=this.get();i.type=n;this._$zone.addClass("transforming")}else if(n!=i.type){var e=s.gesture;i.x=this.x-e.deltaX;i.y=this.y-e.deltaY;i.type=n}return i},_endTransform:function(){if(this._transforming){this._transforming=null;this._$zone.removeClass("transforming");this._unbind()}},_onDrag:function(t){if(this._disabled){return}var s=this._transforming;if(!s){return}if(s.type=="transform"){return}if(s.type!="drag"){s=this._updateTransform(t)}var i=t.gesture;this.update({x:s.x+i.deltaX,y:s.y+i.deltaY})},_onTransform:function(t){if(this._disabled){return}var s=this._transforming,i=t.gesture;if(!s||!i){return}this.update({scale:s.scale+i.scale-1,x:s.x+i.deltaX,y:s.y+i.deltaY,rotate:s.rotate+i.rotation})},_onTransformEnd:function(t){if(this._disabled){return}this._updateTransform(t)},_onTransformStart:function(t){if(this._disabled){return}this._updateTransform(t);this._bind()},_onTouch:function(t){if(this._disabled){return}this._updateTransform(t)},_onRelease:function(){if(this._disabled){return}this._endTransform()},_onMouseWheel:function(t){if(this._disabled||!this.zoomWithMouseWheel){return}t.preventDefault();var s=this.scale+.1*t.delta;this.update({scale:s})}});return function(t){var s;this.each(function(){var e=i(this);var a=e.data("transformable");if(t===null||t=="dispose"){if(a){e.data("transformable",null);a.dispose()}}else if(!a){e.data("transformable",new n(e,t))}else{s=a.update(t)}});if(typeof s!="undefined"){return s}return this}}u8.Base._Window.extend("jquery.transformable",function(t){var i=t.$;if(i){i.fn.transformable=s(t,i)}})})();