|
8 | 8 | var defaults = { |
9 | 9 | useCSS : true, |
10 | 10 | initialIndexOnArray : 0, |
| 11 | + closeBySwipe: true, |
11 | 12 | hideBarsDelay : 3000, |
12 | 13 | videoMaxWidth : 1140, |
13 | 14 | vimeoColor : 'CCCCCC', |
|
273 | 274 |
|
274 | 275 | var $this = this, |
275 | 276 | distance = null, |
| 277 | + vDistance = null, |
| 278 | + vSwipe = false, |
276 | 279 | swipMinDistance = 10, |
| 280 | + vSwipMinDistance = 50, |
277 | 281 | startCoords = {}, |
278 | 282 | endCoords = {}; |
279 | | - var bars = $( '#swipebox-caption, #swipebox-action' ); |
| 283 | + |
| 284 | + var bars = $('#swipebox-caption, #swipebox-action'); |
| 285 | + var slider = $('#swipebox-slider'); |
280 | 286 |
|
281 | 287 | bars.addClass( 'visible-bars' ); |
282 | 288 | $this.setTimeout(); |
|
287 | 293 |
|
288 | 294 | endCoords = event.originalEvent.targetTouches[0]; |
289 | 295 | startCoords.pageX = event.originalEvent.targetTouches[0].pageX; |
| 296 | + startCoords.pageY = event.originalEvent.targetTouches[0].pageY; |
290 | 297 |
|
291 | 298 | $( '.touching' ).bind( 'touchmove',function( event ) { |
292 | 299 | event.preventDefault(); |
293 | 300 | event.stopPropagation(); |
294 | 301 | endCoords = event.originalEvent.targetTouches[0]; |
295 | 302 |
|
| 303 | + if (plugin.settings.closeBySwipe) { |
| 304 | + vDistance = endCoords.pageY - startCoords.pageY; |
| 305 | + if (Math.abs(vDistance) >= vSwipMinDistance || vSwipe) { |
| 306 | + var opacity = 0.75 - Math.abs(vDistance) / slider.height(); |
| 307 | + |
| 308 | + slider.css({ 'top': vDistance + 'px' }); |
| 309 | + slider.css({ 'opacity': opacity }); |
| 310 | + |
| 311 | + vSwipe = true; |
| 312 | + } |
| 313 | + } |
| 314 | + |
296 | 315 | } ); |
297 | 316 |
|
298 | 317 | return false; |
299 | 318 |
|
300 | 319 | } ).bind( 'touchend',function( event ) { |
301 | 320 | event.preventDefault(); |
302 | 321 | event.stopPropagation(); |
| 322 | + |
| 323 | + if (plugin.settings.closeBySwipe) { |
| 324 | + if (slider.css("opacity") <= 0.5) { |
| 325 | + var vOffset = vDistance > 0 ? slider.height() : -slider.height(); |
| 326 | + slider.animate({ top: vOffset + 'px', 'opacity': 0 }, 300, function () { |
| 327 | + $this.closeSlide(); |
| 328 | + }); |
| 329 | + } else { |
| 330 | + slider.animate({ top: 0, 'opacity': 1 }, 300); |
| 331 | + } |
| 332 | + |
| 333 | + if (vSwipe) { |
| 334 | + vSwipe = false; |
| 335 | + return; |
| 336 | + } |
| 337 | + } |
303 | 338 |
|
304 | 339 | distance = endCoords.pageX - startCoords.pageX; |
305 | 340 |
|
|
0 commit comments