forked from malsup/cycle2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.cycle2.prevnext.js
65 lines (54 loc) · 2.06 KB
/
jquery.cycle2.prevnext.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*! prevnext plugin for Cycle2; version: 20130709 */
(function($) {
"use strict";
$.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.API.next();
});
opts.container.on( prevEvent, function() {
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);