Best JavaScript code snippet using storybook-test-runner
jquery.cycle.js
Source:jquery.cycle.js
...65 opts: function() {66 return this._container.data( 'cycle.opts' );67 },68 addInitialSlides: function() {69 var opts = this.opts();70 var slides = opts.slides;71 opts.slideCount = 0;72 opts.slides = $(); // empty set73 // add slides that already exist74 slides = slides.jquery ? slides : opts.container.find( slides );75 if ( opts.random ) {76 slides.sort(function() {return Math.random() - 0.5;});77 }78 opts.API.add( slides );79 },80 preInitSlideshow: function() {81 var opts = this.opts();82 opts.API.trigger('cycle-pre-initialize', [ opts ]);83 var tx = $.fn.cycle.transitions[opts.fx];84 if (tx && $.isFunction(tx.preInit))85 tx.preInit( opts );86 opts._preInitialized = true;87 },88 postInitSlideshow: function() {89 var opts = this.opts();90 opts.API.trigger('cycle-post-initialize', [ opts ]);91 var tx = $.fn.cycle.transitions[opts.fx];92 if (tx && $.isFunction(tx.postInit))93 tx.postInit( opts );94 },95 initSlideshow: function() {96 var opts = this.opts();97 var pauseObj = opts.container;98 var slideOpts;99 opts.API.calcFirstSlide();100 if ( opts.container.css('position') == 'static' )101 opts.container.css('position', 'relative');102 $(opts.slides[opts.currSlide]).css({103 opacity: 1,104 display: 'block',105 visibility: 'visible'106 });107 opts.API.stackSlides( opts.slides[opts.currSlide], opts.slides[opts.nextSlide], !opts.reverse );108 if ( opts.pauseOnHover ) {109 // allow pauseOnHover to specify an element110 if ( opts.pauseOnHover !== true )111 pauseObj = $( opts.pauseOnHover );112 pauseObj.hover(113 function(){ opts.API.pause( true ); },114 function(){ opts.API.resume( true ); }115 );116 }117 // stage initial transition118 if ( opts.timeout ) {119 slideOpts = opts.API.getSlideOpts( opts.currSlide );120 opts.API.queueTransition( slideOpts, slideOpts.timeout + opts.delay );121 }122 opts._initialized = true;123 opts.API.updateView( true );124 opts.API.trigger('cycle-initialized', [ opts ]);125 opts.API.postInitSlideshow();126 },127 pause: function( hover ) {128 var opts = this.opts(),129 slideOpts = opts.API.getSlideOpts(),130 alreadyPaused = opts.hoverPaused || opts.paused;131 if ( hover )132 opts.hoverPaused = true;133 else134 opts.paused = true;135 if ( ! alreadyPaused ) {136 opts.container.addClass('cycle-paused');137 opts.API.trigger('cycle-paused', [ opts ]).log('cycle-paused');138 if ( slideOpts.timeout ) {139 clearTimeout( opts.timeoutId );140 opts.timeoutId = 0;141 // determine how much time is left for the current slide142 opts._remainingTimeout -= ( $.now() - opts._lastQueue );143 if ( opts._remainingTimeout < 0 || isNaN(opts._remainingTimeout) )144 opts._remainingTimeout = undefined;145 }146 }147 },148 resume: function( hover ) {149 var opts = this.opts(),150 alreadyResumed = !opts.hoverPaused && !opts.paused,151 remaining;152 if ( hover )153 opts.hoverPaused = false;154 else155 opts.paused = false;156 if ( ! alreadyResumed ) {157 opts.container.removeClass('cycle-paused');158 // #gh-230; if an animation is in progress then don't queue a new transition; it will159 // happen naturally160 if ( opts.slides.filter(':animated').length === 0 )161 opts.API.queueTransition( opts.API.getSlideOpts(), opts._remainingTimeout );162 opts.API.trigger('cycle-resumed', [ opts, opts._remainingTimeout ] ).log('cycle-resumed');163 }164 },165 add: function( slides, prepend ) {166 var opts = this.opts();167 var oldSlideCount = opts.slideCount;168 var startSlideshow = false;169 var len;170 if ( $.type(slides) == 'string')171 slides = $.trim( slides );172 $( slides ).each(function(i) {173 var slideOpts;174 var slide = $(this);175 if ( prepend )176 opts.container.prepend( slide );177 else178 opts.container.append( slide );179 opts.slideCount++;180 slideOpts = opts.API.buildSlideOpts( slide );181 if ( prepend )182 opts.slides = $( slide ).add( opts.slides );183 else184 opts.slides = opts.slides.add( slide );185 opts.API.initSlide( slideOpts, slide, --opts._maxZ );186 slide.data('cycle.opts', slideOpts);187 opts.API.trigger('cycle-slide-added', [ opts, slideOpts, slide ]);188 });189 opts.API.updateView( true );190 startSlideshow = opts._preInitialized && (oldSlideCount < 2 && opts.slideCount >= 1);191 if ( startSlideshow ) {192 if ( !opts._initialized )193 opts.API.initSlideshow();194 else if ( opts.timeout ) {195 len = opts.slides.length;196 opts.nextSlide = opts.reverse ? len - 1 : 1;197 if ( !opts.timeoutId ) {198 opts.API.queueTransition( opts );199 }200 }201 }202 },203 calcFirstSlide: function() {204 var opts = this.opts();205 var firstSlideIndex;206 firstSlideIndex = parseInt( opts.startingSlide || 0, 10 );207 if (firstSlideIndex >= opts.slides.length || firstSlideIndex < 0)208 firstSlideIndex = 0;209 opts.currSlide = firstSlideIndex;210 if ( opts.reverse ) {211 opts.nextSlide = firstSlideIndex - 1;212 if (opts.nextSlide < 0)213 opts.nextSlide = opts.slides.length - 1;214 }215 else {216 opts.nextSlide = firstSlideIndex + 1;217 if (opts.nextSlide == opts.slides.length)218 opts.nextSlide = 0;219 }220 },221 calcNextSlide: function() {222 var opts = this.opts();223 var roll;224 if ( opts.reverse ) {225 roll = (opts.nextSlide - 1) < 0;226 opts.nextSlide = roll ? opts.slideCount - 1 : opts.nextSlide-1;227 opts.currSlide = roll ? 0 : opts.nextSlide+1;228 }229 else {230 roll = (opts.nextSlide + 1) == opts.slides.length;231 opts.nextSlide = roll ? 0 : opts.nextSlide+1;232 opts.currSlide = roll ? opts.slides.length-1 : opts.nextSlide-1;233 }234 },235 calcTx: function( slideOpts, manual ) {236 var opts = slideOpts;237 var tx;238 if ( opts._tempFx )239 tx = $.fn.cycle.transitions[opts._tempFx];240 else if ( manual && opts.manualFx )241 tx = $.fn.cycle.transitions[opts.manualFx];242 if ( !tx )243 tx = $.fn.cycle.transitions[opts.fx];244 opts._tempFx = null;245 this.opts()._tempFx = null;246 if (!tx) {247 tx = $.fn.cycle.transitions.fade;248 opts.API.log('Transition "' + opts.fx + '" not found. Using fade.');249 }250 return tx;251 },252 prepareTx: function( manual, fwd ) {253 var opts = this.opts();254 var after, curr, next, slideOpts, tx;255 if ( opts.slideCount < 2 ) {256 opts.timeoutId = 0;257 return;258 }259 if ( manual && ( !opts.busy || opts.manualTrump ) ) {260 opts.API.stopTransition();261 opts.busy = false;262 clearTimeout(opts.timeoutId);263 opts.timeoutId = 0;264 }265 if ( opts.busy )266 return;267 if ( opts.timeoutId === 0 && !manual )268 return;269 curr = opts.slides[opts.currSlide];270 next = opts.slides[opts.nextSlide];271 slideOpts = opts.API.getSlideOpts( opts.nextSlide );272 tx = opts.API.calcTx( slideOpts, manual );273 opts._tx = tx;274 if ( manual && slideOpts.manualSpeed !== undefined )275 slideOpts.speed = slideOpts.manualSpeed;276 // if ( opts.nextSlide === opts.currSlide )277 // opts.API.calcNextSlide();278 // ensure that:279 // 1. advancing to a different slide280 // 2. this is either a manual event (prev/next, pager, cmd) or281 // a timer event and slideshow is not paused282 if ( opts.nextSlide != opts.currSlide &&283 (manual || (!opts.paused && !opts.hoverPaused && opts.timeout) )) { // #62284 opts.API.trigger('cycle-before', [ slideOpts, curr, next, fwd ]);285 if ( tx.before )286 tx.before( slideOpts, curr, next, fwd );287 after = function() {288 opts.busy = false;289 // #76; bail if slideshow has been destroyed290 if (! opts.container.data( 'cycle.opts' ) )291 return;292 if (tx.after)293 tx.after( slideOpts, curr, next, fwd );294 opts.API.trigger('cycle-after', [ slideOpts, curr, next, fwd ]);295 opts.API.queueTransition( slideOpts);296 opts.API.updateView( true );297 };298 opts.busy = true;299 if (tx.transition)300 tx.transition(slideOpts, curr, next, fwd, after);301 else302 opts.API.doTransition( slideOpts, curr, next, fwd, after);303 opts.API.calcNextSlide();304 opts.API.updateView();305 } else {306 opts.API.queueTransition( slideOpts );307 }308 },309 // perform the actual animation310 doTransition: function( slideOpts, currEl, nextEl, fwd, callback) {311 var opts = slideOpts;312 var curr = $(currEl), next = $(nextEl);313 var fn = function() {314 // make sure animIn has something so that callback doesn't trigger immediately315 next.animate(opts.animIn || { opacity: 1}, opts.speed, opts.easeIn || opts.easing, callback);316 };317 next.css(opts.cssBefore || {});318 curr.animate(opts.animOut || {}, opts.speed, opts.easeOut || opts.easing, function() {319 curr.css(opts.cssAfter || {});320 if (!opts.sync) {321 fn();322 }323 });324 if (opts.sync) {325 fn();326 }327 },328 queueTransition: function( slideOpts, specificTimeout ) {329 var opts = this.opts();330 var timeout = specificTimeout !== undefined ? specificTimeout : slideOpts.timeout;331 if (opts.nextSlide === 0 && --opts.loop === 0) {332 opts.API.log('terminating; loop=0');333 opts.timeout = 0;334 if ( timeout ) {335 setTimeout(function() {336 opts.API.trigger('cycle-finished', [ opts ]);337 }, timeout);338 }339 else {340 opts.API.trigger('cycle-finished', [ opts ]);341 }342 // reset nextSlide343 opts.nextSlide = opts.currSlide;344 return;345 }346 if ( opts.continueAuto !== undefined ) {347 if ( opts.continueAuto === false ||348 ($.isFunction(opts.continueAuto) && opts.continueAuto() === false )) {349 opts.API.log('terminating automatic transitions');350 opts.timeout = 0;351 if ( opts.timeoutId )352 clearTimeout(opts.timeoutId);353 return;354 }355 }356 if ( timeout ) {357 opts._lastQueue = $.now();358 if ( specificTimeout === undefined )359 opts._remainingTimeout = slideOpts.timeout;360 if ( !opts.paused && ! opts.hoverPaused ) {361 opts.timeoutId = setTimeout(function() {362 opts.API.prepareTx( false, !opts.reverse );363 }, timeout );364 }365 }366 },367 stopTransition: function() {368 var opts = this.opts();369 if ( opts.slides.filter(':animated').length ) {370 opts.slides.stop(false, true);371 opts.API.trigger('cycle-transition-stopped', [ opts ]);372 }373 if ( opts._tx && opts._tx.stopTransition )374 opts._tx.stopTransition( opts );375 },376 // advance slide forward or back377 advanceSlide: function( val ) {378 var opts = this.opts();379 clearTimeout(opts.timeoutId);380 opts.timeoutId = 0;381 opts.nextSlide = opts.currSlide + val;382 if (opts.nextSlide < 0)383 opts.nextSlide = opts.slides.length - 1;384 else if (opts.nextSlide >= opts.slides.length)385 opts.nextSlide = 0;386 opts.API.prepareTx( true, val >= 0 );387 return false;388 },389 buildSlideOpts: function( slide ) {390 var opts = this.opts();391 var val, shortName;392 var slideOpts = slide.data() || {};393 for (var p in slideOpts) {394 // allow props to be accessed sans 'cycle' prefix and log the overrides395 if (slideOpts.hasOwnProperty(p) && /^cycle[A-Z]+/.test(p) ) {396 val = slideOpts[p];397 shortName = p.match(/^cycle(.*)/)[1].replace(/^[A-Z]/, lowerCase);398 opts.API.log('['+(opts.slideCount-1)+']', shortName+':', val, '('+typeof val +')');399 slideOpts[shortName] = val;400 }401 }402 slideOpts = $.extend( {}, $.fn.cycle.defaults, opts, slideOpts );403 slideOpts.slideNum = opts.slideCount;404 try {405 // these props should always be read from the master state object406 delete slideOpts.API;407 delete slideOpts.slideCount;408 delete slideOpts.currSlide;409 delete slideOpts.nextSlide;410 delete slideOpts.slides;411 } catch(e) {412 // no op413 }414 return slideOpts;415 },416 getSlideOpts: function( index ) {417 var opts = this.opts();418 if ( index === undefined )419 index = opts.currSlide;420 var slide = opts.slides[index];421 var slideOpts = $(slide).data('cycle.opts');422 return $.extend( {}, opts, slideOpts );423 },424 initSlide: function( slideOpts, slide, suggestedZindex ) {425 var opts = this.opts();426 slide.css( slideOpts.slideCss || {} );427 if ( suggestedZindex > 0 )428 slide.css( 'zIndex', suggestedZindex );429 // ensure that speed settings are sane430 if ( isNaN( slideOpts.speed ) )431 slideOpts.speed = $.fx.speeds[slideOpts.speed] || $.fx.speeds._default;432 if ( !slideOpts.sync )433 slideOpts.speed = slideOpts.speed / 2;434 slide.addClass( opts.slideClass );435 },436 updateView: function( isAfter, isDuring, forceEvent ) {437 var opts = this.opts();438 if ( !opts._initialized )439 return;440 var slideOpts = opts.API.getSlideOpts();441 var currSlide = opts.slides[ opts.currSlide ];442 if ( ! isAfter && isDuring !== true ) {443 opts.API.trigger('cycle-update-view-before', [ opts, slideOpts, currSlide ]);444 if ( opts.updateView < 0 )445 return;446 }447 if ( opts.slideActiveClass ) {448 opts.slides.removeClass( opts.slideActiveClass )449 .eq( opts.currSlide ).addClass( opts.slideActiveClass );450 }451 if ( isAfter && opts.hideNonActive )452 opts.slides.filter( ':not(.' + opts.slideActiveClass + ')' ).css('visibility', 'hidden');453 if ( opts.updateView === 0 ) {454 setTimeout(function() {455 opts.API.trigger('cycle-update-view', [ opts, slideOpts, currSlide, isAfter ]);456 }, slideOpts.speed / (opts.sync ? 2 : 1) );457 }458 if ( opts.updateView !== 0 )459 opts.API.trigger('cycle-update-view', [ opts, slideOpts, currSlide, isAfter ]);460 if ( isAfter )461 opts.API.trigger('cycle-update-view-after', [ opts, slideOpts, currSlide ]);462 },463 getComponent: function( name ) {464 var opts = this.opts();465 var selector = opts[name];466 if (typeof selector === 'string') {467 // if selector is a child, sibling combinator, adjancent selector then use find, otherwise query full dom468 return (/^\s*[\>|\+|~]/).test( selector ) ? opts.container.find( selector ) : $( selector );469 }470 if (selector.jquery)471 return selector;472 return $(selector);473 },474 stackSlides: function( curr, next, fwd ) {475 var opts = this.opts();476 if ( !curr ) {477 curr = opts.slides[opts.currSlide];478 next = opts.slides[opts.nextSlide];479 fwd = !opts.reverse;480 }481 // reset the zIndex for the common case:482 // curr slide on top, next slide beneath, and the rest in order to be shown483 $(curr).css('zIndex', opts.maxZ);484 var i;485 var z = opts.maxZ - 2;486 var len = opts.slideCount;487 if (fwd) {488 for ( i = opts.currSlide + 1; i < len; i++ )489 $( opts.slides[i] ).css( 'zIndex', z-- );490 for ( i = 0; i < opts.currSlide; i++ )491 $( opts.slides[i] ).css( 'zIndex', z-- );492 }493 else {494 for ( i = opts.currSlide - 1; i >= 0; i-- )495 $( opts.slides[i] ).css( 'zIndex', z-- );496 for ( i = len - 1; i > opts.currSlide; i-- )497 $( opts.slides[i] ).css( 'zIndex', z-- );498 }499 $(next).css('zIndex', opts.maxZ - 1);500 },501 getSlideIndex: function( el ) {502 return this.opts().slides.index( el );503 }504 }; // API505// default logger506 $.fn.cycle.log = function log() {507 /*global console:true */508 if (window.console && console.log)509 console.log('[cycle2] ' + Array.prototype.join.call(arguments, ' ') );510 };511 $.fn.cycle.version = function() { return 'Cycle2: ' + version; };512// helper functions513 function lowerCase(s) {514 return (s || '').toLowerCase();515 }516// expose transition object517 $.fn.cycle.transitions = {518 custom: {519 },520 none: {521 before: function( opts, curr, next, fwd ) {522 opts.API.stackSlides( next, curr, fwd );523 opts.cssBefore = { opacity: 1, visibility: 'visible', display: 'block' };524 }525 },526 fade: {527 before: function( opts, curr, next, fwd ) {528 var css = opts.API.getSlideOpts( opts.nextSlide ).slideCss || {};529 opts.API.stackSlides( curr, next, fwd );530 opts.cssBefore = $.extend(css, { opacity: 0, visibility: 'visible', display: 'block' });531 opts.animIn = { opacity: 1 };532 opts.animOut = { opacity: 0 };533 }534 },535 fadeout: {536 before: function( opts , curr, next, fwd ) {537 var css = opts.API.getSlideOpts( opts.nextSlide ).slideCss || {};538 opts.API.stackSlides( curr, next, fwd );539 opts.cssBefore = $.extend(css, { opacity: 1, visibility: 'visible', display: 'block' });540 opts.animOut = { opacity: 0 };541 }542 },543 scrollHorz: {544 before: function( opts, curr, next, fwd ) {545 opts.API.stackSlides( curr, next, fwd );546 var w = opts.container.css('overflow','hidden').width();547 opts.cssBefore = { left: fwd ? w : - w, top: 0, opacity: 1, visibility: 'visible', display: 'block' };548 opts.cssAfter = { zIndex: opts._maxZ - 2, left: 0 };549 opts.animIn = { left: 0 };550 opts.animOut = { left: fwd ? -w : w };551 }552 }553 };554// @see: http://jquery.malsup.com/cycle2/api555 $.fn.cycle.defaults = {556 allowWrap: true,557 autoSelector: '.cycle-slideshow[data-cycle-auto-init!=false]',558 delay: 0,559 easing: null,560 fx: 'fade',561 hideNonActive: true,562 loop: 0,563 manualFx: undefined,564 manualSpeed: undefined,565 manualTrump: true,566 maxZ: 100,567 pauseOnHover: false,568 reverse: false,569 slideActiveClass: 'cycle-slide-active',570 slideClass: 'cycle-slide',571 slideCss: { position: 'absolute', top: 0, left: 0 },572 slides: '> img',573 speed: 500,574 startingSlide: 0,575 sync: true,576 timeout: 4000,577 updateView: 0578 };579// automatically find and run slideshows580 $(document).ready(function() {581 $( $.fn.cycle.defaults.autoSelector ).cycle();582 });583})(jQuery);584/*! Cycle2 autoheight plugin; Copyright (c) M.Alsup, 2012; version: 20130913 */585(function($) {586 "use strict";587 $.extend($.fn.cycle.defaults, {588 autoHeight: 0, // setting this option to false disables autoHeight logic589 autoHeightSpeed: 250,590 autoHeightEasing: null591 });592 $(document).on( 'cycle-initialized', function( e, opts ) {593 var autoHeight = opts.autoHeight;594 var t = $.type( autoHeight );595 var resizeThrottle = null;596 var ratio;597 if ( t !== 'string' && t !== 'number' )598 return;599 // bind events600 opts.container.on( 'cycle-slide-added cycle-slide-removed', initAutoHeight );601 opts.container.on( 'cycle-destroyed', onDestroy );602 if ( autoHeight == 'container' ) {603 opts.container.on( 'cycle-before', onBefore );604 }605 else if ( t === 'string' && /\d+\:\d+/.test( autoHeight ) ) {606 // use ratio607 ratio = autoHeight.match(/(\d+)\:(\d+)/);608 ratio = ratio[1] / ratio[2];609 opts._autoHeightRatio = ratio;610 }611 // if autoHeight is a number then we don't need to recalculate the sentinel612 // index on resize613 if ( t !== 'number' ) {614 // bind unique resize handler per slideshow (so it can be 'off-ed' in onDestroy)615 opts._autoHeightOnResize = function () {616 clearTimeout( resizeThrottle );617 resizeThrottle = setTimeout( onResize, 50 );618 };619 $(window).on( 'resize orientationchange', opts._autoHeightOnResize );620 }621 setTimeout( onResize, 30 );622 function onResize() {623 initAutoHeight( e, opts );624 }625 });626 function initAutoHeight( e, opts ) {627 var clone, height, sentinelIndex;628 var autoHeight = opts.autoHeight;629 if ( autoHeight == 'container' ) {630 height = $( opts.slides[ opts.currSlide ] ).outerHeight();631 opts.container.height( height );632 }633 else if ( opts._autoHeightRatio ) {634 opts.container.height( opts.container.width() / opts._autoHeightRatio );635 }636 else if ( autoHeight === 'calc' || ( $.type( autoHeight ) == 'number' && autoHeight >= 0 ) ) {637 if ( autoHeight === 'calc' )638 sentinelIndex = calcSentinelIndex( e, opts );639 else if ( autoHeight >= opts.slides.length )640 sentinelIndex = 0;641 else642 sentinelIndex = autoHeight;643 // only recreate sentinel if index is different644 if ( sentinelIndex == opts._sentinelIndex )645 return;646 opts._sentinelIndex = sentinelIndex;647 if ( opts._sentinel )648 opts._sentinel.remove();649 // clone existing slide as sentinel650 clone = $( opts.slides[ sentinelIndex ].cloneNode(true) );651 // #50; remove special attributes from cloned content652 clone.removeAttr( 'id name rel' ).find( '[id],[name],[rel]' ).removeAttr( 'id name rel' );653 clone.css({654 position: 'static',655 visibility: 'hidden',656 display: 'block'657 }).prependTo( opts.container ).addClass('cycle-sentinel cycle-slide').removeClass('cycle-slide-active');658 clone.find( '*' ).css( 'visibility', 'hidden' );659 opts._sentinel = clone;660 }661 }662 function calcSentinelIndex( e, opts ) {663 var index = 0, max = -1;664 // calculate tallest slide index665 opts.slides.each(function(i) {666 var h = $(this).height();667 if ( h > max ) {668 max = h;669 index = i;670 }671 });672 return index;673 }674 function onBefore( e, opts, outgoing, incoming, forward ) {675 var h = $(incoming).outerHeight();676 opts.container.animate( { height: h }, opts.autoHeightSpeed, opts.autoHeightEasing );677 }678 function onDestroy( e, opts ) {679 if ( opts._autoHeightOnResize ) {680 $(window).off( 'resize orientationchange', opts._autoHeightOnResize );681 opts._autoHeightOnResize = null;682 }683 opts.container.off( 'cycle-slide-added cycle-slide-removed', initAutoHeight );684 opts.container.off( 'cycle-destroyed', onDestroy );685 opts.container.off( 'cycle-before', onBefore );686 if ( opts._sentinel ) {687 opts._sentinel.remove();688 opts._sentinel = null;689 }690 }691})(jQuery);692/*! caption plugin for Cycle2; version: 20130306 */693(function($) {694 "use strict";695 $.extend($.fn.cycle.defaults, {696 caption: '> .cycle-caption',697 captionTemplate: '{{slideNum}} / {{slideCount}}',698 overlay: '> .cycle-overlay',699 overlayTemplate: '<div>{{title}}</div><div>{{desc}}</div>',700 captionModule: 'caption'701 });702 $(document).on( 'cycle-update-view', function( e, opts, slideOpts, currSlide ) {703 if ( opts.captionModule !== 'caption' )704 return;705 var el;706 $.each(['caption','overlay'], function() {707 var name = this;708 var template = slideOpts[name+'Template'];709 var el = opts.API.getComponent( name );710 if( el.length && template ) {711 el.html( opts.API.tmpl( template, slideOpts, opts, currSlide ) );712 el.show();713 }714 else {715 el.hide();716 }717 });718 });719 $(document).on( 'cycle-destroyed', function( e, opts ) {720 var el;721 $.each(['caption','overlay'], function() {722 var name = this, template = opts[name+'Template'];723 if ( opts[name] && template ) {724 el = opts.API.getComponent( 'caption' );725 el.empty();726 }727 });728 });729})(jQuery);730/*! command plugin for Cycle2; version: 20140415 */731(function($) {732 "use strict";733 var c2 = $.fn.cycle;734 $.fn.cycle = function( options ) {735 var cmd, cmdFn, opts;736 var args = $.makeArray( arguments );737 if ( $.type( options ) == 'number' ) {738 return this.cycle( 'goto', options );739 }740 if ( $.type( options ) == 'string' ) {741 return this.each(function() {742 var cmdArgs;743 cmd = options;744 opts = $(this).data('cycle.opts');745 if ( opts === undefined ) {746 c2.log('slideshow must be initialized before sending commands; "' + cmd + '" ignored');747 return;748 }749 else {750 cmd = cmd == 'goto' ? 'jump' : cmd; // issue #3; change 'goto' to 'jump' internally751 cmdFn = opts.API[ cmd ];752 if ( $.isFunction( cmdFn )) {753 cmdArgs = $.makeArray( args );754 cmdArgs.shift();755 return cmdFn.apply( opts.API, cmdArgs );756 }757 else {758 c2.log( 'unknown command: ', cmd );759 }760 }761 });762 }763 else {764 return c2.apply( this, arguments );765 }766 };767// copy props768 $.extend( $.fn.cycle, c2 );769 $.extend( c2.API, {770 next: function() {771 var opts = this.opts();772 if ( opts.busy && ! opts.manualTrump )773 return;774 var count = opts.reverse ? -1 : 1;775 if ( opts.allowWrap === false && ( opts.currSlide + count ) >= opts.slideCount )776 return;777 opts.API.advanceSlide( count );778 opts.API.trigger('cycle-next', [ opts ]).log('cycle-next');779 },780 prev: function() {781 var opts = this.opts();782 if ( opts.busy && ! opts.manualTrump )783 return;784 var count = opts.reverse ? 1 : -1;785 if ( opts.allowWrap === false && ( opts.currSlide + count ) < 0 )786 return;787 opts.API.advanceSlide( count );788 opts.API.trigger('cycle-prev', [ opts ]).log('cycle-prev');789 },790 destroy: function() {791 this.stop(); //#204792 var opts = this.opts();793 var clean = $.isFunction( $._data ) ? $._data : $.noop; // hack for #184 and #201794 clearTimeout(opts.timeoutId);795 opts.timeoutId = 0;796 opts.API.stop();797 opts.API.trigger( 'cycle-destroyed', [ opts ] ).log('cycle-destroyed');798 opts.container.removeData();799 clean( opts.container[0], 'parsedAttrs', false );800 // #75; remove inline styles801 if ( ! opts.retainStylesOnDestroy ) {802 opts.container.removeAttr( 'style' );803 opts.slides.removeAttr( 'style' );804 opts.slides.removeClass( opts.slideActiveClass );805 }806 opts.slides.each(function() {807 var slide = $(this);808 slide.removeData();809 slide.removeClass( opts.slideClass );810 clean( this, 'parsedAttrs', false );811 });812 },813 jump: function( index, fx ) {814 // go to the requested slide815 var fwd;816 var opts = this.opts();817 if ( opts.busy && ! opts.manualTrump )818 return;819 var num = parseInt( index, 10 );820 if (isNaN(num) || num < 0 || num >= opts.slides.length) {821 opts.API.log('goto: invalid slide index: ' + num);822 return;823 }824 if (num == opts.currSlide) {825 opts.API.log('goto: skipping, already on slide', num);826 return;827 }828 opts.nextSlide = num;829 clearTimeout(opts.timeoutId);830 opts.timeoutId = 0;831 opts.API.log('goto: ', num, ' (zero-index)');832 fwd = opts.currSlide < opts.nextSlide;833 opts._tempFx = fx;834 opts.API.prepareTx( true, fwd );835 },836 stop: function() {837 var opts = this.opts();838 var pauseObj = opts.container;839 clearTimeout(opts.timeoutId);840 opts.timeoutId = 0;841 opts.API.stopTransition();842 if ( opts.pauseOnHover ) {843 if ( opts.pauseOnHover !== true )844 pauseObj = $( opts.pauseOnHover );845 pauseObj.off('mouseenter mouseleave');846 }847 opts.API.trigger('cycle-stopped', [ opts ]).log('cycle-stopped');848 },849 reinit: function() {850 var opts = this.opts();851 opts.API.destroy();852 opts.container.cycle();853 },854 remove: function( index ) {855 var opts = this.opts();856 var slide, slideToRemove, slides = [], slideNum = 1;857 for ( var i=0; i < opts.slides.length; i++ ) {858 slide = opts.slides[i];859 if ( i == index ) {860 slideToRemove = slide;861 }862 else {863 slides.push( slide );864 $( slide ).data('cycle.opts').slideNum = slideNum;865 slideNum++;866 }867 }868 if ( slideToRemove ) {869 opts.slides = $( slides );870 opts.slideCount--;871 $( slideToRemove ).remove();872 if (index == opts.currSlide)873 opts.API.advanceSlide( 1 );874 else if ( index < opts.currSlide )875 opts.currSlide--;876 else877 opts.currSlide++;878 opts.API.trigger('cycle-slide-removed', [ opts, index, slideToRemove ]).log('cycle-slide-removed');879 opts.API.updateView();880 }881 }882 });883// listen for clicks on elements with data-cycle-cmd attribute884 $(document).on('click.cycle', '[data-cycle-cmd]', function(e) {885 // issue cycle command886 e.preventDefault();887 var el = $(this);888 var command = el.data('cycle-cmd');889 var context = el.data('cycle-context') || '.cycle-slideshow';890 $(context).cycle(command, el.data('cycle-arg'));891 });892})(jQuery);893/*! hash plugin for Cycle2; version: 20130905 */894(function($) {895 "use strict";896 $(document).on( 'cycle-pre-initialize', function( e, opts ) {897 onHashChange( opts, true );898 opts._onHashChange = function() {899 onHashChange( opts, false );900 };901 $( window ).on( 'hashchange', opts._onHashChange);902 });903 $(document).on( 'cycle-update-view', function( e, opts, slideOpts ) {904 if ( slideOpts.hash && ( '#' + slideOpts.hash ) != window.location.hash ) {905 opts._hashFence = true;906 window.location.hash = slideOpts.hash;907 }908 });909 $(document).on( 'cycle-destroyed', function( e, opts) {910 if ( opts._onHashChange ) {911 $( window ).off( 'hashchange', opts._onHashChange );912 }913 });914 function onHashChange( opts, setStartingSlide ) {915 var hash;916 if ( opts._hashFence ) {917 opts._hashFence = false;918 return;919 }920 hash = window.location.hash.substring(1);921 opts.slides.each(function(i) {922 if ( $(this).data( 'cycle-hash' ) == hash ) {923 if ( setStartingSlide === true ) {924 opts.startingSlide = i;925 }926 else {927 var fwd = opts.currSlide < i;928 opts.nextSlide = i;929 opts.API.prepareTx( true, fwd );930 }931 return false;932 }933 });934 }935})(jQuery);936/*! loader plugin for Cycle2; version: 20131121 */937(function($) {938 "use strict";939 $.extend($.fn.cycle.defaults, {940 loader: false941 });942 $(document).on( 'cycle-bootstrap', function( e, opts ) {943 var addFn;944 if ( !opts.loader )945 return;946 // override API.add for this slideshow947 addFn = opts.API.add;948 opts.API.add = add;949 function add( slides, prepend ) {950 var slideArr = [];951 if ( $.type( slides ) == 'string' )952 slides = $.trim( slides );953 else if ( $.type( slides) === 'array' ) {954 for (var i=0; i < slides.length; i++ )955 slides[i] = $(slides[i])[0];956 }957 slides = $( slides );958 var slideCount = slides.length;959 if ( ! slideCount )960 return;961 slides.css('visibility','hidden').appendTo('body').each(function(i) { // appendTo fixes #56962 var count = 0;963 var slide = $(this);964 var images = slide.is('img') ? slide : slide.find('img');965 slide.data('index', i);966 // allow some images to be marked as unimportant (and filter out images w/o src value)967 images = images.filter(':not(.cycle-loader-ignore)').filter(':not([src=""])');968 if ( ! images.length ) {969 --slideCount;970 slideArr.push( slide );971 return;972 }973 count = images.length;974 images.each(function() {975 // add images that are already loaded976 if ( this.complete ) {977 imageLoaded();978 }979 else {980 $(this).load(function() {981 imageLoaded();982 }).on("error", function() {983 if ( --count === 0 ) {984 // ignore this slide985 opts.API.log('slide skipped; img not loaded:', this.src);986 if ( --slideCount === 0 && opts.loader == 'wait') {987 addFn.apply( opts.API, [ slideArr, prepend ] );988 }989 }990 });991 }992 });993 function imageLoaded() {994 if ( --count === 0 ) {995 --slideCount;996 addSlide( slide );997 }998 }999 });1000 if ( slideCount )1001 opts.container.addClass('cycle-loading');1002 function addSlide( slide ) {1003 var curr;1004 if ( opts.loader == 'wait' ) {1005 slideArr.push( slide );1006 if ( slideCount === 0 ) {1007 // #59; sort slides into original markup order1008 slideArr.sort( sorter );1009 addFn.apply( opts.API, [ slideArr, prepend ] );1010 opts.container.removeClass('cycle-loading');1011 }1012 }1013 else {1014 curr = $(opts.slides[opts.currSlide]);1015 addFn.apply( opts.API, [ slide, prepend ] );1016 curr.show();1017 opts.container.removeClass('cycle-loading');1018 }1019 }1020 function sorter(a, b) {1021 return a.data('index') - b.data('index');1022 }1023 }1024 });1025})(jQuery);1026/*! pager plugin for Cycle2; version: 20140415 */1027(function($) {1028 "use strict";1029 $.extend($.fn.cycle.defaults, {1030 pager: '> .cycle-pager',1031 pagerActiveClass: 'cycle-pager-active',1032 pagerEvent: 'click.cycle',1033 pagerEventBubble: undefined,1034 pagerTemplate: '<span>•</span>'1035 });1036 $(document).on( 'cycle-bootstrap', function( e, opts, API ) {1037 // add method to API1038 API.buildPagerLink = buildPagerLink;1039 });1040 $(document).on( 'cycle-slide-added', function( e, opts, slideOpts, slideAdded ) {1041 if ( opts.pager ) {1042 opts.API.buildPagerLink ( opts, slideOpts, slideAdded );1043 opts.API.page = page;1044 }1045 });1046 $(document).on( 'cycle-slide-removed', function( e, opts, index, slideRemoved ) {1047 if ( opts.pager ) {1048 var pagers = opts.API.getComponent( 'pager' );1049 pagers.each(function() {1050 var pager = $(this);1051 $( pager.children()[index] ).remove();1052 });1053 }1054 });1055 $(document).on( 'cycle-update-view', function( e, opts, slideOpts ) {1056 var pagers;1057 if ( opts.pager ) {1058 pagers = opts.API.getComponent( 'pager' );1059 pagers.each(function() {1060 $(this).children().removeClass( opts.pagerActiveClass )1061 .eq( opts.currSlide ).addClass( opts.pagerActiveClass );1062 });1063 }1064 });1065 $(document).on( 'cycle-destroyed', function( e, opts ) {1066 var pager = opts.API.getComponent( 'pager' );1067 if ( pager ) {1068 pager.children().off( opts.pagerEvent ); // #2021069 if ( opts.pagerTemplate )1070 pager.empty();1071 }1072 });1073 function buildPagerLink( opts, slideOpts, slide ) {1074 var pagerLink;1075 var pagers = opts.API.getComponent( 'pager' );1076 pagers.each(function() {1077 var pager = $(this);1078 if ( slideOpts.pagerTemplate ) {1079 var markup = opts.API.tmpl( slideOpts.pagerTemplate, slideOpts, opts, slide[0] );1080 pagerLink = $( markup ).appendTo( pager );1081 }1082 else {1083 pagerLink = pager.children().eq( opts.slideCount - 1 );1084 }1085 pagerLink.on( opts.pagerEvent, function(e) {1086 if ( ! opts.pagerEventBubble )1087 e.preventDefault();1088 opts.API.page( pager, e.currentTarget);1089 });1090 });1091 }1092 function page( pager, target ) {1093 /*jshint validthis:true */1094 var opts = this.opts();1095 if ( opts.busy && ! opts.manualTrump )1096 return;1097 var index = pager.children().index( target );1098 var nextSlide = index;1099 var fwd = opts.currSlide < nextSlide;1100 if (opts.currSlide == nextSlide) {1101 return; // no op, clicked pager for the currently displayed slide1102 }1103 opts.nextSlide = nextSlide;1104 opts._tempFx = opts.pagerFx;1105 opts.API.prepareTx( true, fwd );1106 opts.API.trigger('cycle-pager-activated', [opts, pager, target ]);1107 }1108})(jQuery);1109/*! prevnext plugin for Cycle2; version: 20140408 */1110(function($) {1111 "use strict";1112 $.extend($.fn.cycle.defaults, {1113 next: '> .cycle-next',1114 nextEvent: 'click.cycle',1115 disabledClass: 'disabled',1116 prev: '> .cycle-prev',1117 prevEvent: 'click.cycle',1118 swipe: false1119 });1120 $(document).on( 'cycle-initialized', function( e, opts ) {1121 opts.API.getComponent( 'next' ).on( opts.nextEvent, function(e) {1122 e.preventDefault();1123 opts.API.next();1124 });1125 opts.API.getComponent( 'prev' ).on( opts.prevEvent, function(e) {1126 e.preventDefault();1127 opts.API.prev();1128 });1129 if ( opts.swipe ) {1130 var nextEvent = opts.swipeVert ? 'swipeUp.cycle' : 'swipeLeft.cycle swipeleft.cycle';1131 var prevEvent = opts.swipeVert ? 'swipeDown.cycle' : 'swipeRight.cycle swiperight.cycle';1132 opts.container.on( nextEvent, function(e) {1133 opts._tempFx = opts.swipeFx;1134 opts.API.next();1135 });1136 opts.container.on( prevEvent, function() {1137 opts._tempFx = opts.swipeFx;1138 opts.API.prev();1139 });1140 }1141 });1142 $(document).on( 'cycle-update-view', function( e, opts, slideOpts, currSlide ) {1143 if ( opts.allowWrap )1144 return;1145 var cls = opts.disabledClass;1146 var next = opts.API.getComponent( 'next' );1147 var prev = opts.API.getComponent( 'prev' );1148 var prevBoundry = opts._prevBoundry || 0;1149 var nextBoundry = (opts._nextBoundry !== undefined)?opts._nextBoundry:opts.slideCount - 1;1150 if ( opts.currSlide == nextBoundry )1151 next.addClass( cls ).prop( 'disabled', true );1152 else1153 next.removeClass( cls ).prop( 'disabled', false );1154 if ( opts.currSlide === prevBoundry )1155 prev.addClass( cls ).prop( 'disabled', true );1156 else1157 prev.removeClass( cls ).prop( 'disabled', false );1158 });1159 $(document).on( 'cycle-destroyed', function( e, opts ) {1160 opts.API.getComponent( 'prev' ).off( opts.nextEvent );1161 opts.API.getComponent( 'next' ).off( opts.prevEvent );1162 opts.container.off( 'swipeleft.cycle swiperight.cycle swipeLeft.cycle swipeRight.cycle swipeUp.cycle swipeDown.cycle' );1163 });1164})(jQuery);1165/*! progressive loader plugin for Cycle2; version: 20130315 */1166(function($) {1167 "use strict";1168 $.extend($.fn.cycle.defaults, {1169 progressive: false1170 });1171 $(document).on( 'cycle-pre-initialize', function( e, opts ) {1172 if ( !opts.progressive )1173 return;1174 var API = opts.API;1175 var nextFn = API.next;1176 var prevFn = API.prev;1177 var prepareTxFn = API.prepareTx;1178 var type = $.type( opts.progressive );1179 var slides, scriptEl;1180 if ( type == 'array' ) {1181 slides = opts.progressive;1182 }1183 else if ($.isFunction( opts.progressive ) ) {1184 slides = opts.progressive( opts );1185 }1186 else if ( type == 'string' ) {1187 scriptEl = $( opts.progressive );1188 slides = $.trim( scriptEl.html() );1189 if ( !slides )1190 return;1191 // is it json array?1192 if ( /^(\[)/.test( slides ) ) {1193 try {1194 slides = $.parseJSON( slides );1195 }1196 catch(err) {1197 API.log( 'error parsing progressive slides', err );1198 return;1199 }1200 }1201 else {1202 // plain text, split on delimeter1203 slides = slides.split( new RegExp( scriptEl.data('cycle-split') || '\n') );1204 // #95; look for empty slide1205 if ( ! slides[ slides.length - 1 ] )1206 slides.pop();1207 }1208 }1209 if ( prepareTxFn ) {1210 API.prepareTx = function( manual, fwd ) {1211 var index, slide;1212 if ( manual || slides.length === 0 ) {1213 prepareTxFn.apply( opts.API, [ manual, fwd ] );1214 return;1215 }1216 if ( fwd && opts.currSlide == ( opts.slideCount-1) ) {1217 slide = slides[ 0 ];1218 slides = slides.slice( 1 );1219 opts.container.one('cycle-slide-added', function(e, opts ) {1220 setTimeout(function() {1221 opts.API.advanceSlide( 1 );1222 },50);1223 });1224 opts.API.add( slide );1225 }1226 else if ( !fwd && opts.currSlide === 0 ) {1227 index = slides.length-1;1228 slide = slides[ index ];1229 slides = slides.slice( 0, index );1230 opts.container.one('cycle-slide-added', function(e, opts ) {1231 setTimeout(function() {1232 opts.currSlide = 1;1233 opts.API.advanceSlide( -1 );1234 },50);1235 });1236 opts.API.add( slide, true );1237 }1238 else {1239 prepareTxFn.apply( opts.API, [ manual, fwd ] );1240 }1241 };1242 }1243 if ( nextFn ) {1244 API.next = function() {1245 var opts = this.opts();1246 if ( slides.length && opts.currSlide == ( opts.slideCount - 1 ) ) {1247 var slide = slides[ 0 ];1248 slides = slides.slice( 1 );1249 opts.container.one('cycle-slide-added', function(e, opts ) {1250 nextFn.apply( opts.API );1251 opts.container.removeClass('cycle-loading');1252 });1253 opts.container.addClass('cycle-loading');1254 opts.API.add( slide );1255 }1256 else {1257 nextFn.apply( opts.API );1258 }1259 };1260 }1261 if ( prevFn ) {1262 API.prev = function() {1263 var opts = this.opts();1264 if ( slides.length && opts.currSlide === 0 ) {1265 var index = slides.length-1;1266 var slide = slides[ index ];1267 slides = slides.slice( 0, index );1268 opts.container.one('cycle-slide-added', function(e, opts ) {1269 opts.currSlide = 1;1270 opts.API.advanceSlide( -1 );1271 opts.container.removeClass('cycle-loading');1272 });1273 opts.container.addClass('cycle-loading');1274 opts.API.add( slide, true );1275 }1276 else {1277 prevFn.apply( opts.API );...
cycle2.js
Source:cycle2.js
...65 opts: function() {66 return this._container.data( 'cycle.opts' );67 },68 addInitialSlides: function() {69 var opts = this.opts();70 var slides = opts.slides;71 opts.slideCount = 0;72 opts.slides = $(); // empty set73 74 // add slides that already exist75 slides = slides.jquery ? slides : opts.container.find( slides );76 if ( opts.random ) {77 slides.sort(function() {return Math.random() - 0.5;});78 }79 opts.API.add( slides );80 },81 preInitSlideshow: function() {82 var opts = this.opts();83 opts.API.trigger('cycle-pre-initialize', [ opts ]);84 var tx = $.fn.cycle.transitions[opts.fx];85 if (tx && $.isFunction(tx.preInit))86 tx.preInit( opts );87 opts._preInitialized = true;88 },89 postInitSlideshow: function() {90 var opts = this.opts();91 opts.API.trigger('cycle-post-initialize', [ opts ]);92 var tx = $.fn.cycle.transitions[opts.fx];93 if (tx && $.isFunction(tx.postInit))94 tx.postInit( opts );95 },96 initSlideshow: function() {97 var opts = this.opts();98 var pauseObj = opts.container;99 var slideOpts;100 opts.API.calcFirstSlide();101 if ( opts.container.css('position') == 'static' )102 opts.container.css('position', 'relative');103 $(opts.slides[opts.currSlide]).css({104 opacity: 1,105 display: 'block',106 visibility: 'visible'107 });108 opts.API.stackSlides( opts.slides[opts.currSlide], opts.slides[opts.nextSlide], !opts.reverse );109 if ( opts.pauseOnHover ) {110 // allow pauseOnHover to specify an element111 if ( opts.pauseOnHover !== true )112 pauseObj = $( opts.pauseOnHover );113 pauseObj.hover(114 function(){ opts.API.pause( true ); }, 115 function(){ opts.API.resume( true ); }116 );117 }118 // stage initial transition119 if ( opts.timeout ) {120 slideOpts = opts.API.getSlideOpts( opts.currSlide );121 opts.API.queueTransition( slideOpts, slideOpts.timeout + opts.delay );122 }123 opts._initialized = true;124 opts.API.updateView( true );125 opts.API.trigger('cycle-initialized', [ opts ]);126 opts.API.postInitSlideshow();127 },128 pause: function( hover ) {129 var opts = this.opts(),130 slideOpts = opts.API.getSlideOpts(),131 alreadyPaused = opts.hoverPaused || opts.paused;132 if ( hover )133 opts.hoverPaused = true; 134 else135 opts.paused = true;136 if ( ! alreadyPaused ) {137 opts.container.addClass('cycle-paused');138 opts.API.trigger('cycle-paused', [ opts ]).log('cycle-paused');139 if ( slideOpts.timeout ) {140 clearTimeout( opts.timeoutId );141 opts.timeoutId = 0;142 143 // determine how much time is left for the current slide144 opts._remainingTimeout -= ( $.now() - opts._lastQueue );145 if ( opts._remainingTimeout < 0 || isNaN(opts._remainingTimeout) )146 opts._remainingTimeout = undefined;147 }148 }149 },150 resume: function( hover ) {151 var opts = this.opts(),152 alreadyResumed = !opts.hoverPaused && !opts.paused,153 remaining;154 if ( hover )155 opts.hoverPaused = false; 156 else157 opts.paused = false;158 159 if ( ! alreadyResumed ) {160 opts.container.removeClass('cycle-paused');161 // #gh-230; if an animation is in progress then don't queue a new transition; it will162 // happen naturally163 if ( opts.slides.filter(':animated').length === 0 )164 opts.API.queueTransition( opts.API.getSlideOpts(), opts._remainingTimeout );165 opts.API.trigger('cycle-resumed', [ opts, opts._remainingTimeout ] ).log('cycle-resumed');166 }167 },168 add: function( slides, prepend ) {169 var opts = this.opts();170 var oldSlideCount = opts.slideCount;171 var startSlideshow = false;172 var len;173 if ( $.type(slides) == 'string')174 slides = $.trim( slides );175 $( slides ).each(function(i) {176 var slideOpts;177 var slide = $(this);178 if ( prepend )179 opts.container.prepend( slide );180 else181 opts.container.append( slide );182 opts.slideCount++;183 slideOpts = opts.API.buildSlideOpts( slide );184 if ( prepend )185 opts.slides = $( slide ).add( opts.slides );186 else187 opts.slides = opts.slides.add( slide );188 opts.API.initSlide( slideOpts, slide, --opts._maxZ );189 slide.data('cycle.opts', slideOpts);190 opts.API.trigger('cycle-slide-added', [ opts, slideOpts, slide ]);191 });192 opts.API.updateView( true );193 startSlideshow = opts._preInitialized && (oldSlideCount < 2 && opts.slideCount >= 1);194 if ( startSlideshow ) {195 if ( !opts._initialized )196 opts.API.initSlideshow();197 else if ( opts.timeout ) {198 len = opts.slides.length;199 opts.nextSlide = opts.reverse ? len - 1 : 1;200 if ( !opts.timeoutId ) {201 opts.API.queueTransition( opts );202 }203 }204 }205 },206 calcFirstSlide: function() {207 var opts = this.opts();208 var firstSlideIndex;209 firstSlideIndex = parseInt( opts.startingSlide || 0, 10 );210 if (firstSlideIndex >= opts.slides.length || firstSlideIndex < 0)211 firstSlideIndex = 0;212 opts.currSlide = firstSlideIndex;213 if ( opts.reverse ) {214 opts.nextSlide = firstSlideIndex - 1;215 if (opts.nextSlide < 0)216 opts.nextSlide = opts.slides.length - 1;217 }218 else {219 opts.nextSlide = firstSlideIndex + 1;220 if (opts.nextSlide == opts.slides.length)221 opts.nextSlide = 0;222 }223 },224 calcNextSlide: function() {225 var opts = this.opts();226 var roll;227 if ( opts.reverse ) {228 roll = (opts.nextSlide - 1) < 0;229 opts.nextSlide = roll ? opts.slideCount - 1 : opts.nextSlide-1;230 opts.currSlide = roll ? 0 : opts.nextSlide+1;231 }232 else {233 roll = (opts.nextSlide + 1) == opts.slides.length;234 opts.nextSlide = roll ? 0 : opts.nextSlide+1;235 opts.currSlide = roll ? opts.slides.length-1 : opts.nextSlide-1;236 }237 },238 calcTx: function( slideOpts, manual ) {239 var opts = slideOpts;240 var tx;241 if ( opts._tempFx )242 tx = $.fn.cycle.transitions[opts._tempFx];243 else if ( manual && opts.manualFx )244 tx = $.fn.cycle.transitions[opts.manualFx];245 if ( !tx )246 tx = $.fn.cycle.transitions[opts.fx];247 opts._tempFx = null;248 this.opts()._tempFx = null;249 if (!tx) {250 tx = $.fn.cycle.transitions.fade;251 opts.API.log('Transition "' + opts.fx + '" not found. Using fade.');252 }253 return tx;254 },255 prepareTx: function( manual, fwd ) {256 var opts = this.opts();257 var after, curr, next, slideOpts, tx;258 if ( opts.slideCount < 2 ) {259 opts.timeoutId = 0;260 return;261 }262 if ( manual && ( !opts.busy || opts.manualTrump ) ) {263 opts.API.stopTransition();264 opts.busy = false;265 clearTimeout(opts.timeoutId);266 opts.timeoutId = 0;267 }268 if ( opts.busy )269 return;270 if ( opts.timeoutId === 0 && !manual )271 return;272 curr = opts.slides[opts.currSlide];273 next = opts.slides[opts.nextSlide];274 slideOpts = opts.API.getSlideOpts( opts.nextSlide );275 tx = opts.API.calcTx( slideOpts, manual );276 opts._tx = tx;277 if ( manual && slideOpts.manualSpeed !== undefined )278 slideOpts.speed = slideOpts.manualSpeed;279 // if ( opts.nextSlide === opts.currSlide )280 // opts.API.calcNextSlide();281 // ensure that:282 // 1. advancing to a different slide283 // 2. this is either a manual event (prev/next, pager, cmd) or 284 // a timer event and slideshow is not paused285 if ( opts.nextSlide != opts.currSlide && 286 (manual || (!opts.paused && !opts.hoverPaused && opts.timeout) )) { // #62287 opts.API.trigger('cycle-before', [ slideOpts, curr, next, fwd ]);288 if ( tx.before )289 tx.before( slideOpts, curr, next, fwd );290 after = function() {291 opts.busy = false;292 // #76; bail if slideshow has been destroyed293 if (! opts.container.data( 'cycle.opts' ) )294 return;295 if (tx.after)296 tx.after( slideOpts, curr, next, fwd );297 opts.API.trigger('cycle-after', [ slideOpts, curr, next, fwd ]);298 opts.API.queueTransition( slideOpts);299 opts.API.updateView( true );300 };301 opts.busy = true;302 if (tx.transition)303 tx.transition(slideOpts, curr, next, fwd, after);304 else305 opts.API.doTransition( slideOpts, curr, next, fwd, after);306 opts.API.calcNextSlide();307 opts.API.updateView();308 } else {309 opts.API.queueTransition( slideOpts );310 }311 },312 // perform the actual animation313 doTransition: function( slideOpts, currEl, nextEl, fwd, callback) {314 var opts = slideOpts;315 var curr = $(currEl), next = $(nextEl);316 var fn = function() {317 // make sure animIn has something so that callback doesn't trigger immediately318 next.animate(opts.animIn || { opacity: 1}, opts.speed, opts.easeIn || opts.easing, callback);319 };320 next.css(opts.cssBefore || {});321 curr.animate(opts.animOut || {}, opts.speed, opts.easeOut || opts.easing, function() {322 curr.css(opts.cssAfter || {});323 if (!opts.sync) {324 fn();325 }326 });327 if (opts.sync) {328 fn();329 }330 },331 queueTransition: function( slideOpts, specificTimeout ) {332 var opts = this.opts();333 var timeout = specificTimeout !== undefined ? specificTimeout : slideOpts.timeout;334 if (opts.nextSlide === 0 && --opts.loop === 0) {335 opts.API.log('terminating; loop=0');336 opts.timeout = 0;337 if ( timeout ) {338 setTimeout(function() {339 opts.API.trigger('cycle-finished', [ opts ]);340 }, timeout);341 }342 else {343 opts.API.trigger('cycle-finished', [ opts ]);344 }345 // reset nextSlide346 opts.nextSlide = opts.currSlide;347 return;348 }349 if ( opts.continueAuto !== undefined ) {350 if ( opts.continueAuto === false || 351 ($.isFunction(opts.continueAuto) && opts.continueAuto() === false )) {352 opts.API.log('terminating automatic transitions');353 opts.timeout = 0;354 if ( opts.timeoutId )355 clearTimeout(opts.timeoutId);356 return;357 }358 }359 if ( timeout ) {360 opts._lastQueue = $.now();361 if ( specificTimeout === undefined )362 opts._remainingTimeout = slideOpts.timeout;363 if ( !opts.paused && ! opts.hoverPaused ) {364 opts.timeoutId = setTimeout(function() { 365 opts.API.prepareTx( false, !opts.reverse ); 366 }, timeout );367 }368 }369 },370 stopTransition: function() {371 var opts = this.opts();372 if ( opts.slides.filter(':animated').length ) {373 opts.slides.stop(false, true);374 opts.API.trigger('cycle-transition-stopped', [ opts ]);375 }376 if ( opts._tx && opts._tx.stopTransition )377 opts._tx.stopTransition( opts );378 },379 // advance slide forward or back380 advanceSlide: function( val ) {381 var opts = this.opts();382 clearTimeout(opts.timeoutId);383 opts.timeoutId = 0;384 opts.nextSlide = opts.currSlide + val;385 386 if (opts.nextSlide < 0)387 opts.nextSlide = opts.slides.length - 1;388 else if (opts.nextSlide >= opts.slides.length)389 opts.nextSlide = 0;390 opts.API.prepareTx( true, val >= 0 );391 return false;392 },393 buildSlideOpts: function( slide ) {394 var opts = this.opts();395 var val, shortName;396 var slideOpts = slide.data() || {};397 for (var p in slideOpts) {398 // allow props to be accessed sans 'cycle' prefix and log the overrides399 if (slideOpts.hasOwnProperty(p) && /^cycle[A-Z]+/.test(p) ) {400 val = slideOpts[p];401 shortName = p.match(/^cycle(.*)/)[1].replace(/^[A-Z]/, lowerCase);402 opts.API.log('['+(opts.slideCount-1)+']', shortName+':', val, '('+typeof val +')');403 slideOpts[shortName] = val;404 }405 }406 slideOpts = $.extend( {}, $.fn.cycle.defaults, opts, slideOpts );407 slideOpts.slideNum = opts.slideCount;408 try {409 // these props should always be read from the master state object410 delete slideOpts.API;411 delete slideOpts.slideCount;412 delete slideOpts.currSlide;413 delete slideOpts.nextSlide;414 delete slideOpts.slides;415 } catch(e) {416 // no op417 }418 return slideOpts;419 },420 getSlideOpts: function( index ) {421 var opts = this.opts();422 if ( index === undefined )423 index = opts.currSlide;424 var slide = opts.slides[index];425 var slideOpts = $(slide).data('cycle.opts');426 return $.extend( {}, opts, slideOpts );427 },428 429 initSlide: function( slideOpts, slide, suggestedZindex ) {430 var opts = this.opts();431 slide.css( slideOpts.slideCss || {} );432 if ( suggestedZindex > 0 )433 slide.css( 'zIndex', suggestedZindex );434 // ensure that speed settings are sane435 if ( isNaN( slideOpts.speed ) )436 slideOpts.speed = $.fx.speeds[slideOpts.speed] || $.fx.speeds._default;437 if ( !slideOpts.sync )438 slideOpts.speed = slideOpts.speed / 2;439 slide.addClass( opts.slideClass );440 },441 updateView: function( isAfter, isDuring, forceEvent ) {442 var opts = this.opts();443 if ( !opts._initialized )444 return;445 var slideOpts = opts.API.getSlideOpts();446 var currSlide = opts.slides[ opts.currSlide ];447 if ( ! isAfter && isDuring !== true ) {448 opts.API.trigger('cycle-update-view-before', [ opts, slideOpts, currSlide ]);449 if ( opts.updateView < 0 )450 return;451 }452 if ( opts.slideActiveClass ) {453 opts.slides.removeClass( opts.slideActiveClass )454 .eq( opts.currSlide ).addClass( opts.slideActiveClass );455 }456 if ( isAfter && opts.hideNonActive )457 opts.slides.filter( ':not(.' + opts.slideActiveClass + ')' ).css('visibility', 'hidden');458 if ( opts.updateView === 0 ) {459 setTimeout(function() {460 opts.API.trigger('cycle-update-view', [ opts, slideOpts, currSlide, isAfter ]);461 }, slideOpts.speed / (opts.sync ? 2 : 1) );462 }463 if ( opts.updateView !== 0 )464 opts.API.trigger('cycle-update-view', [ opts, slideOpts, currSlide, isAfter ]);465 466 if ( isAfter )467 opts.API.trigger('cycle-update-view-after', [ opts, slideOpts, currSlide ]);468 },469 getComponent: function( name ) {470 var opts = this.opts();471 var selector = opts[name];472 if (typeof selector === 'string') {473 // if selector is a child, sibling combinator, adjancent selector then use find, otherwise query full dom474 return (/^\s*[\>|\+|~]/).test( selector ) ? opts.container.find( selector ) : $( selector );475 }476 if (selector.jquery)477 return selector;478 479 return $(selector);480 },481 stackSlides: function( curr, next, fwd ) {482 var opts = this.opts();483 if ( !curr ) {484 curr = opts.slides[opts.currSlide];485 next = opts.slides[opts.nextSlide];486 fwd = !opts.reverse;487 }488 // reset the zIndex for the common case:489 // curr slide on top, next slide beneath, and the rest in order to be shown490 $(curr).css('zIndex', opts.maxZ);491 var i;492 var z = opts.maxZ - 2;493 var len = opts.slideCount;494 if (fwd) {495 for ( i = opts.currSlide + 1; i < len; i++ )496 $( opts.slides[i] ).css( 'zIndex', z-- );497 for ( i = 0; i < opts.currSlide; i++ )498 $( opts.slides[i] ).css( 'zIndex', z-- );499 }500 else {501 for ( i = opts.currSlide - 1; i >= 0; i-- )502 $( opts.slides[i] ).css( 'zIndex', z-- );503 for ( i = len - 1; i > opts.currSlide; i-- )504 $( opts.slides[i] ).css( 'zIndex', z-- );505 }506 $(next).css('zIndex', opts.maxZ - 1);507 },508 getSlideIndex: function( el ) {509 return this.opts().slides.index( el );510 }511}; // API512// default logger513$.fn.cycle.log = function log() {514 /*global console:true */515 if (window.console && console.log)516 console.log('[cycle2] ' + Array.prototype.join.call(arguments, ' ') );517};518$.fn.cycle.version = function() { return 'Cycle2: ' + version; };519// helper functions520function lowerCase(s) {521 return (s || '').toLowerCase();522}523// expose transition object524$.fn.cycle.transitions = {525 custom: {526 },527 none: {528 before: function( opts, curr, next, fwd ) {529 opts.API.stackSlides( next, curr, fwd );530 opts.cssBefore = { opacity: 1, visibility: 'visible', display: 'block' };531 }532 },533 fade: {534 before: function( opts, curr, next, fwd ) {535 var css = opts.API.getSlideOpts( opts.nextSlide ).slideCss || {};536 opts.API.stackSlides( curr, next, fwd );537 opts.cssBefore = $.extend(css, { opacity: 0, visibility: 'visible', display: 'block' });538 opts.animIn = { opacity: 1 };539 opts.animOut = { opacity: 0 };540 }541 },542 fadeout: {543 before: function( opts , curr, next, fwd ) {544 var css = opts.API.getSlideOpts( opts.nextSlide ).slideCss || {};545 opts.API.stackSlides( curr, next, fwd );546 opts.cssBefore = $.extend(css, { opacity: 1, visibility: 'visible', display: 'block' });547 opts.animOut = { opacity: 0 };548 }549 },550 scrollHorz: {551 before: function( opts, curr, next, fwd ) {552 opts.API.stackSlides( curr, next, fwd );553 var w = opts.container.css('overflow','hidden').width();554 opts.cssBefore = { left: fwd ? w : - w, top: 0, opacity: 1, visibility: 'visible', display: 'block' };555 opts.cssAfter = { zIndex: opts._maxZ - 2, left: 0 };556 opts.animIn = { left: 0 };557 opts.animOut = { left: fwd ? -w : w };558 }559 }560};561// @see: http://jquery.malsup.com/cycle2/api562$.fn.cycle.defaults = {563 allowWrap: true,564 autoSelector: '.cycle-slideshow[data-cycle-auto-init!=false]',565 delay: 0,566 easing: null,567 fx: 'fade',568 hideNonActive: true,569 loop: 0,570 manualFx: undefined,571 manualSpeed: undefined,572 manualTrump: true,573 maxZ: 100,574 pauseOnHover: false,575 reverse: false,576 slideActiveClass: 'cycle-slide-active',577 slideClass: 'cycle-slide',578 slideCss: { position: 'absolute', top: 0, left: 0 },579 slides: '> img',580 speed: 500,581 startingSlide: 0,582 sync: true,583 timeout: 4000,584 updateView: 0585};586// automatically find and run slideshows587$(document).ready(function() {588 $( $.fn.cycle.defaults.autoSelector ).cycle();589});590})(jQuery);591/*! Cycle2 autoheight plugin; Copyright (c) M.Alsup, 2012; version: 20130913 */592(function($) {593"use strict";594$.extend($.fn.cycle.defaults, {595 autoHeight: 0, // setting this option to false disables autoHeight logic596 autoHeightSpeed: 250,597 autoHeightEasing: null598}); 599$(document).on( 'cycle-initialized', function( e, opts ) {600 var autoHeight = opts.autoHeight;601 var t = $.type( autoHeight );602 var resizeThrottle = null;603 var ratio;604 if ( t !== 'string' && t !== 'number' )605 return;606 // bind events607 opts.container.on( 'cycle-slide-added cycle-slide-removed', initAutoHeight );608 opts.container.on( 'cycle-destroyed', onDestroy );609 if ( autoHeight == 'container' ) {610 opts.container.on( 'cycle-before', onBefore );611 }612 else if ( t === 'string' && /\d+\:\d+/.test( autoHeight ) ) { 613 // use ratio614 ratio = autoHeight.match(/(\d+)\:(\d+)/);615 ratio = ratio[1] / ratio[2];616 opts._autoHeightRatio = ratio;617 }618 // if autoHeight is a number then we don't need to recalculate the sentinel619 // index on resize620 if ( t !== 'number' ) {621 // bind unique resize handler per slideshow (so it can be 'off-ed' in onDestroy)622 opts._autoHeightOnResize = function () {623 clearTimeout( resizeThrottle );624 resizeThrottle = setTimeout( onResize, 50 );625 };626 $(window).on( 'resize orientationchange', opts._autoHeightOnResize );627 }628 setTimeout( onResize, 30 );629 function onResize() {630 initAutoHeight( e, opts );631 }632});633function initAutoHeight( e, opts ) {634 var clone, height, sentinelIndex;635 var autoHeight = opts.autoHeight;636 if ( autoHeight == 'container' ) {637 height = $( opts.slides[ opts.currSlide ] ).outerHeight();638 opts.container.height( height );639 }640 else if ( opts._autoHeightRatio ) { 641 opts.container.height( opts.container.width() / opts._autoHeightRatio );642 }643 else if ( autoHeight === 'calc' || ( $.type( autoHeight ) == 'number' && autoHeight >= 0 ) ) {644 if ( autoHeight === 'calc' )645 sentinelIndex = calcSentinelIndex( e, opts );646 else if ( autoHeight >= opts.slides.length )647 sentinelIndex = 0;648 else 649 sentinelIndex = autoHeight;650 // only recreate sentinel if index is different651 if ( sentinelIndex == opts._sentinelIndex )652 return;653 opts._sentinelIndex = sentinelIndex;654 if ( opts._sentinel )655 opts._sentinel.remove();656 // clone existing slide as sentinel657 clone = $( opts.slides[ sentinelIndex ].cloneNode(true) );658 659 // #50; remove special attributes from cloned content660 clone.removeAttr( 'id name rel' ).find( '[id],[name],[rel]' ).removeAttr( 'id name rel' );661 clone.css({662 position: 'static',663 visibility: 'hidden',664 display: 'block'665 }).prependTo( opts.container ).addClass('cycle-sentinel cycle-slide').removeClass('cycle-slide-active');666 clone.find( '*' ).css( 'visibility', 'hidden' );667 opts._sentinel = clone;668 }669} 670function calcSentinelIndex( e, opts ) {671 var index = 0, max = -1;672 // calculate tallest slide index673 opts.slides.each(function(i) {674 var h = $(this).height();675 if ( h > max ) {676 max = h;677 index = i;678 }679 });680 return index;681}682function onBefore( e, opts, outgoing, incoming, forward ) {683 var h = $(incoming).outerHeight();684 opts.container.animate( { height: h }, opts.autoHeightSpeed, opts.autoHeightEasing );685}686function onDestroy( e, opts ) {687 if ( opts._autoHeightOnResize ) {688 $(window).off( 'resize orientationchange', opts._autoHeightOnResize );689 opts._autoHeightOnResize = null;690 }691 opts.container.off( 'cycle-slide-added cycle-slide-removed', initAutoHeight );692 opts.container.off( 'cycle-destroyed', onDestroy );693 opts.container.off( 'cycle-before', onBefore );694 if ( opts._sentinel ) {695 opts._sentinel.remove();696 opts._sentinel = null;697 }698}699})(jQuery);700/*! caption plugin for Cycle2; version: 20130306 */701(function($) {702"use strict";703$.extend($.fn.cycle.defaults, {704 caption: '> .cycle-caption',705 captionTemplate: '{{slideNum}} / {{slideCount}}',706 overlay: '> .cycle-overlay',707 overlayTemplate: '<div>{{title}}</div><div>{{desc}}</div>',708 captionModule: 'caption'709}); 710$(document).on( 'cycle-update-view', function( e, opts, slideOpts, currSlide ) {711 if ( opts.captionModule !== 'caption' )712 return;713 var el;714 $.each(['caption','overlay'], function() {715 var name = this; 716 var template = slideOpts[name+'Template'];717 var el = opts.API.getComponent( name );718 if( el.length && template ) {719 el.html( opts.API.tmpl( template, slideOpts, opts, currSlide ) );720 el.show();721 }722 else {723 el.hide();724 }725 });726});727$(document).on( 'cycle-destroyed', function( e, opts ) {728 var el;729 $.each(['caption','overlay'], function() {730 var name = this, template = opts[name+'Template'];731 if ( opts[name] && template ) {732 el = opts.API.getComponent( 'caption' );733 el.empty();734 }735 });736});737})(jQuery);738/*! command plugin for Cycle2; version: 20140415 */739(function($) {740"use strict";741var c2 = $.fn.cycle;742$.fn.cycle = function( options ) {743 var cmd, cmdFn, opts;744 var args = $.makeArray( arguments );745 if ( $.type( options ) == 'number' ) {746 return this.cycle( 'goto', options );747 }748 if ( $.type( options ) == 'string' ) {749 return this.each(function() {750 var cmdArgs;751 cmd = options;752 opts = $(this).data('cycle.opts');753 if ( opts === undefined ) {754 c2.log('slideshow must be initialized before sending commands; "' + cmd + '" ignored');755 return;756 }757 else {758 cmd = cmd == 'goto' ? 'jump' : cmd; // issue #3; change 'goto' to 'jump' internally759 cmdFn = opts.API[ cmd ];760 if ( $.isFunction( cmdFn )) {761 cmdArgs = $.makeArray( args );762 cmdArgs.shift();763 return cmdFn.apply( opts.API, cmdArgs );764 }765 else {766 c2.log( 'unknown command: ', cmd );767 }768 }769 });770 }771 else {772 return c2.apply( this, arguments );773 }774};775// copy props776$.extend( $.fn.cycle, c2 );777$.extend( c2.API, {778 next: function() {779 var opts = this.opts();780 if ( opts.busy && ! opts.manualTrump )781 return;782 var count = opts.reverse ? -1 : 1;783 if ( opts.allowWrap === false && ( opts.currSlide + count ) >= opts.slideCount )784 return;785 opts.API.advanceSlide( count );786 opts.API.trigger('cycle-next', [ opts ]).log('cycle-next');787 },788 prev: function() {789 var opts = this.opts();790 if ( opts.busy && ! opts.manualTrump )791 return;792 var count = opts.reverse ? 1 : -1;793 if ( opts.allowWrap === false && ( opts.currSlide + count ) < 0 )794 return;795 opts.API.advanceSlide( count );796 opts.API.trigger('cycle-prev', [ opts ]).log('cycle-prev');797 },798 destroy: function() {799 this.stop(); //#204800 var opts = this.opts();801 var clean = $.isFunction( $._data ) ? $._data : $.noop; // hack for #184 and #201802 clearTimeout(opts.timeoutId);803 opts.timeoutId = 0;804 opts.API.stop();805 opts.API.trigger( 'cycle-destroyed', [ opts ] ).log('cycle-destroyed');806 opts.container.removeData();807 clean( opts.container[0], 'parsedAttrs', false );808 // #75; remove inline styles809 if ( ! opts.retainStylesOnDestroy ) {810 opts.container.removeAttr( 'style' );811 opts.slides.removeAttr( 'style' );812 opts.slides.removeClass( opts.slideActiveClass );813 }814 opts.slides.each(function() {815 var slide = $(this);816 slide.removeData();817 slide.removeClass( opts.slideClass );818 clean( this, 'parsedAttrs', false );819 });820 },821 jump: function( index, fx ) {822 // go to the requested slide823 var fwd;824 var opts = this.opts();825 if ( opts.busy && ! opts.manualTrump )826 return;827 var num = parseInt( index, 10 );828 if (isNaN(num) || num < 0 || num >= opts.slides.length) {829 opts.API.log('goto: invalid slide index: ' + num);830 return;831 }832 if (num == opts.currSlide) {833 opts.API.log('goto: skipping, already on slide', num);834 return;835 }836 opts.nextSlide = num;837 clearTimeout(opts.timeoutId);838 opts.timeoutId = 0;839 opts.API.log('goto: ', num, ' (zero-index)');840 fwd = opts.currSlide < opts.nextSlide;841 opts._tempFx = fx;842 opts.API.prepareTx( true, fwd );843 },844 stop: function() {845 var opts = this.opts();846 var pauseObj = opts.container;847 clearTimeout(opts.timeoutId);848 opts.timeoutId = 0;849 opts.API.stopTransition();850 if ( opts.pauseOnHover ) {851 if ( opts.pauseOnHover !== true )852 pauseObj = $( opts.pauseOnHover );853 pauseObj.off('mouseenter mouseleave');854 }855 opts.API.trigger('cycle-stopped', [ opts ]).log('cycle-stopped');856 },857 reinit: function() {858 var opts = this.opts();859 opts.API.destroy();860 opts.container.cycle();861 },862 remove: function( index ) {863 var opts = this.opts();864 var slide, slideToRemove, slides = [], slideNum = 1;865 for ( var i=0; i < opts.slides.length; i++ ) {866 slide = opts.slides[i];867 if ( i == index ) {868 slideToRemove = slide;869 }870 else {871 slides.push( slide );872 $( slide ).data('cycle.opts').slideNum = slideNum;873 slideNum++;874 }875 }876 if ( slideToRemove ) {877 opts.slides = $( slides );878 opts.slideCount--;879 $( slideToRemove ).remove();880 if (index == opts.currSlide)881 opts.API.advanceSlide( 1 );882 else if ( index < opts.currSlide )883 opts.currSlide--;884 else885 opts.currSlide++;886 opts.API.trigger('cycle-slide-removed', [ opts, index, slideToRemove ]).log('cycle-slide-removed');887 opts.API.updateView();888 }889 }890});891// listen for clicks on elements with data-cycle-cmd attribute892$(document).on('click.cycle', '[data-cycle-cmd]', function(e) {893 // issue cycle command894 e.preventDefault();895 var el = $(this);896 var command = el.data('cycle-cmd');897 var context = el.data('cycle-context') || '.cycle-slideshow';898 $(context).cycle(command, el.data('cycle-arg'));899});900})(jQuery);901/*! hash plugin for Cycle2; version: 20130905 */902(function($) {903"use strict";904$(document).on( 'cycle-pre-initialize', function( e, opts ) {905 onHashChange( opts, true );906 opts._onHashChange = function() {907 onHashChange( opts, false );908 };909 $( window ).on( 'hashchange', opts._onHashChange);910});911$(document).on( 'cycle-update-view', function( e, opts, slideOpts ) {912 if ( slideOpts.hash && ( '#' + slideOpts.hash ) != window.location.hash ) {913 opts._hashFence = true;914 window.location.hash = slideOpts.hash;915 }916});917$(document).on( 'cycle-destroyed', function( e, opts) {918 if ( opts._onHashChange ) {919 $( window ).off( 'hashchange', opts._onHashChange );920 }921});922function onHashChange( opts, setStartingSlide ) {923 var hash;924 if ( opts._hashFence ) {925 opts._hashFence = false;926 return;927 }928 929 hash = window.location.hash.substring(1);930 opts.slides.each(function(i) {931 if ( $(this).data( 'cycle-hash' ) == hash ) {932 if ( setStartingSlide === true ) {933 opts.startingSlide = i;934 }935 else {936 var fwd = opts.currSlide < i;937 opts.nextSlide = i;938 opts.API.prepareTx( true, fwd );939 }940 return false;941 }942 });943}944})(jQuery);945/*! loader plugin for Cycle2; version: 20131121 */946(function($) {947"use strict";948$.extend($.fn.cycle.defaults, {949 loader: false950});951$(document).on( 'cycle-bootstrap', function( e, opts ) {952 var addFn;953 if ( !opts.loader )954 return;955 // override API.add for this slideshow956 addFn = opts.API.add;957 opts.API.add = add;958 function add( slides, prepend ) {959 var slideArr = [];960 if ( $.type( slides ) == 'string' )961 slides = $.trim( slides );962 else if ( $.type( slides) === 'array' ) {963 for (var i=0; i < slides.length; i++ )964 slides[i] = $(slides[i])[0];965 }966 slides = $( slides );967 var slideCount = slides.length;968 if ( ! slideCount )969 return;970 slides.css('visibility','hidden').appendTo('body').each(function(i) { // appendTo fixes #56971 var count = 0;972 var slide = $(this);973 var images = slide.is('img') ? slide : slide.find('img');974 slide.data('index', i);975 // allow some images to be marked as unimportant (and filter out images w/o src value)976 images = images.filter(':not(.cycle-loader-ignore)').filter(':not([src=""])');977 if ( ! images.length ) {978 --slideCount;979 slideArr.push( slide );980 return;981 }982 count = images.length;983 images.each(function() {984 // add images that are already loaded985 if ( this.complete ) {986 imageLoaded();987 }988 else {989 $(this).load(function() {990 imageLoaded();991 }).on("error", function() {992 if ( --count === 0 ) {993 // ignore this slide994 opts.API.log('slide skipped; img not loaded:', this.src);995 if ( --slideCount === 0 && opts.loader == 'wait') {996 addFn.apply( opts.API, [ slideArr, prepend ] );997 }998 }999 });1000 }1001 });1002 function imageLoaded() {1003 if ( --count === 0 ) {1004 --slideCount;1005 addSlide( slide );1006 }1007 }1008 });1009 if ( slideCount )1010 opts.container.addClass('cycle-loading');1011 1012 function addSlide( slide ) {1013 var curr;1014 if ( opts.loader == 'wait' ) {1015 slideArr.push( slide );1016 if ( slideCount === 0 ) {1017 // #59; sort slides into original markup order1018 slideArr.sort( sorter );1019 addFn.apply( opts.API, [ slideArr, prepend ] );1020 opts.container.removeClass('cycle-loading');1021 }1022 }1023 else {1024 curr = $(opts.slides[opts.currSlide]);1025 addFn.apply( opts.API, [ slide, prepend ] );1026 curr.show();1027 opts.container.removeClass('cycle-loading');1028 }1029 }1030 function sorter(a, b) {1031 return a.data('index') - b.data('index');1032 }1033 }1034});1035})(jQuery);1036/*! pager plugin for Cycle2; version: 20140415 */1037(function($) {1038"use strict";1039$.extend($.fn.cycle.defaults, {1040 pager: '> .cycle-pager',1041 pagerActiveClass: 'cycle-pager-active',1042 pagerEvent: 'click.cycle',1043 pagerEventBubble: undefined,1044 pagerTemplate: '<span>•</span>'1045});1046$(document).on( 'cycle-bootstrap', function( e, opts, API ) {1047 // add method to API1048 API.buildPagerLink = buildPagerLink;1049});1050$(document).on( 'cycle-slide-added', function( e, opts, slideOpts, slideAdded ) {1051 if ( opts.pager ) {1052 opts.API.buildPagerLink ( opts, slideOpts, slideAdded );1053 opts.API.page = page;1054 }1055});1056$(document).on( 'cycle-slide-removed', function( e, opts, index, slideRemoved ) {1057 if ( opts.pager ) {1058 var pagers = opts.API.getComponent( 'pager' );1059 pagers.each(function() {1060 var pager = $(this);1061 $( pager.children()[index] ).remove();1062 });1063 }1064});1065$(document).on( 'cycle-update-view', function( e, opts, slideOpts ) {1066 var pagers;1067 if ( opts.pager ) {1068 pagers = opts.API.getComponent( 'pager' );1069 pagers.each(function() {1070 $(this).children().removeClass( opts.pagerActiveClass )1071 .eq( opts.currSlide ).addClass( opts.pagerActiveClass );1072 });1073 }1074});1075$(document).on( 'cycle-destroyed', function( e, opts ) {1076 var pager = opts.API.getComponent( 'pager' );1077 if ( pager ) {1078 pager.children().off( opts.pagerEvent ); // #2021079 if ( opts.pagerTemplate )1080 pager.empty();1081 }1082});1083function buildPagerLink( opts, slideOpts, slide ) {1084 var pagerLink;1085 var pagers = opts.API.getComponent( 'pager' );1086 pagers.each(function() {1087 var pager = $(this);1088 if ( slideOpts.pagerTemplate ) {1089 var markup = opts.API.tmpl( slideOpts.pagerTemplate, slideOpts, opts, slide[0] );1090 pagerLink = $( markup ).appendTo( pager );1091 }1092 else {1093 pagerLink = pager.children().eq( opts.slideCount - 1 );1094 }1095 pagerLink.on( opts.pagerEvent, function(e) {1096 if ( ! opts.pagerEventBubble )1097 e.preventDefault();1098 opts.API.page( pager, e.currentTarget);1099 });1100 });1101}1102function page( pager, target ) {1103 /*jshint validthis:true */1104 var opts = this.opts();1105 if ( opts.busy && ! opts.manualTrump )1106 return;1107 var index = pager.children().index( target );1108 var nextSlide = index;1109 var fwd = opts.currSlide < nextSlide;1110 if (opts.currSlide == nextSlide) {1111 return; // no op, clicked pager for the currently displayed slide1112 }1113 opts.nextSlide = nextSlide;1114 opts._tempFx = opts.pagerFx;1115 opts.API.prepareTx( true, fwd );1116 opts.API.trigger('cycle-pager-activated', [opts, pager, target ]);1117}1118})(jQuery);1119/*! prevnext plugin for Cycle2; version: 20140408 */1120(function($) {1121"use strict";1122$.extend($.fn.cycle.defaults, {1123 next: '> .cycle-next',1124 nextEvent: 'click.cycle',1125 disabledClass: 'disabled',1126 prev: '> .cycle-prev',1127 prevEvent: 'click.cycle',1128 swipe: false1129});1130$(document).on( 'cycle-initialized', function( e, opts ) {1131 opts.API.getComponent( 'next' ).on( opts.nextEvent, function(e) {1132 e.preventDefault();1133 opts.API.next();1134 });1135 opts.API.getComponent( 'prev' ).on( opts.prevEvent, function(e) {1136 e.preventDefault();1137 opts.API.prev();1138 });1139 if ( opts.swipe ) {1140 var nextEvent = opts.swipeVert ? 'swipeUp.cycle' : 'swipeLeft.cycle swipeleft.cycle';1141 var prevEvent = opts.swipeVert ? 'swipeDown.cycle' : 'swipeRight.cycle swiperight.cycle';1142 opts.container.on( nextEvent, function(e) {1143 opts._tempFx = opts.swipeFx;1144 opts.API.next();1145 });1146 opts.container.on( prevEvent, function() {1147 opts._tempFx = opts.swipeFx;1148 opts.API.prev();1149 });1150 }1151});1152$(document).on( 'cycle-update-view', function( e, opts, slideOpts, currSlide ) {1153 if ( opts.allowWrap )1154 return;1155 var cls = opts.disabledClass;1156 var next = opts.API.getComponent( 'next' );1157 var prev = opts.API.getComponent( 'prev' );1158 var prevBoundry = opts._prevBoundry || 0;1159 var nextBoundry = (opts._nextBoundry !== undefined)?opts._nextBoundry:opts.slideCount - 1;1160 if ( opts.currSlide == nextBoundry )1161 next.addClass( cls ).prop( 'disabled', true );1162 else1163 next.removeClass( cls ).prop( 'disabled', false );1164 if ( opts.currSlide === prevBoundry )1165 prev.addClass( cls ).prop( 'disabled', true );1166 else1167 prev.removeClass( cls ).prop( 'disabled', false );1168});1169$(document).on( 'cycle-destroyed', function( e, opts ) {1170 opts.API.getComponent( 'prev' ).off( opts.nextEvent );1171 opts.API.getComponent( 'next' ).off( opts.prevEvent );1172 opts.container.off( 'swipeleft.cycle swiperight.cycle swipeLeft.cycle swipeRight.cycle swipeUp.cycle swipeDown.cycle' );1173});1174})(jQuery);1175/*! progressive loader plugin for Cycle2; version: 20130315 */1176(function($) {1177"use strict";1178$.extend($.fn.cycle.defaults, {1179 progressive: false1180});1181$(document).on( 'cycle-pre-initialize', function( e, opts ) {1182 if ( !opts.progressive )1183 return;1184 var API = opts.API;1185 var nextFn = API.next;1186 var prevFn = API.prev;1187 var prepareTxFn = API.prepareTx;1188 var type = $.type( opts.progressive );1189 var slides, scriptEl;1190 if ( type == 'array' ) {1191 slides = opts.progressive;1192 }1193 else if ($.isFunction( opts.progressive ) ) {1194 slides = opts.progressive( opts );1195 }1196 else if ( type == 'string' ) {1197 scriptEl = $( opts.progressive );1198 slides = $.trim( scriptEl.html() );1199 if ( !slides )1200 return;1201 // is it json array?1202 if ( /^(\[)/.test( slides ) ) {1203 try {1204 slides = $.parseJSON( slides );1205 }1206 catch(err) {1207 API.log( 'error parsing progressive slides', err );1208 return;1209 }1210 }1211 else {1212 // plain text, split on delimeter1213 slides = slides.split( new RegExp( scriptEl.data('cycle-split') || '\n') );1214 1215 // #95; look for empty slide1216 if ( ! slides[ slides.length - 1 ] )1217 slides.pop();1218 }1219 }1220 if ( prepareTxFn ) {1221 API.prepareTx = function( manual, fwd ) {1222 var index, slide;1223 if ( manual || slides.length === 0 ) {1224 prepareTxFn.apply( opts.API, [ manual, fwd ] );1225 return;1226 }1227 if ( fwd && opts.currSlide == ( opts.slideCount-1) ) {1228 slide = slides[ 0 ];1229 slides = slides.slice( 1 );1230 opts.container.one('cycle-slide-added', function(e, opts ) {1231 setTimeout(function() {1232 opts.API.advanceSlide( 1 );1233 },50);1234 });1235 opts.API.add( slide );1236 }1237 else if ( !fwd && opts.currSlide === 0 ) {1238 index = slides.length-1;1239 slide = slides[ index ];1240 slides = slides.slice( 0, index );1241 opts.container.one('cycle-slide-added', function(e, opts ) {1242 setTimeout(function() {1243 opts.currSlide = 1;1244 opts.API.advanceSlide( -1 );1245 },50);1246 });1247 opts.API.add( slide, true );1248 }1249 else {1250 prepareTxFn.apply( opts.API, [ manual, fwd ] );1251 }1252 };1253 }1254 if ( nextFn ) {1255 API.next = function() {1256 var opts = this.opts();1257 if ( slides.length && opts.currSlide == ( opts.slideCount - 1 ) ) {1258 var slide = slides[ 0 ];1259 slides = slides.slice( 1 );1260 opts.container.one('cycle-slide-added', function(e, opts ) {1261 nextFn.apply( opts.API );1262 opts.container.removeClass('cycle-loading');1263 });1264 opts.container.addClass('cycle-loading');1265 opts.API.add( slide );1266 }1267 else {1268 nextFn.apply( opts.API ); 1269 }1270 };1271 }1272 1273 if ( prevFn ) {1274 API.prev = function() {1275 var opts = this.opts();1276 if ( slides.length && opts.currSlide === 0 ) {1277 var index = slides.length-1;1278 var slide = slides[ index ];1279 slides = slides.slice( 0, index );1280 opts.container.one('cycle-slide-added', function(e, opts ) {1281 opts.currSlide = 1;1282 opts.API.advanceSlide( -1 );1283 opts.container.removeClass('cycle-loading');1284 });1285 opts.container.addClass('cycle-loading');1286 opts.API.add( slide, true );1287 }1288 else {1289 prevFn.apply( opts.API );...
jquery.cycle2.js
Source:jquery.cycle2.js
...65 opts: function() {66 return this._container.data( 'cycle.opts' );67 },68 addInitialSlides: function() {69 var opts = this.opts();70 var slides = opts.slides;71 opts.slideCount = 0;72 opts.slides = $(); // empty set73 74 // add slides that already exist75 slides = slides.jquery ? slides : opts.container.find( slides );76 if ( opts.random ) {77 slides.sort(function() {return Math.random() - 0.5;});78 }79 opts.API.add( slides );80 },81 preInitSlideshow: function() {82 var opts = this.opts();83 opts.API.trigger('cycle-pre-initialize', [ opts ]);84 var tx = $.fn.cycle.transitions[opts.fx];85 if (tx && $.isFunction(tx.preInit))86 tx.preInit( opts );87 opts._preInitialized = true;88 },89 postInitSlideshow: function() {90 var opts = this.opts();91 opts.API.trigger('cycle-post-initialize', [ opts ]);92 var tx = $.fn.cycle.transitions[opts.fx];93 if (tx && $.isFunction(tx.postInit))94 tx.postInit( opts );95 },96 initSlideshow: function() {97 var opts = this.opts();98 var pauseObj = opts.container;99 var slideOpts;100 opts.API.calcFirstSlide();101 if ( opts.container.css('position') == 'static' )102 opts.container.css('position', 'relative');103 $(opts.slides[opts.currSlide]).css('opacity',1).show();104 opts.API.stackSlides( opts.slides[opts.currSlide], opts.slides[opts.nextSlide], !opts.reverse );105 if ( opts.pauseOnHover ) {106 // allow pauseOnHover to specify an element107 if ( opts.pauseOnHover !== true )108 pauseObj = $( opts.pauseOnHover );109 pauseObj.hover(110 function(){ opts.API.pause( true ); }, 111 function(){ opts.API.resume( true ); }112 );113 }114 // stage initial transition115 if ( opts.timeout ) {116 slideOpts = opts.API.getSlideOpts( opts.currSlide );117 opts.API.queueTransition( slideOpts, slideOpts.timeout + opts.delay );118 }119 opts._initialized = true;120 opts.API.updateView( true );121 opts.API.trigger('cycle-initialized', [ opts ]);122 opts.API.postInitSlideshow();123 },124 pause: function( hover ) {125 var opts = this.opts(),126 slideOpts = opts.API.getSlideOpts(),127 alreadyPaused = opts.hoverPaused || opts.paused;128 if ( hover )129 opts.hoverPaused = true; 130 else131 opts.paused = true;132 if ( ! alreadyPaused ) {133 opts.container.addClass('cycle-paused');134 opts.API.trigger('cycle-paused', [ opts ]).log('cycle-paused');135 if ( slideOpts.timeout ) {136 clearTimeout( opts.timeoutId );137 opts.timeoutId = 0;138 139 // determine how much time is left for the current slide140 opts._remainingTimeout -= ( $.now() - opts._lastQueue );141 if ( opts._remainingTimeout < 0 || isNaN(opts._remainingTimeout) )142 opts._remainingTimeout = undefined;143 }144 }145 },146 resume: function( hover ) {147 var opts = this.opts(),148 alreadyResumed = !opts.hoverPaused && !opts.paused,149 remaining;150 if ( hover )151 opts.hoverPaused = false; 152 else153 opts.paused = false;154 155 if ( ! alreadyResumed ) {156 opts.container.removeClass('cycle-paused');157 // #gh-230; if an animation is in progress then don't queue a new transition; it will158 // happen naturally159 if ( opts.slides.filter(':animated').length === 0 )160 opts.API.queueTransition( opts.API.getSlideOpts(), opts._remainingTimeout );161 opts.API.trigger('cycle-resumed', [ opts, opts._remainingTimeout ] ).log('cycle-resumed');162 }163 },164 add: function( slides, prepend ) {165 var opts = this.opts();166 var oldSlideCount = opts.slideCount;167 var startSlideshow = false;168 var len;169 if ( $.type(slides) == 'string')170 slides = $.trim( slides );171 $( slides ).each(function(i) {172 var slideOpts;173 var slide = $(this);174 if ( prepend )175 opts.container.prepend( slide );176 else177 opts.container.append( slide );178 opts.slideCount++;179 slideOpts = opts.API.buildSlideOpts( slide );180 if ( prepend )181 opts.slides = $( slide ).add( opts.slides );182 else183 opts.slides = opts.slides.add( slide );184 opts.API.initSlide( slideOpts, slide, --opts._maxZ );185 slide.data('cycle.opts', slideOpts);186 opts.API.trigger('cycle-slide-added', [ opts, slideOpts, slide ]);187 });188 opts.API.updateView( true );189 startSlideshow = opts._preInitialized && (oldSlideCount < 2 && opts.slideCount >= 1);190 if ( startSlideshow ) {191 if ( !opts._initialized )192 opts.API.initSlideshow();193 else if ( opts.timeout ) {194 len = opts.slides.length;195 opts.nextSlide = opts.reverse ? len - 1 : 1;196 if ( !opts.timeoutId ) {197 opts.API.queueTransition( opts );198 }199 }200 }201 },202 calcFirstSlide: function() {203 var opts = this.opts();204 var firstSlideIndex;205 firstSlideIndex = parseInt( opts.startingSlide || 0, 10 );206 if (firstSlideIndex >= opts.slides.length || firstSlideIndex < 0)207 firstSlideIndex = 0;208 opts.currSlide = firstSlideIndex;209 if ( opts.reverse ) {210 opts.nextSlide = firstSlideIndex - 1;211 if (opts.nextSlide < 0)212 opts.nextSlide = opts.slides.length - 1;213 }214 else {215 opts.nextSlide = firstSlideIndex + 1;216 if (opts.nextSlide == opts.slides.length)217 opts.nextSlide = 0;218 }219 },220 calcNextSlide: function() {221 var opts = this.opts();222 var roll;223 if ( opts.reverse ) {224 roll = (opts.nextSlide - 1) < 0;225 opts.nextSlide = roll ? opts.slideCount - 1 : opts.nextSlide-1;226 opts.currSlide = roll ? 0 : opts.nextSlide+1;227 }228 else {229 roll = (opts.nextSlide + 1) == opts.slides.length;230 opts.nextSlide = roll ? 0 : opts.nextSlide+1;231 opts.currSlide = roll ? opts.slides.length-1 : opts.nextSlide-1;232 }233 },234 calcTx: function( slideOpts, manual ) {235 var opts = slideOpts;236 var tx;237 if ( manual && opts.manualFx )238 tx = $.fn.cycle.transitions[opts.manualFx];239 if ( !tx )240 tx = $.fn.cycle.transitions[opts.fx];241 if (!tx) {242 tx = $.fn.cycle.transitions.fade;243 opts.API.log('Transition "' + opts.fx + '" not found. Using fade.');244 }245 return tx;246 },247 prepareTx: function( manual, fwd ) {248 var opts = this.opts();249 var after, curr, next, slideOpts, tx;250 if ( opts.slideCount < 2 ) {251 opts.timeoutId = 0;252 return;253 }254 if ( manual && ( !opts.busy || opts.manualTrump ) ) {255 opts.API.stopTransition();256 opts.busy = false;257 clearTimeout(opts.timeoutId);258 opts.timeoutId = 0;259 }260 if ( opts.busy )261 return;262 if ( opts.timeoutId === 0 && !manual )263 return;264 curr = opts.slides[opts.currSlide];265 next = opts.slides[opts.nextSlide];266 slideOpts = opts.API.getSlideOpts( opts.nextSlide );267 tx = opts.API.calcTx( slideOpts, manual );268 opts._tx = tx;269 if ( manual && slideOpts.manualSpeed !== undefined )270 slideOpts.speed = slideOpts.manualSpeed;271 // if ( opts.nextSlide === opts.currSlide )272 // opts.API.calcNextSlide();273 // ensure that:274 // 1. advancing to a different slide275 // 2. this is either a manual event (prev/next, pager, cmd) or 276 // a timer event and slideshow is not paused277 if ( opts.nextSlide != opts.currSlide && 278 (manual || (!opts.paused && !opts.hoverPaused && opts.timeout) )) { // #62279 opts.API.trigger('cycle-before', [ slideOpts, curr, next, fwd ]);280 if ( tx.before )281 tx.before( slideOpts, curr, next, fwd );282 after = function() {283 opts.busy = false;284 // #76; bail if slideshow has been destroyed285 if (! opts.container.data( 'cycle.opts' ) )286 return;287 if (tx.after)288 tx.after( slideOpts, curr, next, fwd );289 opts.API.trigger('cycle-after', [ slideOpts, curr, next, fwd ]);290 opts.API.queueTransition( slideOpts);291 opts.API.updateView( true );292 };293 opts.busy = true;294 if (tx.transition)295 tx.transition(slideOpts, curr, next, fwd, after);296 else297 opts.API.doTransition( slideOpts, curr, next, fwd, after);298 opts.API.calcNextSlide();299 opts.API.updateView();300 } else {301 opts.API.queueTransition( slideOpts );302 }303 },304 // perform the actual animation305 doTransition: function( slideOpts, currEl, nextEl, fwd, callback) {306 var opts = slideOpts;307 var curr = $(currEl), next = $(nextEl);308 var fn = function() {309 // make sure animIn has something so that callback doesn't trigger immediately310 next.animate(opts.animIn || { opacity: 1}, opts.speed, opts.easeIn || opts.easing, callback);311 };312 next.css(opts.cssBefore || {});313 curr.animate(opts.animOut || {}, opts.speed, opts.easeOut || opts.easing, function() {314 curr.css(opts.cssAfter || {});315 if (!opts.sync) {316 fn();317 }318 });319 if (opts.sync) {320 fn();321 }322 },323 queueTransition: function( slideOpts, specificTimeout ) {324 var opts = this.opts();325 var timeout = specificTimeout !== undefined ? specificTimeout : slideOpts.timeout;326 if (opts.nextSlide === 0 && --opts.loop === 0) {327 opts.API.log('terminating; loop=0');328 opts.timeout = 0;329 if ( timeout ) {330 setTimeout(function() {331 opts.API.trigger('cycle-finished', [ opts ]);332 }, timeout);333 }334 else {335 opts.API.trigger('cycle-finished', [ opts ]);336 }337 // reset nextSlide338 opts.nextSlide = opts.currSlide;339 return;340 }341 if ( timeout ) {342 opts._lastQueue = $.now();343 if ( specificTimeout === undefined )344 opts._remainingTimeout = slideOpts.timeout;345 if ( !opts.paused && ! opts.hoverPaused ) {346 opts.timeoutId = setTimeout(function() { 347 opts.API.prepareTx( false, !opts.reverse ); 348 }, timeout );349 }350 }351 },352 stopTransition: function() {353 var opts = this.opts();354 if ( opts.slides.filter(':animated').length ) {355 opts.slides.stop(false, true);356 opts.API.trigger('cycle-transition-stopped', [ opts ]);357 }358 if ( opts._tx && opts._tx.stopTransition )359 opts._tx.stopTransition( opts );360 },361 // advance slide forward or back362 advanceSlide: function( val ) {363 var opts = this.opts();364 clearTimeout(opts.timeoutId);365 opts.timeoutId = 0;366 opts.nextSlide = opts.currSlide + val;367 368 if (opts.nextSlide < 0)369 opts.nextSlide = opts.slides.length - 1;370 else if (opts.nextSlide >= opts.slides.length)371 opts.nextSlide = 0;372 opts.API.prepareTx( true, val >= 0 );373 return false;374 },375 buildSlideOpts: function( slide ) {376 var opts = this.opts();377 var val, shortName;378 var slideOpts = slide.data() || {};379 for (var p in slideOpts) {380 // allow props to be accessed sans 'cycle' prefix and log the overrides381 if (slideOpts.hasOwnProperty(p) && /^cycle[A-Z]+/.test(p) ) {382 val = slideOpts[p];383 shortName = p.match(/^cycle(.*)/)[1].replace(/^[A-Z]/, lowerCase);384 opts.API.log('['+(opts.slideCount-1)+']', shortName+':', val, '('+typeof val +')');385 slideOpts[shortName] = val;386 }387 }388 slideOpts = $.extend( {}, $.fn.cycle.defaults, opts, slideOpts );389 slideOpts.slideNum = opts.slideCount;390 try {391 // these props should always be read from the master state object392 delete slideOpts.API;393 delete slideOpts.slideCount;394 delete slideOpts.currSlide;395 delete slideOpts.nextSlide;396 delete slideOpts.slides;397 } catch(e) {398 // no op399 }400 return slideOpts;401 },402 getSlideOpts: function( index ) {403 var opts = this.opts();404 if ( index === undefined )405 index = opts.currSlide;406 var slide = opts.slides[index];407 var slideOpts = $(slide).data('cycle.opts');408 return $.extend( {}, opts, slideOpts );409 },410 411 initSlide: function( slideOpts, slide, suggestedZindex ) {412 var opts = this.opts();413 slide.css( slideOpts.slideCss || {} );414 if ( suggestedZindex > 0 )415 slide.css( 'zIndex', suggestedZindex );416 // ensure that speed settings are sane417 if ( isNaN( slideOpts.speed ) )418 slideOpts.speed = $.fx.speeds[slideOpts.speed] || $.fx.speeds._default;419 if ( !slideOpts.sync )420 slideOpts.speed = slideOpts.speed / 2;421 slide.addClass( opts.slideClass );422 },423 updateView: function( isAfter, isDuring ) {424 var opts = this.opts();425 if ( !opts._initialized )426 return;427 var slideOpts = opts.API.getSlideOpts();428 var currSlide = opts.slides[ opts.currSlide ];429 if ( ! isAfter && isDuring !== true ) {430 opts.API.trigger('cycle-update-view-before', [ opts, slideOpts, currSlide ]);431 if ( opts.updateView < 0 )432 return;433 }434 if ( opts.slideActiveClass ) {435 opts.slides.removeClass( opts.slideActiveClass )436 .eq( opts.currSlide ).addClass( opts.slideActiveClass );437 }438 if ( isAfter && opts.hideNonActive )439 opts.slides.filter( ':not(.' + opts.slideActiveClass + ')' ).hide();440 if ( opts.updateView === 0 ) {441 setTimeout(function() {442 opts.API.trigger('cycle-update-view', [ opts, slideOpts, currSlide, isAfter ]);443 }, slideOpts.speed / (opts.sync ? 2 : 1) );444 }445 if ( opts.updateView !== 0 )446 opts.API.trigger('cycle-update-view', [ opts, slideOpts, currSlide, isAfter ]);447 448 if ( isAfter )449 opts.API.trigger('cycle-update-view-after', [ opts, slideOpts, currSlide ]);450 },451 getComponent: function( name ) {452 var opts = this.opts();453 var selector = opts[name];454 if (typeof selector === 'string') {455 // if selector is a child, sibling combinator, adjancent selector then use find, otherwise query full dom456 return (/^\s*[\>|\+|~]/).test( selector ) ? opts.container.find( selector ) : $( selector );457 }458 if (selector.jquery)459 return selector;460 461 return $(selector);462 },463 stackSlides: function( curr, next, fwd ) {464 var opts = this.opts();465 if ( !curr ) {466 curr = opts.slides[opts.currSlide];467 next = opts.slides[opts.nextSlide];468 fwd = !opts.reverse;469 }470 // reset the zIndex for the common case:471 // curr slide on top, next slide beneath, and the rest in order to be shown472 $(curr).css('zIndex', opts.maxZ);473 var i;474 var z = opts.maxZ - 2;475 var len = opts.slideCount;476 if (fwd) {477 for ( i = opts.currSlide + 1; i < len; i++ )478 $( opts.slides[i] ).css( 'zIndex', z-- );479 for ( i = 0; i < opts.currSlide; i++ )480 $( opts.slides[i] ).css( 'zIndex', z-- );481 }482 else {483 for ( i = opts.currSlide - 1; i >= 0; i-- )484 $( opts.slides[i] ).css( 'zIndex', z-- );485 for ( i = len - 1; i > opts.currSlide; i-- )486 $( opts.slides[i] ).css( 'zIndex', z-- );487 }488 $(next).css('zIndex', opts.maxZ - 1);489 },490 getSlideIndex: function( el ) {491 return this.opts().slides.index( el );492 }493}; // API494// default logger495$.fn.cycle.log = function log() {496 /*global console:true */497 if (window.console && console.log)498 console.log('[cycle2] ' + Array.prototype.join.call(arguments, ' ') );499};500$.fn.cycle.version = function() { return 'Cycle2: ' + version; };501// helper functions502function lowerCase(s) {503 return (s || '').toLowerCase();504}505// expose transition object506$.fn.cycle.transitions = {507 custom: {508 },509 none: {510 before: function( opts, curr, next, fwd ) {511 opts.API.stackSlides( next, curr, fwd );512 opts.cssBefore = { opacity: 1, display: 'block' };513 }514 },515 fade: {516 before: function( opts, curr, next, fwd ) {517 var css = opts.API.getSlideOpts( opts.nextSlide ).slideCss || {};518 opts.API.stackSlides( curr, next, fwd );519 opts.cssBefore = $.extend(css, { opacity: 0, display: 'block' });520 opts.animIn = { opacity: 1 };521 opts.animOut = { opacity: 0 };522 }523 },524 fadeout: {525 before: function( opts , curr, next, fwd ) {526 var css = opts.API.getSlideOpts( opts.nextSlide ).slideCss || {};527 opts.API.stackSlides( curr, next, fwd );528 opts.cssBefore = $.extend(css, { opacity: 1, display: 'block' });529 opts.animOut = { opacity: 0 };530 }531 },532 scrollHorz: {533 before: function( opts, curr, next, fwd ) {534 opts.API.stackSlides( curr, next, fwd );535 var w = opts.container.css('overflow','hidden').width();536 opts.cssBefore = { left: fwd ? w : - w, top: 0, opacity: 1, display: 'block' };537 opts.cssAfter = { zIndex: opts._maxZ - 2, left: 0 };538 opts.animIn = { left: 0 };539 opts.animOut = { left: fwd ? -w : w };540 }541 }542};543// @see: http://jquery.malsup.com/cycle2/api544$.fn.cycle.defaults = {545 allowWrap: true,546 autoSelector: '.cycle-slideshow[data-cycle-auto-init!=false]',547 delay: 0,548 easing: null,549 fx: 'fade',550 hideNonActive: true,551 loop: 0,552 manualFx: undefined,553 manualSpeed: undefined,554 manualTrump: true,555 maxZ: 100,556 pauseOnHover: false,557 reverse: false,558 slideActiveClass: 'cycle-slide-active',559 slideClass: 'cycle-slide',560 slideCss: { position: 'absolute', top: 0, left: 0 },561 slides: '> img',562 speed: 500,563 startingSlide: 0,564 sync: true,565 timeout: 4000,566 updateView: 0567};568// automatically find and run slideshows569$(document).ready(function() {570 $( $.fn.cycle.defaults.autoSelector ).cycle();571});572})(jQuery);573/*! Cycle2 autoheight plugin; Copyright (c) M.Alsup, 2012; version: 20130304 */574(function($) {575"use strict";576$.extend($.fn.cycle.defaults, {577 autoHeight: 0 // setting this option to false disables autoHeight logic578}); 579$(document).on( 'cycle-initialized', function( e, opts ) {580 var autoHeight = opts.autoHeight;581 var t = $.type( autoHeight );582 var resizeThrottle = null;583 var ratio;584 if ( t !== 'string' && t !== 'number' )585 return;586 // bind events587 opts.container.on( 'cycle-slide-added cycle-slide-removed', initAutoHeight );588 opts.container.on( 'cycle-destroyed', onDestroy );589 if ( autoHeight == 'container' ) {590 opts.container.on( 'cycle-before', onBefore );591 }592 else if ( t === 'string' && /\d+\:\d+/.test( autoHeight ) ) { 593 // use ratio594 ratio = autoHeight.match(/(\d+)\:(\d+)/);595 ratio = ratio[1] / ratio[2];596 opts._autoHeightRatio = ratio;597 }598 // if autoHeight is a number then we don't need to recalculate the sentinel599 // index on resize600 if ( t !== 'number' ) {601 // bind unique resize handler per slideshow (so it can be 'off-ed' in onDestroy)602 opts._autoHeightOnResize = function () {603 clearTimeout( resizeThrottle );604 resizeThrottle = setTimeout( onResize, 50 );605 };606 $(window).on( 'resize orientationchange', opts._autoHeightOnResize );607 }608 setTimeout( onResize, 30 );609 function onResize() {610 initAutoHeight( e, opts );611 }612});613function initAutoHeight( e, opts ) {614 var clone, height, sentinelIndex;615 var autoHeight = opts.autoHeight;616 if ( autoHeight == 'container' ) {617 height = $( opts.slides[ opts.currSlide ] ).outerHeight();618 opts.container.height( height );619 }620 else if ( opts._autoHeightRatio ) { 621 opts.container.height( opts.container.width() / opts._autoHeightRatio );622 }623 else if ( autoHeight === 'calc' || ( $.type( autoHeight ) == 'number' && autoHeight >= 0 ) ) {624 if ( autoHeight === 'calc' )625 sentinelIndex = calcSentinelIndex( e, opts );626 else if ( autoHeight >= opts.slides.length )627 sentinelIndex = 0;628 else 629 sentinelIndex = autoHeight;630 // only recreate sentinel if index is different631 if ( sentinelIndex == opts._sentinelIndex )632 return;633 opts._sentinelIndex = sentinelIndex;634 if ( opts._sentinel )635 opts._sentinel.remove();636 // clone existing slide as sentinel637 clone = $( opts.slides[ sentinelIndex ].cloneNode(true) );638 639 // #50; remove special attributes from cloned content640 clone.removeAttr( 'id name rel' ).find( '[id],[name],[rel]' ).removeAttr( 'id name rel' );641 clone.css({642 position: 'static',643 visibility: 'hidden',644 display: 'block'645 }).prependTo( opts.container ).addClass('cycle-sentinel cycle-slide').removeClass('cycle-slide-active');646 clone.find( '*' ).css( 'visibility', 'hidden' );647 opts._sentinel = clone;648 }649} 650function calcSentinelIndex( e, opts ) {651 var index = 0, max = -1;652 // calculate tallest slide index653 opts.slides.each(function(i) {654 var h = $(this).height();655 if ( h > max ) {656 max = h;657 index = i;658 }659 });660 return index;661}662function onBefore( e, opts, outgoing, incoming, forward ) {663 var h = $(incoming).outerHeight();664 var duration = opts.sync ? opts.speed / 2 : opts.speed;665 opts.container.animate( { height: h }, duration );666}667function onDestroy( e, opts ) {668 if ( opts._autoHeightOnResize ) {669 $(window).off( 'resize orientationchange', opts._autoHeightOnResize );670 opts._autoHeightOnResize = null;671 }672 opts.container.off( 'cycle-slide-added cycle-slide-removed', initAutoHeight );673 opts.container.off( 'cycle-destroyed', onDestroy );674 opts.container.off( 'cycle-before', onBefore );675 if ( opts._sentinel ) {676 opts._sentinel.remove();677 opts._sentinel = null;678 }679}680})(jQuery);681/*! caption plugin for Cycle2; version: 20130306 */682(function($) {683"use strict";684$.extend($.fn.cycle.defaults, {685 caption: '> .cycle-caption',686 captionTemplate: '{{slideNum}} / {{slideCount}}',687 overlay: '> .cycle-overlay',688 overlayTemplate: '<div>{{title}}</div><div>{{desc}}</div>',689 captionModule: 'caption'690}); 691$(document).on( 'cycle-update-view', function( e, opts, slideOpts, currSlide ) {692 if ( opts.captionModule !== 'caption' )693 return;694 var el;695 $.each(['caption','overlay'], function() {696 var name = this; 697 var template = slideOpts[name+'Template'];698 var el = opts.API.getComponent( name );699 if( el.length && template ) {700 el.html( opts.API.tmpl( template, slideOpts, opts, currSlide ) );701 el.show();702 }703 else {704 el.hide();705 }706 });707});708$(document).on( 'cycle-destroyed', function( e, opts ) {709 var el;710 $.each(['caption','overlay'], function() {711 var name = this, template = opts[name+'Template'];712 if ( opts[name] && template ) {713 el = opts.API.getComponent( 'caption' );714 el.empty();715 }716 });717});718})(jQuery);719/*! command plugin for Cycle2; version: 20130707 */720(function($) {721"use strict";722var c2 = $.fn.cycle;723$.fn.cycle = function( options ) {724 var cmd, cmdFn, opts;725 var args = $.makeArray( arguments );726 if ( $.type( options ) == 'number' ) {727 return this.cycle( 'goto', options );728 }729 if ( $.type( options ) == 'string' ) {730 return this.each(function() {731 var cmdArgs;732 cmd = options;733 opts = $(this).data('cycle.opts');734 if ( opts === undefined ) {735 c2.log('slideshow must be initialized before sending commands; "' + cmd + '" ignored');736 return;737 }738 else {739 cmd = cmd == 'goto' ? 'jump' : cmd; // issue #3; change 'goto' to 'jump' internally740 cmdFn = opts.API[ cmd ];741 if ( $.isFunction( cmdFn )) {742 cmdArgs = $.makeArray( args );743 cmdArgs.shift();744 return cmdFn.apply( opts.API, cmdArgs );745 }746 else {747 c2.log( 'unknown command: ', cmd );748 }749 }750 });751 }752 else {753 return c2.apply( this, arguments );754 }755};756// copy props757$.extend( $.fn.cycle, c2 );758$.extend( c2.API, {759 next: function() {760 var opts = this.opts();761 if ( opts.busy && ! opts.manualTrump )762 return;763 764 var count = opts.reverse ? -1 : 1;765 if ( opts.allowWrap === false && ( opts.currSlide + count ) >= opts.slideCount )766 return;767 opts.API.advanceSlide( count );768 opts.API.trigger('cycle-next', [ opts ]).log('cycle-next');769 },770 prev: function() {771 var opts = this.opts();772 if ( opts.busy && ! opts.manualTrump )773 return;774 var count = opts.reverse ? 1 : -1;775 if ( opts.allowWrap === false && ( opts.currSlide + count ) < 0 )776 return;777 opts.API.advanceSlide( count );778 opts.API.trigger('cycle-prev', [ opts ]).log('cycle-prev');779 },780 destroy: function() {781 this.stop(); //#204782 var opts = this.opts();783 var clean = $.isFunction( $._data ) ? $._data : $.noop; // hack for #184 and #201784 clearTimeout(opts.timeoutId);785 opts.timeoutId = 0;786 opts.API.stop();787 opts.API.trigger( 'cycle-destroyed', [ opts ] ).log('cycle-destroyed');788 opts.container.removeData();789 clean( opts.container[0], 'parsedAttrs', false );790 // #75; remove inline styles791 if ( ! opts.retainStylesOnDestroy ) {792 opts.container.removeAttr( 'style' );793 opts.slides.removeAttr( 'style' );794 opts.slides.removeClass( opts.slideActiveClass );795 }796 opts.slides.each(function() {797 $(this).removeData();798 clean( this, 'parsedAttrs', false );799 });800 },801 jump: function( index ) {802 // go to the requested slide803 var fwd;804 var opts = this.opts();805 if ( opts.busy && ! opts.manualTrump )806 return;807 var num = parseInt( index, 10 );808 if (isNaN(num) || num < 0 || num >= opts.slides.length) {809 opts.API.log('goto: invalid slide index: ' + num);810 return;811 }812 if (num == opts.currSlide) {813 opts.API.log('goto: skipping, already on slide', num);814 return;815 }816 opts.nextSlide = num;817 clearTimeout(opts.timeoutId);818 opts.timeoutId = 0;819 opts.API.log('goto: ', num, ' (zero-index)');820 fwd = opts.currSlide < opts.nextSlide;821 opts.API.prepareTx( true, fwd );822 },823 stop: function() {824 var opts = this.opts();825 var pauseObj = opts.container;826 clearTimeout(opts.timeoutId);827 opts.timeoutId = 0;828 opts.API.stopTransition();829 if ( opts.pauseOnHover ) {830 if ( opts.pauseOnHover !== true )831 pauseObj = $( opts.pauseOnHover );832 pauseObj.off('mouseenter mouseleave');833 }834 opts.API.trigger('cycle-stopped', [ opts ]).log('cycle-stopped');835 },836 reinit: function() {837 var opts = this.opts();838 opts.API.destroy();839 opts.container.cycle();840 },841 remove: function( index ) {842 var opts = this.opts();843 var slide, slideToRemove, slides = [], slideNum = 1;844 for ( var i=0; i < opts.slides.length; i++ ) {845 slide = opts.slides[i];846 if ( i == index ) {847 slideToRemove = slide;848 }849 else {850 slides.push( slide );851 $( slide ).data('cycle.opts').slideNum = slideNum;852 slideNum++;853 }854 }855 if ( slideToRemove ) {856 opts.slides = $( slides );857 opts.slideCount--;858 $( slideToRemove ).remove();859 if (index == opts.currSlide)860 opts.API.advanceSlide( 1 );861 else if ( index < opts.currSlide )862 opts.currSlide--;863 else864 opts.currSlide++;865 opts.API.trigger('cycle-slide-removed', [ opts, index, slideToRemove ]).log('cycle-slide-removed');866 opts.API.updateView();867 }868 }869});870// listen for clicks on elements with data-cycle-cmd attribute871$(document).on('click.cycle', '[data-cycle-cmd]', function(e) {872 // issue cycle command873 e.preventDefault();874 var el = $(this);875 var command = el.data('cycle-cmd');876 var context = el.data('cycle-context') || '.cycle-slideshow';877 $(context).cycle(command, el.data('cycle-arg'));878});879})(jQuery);880/*! hash plugin for Cycle2; version: 20130905 */881(function($) {882"use strict";883$(document).on( 'cycle-pre-initialize', function( e, opts ) {884 onHashChange( opts, true );885 opts._onHashChange = function() {886 onHashChange( opts, false );887 };888 $( window ).on( 'hashchange', opts._onHashChange);889});890$(document).on( 'cycle-update-view', function( e, opts, slideOpts ) {891 if ( slideOpts.hash && ( '#' + slideOpts.hash ) != window.location.hash ) {892 opts._hashFence = true;893 window.location.hash = slideOpts.hash;894 }895});896$(document).on( 'cycle-destroyed', function( e, opts) {897 if ( opts._onHashChange ) {898 $( window ).off( 'hashchange', opts._onHashChange );899 }900});901function onHashChange( opts, setStartingSlide ) {902 var hash;903 if ( opts._hashFence ) {904 opts._hashFence = false;905 return;906 }907 908 hash = window.location.hash.substring(1);909 opts.slides.each(function(i) {910 if ( $(this).data( 'cycle-hash' ) == hash ) {911 if ( setStartingSlide === true ) {912 opts.startingSlide = i;913 }914 else {915 var fwd = opts.currSlide < i;916 opts.nextSlide = i;917 opts.API.prepareTx( true, fwd );918 }919 return false;920 }921 });922}923})(jQuery);924/*! loader plugin for Cycle2; version: 20131020 */925(function($) {926"use strict";927$.extend($.fn.cycle.defaults, {928 loader: false929});930$(document).on( 'cycle-bootstrap', function( e, opts ) {931 var addFn;932 if ( !opts.loader )933 return;934 // override API.add for this slideshow935 addFn = opts.API.add;936 opts.API.add = add;937 function add( slides, prepend ) {938 var slideArr = [];939 if ( $.type( slides ) == 'string' )940 slides = $.trim( slides );941 else if ( $.type( slides) === 'array' ) {942 for (var i=0; i < slides.length; i++ )943 slides[i] = $(slides[i])[0];944 }945 slides = $( slides );946 var slideCount = slides.length;947 if ( ! slideCount )948 return;949 opts.eventualSlideCount = opts.slideCount + slideCount;950 slides.hide().appendTo('body').each(function(i) { // appendTo fixes #56951 var count = 0;952 var slide = $(this);953 var images = slide.is('img') ? slide : slide.find('img');954 slide.data('index', i);955 // allow some images to be marked as unimportant (and filter out images w/o src value)956 images = images.filter(':not(.cycle-loader-ignore)').filter(':not([src=""])');957 if ( ! images.length ) {958 --slideCount;959 slideArr.push( slide );960 return;961 }962 count = images.length;963 images.each(function() {964 // add images that are already loaded965 if ( this.complete ) {966 imageLoaded();967 }968 else {969 $(this).load(function() {970 imageLoaded();971 }).error(function() {972 if ( --count === 0 ) {973 // ignore this slide974 opts.API.log('slide skipped; img not loaded:', this.src);975 if ( --slideCount === 0 && opts.loader == 'wait') {976 addFn.apply( opts.API, [ slideArr, prepend ] );977 }978 }979 });980 }981 });982 function imageLoaded() {983 if ( --count === 0 ) {984 --slideCount;985 addSlide( slide );986 }987 }988 });989 if ( slideCount )990 opts.container.addClass('cycle-loading');991 992 function addSlide( slide ) {993 var curr;994 if ( opts.loader == 'wait' ) {995 slideArr.push( slide );996 if ( slideCount === 0 ) {997 // #59; sort slides into original markup order998 slideArr.sort( sorter );999 addFn.apply( opts.API, [ slideArr, prepend ] );1000 opts.container.removeClass('cycle-loading');1001 }1002 }1003 else {1004 curr = $(opts.slides[opts.currSlide]);1005 addFn.apply( opts.API, [ slide, prepend ] );1006 curr.show();1007 opts.container.removeClass('cycle-loading');1008 }1009 }1010 function sorter(a, b) {1011 return a.data('index') - b.data('index');1012 }1013 }1014});1015})(jQuery);1016/*! pager plugin for Cycle2; version: 20130525 */1017(function($) {1018"use strict";1019$.extend($.fn.cycle.defaults, {1020 pager: '> .cycle-pager',1021 pagerActiveClass: 'cycle-pager-active',1022 pagerEvent: 'click.cycle',1023 pagerTemplate: '<span>•</span>'1024}); 1025$(document).on( 'cycle-bootstrap', function( e, opts, API ) {1026 // add method to API1027 API.buildPagerLink = buildPagerLink;1028});1029$(document).on( 'cycle-slide-added', function( e, opts, slideOpts, slideAdded ) {1030 if ( opts.pager ) {1031 opts.API.buildPagerLink ( opts, slideOpts, slideAdded );1032 opts.API.page = page;1033 }1034});1035$(document).on( 'cycle-slide-removed', function( e, opts, index, slideRemoved ) {1036 if ( opts.pager ) {1037 var pagers = opts.API.getComponent( 'pager' );1038 pagers.each(function() {1039 var pager = $(this);1040 $( pager.children()[index] ).remove();1041 });1042 }1043});1044$(document).on( 'cycle-update-view', function( e, opts, slideOpts ) {1045 var pagers;1046 if ( opts.pager ) {1047 pagers = opts.API.getComponent( 'pager' );1048 pagers.each(function() {1049 $(this).children().removeClass( opts.pagerActiveClass )1050 .eq( opts.currSlide ).addClass( opts.pagerActiveClass );1051 });1052 }1053});1054$(document).on( 'cycle-destroyed', function( e, opts ) {1055 var pager = opts.API.getComponent( 'pager' );1056 if ( pager ) {1057 pager.children().off( opts.pagerEvent ); // #2021058 if ( opts.pagerTemplate )1059 pager.empty();1060 }1061});1062function buildPagerLink( opts, slideOpts, slide ) {1063 var pagerLink;1064 var pagers = opts.API.getComponent( 'pager' );1065 pagers.each(function() {1066 var pager = $(this);1067 if ( slideOpts.pagerTemplate ) {1068 var markup = opts.API.tmpl( slideOpts.pagerTemplate, slideOpts, opts, slide[0] );1069 pagerLink = $( markup ).appendTo( pager );1070 }1071 else {1072 pagerLink = pager.children().eq( opts.slideCount - 1 );1073 }1074 pagerLink.on( opts.pagerEvent, function(e) {1075 e.preventDefault();1076 opts.API.page( pager, e.currentTarget);1077 });1078 });1079}1080function page( pager, target ) {1081 /*jshint validthis:true */1082 var opts = this.opts();1083 if ( opts.busy && ! opts.manualTrump )1084 return;1085 var index = pager.children().index( target );1086 var nextSlide = index;1087 var fwd = opts.currSlide < nextSlide;1088 if (opts.currSlide == nextSlide) {1089 return; // no op, clicked pager for the currently displayed slide1090 }1091 opts.nextSlide = nextSlide;1092 opts.API.prepareTx( true, fwd );1093 opts.API.trigger('cycle-pager-activated', [opts, pager, target ]);1094}1095})(jQuery);1096/*! prevnext plugin for Cycle2; version: 20130709 */1097(function($) {1098"use strict";1099$.extend($.fn.cycle.defaults, {1100 next: '> .cycle-next',1101 nextEvent: 'click.cycle',1102 disabledClass: 'disabled',1103 prev: '> .cycle-prev',1104 prevEvent: 'click.cycle',1105 swipe: false1106});1107$(document).on( 'cycle-initialized', function( e, opts ) {1108 opts.API.getComponent( 'next' ).on( opts.nextEvent, function(e) {1109 e.preventDefault();1110 opts.API.next();1111 });1112 opts.API.getComponent( 'prev' ).on( opts.prevEvent, function(e) {1113 e.preventDefault();1114 opts.API.prev();1115 });1116 if ( opts.swipe ) {1117 var nextEvent = opts.swipeVert ? 'swipeUp.cycle' : 'swipeLeft.cycle swipeleft.cycle';1118 var prevEvent = opts.swipeVert ? 'swipeDown.cycle' : 'swipeRight.cycle swiperight.cycle';1119 opts.container.on( nextEvent, function(e) {1120 opts.API.next();1121 });1122 opts.container.on( prevEvent, function() {1123 opts.API.prev();1124 });1125 }1126});1127$(document).on( 'cycle-update-view', function( e, opts, slideOpts, currSlide ) {1128 if ( opts.allowWrap )1129 return;1130 var cls = opts.disabledClass;1131 var next = opts.API.getComponent( 'next' );1132 var prev = opts.API.getComponent( 'prev' );1133 var prevBoundry = opts._prevBoundry || 0;1134 var nextBoundry = (opts._nextBoundry !== undefined)?opts._nextBoundry:opts.slideCount - 1;1135 if ( opts.currSlide == nextBoundry )1136 next.addClass( cls ).prop( 'disabled', true );1137 else1138 next.removeClass( cls ).prop( 'disabled', false );1139 if ( opts.currSlide === prevBoundry )1140 prev.addClass( cls ).prop( 'disabled', true );1141 else1142 prev.removeClass( cls ).prop( 'disabled', false );1143});1144$(document).on( 'cycle-destroyed', function( e, opts ) {1145 opts.API.getComponent( 'prev' ).off( opts.nextEvent );1146 opts.API.getComponent( 'next' ).off( opts.prevEvent );1147 opts.container.off( 'swipeleft.cycle swiperight.cycle swipeLeft.cycle swipeRight.cycle swipeUp.cycle swipeDown.cycle' );1148});1149})(jQuery);1150/*! progressive loader plugin for Cycle2; version: 20130315 */1151(function($) {1152"use strict";1153$.extend($.fn.cycle.defaults, {1154 progressive: false1155});1156$(document).on( 'cycle-pre-initialize', function( e, opts ) {1157 if ( !opts.progressive )1158 return;1159 var API = opts.API;1160 var nextFn = API.next;1161 var prevFn = API.prev;1162 var prepareTxFn = API.prepareTx;1163 var type = $.type( opts.progressive );1164 var slides, scriptEl;1165 if ( type == 'array' ) {1166 slides = opts.progressive;1167 }1168 else if ($.isFunction( opts.progressive ) ) {1169 slides = opts.progressive( opts );1170 }1171 else if ( type == 'string' ) {1172 scriptEl = $( opts.progressive );1173 slides = $.trim( scriptEl.html() );1174 if ( !slides )1175 return;1176 // is it json array?1177 if ( /^(\[)/.test( slides ) ) {1178 try {1179 slides = $.parseJSON( slides );1180 }1181 catch(err) {1182 API.log( 'error parsing progressive slides', err );1183 return;1184 }1185 }1186 else {1187 // plain text, split on delimeter1188 slides = slides.split( new RegExp( scriptEl.data('cycle-split') || '\n') );1189 1190 // #95; look for empty slide1191 if ( ! slides[ slides.length - 1 ] )1192 slides.pop();1193 }1194 }1195 if ( prepareTxFn ) {1196 API.prepareTx = function( manual, fwd ) {1197 var index, slide;1198 if ( manual || slides.length === 0 ) {1199 prepareTxFn.apply( opts.API, [ manual, fwd ] );1200 return;1201 }1202 if ( fwd && opts.currSlide == ( opts.slideCount-1) ) {1203 slide = slides[ 0 ];1204 slides = slides.slice( 1 );1205 opts.container.one('cycle-slide-added', function(e, opts ) {1206 setTimeout(function() {1207 opts.API.advanceSlide( 1 );1208 },50);1209 });1210 opts.API.add( slide );1211 }1212 else if ( !fwd && opts.currSlide === 0 ) {1213 index = slides.length-1;1214 slide = slides[ index ];1215 slides = slides.slice( 0, index );1216 opts.container.one('cycle-slide-added', function(e, opts ) {1217 setTimeout(function() {1218 opts.currSlide = 1;1219 opts.API.advanceSlide( -1 );1220 },50);1221 });1222 opts.API.add( slide, true );1223 }1224 else {1225 prepareTxFn.apply( opts.API, [ manual, fwd ] );1226 }1227 };1228 }1229 if ( nextFn ) {1230 API.next = function() {1231 var opts = this.opts();1232 if ( slides.length && opts.currSlide == ( opts.slideCount - 1 ) ) {1233 var slide = slides[ 0 ];1234 slides = slides.slice( 1 );1235 opts.container.one('cycle-slide-added', function(e, opts ) {1236 nextFn.apply( opts.API );1237 opts.container.removeClass('cycle-loading');1238 });1239 opts.container.addClass('cycle-loading');1240 opts.API.add( slide );1241 }1242 else {1243 nextFn.apply( opts.API ); 1244 }1245 };1246 }1247 1248 if ( prevFn ) {1249 API.prev = function() {1250 var opts = this.opts();1251 if ( slides.length && opts.currSlide === 0 ) {1252 var index = slides.length-1;1253 var slide = slides[ index ];1254 slides = slides.slice( 0, index );1255 opts.container.one('cycle-slide-added', function(e, opts ) {1256 opts.currSlide = 1;1257 opts.API.advanceSlide( -1 );1258 opts.container.removeClass('cycle-loading');1259 });1260 opts.container.addClass('cycle-loading');1261 opts.API.add( slide, true );1262 }1263 else {1264 prevFn.apply( opts.API );...
Using AI Code Generation
1const path = require('path');2const { opts } = require('storybook-test-runner');3module.exports = opts({4 storybookConfigDir: path.resolve(__dirname, '../.storybook'),5 testFiles: path.resolve(__dirname, '../src/**/*.story.js'),6 storybookBaseDir: path.resolve(__dirname, '../'),7 storybookStaticDir: path.resolve(__dirname, '../storybook-static'),8});9const { jest } = require('storybook-test-runner');10module.exports = jest();
Using AI Code Generation
1const { opts } = require('storybook-test-runner')2const { stories, addons } = opts()3const storybookTestRunner = require('storybook-test-runner').storybookTestRunner4const { stories, addons } = storybookTestRunner()5const storybookTestRunner = require('storybook-test-runner').storybookTestRunner6const { stories, addons } = storybookTestRunner()7const storybookTestRunner = require('storybook-test-runner').storybookTestRunner8const { stories, addons } = storybookTestRunner()9const storybookTestRunner = require('storybook-test-runner').storybookTestRunner10const { stories, addons } = storybookTestRunner()11const storybookTestRunner = require('storybook-test-runner').storybookTestRunner12const { stories, addons } = storybookTestRunner()13const storybookTestRunner = require('storybook-test-runner').storybookTestRunner14const { stories, addons } = storybookTestRunner()15const storybookTestRunner = require('storybook-test-runner').storybookTestRunner16const { stories, addons } = storybookTestRunner()17const storybookTestRunner = require('storybook-test-runner').storybookTestRunner18const { stories, addons } = storybookTestRunner()19const storybookTestRunner = require('storybook-test-runner').storybookTestRunner20const { stories, addons } = storybookTestRunner()21const storybookTestRunner = require('storybook-test-runner').storybookTestRunner22const { stories, addons } = storybookTestRunner()23const storybookTestRunner = require('storybook-test-runner').storybookTestRunner24const { stories, addons } = storybookTestRunner()
Using AI Code Generation
1const { opts } = require('storyshots-test-runner');2const storybookTestRunner = require('storybook-test-runner');3const initStoryshots = require('@storybook/addon-storyshots');4const puppeteer = require('puppeteer');5initStoryshots({6 test: storybookTestRunner(opts, {7 test: async ({ page, context }) => {8 const image = await page.screenshot();9 expect(image).toMatchImageSnapshot();10 },11 }),12});13const puppeteer = require('puppeteer');14initStoryshots({15 test: storybookTestRunner(opts, {16 test: async ({ page, context }) => {17 const image = await page.screenshot();18 expect(image).toMatchImageSnapshot();19 },20 }),21});22const puppeteer = require('puppeteer');23initStoryshots({24 test: storybookTestRunner(opts, {25 test: async ({ page, context }) => {26 const image = await page.screenshot();27 expect(image).toMatchImageSnapshot();28 },29 }),30});31const puppeteer = require('puppeteer');32initStoryshots({33 test: storybookTestRunner(opts, {34 test: async ({ page, context }) => {35 const image = await page.screenshot();36 expect(image).toMatchImageSnapshot();37 },38 }),39});40const puppeteer = require('puppeteer');41initStoryshots({
Using AI Code Generation
1import {opts} from 'storybook-test-runner';2import path from 'path';3const testOpts = opts({4 storybook: {5 stories: path.join(__dirname, '../stories'),6 configDir: path.join(__dirname, '../.storybook'),7 },8});9export default testOpts;10import test from 'storybook-test-runner';11import testOpts from './test';12test('stories', testOpts);
Using AI Code Generation
1const opts = require('storytest-runner').opts;2const options = opts({3 storybook: {4 webpackFinal: (config, { configType }) => {5 config.module.rules.push({6 include: path.resolve(__dirname, '../')7 });8 return config;9 },10 },11 tests: {12 cypress: {13 }14 }15});16module.exports = options;17{18 "testFiles": "**/*.{spec,test}.{js,jsx,ts,tsx}",
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!