-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.tabify.source.js
72 lines (58 loc) · 1.58 KB
/
jquery.tabify.source.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
/**
* @name Tabify
* @descripton Tabbed content with ease
* @version 1.4
* @requires Jquery 1.3.2
*
* @author Jan Jarfalk
* @author-email jan.jarfalk@unwrongest.com
* @author-twitter janjarfalk
* @author-website http://www.unwrongest.com
*
* @licens MIT License - http://www.opensource.org/licenses/mit-license.php
*/
(function($){
$.fn.extend({
tabify: function( callback ) {
function getHref(el){
hash = $(el).find('a').attr('href');
hash = hash.substring(0,hash.length-4);
return hash;
}
function setActive(el){
$(el).addClass('active');
$(getHref(el)).show();
$(el).siblings('li').each(function(){
$(this).removeClass('active');
$(getHref(this)).hide();
});
}
return this.each(function() {
var self = this;
var callbackArguments = {'ul':$(self)};
$(this).find('li a').each(function(){
$(this).attr('href',$(this).attr('href') + '-tab');
});
function handleHash(){
if(location.hash && $(self).find('a[href=' + location.hash + ']').length > 0){
setActive($(self).find('a[href=' + location.hash + ']').parent());
}
}
if(location.hash){
handleHash();
}
setInterval(handleHash,100);
$(this).find('li').each(function(){
if($(this).hasClass('active')){
$(getHref(this)).show();
} else {
$(getHref(this)).hide();
}
});
if(callback){
callback(callbackArguments);
}
});
}
});
})(jQuery);