forked from malsup/cycle2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.cycle2.caption2.js
67 lines (58 loc) · 1.95 KB
/
jquery.cycle2.caption2.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
66
67
/*! caption2 plugin for Cycle2; version: 20130306 */
(function($) {
"use strict";
$.extend($.fn.cycle.defaults, {
captionFxOut: 'fadeOut',
captionFxIn: 'fadeIn',
captionFxSel: undefined,
overlayFxOut: 'fadeOut',
overlayFxIn: 'fadeIn',
overlayFxSel: undefined
});
$(document).on( 'cycle-bootstrap', function(e, opts) {
opts.container.on( 'cycle-update-view-before', update );
opts.container.one( 'cycle-update-view-after', init );
});
function update( e, opts, slideOpts, currSlide, isAfter ) {
if ( opts.captionPlugin !== 'caption2' )
return;
$.each(['caption','overlay'], function() {
var fxBase = this + 'Fx',
fx = opts[fxBase + 'Out'] || 'hide',
template = slideOpts[this+'Template'],
el = opts.API.getComponent( this ),
sel = opts[fxBase+'Sel'],
speed = opts.speed,
animEl;
if ( opts.sync )
speed = speed/2;
animEl = sel ? el.find( sel ) : el;
if( el.length && template ) {
if ( fx == 'hide')
speed = 0;
animEl[fx]( speed, function() {
var content = opts.API.tmpl( template, slideOpts, opts, currSlide );
el.html( content );
animEl = sel ? el.find( sel ) : el;
if ( sel )
animEl.hide();
fx = opts[ fxBase + 'In'] || 'show';
animEl[fx]( speed );
});
}
else {
el.hide();
}
});
}
function init( e, opts, slideOpts, currSlide, isAfter ) {
if ( opts.captionPlugin !== 'caption2' )
return;
$.each(['caption','overlay'], function() {
var template = slideOpts[this+'Template'],
el = opts.API.getComponent( this );
if( el.length && template )
el.html( opts.API.tmpl( template, slideOpts, opts, currSlide ) );
});
}
})(jQuery);