(function(){function h(a,b,c,d,f){!a||3!==a.nodeType&&8!==a.nodeType||(a=a.parentNode);var e=f;e||(e={sx:0,sy:0,cx:0,cy:0});f=document.createEvent("MouseEvent");f.initMouseEvent(b,!0,!0,window,1,d.screenX+e.sx,d.screenY+e.sy,d.clientX+e.cx,d.clientY+e.cy,!1,!1,!1,!1,c,null);b=jq.event.props;c=jq.Event(f);b.push("button","charCode","clientX","clientY","detail","fromElement","keyCode","layerX","layerY","offsetX","offsetY","pageX","pageY","screenX","screenY","srcElement","toElement");for(d=b.length;d;)e=
b[--d],c[e]=f[e];c.target=a;return c}function m(a,b){switch(a.type){case "touchstart":return h(b.target,"mousedown",0,b);case "touchend":return h(document.elementFromPoint(b.clientX,b.clientY),"mouseup",0,b);case "touchmove":return(a=document.elementFromPoint(b.clientX,b.clientY))&&h(a,"mousemove",0,b)||null}return a}function k(a){var b=a.originalEvent;if(!(1<b.touches.length)&&(b=m(a,b.changedTouches[0]))){var c=a.type,d=jq.data(a.currentTarget,"zk_eventFuncs"),f;b.touchEvent=a.originalEvent;if(d&&
(f=d[c]))for(a=0,c=f.length;a<c;a++)f[a](b)}}zk.copy(zjq,{eventTypes:{zmousedown:"touchstart",zmouseup:"touchend",zmousemove:"touchmove"}});zk.override(zk.Widget.prototype,{},{bindSwipe_:function(){var a=this.$n();if(this.isListen("onSwipe")||jq(a).data("swipeable"))this._swipe=new zk.Swipe(this,a)},unbindSwipe_:function(){var a=this._swipe;a&&(this._swipe=null,a.destroy(this.$n()))},bindDoubleTap_:function(){this.isListen("onDoubleClick")&&(this._startTap=function(a){a._lastTap=a.$n();a._tapValid=
!0;a._tapTimeout=setTimeout(function(){a._tapValid=!1},500)},jq(this.$n()).bind("touchstart",this.proxy(this._dblTapStart)).bind("touchend",this.proxy(this._dblTapEnd)))},unbindDoubleTap_:function(){this.isListen("onDoubleClick")&&(this._startTap=null,jq(this.$n()).unbind("touchstart",this.proxy(this._dblTapStart)).unbind("touchend",this.proxy(this._dblTapEnd)))},_dblTapStart:function(a){var b=a.originalEvent;1<b.touches.length||(this._tapValid?(clearTimeout(this._tapTimeout),this._tapTimeout=null,
this.$n()==this._lastTap?this._dbTap=!0:this._startTap(this)):this._startTap(this),a=zk.Widget.$(a.target).parent,!a||zk.isLoaded("zul.grid")&&a.$instanceof(zul.grid.Row)||zk.isLoaded("zul.sel")&&(a.$instanceof(zul.sel.Listitem)||a.$instanceof(zul.sel.Treerow))||b.stopPropagation())},_dblTapEnd:function(a){var b=a.originalEvent;if(!(1<b.touches.length)&&this._dbTap){this._dbTap=this._tapValid=this._lastTap=null;var c=b.changedTouches[0];a=new zk.Event(this,"onDoubleClick",{pageX:c.clientX,pageY:c.clientY},
{},a);this.$weave||(a.stopped||this.doDoubleClick_.call(this,a),a.domStopped&&a.domEvent.stop());b.preventDefault()}},bindTapHold_:function(){if(this.isListen("onRightClick")||this.getContext&&this.getContext())this._holdTime=800,this._startHold=function(a){this._rightClickPending||(self=this,self._rightClickPending=!0,self._rightClickEvent=a,self._holdTimeout=setTimeout(function(){self._rightClickPending=!1;var a=new zk.Event(self,"onRightClick",{pageX:self._pt[0],pageY:self._pt[1]},{},self._rightClickEvent);
self.$weave||(a.stopped||self.doRightClick_.call(self,a),a.domStopped&&a.domEvent.stop());self._cancelMouseUp=!0;self._rightClickEvent=null},self._holdTime))},this._cancelHold=function(){this._rightClickPending&&(this._rightClickPending=!1,this._rightClickEvent=null,clearTimeout(this._holdTimeout),this._holdTimeout=null)},jq(this.$n()).bind("touchstart",this.proxy(this._tapHoldStart)).bind("touchmove",this.proxy(this._tapHoldMove)).bind("click",this.proxy(this._tapHoldClick)).bind("touchend",this.proxy(this._tapHoldEnd))},
unbindTapHold_:function(){if(this.isListen("onRightClick")||this.getContext&&this.getContext())this._startHold=this._cancelHold=null,jq(this.$n()).unbind("touchstart",this.proxy(this._tapHoldStart)).unbind("touchmove",this.proxy(this._tapHoldMove)).unbind("click",this.proxy(this._tapHoldClick)).unbind("touchend",this.proxy(this._tapHoldEnd))},_tapHoldStart:function(a){var b=a.originalEvent;if(!(1<b.touches.length)){var c=b.changedTouches[0];this._pt=[c.clientX,c.clientY];this._startHold(a);a=zk.Widget.$(a.target).parent;
!a||zk.isLoaded("zul.grid")&&a.$instanceof(zul.grid.Row)||zk.isLoaded("zul.sel")&&(a.$instanceof(zul.sel.Listitem)||a.$instanceof(zul.sel.Treerow))||b.stopPropagation()}},_tapHoldMove:function(a){a=a.originalEvent;1<a.touches.length||!this._pt||(a=a.changedTouches[0],(3<Math.abs(a.clientX-this._pt[0])||3<Math.abs(a.clientY-this._pt[1]))&&this._cancelHold())},_tapHoldClick:function(a){if(this._cancelClick){if(100>zUtl.now()-this._cancelClick)return a.stopImmediatePropagation(),!1;this._cancelClick=
null}},_tapHoldEnd:function(a){if(!(1<a.originalEvent.touches.length)){if(this._cancelMouseUp)return this._cancelClick=zUtl.now(),this._cancelMouseUp=!1,a.stopImmediatePropagation(),!1;this._cancelHold()}}});var l={};zk.override(jq.fn,{},{bind:function(a,b,c){var d;if(d=zjq.eventTypes[a]){if(jq.isFunction(b)||!1===b)c=b,b=void 0;var f=this[0];var e=c;var g=jq.data(f,"zk_eventFuncs");g||(g={},jq.data(f,"zk_eventFuncs",g));(f=g[d])?(f.push(e),e=!1):(g[d]=[e],e=!0);e&&this.zbind(d,b,k)}else this.zbind.apply(this,
arguments);return this},unbind:function(a,b){var c;if(c=zjq.eventTypes[a]){a:{var d=this[0];var f=b,e=jq.data(d,"zk_eventFuncs"),g;if(e&&(g=e[c])&&(g.$remove(f),!g.length)){delete e[c];for(var h in e)if(h){d=!0;break a}jq.removeData(d,"zk_eventFuncs");d=!0;break a}d=void 0}d&&this.zunbind(c,k)}else this.zunbind.apply(this,arguments);return this}});zk.override(jq.Event.prototype,l,{stop:function(){l.stop.apply(this);var a;if(a=this.touchEvent)a.preventDefault(),a.stopPropagation()}})})();
