|
1 | 1 | /*! |
2 | | - Zoom v1.7.8 - 2013-07-30 |
| 2 | + Zoom v1.7.9 - 2013-10-16 |
3 | 3 | Enlarge images on click or mouseover. |
4 | 4 | (c) 2013 Jack Moore - http://www.jacklmoore.com/zoom |
5 | 5 | license: http://www.opensource.org/licenses/mit-license.php |
|
10 | 10 | callback: false, |
11 | 11 | target: false, |
12 | 12 | duration: 120, |
13 | | - on: 'mouseover', // other options: 'grab', 'click', 'toggle' |
| 13 | + on: 'mouseover', // other options: grab, click, toggle |
| 14 | + touch: true, // enables a touch fallback |
14 | 15 | onZoomIn: false, |
15 | 16 | onZoomOut: false |
16 | 17 | }; |
|
79 | 80 | $img = $(img), |
80 | 81 | mousemove = 'mousemove.zoom', |
81 | 82 | clicked = false, |
| 83 | + touched = false, |
82 | 84 | $urlElement; |
83 | 85 |
|
84 | 86 | // If a url wasn't specified, look for an image element. |
|
110 | 112 | .fadeTo(settings.duration, 0, $.isFunction(settings.onZoomOut) ? settings.onZoomOut.call(img) : false); |
111 | 113 | } |
112 | 114 |
|
| 115 | + // Mouse events |
113 | 116 | if (settings.on === 'grab') { |
114 | 117 | $(source) |
115 | 118 | .on('mousedown.zoom', |
|
130 | 133 | e.preventDefault(); |
131 | 134 | } |
132 | 135 | } |
133 | | - ) |
134 | | - .on('touchstart.zoom', function (e) { |
135 | | - e.preventDefault(); |
136 | | - start( e.originalEvent.touches[0] || e.originalEvent.changedTouches[0] ); |
137 | | - }) |
138 | | - .on('touchmove.zoom', function (e) { |
139 | | - e.preventDefault(); |
140 | | - zoom.move( e.originalEvent.touches[0] || e.originalEvent.changedTouches[0] ); |
141 | | - }) |
142 | | - .on('touchend.zoom', stop); |
143 | | - |
| 136 | + ); |
144 | 137 | } else if (settings.on === 'click') { |
145 | 138 | $(source).on('click.zoom', |
146 | 139 | function (e) { |
|
150 | 143 | } else { |
151 | 144 | clicked = true; |
152 | 145 | start(e); |
153 | | - $(document) |
154 | | - .on(mousemove, zoom.move) |
155 | | - .on('touchstart.zoom', function (e) { |
156 | | - // no e.preventDefault() cause it will be impossible to turn off with a click |
157 | | - start( e.originalEvent.touches[0] || e.originalEvent.changedTouches[0] ); |
158 | | - }) |
159 | | - .on('touchmove.zoom', function (e) { |
160 | | - e.preventDefault(); |
161 | | - zoom.move( e.originalEvent.touches[0] || e.originalEvent.changedTouches[0] ); |
162 | | - }); |
| 146 | + $(document).on(mousemove, zoom.move); |
163 | 147 | $(document).one('click.zoom', |
164 | 148 | function () { |
165 | 149 | stop(); |
166 | 150 | clicked = false; |
167 | | - $(document) |
168 | | - .off(mousemove, zoom.move) |
169 | | - .off('touchstart.zoom') |
170 | | - .off('touchmove.zoom'); |
| 151 | + $(document).off(mousemove, zoom.move); |
171 | 152 | } |
172 | 153 | ); |
173 | 154 | return false; |
|
185 | 166 | clicked = !clicked; |
186 | 167 | } |
187 | 168 | ); |
188 | | - } else { |
| 169 | + } else if (settings.on === 'mouseover') { |
189 | 170 | zoom.init(); // Preemptively call init because IE7 will fire the mousemove handler before the hover handler. |
190 | 171 |
|
191 | 172 | $(source) |
192 | 173 | .on('mouseenter.zoom', start) |
193 | 174 | .on('mouseleave.zoom', stop) |
194 | | - .on(mousemove, zoom.move) |
| 175 | + .on(mousemove, zoom.move); |
| 176 | + } |
| 177 | + |
| 178 | + // Touch fallback |
| 179 | + if (settings.touch) { |
| 180 | + $(source) |
195 | 181 | .on('touchstart.zoom', function (e) { |
196 | 182 | e.preventDefault(); |
197 | | - start( e.originalEvent.touches[0] || e.originalEvent.changedTouches[0] ); |
| 183 | + if (touched) { |
| 184 | + touched = false; |
| 185 | + stop(); |
| 186 | + } else { |
| 187 | + touched = true; |
| 188 | + start( e.originalEvent.touches[0] || e.originalEvent.changedTouches[0] ); |
| 189 | + } |
198 | 190 | }) |
199 | 191 | .on('touchmove.zoom', function (e) { |
200 | 192 | e.preventDefault(); |
201 | 193 | zoom.move( e.originalEvent.touches[0] || e.originalEvent.changedTouches[0] ); |
202 | | - }) |
203 | | - .on('touchend.zoom', stop); |
| 194 | + }); |
204 | 195 | } |
205 | | - |
| 196 | + |
206 | 197 | if ($.isFunction(settings.callback)) { |
207 | 198 | settings.callback.call(img); |
208 | 199 | } |
|
0 commit comments