1/* 2* jQuery Orbit Plugin 1.4.0 3* www.ZURB.com/playground 4* Copyright ZURB 5* Free to use under the MIT license. 6* http://www.opensource.org/licenses/mit-license.php 7*/ 8 9(function($) { 10 11 'use strict'; 12 13 $.fn.findFirstImage = function () { 14 return this.first() 15 .find('img') 16 .andSelf().filter('img') 17 .first(); 18 }; 19 20 var ORBIT = { 21 22 defaults: { 23 animation: 'horizontal-push', // fade, horizontal-slide, vertical-slide, horizontal-push, vertical-push 24 animationSpeed: 450, // how fast animtions are 25 timer: true, // true or false to have the timer 26 advanceSpeed: 4000, // if timer is enabled, time between transitions 27 pauseOnHover: false, // if you hover pauses the slider 28 startClockOnMouseOut: false, // if clock should start on MouseOut 29 startClockOnMouseOutAfter: 1000, // how long after MouseOut should the timer start again 30 directionalNav: true, // manual advancing directional navs 31 directionalNavRightText: 'Right', // text of right directional element for accessibility 32 directionalNavLeftText: 'Left', // text of left directional element for accessibility 33 captions: true, // do you want captions? 34 captionAnimation: 'fade', // fade, slideOpen, none 35 captionAnimationSpeed: 600, // if so how quickly should they animate in 36 resetTimerOnClick: false, // true resets the timer instead of pausing slideshow progress on manual navigation 37 bullets: false, // true or false to activate the bullet navigation 38 bulletThumbs: false, // thumbnails for the bullets 39 bulletThumbLocation: '', // location from this file where thumbs will be 40 afterSlideChange: $.noop, // empty function 41 afterLoadComplete: $.noop, //callback to execute after everything has been loaded 42 fluid: true, 43 centerBullets: true // center bullet nav with js, turn this off if you want to position the bullet nav manually 44 }, 45 46 activeSlide: 0, 47 numberSlides: 0, 48 orbitWidth: null, 49 orbitHeight: null, 50 locked: null, 51 timerRunning: null, 52 degrees: 0, 53 wrapperHTML: '<div class="orbit-wrapper" />', 54 timerHTML: '<div class="timer"><span class="mask"><span class="rotator"></span></span><span class="pause"></span></div>', 55 captionHTML: '<div class="orbit-caption"></div>', 56 directionalNavHTML: '<div class="slider-nav"><span class="right"></span><span class="left"></span></div>', 57 bulletHTML: '<ul class="orbit-bullets"></ul>', 58 59 init: function (element, options) { 60 var $imageSlides, 61 imagesLoadedCount = 0, 62 self = this; 63 64 // Bind functions to correct context 65 this.clickTimer = $.proxy(this.clickTimer, this); 66 this.addBullet = $.proxy(this.addBullet, this); 67 this.resetAndUnlock = $.proxy(this.resetAndUnlock, this); 68 this.stopClock = $.proxy(this.stopClock, this); 69 this.startTimerAfterMouseLeave = $.proxy(this.startTimerAfterMouseLeave, this); 70 this.clearClockMouseLeaveTimer = $.proxy(this.clearClockMouseLeaveTimer, this); 71 this.rotateTimer = $.proxy(this.rotateTimer, this); 72 73 this.options = $.extend({}, this.defaults, options); 74 if (this.options.timer === 'false') this.options.timer = false; 75 if (this.options.captions === 'false') this.options.captions = false; 76 if (this.options.directionalNav === 'false') this.options.directionalNav = false; 77 78 this.$element = $(element); 79 this.$wrapper = this.$element.wrap(this.wrapperHTML).parent(); 80 this.$slides = this.$element.children('img, a, div'); 81 82 this.$element.bind('orbit.next', function () { 83 self.shift('next'); 84 }); 85 86 this.$element.bind('orbit.prev', function () { 87 self.shift('prev'); 88 }); 89 90 this.$element.bind('orbit.goto', function (event, index) { 91 self.shift(index); 92 }); 93 94 this.$element.bind('orbit.start', function (event, index) { 95 self.startClock(); 96 }); 97 98 this.$element.bind('orbit.stop', function (event, index) { 99 self.stopClock(); 100 }); 101 102 $imageSlides = this.$slides.filter('img'); 103 104 if ($imageSlides.length === 0) { 105 this.loaded(); 106 } else { 107 $imageSlides.bind('imageready', function () { 108 imagesLoadedCount += 1; 109 if (imagesLoadedCount === $imageSlides.length) { 110 self.loaded(); 111 } 112 }); 113 } 114 }, 115 116 loaded: function () { 117 this.$element 118 .addClass('orbit') 119 .css({width: '1px', height: '1px'}); 120 121 this.$slides.addClass('orbit-slide'); 122 123 this.setDimentionsFromLargestSlide(); 124 this.updateOptionsIfOnlyOneSlide(); 125 this.setupFirstSlide(); 126 127 if (this.options.timer) { 128 this.setupTimer(); 129 this.startClock(); 130 } 131 132 if (this.options.captions) { 133 this.setupCaptions(); 134 } 135 136 if (this.options.directionalNav) { 137 this.setupDirectionalNav(); 138 } 139 140 if (this.options.bullets) { 141 this.setupBulletNav(); 142 this.setActiveBullet(); 143 } 144 145 this.options.afterLoadComplete.call(this); 146 }, 147 148 currentSlide: function () { 149 return this.$slides.eq(this.activeSlide); 150 }, 151 152 setDimentionsFromLargestSlide: function () { 153 //Collect all slides and set slider size of largest image 154 var self = this, 155 $fluidPlaceholder; 156 157 self.$element.add(self.$wrapper).width(this.$slides.first().width()); 158 self.$element.add(self.$wrapper).height(this.$slides.first().height()); 159 self.orbitWidth = this.$slides.first().width(); 160 self.orbitHeight = this.$slides.first().height(); 161 $fluidPlaceholder = this.$slides.first().findFirstImage().clone(); 162 163 164 this.$slides.each(function () { 165 var slide = $(this), 166 slideWidth = slide.width(), 167 slideHeight = slide.height(); 168 169 if (slideWidth > self.$element.width()) { 170 self.$element.add(self.$wrapper).width(slideWidth); 171 self.orbitWidth = self.$element.width(); 172 } 173 if (slideHeight > self.$element.height()) { 174 self.$element.add(self.$wrapper).height(slideHeight); 175 self.orbitHeight = self.$element.height(); 176 $fluidPlaceholder = $(this).findFirstImage().clone(); 177 } 178 self.numberSlides += 1; 179 }); 180 181 if (this.options.fluid) { 182 if (typeof this.options.fluid === "string") { 183 $fluidPlaceholder = $('<img src="http://placehold.it/'
183+ this.options.fluid + '" />'); 184 } 185 186 self.$element.prepend($fluidPlaceholder); 187 $fluidPlaceholder.addClass('fluid-placeholder'); 188 self.$element.add(self.$wrapper).css({width: 'inherit'}); 189 self.$element.add(self.$wrapper).css({height: 'inherit'}); 190 191 $(window).bind('resize', function () { 192 self.orbitWidth = self.$element.width(); 193 self.orbitHeight = self.$element.height(); 194 }); 195 } 196 }, 197 198 //Animation locking functions 199 lock: function () { 200 this.locked = true; 201 }, 202 203 unlock: function () { 204 this.locked = false; 205 }, 206 207 updateOptionsIfOnlyOneSlide: function () { 208 if(this.$slides.length === 1) { 209 this.options.directionalNav = false; 210 this.options.timer = false; 211 this.options.bullets = false; 212 } 213 }, 214 215 setupFirstSlide: function () { 216 //Set initial front photo z-index and fades it in 217 var self = this; 218 219 //webkit video fix 220 this.$slides.find('.video').hide(); 221 if( this.$slides.first().find('.video').length > 0) { 222 this.$slides.first().find('.video').show(); 223 this.$slides.first().find('.mejs-mediaelement').css('visibility','hidden'); 224 } 225 226 if( $('#featured').attr('data-caption-animation') == '0' ){ 227 $('#featured').find('.post-title').children().css({'opacity':1, 'margin-top': 0}); 228 } 229 230
231 //reset opacity on all slides 232 this.$slides.css({"opacity" : 0}); 233 this.$slides.first().css({"opacity" : 1}); 234 235 this.$slides.first() 236 .css({"z-index" : 3}) 237 .fadeIn(function() { 238 239 if( $('#featured').attr('data-caption-animation') == '1' ){ 240 241 $('#featured').find('.post-title').children().css({'opacity':0, 'margin-top': 20}); 242 self.$slides.first().find('.post-title').children().each(function(i){ 243 $(this).stop().delay(i*320).animate({ 244 'opacity' : 1, 245 'margin-top' : 0 246 },600,'easeOutSine'); 247 }); 248 } 249 250 //brings in all other slides IF css declares a display: none 251 self.$slides.css({"display":"block"}); 252 }); 253 }, 254 255 startClock: function () { 256 var self = this; 257 258 if(!this.options.timer) { 259 return false; 260 } 261 262 if (this.$timer.is(':hidden')) { 263 this.clock = setInterval(function () { 264 self.$element.trigger('orbit.next'); 265 }, this.options.advanceSpeed); 266 } else { 267 this.timerRunning = true; 268 this.$pause.removeClass('active'); 269 this.clock = setInterval(this.rotateTimer, this.options.advanceSpeed / 180); 270 } 271 }, 272 273 rotateTimer: function (reset) { 274 var degreeCSS = "rotate(" + this.degrees + "deg)"; 275 this.degrees += 2; 276 this.$rotator.css({ 277 "-webkit-transform": degreeCSS, 278 "-moz-transform": degreeCSS, 279 "-o-transform": degreeCSS 280 }); 281 if(this.degrees > 180) { 282 this.$rotator.addClass('move'); 283 this.$mask.addClass('move'); 284 } 285 if(this.degrees > 360 || reset) { 286 this.$rotator.removeClass('move'); 287 this.$mask.removeClass('move'); 288 this.degrees = 0; 289 this.$element.trigger('orbit.next'); 290 } 291 }, 292 293 stopClock: function () { 294 if (!this.options.timer) { 295 return false; 296 } else { 297 this.timerRunning = false; 298 clearInterval(this.clock); 299 this.$pause.addClass('active'); 300 } 301 }, 302 303 setupTimer: function () { 304 this.$timer = $(this.timerHTML); 305 this.$wrapper.append(this.$timer); 306 307 this.$rotator = this.$timer.find('.rotator'); 308 this.$mask = this.$timer.find('.mask'); 309 this.$pause = this.$timer.find('.pause'); 310 311 this.$timer.click(this.clickTimer); 312 313 if (this.options.startClockOnMouseOut) { 314 this.$wrapper.mouseleave(this.startTimerAfterMouseLeave); 315 this.$wrapper.mouseenter(this.clearClockMouseLeaveTimer); 316 } 317 318 if (this.options.pauseOnHover) { 319 this.$wrapper.mouseenter(this.stopClock); 320 } 321 }, 322 323 startTimerAfterMouseLeave: function () { 324 var self = this; 325 326 this.outTimer = setTimeout(function() { 327 if(!self.timerRunning){ 328 self.startClock(); 329 } 330 }, this.options.startClockOnMouseOutAfter); 331 }, 332 333 clearClockMouseLeaveTimer: function () { 334 clearTimeout(this.outTimer); 335 }, 336 337 clickTimer: function () { 338 if(!this.timerRunning) { 339 this.startClock(); 340 } else { 341 this.stopClock(); 342 } 343 }, 344 345 setupCaptions: function () { 346 this.$caption = $(this.captionHTML); 347 this.$wrapper.append(this.$caption); 348 this.setCaption(); 349 }, 350 351 setCaption: function () { 352 var captionLocation = this.currentSlide().attr('data-caption'), 353 captionHTML; 354 355 if (!this.options.captions) { 356 return false; 357 } 358 359 //Set HTML for the caption if it exists 360 if (captionLocation) { 361 captionHTML = $(captionLocation).html(); //get HTML from the matching HTML entity 362 this.$caption 363 .attr('id', captionLocation) // Add ID caption TODO why is the id being set? 364 .html(captionHTML); // Change HTML in Caption 365 //Animations for Caption entrances 366 switch (this.options.captionAnimation) { 367 case 'none': 368 this.$caption.show(); 369 break; 370 case 'fade': 371 this.$caption.fadeIn(this.options.captionAnimationSpeed); 372 break; 373 case 'slideOpen': 374 this.$caption.slideDown(this.options.captionAnimationSpeed); 375 break; 376 } 377 } else { 378 //Animations for Caption exits 379 switch (this.options.captionAnimation) { 380 case 'none': 381 this.$caption.hide(); 382 break; 383 case 'fade': 384 this.$caption.fadeOut(this.options.captionAnimationSpeed); 385 break; 386 case 'slideOpen':
387 this.$caption.slideUp(this.options.captionAnimationSpeed); 388 break; 389 } 390 } 391 }, 392 393 setupDirectionalNav: function () { 394 var self = this, 395 $directionalNav = $(this.directionalNavHTML); 396 397 $directionalNav.find('.right').html(this.options.directionalNavRightText); 398 $directionalNav.find('.left').html(this.options.directionalNavLeftText); 399 400 this.$wrapper.append($directionalNav); 401 402 this.$wrapper.find('.slider-nav > span.left').click(function () { 403 self.stopClock(); 404 if (self.options.resetTimerOnClick) { 405 self.rotateTimer(true); 406 self.startClock(); 407 } 408 $(".mejs-pause").trigger('click'); 409 self.$element.trigger('orbit.prev'); 410 }); 411 412 this.$wrapper.find('.slider-nav > span.right').click(function () { 413 self.stopClock(); 414 if (self.options.resetTimerOnClick) { 415 self.rotateTimer(true); 416 self.startClock(); 417 } 418 $(".mejs-pause").trigger('click'); 419 self.$element.trigger('orbit.next'); 420 }); 421 422 this.$wrapper.find('.jp-play, .more-info a, #featured article .post-title > a, .video, .mejs-button, button, .mejs-controls, .mejs-playpause-button').on('click',function () { 423 self.stopClock(); 424 }); 425 426 this.$wrapper.find('button, .mejs-controls, .mejs-playpause-button').mousedown(function(){ 427 self.stopClock(); 428 $(this).parents('.video').find('.mejs-mediaelement').css('visibility','visible'); 429 }); 430 431 }, 432 433 setupBulletNav: function () { 434 this.$bullets = $(this.bulletHTML); 435 this.$wrapper.append(this.$bullets); 436 this.$slides.each(this.addBullet); 437 this.$element.addClass('with-bullets'); 438 if (this.options.centerBullets) this.$bullets.css('margin-left', -this.$bullets.width() / 2); 439 }, 440 441 addBullet: function (index, slide) { 442 var position = index + 1, 443 $li = $('<li>' + (position) + '</li>'), 444 thumbName, 445 self = this; 446 447 if (this.options.bulletThumbs) { 448 thumbName = $(slide).attr('data-thumb'); 449 if (thumbName) { 450 $li 451 .addClass('has-thumb') 452 .css({background: "url(" + this.options.bulletThumbLocation + thumb
452Name + ") no-repeat"}); 453 } 454 } 455 this.$bullets.append($li); 456 $li.data('index', index); 457 $li.click(function () { 458 self.stopClock(); 459 if (self.options.resetTimerOnClick) { 460 self.rotateTimer(true); 461 self.startClock(); 462 } 463 self.$element.trigger('orbit.goto', [$li.data('index')]); 464 }); 465 }, 466 467 setActiveBullet: function () { 468 if(!this.options.bullets) { return false; } else { 469 this.$bullets.find('li') 470 .removeClass('active') 471 .eq(this.activeSlide) 472 .addClass('active'); 473 } 474 }, 475 476 resetAndUnlock: function () { 477 //reset caption animation 478 if( $('#featured').attr('data-caption-animation') == '1' ){ 479 this.$slides.find('.post-title').children().stop(true,true).css({'opacity':0, 'margin-top':20}); 480 } 481 482 this.$slides.eq(this.prevActiveSlide).css({"z-index" : 1}); 483 this.options.afterSlideChange.call(this, this.$slides.eq(this.prevActiveSlide), this.$slides.eq(this.activeSlide)); 484 this.unlock(); 485 }, 486 487 shift: function (direction) { 488 489 if($(this.$slides).filter(':animated').length == 0 && $(this.$slides).find('h2').filter(':animated').length == 0 && $(this.$slides).find('a').filter(':animated').length == 0 && $(this.$slides).find('div').filter(':animated').length == 0 && $(this.$slides).find('span').filter(':animated').length == 0) { 490 491 var slideDirection = direction; 492 493 //remember previous activeSlide 494 this.prevActiveSlide = this.activeSlide; 495 496 //exit function if bullet clicked is same as the current image 497 if (this.prevActiveSlide == slideDirection) { return false; } 498 499 if (this.$slides.length == "1") { return false; } 500 if (!this.locked) { 501 this.lock(); 502 //deduce the proper activeImage 503 if (direction == "next") { 504 this.activeSlide++; 505 if (this.activeSlide == this.numberSlides) { 506 this.activeSlide = 0; 507 } 508 } else if (direction == "prev") { 509 this.activeSlide--; 510 if (this.activeSlide < 0) { 511 this.activeSlide = this.numberSlides - 1; 512 } 513 } else { 514 this.activeSlide = direction; 515 if (this.prevActiveSlide < this.activeSlide) { 516 slideDirection = "next"; 517 } else if (this.prevActiveSlide > this.activeSlide) { 518 slideDirection = "prev"; 519 } 520 } 521 522 //set to correct bullet 523 this.setActiveBullet(); 524 525 //set previous slide z-index to one below what new activeSlide will be 526 this.$slides 527 .eq(this.prevActiveSlide) 528 .css({"z-index" : 2}); 529 530 //fade 531 if (this.options.animation == "fade" ) { 532 533 var $that = this; 534 var $currentSlide = this.$slides.eq(this.activeSlide); 535 var timeout = 0; 536 var count = 0; 537 var infoLength = this.$slides.eq(this.prevActiveSlide).find('.post-title').children().length; 538 var currentPos = this.$slides.eq(this.prevActiveSlide).find('article').css('top'); 539 this.$slides 540 .eq(this.prevActiveSlide).find('.post-title').children().each(function(i){ 541 542 count++; 543 infoLength--; 544 545 //if aniamtion is on 546 if( $('#featured').attr('data-caption-animation') == '1' ){ 547 548 //fadeOut in reverse 549 $(this).stop().delay(infoLength*150).animate({ 550 'opacity' : 0 551 },300,'easeOutSine'); 552 553 timeout = count*300 - count*150; 554 555 } 556 557 }); 558 559 //switch slides when the caption is faded out 560 var currentTimeout = setTimeout(function(){ 561 562 //webkit video fix.. 563 if( $('#featured').attr('data-caption-animation') == '1' && $(window).width() > 1000){ 564 $that.$slides.find('.mejs-mediaelement').css('visibility','hidden'); 565 $that.$slides.find('.video').hide(); 566 $that.$slides.find('.mejs-mediaelement').parents('.video').show(); 567 } 568 569 570 if( $('#featured').attr('data-caption-animation') == '1' ){ 571 $that.$slides.find('.video .jp-jplayer > img').show(); 572 } 573 574 if($currentSlide.find('.video').length > 0) { 575 $currentSlide.find('.video').show(); 576 $currentSlide.find('.mejs-poster').show(); 577 } 578 579 580 $that.$slides 581 .eq($that.activeSlide) 582 .find('article').css({"top" : currentPos}); 583 584 $that.$slides 585 .eq($that.activeSlide) 586 .css({"opacity" : 0, "z-index" : 3}) 587 .animate({"opacity" : 1}, $that.options.animationSpeed, function(){ 588 589 590
591 //reset opacity on all slides 592 $that.$slides.css({"opacity" : 0}); 593 $that.$slides.eq($that.activeSlide).css({"opacity" : 1}); 594 595 //stop any previously playing video 596 if($that.$slides.eq($that.prevActiveSlide).find('.jp-jplayer-video').length>0){ 597 $that.$slides.find('video').hide(); 598 $that.$slides.eq($that.prevActiveSlide).find('.jp-jplayer-video').jPlayer("stop"); 599 } 600 601 //reset caption animation 602 if( $('#featured').attr('data-caption-animation') == '1' ){ 603 $that.$slides.find('.post-title').children().css({'opacity':0, 'margin-top':20}); 604 } 605 606 607 if( $('#featured').attr('data-caption-animation') == '0' ){ 608 $that.$slides.find('video').hide(); 609 $that.$slides.find('.video').hide(); 610 $that.$slides.find('.video .jp-jplayer > img').show(); 611 612 if($currentSlide.find('.video').length > 0) { 613 $currentSlide.find('.video').show(); 614 $currentSlide.find('.mejs-poster').show(); 615 $currentSlide.find('.mejs-mediaelement').css('visibility','hidden'); 616 } 617 } 618 619 $that.resetAndUnlock(); 620 621 if( $('.fancybox-container.fancybox-is-open').length == 0 ) { 622 $(window).trigger('resize'); 623 } 624 625 626 if( $('#featured').attr('data-caption-animation') == '1' ){ 627 $currentSlide.find('.post-title').children().each(function(i){ 628 $(this).stop().delay(i*270).animate({ 629 'opacity' : 1, 630 'margin-top' : 0 631 },500,'easeOutSine'); 632 }); 633 } 634 635 636 }); 637 638 }, timeout); 639 640 } 641 642 //horizontal-slide 643 if (this.options.animation == "horizontal-slide") { 644 if (slideDirection == "next") { 645 this.$slides 646 .eq(this.activeSlide) 647 .css({"left": this.orbitWidth, "z-index" : 3}) 648 .animate({"left" : 0}, this.options.animationSpeed, this.resetAndUnlock); 649 } 650 if (slideDirection == "prev") { 651 this.$slides 652 .eq(this.activeSlide) 653 .css({"left": -this.orbitWidth, "z-index" : 3}) 654 .animate({"left" : 0}, this.options.animationSpeed, this.resetAndUnlock); 655 } 656 } 657 658 //vertical-slide 659 if (this.options.animation == "vertical-slide") { 660 if (slideDirection == "prev") { 661 this.$slides 662 .eq(this.activeSlide) 663 .css({"top": this.orbitHeight, "z-index" : 3}) 664 .animate({"top" : 0}, this.options.animationSpeed, this.resetAndUnlock); 665 } 666 if (slideDirection == "next") { 667 this.$slides 668 .eq(this.activeSlide) 669 .css({"top": -this.orbitHeight, "z-index" : 3}) 670 .animate({"top" : 0}, this.options.animationSpeed, this.resetAndUnlock); 671 } 672 } 673 674 //horizontal-push 675 if (this.options.animation == "horizontal-push") { 676 if (slideDirection == "next") { 677 this.$slides 678 .eq(this.activeSlide) 679 .css({"left": this.orbitWidth, "z-index" : 3}) 680 .animate({"left" : 0}, this.options.animationSpeed, this.resetAndUnlock); 681 this.$slides 682 .eq(this.prevActiveSlide) 683 .animate({"left" : -this.orbitWidth}, this.options.animationSpeed); 684 } 685 if (slideDirection == "prev") { 686 this.$slides 687 .eq(this.activeSlide) 688 .css({"left": -this.orbitWidth, "z-index" : 3}) 689 .animate({"left" : 0}, this.options.animationSpeed, this.resetAndUnlock); 690 this.$slides 691 .eq(this.prevActiveSlide) 692 .animate({"left" : this.orbitWidth}, this.options.animationSpeed); 693 } 694 } 695 696 //vertical-push 697 if (this.options.animation == "vertical-push") { 698 if (slideDirection == "next") { 699 this.$slides 700 .eq(this.activeSlide) 701 .css({top: -this.orbitHeight, "z-index" : 3}) 702 .animate({top : 0}, this.options.animationSpeed, this.resetAndUnlock); 703 this.$slides 704 .eq(this.prevActiveSlide) 705 .animate({top : this.orbitHeight}, this.options.animationSpeed); 706 } 707 if (slideDirection == "prev") { 708 this.$slides 709 .eq(this.activeSlide) 710 .css({top: this.orbitHeight, "z-index" : 3}) 711 .animate({top : 0}, this.options.animationSpeed, this.resetAndUnlock); 712 this.$slides 713 .eq(this.prevActiveSlide) 714 .animate({top : -this.orbitHeight}, this.options.animationSpeed); 715 } 716 } 717 718 this.setCaption(); 719 720 } 721 } 722 } 723 }; 724 725 $.fn.orbit = function (options) { 726 return this.each(function () { 727 var orbit = $.extend({}, ORBIT); 728 orbit.init(this, options); 729 }); 730 }; 731 732})(jQuery); 733 734/*! 735* jQuery imageready Plugin 736* http://www.zurb.com/playground/ 737* 738* Copyright 2011, ZURB 739* Released under the MIT License 740*/ 741(function ($) { 742 743 'use strict'; 744 745 var options = {}; 746 747 $.event.special.imageready = { 748 749 setup: function (data, namespaces, eventHandle) { 750 options = data || options; 751 }, 752 753 add: function (handleObj) { 754 var $this = $(this), 755 src; 756 757 if ( this.nodeType === 1 && this.tagName.toLowerCase() === 'img' && this.src !== '' ) { 758 if (options.forceLoad) { 759 src = $this.attr('src'); 760 $this.attr('src', ''); 761 bindToLoad(this, handleObj.handler); 762 $this.attr('src', src); 763 } else if ( this.complete || this.readyState === 4 ) { 764 handleObj.handler.apply(this, arguments); 765 } else { 766 bindToLoad(this, handleObj.handler); 767 } 768 } 769 }, 770 771 teardown: function (namespaces) { 772 $(this).unbind('.imageready'); 773 } 774 }; 775 776 function bindToLoad(element, callback) { 777 var $this = $(element); 778 779 $this.bind('load.imageready', function () { 780 callback.apply(element, arguments); 781 $this.unbind('load.imageready'); 782 }); 783 } 784 785
786 787 788 789 790 /***************** Home Slider ******************/ 791 792 var sliderAdvanceSpeed = parseInt($('#featured').attr('data-advance-speed')); 793 var sliderAnimationSpeed = parseInt($('#featured').attr('data-animation-speed')); 794 var sliderAutoplay = parseInt($('#featured').attr('data-autoplay')); 795 796 if( isNaN(sliderAdvanceSpeed) ) { sliderAdvanceSpeed = 5500;} 797 if( isNaN(sliderAnimationSpeed) ) { sliderAnimationSpeed = 800;} 798 799 800 var img_urls=[]; 801 $('[style*="background"]').each(function() { 802 var style = $(this).attr('style'); 803 var pattern = /background.*?url\('(.*?)'\)/g; 804 var match = pattern.exec(style); 805 if (match) { 806 img_urls.push(match[1]); 807 } 808 }); 809 810 var imgArray = []; 811 812 for(var i=0;i<img_urls.length;i++){ 813 imgArray[i] = new Image(); 814 imgArray[i].src = img_urls[i]; 815 } 816 817 818 //home slider height 819 var sliderHeight = parseInt($('#featured').attr('data-slider-height')); 820 if( isNaN(sliderHeight) ) { 821 sliderHeight = 650; 822 } else { 823 sliderHeight = sliderHeight - 12; 824 } 825 826 ////min height if video 827 if( $('#featured .video').length > 0 && sliderHeight < 500) { 828 sliderHeight = 500; 829 } 830 831 function customSliderHeight(){ 832 if(!$('body').hasClass('mobile')){ 833 $('#featured').attr('style', 'height: '+sliderHeight+'px !important'); 834 $('#featured article').css('height',sliderHeight+headerPadding2-23+'px'); 835 } 836 else { 837 $('#featured').attr('style', 'height: '+sliderHeight+'px'); 838 } 839 840 //transparent header fix 841 if($('#header-outer[data-transparent-header="true"]').length > 0) { 842 $('.orbit-wrapper').addClass('transparent-header'); 843 } 844 } 845 846 customSliderHeight(); 847 848 849 850 851 //take into account header height when calculating the controls and info positioning 852 var logoHeight = parseInt($('#header-outer').attr('data-logo-height')); 853 var headerPadding = parseInt($('#header-outer').attr('data-padding')); 854 var headerPadding2 = parseInt($('#header-outer').attr('data-padding')); 855 var extraDef = 0; 856 var headerResize = ($('body').hasClass('pp-video-function')) ? '1' : $('#header-outer').attr('data-header-resize'); 857 var headerResizeOffExtra = 0; 858 var extraHeight = ($('#wpadminbar').length > 0) ? $('#wpadminbar').height() : 0; //admin bar 859 var mediaElement = ($('.wp-video-shortcode').length > 0) ? 36 : 0; 860 var secondaryHeader = ($('#header-outer').attr('data-using-secondary') === '1') ? 32 : 0 ; 861 862 if( isNaN(logoHeight) ) { 863 logoHeight = 30; 864 } 865 if( isNaN(headerPadding) ) { 866 headerPadding = 28; 867 headerPadding2 = 28; 868 } 869 870 if( $('header#top #logo img').length === 0 ) { 871 logoHeight = 30; 872 } 873 874 var $captionPos = (((sliderHeight-70)/2 - $('div.slider-nav span.left span.white').height()/2) + headerPadding2 - headerResizeOffExtra) - 75; 875 var $controlsPos = (((sliderHeight-70)/2 - $('div.slider-nav span.left span.white').height()/2) + logoHeight + headerPadding*2 + extraHeight + secondaryHeader) -10; 876 var $scrollTop = 0; 877 var $videoHeight; 878 879 880 function homeSliderInit() { 881 882 $('#featured').orbit({ 883 animation: 'fade', 884 advanceSpeed: sliderAdvanceSpeed, 885 animationSpeed: sliderAnimationSpeed, 886 timer: sliderAutoplay 887 }); 888 889 customSliderHeight(); 890 sliderAfterSetup(); 891 892 //test for slider arrows 893 if(!$('body').hasClass('mobile')){ 894 $('.orbit-wrapper #featured article').css('top', ((- $scrollTop / 5)+logoHeight+headerPadding2+headerResizeOffExtra+extraHeight-extraDef+secondaryHeader) + 'px'); 895 $('.orbit-wrapper div.slider-nav span.right, .orbit-wrapper div.slider-nav span.left').html('<span class="white"></span><span class="shadow"></span>'); 896 } else { 897 $('.orbit-wrapper div.slider-nav span.right').html('<i class="icon-angle-right"></i>'); 898 $('.orbit-wrapper div.slider-nav span.left').html('<i class="icon-angle-left"></i>'); 899 } 900 901 //no caption home slider fix 902 $('#featured article').each(function () { 903 if ($(this).find('h2').attr('data-has-caption') == '0') { 904 $(this).parents('.slide').addClass('no-caption'); 905 } 906 }); 907 908 } 909 910 //home slider init 911 function homeSliderInit2() { 912 913 if($('#featured').length > 0 && $().orbit) { 914 915 $('#featured article .post-title h2 span').show(); 916 917 //home slider bg color
918 var sliderBackgroundColor = $('#featured').attr('data-bg-color'); 919 if( sliderBackgroundColor.length === 0 ) sliderBackgroundColor = '#000000'; 920 921 $('#featured article').css('background-color',sliderBackgroundColor); 922 923 var $firstBg = $('#featured').find('.slide:first-child > article').attr('style'); 924 925 var pattern = /url\(["']?([^'")]+)['"]?\)/; 926 var match = pattern.exec($firstBg); 927 928 if (match && match[1].indexOf('.') !== -1) { 929 var slideImg = new Image(); 930 slideImg.onload = function(){ 931 homeSliderInit(); 932 }; 933 slideImg.src = match[1]; 934 } else { 935 homeSliderInit(); 936 } 937 938 ////add hover effect to slider nav 939 if($('.slider-nav > span').find('.white').length === 0) { 940 $('.slider-nav > span').append('<span class="white"></span><span class="shadow"></span>'); 941 } 942 943 ////swipe for home slider 944 if($('body').hasClass('mobile')){ 945 $('#featured h2, #featured .video').swipe({ 946 swipeRight : function(e) { 947 $('.slider-nav .left').trigger('click'); 948 e.stopImmediatePropagation(); 949 return false; 950 }, 951 swipeLeft : function(e) { 952 $('.slider-nav .right').trigger('click'); 953 e.stopImmediatePropagation(); 954 return false; 955 } 956 }); 957 } 958 959 960 } 961 } 962 963 homeSliderInit2(); 964 965 966 967 //inital load 968 function sliderAfterSetup(){ 969 //webkit video fix 970 $(window).on('load',function(){ 971 $('#featured .mejs-container').css('width',$('#featured .video').width()); 972 $('#featured .mejs-container, #featured .mejs-container video').css('height',$('#featured .video').width()/1.7777); 973 }); 974 975 $('body:not(.mobile) .orbit-wrapper #featured .orbit-slide:not(".has-video") article .container').css('top', $captionPos +"px"); 976 $('body:not(.mobile) .orbit-wrapper #featured .orbit-slide.has-video article .container').css('top', $videoHeight +"px"); 977 $('body:not(.mobile) .orbit-wrapper .slider-nav > span').css('top', $controlsPos +"px"); 978 $('body:not(.mobile) .orbit-wrapper #featured .slide article').css({'top': ((- $scrollTop / 5)+logoHeight+headerPadding2+headerResizeOffExtra+extraHeight-extraDef+secondaryHeader) + 'px' }); 979 980 //height fix for when resize on scroll if off 981 if(!$('body').hasClass('mobile') && headerResize.length === 0){ 982 $('#featured article').css('height',sliderHeight-32+'px'); 983 } 984 985 $(window).trigger('resize'); 986 } 987 988 989 function videoSlidePos(){ 990 $('#featured > div').has('.video').each(function(){ 991 if( $(window).width() > 1300 ) { 992 $('#featured .orbit-slide.has-video .video, #featured .orbit-slide.has-video h2').css('top','0'); 993 $('#featured .orbit-slide.has-video .post-title > a').css('top','10px'); 994 995 $videoHeight = ((sliderHeight-28)/2) - ((410-mediaElement)/2) + headerPadding2 - headerResizeOffExtra; 996 } 997 998 else if( $(window).width() > 1000 && $(window).width() < 1081 ){ 999 $('#featured .orbit-slide.has-video .video, #featured .orbit-slide.has-video h2').css('top','0'); 1000 $('#featured .orbit-slide.has-video .post-title > a').css('top','10px'); 1001 1002 $videoHeight = ((sliderHeight-28)/2) - ((290-mediaElement)/2) + headerPadding2 - headerResizeOffExtra; 1003 } 1004 1005 else { 1006 $videoHeight = ((sliderHeight-28)/2) - ((336-mediaElement)/2) +headerPadding2 - headerResizeOffExtra; 1007 } 1008 1009 }); 1010 } 1011 1012 videoSlidePos(); 1013 1014 //dynamic controls and info positioning 1015 function controlsAndInfoPos(){ 1016 $scrollTop = $(window).scrollTop(); 1017 1018 $('body:not(.mobile) .orbit-wrapper #featured .orbit-slide:not(".has-video") article .container').css({ 1019 'opacity' : 1-($scrollTop/(sliderHeight-130)), 1020 'top' : ($scrollTop*-0.2) + $captionPos +"px" 1021 }); 1022 1023 //video slides 1024 $('body:not(.mobile) .orbit-wrapper #featured .orbit-slide.has-video article .container').css({ 1025 'opacity' : 1-($scrollTop/(sliderHeight-130)), 1026 'top' : ($scrollTop*-0.2) + $videoHeight +"px" 1027 }); 1028 1029 if($('#boxed').length === 0){ 1030 $('body:not(.mobile) .orbit-wrapper .slider-nav > span').css({ 1031 'opacity' : 1-($scrollTop/(sliderHeight-130)), 1032 'top' : ($scrollTop*-0.4) + $controlsPos +"px" 1033 }); 1034 } 1035 1036 } 1037 1038 controlsInit(); 1039 function controlsInit(){ 1040 1041 if($('#boxed').length > 0) { 1042 if(1-$scrollTop/(sliderHeight-$controlsPos-20) >= 0){ 1043 $(window).off('scroll',hideControls); 1044 $(window).on('scroll',showControls); 1045 } else { 1046 $(window).off('scroll',showControls); 1047 $(window).on('scroll',hideControls); 1048 } 1049 } else { 1050 $(window).off('scroll',showControls); 1051 $(window).off('scroll',hideControls); 1052 } 1053 1054 } 1055 1056 function showControls(){ 1057 1058 if(1-$scrollTop/(sliderHeight-$controlsPos-20) >= 0){ 1059 $('body:not(.mobile) .orbit-wrapper .slider-nav > span.left').stop(true,true).animate({ 'left' : '0px'},450,'easeOutCubic'); 1060 if( $('body').attr('data-smooth-scrolling') === '1' ){ 1061 $('body:not(.mobile) .orbit-wrapper .slider-nav > span.right').stop(true,true).animate({ 'right' : '15px'},450,'easeOutCubic'); 1062 } else { 1063 $('body:not(.mobile) .orbit-wrapper .slider-nav > span.right').stop(true,true).animate({ 'right' : '0px'},450,'easeOutCubic'); 1064 } 1065 $(window).off('scroll',showControls); 1066 $(window).on('scroll',hideControls); 1067 } 1068 } 1069 1070 function hideControls(){ 1071 1072 if(1-$scrollTop/(sliderHeight-$controlsPos-20) < 0){ 1073 $('body:not(.mobile) .orbit-wrapper .slider-nav > span.left').stop(true,true).animate({ 'left' : '-80px'},450,'easeOutCubic'); 1074 $('body:not(.mobile) .orbit-wrapper .slider-nav > span.right').stop(true,true).animate({ 'right' : '-80px'},450,'easeOutCubic'); 1075 $(window).off('scroll',hideControls); 1076 $(window).on('scroll',showControls); 1077 } 1078 1079 } 1080 1081
1082 function homeSliderParallaxScroll(){ 1083 1084 //hide video to not mess up parallax section 1085 $('#featured .mejs-mediaelement, #featured .iframe-embed').each(function(){ 1086 1087 if( $(this).parents('.container').css('opacity') <= 0){ 1088 $(this).css('visibility','hidden').hide(); 1089 } else { 1090 $(this).css('visibility','visible').show(); 1091 } 1092 }); 1093 1094 if(!$('body').hasClass('mobile')){ 1095 1096 controlsAndInfoPos(); 1097 $('body:not(.mobile) .orbit-wrapper #featured .slide:not(:transparent) article').css({'top': ((- $scrollTop / 5)+logoHeight+headerPadding2+headerResizeOffExtra+extraHeight-extraDef+secondaryHeader) + 'px' }); 1098 1099 } 1100 } 1101 1102 function homeSliderMobile() { 1103 1104 if(!$('body').hasClass('mobile')){ 1105 $('.orbit-wrapper #featured article').css('top', ((- $scrollTop / 5)+logoHeight+headerPadding2+headerResizeOffExtra+extraHeight-extraDef+secondaryHeader) + 'px'); 1106 $('.orbit-wrapper div.slider-nav span.right, .orbit-wrapper div.slider-nav span.left').html('<span class="white"></span><span class="shadow"></span>'); 1107 } else { 1108 $('.orbit-wrapper div.slider-nav span.right').html('<i class="icon-angle-right"></i>'); 1109 $('.orbit-wrapper div.slider-nav span.left').html('<i class="icon-angle-left"></i>'); 1110 } 1111 1112 videoSlidePos(); 1113 controlsAndInfoPos(); 1114 customSliderHeight(); 1115 1116 //height fix for when resize on scroll if off 1117 if(!$('body').hasClass('mobile') && headerResize.length === 0){ 1118 $('#featured article').css('height',sliderHeight-32+'px'); 1119 } 1120 1121 } 1122 1123 1124 if( $('#featured').length > 0){ 1125 1126 $(window).off('scroll.hsps'); 1127 $(window).on('scroll.hsps',homeSliderParallaxScroll); 1128 1129 //disable parallax for mobile 1130 $(window).off('resize.hsps'); 1131 $(window).on('resize.hsps',homeSliderMobile); 1132 1133 } 1134 1135 1136 //mobile video more info 1137 $('#featured .span_12 a.more-info').on('click', function(){ 1138 1139 var $btnParentSelect = $(this).parent().parent(); 1140 1141 if( !$(this).find('.btv').is(":visible")){ 1142 $btnParentSelect.find('h2, > a').css('opacity',1); 1143 $btnParentSelect.find('.video').stop().animate({'top':'-400px'},800,'easeOutCubic'); 1144 $btnParentSelect.find('h2').stop().animate({'top':'-400px'},800,'easeOutCubic'); 1145 $btnParentSelect.find('> a').stop().animate({'top':'-380px'},800,'easeOutCubic'); 1146 $(this).find('.btv').show(); 1147 $(this).find('.mi').hide(); 1148 } 1149 else { 1150 $btnParentSelect.find('.video').stop().animate({'top':'0px'},800,'easeOutCubic'); 1151 $btnParentSelect.find('h2').stop().animate({'top':'0px'},800,'easeOutCubic'); 1152 $btnParentSelect.find('> a').stop().animate({'top':'0px'},800,'easeOutCubic'); 1153 $(this).find('.mi').show(); 1154 $(this).find('.btv').hide(); 1155 } 1156 1157 return false; 1158 }); 1159 1160 1161 1162 1163}(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.