forked from flatlogic/bootstrap-tabcollapse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap-tabcollapse.js
More file actions
65 lines (53 loc) · 2.34 KB
/
Copy pathbootstrap-tabcollapse.js
File metadata and controls
65 lines (53 loc) · 2.34 KB
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
!function ($) {
"use strict";
function accordionGroupTemplate(parentId, $heading){
var tabSelector = $heading.attr('data-target'),
active = $heading.parent().is('.active');
if (!tabSelector) {
tabSelector = $heading.attr('href');
tabSelector = tabSelector && tabSelector.replace(/.*(?=#[^\s]*$)/, ''); //strip for ie7
}
var $tabContent = $(tabSelector),
groupId = $tabContent.attr('id') + '-collapse';
return '<div class="panel panel-default">' +
' <div class="panel-heading">' +
' <h4 class="panel-title">' +
' <a class="' + (active ? '' : 'collapsed') + '" data-toggle="collapse" data-parent="#' + parentId + '" href="#' + groupId + '">' +
' ' + $heading.html() +
' </a>' +
' </h4>' +
' </div>' +
' <div id="' + groupId + '" class="panel-collapse collapse ' + (active ? 'in' : '') + '">' +
' <div class="panel-body">' +
' ' + $tabContent.html() +
' </div>' +
' </div>' +
'</div>';
}
function accordionTemplate(id, $headings, clazz){
var accordionTemplate = '<div class="panel-group ' + clazz + '" id="' + id +'">';
$headings.each(function(){
var $heading = $(this);
accordionTemplate += accordionGroupTemplate(id, $heading);
});
accordionTemplate += '</div>';
return accordionTemplate;
}
/* TAB-COLLAPSE PLUGIN DEFINITION
* ===================== */
$.fn.tabCollapse = function (options) {
return this.each(function () {
var $this = $(this),
$headings = $this.find('li:not(.dropdown) [data-toggle="tab"], li:not(.dropdown) [data-toggle="pill"]');
options = $.extend({}, $.fn.tabCollapse.defaults, options);
var accordionHtml = accordionTemplate($this.attr('id') + '-accordion', $headings, options.accordionClass);
$this.after(accordionHtml);
$this.addClass(options.tabsClass);
$this.siblings('.tab-content').addClass(options.tabsClass);
})
};
$.fn.tabCollapse.defaults = {
accordionClass: 'visible-xs',
tabsClass: 'hidden-xs'
}
}(window.jQuery);