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