-
Notifications
You must be signed in to change notification settings - Fork 736
/
jquery.jcarousel-control.js
76 lines (66 loc) · 2.47 KB
/
jquery.jcarousel-control.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
68
69
70
71
72
73
74
75
76
/*! jCarousel - v0.3.9 - 2018-07-30
* http://sorgalla.com/jcarousel/
* Copyright (c) 2006-2018 Jan Sorgalla; Licensed MIT */
(function($) {
'use strict';
$.jCarousel.plugin('jcarouselControl', {
_options: {
target: '+=1',
event: 'click',
method: 'scroll'
},
_active: null,
_init: function() {
this.onDestroy = $.proxy(function() {
this._destroy();
this.carousel()
.one('jcarousel:createend', $.proxy(this._create, this));
}, this);
this.onReload = $.proxy(this._reload, this);
this.onEvent = $.proxy(function(e) {
e.preventDefault();
var method = this.options('method');
if ($.isFunction(method)) {
method.call(this);
} else {
this.carousel()
.jcarousel(this.options('method'), this.options('target'));
}
}, this);
},
_create: function() {
this.carousel()
.one('jcarousel:destroy', this.onDestroy)
.on('jcarousel:reloadend jcarousel:scrollend', this.onReload);
this._element
.on(this.options('event') + '.jcarouselcontrol', this.onEvent);
this._reload();
},
_destroy: function() {
this._element
.off('.jcarouselcontrol', this.onEvent);
this.carousel()
.off('jcarousel:destroy', this.onDestroy)
.off('jcarousel:reloadend jcarousel:scrollend', this.onReload);
},
_reload: function() {
var parsed = $.jCarousel.parseTarget(this.options('target')),
carousel = this.carousel(),
active;
if (parsed.relative) {
active = carousel
.jcarousel(parsed.target > 0 ? 'hasNext' : 'hasPrev');
} else {
var target = typeof parsed.target !== 'object' ?
carousel.jcarousel('items').eq(parsed.target) :
parsed.target;
active = carousel.jcarousel('target').index(target) >= 0;
}
if (this._active !== active) {
this._trigger(active ? 'active' : 'inactive');
this._active = active;
}
return this;
}
});
}(jQuery));