1 | jQuery.pageTabs = function(start_tab,settings) { |
---|
2 | return new jQuery._pageTabs(start_tab,settings); |
---|
3 | }; |
---|
4 | |
---|
5 | jQuery._pageTabs = function(start_tab,settings) { |
---|
6 | var defaults = { |
---|
7 | className: 'multi-part', |
---|
8 | listClassName: 'part-tabs', |
---|
9 | breakerClassName: 'clear' |
---|
10 | }; |
---|
11 | |
---|
12 | var index = start_tab ? start_tab : 0; |
---|
13 | var hash = document.location.hash.split('#').join(''); |
---|
14 | if( hash != '' ) { |
---|
15 | var index = hash; |
---|
16 | } |
---|
17 | |
---|
18 | this.params = jQuery.extend(defaults,settings); |
---|
19 | this.divs = jQuery('div.'+this.params.className); |
---|
20 | this.createList(); |
---|
21 | this.showDiv(index); |
---|
22 | var pageTabs = this; |
---|
23 | |
---|
24 | window.onhashchange = function (event) { |
---|
25 | pageTabs.showDiv(document.location.hash.split('#').join('')); |
---|
26 | } |
---|
27 | }; |
---|
28 | |
---|
29 | jQuery._pageTabs.prototype = { |
---|
30 | items: new Array(), |
---|
31 | |
---|
32 | createList: function() { |
---|
33 | if (this.divs.length <= 0) { |
---|
34 | return; |
---|
35 | } |
---|
36 | |
---|
37 | this.block = document.createElement('div'); |
---|
38 | this.block.className = this.params.listClassName; |
---|
39 | this.list = document.createElement('ul'); |
---|
40 | //this.list.className = this.params.listClassName; |
---|
41 | this.block.appendChild(this.list); |
---|
42 | var li, a; |
---|
43 | |
---|
44 | var This = this; |
---|
45 | var i=0; |
---|
46 | jQuery('.'+this.params.className).each(function() { |
---|
47 | if (this.tagName == "DIV") { |
---|
48 | li = document.createElement('li'); |
---|
49 | a = document.createElement('a'); |
---|
50 | $(a).html(this.title); |
---|
51 | this.title = ''; |
---|
52 | a.fn = This.showDiv; |
---|
53 | a.index = this.id || i; |
---|
54 | a.href = '#'+a.index; |
---|
55 | li.id = "part-tabs-"+a.index; |
---|
56 | a.obj = This; |
---|
57 | li.appendChild(a); |
---|
58 | This.list.appendChild(li); |
---|
59 | This.items[i] = li; |
---|
60 | i++; |
---|
61 | } else { |
---|
62 | li = document.createElement('li'); |
---|
63 | li.className = This.params.listClassName+'-link'; |
---|
64 | li.appendChild(this); |
---|
65 | This.list.appendChild(li); |
---|
66 | } |
---|
67 | }); |
---|
68 | |
---|
69 | this.breaker = document.createElement('br'); |
---|
70 | this.breaker.className = this.params.breakerClassName; |
---|
71 | |
---|
72 | jQuery(this.divs.get(0)).before(this.block); |
---|
73 | jQuery(this.block).after(this.breaker); |
---|
74 | }, |
---|
75 | |
---|
76 | showDiv: function(index) { |
---|
77 | var This = this; |
---|
78 | var i = 0; |
---|
79 | var to_trigger = null; |
---|
80 | var exists = false; |
---|
81 | |
---|
82 | this.divs.each(function() { |
---|
83 | if ((this.id != '' && this.id == index) || i == index) { |
---|
84 | exists = true; |
---|
85 | } |
---|
86 | i++; |
---|
87 | }); |
---|
88 | |
---|
89 | i = 0; |
---|
90 | |
---|
91 | if( exists ) { |
---|
92 | this.divs.each(function() { |
---|
93 | if ((this.id != '' && this.id == index) || i == index) { |
---|
94 | jQuery(this).show(0); |
---|
95 | This.items[i].className = This.params.listClassName+'-active'; |
---|
96 | to_trigger = i; |
---|
97 | } else { |
---|
98 | jQuery(this).hide(0); |
---|
99 | This.items[i].className = ''; |
---|
100 | } |
---|
101 | |
---|
102 | i++; |
---|
103 | }); |
---|
104 | } |
---|
105 | |
---|
106 | if (to_trigger != null) { |
---|
107 | jQuery(this.divs[to_trigger]).onetabload(); |
---|
108 | jQuery(this.divs[to_trigger]).tabload(); |
---|
109 | } |
---|
110 | } |
---|
111 | }; |
---|
112 | |
---|
113 | jQuery.fn.tabload = function(f) { |
---|
114 | this.each(function() { |
---|
115 | if (f) { |
---|
116 | chainHandler(this,'tabload',f) |
---|
117 | } else { |
---|
118 | var h = this.tabload; |
---|
119 | if (h) { h.apply(this); } |
---|
120 | } |
---|
121 | }); |
---|
122 | return this; |
---|
123 | }; |
---|
124 | jQuery.fn.onetabload = function(f) { |
---|
125 | this.each(function() { |
---|
126 | if (f) { |
---|
127 | chainHandler(this,'onetabload',f); |
---|
128 | } else { |
---|
129 | var h = this.onetabload; |
---|
130 | if (h != null) { |
---|
131 | h.apply(this); |
---|
132 | this.onetabload = null; |
---|
133 | } |
---|
134 | } |
---|
135 | }); |
---|
136 | return this; |
---|
137 | }; |
---|