1/** 2 * jQuery Plugin to obtain touch gestures from iPhone, iPod Touch and iPad, should also work with Android mobile phones (not tested yet!) 3 * Common usage: wipe images (left and right to show the previous or next image) 4 * 5 * @author Andreas Waltl, netCU Internetagentur (http://www.netcu.de) 6 * @version 1.1.1 (9th December 2010) - fix bug (older IE's had problems) 7 * @version 1.1 (1st September 2010) - support wipe up and wipe down 8 * @version 1.0 (15th July 2010) 9 */ 10(function ($) { 11 $.fn.touchwipe = function (settings) { 12 var config = { 13 min_move_x: 20, 14 min_move_y: 20, 15 wipeLeft: function () {}, 16 wipeRight: function () {}, 17 wipeUp: function () {}, 18 wipeDown: function () {}, 19 preventDefaultEvents: true 20 }; 21 if (settings) $.extend(config, settings); 22 this.each(function () { 23 var startX; 24 var startY; 25 var isMoving = false; 26 27 function cancelTouch() { 28 this.removeEventListener('touchmove', onTouchMove); 29 startX = null; 30 isMoving = false 31 } 32 function onTouchMove(e) { 33 if (config.preventDefaultEvents) { 34 e.preventDefault() 35 } 36 if (isMoving) { 37 var x = e.touches[0].pageX; 38 var y = e.touches[0].pageY; 39 var dx = startX - x; 40 var dy = startY - y; 41 if (Math.abs(dx) >= config.min_move_x) { 42 cancelTouch(); 43 if (dx > 0) { 44 config.wipeLeft() 45 } else { 46 config.wipeRight() 47 } 48 } else if (Math.abs(dy) >= config.min_move_y) { 49 cancelTouch(); 50 if (dy > 0) { 51 config.wipeDown() 52 } else { 53 config.wipeUp() 54 } 55 } 56 } 57 } 58 function onTouchStart(e) { 59 if (e.touches.length == 1) { 60 startX = e.touches[0].pageX; 61 startY = e.touches[0].pageY; 62 isMoving = true; 63 this.addEventListener('touchmove', onTouchMove, false) 64 } 65 } 66 if ('ontouchstart' in document.documentElement) { 67 this.addEventListener('touchstart', onTouchStart, false) 68 } 69 }); 70 return this 71 } 72})(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.