1/*!----------------------------------------------------------------------------- 2 * Vegas - Fullscreen Backgrounds and Slideshows. 3 * v2.4.0 - built 2017-01-04 4 * Licensed under the MIT License. 5 * http://vegas.jaysalvat.com/ 6 * ---------------------------------------------------------------------------- 7 * Copyright (C) 2010-2017 Jay Salvat 8 * http://jaysalvat.com/ 9 * --------------------------------------------------------------------------*/ 10 11(function ($) { 12 'use strict'; 13 14 var defaults = { 15 slide: 0, 16 delay: 5000, 17 loop: true, 18 preload: false, 19 preloadImage: false, 20 preloadVideo: false, 21 timer: true, 22 overlay: false, 23 autoplay: true, 24 shuffle: false, 25 cover: true, 26 color: null, 27 align: 'center', 28 valign: 'center', 29 firstTransition: null, 30 firstTransitionDuration: null, 31 transition: 'fade', 32 transitionDuration: 1000, 33 transitionRegister: [], 34 animation: null, 35 animationDuration: 'auto', 36 animationRegister: [], 37 slidesToKeep: 1, 38 init: function () {}, 39 play: function () {}, 40 pause: function () {}, 41 walk: function () {}, 42 slides: [ 43 // { 44 // src: null, 45 // color: null, 46 // delay: null, 47 // align: null, 48 // valign: null, 49 // transition: null, 50 // transitionDuration: null, 51 // animation: null, 52 // animationDuration: null, 53 // cover: true, 54 // video: { 55 // src: [], 56 // mute: true, 57 // loop: true 58 // } 59 // ... 60 ] 61 }; 62 63 var videoCache = {}; 64 65 var Vegas = function (elmt, options) { 66 this.elmt = elmt; 67 this.settings = $.extend({}, defaults, $.vegas.defaults, options); 68 this.slide = this.settings.slide; 69 this.total = this.settings.slides.length; 70 this.noshow = this.total < 2; 71 this.paused = !this.settings.autoplay || this.noshow; 72 this.ended = false; 73 this.$elmt = $(elmt); 74 this.$timer = null; 75 this.$overlay = null; 76 this.$slide = null; 77 this.timeout = null; 78 this.first = true; 79 80 this.transitions = [ 81 'fade', 'fade2', 82 'blur', 'blur2', 83 'flash', 'flash2', 84 'negative', 'negative2', 85 'burn', 'burn2', 86 'slideLeft', 'slideLeft2', 87 'slideRight', 'slideRight2', 88 'slideUp', 'slideUp2', 89 'slideDown', 'slideDown2', 90 'zoomIn', 'zoomIn2', 91 'zoomOut', 'zoomOut2', 92 'swirlLeft', 'swirlLeft2', 93 'swirlRight', 'swirlRight2' 94 ]; 95 96 this.animations = [ 97 'kenburns', 98 'kenburnsLeft', 'kenburnsRight', 99 'kenburnsUp', 'kenburnsUpLeft', 'kenburnsUpRight', 100 'kenburnsDown', 'kenburnsDownLeft', 'kenburnsDownRight' 101 ]; 102 103 if (this.settings.transitionRegister instanceof Array === false) { 104 this.settings.transitionRegister = [ this.settings.transitionRegister ]; 105 } 106 107 if (this.settings.animationRegister instanceof Array === false) { 108 this.settings.animationRegister = [ this.settings.animationRegister ]; 109 } 110 111 this.transitions = this.transitions.concat(this.settings.transitionRegister); 112 this.animations = this.animations.concat(this.settings.animationRegister); 113 114 this.support = { 115 objectFit: 'objectFit' in document.body.style, 116 transition: 'transition' in document.body.style || 'WebkitTransition' in document.body.style, 117 video: $.vegas.isVideoCompatible() 118 }; 119 120 if (this.settings.shuffle === true) { 121 this.shuffle(); 122 } 123 124 this._init(); 125 }; 126 127 Vegas.prototype = { 128 _init: function () { 129 var $wrapper, 130 $overlay, 131 $timer, 132 isBody = this.elmt.tagName === 'BODY', 133 timer = this.settings.timer,
134 overlay = this.settings.overlay, 135 self = this; 136 137 // Preloading 138 this._preload(); 139 140 // Wrapper with content 141 if (!isBody) { 142 // this.$elmt.css('height', this.$elmt.css('height')); 143 144 $wrapper = $('<div class="vegas-wrapper">') 145 .css('overflow', this.$elmt.css('overflow')) 146 .css('padding', this.$elmt.css('padding')); 147 148 // Some browsers don't compute padding shorthand 149 if (!this.$elmt.css('padding')) { 150 $wrapper 151 .css('padding-top', this.$elmt.css('padding-top')) 152 .css('padding-bottom', this.$elmt.css('padding-bottom')) 153 .css('padding-left', this.$elmt.css('padding-left')) 154 .css('padding-right', this.$elmt.css('padding-right')); 155 } 156 157 this.$elmt.clone(true).children().appendTo($wrapper); 158 this.elmt.innerHTML = ''; 159 } 160 161 // Timer 162 if (timer && this.support.transition) { 163 $timer = $('<div class="vegas-timer"><div class="vegas-timer-progress">'); 164 this.$timer = $timer; 165 this.$elmt.prepend($timer); 166 } 167 168 // Overlay 169 if (overlay) { 170 $overlay = $('<div class="vegas-overlay">'); 171 172 if (typeof overlay === 'string') { 173 $overlay.css('background-image', 'url(' + overlay + ')'); 174 } 175 176 this.$overlay = $overlay; 177 this.$elmt.prepend($overlay); 178 } 179 180 // Container 181 this.$elmt.addClass('vegas-container'); 182 183 if (!isBody) { 184 this.$elmt.append($wrapper); 185 } 186 187 setTimeout(function () { 188 self.trigger('init'); 189 self._goto(self.slide); 190 191 if (self.settings.autoplay) { 192 self.trigger('play'); 193 } 194 }, 1); 195 }, 196 197 _preload: function () { 198 var img, i; 199 200 for (i = 0; i < this.settings.slides.length; i++) { 201 if (this.settings.preload || this.settings.preloadImages) { 202 if (this.settings.slides[i].src) { 203 img = new Image(); 204 img.src = this.settings.slides[i].src; 205 } 206 } 207 208 if (this.settings.preload || this.settings.preloadVideos) { 209 if (this.support.video && this.settings.slides[i].video) { 210 if (this.settings.slides[i].video instanceof Array) { 211 this._video(this.settings.slides[i].video); 212 } else { 213 this._video(this.settings.slides[i].video.src); 214 } 215 } 216 } 217 } 218 }, 219 220 _random: function (array) { 221 return array[Math.floor(Math.random() * array.length)]; 222 }, 223 224 _slideShow: function () { 225 var self = this; 226 227 if (this.total > 1 && !this.ended && !this.paused && !this.noshow) { 228 this.timeout = setTimeout(function () { 229 self.next(); 230 }, this._options('delay')); 231 } 232 }, 233 234 _timer: function (state) { 235 var self = this; 236 237 clearTimeout(this.timeout); 238 239 if (!this.$timer) { 240 return; 241 } 242 243 this.$timer 244 .removeClass('vegas-timer-running') 245 .find('div') 246 .css('transition-duration', '0ms'); 247 248 if (this.ended || this.paused || this.noshow) { 249 return; 250 } 251 252 if (state) { 253 setTimeout(function () { 254 self.$timer 255 .addClass('vegas-timer-running') 256 .find('div') 257 .css('transition-duration', self._options('delay') - 100 + 'ms'); 258 }, 100); 259 } 260 }, 261 262 _video: function (srcs) { 263 var video, 264 source, 265 cacheKey = srcs.toString(); 266 267 if (videoCache[cacheKey]) { 268 return videoCache[cacheKey]; 269 } 270 271 if (srcs instanceof Array === false) { 272 srcs = [ srcs ]; 273 } 274 275 video = document.createElement('video'); 276 video.preload = true; 277 278 srcs.forEach(function (src) { 279 source = document.createElement('source'); 280 source.src = src; 281 video.appendChild(source); 282 }); 283 284 videoCache[cacheKey] = video; 285 286 return video; 287 }, 288 289 _fadeOutSound: function (video, duration) { 290 var self = this, 291 delay = duration / 10, 292 volume = video.volume - 0.09; 293 294 if (volume > 0) { 295 video.volume = volume; 296 297 setTimeout(function () { 298 self._fadeOutSound(video, duration); 299 }, delay); 300 } else { 301 video.pause(); 302 } 303 }, 304 305 _fadeInSound: function (video, duration) { 306 var self = this, 307 delay = duration / 10,
308 volume = video.volume + 0.09; 309 310 if (volume < 1) { 311 video.volume = volume; 312 313 setTimeout(function () { 314 self._fadeInSound(video, duration); 315 }, delay); 316 } 317 }, 318 319 _options: function (key, i) { 320 if (i === undefined) { 321 i = this.slide; 322 } 323 324 if (this.settings.slides[i][key] !== undefined) { 325 return this.settings.slides[i][key]; 326 } 327 328 return this.settings[key]; 329 }, 330 331 _goto: function (nb) { 332 if (typeof this.settings.slides[nb] === 'undefined') { 333 nb = 0; 334 } 335 336 this.slide = nb; 337 338 var $slide, 339 $inner, 340 $video, 341 $slides = this.$elmt.children('.vegas-slide'), 342 src = this.settings.slides[nb].src, 343 videoSettings = this.settings.slides[nb].video, 344 delay = this._options('delay'), 345 align = this._options('align'), 346 valign = this._options('valign'), 347 cover = this._options('cover'), 348 color = this._options('color') || this.$elmt.css('background-color'), 349 self = this, 350 total = $slides.length, 351 video, 352 img; 353 354 var transition = this._options('transition'), 355 transitionDuration = this._options('transitionDuration'), 356 animation = this._options('animation'), 357 animationDuration = this._options('animationDuration'); 358 359 if (this.settings.firstTransition && this.first) { 360 transition = this.settings.firstTransition || transition; 361 } 362 363 if (this.settings.firstTransitionDuration && this.first) { 364 transitionDuration = this.settings.firstTransitionDuration || transitionDuration; 365 } 366 367 if (this.first) { 368 this.first = false; 369 } 370 371 if (cover !== 'repeat') { 372 if (cover === true) { 373 cover = 'cover'; 374 } else if (cover === false) { 375 cover = 'contain'; 376 } 377 } 378 379 if (transition === 'random' || transition instanceof Array) { 380 if (transition instanceof Array) { 381 transition = this._random(transition); 382 } else { 383 transition = this._random(this.transitions); 384 } 385 } 386 387 if (animation === 'random' || animation instanceof Array) { 388 if (animation instanceof Array) { 389 animation = this._random(animation); 390 } else { 391 animation = this._random(this.animations); 392 } 393 } 394 395 if (transitionDuration === 'auto' || transitionDuration > delay) { 396 transitionDuration = delay; 397 } 398 399 if (animationDuration === 'auto') { 400 animationDuration = delay; 401 } 402 403 $slide = $('<div class="vegas-slide"></div>'); 404 405 if (this.support.transition && transition) { 406 $slide.addClass('vegas-transition-' + transition); 407 } 408 409 // Video 410 411 if (this.support.video && videoSettings) { 412 if (videoSettings instanceof Array) { 413 video = this._video(videoSettings); 414 } else { 415 video = this._video(videoSettings.src); 416 } 417 418 video.loop = videoSettings.loop !== undefined ? videoSettings.loop : true; 419 video.muted = videoSettings.mute !== undefined ? videoSettings.mute : true; 420 421 if (video.muted === false) { 422 video.volume = 0; 423 this._fadeInSound(video, transitionDuration); 424 } else { 425 video.pause(); 426 } 427 428 $video = $(video) 429 .addClass('vegas-video') 430 .css('background-color', color); 431 432 if (this.support.objectFit) { 433 $video 434 .css('object-position', align + ' ' + valign) 435 .css('object-fit', cover) 436 .css('width', '100%') 437 .css('height', '100%'); 438 } else if (cover === 'contain') { 439 $video 440 .css('width', '100%') 441 .css('height', '100%'); 442 } 443 444 $slide.append($video); 445 446 // Image 447 448 } else { 449 img = new Image(); 450
451 $inner = $('<div class="vegas-slide-inner"></div>') 452 .css('background-image', 'url("' + src + '")') 453 .css('background-color', color) 454 .css('background-position', align + ' ' + valign); 455 456 if (cover === 'repeat') { 457 $inner.css('background-repeat', 'repeat'); 458 } else { 459 $inner.css('background-size', cover); 460 } 461 462 if (this.support.transition && animation) { 463 $inner 464 .addClass('vegas-animation-' + animation) 465 .css('animation-duration', animationDuration + 'ms'); 466 } 467 468 $slide.append($inner); 469 } 470 471 if (!this.support.transition) { 472 $slide.css('display', 'none'); 473 } 474 475 if (total) { 476 $slides.eq(total - 1).after($slide); 477 } else { 478 this.$elmt.prepend($slide); 479 } 480 481 $slides 482 .css('transition', 'all 0ms') 483 .each(function () { 484 this.className = 'vegas-slide'; 485 486 if (this.tagName === 'VIDEO') { 487 this.className += ' vegas-video'; 488 } 489 490 if (transition) { 491 this.className += ' vegas-transition-' + transition; 492 this.className += ' vegas-transition-' + transition + '-in'; 493 } 494 } 495 ); 496 497 self._timer(false); 498 499 function go () { 500 self._timer(true); 501 502 setTimeout(function () { 503 if (transition) { 504 if (self.support.transition) { 505 $slides 506 .css('transition', 'all ' + transitionDuration + 'ms') 507 .addClass('vegas-transition-' + transition + '-out'); 508 509 $slides.each(function () { 510 var video = $slides.find('video').get(0); 511 512 if (video) { 513 video.volume = 1; 514 self._fadeOutSound(video, transitionDuration); 515 } 516 }); 517 518 $slide 519 .css('transition', 'all ' + transitionDuration + 'ms') 520 .addClass('vegas-transition-' + transition + '-in'); 521 } else { 522 $slide.fadeIn(transitionDuration); 523 } 524 } 525 526 for (var i = 0; i < $slides.length - self.settings.slidesToKeep; i++) { 527 $slides.eq(i).remove(); 528 } 529 530 self.trigger('walk'); 531 self._slideShow(); 532 }, 100); 533 } 534 if (video) { 535 if (video.readyState === 4) { 536 video.currentTime = 0; 537 } 538 539 video.play(); 540 go(); 541 } else { 542 img.src = src; 543 544 if (img.complete) { 545 go(); 546 } else { 547 img.onload = go; 548 } 549 } 550 }, 551 552 _end: function () { 553 this.ended = true; 554 this._timer(false); 555 this.trigger('end'); 556 }, 557 558 shuffle: function () { 559 var temp, 560 rand; 561 562 for (var i = this.total - 1; i > 0; i--) { 563 rand = Math.floor(Math.random() * (i + 1)); 564 temp = this.settings.slides[i]; 565 566 this.settings.slides[i] = this.settings.slides[rand]; 567 this.settings.slides[rand] = temp; 568 } 569 }, 570 571 play: function () { 572 if (this.paused) { 573 this.paused = false; 574 this.next(); 575 this.trigger('play'); 576 } 577 }, 578 579 pause: function () { 580 this._timer(false); 581 this.paused = true; 582 this.trigger('pause'); 583 }, 584 585 toggle: function () { 586 if (this.paused) { 587 this.play(); 588 } else { 589 this.pause(); 590 } 591 }, 592 593 playing: function () { 594 return !this.paused && !this.noshow; 595 }, 596 597 current: function (advanced) { 598 if (advanced) { 599 return { 600 slide: this.slide, 601 data: this.settings.slides[this.slide] 602 }; 603 } 604 return this.slide; 605 }, 606 607 jump: function (nb) { 608 if (nb < 0 || nb > this.total - 1 || nb === this.slide) { 609 return; 610 } 611 612 this.slide = nb; 613 this._goto(this.slide); 614 }, 615 616 next: function () { 617 this.slide++; 618 619 if (this.slide >= this.total) { 620 if (!this.settings.loop) { 621 return this._end(); 622 } 623 624 this.slide = 0; 625 } 626 627 this._goto(this.slide); 628 }, 629 630 previous: function () { 631 this.slide--; 632 633 if (this.slide < 0) { 634 if (!this.settings.loop) { 635 this.slide++; 636 return; 637 } else { 638 this.slide = this.total - 1; 639 } 640 } 641 642 this._goto(this.slide); 643 }, 644 645 trigger: function (fn) { 646 var params = []; 647 648 if (fn === 'init') { 649 params = [ this.settings ]; 650 } else { 651 params = [ 652 this.slide, 653 this.settings.slides[this.slide] 654 ]; 655 } 656 657 this.$elmt.trigger('vegas' + fn, params); 658 659 if (typeof this.settings[fn] === 'function') { 660 this.settings[fn].apply(this.$elmt, params); 661 } 662 }, 663 664 options: function (key, value) { 665 var oldSlides = this.settings.slides.slice(); 666 667 if (typeof key === 'object') { 668 this.settings = $.extend({}, defaults, $.vegas.defaults, key); 669 } else if (typeof key === 'string') { 670 if (value === undefined) { 671 return this.settings[key]; 672 } 673 this.settings[key] = value; 674 } else { 675 return this.settings; 676 } 677 678 // In case slides have changed 679 if (this.settings.slides !== oldSlides) { 680 this.total = this.settings.slides.length; 681 this.noshow = this.total < 2; 682 this._preload(); 683 } 684 }, 685 686 destroy: function () { 687 clearTimeout(this.timeout); 688 689 this.$elmt.removeClass('vegas-container'); 690 this.$elmt.find('> .vegas-slide').remove(); 691 this.$elmt.find('> .vegas-wrapper').clone(true).children().appendTo(this.$elmt); 692 this.$elmt.find('> .vegas-wrapper').remove(); 693 694 if (this.settings.timer) { 695 this.$timer.remove(); 696 } 697 698 if (this.settings.overlay) { 699 this.$overlay.remove(); 700 } 701 702 this.elmt._vegas = null; 703 } 704 }; 705 706 $.fn.vegas = function(options) { 707 var args = arguments, 708 error = false, 709 returns; 710 711 if (options === undefined || typeof options === 'object') { 712 return this.each(function () { 713 if (!this._vegas) { 714 this._vegas = new Vegas(this, options); 715 } 716 }); 717 } else if (typeof options === 'string') { 718 this.each(function () { 719 var instance = this._vegas; 720 721 if (!instance) { 722 throw new Error('No Vegas applied to this element.'); 723 } 724 725 if (typeof instance[options] === 'function' && options[0] !== '_') { 726 returns = instance[options].apply(instance, [].slice.call(args, 1)); 727 } else { 728 error = true; 729 } 730 }); 731 732 if (error) { 733 throw new Error('No method "' + options + '" in Vegas.'); 734 } 735 736 return returns !== undefined ? returns : this; 737 } 738 }; 739 740 $.vegas = {}; 741 $.vegas.defaults = defaults; 742 743 $.vegas.isVideoCompatible = function () {
744 return !/(Android|webOS|Phone|iPad|iPod|BlackBerry|Windows Phone)/i.test(navigator.userAgent); 745 }; 746 747})(window.jQuery || window.Zepto);
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.