1;(function($){ 2 3 "use strict"; 4 5 var isTouch = 'ontouchstart' in document, 6 isPointer = window.navigator.pointerEnabled, 7 isMSPoiner = !isPointer && window.navigator.msPointerEnabled, 8 usePointer = isPointer || isMSPoiner, 9 // Events 10 ev_start = (isPointer ? 'pointerdown ' : '' ) + (isMSPoiner ? 'MSPointerDown ' : '' ) + (isTouch ? 'touchstart ' : '' ) + 'mousedown', 11 ev_move = (isPointer ? 'pointermove ' : '' ) + (isMSPoiner ? 'MSPointerMove ' : '' ) + (isTouch ? 'touchmove ' : '' ) + 'mousemove', 12 ev_end = (isPointer ? 'pointerup ' : '' ) + (isMSPoiner ? 'MSPointerUp ' : '' ) + (isTouch ? 'touchend ' : '' ) + 'mouseup', 13 ev_cancel = (isPointer ? 'pointercancel ' : '' ) + (isMSPoiner ? 'MSPointerCancel ': '' ) + 'touchcancel'; 14 15 16 averta.TouchSwipe = function($element){ 17 this.$element = $element; 18 this.enabled = true; 19 20 $element.bind(ev_start , {target: this} , this.__touchStart); 21 22 $element[0].swipe = this; 23 24 this.onSwipe = null; 25 this.swipeType = 'horizontal'; 26 this.noSwipeSelector = 'input, textarea, button, .no-swipe, .ms-no-swipe'; 27 28 this.lastStatus = {}; 29 30 }; 31 32 var p = averta.TouchSwipe.prototype; 33 34 /*-------------- METHODS --------------*/ 35 36 p.getDirection = function(new_x , new_y){ 37 switch(this.swipeType){ 38 case 'horizontal': 39 return new_x <= this.start_x ? 'left' : 'right'; 40 break; 41 case 'vertical': 42 return new_y <= this.start_y ? 'up' : 'down'; 43 break; 44 case 'all': 45 if(Math.abs(new_x - this.start_x) > Math.abs(new_y - this.start_y)) 46 return new_x <= this.start_x ? 'left' : 'right'; 47 else 48 return new_y <= this.start_y ? 'up' : 'down'; 49 break; 50 } 51 }; 52 53 p.priventDefultEvent = function(new_x , new_y){ 54 //if(this.priventEvt != null) return this.priventEvt; 55 var dx = Math.abs(new_x - this.start_x); 56 var dy = Math.abs(new_y - this.start_y); 57 58 var horiz = dx > dy; 59 60 return (this.swipeType === 'horizontal' && horiz) || 61 (this.swipeType === 'vertical' && !horiz); 62 63 //return this.priventEvt; 64 }; 65 66 p.createStatusObject = function(evt){ 67 var status_data = {} , temp_x , temp_y; 68 69 temp_x = this.lastStatus.distanceX || 0; 70 temp_y = this.lastStatus.distanceY || 0; 71 72 status_data.distanceX = evt.pageX - this.start_x; 73 status_data.distanceY = evt.pageY - this.start_y; 74 status_data.moveX = status_data.distanceX - temp_x; 75 status_data.moveY = status_data.distanceY - temp_y; 76 77 status_data.distance = parseInt( Math.sqrt(Math.pow(status_data.distanceX , 2) + Math.pow(status_data.distanceY , 2)) ); 78 79 status_data.duration = new Date().getTime() - this.start_time; 80 status_data.direction = this.getDirection(evt.pageX , evt.pageY); 81 82 return status_data; 83 }; 84 85 86 p.__reset = function(event , jqevt){ 87 this.reset = false; 88 this.lastStatus = {}; 89 this.start_time = new Date().getTime(); 90 91 var point = this.__getPoint( event, jqevt ); 92 this.start_x = point.pageX; 93 this.start_y = point.pageY; 94 }; 95 96 p.__touchStart = function(event){ 97 98 var swipe = event.data.target; 99 var jqevt = event; 100 if(!swipe.enabled) return; 101 102 if ( $(event.target).closest(swipe.noSwipeSelector, swipe.$element).length > 0 ) { 103 return; 104 } 105 106 event = event.originalEvent; 107 108 if( usePointer ) { 109 $(this).css('-ms-touch-action', swipe.swipeType === 'horizontal' ? 'pan-y' : 'pan-x'); 110 } 111 112 if(!swipe.onSwipe) { 113 $.error('Swipe listener is undefined'); 114 return; 115 } 116 117 // don't catch the touch start again, also don't go further if the delay between touchstart and mousedown is small 118 // if ( swipe.touchStarted ) { 119 if ( swipe.touchStarted || isTouch && swipe.start_time && event.type === 'mousedown' && new Date().getTime() - swipe.start_time < 600 ) { 120 return; 121 } 122 123 var point = swipe.__getPoint( event, jqevt ); 124 swipe.start_x = point.pageX; 125 swipe.start_y = point.pageY; 126 127 swipe.start_time = new Date().getTime(); 128 129 $(document).bind(ev_end , {target: swipe} , swipe.__touchEnd). 130 bind(ev_move , {target: swipe} , swipe.__touchMove). 131 bind(ev_cancel , {target: swipe} , swipe.__touchCancel); 132 133 var status = swipe.createStatusObject(point); 134 status.phase = 'start'; 135 136 swipe.onSwipe.call(null , status); 137 138 if(!isTouch) 139 jqevt.preventDefault(); 140 141 swipe.lastStatus = status; 142 swipe.touchStarted = true; 143 }; 144 145 p.__touchMove = function(event){ 146 var swipe = event.data.target; 147 var jqevt = event; 148 event = event.originalEvent; 149 150 if(!swipe.touchStarted) return; 151 152 clearTimeout(swipe.timo); 153 swipe.timo = setTimeout(function(){swipe.__reset(event , jqevt);} , 60); 154 155 var point = swipe.__getPoint( event, jqevt ); 156 157 var status = swipe.createStatusObject(point); 158 159 if(swipe.priventDefultEvent(point.pageX , point.pageY)) 160 jqevt.preventDefault(); 161 162 status.phase = 'move'; 163 164 //if(swipe.lastStatus.direction !== status.direction) swipe.__reset(event , jqevt); 165 166 swipe.lastStatus = status; 167 168 swipe.onSwipe.call(null , status); 169 }; 170 171 p.__touchEnd = function(event){ 172 173 var swipe = event.data.target; 174 var jqevt = event; 175 event = event.originalEvent; 176 177 clearTimeout(swipe.timo); 178 179 var status = swipe.lastStatus; 180 181 if(!isTouch) 182 jqevt.preventDefault(); 183 184 status.phase = 'end'; 185 186 swipe.touchStarted = false;
187 swipe.priventEvt = null; 188 189 $(document).unbind(ev_end , swipe.__touchEnd). 190 unbind(ev_move , swipe.__touchMove). 191 unbind(ev_cancel , swipe.__touchCancel); 192 193 status.speed = status.distance / status.duration; 194 195 swipe.onSwipe.call(null , status); 196 197 }; 198 199 p.__touchCancel = function(event){ 200 var swipe = event.data.target; 201 swipe.__touchEnd(event); 202 }; 203 204 p.__getPoint = function( event, jqEvent ) { 205 if ( isTouch && event.type.indexOf('mouse') === -1 ) { 206 return event.touches[0]; 207 } else if ( usePointer ) { 208 return event; 209 } else { 210 return jqEvent; 211 } 212 }; 213 214 p.enable = function(){ 215 if(this.enabled) return; 216 this.enabled = true; 217 }; 218 219 p.disable = function(){ 220 if(!this.enabled) return; 221 this.enabled = false; 222 }; 223 224})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.