Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support width: 'auto' and improve hash support #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ <h2>Download</h2>
<h2>Default settings</h2>
<div class="example-1">
<ul>
<li><a href="#1">Tab 1</a></li>
<li><a href="#2">Tab 2</a></li>
<li><a href="#3">Tab 3</a></li>
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<div name="#1">
<div id="tab1_">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies fermentum tempor.
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend.
Ut posuere vestibulum lorem quis iaculis. Nullam luctus ipsum aliquam justo convallis egestas.
</div>
<div name="#2">
<div id="tab2_">
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend. Ut posuere vestibulum lorem quis iaculis.
Nullam luctus ipsum aliquam justo convallis egestas. Vivamus mattis nunc molestie nisi tincidunt gravida. Aliquam erat volutpat.
Donec a dolor vitae quam gravida pharetra euismod eget metus. Ut nisi quam, molestie vitae semper non, malesuada quis justo.
Quisque magna velit, eleifend hendrerit vestibulum non, dignissim sed felis.
</div>
<div name="#3">
<div id="tab3_">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies fermentum tempor.
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend. Ut posuere vestibulum lorem quis iaculis.
Nullam luctus ipsum aliquam justo convallis egestas. Vivamus mattis nunc molestie nisi tincidunt gravida. Aliquam erat volutpat.
Expand All @@ -52,22 +52,22 @@ <h2>Default settings</h2>
<h2>Option: rounded</h2>
<div class="example-2">
<ul>
<li><a href="#1">Tab 1</a></li>
<li><a href="#2">Tab 2</a></li>
<li><a href="#3">Tab 3</a></li>
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<div name="#1">
<div id="tab1_">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies fermentum tempor.
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend.
Ut posuere vestibulum lorem quis iaculis. Nullam luctus ipsum aliquam justo convallis egestas.
</div>
<div name="#2">
<div id="tab2_">
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend. Ut posuere vestibulum lorem quis iaculis.
Nullam luctus ipsum aliquam justo convallis egestas. Vivamus mattis nunc molestie nisi tincidunt gravida. Aliquam erat volutpat.
Donec a dolor vitae quam gravida pharetra euismod eget metus. Ut nisi quam, molestie vitae semper non, malesuada quis justo.
Quisque magna velit, eleifend hendrerit vestibulum non, dignissim sed felis.
</div>
<div name="#3">
<div id="tab3_">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies fermentum tempor.
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend. Ut posuere vestibulum lorem quis iaculis.
Nullam luctus ipsum aliquam justo convallis egestas. Vivamus mattis nunc molestie nisi tincidunt gravida. Aliquam erat volutpat.
Expand All @@ -79,22 +79,22 @@ <h2>Option: rounded</h2>
<h2>Option: fixed height</h2>
<div class="example-3">
<ul>
<li><a href="#1">Tab 1</a></li>
<li><a href="#2">Tab 2</a></li>
<li><a href="#3">Tab 3</a></li>
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<div name="#1">
<div id="tab1_">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies fermentum tempor.
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend.
Ut posuere vestibulum lorem quis iaculis. Nullam luctus ipsum aliquam justo convallis egestas.
</div>
<div name="#2">
<div id="tab2_">
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend. Ut posuere vestibulum lorem quis iaculis.
Nullam luctus ipsum aliquam justo convallis egestas. Vivamus mattis nunc molestie nisi tincidunt gravida. Aliquam erat volutpat.
Donec a dolor vitae quam gravida pharetra euismod eget metus. Ut nisi quam, molestie vitae semper non, malesuada quis justo.
Quisque magna velit, eleifend hendrerit vestibulum non, dignissim sed felis.
</div>
<div name="#3">
<div id="tab3_">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies fermentum tempor.
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend. Ut posuere vestibulum lorem quis iaculis.
Nullam luctus ipsum aliquam justo convallis egestas. Vivamus mattis nunc molestie nisi tincidunt gravida. Aliquam erat volutpat.
Expand All @@ -108,22 +108,22 @@ <h2>Option: fixed height</h2>
<h2>Option: borders</h2>
<div class="example-4">
<ul>
<li><a href="#1">Tab 1</a></li>
<li><a href="#2">Tab 2</a></li>
<li><a href="#3">Tab 3</a></li>
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<div name="#1">
<div id="tab1_">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies fermentum tempor.
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend.
Ut posuere vestibulum lorem quis iaculis. Nullam luctus ipsum aliquam justo convallis egestas.
</div>
<div name="#2">
<div id="tab2_">
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend. Ut posuere vestibulum lorem quis iaculis.
Nullam luctus ipsum aliquam justo convallis egestas. Vivamus mattis nunc molestie nisi tincidunt gravida. Aliquam erat volutpat.
Donec a dolor vitae quam gravida pharetra euismod eget metus. Ut nisi quam, molestie vitae semper non, malesuada quis justo.
Quisque magna velit, eleifend hendrerit vestibulum non, dignissim sed felis.
</div>
<div name="#3">
<div id="tab3_">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies fermentum tempor.
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend. Ut posuere vestibulum lorem quis iaculis.
Nullam luctus ipsum aliquam justo convallis egestas. Vivamus mattis nunc molestie nisi tincidunt gravida. Aliquam erat volutpat.
Expand All @@ -135,22 +135,22 @@ <h2>Option: borders</h2>
<h2>Option: boxed, fade in tab contents</h2>
<div class="example-5">
<ul>
<li><a href="#1">Tab 1</a></li>
<li><a href="#2">Tab 2</a></li>
<li><a href="#3">Tab 3</a></li>
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<div name="#1">
<div id="tab1_">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies fermentum tempor.
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend.
Ut posuere vestibulum lorem quis iaculis. Nullam luctus ipsum aliquam justo convallis egestas.
</div>
<div name="#2">
<div id="tab2_">
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend. Ut posuere vestibulum lorem quis iaculis.
Nullam luctus ipsum aliquam justo convallis egestas. Vivamus mattis nunc molestie nisi tincidunt gravida. Aliquam erat volutpat.
Donec a dolor vitae quam gravida pharetra euismod eget metus. Ut nisi quam, molestie vitae semper non, malesuada quis justo.
Quisque magna velit, eleifend hendrerit vestibulum non, dignissim sed felis.
</div>
<div name="#3">
<div id="tab3_">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies fermentum tempor.
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend. Ut posuere vestibulum lorem quis iaculis.
Nullam luctus ipsum aliquam justo convallis egestas. Vivamus mattis nunc molestie nisi tincidunt gravida. Aliquam erat volutpat.
Expand All @@ -162,22 +162,22 @@ <h2>Option: boxed, fade in tab contents</h2>
<h2>Option: rounded, fixed height, second tab selected</h2>
<div class="example-6">
<ul>
<li><a href="#1">Tab 1</a></li>
<li><a href="#2">Tab 2</a></li>
<li><a href="#3">Tab 3</a></li>
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>
<div name="#1">
<div id="tab1_">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies fermentum tempor.
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend.
Ut posuere vestibulum lorem quis iaculis. Nullam luctus ipsum aliquam justo convallis egestas.
</div>
<div name="#2">
<div id="tab2_">
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend. Ut posuere vestibulum lorem quis iaculis.
Nullam luctus ipsum aliquam justo convallis egestas. Vivamus mattis nunc molestie nisi tincidunt gravida. Aliquam erat volutpat.
Donec a dolor vitae quam gravida pharetra euismod eget metus. Ut nisi quam, molestie vitae semper non, malesuada quis justo.
Quisque magna velit, eleifend hendrerit vestibulum non, dignissim sed felis.
</div>
<div name="#3">
<div id="tab3_">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies fermentum tempor.
Maecenas rutrum augue vehicula nisi feugiat tempus. Aenean pretium fringilla eleifend. Ut posuere vestibulum lorem quis iaculis.
Nullam luctus ipsum aliquam justo convallis egestas. Vivamus mattis nunc molestie nisi tincidunt gravida. Aliquam erat volutpat.
Expand Down
2 changes: 1 addition & 1 deletion litetabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
.liteTabs a:hover { background: #999 }
.liteTabs a:focus { text-decoration: underline }
.liteTabs a.selected, .liteTabs a.selected:hover { background: white }
.liteTabs div { float: left; width: 100%; padding: 10px; background: white }
.liteTabs div { padding: 10px; background: white }
.liteTabs div.selected { position: static !important }

/*************************************** Rounded */
Expand Down
165 changes: 89 additions & 76 deletions litetabs.jquery.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,94 @@
/*************************************************
*
* project: liteTabs - Lightweight jQuery tabs plugin
* author: Nicola Hibbert
* url: http://nicolahibbert.com/lightweight-jquery-tab-plugin/
* demo: http://www.nicolahibbert.com/demo/liteTabs/
*
* Version: 1.0.0
* Copyright: (c) 2010-2011 Nicola Hibbert
* License: MIT
*
/*************************************************/
/**
* @preserve
*
* Project: liteTabs - Lightweight jQuery tabs plugin
* Author: Nicola Hibbert
* Url: http://nicolahibbert.com/lightweight-jquery-tab-plugin/
* Demo: http://www.nicolahibbert.com/demo/liteTabs/
*
* Version: 1.0.0
* Copyright: (c) 2010-2011 Nicola Hibbert
* License: MIT
*
*/
;(function($) {

$.fn.liteTabs = function(options) {

return this.each(function() {

var defaults = {
borders : false,
boxed : false,
fadeIn : false,
height : 'auto',
hideHash : true,
rounded : false,
selectedTab : 1,
width : 500
},

// merge defaults with options in new settings object
settings = $.extend({}, defaults, options),

// define key variables
$this = $(this),
$ul = $this.children('ul'),
$tab = $ul.find('a'),
$div = $('> div', $this);

// set liteTabs class for css & set optional overall width
$this.addClass('liteTabs').width(settings.width);

// option: set overall height
$div.css({
height : settings.height,
width : settings.width - (parseInt($div.css('padding-left')) + parseInt($div.css('padding-right'))),
position : 'absolute',
left : -9999
});

// on tab click...
$tab.click(function(e) {
var filterHash = $div.removeClass('selected').filter('[name=' + this.hash + ']');

// defaults: add selected class to tab
$tab.removeClass('selected').filter(this).addClass('selected');

// option: fade in divs
(settings.fadeIn) ? filterHash.hide().addClass('selected').fadeIn() : filterHash.addClass('selected');

// option: hide hash change
settings.hideHash && e.preventDefault();

});

// option: set selected tab
settings.selectedTab && $tab.eq(settings.selectedTab - 1).click();

// option: set rounded corners
settings.rounded && $this.addClass('rounded');

// option: set borders
settings.borders && $this.addClass('borders') && $div.width($div.width() - (parseInt($div.css('border-left-width')) + parseInt($div.css('border-right-width'))));

// option: set boxed
settings.boxed && $this.addClass('boxed');

});


return this.each(function() {

var defaults = {
borders: false,
boxed: false,
fadeIn: false,
height: 'auto',
hideHash: false,
rounded: false,
selectedTab: 1,
width: 'auto'
},
first_load = true,

// merge defaults with options in new settings object
settings = $.extend({}, defaults, options),

// define key variables
$this = $(this),
$ul = $this.children('ul'),
$tab = $ul.find('a'),
$div = $('> div', $this);

// set liteTabs class for css & set optional overall width
$this.addClass('liteTabs').width(settings.width);

// option: set overall height
$div.css({
height: settings.height,
width: settings.width - (parseInt($div.css('padding-left')) + parseInt($div.css('padding-right'))),
position: 'absolute',
left: -9999
});

// on tab click...
$tab.click(function(e) {
hash = this.hash;

// On first load, check URL fragments for valid hashs.
if (first_load && window.location.hash) {
if ($div.filter( window.location.hash + '_')) {
hash = window.location.hash;
}
}
first_load = false;
// The div's id has a trailing underscore to prevent
// the url fragment from scrolling the page.
var filterHash = $div.removeClass('selected').filter(hash + '_');

// defaults: add selected class to tab
$tab.removeClass('selected').filter('[href=' + hash + ']').addClass('selected');

// option: fade in divs
(settings.fadeIn) ? filterHash.hide().addClass('selected').fadeIn() : filterHash.addClass('selected');

// option: hide hash change
settings.hideHash && e.preventDefault();

});

// option: set selected tab
settings.selectedTab && $tab.eq(settings.selectedTab - 1).click();

// option: set rounded corners
settings.rounded && $this.addClass('rounded');

// option: set borders
settings.borders && $this.addClass('borders') && settings.width != 'auto' && $div.width($div.width() - (parseInt($div.css('border-left-width')) + parseInt($div.css('border-right-width'))));

// option: set boxed
settings.boxed && $this.addClass('boxed');

});

};

})(jQuery);
})(jQuery);