This repository has been archived by the owner on Feb 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathsco.panes.js
116 lines (101 loc) · 3.14 KB
/
sco.panes.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* ==========================================================
* sco.panes.js
* http://github.com/terebentina/sco.js
* ==========================================================
* Copyright 2013 Dan Caragea.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================== */
/*jshint laxcomma:true, sub:true, browser:true, jquery:true, devel:true */
;(function($, undefined) {
"use strict";
var pluginName = 'scojs_panes';
function Panes($wrapper, options) {
var self = this;
this.options = $.extend({}, $[pluginName].defaults, options);
var transitionEnd = ($.support.transition && this.options.easing) ? $.support.transition.end : null;
this.$pane_wrapper = $wrapper;
if (this.options.easing) {
this.$pane_wrapper.addClass(this.options.easing);
}
this.$pane_wrapper.on('select.' + pluginName, function(e, options, index) {
if (!e.namespace || e.namespace != pluginName) {
return;
}
var direction = 'left'
,type = 'next'
;
if (options.active > index) {
direction = 'right';
type = 'prev';
}
function onEnd() {
self.$panes.eq(options.active).removeClass('active ' + direction);
self.options.active = index;
self.$panes.eq(index).removeClass([type, direction].join(' ')).addClass('active');
}
if (transitionEnd) {
self.$pane_wrapper.one(transitionEnd, onEnd);
}
self.$panes.eq(index).addClass(type)[0].offsetWidth; // force reflow
self.$panes.eq(options.active).addClass(direction);
self.$panes.eq(index).addClass(direction);
if (!transitionEnd) {
onEnd();
}
});
this.$panes = this.$pane_wrapper.children();
this.$panes.eq(this.options.active).addClass('active');
}
$.extend(Panes.prototype, {
select: function(index) {
if (index !== this.options.active) {
if (typeof this.options.onBeforeSelect != 'function' || this.options.onBeforeSelect.call(this, index) !== false) {
this.$pane_wrapper.trigger('select.' + pluginName, [this.options, index]);
return true;
}
}
return false;
}
,next: function() {
var tab_count = this.$panes.length
,next
;
if (this.options.active === tab_count - 1) {
next = 0;
} else {
next = this.options.active + 1;
}
return this.select(next);
}
,prev: function() {
var prev;
if (this.options.active === 0) {
prev = this.$panes.length - 1;
} else {
prev = this.options.active - 1;
}
return this.select(prev);
}
});
$[pluginName] = function(elem, options) {
if (typeof elem === 'string') {
elem = $(elem);
}
return new Panes(elem, options);
};
$[pluginName].defaults = {
active: 0
,easing: ''
}
})(jQuery);