1/*! Swipebox v1.5.2 | Constantin Saguin csag.co | MIT License | github.com/brutaldesign/swipebox */ 2 3;( function ( window, document, $, undefined ) { 4 5 $.swipebox = function( elem, options ) { 6 7 $( elem ).addClass( 'swipebox' ); // fugly but yea, swipebox class all the things 8 9 // Default options 10 var ui, 11 defaults = { 12 useCSS : true, 13 useSVG : true, 14 initialIndexOnArray : 0, 15 removeBarsOnMobile : true, 16 hideCloseButtonOnMobile : false, 17 hideBarsDelay : 3000, 18 videoMaxWidth : 1140, 19 vimeoColor : 'cccccc', 20 beforeOpen: null, 21 afterOpen: null, 22 afterClose: null, 23 afterMedia: null, 24 nextSlide: null, 25 prevSlide: null, 26 loopAtEnd: false, 27 autoplayVideos: false, 28 queryStringData: {}, 29 toggleClassOnLoad: '' 30 }, 31 32 plugin = this, 33 elements = [], // slides array [ { href:'...', title:'...' }, ...], 34 $elem, 35 selector = '.swipebox', 36 isMobile = navigator.userAgent.match( /(iPad)|(iPhone)|(iPod)|(Android)|(PlayBook)|(BB10)|(BlackBerry)|(Opera Mini)|(IEMobile)|(webOS)|(MeeGo)/i ), 37 isTouch = isMobile !== null || document.createTouch !== undefined || ( 'ontouchstart' in window ) || ( 'onmsgesturechange' in window ) || navigator.msMaxTouchPoints, 38 supportSVG = !! document.createElementNS && !! document.createElementNS( 'http://www.w3.org/2000/svg', 'svg').createSVGRect, 39 winWidth = window.innerWidth ? window.innerWidth : $( window ).width(), 40 winHeight = window.innerHeight ? window.innerHeight : $( window ).height(), 41 currentX = 0, 42 /* jshint multistr: true */ 43 html = '<div id="swipebox-overlay">\ 44 <div id="swipebox-container">\ 45 <div id="swipebox-slider"></div>\ 46 <div id="swipebox-top-bar">\ 47 <div id="swipebox-title"></div>\ 48 </div>\ 49 <div id="swipebox-bottom-bar">\ 50 <div id="swipebox-arrows">\ 51 <a id="swipebox-prev"></a>\ 52 <a id="swipebox-next"></a>\ 53 </div>\ 54 </div>\ 55 <a id="swipebox-close"></a>\ 56 </div>\ 57 </div>'; 58 59 plugin.settings = {}; 60 61 $.swipebox.close = function () { 62 ui.closeSlide(); 63 }; 64 65 $.swipebox.extend = function () { 66 return ui; 67 }; 68 69 plugin.init = function() { 70 71 plugin.settings = $.extend( {}, defaults, options ); 72 73 if ( Array.isArray( elem ) ) { 74 75 elements = elem; 76 ui.target = $( window ); 77 ui.init( plugin.settings.initialIndexOnArray ); 78 79 } else { 80 81 $( document ).on( 'click', selector, function( event ) { 82 83 // console.log( isTouch ); 84 85 if ( event.target.parentNode.className === 'slide current' ) { 86 87 return false; 88 } 89 90 if ( ! Array.isArray( elem ) ) { 91 ui.destroy(); 92 $elem = $( selector ); 93 ui.actions(); 94 } 95 96 elements = []; 97 var index, relType, relVal; 98 99 // Allow for HTML5 compliant attribute before legacy use of rel 100 if ( ! relVal ) { 101 relType = 'data-rel'; 102 relVal = $( this ).attr( relType ); 103 } 104 105 if ( ! relVal ) { 106 relType = 'rel'; 107 relVal = $( this ).attr( relType ); 108 } 109 110 if ( relVal && relVal !== '' && relVal !== 'nofollow' ) { 111 $elem = $( selector ).filter( '[' + relType + '="' + relVal + '"]' ); 112 } else { 113 $elem = $( selector ); 114 } 115 116 $elem.each( function() { 117 118 var title = null, 119 href = null; 120 121 if ( $( this ).attr( 'title' ) ) { 122 title = $( this ).attr( 'title' ); 123 } 124 125 if ( $( this ).attr( 'href' ) ) { 126 href = $( this ).attr( 'href' ); 127 } 128 129 elements.push( { 130 href: href, 131 title: title 132 } ); 133 } ); 134 135 index = $elem.index( $( this ) ); 136 event.preventDefault(); 137 event.stopPropagation(); 138 ui.target = $( event.target ); 139 ui.init( index ); 140 } ); 141 } 142 }; 143 144 ui = { 145 146 /** 147 * Initiate Swipebox 148 */ 149 init : function( index ) { 150 if ( plugin.settings.beforeOpen ) { 151 plugin.settings.beforeOpen(); 152 } 153 this.target.trigger( 'swipebox-start' ); 154 $.swipebox.isOpen = true; 155 this.build(); 156 this.openSlide( index ); 157 this.openMedia( index ); 158 this.preloadMedia( index+1 ); 159 this.preloadMedia( index-1 ); 160 if ( plugin.settings.afterOpen ) { 161 plugin.settings.afterOpen(index); 162 } 163 }, 164 165 /** 166 * Built HTML containers and fire main functions 167 */ 168 build : function () { 169 var $this = this, bg; 170 171 $( 'body' ).append( html ); 172 173 if ( supportSVG && plugin.settings.useSVG === true ) { 174 bg = $( '#swipebox-close' ).css( 'background-image' ); 175 bg = bg.replace( 'png', 'svg' ); 176 $( '#swipebox-prev, #swipebox-next, #swipebox-close' ).css( { 177 'background-image' : bg 178 } ); 179 } 180 181 if ( isMobile && plugin.settings.removeBarsOnMobile ) { 182 $( '#swipebox-bottom-bar, #swipebox-top-bar' ).remove(); 183 } 184 185 $.each( elements, function() { 186 $( '#swipebox-slider' ).append( '<div class="slide"></div>' ); 187 } ); 188 189 $this.setDim(); 190 $this.actions(); 191 192 if ( isTouch ) { 193 $this.gesture(); 194 } 195
196 // Devices can have both touch and keyboard input so always allow key events 197 $this.keyboard(); 198 199 $this.animBars(); 200 $this.resize(); 201 202 }, 203 204 /** 205 * Set dimensions depending on windows width and height 206 */ 207 setDim : function () { 208 209 var width, height, sliderCss = {}; 210 211 // Reset dimensions on mobile orientation change 212 if ( 'onorientationchange' in window ) { 213 214 window.addEventListener( 'orientationchange', function() { 215 if ( window.orientation === 0 ) { 216 width = winWidth; 217 height = winHeight; 218 } else if ( window.orientation === 90 || window.orientation === -90 ) { 219 width = winHeight; 220 height = winWidth; 221 } 222 }, false ); 223 224 225 } else { 226 227 width = window.innerWidth ? window.innerWidth : $( window ).width(); 228 height = window.innerHeight ? window.innerHeight : $( window ).height(); 229 } 230 231 sliderCss = { 232 width : width, 233 height : height 234 }; 235 236 $( '#swipebox-overlay' ).css( sliderCss ); 237 238 }, 239 240 /** 241 * Reset dimensions on window resize envent 242 */ 243 resize : function () { 244 var $this = this; 245 246 $( window ).resize( function() { 247 $this.setDim(); 248 } ).resize(); 249 }, 250 251 /** 252 * Check if device supports CSS transitions 253 */ 254 supportTransition : function () { 255 256 var prefixes = 'transition WebkitTransition MozTransition OTransition msTransition KhtmlTransition'.split( ' ' ), 257 i; 258 259 for ( i = 0; i < prefixes.length; i++ ) { 260 if ( document.createElement( 'div' ).style[ prefixes[i] ] !== undefined ) { 261 return prefixes[i]; 262 } 263 } 264 return false; 265 }, 266 267 /** 268 * Check if CSS transitions are allowed (options + devicesupport) 269 */ 270 doCssTrans : function () { 271 if ( plugin.settings.useCSS && this.supportTransition() ) { 272 return true; 273 } 274 }, 275 276 /** 277 * Touch navigation 278 */ 279 gesture : function () { 280 281 var $this = this, 282 index, 283 hDistance, 284 vDistance, 285 hDistanceLast, 286 vDistanceLast, 287 hDistancePercent, 288 vSwipe = false, 289 hSwipe = false, 290 hSwipMinDistance = 10, 291 vSwipMinDistance = 50, 292 startCoords = {}, 293 endCoords = {}, 294 bars = $( '#swipebox-top-bar, #swipebox-bottom-bar' ), 295 slider = $( '#swipebox-slider' ); 296 297 bars.addClass( 'visible-bars' ); 298 $this.setTimeout(); 299 300 $( 'body' ).bind( 'touchstart', function( event ) { 301 302 $( this ).addClass( 'touching' ); 303 index = $( '#swipebox-slider .slide' ).index( $( '#swipebox-slider .slide.current' ) ); 304 endCoords = event.originalEvent.targetTouches[0]; 305 startCoords.pageX = event.originalEvent.targetTouches[0].pageX; 306 startCoords.pageY = event.originalEvent.targetTouches[0].pageY; 307 308 $( '#swipebox-slider' ).css( { 309 '-webkit-transform' : 'translate3d(' + currentX +'%, 0, 0)', 310 'transform' : 'translate3d(' + currentX + '%, 0, 0)' 311 } ); 312 313 $( '.touching' ).bind( 'touchmove',function( event ) { 314 event.preventDefault(); 315 event.stopPropagation(); 316 endCoords = event.originalEvent.targetTouches[0]; 317 318 if ( ! hSwipe ) { 319 vDistanceLast = vDistance; 320 vDistance = endCoords.pageY - startCoords.pageY; 321 if ( Math.abs( vDistance ) >= vSwipMinDistance || vSwipe ) { 322 var opacity = 0.75 - Math.abs(vDistance) / slider.height(); 323 324 slider.css( { 'top': vDistance + 'px' } ); 325 slider.css( { 'opacity': opacity } ); 326 327 vSwipe = true; 328 } 329 } 330 331 hDistanceLast = hDistance;
332 hDistance = endCoords.pageX - startCoords.pageX; 333 hDistancePercent = hDistance * 100 / winWidth; 334 335 if ( ! hSwipe && ! vSwipe && Math.abs( hDistance ) >= hSwipMinDistance ) { 336 $( '#swipebox-slider' ).css( { 337 '-webkit-transition' : '', 338 'transition' : '' 339 } ); 340 hSwipe = true; 341 } 342 343 if ( hSwipe ) { 344 345 // swipe left 346 if ( 0 < hDistance ) { 347 348 // first slide 349 if ( 0 === index ) { 350 // console.log( 'first' ); 351 $( '#swipebox-overlay' ).addClass( 'leftSpringTouch' ); 352 } else { 353 // Follow gesture 354 $( '#swipebox-overlay' ).removeClass( 'leftSpringTouch' ).removeClass( 'rightSpringTouch' ); 355 $( '#swipebox-slider' ).css( { 356 '-webkit-transform' : 'translate3d(' + ( currentX + hDistancePercent ) +'%, 0, 0)', 357 'transform' : 'translate3d(' + ( currentX + hDistancePercent ) + '%, 0, 0)' 358 } ); 359 } 360 361 // swipe right 362 } else if ( 0 > hDistance ) { 363 364 // last Slide 365 if ( elements.length === index +1 ) { 366 // console.log( 'last' ); 367 $( '#swipebox-overlay' ).addClass( 'rightSpringTouch' ); 368 } else { 369 $( '#swipebox-overlay' ).removeClass( 'leftSpringTouch' ).removeClass( 'rightSpringTouch' ); 370 $( '#swipebox-slider' ).css( { 371 '-webkit-transform' : 'translate3d(' + ( currentX + hDistancePercent ) +'%, 0, 0)', 372 'transform' : 'translate3d(' + ( currentX + hDistancePercent ) + '%, 0, 0)' 373 } ); 374 } 375 376 } 377 } 378 } ); 379 380 return false; 381 382 } ).bind( 'touchend',function( event ) { 383 event.preventDefault(); 384 event.stopPropagation(); 385 386 $( '#swipebox-slider' ).css( { 387 '-webkit-transition' : '-webkit-transform 0.4s ease', 388 'transition' : 'transform 0.4s ease' 389 } ); 390 391 vDistance = endCoords.pageY - startCoords.pageY;
392 hDistance = endCoords.pageX - startCoords.pageX; 393 hDistancePercent = hDistance*100/winWidth; 394 395 // Swipe to bottom to close 396 if ( vSwipe ) { 397 vSwipe = false; 398 if ( Math.abs( vDistance ) >= 2 * vSwipMinDistance && Math.abs( vDistance ) > Math.abs( vDistanceLast ) ) { 399 var vOffset = vDistance > 0 ? slider.height() : - slider.height(); 400 slider.animate( { top: vOffset + 'px', 'opacity': 0 }, 401 300, 402 function () { 403 $this.closeSlide(); 404 } ); 405 } else { 406 slider.animate( { top: 0, 'opacity': 1 }, 300 ); 407 } 408 409 } else if ( hSwipe ) { 410 411 hSwipe = false; 412 413 // swipeLeft 414 if( hDistance >= hSwipMinDistance && hDistance >= hDistanceLast) { 415 416 $this.getPrev(); 417 418 // swipeRight 419 } else if ( hDistance <= -hSwipMinDistance && hDistance <= hDistanceLast) { 420 421 $this.getNext(); 422 } 423 424 } else { // Top and bottom bars have been removed on touchable devices 425 // tap 426 if ( ! bars.hasClass( 'visible-bars' ) ) { 427 $this.showBars(); 428 $this.setTimeout(); 429 } else { 430 $this.clearTimeout(); 431 $this.hideBars(); 432 } 433 } 434 435 $( '#swipebox-slider' ).css( { 436 '-webkit-transform' : 'translate3d(' + currentX + '%, 0, 0)', 437 'transform' : 'translate3d(' + currentX + '%, 0, 0)' 438 } ); 439 440 $( '#swipebox-overlay' ).removeClass( 'leftSpringTouch' ).removeClass( 'rightSpringTouch' ); 441 $( '.touching' ).off( 'touchmove' ).removeClass( 'touching' ); 442 443 } ); 444 }, 445 446 /** 447 * Set timer to hide the action bars 448 */ 449 setTimeout: function () { 450 if ( plugin.settings.hideBarsDelay > 0 ) { 451 var $this = this; 452 $this.clearTimeout(); 453 $this.timeout = window.setTimeout( function() { 454 $this.hideBars(); 455 }, 456 457 plugin.settings.hideBarsDelay 458 ); 459 } 460 }, 461 462 /** 463 * Clear timer 464 */ 465 clearTimeout: function () { 466 window.clearTimeout( this.timeout ); 467 this.timeout = null; 468 }, 469 470 /** 471 * Show navigation and title bars 472 */ 473 showBars : function () { 474 var bars = $( '#swipebox-top-bar, #swipebox-bottom-bar' ); 475 if ( this.doCssTrans() ) { 476 bars.addClass( 'visible-bars' ); 477 } else { 478 $( '#swipebox-top-bar' ).animate( { top : 0 }, 500 ); 479 $( '#swipebox-bottom-bar' ).animate( { bottom : 0 }, 500 ); 480 setTimeout( function() { 481 bars.addClass( 'visible-bars' ); 482 }, 1000 ); 483 } 484 }, 485 486 /** 487 * Hide navigation and title bars 488 */ 489 hideBars : function () { 490 var bars = $( '#swipebox-top-bar, #swipebox-bottom-bar' ); 491 if ( this.doCssTrans() ) { 492 bars.removeClass( 'visible-bars' ); 493 } else { 494 $( '#swipebox-top-bar' ).animate( { top : '-50px' }, 500 ); 495 $( '#swipebox-bottom-bar' ).animate( { bottom : '-50px' }, 500 ); 496 setTimeout( function() { 497 bars.removeClass( 'visible-bars' ); 498 }, 1000 ); 499 } 500 }, 501 502 /** 503 * Animate navigation and top bars 504 */ 505 animBars : function () { 506 var $this = this, 507 bars = $( '#swipebox-top-bar, #swipebox-bottom-bar' ); 508 509 bars.addClass( 'visible-bars' ); 510 $this.setTimeout(); 511 512 $( '#swipebox-slider' ).click( function() { 513 if ( ! bars.hasClass( 'visible-bars' ) ) { 514 $this.showBars(); 515 $this.setTimeout(); 516 } 517 } ); 518 519 $( '#swipebox-bottom-bar' ).hover( function() { 520 $this.showBars(); 521 bars.addClass( 'visible-bars' ); 522 $this.clearTimeout(); 523 524 }, function() { 525 if ( plugin.settings.hideBarsDelay > 0 ) { 526 bars.removeClass( 'visible-bars' ); 527 $this.setTimeout(); 528 } 529 530 } ); 531 }, 532 533 /** 534 * Keyboard navigation 535 */ 536 keyboard : function () { 537 var $this = this; 538 $( window ).bind( 'keyup', function( event ) { 539 event.preventDefault(); 540 event.stopPropagation(); 541 542 if ( event.keyCode === 37 ) { 543 544 $this.getPrev(); 545 546 } else if ( event.keyCode === 39 ) { 547 548 $this.getNext(); 549 550 } else if ( event.keyCode === 27 ) { 551 552 $this.closeSlide(); 553 } 554 } ); 555 }, 556 557 /** 558 * Navigation events : go to next slide, go to prevous slide and close 559 */ 560 actions : function () { 561 var $this = this, 562 action = 'touchend click'; // Just detect for both event types to allow for multi-input 563 564 if ( elements.length < 2 ) { 565 566 $( '#swipebox-bottom-bar' ).hide(); 567 568 if ( undefined === elements[ 1 ] ) { 569 $( '#swipebox-top-bar' ).hide(); 570 } 571 572 } else { 573 $( '#swipebox-prev' ).bind( action, function( event ) { 574 event.preventDefault(); 575 event.stopPropagation(); 576 $this.getPrev(); 577 $this.setTimeout(); 578 } ); 579 580 $( '#swipebox-next' ).bind( action, function( event ) { 581 event.preventDefault(); 582 event.stopPropagation(); 583 $this.getNext(); 584 $this.setTimeout(); 585 } ); 586 } 587 588 $( '#swipebox-close' ).bind( action, function( event ) { 589 event.preventDefault(); 590 event.stopPropagation(); 591 $this.closeSlide(); 592 } ); 593 }, 594 595 /** 596 * Set current slide 597 */ 598 setSlide : function ( index, isFirst ) { 599 600 isFirst = isFirst || false; 601 602 var slider = $( '#swipebox-slider' ); 603 604 currentX = -index*100; 605 606 if ( this.doCssTrans() ) { 607 slider.css( { 608 '-webkit-transform' : 'translate3d(' + (-index*100)+'%, 0, 0)', 609 'transform' : 'translate3d(' + (-index*100)+'%, 0, 0)' 610 } ); 611 } else { 612 slider.animate( { left : ( -index*100 )+'%' } ); 613 } 614 615 $( '#swipebox-slider .slide' ).removeClass( 'current' ); 616 $( '#swipebox-slider .slide' ).eq( index ).addClass( 'current' ); 617 this.setTitle( index ); 618 619 if ( isFirst ) { 620 slider.fadeIn(); 621 } 622 623 $( '#swipebox-prev, #swipebox-next' ).removeClass( 'disabled' ); 624 625 if ( index === 0 ) { 626 $( '#swipebox-prev' ).addClass( 'disabled' ); 627 } else if ( index === elements.length - 1 && plugin.settings.loopAtEnd !== true ) { 628 $( '#swipebox-next' ).addClass( 'disabled' ); 629 } 630 }, 631 632 /** 633 * Open slide 634 */ 635 openSlide : function ( index ) { 636 $( 'html' ).addClass( 'swipebox-html' ); 637 if ( isTouch ) { 638 $( 'html' ).addClass( 'swipebox-touch' ); 639 640 if ( plugin.settings.hideCloseButtonOnMobile ) { 641 $( 'html' ).addClass( 'swipebox-no-close-button' ); 642 } 643 } else { 644 $( 'html' ).addClass( 'swipebox-no-touch' ); 645 } 646 $( window ).trigger( 'resize' ); // fix scroll bar visibility on desktop 647 this.setSlide( index, true ); 648 }, 649 650 /** 651 * Set a time out if the media is a video 652 */ 653 preloadMedia : function ( index ) { 654 var $this = this, 655 src = null; 656 657 if ( elements[ index ] !== undefined ) { 658 src = elements[ index ].href; 659 } 660 661 if ( ! $this.isVideo( src ) && ( !src || src.indexOf('.mzstatic') === -1 ) ) { 662 663 console.log('Preload' + src); 664 setTimeout( function() { 665 $this.openMedia( index ); 666 }, 1000); 667 668 } else { 669 670 $this.openMedia( index ); 671 672 } 673 }, 674 675 /** 676 * Open 677 */ 678 openMedia : function ( index ) { 679 var $this = this, 680 src, 681 slide; 682 683 if ( elements[ index ] !== undefined ) { 684 src = elements[ index ].href; 685 } 686 687 if ( index < 0 || index >= elements.length ) { 688 return false;
689 } 690 691 slide = $( '#swipebox-slider .slide' ).eq( index ); 692 693 if ( ! $this.isVideo( src ) ) { 694 slide.addClass( 'slide-loading' ); 695 $this.loadMedia( src, function() { 696 slide.removeClass( 'slide-loading' ); 697 slide.html( this ); 698 699 if ( plugin.settings.afterMedia ) { 700 plugin.settings.afterMedia( index ); 701 } 702 } ); 703 } else { 704 slide.html( $this.getVideo( src ) ); 705 706 if ( plugin.settings.afterMedia ) { 707 plugin.settings.afterMedia( index ); 708 } 709 } 710 711 }, 712 713 /** 714 * Set link title attribute as caption 715 */ 716 setTitle : function ( index ) { 717 var title = null; 718 719 $( '#swipebox-title' ).empty(); 720 721 if ( elements[ index ] !== undefined ) { 722 title = elements[ index ].title; 723 } 724 725 if ( title ) { 726 $( '#swipebox-top-bar' ).show(); 727 $( '#swipebox-title' ).append( title ); 728 } else { 729 $( '#swipebox-top-bar' ).hide(); 730 } 731 }, 732 733 /** 734 * Check if the URL is a video 735 */ 736 isVideo : function ( src ) { 737 738 if ( src ) { 739 if ( src.match( /(youtube\.com|youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/) || src.match( /vimeo\.com\/([0-9]*)/ ) || src.match( /youtu\.be\/([a-zA-Z0-9\-_]+)/ ) ) { 740 return true; 741 } 742 743 if ( src.toLowerCase().indexOf( 'swipeboxvideo=1' ) >= 0 ) { 744 return true; 745 } 746 } 747 }, 748 749 /** 750 * Parse URI querystring and: 751 * - overrides value provided via dictionary 752 * - rebuild it again returning a string 753 */ 754 parseUri : function (uri, customData) { 755 var a = document.createElement('a'), 756 qs = {}; 757 758 // Decode the URI 759 a.href = decodeURIComponent( uri ); 760 761 // QueryString to Object 762 if ( a.search ) { 763 qs = JSON.parse( '{"' + a.search.toLowerCase().replace('?','').replace(/&/g,'","').replace(/=/g,'":"') + '"}' ); 764 } 765 766 // Extend with custom data 767 if ( $.isPlainObject( customData ) ) { 768 qs = $.extend( qs, customData, plugin.settings.queryStringData ); // The dev has always the final word 769 } 770 771 // Return querystring as a string 772 return $ 773 .map( qs, function (val, key) { 774 if ( val && val > '' ) { 775 return encodeURIComponent( key ) + '=' + encodeURIComponent( val ); 776 } 777 }) 778 .join('&'); 779 }, 780 781 /** 782 * Get video iframe code from URL 783 */ 784 getVideo : function( url ) { 785 var iframe = '', 786 youtubeUrl = url.match( /((?:www\.)?youtube\.com|(?:www\.)?youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/ ), 787 youtubeShortUrl = url.match(/(?:www\.)?youtu\.be\/([a-zA-Z0-9\-_]+)/), 788 vimeoUrl = url.match( /(?:www\.)?vimeo\.com\/([0-9]*)/ ), 789 qs = ''; 790 791 if ( youtubeUrl || youtubeShortUrl) { 792 if ( youtubeShortUrl ) { 793 youtubeUrl = youtubeShortUrl; 794 } 795 796 console.log( youtubeUrl ); 797 798 qs = ui.parseUri( url, { 799 'autoplay' : ( plugin.settings.autoplayVideos ? '1' : '0' ), 800 'v' : '' 801 }); 802 iframe = '<iframe width="560" height="315" src="https://' + youtubeUrl[1] + '/embed/' + youtubeUrl[2] + '?' + qs + '" frameborder="0" allowfullscreen></iframe>'; 803 804 } else if ( vimeoUrl ) { 805 qs = ui.parseUri( url, { 806 'autoplay' : ( plugin.settings.autoplayVideos ? '1' : '0' ), 807 'byline' : '0', 808 'portrait' : '0', 809 'color': plugin.settings.vimeoColor 810 }); 811 iframe = '<iframe width="560" height="315" src="//player.vimeo.com/video/' + vimeoUrl[1] + '?' + qs + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; 812 813 } else { 814 iframe = '<iframe width="560" height="315" src="' + url + '" frameborder="0" allowfullscreen></iframe>'; 815 } 816 817 return '<div class="swipebox-video-container" style="max-width:' + plugin.settings.videoMaxWidth + 'px"><div class="swipebox-video">' + iframe + '</div></div>'; 818 }, 819 820 /** 821 * Load image 822 */ 823 loadMedia : function ( src, callback ) { 824 // Inline content 825 if ( src.trim().indexOf('#') === 0 ) { 826 callback.call( 827 $('<div>', { 828 'class' : 'swipebox-inline-container' 829 }) 830 .append( 831 $(src) 832 .clone() 833 .toggleClass( plugin.settings.toggleClassOnLoad ) 834 ) 835 ); 836 } 837 // Everything else 838 else { 839 if ( ! this.isVideo( src ) ) { 840 var img = $( '<img>' ).on( 'load', function() { 841 callback.call( img ); 842 } ); 843 844 img.attr( 'src', src ); 845 } 846 } 847 }, 848 849 /** 850 * Get next slide 851 */ 852 getNext : function () { 853 var $this = this, 854 src, 855 index = $( '#swipebox-slider .slide' ).index( $( '#swipebox-slider .slide.current' ) ); 856 if ( index + 1 < elements.length ) { 857 858 src = $( '#swipebox-slider .slide' ).eq( index ).contents().find( 'iframe' ).attr( 'src' ); 859 $( '#swipebox-slider .slide' ).eq( index ).contents().find( 'iframe' ).attr( 'src', src ); 860 index++; 861 $this.setSlide( index ); 862 $this.preloadMedia( index+1 ); 863 if ( plugin.settings.nextSlide ) { 864 plugin.settings.nextSlide(index); 865 } 866 } else { 867 868 if ( plugin.settings.loopAtEnd === true ) { 869 src = $( '#swipebox-slider .slide' ).eq( index ).contents().find( 'iframe' ).attr( 'src' ); 870 $( '#swipebox-slider .slide' ).eq( index ).contents().find( 'iframe' ).attr( 'src', src ); 871 index = 0; 872 $this.preloadMedia( index ); 873 $this.setSlide( index ); 874 $this.preloadMedia( index + 1 ); 875 if ( plugin.settings.nextSlide ) { 876 plugin.settings.nextSlide(index); 877 } 878 } else { 879 $( '#swipebox-overlay' ).addClass( 'rightSpring' ); 880 setTimeout( function() { 881 $( '#swipebox-overlay' ).removeClass( 'rightSpring' ); 882 }, 500 ); 883 } 884 } 885 }, 886 887 /** 888 * Get previous slide 889 */ 890 getPrev : function () { 891 var index = $( '#swipebox-slider .slide' ).index( $( '#swipebox-slider .slide.current' ) ), 892 src; 893 if ( index > 0 ) { 894 src = $( '#swipebox-slider .slide' ).eq( index ).contents().find( 'iframe').attr( 'src' ); 895 $( '#swipebox-slider .slide' ).eq( index ).contents().find( 'iframe' ).attr( 'src', src ); 896 index--; 897 this.setSlide( index ); 898 this.preloadMedia( index-1 ); 899 if ( plugin.settings.prevSlide ) { 900 plugin.settings.prevSlide(index); 901 } 902 } else { 903 $( '#swipebox-overlay' ).addClass( 'leftSpring' ); 904 setTimeout( function() { 905 $( '#swipebox-overlay' ).removeClass( 'leftSpring' ); 906 }, 500 ); 907 } 908 }, 909 /* jshint unused:false */ 910 nextSlide : function ( index ) { 911 // Callback for next slide 912 }, 913 914 prevSlide : function ( index ) { 915 // Callback for prev slide 916 }, 917 918 /** 919 * Close 920 */ 921 closeSlide : function () { 922 $( 'html' ).removeClass( 'swipebox-html' ); 923 $( 'html' ).removeClass( 'swipebox-touch' ); 924 $( window ).trigger( 'resize' ); 925 this.destroy(); 926 }, 927 928 /** 929 * Destroy the whole thing 930 */ 931 destroy : function () { 932 $( window ).unbind( 'keyup' ); 933 $( 'body' ).unbind( 'touchstart' ); 934 $( 'body' ).unbind( 'touchmove' ); 935 $( 'body' ).unbind( 'touchend' ); 936 $( '#swipebox-slider' ).unbind(); 937 $( '#swipebox-overlay' ).remove(); 938 939 if ( ! Array.isArray( elem ) ) { 940 elem.removeData( '_swipebox' ); 941 } 942 943 if ( this.target ) { 944 this.target.trigger( 'swipebox-destroy' ); 945 } 946 947 $.swipebox.isOpen = false;
948 949 if ( plugin.settings.afterClose ) { 950 plugin.settings.afterClose(); 951 } 952 } 953 }; 954 955 plugin.init(); 956 }; 957 958 $.fn.swipebox = function( options ) { 959 960 if ( ! $.data( this, '_swipebox' ) ) { 961 var swipebox = new $.swipebox( this, options ); 962 this.data( '_swipebox', swipebox ); 963 } 964 return this.data( '_swipebox' ); 965 966 }; 967 968}( window, document, 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.