PluginProbe
Photonic Gallery & Lightbox for Flickr, SmugMug & Others / 3.37
Photonic Gallery & Lightbox for Flickr, SmugMug & Others v3.37
3.37 3.36 3.35 3.34 3.33 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 2.31 2.32 2.33 2.34 2.40 2.41 2.42 2.43 All 142 releases
photonic / include / ext / jquery.detect_swipe.js

jquery.detect_swipe.js in Photonic Gallery & Lightbox for Flickr, SmugMug & Others 3.37, at include/ext/jquery.detect_swipe.js

84 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * jquery.detectSwipe v2.1.3
3 * jQuery Plugin to obtain touch gestures from iPhone, iPod Touch, iPad and Android
4 * http://github.com/marcandre/detect_swipe
5 * Based on touchwipe by Andreas Waltl, netCU Internetagentur (http://www.netcu.de)
6 */
7
8 (function (factory) {
9 if (typeof define === 'function' && define.amd) {
10 // AMD. Register as an anonymous module.
11 define(['jquery'], factory);
12 } else if (typeof exports === 'object') {
13 // Node/CommonJS
14 module.exports = factory(require('jquery'));
15 } else {
16 // Browser globals
17 factory(jQuery);
18 }
19 }(function($) {
20
21 $.detectSwipe = {
22 version: '2.1.2',
23 enabled: 'ontouchstart' in document.documentElement,
24 preventDefault: true,
25 threshold: 20
26 };
27
28 var startX,
29 startY,
30 isMoving = false;
31
32 function onTouchEnd() {
33 this.removeEventListener('touchmove', onTouchMove);
34 this.removeEventListener('touchend', onTouchEnd);
35 isMoving = false;
36 }
37
38 function onTouchMove(e) {
39 if ($.detectSwipe.preventDefault) { e.preventDefault(); }
40 if(isMoving) {
41 var x = e.touches[0].pageX;
42 var y = e.touches[0].pageY;
43 var dx = startX - x;
44 var dy = startY - y;
45 var dir;
46 if(Math.abs(dx) >= $.detectSwipe.threshold) {
47 dir = dx > 0 ? 'left' : 'right'
48 }
49 else if(Math.abs(dy) >= $.detectSwipe.threshold) {
50 dir = dy > 0 ? 'up' : 'down'
51 }
52 if(dir) {
53 onTouchEnd.call(this);
54 $(this).trigger('swipe', dir).trigger('swipe' + dir);
55 }
56 }
57 }
58
59 function onTouchStart(e) {
60 if (e.touches.length == 1) {
61 startX = e.touches[0].pageX;
62 startY = e.touches[0].pageY;
63 isMoving = true;
64 this.addEventListener('touchmove', onTouchMove, false);
65 this.addEventListener('touchend', onTouchEnd, false);
66 }
67 }
68
69 function setup() {
70 this.addEventListener && this.addEventListener('touchstart', onTouchStart, false);
71 }
72
73 function teardown() {
74 this.removeEventListener('touchstart', onTouchStart);
75 }
76
77 $.event.special.swipe = { setup: setup };
78
79 $.each(['left', 'up', 'down', 'right'], function () {
80 $.event.special['swipe' + this] = { setup: function(){
81 $(this).on('swipe', $.noop);
82 } };
83 });
84 }));