-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
115 lines (107 loc) · 4.16 KB
/
index.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
(function ($) {
/**
* @return {function|boolean}
*/
$.fn.TabWizard = function (options) {
if (typeof $.fn.tab !== 'function') {
console.warn('TabWizard depends on Bootstrap 4 Tab plugin');
return false;
}
let self = this;
var visibleButtons = [];
let settings = $.extend({
showTabs: true,
additionalButtons: [],
nextButtonClass: '.btnNext',
previousButtonClass: '.btnPrevious',
finishButtonText: 'Finish',
onNext: function (callback) {
if (typeof callback === 'function') {
callback();
}
},
onPrevious: function (callback) {
if (typeof callback === 'function') {
callback();
}
},
onFinish: function (callback) {
if (typeof callback === 'function') {
callback();
}
}
}, options);
function hideAdditionalButtons() {
let buttons = settings.additionalButtons;
for (let index in buttons) {
for (let btn in buttons[index].buttons) {
$(self).find(buttons[index].buttons[btn]).addClass('d-none');
$(self).find(buttons[index].buttons[btn]).removeClass('d-block');
}
}
}
function updateNextButtonState(e) {
let btn = $(self).find(settings.nextButtonClass);
let tab = $(e.target).attr('href');
$(self).find('.tab-content').find($(e.target));
if ($(self).find(tab).is(':last-child')) {
btn.addClass('btnFinish').text(settings.finishButtonText);
} else {
$(btn).removeClass('btnFinish').text('Next');
}
}
function updateAdditionalButtonsState(btn) {
let tab = $(btn).attr('href');
let visible = settings.additionalButtons.filter(function (group) {
if (group.tab === tab) {
if (group.buttons) {
return group.buttons;
}
}
})[0];
hideAdditionalButtons();
if (visible) {
let btns = visible.buttons.join(', ');
console.log(btns);
$(self).find(btns).removeClass('d-none');
$(self).find(btns).addClass('d-block');
}
}
if (!settings.showTabs) {
$(self).find('.nav-tabs').hide();
}
hideAdditionalButtons();
let activeTab = $(self).find('.nav-tabs a.active');
console.log(activeTab);
updateAdditionalButtonsState(activeTab);
$(self).find(settings.nextButtonClass).click(function () {
let btn = this;
if ($(btn).hasClass('btnFinish')) {
settings.onFinish();
} else {
$(self).find('.tab-content .tab-pane').each(function (pane) {
if ($(this).hasClass('active') && $(this).next('.tab-pane').length) {
let me = pane + 1;
$(self).find(`.nav-tabs`).find(`li:nth-child(${me + 1}) a`).tab('show');
return false;
}
});
}
});
$(self).find('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
updateNextButtonState(e);
updateAdditionalButtonsState(this);
});
$(self).find(settings.previousButtonClass).click(function () {
let btn = this;
$(self).find('.tab-content .tab-pane').each(function (pane) {
if ($(this).hasClass('active') && $(this).prev('.tab-pane').length) {
let me = pane + 1;
$(self).find(`.nav-tabs`).find(`li:nth-child(${me - 1}) a`).tab('show');
return false;
}
});
});
return this;
};
}(jQuery));