UNPKG

jquery-cycle2-ibe

Version:

Cycle2 is a versatile slideshow plugin for jQuery built around ease-of-use. It supports a declarative initialization style that allows full customization without any scripting.

53 lines (43 loc) 1.33 kB
/*! hash plugin for Cycle2; version: 20130905 */ (function($) { "use strict"; $(document).on( 'cycle-pre-initialize', function( e, opts ) { onHashChange( opts, true ); opts._onHashChange = function() { onHashChange( opts, false ); }; $( window ).on( 'hashchange', opts._onHashChange); }); $(document).on( 'cycle-update-view', function( e, opts, slideOpts ) { if ( slideOpts.hash && ( '#' + slideOpts.hash ) != window.location.hash ) { opts._hashFence = true; window.location.hash = slideOpts.hash; } }); $(document).on( 'cycle-destroyed', function( e, opts) { if ( opts._onHashChange ) { $( window ).off( 'hashchange', opts._onHashChange ); } }); function onHashChange( opts, setStartingSlide ) { var hash; if ( opts._hashFence ) { opts._hashFence = false; return; } hash = window.location.hash.substring(1); opts.slides.each(function(i) { if ( $(this).data( 'cycle-hash' ) == hash ) { if ( setStartingSlide === true ) { opts.startingSlide = i; } else { var fwd = opts.currSlide < i; opts.nextSlide = i; opts.API.prepareTx( true, fwd ); } return false; } }); } })(jQuery);