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 | |
---|
14 | this.params = jQuery.extend(defaults,settings); |
---|
15 | this.divs = jQuery('div.'+this.params.className); |
---|
16 | this.createList(); |
---|
17 | this.showDiv(index); |
---|
18 | }; |
---|
19 | |
---|
20 | jQuery._pageTabs.prototype = { |
---|
21 | items: new Array(), |
---|
22 | |
---|
23 | createList: function() { |
---|
24 | if (this.divs.length <= 0) { |
---|
25 | return; |
---|
26 | } |
---|
27 | |
---|
28 | this.block = document.createElement('div'); |
---|
29 | this.block.className = this.params.listClassName; |
---|
30 | this.list = document.createElement('ul'); |
---|
31 | //this.list.className = this.params.listClassName; |
---|
32 | this.block.appendChild(this.list); |
---|
33 | var li, a; |
---|
34 | |
---|
35 | var This = this; |
---|
36 | var i=0; |
---|
37 | jQuery('.'+this.params.className).each(function() { |
---|
38 | if (this.tagName == "DIV") { |
---|
39 | li = document.createElement('li'); |
---|
40 | a = document.createElement('a'); |
---|
41 | a.appendChild(document.createTextNode(this.title)); |
---|
42 | this.title = ''; |
---|
43 | a.href = '#'; |
---|
44 | a.fn = This.showDiv; |
---|
45 | a.index = this.id || i; |
---|
46 | a.obj = This; |
---|
47 | jQuery(a).click(function() { this.fn.call(this.obj,this.index); return false; }); |
---|
48 | li.appendChild(a); |
---|
49 | This.list.appendChild(li); |
---|
50 | This.items[i] = li; |
---|
51 | i++; |
---|
52 | } else { |
---|
53 | li = document.createElement('li'); |
---|
54 | li.className = This.params.listClassName+'-link'; |
---|
55 | li.appendChild(this); |
---|
56 | This.list.appendChild(li); |
---|
57 | } |
---|
58 | }); |
---|
59 | |
---|
60 | this.breaker = document.createElement('br'); |
---|
61 | this.breaker.className = this.params.breakerClassName; |
---|
62 | |
---|
63 | jQuery(this.divs.get(0)).before(this.block); |
---|
64 | jQuery(this.block).after(this.breaker); |
---|
65 | }, |
---|
66 | |
---|
67 | showDiv: function(index) { |
---|
68 | var This = this; |
---|
69 | var i = 0; |
---|
70 | var to_trigger = null; |
---|
71 | |
---|
72 | this.divs.each(function() { |
---|
73 | if ((this.id != '' && this.id == index) || i == index) { |
---|
74 | jQuery(this).show(0, positionFooter); |
---|
75 | This.items[i].className = This.params.listClassName+'-active'; |
---|
76 | to_trigger = i; |
---|
77 | } else { |
---|
78 | jQuery(this).hide(0, positionFooter); |
---|
79 | This.items[i].className = ''; |
---|
80 | } |
---|
81 | |
---|
82 | i++; |
---|
83 | }); |
---|
84 | |
---|
85 | if (to_trigger != null) { |
---|
86 | jQuery(this.divs[to_trigger]).onetabload(); |
---|
87 | jQuery(this.divs[to_trigger]).tabload(); |
---|
88 | } |
---|
89 | } |
---|
90 | }; |
---|
91 | |
---|
92 | jQuery.fn.tabload = function(f) { |
---|
93 | this.each(function() { |
---|
94 | if (f) { |
---|
95 | chainHandler(this,'tabload',f) |
---|
96 | } else { |
---|
97 | var h = this.tabload; |
---|
98 | if (h) { h.apply(this); } |
---|
99 | } |
---|
100 | }); |
---|
101 | return this; |
---|
102 | }; |
---|
103 | jQuery.fn.onetabload = function(f) { |
---|
104 | this.each(function() { |
---|
105 | if (f) { |
---|
106 | chainHandler(this,'onetabload',f); |
---|
107 | } else { |
---|
108 | var h = this.onetabload; |
---|
109 | if (h != null) { |
---|
110 | h.apply(this); |
---|
111 | this.onetabload = null; |
---|
112 | } |
---|
113 | } |
---|
114 | }); |
---|
115 | return this; |
---|
116 | }; |
---|