I've got following code:
<div id="action_wrap">
<div id="action_nav">
<div class="action" data-target="#content1" data-toggle="tab">First Block</div>
<div class="action" data-target="#content2" data-toggle="tab">Second Block</div>
<div class="action" data-target="#content3" data-toggle="tab">Third Block</div>
</div>
<div id="action_items">
<div class="action_text collapse" id="content1">
<p>Content 1</p>
<span class="close">Close</span>
<div class="clearfix"></div>
</div>
<div class="action_text collapse" id="content2">
<p>Content 2</p>
<span class="close">Close</span>
<div class="clearfix"></div>
</div>
<div class="action_text collapse" id="content3">
<p>Content 3</p>
<span class="close">Close</span>
<div class="clearfix"></div>
</div>
</div>
</div>
and using Twitter Boostrap's "Tab" script, it works fine. I've added some really nasty looking script for close button and for nav button to get active class like so:
$(".action").click(function () {
$(this).parent().children().removeClass("active");
$(this).addClass("active");
$(this).parent().addClass("active");
});
$(".close").click(function () {
$(this).parent().parent().parent().children().removeClass("active");
$(this).parent().parent().parent().children().children().removeClass("active");
});
it's not much but meh, it's working.
What i cannot do tho is make Bootstrap's Tab's closable by clicking active nav div. Meaning if i click first .action div with data-target on #content1, .action_text#content1 will get .active class and so will the .action div i clicked on. And what i want is for .action.active data-target="#content1" on click removing .tab()'s class "active" and same for itself.
I found in another thread that changing the code from Bootstrap's Tab script
$(document).on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
e.preventDefault()
$(this).tab('show')
})
but it seems everytime i edit it, it just breaks whole thing. I tried adding if statement like so
$(document).on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
if ($(this).hasClass('active')) {
$(this).tab().removeClass('active');
$(this).removeClass('active');
} else {
e.preventDefault()
$(this).tab('show')
}
})
But whole thing stopped working.