-
Notifications
You must be signed in to change notification settings - Fork 9
/
litetabs.jquery.js
81 lines (62 loc) · 2.3 KB
/
litetabs.jquery.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*************************************************
*
* 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');
});
};
})(jQuery);