PageSourceSearch

https://www.inp-toulouse.fr/skins/inp-new/resources/js/jquery.touchwipe.modified.1.1.1.js

js inp-toulouse.fr collected 2026-10-01 11:28:26 UTC 5,082 bytes, 197 lines download raw bytes

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 * @author AnywareServices
11 * modified for adding progressive event and mouse support
12 */
13(function($) { 
14   $.fn.touchwipe = function(settings) {
15     var config = {
16    		min_move_x: 20,
17    		min_move_y: 20,
18 			wipeStart: function() { },
19 			wipeStop: function() { },
20 			wipeCancel: function() { },
21 			wipeLeft: null,
22 			wipeRight: null,
23 			wipeUp: null,
24 			wipeDown: null,
25			preventDefaultEvents: true
26	 };
27     
28     if (settings) $.extend(config, settings);
29 
30     this.each(function() 
31     {
32    	 var startX;
33    	 var startY;
34		 var isMoving = false;
35		 var lastX;
36		 var lastY;
37		 var startTarget;
38		 
39		 // ENDS MOVE
40		 function ends()
41		 {
42			 if (isMoving)
43			 {
44	    		 var dx = startX - lastX;
45	    		 var dy = startY - lastY;
46	    		 
47	    		 var moveX = Math.abs(dx) >= config.min_move_x;
48	    		 var moveY = Math.abs(dy) >= config.min_move_y;
49	    		 var handleX = config.wipeLeft != null || config.wipeRight != null;
50	    		 var handleY = config.wipeDown != null || config.wipeUp != null;
51				 if (moveX && handleX || moveY && handleY)
52				 {
53					 config.wipeStop();
54				 }
55				 else
56				 {
57					 if (/ipad|iphone/i.test(navigator.userAgent))
58					 {
59			    		 var links = $(startTarget).closest('a');
60			    		 if (links.length != 0)
61			    		 {
62			    			 // bug on ios that link do not work with ontouchstart
63			    			 window.location.href = links[0].href;
64			    		 }
65					 }
66
67		    		 config.wipeCancel();
68				 }
69				 
70				 startX = null;
71				 lastX = null;
72				 startY = null;
73				 lastY = null;
74				 isMoving = false;
75			 }
76			 
77		 }
78		 function onMouseUp(e) {
79    		 $(this).unbind('mousemove', onMouseMove);
80    		 $(this).unbind('mouseup', onMouseUp);
81    		 $(this).unbind('mouseout', onMouseUp);
82    		 ends();
83		 }
84    	 function onTouchEnd(e) {
85    		 this.removeEventListener('touchmove', onTouchMove);
86    		 this.removeEventListener('touchend', onTouchEnd);
87    		 ends();
88    	 }	
89    	 
90    	 // MOVING
91		 function moves(x, y)
92		 {
93    		 if(isMoving) 
94    		 {
95    			 lastX = x;
96    			 lastY = y;
97    			 
98	    		 var dx = startX - x;
99	    		 var dy = startY - y;
100	    		 
101	    		 var moveX = Math.abs(dx) >= config.min_move_x;
102	    		 var moveY = Math.abs(dy) >= config.min_move_y;
103	    		 var handleX = config.wipeLeft != null || config.wipeRight != null;
104	    		 var handleY = config.wipeDown != null || config.wipeUp != null;
105
106	    		 if(moveX && handleX) 
107	    		 {
108	    			if(dx > 0) 
109	    			{
110	    				config.wipeLeft && config.wipeLeft(dx);
111	    			}
112	    			else 
113	    			{
114	    				config.wipeRight && config.wipeRight(dx);
115	    			}
116	    		 }
117	    		 
118	    		 if(moveY && handleY) 
119	    		 {
120	    			if(dy > 0) 
121	    			{
122	    				config.wipeDown && config.wipeDown(dy);
123	    			}
124	    			else 
125	    			{
126	    				config.wipeUp && config.wipeUp(dy);
127	    			}
128	    		 }
129
130	    		 return moveX && handleX   || moveY && handleY;
131    		 }
132
133		 }
134    	 function onMouseMove(e) 
135    	 {
136    		 if (moves(e.pageX, e.pageY) && config.preventDefaultEvents)
137    		 {
138    			 e.preventDefault();
139    		 }
140    	 }
141    	 function onTouchMove(e) 
142    	 {
143    		 if(moves(e.touches[0].pageX, e.touches[0].pageY) && config.preventDefaultEvents) 
144    		 {
145    			 e.preventDefault();
146    		 }
147    	 }
148    	 
149    	 
150    	 // STARTS MOVE
151    	 function starts(target, x, y)
152    	 {
153			 startTarget = target;
154			 startX = x;
155			 startY = y;
156			 lastX = x;
157			 lastY = y;
158			 isMoving = true;
159			 config.wipeStart(startX, startY);
160			 return true;
161    	 }    	 
162    	 function onMouseDown(e)
163    	 {
164    		 if (starts(e.target, e.pageX, e.pageY))
165    		 {
166    			 $(this).bind('mousemove', onMouseMove);
167    			 $(this).bind('mouseup', onMouseUp);
168    			 $(this).bind('mouseout', onMouseUp);
169    		 }
170    	 }    	 
171    	 function onTouchStart(e)
172    	 {
173    		 if (starts(e.touches.item(0).target, e.touches[0].pageX, e.touches[0].pageY))
174    		 {
175				 this.addEventListener('touchmove', onTouchMove, false);
176				 this.addEventListener('touchend', onTouchEnd, false);
177    		 }
178    	 }    	
179    	 
180    	 // REGISTER LISTENERS
181    	 $(this).bind('dragstart', function(event) { event.preventDefault(); });
182    	 if (/ipad|iphone/i.test(navigator.userAgent))
183    	 {
184    		 // bug on ios that link do not work with ontouchstart
185    		 $(this).children("li").find("a").bind('click', function(event) { event.preventDefault(); });
186    	 }
187   		 $(this).bind('mousedown', onMouseDown);
188    	 if ('ontouchstart' in document.documentElement) 
189    	 {
190    		 this.addEventListener('touchstart', onTouchStart, false);
191    	 }
192     });
193 
194     return this;
195   };
196 
197 })(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.