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: true, 12 initialIndexOnArray: 0, 13 removeBarsOnMobile: false, 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="wcpr-swipebox-overlay">\ 42 <div id="wcpr-swipebox-container">\ 43 <div id="wcpr-swipebox-slider"></div>\ 44 <div id="wcpr-swipebox-top-bar">\ 45 <div id="wcpr-swipebox-title"></div>\ 46 </div>\ 47 <div id="wcpr-swipebox-bottom-bar">\ 48 <div id="wcpr-swipebox-arrows">\ 49 <a id="wcpr-swipebox-prev"></a>\ 50 <a id="wcpr-swipebox-next"></a>\ 51 </div>\ 52 </div>\ 53 <a id="wcpr-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 event.preventDefault(); 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('wcpr-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 = $('#wcpr-swipebox-close').css('background-image'); 174 bg = bg.replace('png', 'svg');
175 $('#wcpr-swipebox-prev, #wcpr-swipebox-next, #wcpr-swipebox-close').css({ 176 'background-image': bg 177 }); 178 } 179 180 if (isMobile && plugin.settings.removeBarsOnMobile) { 181 $('#wcpr-swipebox-bottom-bar, #wcpr-swipebox-top-bar').remove(); 182 } 183 184 $.each(elements, function () { 185 $('#wcpr-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 $('#wcpr-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 = $('#wcpr-swipebox-top-bar, #wcpr-swipebox-bottom-bar'), 294 slider = $('#wcpr-swipebox-slider'); 295 296 bars.addClass('visible-bars'); 297 $this.setTimeout(); 298 299 $('body').bind('touchstart', function (event) { 300 301 $(this).addClass('wcpr-touching'); 302 index = $('#wcpr-swipebox-slider .slide').index($('#wcpr-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 $('#wcpr-swipebox-slider').css({
308 '-webkit-transform': 'translate3d(' + currentX + '%, 0, 0)', 309 'transform': 'translate3d(' + currentX + '%, 0, 0)' 310 }); 311 312 $('.wcpr-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 $('#wcpr-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 $('#wcpr-swipebox-overlay').addClass('leftSpringTouch'); 351 } else { 352 // Follow gesture 353 $('#wcpr-swipebox-overlay').removeClass('leftSpringTouch').removeClass('rightSpringTouch'); 354 $('#wcpr-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 $('#wcpr-swipebox-overlay').addClass('rightSpringTouch'); 367 } else { 368 $('#wcpr-swipebox-overlay').removeClass('leftSpringTouch').removeClass('rightSpringTouch'); 369 $('#wcpr-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 $('#wcpr-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 $('#wcpr-swipebox-slider').css({ 435 '-webkit-transform': 'translate3d(' + currentX + '%, 0, 0)', 436 'transform': 'translate3d(' + currentX + '%, 0, 0)' 437 }); 438 439 $('#wcpr-swipebox-overlay').removeClass('leftSpringTouch').removeClass('rightSpringTouch'); 440 $('.wcpr-touching').off('touchmove').removeClass('wcpr-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 = $('#wcpr-swipebox-top-bar, #wcpr-swipebox-bottom-bar'); 474 if (this.doCssTrans()) { 475 bars.addClass('visible-bars'); 476 } else { 477 $('#wcpr-swipebox-top-bar').animate({top: 0}, 500); 478 $('#wcpr-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 = $('#wcpr-swipebox-top-bar, #wcpr-swipebox-bottom-bar'); 490 if (this.doCssTrans()) { 491 bars.removeClass('visible-bars'); 492 } else { 493 $('#wcpr-swipebox-top-bar').animate({top: '-50px'}, 500); 494 $('#wcpr-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 = $('#wcpr-swipebox-top-bar, #wcpr-swipebox-bottom-bar'); 507 508 bars.addClass('visible-bars'); 509 $this.setTimeout(); 510 511 $('#wcpr-swipebox-slider').click(function () { 512 if (!bars.hasClass('visible-bars')) { 513 $this.showBars();
514 $this.setTimeout(); 515 } 516 }); 517 518 $('#wcpr-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 $('#wcpr-swipebox-bottom-bar').hide(); 566 567 if (undefined === elements[1]) { 568 $('#wcpr-swipebox-top-bar').hide(); 569 } 570 571 } else { 572 $('#wcpr-swipebox-prev').bind(action, function (event) { 573 event.preventDefault(); 574 event.stopPropagation(); 575 $this.getPrev(); 576 $this.setTimeout(); 577 }); 578 579 $('#wcpr-swipebox-next').bind(action, function (event) { 580 event.preventDefault(); 581 event.stopPropagation(); 582 $this.getNext(); 583 $this.setTimeout(); 584 }); 585 } 586 587 $('#wcpr-swipebox-close').bind(action, function (event) { 588 event.preventDefault(); 589 event.stopPropagation(); 590 $this.closeSlide(); 591 }); 592 }, 593 594 /** 595 * Set current slide 596 */ 597 setSlide: function (index, isFirst) { 598 599 isFirst = isFirst || false; 600 601 var slider = $('#wcpr-swipebox-slider'); 602 603 currentX = -index * 100; 604 605 if (this.doCssTrans()) { 606 slider.css({ 607 '-webkit-transform': 'translate3d(' + (-index * 100) + '%, 0, 0)', 608 'transform': 'translate3d(' + (-index * 100) + '%, 0, 0)' 609 }); 610 } else { 611 slider.animate({left: (-index * 100) + '%'}); 612 } 613 614 $('#wcpr-swipebox-slider .slide').removeClass('current'); 615 $('#wcpr-swipebox-slider .slide').eq(index).addClass('current'); 616 this.setTitle(index); 617 618 if (isFirst) { 619 slider.fadeIn(); 620 } 621 622 $('#wcpr-swipebox-prev, #wcpr-swipebox-next').removeClass('disabled'); 623 624 if (index === 0) { 625 $('#wcpr-swipebox-prev').addClass('disabled'); 626 } else if (index === elements.length - 1 && plugin.settings.loopAtEnd !== true) { 627 $('#wcpr-swipebox-next').addClass('disabled'); 628 } 629 }, 630 631 /** 632 * Open slide 633 */ 634 openSlide: function (index) { 635 $('html').addClass('wcpr-swipebox-html'); 636 if (isTouch) { 637 $('html').addClass('wcpr-swipebox-touch'); 638 639 if (plugin.settings.hideCloseButtonOnMobile) { 640 $('html').addClass('wcpr-swipebox-no-close-button'); 641 } 642 } else { 643 $('html').addClass('wcpr-swipebox-no-touch'); 644 } 645 $(window).trigger('resize'); // fix scroll bar visibility on desktop 646 this.setSlide(index, true); 647 }, 648 649 /** 650 * Set a time out if the media is a video 651 */ 652 preloadMedia: function (index) { 653 var $this = this, 654 src = null; 655 656 if (elements[index] !== undefined) { 657 src = elements[index].href; 658 } 659 660 if (!$this.isVideo(src)) { 661 setTimeout(function () { 662 $this.openMedia(index); 663 }, 1000); 664 } else { 665 $this.openMedia(index); 666 } 667 }, 668 669 /** 670 * Open 671 */ 672 openMedia: function (index) { 673 var $this = this, 674 src, 675 slide; 676 677 if (elements[index] !== undefined) { 678 src = elements[index].href; 679 } 680 681 if (index < 0 || index >= elements.length) { 682 return false; 683 } 684 685 slide = $('#wcpr-swipebox-slider .slide').eq(index); 686 687 if (!$this.isVideo(src)) { 688 slide.addClass('slide-loading'); 689 $this.loadMedia(src, function () { 690 slide.removeClass('slide-loading'); 691 slide.html(this); 692 693 if (plugin.settings.afterMedia) { 694 plugin.settings.afterMedia(index); 695 } 696 }); 697 } else { 698 slide.html($this.getVideo(src)); 699 700 if (plugin.settings.afterMedia) { 701 plugin.settings.afterMedia(index); 702 } 703 } 704 705 }, 706 707 /** 708 * Set link title attribute as caption 709 */ 710 setTitle: function (index) { 711 var title = null; 712 713 $('#wcpr-swipebox-title').empty(); 714 715 if (elements[index] !== undefined) { 716 title = elements[index].title; 717 } 718 719 if (title) { 720 $('#wcpr-swipebox-top-bar').show(); 721 $('#wcpr-swipebox-title').append(title); 722 } else { 723 $('#wcpr-swipebox-top-bar').hide(); 724 } 725 }, 726 727 /** 728 * Check if the URL is a video 729 */ 730 isVideo: function (src) { 731 732 if (src) { 733 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\-_]+)/)) { 734 return true; 735 } 736 737 if (src.toLowerCase().indexOf('swipeboxvideo=1') >= 0) { 738 739 return true; 740 } 741 } 742 743 }, 744 745 /** 746 * Parse URI querystring and: 747 * - overrides value provided via dictionary 748 * - rebuild it again returning a string 749 */ 750 parseUri: function (uri, customData) { 751 var a = document.createElement('a'), 752 qs = {}; 753 754 // Decode the URI 755 a.href = decodeURIComponent(uri); 756 757 // QueryString to Object 758 if (a.search) { 759 qs = JSON.parse('{"' + a.search.toLowerCase().replace('?', '').replace(/&/g, '","').replace(/=/g, '":"') + '"}'); 760 } 761 762 // Extend with custom data 763 if ($.isPlainObject(customData)) { 764 qs = $.extend(qs, customData, plugin.settings.queryStringData); // The dev has always the final word 765 } 766 767 // Return querystring as a string 768 return $ 769 .map(qs, function (val, key) { 770 if (val && val > '') { 771 return encodeURIComponent(key) + '=' + encodeURIComponent(val); 772 } 773 }) 774 .join('&'); 775 }, 776 777 /** 778 * Get video iframe code from URL 779 */ 780 getVideo: function (url) { 781 var iframe = '', 782 youtubeUrl = url.match(/((?:www\.)?youtube\.com|(?:www\.)?youtube-nocookie\.com)\/watch\?v=([a-zA-Z0-9\-_]+)/), 783 youtubeShortUrl = url.match(/(?:www\.)?youtu\.be\/([a-zA-Z0-9\-_]+)/), 784 vimeoUrl = url.match(/(?:www\.)?vimeo\.com\/([0-9]*)/), 785 qs = ''; 786 if (youtubeUrl || youtubeShortUrl) { 787 if (youtubeShortUrl) { 788 youtubeUrl = youtubeShortUrl; 789 } 790 qs = ui.parseUri(url, { 791 'autoplay': (plugin.settings.autoplayVideos ? '1' : '0'), 792 'v': '' 793 }); 794 iframe = '<iframe width="560" height="315" src="//' + youtubeUrl[1] + '/embed/' + youtubeUrl[2] + '?' + qs + '" frameborder="0" allowfullscreen></iframe>'; 795 796 } else if (vimeoUrl) { 797 qs = ui.parseUri(url, { 798 'autoplay': (plugin.settings.autoplayVideos ? '1' : '0'), 799 'byline': '0', 800 'portrait': '0', 801 'color': plugin.settings.vimeoColor 802 }); 803 iframe = '<iframe width="560" height="315" src="//player.vimeo.com/video/' + vimeoUrl[1] + '?' + qs + '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>'; 804 805 } else { 806 iframe = '<iframe width="560" height="315" src="' + url + '" frameborder="0" allowfullscreen></iframe>'; 807 } 808 809 return '<div class="swipebox-video-container" style="max-width:' + plugin.settings.videoMaxWidth + 'px"><div class="swipebox-video">' + iframe + '</div></div>'; 810 }, 811 812 /** 813 * Load image 814 */ 815 loadMedia: function (src, callback) { 816 // Inline content 817 if (src.trim().indexOf('#') === 0) { 818 callback.call( 819 $('<div>', { 820 'class': 'wcpr-swipebox-inline-container' 821 }) 822 .append( 823 $(src) 824 .clone() 825 .toggleClass(plugin.settings.toggleClassOnLoad) 826 ) 827 ); 828 } 829 // Everything else 830 else { 831 if (!this.isVideo(src)) { 832 var img = $('<img>').on('load', function () { 833 callback.call(img); 834 }); 835 836 img.attr('src', src); 837 } 838 } 839 }, 840 841 /** 842 * Get next slide 843 */ 844 getNext: function () { 845 var $this = this, 846 src, 847 index = $('#wcpr-swipebox-slider .slide').index($('#wcpr-swipebox-slider .slide.current')); 848 if (index + 1 < elements.length) { 849 850 src = $('#wcpr-swipebox-slider .slide').eq(index).contents().find('iframe').attr('src'); 851 $('#wcpr-swipebox-slider .slide').eq(index).contents().find('iframe').attr('src', src); 852 index++; 853 $this.setSlide(index); 854 $this.preloadMedia(index + 1); 855 if (plugin.settings.nextSlide) { 856 plugin.settings.nextSlide(index); 857 } 858 } else { 859 860 if (plugin.settings.loopAtEnd === true) { 861 src = $('#wcpr-swipebox-slider .slide').eq(index).contents().find('iframe').attr('src'); 862 $('#wcpr-swipebox-slider .slide').eq(index).contents().find('iframe').attr('src', src); 863 index = 0; 864 $this.preloadMedia(index); 865 $this.setSlide(index); 866 $this.preloadMedia(index + 1); 867 if (plugin.settings.nextSlide) { 868 plugin.settings.nextSlide(index); 869 } 870 } else { 871 $('#wcpr-swipebox-overlay').addClass('rightSpring'); 872 setTimeout(function () { 873 $('#wcpr-swipebox-overlay').removeClass('rightSpring'); 874 }, 500); 875 } 876 } 877 }, 878 879 /** 880 * Get previous slide 881 */ 882 getPrev: function () { 883 var index = $('#wcpr-swipebox-slider .slide').index($('#wcpr-swipebox-slider .slide.current')), 884 src; 885 if (index > 0) { 886 src = $('#wcpr-swipebox-slider .slide').eq(index).contents().find('iframe').attr('src'); 887 $('#wcpr-swipebox-slider .slide').eq(index).contents().find('iframe').attr('src', src); 888 index--; 889 this.setSlide(index); 890 this.preloadMedia(index - 1); 891 if (plugin.settings.prevSlide) { 892 plugin.settings.prevSlide(index); 893 } 894 } else { 895 $('#wcpr-swipebox-overlay').addClass('leftSpring'); 896 setTimeout(function () { 897 $('#wcpr-swipebox-overlay').removeClass('leftSpring'); 898 }, 500); 899 } 900 }, 901 /* jshint unused:false */ 902 nextSlide: function (index) { 903 // Callback for next slide 904 }, 905 906 prevSlide: function (index) { 907 // Callback for prev slide 908 }, 909 910 /** 911 * Close 912 */ 913 closeSlide: function () { 914 jQuery('.mfp-close').click(); 915 jQuery('.eicon-close').click(); 916 jQuery('#elementor-lightbox').hide(); 917 $('html').removeClass('wcpr-swipebox-html'); 918 $('html').removeClass('wcpr-swipebox-touch'); 919 $(window).trigger('resize'); 920 this.destroy(); 921 }, 922 923 /** 924 * Destroy the whole thing 925 */ 926 destroy: function () { 927 $(window).unbind('keyup'); 928 $('body').unbind('touchstart'); 929 $('body').unbind('touchmove'); 930 $('body').unbind('touchend'); 931 $('#wcpr-swipebox-slider').unbind(); 932 $('#wcpr-swipebox-overlay').remove(); 933 934 if (!$.isArray(elem)) { 935 elem.removeData('_swipebox'); 936 } 937 938 if (this.target) { 939 this.target.trigger('wcpr-swipebox-destroy'); 940 } 941 942 $.swipebox.isOpen = false; 943 944 if (plugin.settings.afterClose) { 945 plugin.settings.afterClose(); 946 } 947 } 948 }; 949 950 plugin.init(); 951 }; 952 953 $.fn.swipebox = function (options)
953{ 954 955 if (!$.data(this, '_swipebox')) { 956 var swipebox = new $.swipebox(this, options); 957 this.data('_swipebox', swipebox); 958 } 959 return this.data('_swipebox'); 960 961 }; 962 963}(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.