-
Notifications
You must be signed in to change notification settings - Fork 6
/
jquery.tabs.js
38 lines (28 loc) · 1014 Bytes
/
jquery.tabs.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
(function($){
$.fn.tabs = function() {
this.each(function() {
var el = $(this);
var current;
el.addClass('enhance');
var dlHeight = el.height();
el.find('dd').hide();
var hash = location.hash;
if (el.find('dt a[href="'+hash+'"]').length) {
current = el.find('a[href="'+hash+'"]').parent().addClass('current');
} else {
current = el.find('dt:first').addClass('current');
}
var currentHeight = current.next('dd').show().height();
el.css('height', dlHeight + currentHeight);
});
$('dl.enhance dt a').click(function(e){
e.preventDefault();
$(this).parents('dl').find('.current').removeClass('current').next('dd').hide();
var current = $(this).parent('dt').addClass('current');
var currentHeight = current.next('dd').show().height();
var dlHeight = $(this).parents('dl').removeAttr('style').height();
$(this).parents('dl').css('height', dlHeight + currentHeight);
location.hash = $(this).attr('href');
});
}
})(jQuery);