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