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