-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshowhide.js
51 lines (42 loc) · 1.58 KB
/
showhide.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
(function($) {
$.fn.showhide = function(params) {
var element = this;
var options = $(element).data();
var defaultShowSection = options.defaultShow;
var btnActiveClass = options.btnActiveClass || 'dt-btn-active';
function init() {
hideAllSections(element);
removeBtnActiveClass(element);
showSection(element, defaultShowSection);
}
function hideAllSections(element) {
$(element).find('[data-showhide]').each(function() {
$(this).hide();
});
}
function showSection(element,section) {
$(element).find('[data-showhide="'+section+'"]').show();
$(element).find('[data-showhide-btn="'+section+'"]').addClass(btnActiveClass);
}
function removeBtnActiveClass(element) {
$(element).find('[data-showhide-btn]').each(function() {
$(this).removeClass(btnActiveClass);
});
}
$(element).on('click', '[data-showhide-btn]', function() {
hideAllSections(element);
removeBtnActiveClass(element);
var section = $(this).data('showhideBtn');
showSection(element,section);
});
init();
};
$('[data-toggle]').each(function(index,element) {
var plugin = $(element).data('toggle');
switch(plugin) {
case 'showhide' :
$(element).showhide();
break;
}
});
})(jQuery);