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.
68 lines (56 loc) • 2.19 kB
JavaScript
/*! prevnext plugin for Cycle2; version: 20140408 */
(function($) {
;
$.extend($.fn.cycle.defaults, {
next: '> .cycle-next',
nextEvent: 'click.cycle',
disabledClass: 'disabled',
prev: '> .cycle-prev',
prevEvent: 'click.cycle',
swipe: false
});
$(document).on( 'cycle-initialized', function( e, opts ) {
opts.API.getComponent( 'next' ).on( opts.nextEvent, function(e) {
e.preventDefault();
opts.API.next();
});
opts.API.getComponent( 'prev' ).on( opts.prevEvent, function(e) {
e.preventDefault();
opts.API.prev();
});
if ( opts.swipe ) {
var nextEvent = opts.swipeVert ? 'swipeUp.cycle' : 'swipeLeft.cycle swipeleft.cycle';
var prevEvent = opts.swipeVert ? 'swipeDown.cycle' : 'swipeRight.cycle swiperight.cycle';
opts.container.on( nextEvent, function(e) {
opts._tempFx = opts.swipeFx;
opts.API.next();
});
opts.container.on( prevEvent, function() {
opts._tempFx = opts.swipeFx;
opts.API.prev();
});
}
});
$(document).on( 'cycle-update-view', function( e, opts, slideOpts, currSlide ) {
if ( opts.allowWrap )
return;
var cls = opts.disabledClass;
var next = opts.API.getComponent( 'next' );
var prev = opts.API.getComponent( 'prev' );
var prevBoundry = opts._prevBoundry || 0;
var nextBoundry = (opts._nextBoundry !== undefined)?opts._nextBoundry:opts.slideCount - 1;
if ( opts.currSlide == nextBoundry )
next.addClass( cls ).prop( 'disabled', true );
else
next.removeClass( cls ).prop( 'disabled', false );
if ( opts.currSlide === prevBoundry )
prev.addClass( cls ).prop( 'disabled', true );
else
prev.removeClass( cls ).prop( 'disabled', false );
});
$(document).on( 'cycle-destroyed', function( e, opts ) {
opts.API.getComponent( 'prev' ).off( opts.nextEvent );
opts.API.getComponent( 'next' ).off( opts.prevEvent );
opts.container.off( 'swipeleft.cycle swiperight.cycle swipeLeft.cycle swipeRight.cycle swipeUp.cycle swipeDown.cycle' );
});
})(jQuery);