|
1 | | -/** |
2 | | - * Swipebox - A touchable jQuery lightbox |
3 | | - * |
4 | | - * @author Constantin Saguin - @brutaldesign |
5 | | - * @link http://csag.co |
6 | | - * @github http://github.com/brutaldesign/swipebox |
7 | | - * @version 1.2.5 |
8 | | - * @license MIT License |
9 | | -*/ |
| 1 | +/*! Swipebox v1.2.6 | Constantin Saguin csag.co | MIT License | github.com/brutaldesign/swipebox */ |
10 | 2 |
|
11 | 3 | ;( function ( window, document, $, undefined ) { |
12 | 4 |
|
|
27 | 19 | elements = [], // slides array [ { href:'...', title:'...' }, ...], |
28 | 20 | selector = elem.selector, |
29 | 21 | $selector = $( selector ), |
30 | | - isTouch = document.createTouch !== undefined || ( 'ontouchstart' in window ) || ( 'onmsgesturechange' in window ) || navigator.msMaxTouchPoints, |
31 | | - supportSVG = !! ( window.SVGSVGElement ), |
| 22 | + isMobile = navigator.userAgent.match( /(iPad)|(iPhone)|(iPod)|(Android)|(PlayBook)|(BB10)|(BlackBerry)|(Opera Mini)|(IEMobile)|(webOS)|(MeeGo)/i ), |
| 23 | + supportSVG = !! document.createElementNS && !! document.createElementNS( 'http://www.w3.org/2000/svg', "svg").createSVGRect, |
32 | 24 | winWidth = window.innerWidth ? window.innerWidth : $( window ).width(), |
33 | 25 | winHeight = window.innerHeight ? window.innerHeight : $( window ).height(), |
34 | 26 | /* jshint multistr: true */ |
|
103 | 95 | title: title |
104 | 96 | } ); |
105 | 97 | } ); |
106 | | - |
| 98 | + |
107 | 99 | index = $elem.index( $( this ) ); |
108 | 100 | event.preventDefault(); |
109 | 101 | event.stopPropagation(); |
|
148 | 140 | var $this = this; |
149 | 141 |
|
150 | 142 | $( 'body' ).append( html ); |
151 | | - |
| 143 | + |
152 | 144 | if ( $this.doCssTrans() ) { |
153 | 145 | $( '#swipebox-slider' ).css( { |
154 | 146 | '-webkit-transition' : 'left 0.4s ease', |
|
188 | 180 |
|
189 | 181 | $this.setDim(); |
190 | 182 | $this.actions(); |
191 | | - $this.keyboard(); |
192 | | - $this.gesture(); |
| 183 | + |
| 184 | + if ( isMobile ) { |
| 185 | + $this.gesture(); |
| 186 | + } else { |
| 187 | + $this.keyboard(); |
| 188 | + } |
| 189 | + |
193 | 190 | $this.animBars(); |
194 | 191 | $this.resize(); |
195 | 192 |
|
|
270 | 267 | * Touch navigation |
271 | 268 | */ |
272 | 269 | gesture : function () { |
273 | | - if ( isTouch ) { |
274 | | - var $this = this, |
275 | | - distance = null, |
276 | | - swipMinDistance = 10, |
277 | | - startCoords = {}, |
278 | | - endCoords = {}, |
279 | | - bars = $( '#swipebox-caption, #swipebox-action' ); |
| 270 | + |
| 271 | + var $this = this, |
| 272 | + distance = null, |
| 273 | + swipMinDistance = 10, |
| 274 | + startCoords = {}, |
| 275 | + endCoords = {}; |
| 276 | + var bars = $( '#swipebox-caption, #swipebox-action' ); |
280 | 277 |
|
281 | | - bars.addClass( 'visible-bars' ); |
282 | | - $this.setTimeout(); |
| 278 | + bars.addClass( 'visible-bars' ); |
| 279 | + $this.setTimeout(); |
283 | 280 |
|
284 | | - $( 'body' ).bind( 'touchstart', function( event ) { |
| 281 | + $( 'body' ).bind( 'touchstart', function( event ) { |
285 | 282 |
|
286 | | - $( this ).addClass( 'touching' ); |
| 283 | + $(this).addClass( 'touching' ); |
287 | 284 |
|
288 | | - endCoords = event.originalEvent.targetTouches[0]; |
289 | | - startCoords.pageX = event.originalEvent.targetTouches[0].pageX; |
| 285 | + endCoords = event.originalEvent.targetTouches[0]; |
| 286 | + startCoords.pageX = event.originalEvent.targetTouches[0].pageX; |
290 | 287 |
|
291 | | - $( '.touching' ).bind( 'touchmove', function( event ) { |
292 | | - event.preventDefault(); |
293 | | - event.stopPropagation(); |
294 | | - endCoords = e.originalEvent.targetTouches[0]; |
| 288 | + $( '.touching' ).bind( 'touchmove',function( event ) { |
| 289 | + event.preventDefault(); |
| 290 | + event.stopPropagation(); |
| 291 | + endCoords = event.originalEvent.targetTouches[0]; |
295 | 292 |
|
296 | | - } ); |
297 | | - |
| 293 | + } ); |
| 294 | + |
298 | 295 | return false; |
299 | 296 |
|
300 | | - } ).bind( 'touchend', function( event ) { |
301 | | - |
| 297 | + } ).bind( 'touchend',function( event ) { |
302 | 298 | event.preventDefault(); |
303 | 299 | event.stopPropagation(); |
304 | 300 |
|
305 | 301 | distance = endCoords.pageX - startCoords.pageX; |
306 | | - |
| 302 | + |
307 | 303 | if ( distance >= swipMinDistance ) { |
308 | | - |
| 304 | + |
309 | 305 | // swipeLeft |
310 | 306 | $this.getPrev(); |
311 | | - |
312 | | - } else if ( distance <= - swipMinDistance ) { |
313 | 307 |
|
| 308 | + } else if ( distance <= - swipMinDistance ) { |
| 309 | + |
314 | 310 | // swipeRight |
315 | 311 | $this.getNext(); |
316 | | - |
| 312 | + |
317 | 313 | } else { |
318 | 314 | // tap |
319 | 315 | if ( ! bars.hasClass( 'visible-bars' ) ) { |
|
328 | 324 |
|
329 | 325 | $( '.touching' ).off( 'touchmove' ).removeClass( 'touching' ); |
330 | 326 |
|
331 | | - } ); |
| 327 | + } ); |
332 | 328 |
|
333 | | - } |
334 | 329 | }, |
335 | 330 |
|
336 | 331 | /** |
|
406 | 401 | } |
407 | 402 | } ); |
408 | 403 |
|
409 | | - $( '#swipebox-action' ).hover( function() { |
| 404 | + if ( ! isMobile ) { |
| 405 | + |
| 406 | + $( '#swipebox-action' ).hover( function() { |
410 | 407 | $this.showBars(); |
411 | | - bars.addClass( 'force-visible-bars' ); |
| 408 | + bars.addClass( 'visible-bars' ); |
412 | 409 | $this.clearTimeout(); |
413 | 410 |
|
414 | | - }, function() { |
415 | | - bars.removeClass( 'force-visible-bars' ); |
416 | | - $this.setTimeout(); |
| 411 | + }, function() { |
| 412 | + bars.removeClass( 'visible-bars' ); |
| 413 | + $this.setTimeout(); |
417 | 414 |
|
418 | | - } ); |
| 415 | + } ); |
| 416 | + |
| 417 | + } |
419 | 418 | }, |
420 | 419 |
|
421 | 420 | /** |
|
448 | 447 | */ |
449 | 448 | actions : function () { |
450 | 449 | var $this = this; |
| 450 | + |
| 451 | + var action = isMobile ? 'touchend' : 'click'; |
451 | 452 |
|
452 | 453 | if ( elements.length < 2 ) { |
| 454 | + |
453 | 455 | $( '#swipebox-prev, #swipebox-next' ).hide(); |
| 456 | + |
454 | 457 | } else { |
455 | | - $( '#swipebox-prev' ).bind( 'click touchend', function( event ) { |
| 458 | + $( '#swipebox-prev' ).bind( action, function( event ) { |
456 | 459 | event.preventDefault(); |
457 | 460 | event.stopPropagation(); |
458 | 461 | $this.getPrev(); |
459 | 462 | $this.setTimeout(); |
460 | 463 | } ); |
461 | 464 |
|
462 | | - $( '#swipebox-next' ).bind( 'click touchend', function( event ) { |
| 465 | + $( '#swipebox-next' ).bind( action, function( event ) { |
463 | 466 | event.preventDefault(); |
464 | 467 | event.stopPropagation(); |
465 | 468 | $this.getNext(); |
466 | 469 | $this.setTimeout(); |
467 | 470 | } ); |
468 | 471 | } |
469 | 472 |
|
470 | | - $( '#swipebox-close' ).bind( 'click touchend', function() { |
| 473 | + $( '#swipebox-close' ).bind( action, function() { |
471 | 474 | $this.closeSlide(); |
472 | 475 | } ); |
473 | 476 | }, |
|
508 | 511 | */ |
509 | 512 | openSlide : function ( index ) { |
510 | 513 | $( 'html' ).addClass( 'swipebox-html' ); |
| 514 | + if ( isMobile ) { |
| 515 | + $( 'html' ).addClass( 'swipebox-touch' ); |
| 516 | + } |
511 | 517 | $( window ).trigger( 'resize' ); // fix scroll bar visibility on desktop |
512 | 518 | this.setSlide( index, true ); |
513 | 519 | }, |
|
594 | 600 | var youtubeShortUrl = url.match(/youtu\.be\/([a-zA-Z0-9\-_]+)/); |
595 | 601 | var vimeoUrl = url.match( /vimeo\.com\/([0-9]*)/ ); |
596 | 602 | if ( youtubeUrl || youtubeShortUrl) { |
597 | | - if ( youtubeShortUrl ){ |
| 603 | + if ( youtubeShortUrl ) { |
598 | 604 | youtubeUrl = youtubeShortUrl; |
599 | 605 | } |
600 | 606 | iframe = '<iframe width="560" height="315" src="//www.youtube.com/embed/' + youtubeUrl[1] + '" frameborder="0" allowfullscreen></iframe>'; |
|
651 | 657 | this.setSlide( index ); |
652 | 658 | this.preloadMedia( index-1 ); |
653 | 659 | } |
654 | | - else{ |
| 660 | + else { |
655 | 661 |
|
656 | 662 | $( '#swipebox-slider' ).addClass( 'leftSpring' ); |
657 | 663 | setTimeout( function() { |
|
664 | 670 | * Close |
665 | 671 | */ |
666 | 672 | closeSlide : function () { |
667 | | - $( 'html' ).removeClass( 'swipebox' ); |
| 673 | + $( 'html' ).removeClass( 'swipebox-html' ); |
| 674 | + $( 'html' ).removeClass( 'swipebox-touch' ); |
668 | 675 | $( window ).trigger( 'resize' ); |
669 | 676 | this.destroy(); |
670 | 677 | }, |
|
0 commit comments