-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit contains the first code release
- Loading branch information
Iván Melgrati
committed
Dec 27, 2017
1 parent
494f7cb
commit 7c61a10
Showing
4 changed files
with
405 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,75 @@ | ||
# tab-collapse | ||
While Bootstrap's Collapse component (accordions) can be very useful and works well in mobile websites, tab-based navigation usually works better in desktop screens. This component provides a way to integrate both tabs and accordions using some extra CSS and Javascript. | ||
# Tab/Collapse | ||
While Bootstrap's Collapse component (accordions) can be very useful and works well in mobile websites, tab-based navigation usually works better in desktop screens. This component provides a way to integrate both tabs and accordions using some extra CSS and Javascript. | ||
|
||
Developed by [Ivan Melgrati](https://imelgrat.me) [![Twitter](https://img.shields.io/twitter/url/https/github.com/imelgrat/tab-collapse.svg?style=social)](https://twitter.com/imelgrat) | ||
|
||
License: [![GitHub license](https://img.shields.io/github/license/imelgrat/tab-collapse.svg)](https://github.com/imelgrat/tab-collapse/blob/master/LICENSE) | ||
|
||
Status: [![GitHub release](https://img.shields.io/github/release/imelgrat/tab-collapse.svg)](https://github.com/imelgrat/tab-collapse) [![GitHub issues](https://img.shields.io/github/issues/imelgrat/tab-collapse.svg)](https://github.com/imelgrat/tab-collapse/issues) [![GitHub forks](https://img.shields.io/github/forks/imelgrat/tab-collapse.svg)](https://github.com/imelgrat/tab-collapse/network) [![GitHub stars](https://img.shields.io/github/stars/imelgrat/tab-collapse.svg)](https://github.com/imelgrat/tab-collapse/stargazers) | ||
|
||
|
||
Requirements | ||
------------ | ||
|
||
* jQuery >= 3.0 | ||
* Bootstrap >= 3.3 | ||
|
||
Installation | ||
------------ | ||
|
||
While most of the code required to make tabs and accordions work comes from Bootstrap, it is necessary to add some extra code to make the "component switch" between tabs and accordions view and navigation work. | ||
After adding both jQuery and Bootstrap, it's necessary to add the component's CSS rules and JavaScript code | ||
|
||
```html | ||
<link rel="stylesheet" href="../dist/css/tabcollapse-style.css" crossorigin="anonymous"> | ||
<script src="../dist/js/tabcollapse-script.js" crossorigin="anonymous"></script> | ||
``` | ||
|
||
Usage | ||
------------ | ||
For the Tab/Collapse to work, it's necessary to create three blocks. The *vertab-container* div (the whole component's container, used as CSS and JS selector), the *vertab-menu* section (tab navigation links) and the *vertab-accordion* section (accordion and content sections). | ||
For each content section, it's necessary to create a link inside the *list-group* block and a *vertab-content* block. | ||
|
||
```html | ||
<div class="col-lg-12 vertab-container"> | ||
<div class="col-lg-3 col-md-3 col-sm-3 vertab-menu"> | ||
<div class="list-group"> | ||
<a href="#" class="list-group-item text-left"> This is Tab 1 </a> | ||
....... | ||
</div> | ||
</div> | ||
<div id="accordion" class="col-lg-9 col-md-9 col-sm-9 col-xs-12 vertab-accordion panel-group"> | ||
<div class="vertab-content"> | ||
<div class="panel-heading"> | ||
<h4 class="panel-title" data-toggle="collapse" data-parent="#accordion" data-target="#collapse1"> This is Heading 1 </h4> | ||
</div> | ||
<div id="collapse1" class="panel-collapse collapse"> | ||
<div class="panel-body"> | ||
Here goes the content | ||
</div> | ||
</div> | ||
</div> | ||
......... | ||
</div> | ||
</div> | ||
``` | ||
Feedback | ||
-------- | ||
|
||
Please open an issue to request a feature or submit a bug report. Or even if | ||
you just want to provide some feedback, I'd love to hear. I'm also available on | ||
Twitter as [@imelgrat](https://twitter.com/imelgrat). | ||
|
||
Contributing | ||
------------ | ||
|
||
1. Fork it. | ||
2. Create your feature branch (`git checkout -b my-new-feature`). | ||
3. Commit your changes (`git commit -am 'Added some feature'`). | ||
4. Push to the branch (`git push origin my-new-feature`). | ||
5. Create a new Pull Request. | ||
|
||
Links | ||
==== | ||
* Article/Tutorial: https://imelgrat.me/javascript/integrate-bootstrap-tabs-accordions/ | ||
* Live example: https://codepen.io/imelgrat/details/wpGgpN/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
.panel-title { | ||
cursor:pointer; | ||
} | ||
h4.tab-title | ||
{ | ||
font-family: "avenirheavy", Helvetica, Arial, "sans-serif"; | ||
font-weight: normal; | ||
font-size: 22px; | ||
color: #ffffff; | ||
} | ||
.vertab-content ul, .vertab-content ol { | ||
padding-left: 15px; | ||
} | ||
@media (min-width:768px) { | ||
.vertab-container { | ||
z-index: 10; | ||
background-color: #7952b3; | ||
padding: 0 !important; | ||
border: 1px solid #ddd; | ||
margin-top: 20px; | ||
background-clip: padding-box; | ||
opacity: 0.97; | ||
filter: alpha(opacity=97); | ||
overflow: auto; | ||
margin-bottom: 50px; | ||
} | ||
.vertab-menu { | ||
padding-right: 0; | ||
padding-left: 0; | ||
padding-bottom: 0; | ||
display: block; | ||
background-color: #e3e3e3; | ||
} | ||
.vertab-menu .list-group { | ||
margin-bottom: 0; | ||
} | ||
.vertab-menu .list-group>a { | ||
margin-bottom: 0; | ||
border-radius: 0; | ||
} | ||
.vertab-menu .list-group>a, .vertab-menu .list-group>a { | ||
color: #818181; | ||
background-image: none; | ||
background-color: #F6F6F6; | ||
border-radius: 0; | ||
box-sizing: border-box; | ||
border: none; | ||
border-bottom: 1px solid #CACACA; | ||
padding: 15px 10px; | ||
} | ||
.vertab-menu .list-group>a.active, .vertab-menu .list-group>a:hover, .vertab-menu .list-group>a:focus { | ||
position: relative; | ||
border: none; | ||
border-radius: 0; | ||
border-bottom: 1px solid #CACACA; | ||
border-left: 5px solid #7952b3; | ||
padding-left: 5px; | ||
background-image: none; | ||
background-color: #F6F6F6; | ||
color: #7952b3; | ||
} | ||
.vertab-content { | ||
padding-left: 20px; | ||
padding-top: 10px; | ||
color: #FFFFFF; | ||
} | ||
.vertab-accordion .vertab-content:not(.active) { | ||
display: none; | ||
} | ||
.vertab-accordion .vertab-content.active .collapse { | ||
display: block; | ||
} | ||
.vertab-container .panel-heading { | ||
display: none; | ||
} | ||
.vertab-container .panel-body { | ||
border-top: none !important; | ||
} | ||
} | ||
|
||
/* If the tc_breakpoint variable is changed, this breakpoint should be changed as well */ | ||
@media (max-width:767px) { | ||
.vertab-container { | ||
margin-top: 20px; | ||
margin-bottom: 20px; | ||
} | ||
.vertab-container .vertab-menu { | ||
display: none; | ||
} | ||
.vertab-container .panel-heading { | ||
background-color: #F6F6F6; | ||
color: #818181; | ||
padding: 15px; | ||
border-bottom: 1px solid #F6F6F6; | ||
border-top-left-radius: 0; | ||
border-top-right-radius: 0; | ||
border-left: 5px solid #F6F6F6; | ||
} | ||
.vertab-container .panel-heading:hover, .vertab-container .panel-heading:focus, .vertab-container .panel-heading.active { | ||
border-left: 5px solid #7952b3; | ||
border-bottom: 1px solid #7952b3; | ||
} | ||
.vertab-content { | ||
border-bottom: 1px solid #CACACA; | ||
} | ||
.vertab-container .panel-title a:focus, .vertab-container .panel-title a:hover, .vertab-container .panel-title a:active { | ||
color: #818181; | ||
text-decoration: none; | ||
} | ||
.panel-collapse.collapse, .panel-collapse.collapsing { | ||
background-color: #7952b3 !important; | ||
color: #ffffff; | ||
} | ||
.vertab-container .panel-collapse .panel-body { | ||
border-top: none !important; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Screen-width breakpoint | ||
var tc_breakpoint = 767; | ||
|
||
jQuery(document).ready(function() | ||
{ | ||
"use strict"; | ||
|
||
// Switch tabs and update panels classes - Adjust container height | ||
jQuery(".vertab-container .vertab-menu .list-group a").click(function(e) | ||
{ | ||
var index = jQuery(this).index(); | ||
var container = jQuery(this).parents('.vertab-container'); | ||
var accordion = container.find('.vertab-accordion'); | ||
var contents = accordion.find(".vertab-content"); | ||
|
||
e.preventDefault(); | ||
|
||
jQuery(this).addClass("active"); | ||
jQuery(this).siblings('a.active').removeClass("active"); | ||
|
||
contents.removeClass("active"); | ||
contents.eq(index).addClass("active"); | ||
container.data('current',index); | ||
|
||
//Adjust container height | ||
jQuery(this).parents('.vertab-menu').css('min-height',jQuery(container).children('.vertab-accordion').height() + 20); | ||
}); | ||
|
||
// Collapse accordion panels (except the one the user just opened) and add "active" class to the panel heading | ||
jQuery('.vertab-accordion').on('show.bs.collapse','.collapse', function() | ||
{ | ||
var accordion, container, current, index; | ||
|
||
accordion = jQuery(this).parents('.vertab-accordion'); | ||
container = accordion.parents('.vertab-container'); | ||
|
||
accordion.find('.collapse.in').each(function() | ||
{ | ||
jQuery(this).collapse('hide'); | ||
}); | ||
|
||
jQuery(this).siblings('.panel-heading').addClass('active'); | ||
|
||
current = accordion.find('.panel-heading.active'); | ||
index = accordion.find('.panel-heading').index(current); | ||
|
||
container.data('current',index); | ||
}); | ||
|
||
// Remove "active" class from heading when collapsing the current panel | ||
jQuery('.vertab-accordion .panel-collapse').on('hide.bs.collapse', function () { | ||
jQuery(this).siblings('.panel-heading').removeClass('active'); | ||
}); | ||
|
||
// Manage resize / rotation events | ||
jQuery( window ).on( "resize orientationchange", function( ) | ||
{ | ||
resize_vertical_accordions(); | ||
}); | ||
|
||
// Scroll accordion to show the current panel | ||
jQuery(".vertab-accordion .panel-heading").click(function () | ||
{ | ||
var el = this; | ||
setTimeout(function(){jQuery("html, body").animate({scrollTop: jQuery(el).offset().top - 10 }, 1000);},500); | ||
|
||
return true; | ||
}); | ||
|
||
//Initial Panels setup | ||
resize_vertical_accordions( ); | ||
}); | ||
|
||
function resize_vertical_accordions( ) | ||
{ | ||
"use strict"; | ||
jQuery('.vertab-container').each(function(i, e) | ||
{ | ||
var index, menu, contents; | ||
var container = jQuery(this); | ||
|
||
// Setup current tab/panel (default to first tab/panel) | ||
index = jQuery(this).data('current'); | ||
if(index === undefined) | ||
{ | ||
jQuery(this).data('index',0); | ||
index = 0; | ||
} | ||
|
||
// If using a desktop-size screen, manage as tabbed panels | ||
if( jQuery( window ).width() > tc_breakpoint) | ||
{ | ||
// Reset panels heights (Bootstrap's accordions sets heights to zero) | ||
jQuery(this).find('.panel-collapse.collapse').css('height','auto'); | ||
|
||
// Clean tab-navigation styles | ||
menu = jQuery(this).find('.vertab-menu .list-group a'); | ||
menu.removeClass("active"); | ||
|
||
// Clean tab-panels styles | ||
contents = jQuery(this).find(".vertab-accordion .vertab-content"); | ||
contents.removeClass("active"); | ||
|
||
// Update tab navigation and panels styles | ||
menu.eq(index).addClass('active'); | ||
contents.eq(index).addClass("active"); | ||
|
||
// Update tab navigation's height to match current tab | ||
jQuery(this).children('.vertab-menu').css('min-height',jQuery(this).children('.vertab-accordion').height() + 20); | ||
} | ||
else // If using a mobile device (phone + tablets), manage as accordion | ||
{ | ||
// Close all panels | ||
jQuery(this).find('.vertab-content .panel-collapse.collapse').collapse('hide'); | ||
|
||
// Clean styles from headings | ||
jQuery(this).find('.vertab-content .panel-heading').removeClass('active'); | ||
|
||
// Wait until all panels have collapsed and mark the one the user selected as active. | ||
setTimeout(function() | ||
{ | ||
jQuery(container).find('.vertab-content .panel-heading').eq(index).addClass("active"); | ||
jQuery(container).find('.vertab-content .panel-collapse.collapse').eq(index).collapse('show'); | ||
},1000); | ||
|
||
} | ||
}); | ||
} |
Oops, something went wrong.