/*! * @fileoverview touchswipe - jquery plugin * @version 1.6.18 * * @author matt bryson http://www.github.com/mattbryson * @see https://github.com/mattbryson/touchswipe-jquery-plugin * @see http://labs.rampinteractive.co.uk/touchswipe/ * @see http://plugins.jquery.com/project/touchswipe * @license * copyright (c) 2010-2015 matt bryson * dual licensed under the mit or gpl version 2 licenses. * */ !function(factory){"function"==typeof define&&define.amd&&define.amd.jquery?define(["jquery"],factory):factory("undefined"!=typeof module&&module.exports?require("jquery"):jquery)}(function($){"use strict";function init(options){return!options||void 0!==options.allowpagescroll||void 0===options.swipe&&void 0===options.swipestatus||(options.allowpagescroll=none),void 0!==options.click&&void 0===options.tap&&(options.tap=options.click),options||(options={}),options=$.extend({},$.fn.swipe.defaults,options),this.each(function(){var $this=$(this),plugin=$this.data(plugin_ns);plugin||(plugin=new touchswipe(this,options),$this.data(plugin_ns,plugin))})}function touchswipe(element,options){function touchstart(jqevent){if(!(gettouchinprogress()||$(jqevent.target).closest(options.excludedelements,$element).length>0)){var event=jqevent.originalevent?jqevent.originalevent:jqevent;if(!event.pointertype||"mouse"!=event.pointertype||0!=options.fallbacktomouseevents){var ret,touches=event.touches,evt=touches?touches[0]:event;return phase=phase_start,touches?fingercount=touches.length:options.preventdefaultevents!==!1&&jqevent.preventdefault(),distance=0,direction=null,currentdirection=null,pinchdirection=null,duration=0,starttouchesdistance=0,endtouchesdistance=0,pinchzoom=1,pinchdistance=0,maximumsmap=createmaximumsdata(),cancelmultifingerrelease(),createfingerdata(0,evt),!touches||fingercount===options.fingers||options.fingers===all_fingers||haspinches()?(starttime=gettimestamp(),2==fingercount&&(createfingerdata(1,touches[1]),starttouchesdistance=endtouchesdistance=calculatetouchesdistance(fingerdata[0].start,fingerdata[1].start)),(options.swipestatus||options.pinchstatus)&&(ret=triggerhandler(event,phase))):ret=!1,ret===!1?(phase=phase_cancel,triggerhandler(event,phase),ret):(options.hold&&(holdtimeout=settimeout($.proxy(function(){$element.trigger("hold",[event.target]),options.hold&&(ret=options.hold.call($element,event,event.target))},this),options.longtapthreshold)),settouchinprogress(!0),null)}}}function touchmove(jqevent){var event=jqevent.originalevent?jqevent.originalevent:jqevent;if(phase!==phase_end&&phase!==phase_cancel&&!inmultifingerrelease()){var ret,touches=event.touches,evt=touches?touches[0]:event,currentfinger=updatefingerdata(evt);if(endtime=gettimestamp(),touches&&(fingercount=touches.length),options.hold&&cleartimeout(holdtimeout),phase=phase_move,2==fingercount&&(0==starttouchesdistance?(createfingerdata(1,touches[1]),starttouchesdistance=endtouchesdistance=calculatetouchesdistance(fingerdata[0].start,fingerdata[1].start)):(updatefingerdata(touches[1]),endtouchesdistance=calculatetouchesdistance(fingerdata[0].end,fingerdata[1].end),pinchdirection=calculatepinchdirection(fingerdata[0].end,fingerdata[1].end)),pinchzoom=calculatepinchzoom(starttouchesdistance,endtouchesdistance),pinchdistance=math.abs(starttouchesdistance-endtouchesdistance)),fingercount===options.fingers||options.fingers===all_fingers||!touches||haspinches()){if(direction=calculatedirection(currentfinger.start,currentfinger.end),currentdirection=calculatedirection(currentfinger.last,currentfinger.end),validatedefaultevent(jqevent,currentdirection),distance=calculatedistance(currentfinger.start,currentfinger.end),duration=calculateduration(),setmaxdistance(direction,distance),ret=triggerhandler(event,phase),!options.triggerontouchend||options.triggerontouchleave){var inbounds=!0;if(options.triggerontouchleave){var bounds=getbounds(this);inbounds=isinbounds(currentfinger.end,bounds)}!options.triggerontouchend&&inbounds?phase=getnextphase(phase_move):options.triggerontouchleave&&!inbounds&&(phase=getnextphase(phase_end)),phase!=phase_cancel&&phase!=phase_end||triggerhandler(event,phase)}}else phase=phase_cancel,triggerhandler(event,phase);ret===!1&&(phase=phase_cancel,triggerhandler(event,phase))}}function touchend(jqevent){var event=jqevent.originalevent?jqevent.originalevent:jqevent,touches=event.touches;if(touches){if(touches.length&&!inmultifingerrelease())return startmultifingerrelease(event),!0;if(touches.length&&inmultifingerrelease())return!0}return inmultifingerrelease()&&(fingercount=fingercountatrelease),endtime=gettimestamp(),duration=calculateduration(),didswipebacktocancel()||!validateswipedistance()?(phase=phase_cancel,triggerhandler(event,phase)):options.triggerontouchend||options.triggerontouchend===!1&&phase===phase_move?(options.preventdefaultevents!==!1&&jqevent.preventdefault(),phase=phase_end,triggerhandler(event,phase)):!options.triggerontouchend&&hastap()?(phase=phase_end,triggerhandlerforgesture(event,phase,tap)):phase===phase_move&&(phase=phase_cancel,triggerhandler(event,phase)),settouchinprogress(!1),null}function touchcancel(){fingercount=0,endtime=0,starttime=0,starttouchesdistance=0,endtouchesdistance=0,pinchzoom=1,cancelmultifingerrelease(),settouchinprogress(!1)}function touchleave(jqevent){var event=jqevent.originalevent?jqevent.originalevent:jqevent;options.triggerontouchleave&&(phase=getnextphase(phase_end),triggerhandler(event,phase))}function removelisteners(){$element.unbind(start_ev,touchstart),$element.unbind(cancel_ev,touchcancel),$element.unbind(move_ev,touchmove),$element.unbind(end_ev,touchend),leave_ev&&$element.unbind(leave_ev,touchleave),settouchinprogress(!1)}function getnextphase(currentphase){var nextphase=currentphase,validtime=validateswipetime(),validdistance=validateswipedistance(),didcancel=didswipebacktocancel();return!validtime||didcancel?nextphase=phase_cancel:!validdistance||currentphase!=phase_move||options.triggerontouchend&&!options.triggerontouchleave?!validdistance&¤tphase==phase_end&&options.triggerontouchleave&&(nextphase=phase_cancel):nextphase=phase_end,nextphase}function triggerhandler(event,phase){var ret,touches=event.touches;return(didswipe()||hasswipes())&&(ret=triggerhandlerforgesture(event,phase,swipe)),(didpinch()||haspinches())&&ret!==!1&&(ret=triggerhandlerforgesture(event,phase,pinch)),diddoubletap()&&ret!==!1?ret=triggerhandlerforgesture(event,phase,double_tap):didlongtap()&&ret!==!1?ret=triggerhandlerforgesture(event,phase,long_tap):didtap()&&ret!==!1&&(ret=triggerhandlerforgesture(event,phase,tap)),phase===phase_cancel&&touchcancel(event),phase===phase_end&&(touches?touches.length||touchcancel(event):touchcancel(event)),ret}function triggerhandlerforgesture(event,phase,gesture){var ret;if(gesture==swipe){if($element.trigger("swipestatus",[phase,direction||null,distance||0,duration||0,fingercount,fingerdata,currentdirection]),options.swipestatus&&(ret=options.swipestatus.call($element,event,phase,direction||null,distance||0,duration||0,fingercount,fingerdata,currentdirection),ret===!1))return!1;if(phase==phase_end&&validateswipe()){if(cleartimeout(singletaptimeout),cleartimeout(holdtimeout),$element.trigger("swipe",[direction,distance,duration,fingercount,fingerdata,currentdirection]),options.swipe&&(ret=options.swipe.call($element,event,direction,distance,duration,fingercount,fingerdata,currentdirection),ret===!1))return!1;switch(direction){case left:$element.trigger("swipeleft",[direction,distance,duration,fingercount,fingerdata,currentdirection]),options.swipeleft&&(ret=options.swipeleft.call($element,event,direction,distance,duration,fingercount,fingerdata,currentdirection));break;case right:$element.trigger("swiperight",[direction,distance,duration,fingercount,fingerdata,currentdirection]),options.swiperight&&(ret=options.swiperight.call($element,event,direction,distance,duration,fingercount,fingerdata,currentdirection));break;case up:$element.trigger("swipeup",[direction,distance,duration,fingercount,fingerdata,currentdirection]),options.swipeup&&(ret=options.swipeup.call($element,event,direction,distance,duration,fingercount,fingerdata,currentdirection));break;case down:$element.trigger("swipedown",[direction,distance,duration,fingercount,fingerdata,currentdirection]),options.swipedown&&(ret=options.swipedown.call($element,event,direction,distance,duration,fingercount,fingerdata,currentdirection))}}}if(gesture==pinch){if($element.trigger("pinchstatus",[phase,pinchdirection||null,pinchdistance||0,duration||0,fingercount,pinchzoom,fingerdata]),options.pinchstatus&&(ret=options.pinchstatus.call($element,event,phase,pinchdirection||null,pinchdistance||0,duration||0,fingercount,pinchzoom,fingerdata),ret===!1))return!1;if(phase==phase_end&&validatepinch())switch(pinchdirection){case in:$element.trigger("pinchin",[pinchdirection||null,pinchdistance||0,duration||0,fingercount,pinchzoom,fingerdata]),options.pinchin&&(ret=options.pinchin.call($element,event,pinchdirection||null,pinchdistance||0,duration||0,fingercount,pinchzoom,fingerdata));break;case out:$element.trigger("pinchout",[pinchdirection||null,pinchdistance||0,duration||0,fingercount,pinchzoom,fingerdata]),options.pinchout&&(ret=options.pinchout.call($element,event,pinchdirection||null,pinchdistance||0,duration||0,fingercount,pinchzoom,fingerdata))}}return gesture==tap?phase!==phase_cancel&&phase!==phase_end||(cleartimeout(singletaptimeout),cleartimeout(holdtimeout),hasdoubletap()&&!indoubletap()?(doubletapstarttime=gettimestamp(),singletaptimeout=settimeout($.proxy(function(){doubletapstarttime=null,$element.trigger("tap",[event.target]),options.tap&&(ret=options.tap.call($element,event,event.target))},this),options.doubletapthreshold)):(doubletapstarttime=null,$element.trigger("tap",[event.target]),options.tap&&(ret=options.tap.call($element,event,event.target)))):gesture==double_tap?phase!==phase_cancel&&phase!==phase_end||(cleartimeout(singletaptimeout),cleartimeout(holdtimeout),doubletapstarttime=null,$element.trigger("doubletap",[event.target]),options.doubletap&&(ret=options.doubletap.call($element,event,event.target))):gesture==long_tap&&(phase!==phase_cancel&&phase!==phase_end||(cleartimeout(singletaptimeout),doubletapstarttime=null,$element.trigger("longtap",[event.target]),options.longtap&&(ret=options.longtap.call($element,event,event.target)))),ret}function validateswipedistance(){var valid=!0;return null!==options.threshold&&(valid=distance>=options.threshold),valid}function didswipebacktocancel(){var cancelled=!1;return null!==options.cancelthreshold&&null!==direction&&(cancelled=getmaxdistance(direction)-distance>=options.cancelthreshold),cancelled}function validatepinchdistance(){return null!==options.pinchthreshold?pinchdistance>=options.pinchthreshold:!0}function validateswipetime(){var result;return result=options.maxtimethreshold?!(duration>=options.maxtimethreshold):!0}function validatedefaultevent(jqevent,direction){if(options.preventdefaultevents!==!1)if(options.allowpagescroll===none)jqevent.preventdefault();else{var auto=options.allowpagescroll===auto;switch(direction){case left:(options.swipeleft&&auto||!auto&&options.allowpagescroll!=horizontal)&&jqevent.preventdefault();break;case right:(options.swiperight&&auto||!auto&&options.allowpagescroll!=horizontal)&&jqevent.preventdefault();break;case up:(options.swipeup&&auto||!auto&&options.allowpagescroll!=vertical)&&jqevent.preventdefault();break;case down:(options.swipedown&&auto||!auto&&options.allowpagescroll!=vertical)&&jqevent.preventdefault();break;case none:}}}function validatepinch(){var hascorrectfingercount=validatefingers(),hasendpoint=validateendpoint(),hascorrectdistance=validatepinchdistance();return hascorrectfingercount&&hasendpoint&&hascorrectdistance}function haspinches(){return!!(options.pinchstatus||options.pinchin||options.pinchout)}function didpinch(){return!(!validatepinch()||!haspinches())}function validateswipe(){var hasvalidtime=validateswipetime(),hasvaliddistance=validateswipedistance(),hascorrectfingercount=validatefingers(),hasendpoint=validateendpoint(),didcancel=didswipebacktocancel(),valid=!didcancel&&hasendpoint&&hascorrectfingercount&&hasvaliddistance&&hasvalidtime;return valid}function hasswipes(){return!!(options.swipe||options.swipestatus||options.swipeleft||options.swiperight||options.swipeup||options.swipedown)}function didswipe(){return!(!validateswipe()||!hasswipes())}function validatefingers(){return fingercount===options.fingers||options.fingers===all_fingers||!supports_touch}function validateendpoint(){return 0!==fingerdata[0].end.x}function hastap(){return!!options.tap}function hasdoubletap(){return!!options.doubletap}function haslongtap(){return!!options.longtap}function validatedoubletap(){if(null==doubletapstarttime)return!1;var now=gettimestamp();return hasdoubletap()&&now-doubletapstarttime<=options.doubletapthreshold}function indoubletap(){return validatedoubletap()}function validatetap(){return(1===fingercount||!supports_touch)&&(isnan(distance)||distanceoptions.longtapthreshold&&double_tap_threshold>distance}function didtap(){return!(!validatetap()||!hastap())}function diddoubletap(){return!(!validatedoubletap()||!hasdoubletap())}function didlongtap(){return!(!validatelongtap()||!haslongtap())}function startmultifingerrelease(event){previoustouchendtime=gettimestamp(),fingercountatrelease=event.touches.length+1}function cancelmultifingerrelease(){previoustouchendtime=0,fingercountatrelease=0}function inmultifingerrelease(){var withinthreshold=!1;if(previoustouchendtime){var diff=gettimestamp()-previoustouchendtime;diff<=options.fingerreleasethreshold&&(withinthreshold=!0)}return withinthreshold}function gettouchinprogress(){return!($element.data(plugin_ns+"_intouch")!==!0)}function settouchinprogress(val){$element&&(val===!0?($element.bind(move_ev,touchmove),$element.bind(end_ev,touchend),leave_ev&&$element.bind(leave_ev,touchleave)):($element.unbind(move_ev,touchmove,!1),$element.unbind(end_ev,touchend,!1),leave_ev&&$element.unbind(leave_ev,touchleave,!1)),$element.data(plugin_ns+"_intouch",val===!0))}function createfingerdata(id,evt){var f={start:{x:0,y:0},last:{x:0,y:0},end:{x:0,y:0}};return f.start.x=f.last.x=f.end.x=evt.pagex||evt.clientx,f.start.y=f.last.y=f.end.y=evt.pagey||evt.clienty,fingerdata[id]=f,f}function updatefingerdata(evt){var id=void 0!==evt.identifier?evt.identifier:0,f=getfingerdata(id);return null===f&&(f=createfingerdata(id,evt)),f.last.x=f.end.x,f.last.y=f.end.y,f.end.x=evt.pagex||evt.clientx,f.end.y=evt.pagey||evt.clienty,f}function getfingerdata(id){return fingerdata[id]||null}function setmaxdistance(direction,distance){direction!=none&&(distance=math.max(distance,getmaxdistance(direction)),maximumsmap[direction].distance=distance)}function getmaxdistance(direction){return maximumsmap[direction]?maximumsmap[direction].distance:void 0}function createmaximumsdata(){var maxdata={};return maxdata[left]=createmaximumvo(left),maxdata[right]=createmaximumvo(right),maxdata[up]=createmaximumvo(up),maxdata[down]=createmaximumvo(down),maxdata}function createmaximumvo(dir){return{direction:dir,distance:0}}function calculateduration(){return endtime-starttime}function calculatetouchesdistance(startpoint,endpoint){var diffx=math.abs(startpoint.x-endpoint.x),diffy=math.abs(startpoint.y-endpoint.y);return math.round(math.sqrt(diffx*diffx+diffy*diffy))}function calculatepinchzoom(startdistance,enddistance){var percent=enddistance/startdistance*1;return percent.tofixed(2)}function calculatepinchdirection(){return 1>pinchzoom?out:in}function calculatedistance(startpoint,endpoint){return math.round(math.sqrt(math.pow(endpoint.x-startpoint.x,2)+math.pow(endpoint.y-startpoint.y,2)))}function calculateangle(startpoint,endpoint){var x=startpoint.x-endpoint.x,y=endpoint.y-startpoint.y,r=math.atan2(y,x),angle=math.round(180*r/math.pi);return 0>angle&&(angle=360-math.abs(angle)),angle}function calculatedirection(startpoint,endpoint){if(comparepoints(startpoint,endpoint))return none;var angle=calculateangle(startpoint,endpoint);return 45>=angle&&angle>=0?left:360>=angle&&angle>=315?left:angle>=135&&225>=angle?right:angle>45&&135>angle?down:up}function gettimestamp(){var now=new date;return now.gettime()}function getbounds(el){el=$(el);var offset=el.offset(),bounds={left:offset.left,right:offset.left+el.outerwidth(),top:offset.top,bottom:offset.top+el.outerheight()};return bounds}function isinbounds(point,bounds){return point.x>bounds.left&&point.xbounds.top&&point.y