Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
malwaredllc
GitHub Repository: malwaredllc/byob
Path: blob/master/web-gui/buildyourownbotnet/assets/js/jquery.bootstrap.wizard.min.js
1292 views
1
/*!
2
* jQuery twitter bootstrap wizard plugin
3
* Examples and documentation at: http://github.com/VinceG/twitter-bootstrap-wizard
4
* version 1.0
5
* Requires jQuery v1.3.2 or later
6
* Supports Bootstrap 2.2.x, 2.3.x, 3.0
7
* Dual licensed under the MIT and GPL licenses:
8
* http://www.opensource.org/licenses/mit-license.php
9
* http://www.gnu.org/licenses/gpl.html
10
* Authors: Vadim Vincent Gabriel (http://vadimg.com), Jason Gill (www.gilluminate.com)
11
*/
12
;(function($) {
13
var bootstrapWizardCreate = function(element, options) {
14
var element = $(element);
15
var obj = this;
16
17
// selector skips any 'li' elements that do not contain a child with a tab data-toggle
18
var baseItemSelector = 'li:has([data-toggle="tab"])';
19
20
// Merge options with defaults
21
var $settings = $.extend({}, $.fn.bootstrapWizard.defaults, options);
22
var $activeTab = null;
23
var $navigation = null;
24
25
this.rebindClick = function(selector, fn)
26
{
27
selector.unbind('click', fn).bind('click', fn);
28
}
29
30
this.fixNavigationButtons = function() {
31
// Get the current active tab
32
if(!$activeTab.length) {
33
// Select first one
34
$navigation.find('a:first').tab('show');
35
$activeTab = $navigation.find(baseItemSelector + ':first');
36
}
37
38
// See if we're currently in the first/last then disable the previous and last buttons
39
$($settings.previousSelector, element).toggleClass('disabled', (obj.firstIndex() >= obj.currentIndex()));
40
$($settings.nextSelector, element).toggleClass('disabled', (obj.currentIndex() >= obj.navigationLength()));
41
42
// We are unbinding and rebinding to ensure single firing and no double-click errors
43
obj.rebindClick($($settings.nextSelector, element), obj.next);
44
obj.rebindClick($($settings.previousSelector, element), obj.previous);
45
obj.rebindClick($($settings.lastSelector, element), obj.last);
46
obj.rebindClick($($settings.firstSelector, element), obj.first);
47
48
if($settings.onTabShow && typeof $settings.onTabShow === 'function' && $settings.onTabShow($activeTab, $navigation, obj.currentIndex())===false){
49
return false;
50
}
51
};
52
53
this.next = function(e) {
54
e.preventDefault();
55
56
// If we clicked the last then dont activate this
57
if(element.hasClass('last')) {
58
return false;
59
}
60
61
if($settings.onNext && typeof $settings.onNext === 'function' && $settings.onNext($activeTab, $navigation, obj.nextIndex())===false){
62
return false;
63
}
64
65
// Did we click the last button
66
$index = obj.nextIndex();
67
if($index > obj.navigationLength()) {
68
} else {
69
$navigation.find(baseItemSelector + ':eq('+$index+') a').tab('show');
70
}
71
};
72
73
this.previous = function(e) {
74
e.preventDefault();
75
76
// If we clicked the first then dont activate this
77
if(element.hasClass('first')) {
78
return false;
79
}
80
81
if($settings.onPrevious && typeof $settings.onPrevious === 'function' && $settings.onPrevious($activeTab, $navigation, obj.previousIndex())===false){
82
return false;
83
}
84
85
$index = obj.previousIndex();
86
if($index < 0) {
87
} else {
88
$navigation.find(baseItemSelector + ':eq('+$index+') a').tab('show');
89
}
90
};
91
92
this.first = function(e) {
93
e.preventDefault();
94
95
if($settings.onFirst && typeof $settings.onFirst === 'function' && $settings.onFirst($activeTab, $navigation, obj.firstIndex())===false){
96
return false;
97
}
98
99
// If the element is disabled then we won't do anything
100
if(element.hasClass('disabled')) {
101
return false;
102
}
103
$navigation.find(baseItemSelector + ':eq(0) a').tab('show');
104
105
};
106
107
this.last = function(e) {
108
e.preventDefault();
109
110
if($settings.onLast && typeof $settings.onLast === 'function' && $settings.onLast($activeTab, $navigation, obj.lastIndex())===false){
111
return false;
112
}
113
114
// If the element is disabled then we won't do anything
115
if(element.hasClass('disabled')) {
116
return false;
117
}
118
$navigation.find(baseItemSelector + ':eq('+obj.navigationLength()+') a').tab('show');
119
};
120
121
this.currentIndex = function() {
122
return $navigation.find(baseItemSelector).index($activeTab);
123
};
124
this.firstIndex = function() {
125
return 0;
126
};
127
this.lastIndex = function() {
128
return obj.navigationLength();
129
};
130
this.getIndex = function(e) {
131
return $navigation.find(baseItemSelector).index(e);
132
};
133
this.nextIndex = function() {
134
return $navigation.find(baseItemSelector).index($activeTab) + 1;
135
};
136
this.previousIndex = function() {
137
return $navigation.find(baseItemSelector).index($activeTab) - 1;
138
};
139
this.navigationLength = function() {
140
return $navigation.find(baseItemSelector).length - 1;
141
};
142
this.activeTab = function() {
143
return $activeTab;
144
};
145
this.nextTab = function() {
146
return $navigation.find(baseItemSelector + ':eq('+(obj.currentIndex()+1)+')').length ? $navigation.find(baseItemSelector + ':eq('+(obj.currentIndex()+1)+')') : null;
147
};
148
this.previousTab = function() {
149
if(obj.currentIndex() <= 0) {
150
return null;
151
}
152
return $navigation.find(baseItemSelector + ':eq('+parseInt(obj.currentIndex()-1)+')');
153
};
154
this.show = function(index) {
155
return element.find(baseItemSelector + ':eq(' + index + ') a').tab('show');
156
};
157
this.disable = function(index) {
158
$navigation.find(baseItemSelector + ':eq('+index+')').addClass('disabled');
159
};
160
this.enable = function(index) {
161
$navigation.find(baseItemSelector + ':eq('+index+')').removeClass('disabled');
162
};
163
this.hide = function(index) {
164
$navigation.find(baseItemSelector + ':eq('+index+')').hide();
165
};
166
this.display = function(index) {
167
$navigation.find(baseItemSelector + ':eq('+index+')').show();
168
};
169
this.remove = function(args) {
170
var $index = args[0];
171
var $removeTabPane = typeof args[1] != 'undefined' ? args[1] : false;
172
var $item = $navigation.find(baseItemSelector + ':eq('+$index+')');
173
174
// Remove the tab pane first if needed
175
if($removeTabPane) {
176
var $href = $item.find('a').attr('href');
177
$($href).remove();
178
}
179
180
// Remove menu item
181
$item.remove();
182
};
183
184
$navigation = element.find('ul:first', element);
185
$activeTab = $navigation.find(baseItemSelector + '.active', element);
186
187
if(!$navigation.hasClass($settings.tabClass)) {
188
$navigation.addClass($settings.tabClass);
189
}
190
191
// Load onInit
192
if($settings.onInit && typeof $settings.onInit === 'function'){
193
$settings.onInit($activeTab, $navigation, 0);
194
}
195
196
// Load onShow
197
if($settings.onShow && typeof $settings.onShow === 'function'){
198
$settings.onShow($activeTab, $navigation, obj.nextIndex());
199
}
200
201
// Work the next/previous buttons
202
obj.fixNavigationButtons();
203
204
$('a[data-toggle="tab"]', $navigation).on('click', function (e) {
205
// Get the index of the clicked tab
206
var clickedIndex = $navigation.find(baseItemSelector).index($(e.currentTarget).parent(baseItemSelector));
207
if($settings.onTabClick && typeof $settings.onTabClick === 'function' && $settings.onTabClick($activeTab, $navigation, obj.currentIndex(), clickedIndex)===false){
208
return false;
209
}
210
});
211
212
// attach to both shown and shown.bs.tab to support Bootstrap versions 2.3.2 and 3.0.0
213
$('a[data-toggle="tab"]', $navigation).on('shown shown.bs.tab', function (e) { // use shown instead of show to help prevent double firing
214
$element = $(e.target).parent();
215
var nextTab = $navigation.find(baseItemSelector).index($element);
216
217
// If it's disabled then do not change
218
if($element.hasClass('disabled')) {
219
return false;
220
}
221
222
if($settings.onTabChange && typeof $settings.onTabChange === 'function' && $settings.onTabChange($activeTab, $navigation, obj.currentIndex(), nextTab)===false){
223
return false;
224
}
225
226
$activeTab = $element; // activated tab
227
obj.fixNavigationButtons();
228
});
229
};
230
$.fn.bootstrapWizard = function(options) {
231
//expose methods
232
if (typeof options == 'string') {
233
var args = Array.prototype.slice.call(arguments, 1)
234
if(args.length === 1) {
235
args.toString();
236
}
237
return this.data('bootstrapWizard')[options](args);
238
}
239
return this.each(function(index){
240
var element = $(this);
241
// Return early if this element already has a plugin instance
242
if (element.data('bootstrapWizard')) return;
243
// pass options to plugin constructor
244
var wizard = new bootstrapWizardCreate(element, options);
245
// Store plugin object in this element's data
246
element.data('bootstrapWizard', wizard);
247
});
248
};
249
250
// expose options
251
$.fn.bootstrapWizard.defaults = {
252
tabClass: 'nav nav-pills',
253
nextSelector: '.wizard li.next',
254
previousSelector: '.wizard li.previous',
255
firstSelector: '.wizard li.first',
256
lastSelector: '.wizard li.last',
257
onShow: null,
258
onInit: null,
259
onNext: null,
260
onPrevious: null,
261
onLast: null,
262
onFirst: null,
263
onTabChange: null,
264
onTabClick: null,
265
onTabShow: null
266
};
267
268
})(jQuery);
269