blib/lib/JQuery/Tabs.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 9 | 87 | 10.3 |
branch | 0 | 28 | 0.0 |
condition | 0 | 6 | 0.0 |
subroutine | 3 | 10 | 30.0 |
pod | 3 | 7 | 42.8 |
total | 15 | 138 | 10.8 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package JQuery::Tabs ; | ||||||
2 | |||||||
3 | our $VERSION = '1.00'; | ||||||
4 | |||||||
5 | 1 | 1 | 1488 | use warnings; | |||
1 | 2 | ||||||
1 | 34 | ||||||
6 | 1 | 1 | 5 | use strict; | |||
1 | 2 | ||||||
1 | 63 | ||||||
7 | 1 | 1 | 961 | use CGI::Util ; | |||
1 | 2554 | ||||||
1 | 1213 | ||||||
8 | |||||||
9 | sub new { | ||||||
10 | 0 | 0 | 1 | my $this = shift; | |||
11 | 0 | 0 | my $class = ref($this) || $this; | ||||
12 | 0 | my $my ; | |||||
13 | 0 | %{$my->{param}} = @_ ; | |||||
0 | |||||||
14 | |||||||
15 | 0 | 0 | $my->{param}{texts} = [] if ! defined $my->{param}{texts} ; | ||||
16 | 0 | 0 | $my->{param}{tabs} = [] if ! defined $my->{param}{tabs} ; | ||||
17 | 0 | 0 | $my->{param}{remote} = 0 if ! defined $my->{param}{remote} ; | ||||
18 | |||||||
19 | 0 | 0 | die "No id defined for Tabs" unless $my->{param}{id} =~ /\S/ ; | ||||
20 | |||||||
21 | 0 | bless $my, $class; | |||||
22 | 0 | 0 | if ($my->{param}{css}) { | ||||
23 | 0 | push @{$my->{css}},$my->{param}{css} ; | |||||
0 | |||||||
24 | } | ||||||
25 | 0 | my $jquery = $my->{param}{addToJQuery} ; | |||||
26 | 0 | 0 | $my->{param}{history} = 0 unless defined $my->{param}{history} ; | ||||
27 | 0 | my $jqueryDir = $jquery->getJQueryDir ; | |||||
28 | 0 | $my->{fileDir} = "$jqueryDir/plugins" ; | |||||
29 | |||||||
30 | 0 | $my->add_to_jquery ; | |||||
31 | 0 | return $my ; | |||||
32 | } | ||||||
33 | |||||||
34 | sub add_to_jquery { | ||||||
35 | 0 | 0 | 0 | my $my = shift ; | |||
36 | 0 | my $jquery = $my->{param}{addToJQuery} ; | |||||
37 | 0 | 0 | if (defined $jquery) { | ||||
38 | 0 | $jquery->add($my) ; | |||||
39 | } | ||||||
40 | } | ||||||
41 | |||||||
42 | sub id { | ||||||
43 | 0 | 0 | 1 | my $my = shift ; | |||
44 | 0 | return $my->{param}{id} ; | |||||
45 | } | ||||||
46 | |||||||
47 | |||||||
48 | sub packages_needed { | ||||||
49 | 0 | 0 | 0 | my $my = shift ; | |||
50 | 0 | my @packages = ('tabs/jquery.tabs.js') ; | |||||
51 | 0 | 0 | push @packages,'history_remote/jquery.history_remote.js' if $my->{param}{history} ; | ||||
52 | 0 | return @packages ; | |||||
53 | } | ||||||
54 | |||||||
55 | sub get_css { | ||||||
56 | 0 | 0 | 0 | my $my = shift ; | |||
57 | |||||||
58 | 0 | my $id = $my->id ; | |||||
59 | |||||||
60 | 0 | my $cssFile1 = "$my->{fileDir}/tabs/tabs.css" ; | |||||
61 | 0 | my $cssFile2 = '' ; | |||||
62 | # There is apparently a problem with IE 6.0 | ||||||
63 | 0 | 0 | 0 | if (defined $ENV{HTTP_USER_AGENT} and $ENV{HTTP_USER_AGENT} =~ /MSIE\s*6/) { | |||
64 | 0 | $cssFile2 = "$my->{fileDir}/tabs/tabs_ie.css" ; | |||||
65 | } | ||||||
66 | 0 | my $css1 = new JQuery::CSS(file => $cssFile1) ; | |||||
67 | 0 | my $css2 = '' ; | |||||
68 | 0 | 0 | $css2 = new JQuery::CSS(file => $cssFile2) unless $cssFile2 eq '' ; | ||||
69 | |||||||
70 | 0 | my $css3Text =<<'EOD'; | |||||
71 | .tabs-loading span { | ||||||
72 | padding: 0 0 0 20px; | ||||||
73 | background: url(PLUGIN_DIR/tabs/loading.gif) no-repeat 0 50%; | ||||||
74 | } | ||||||
75 | EOD | ||||||
76 | |||||||
77 | 0 | $css3Text =~ s!PLUGIN_DIR!$my->{fileDir}!g ; | |||||
78 | |||||||
79 | 0 | my $css3 = new JQuery::CSS(text => $css3Text) ; | |||||
80 | 0 | 0 | if (!$my->{param}{spinner}) { | ||||
81 | 0 | $css3 = '' ; | |||||
82 | } | ||||||
83 | |||||||
84 | 0 | return [$css1,$css2,$css3] ; | |||||
85 | } | ||||||
86 | |||||||
87 | sub HTML { | ||||||
88 | 0 | 0 | 1 | my $my = shift ; | |||
89 | 0 | my $id = $my->id ; | |||||
90 | 0 | my @tabs = @{$my->{param}{tabs}} ; | |||||
0 | |||||||
91 | 0 | my @texts = @{$my->{param}{texts}} ; | |||||
0 | |||||||
92 | 0 | my $n = 0 ; | |||||
93 | 0 | my $html = qq[ \n
|
|||||
94 | 0 | my $headerId = $n ; | |||||
95 | 0 | for my $h (@tabs) { | |||||
96 | 0 | $n ++ ; | |||||
97 | 0 | my $href = qq[] ; | |||||
98 | 0 | my $tabLabel = CGI::Util::escape($h) ; | |||||
99 | 0 | 0 | $href = qq[] if $my->{param}{remote} ; | ||||
100 | 0 | $html .= qq[ |
|||||
101 | } | ||||||
102 | 0 | $html .= "\n" ; | |||||
103 | 0 | $n = 0 ; | |||||
104 | 0 | for my $text (@texts) { | |||||
105 | 0 | $n ++ ; | |||||
106 | 0 | $html .= qq[ \n$text\n \n] ; |
|||||
107 | } | ||||||
108 | 0 | $html .= "\n" ; | |||||
109 | 0 | return $html ; | |||||
110 | } | ||||||
111 | |||||||
112 | sub get_jquery_code { | ||||||
113 | 0 | 0 | 0 | my $my = shift ; | |||
114 | 0 | my $id = $my->id ; | |||||
115 | 0 | my $remoteProgram = $my->{param}{remoteProgram} ; | |||||
116 | 0 | 0 | return '' unless $id =~ /\S/ ; | ||||
117 | |||||||
118 | 0 | my $function =<<'EOD'; | |||||
119 | |||||||
120 | $('#ID').tabs({PARAMS}); | ||||||
121 | EOD | ||||||
122 | 0 | $function =~ s/ID/$id/g ; | |||||
123 | 0 | my @params = () ; | |||||
124 | 0 | for (qw[remote defaultTab fxFade fxSpeed fxAutoHeight bookmarkable navClass selectedClass disabledClass containerClass loadingClass]) { | |||||
125 | 0 | 0 | push @params, "$_: $my->{param}{$_}" if defined $my->{param}{$_} ; | ||||
126 | } | ||||||
127 | |||||||
128 | 0 | my $params = join(',',@params) ; | |||||
129 | 0 | $function =~ s/PARAMS/$params/ ; | |||||
130 | |||||||
131 | 0 | return $function ; | |||||
132 | } | ||||||
133 | |||||||
134 | |||||||
135 | =head1 NAME | ||||||
136 | |||||||
137 | JQuery::Tabs - Have tabs to see different pages | ||||||
138 | |||||||
139 | =head1 SYNOPSIS | ||||||
140 | |||||||
141 | my @tabs = ("tab 1","tab 2","tab 3","tab 4") ; | ||||||
142 | my @texts = ("line 1","line 2","line 3","line4") ; | ||||||
143 | |||||||
144 | my $tab = JQuery::Tabs->new(id => 'myTab', | ||||||
145 | tabs => \@tabs, | ||||||
146 | texts => \@texts, | ||||||
147 | addToJQuery => $jquery, | ||||||
148 | ) ; | ||||||
149 | |||||||
150 | my $tab = JQuery::Tabs->new(id => 'myTab', | ||||||
151 | tabs => \@tabs, | ||||||
152 | remote => 'true', # no texts needed if remote | ||||||
153 | remoteProgram => '/cgi-bin/jquery_tabs_results.pl', | ||||||
154 | rm => 'myMode', | ||||||
155 | addToJQuery => $jquery, | ||||||
156 | spinner => 1, | ||||||
157 | ) ; | ||||||
158 | my $html = $tab->HTML ; | ||||||
159 | |||||||
160 | =head1 DESCRIPTION | ||||||
161 | |||||||
162 | Allow the user to see different pages using tabs. For an example of | ||||||
163 | how it looks, see L |
||||||
164 | |||||||
165 | This module sets up tabs for different pages. The HTML can be supplied | ||||||
166 | directly, or the page can be updated remotely. When used remotely, the | ||||||
167 | program returns the run mode parameter, rm, as well as the parameter | ||||||
168 | tab, which contains the text in the tab header. | ||||||
169 | |||||||
170 | In remote mode, taconite is not used to refresh the page. All that is | ||||||
171 | expected is a normal html. If you are using CGI, something like this | ||||||
172 | is expected: | ||||||
173 | |||||||
174 | use CGI ; | ||||||
175 | my $q = new CGI ; | ||||||
176 | print $q->header(-type=>'text/html'); | ||||||
177 | print $env ; | ||||||
178 | |||||||
179 | =head1 FUNCTIONS | ||||||
180 | |||||||
181 | =over | ||||||
182 | |||||||
183 | =item new | ||||||
184 | |||||||
185 | Instantiate the object | ||||||
186 | |||||||
187 | =item HTML | ||||||
188 | |||||||
189 | Get the HTML for the object | ||||||
190 | |||||||
191 | =back | ||||||
192 | |||||||
193 | =head2 Parameters | ||||||
194 | |||||||
195 | =over 4 | ||||||
196 | |||||||
197 | =item id | ||||||
198 | |||||||
199 | This is the id of the tab | ||||||
200 | |||||||
201 | =item addToJQuery | ||||||
202 | |||||||
203 | The JQuery object to be added to. | ||||||
204 | |||||||
205 | =item tabs | ||||||
206 | |||||||
207 | This is a list of tab names for the headers | ||||||
208 | |||||||
209 | =item texts | ||||||
210 | |||||||
211 | This is a list of HTML texts needed for each tab. If the page is going | ||||||
212 | to be updated remotely, this is not needed. | ||||||
213 | |||||||
214 | =item rm | ||||||
215 | |||||||
216 | The run mode that will be returned to the server. | ||||||
217 | |||||||
218 | =item spinner | ||||||
219 | |||||||
220 | When updated remotely, this add a little spinning wheel to the tab to | ||||||
221 | show that it is being updated. | ||||||
222 | |||||||
223 | =item bookmarkable | ||||||
224 | |||||||
225 | Allow the back button in the browser to give the expected results. | ||||||
226 | |||||||
227 | =back | ||||||
228 | |||||||
229 | =head1 AUTHOR | ||||||
230 | |||||||
231 | Peter Gordon, C<< |
||||||
232 | |||||||
233 | =head1 BUGS | ||||||
234 | |||||||
235 | Please report any bugs or feature requests to | ||||||
236 | C |
||||||
237 | L |
||||||
238 | I will be notified, and then you'll automatically be notified of progress on | ||||||
239 | your bug as I make changes. | ||||||
240 | |||||||
241 | =head1 SUPPORT | ||||||
242 | |||||||
243 | You can find documentation for this module with the perldoc command. | ||||||
244 | |||||||
245 | perldoc JQuery | ||||||
246 | |||||||
247 | You can also look for information at: | ||||||
248 | |||||||
249 | =over 4 | ||||||
250 | |||||||
251 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||
252 | |||||||
253 | L |
||||||
254 | |||||||
255 | =item * CPAN Ratings | ||||||
256 | |||||||
257 | L |
||||||
258 | |||||||
259 | =item * RT: CPAN's request tracker | ||||||
260 | |||||||
261 | L |
||||||
262 | |||||||
263 | =item * Search CPAN | ||||||
264 | |||||||
265 | L |
||||||
266 | |||||||
267 | =back | ||||||
268 | |||||||
269 | =head1 ACKNOWLEDGEMENTS | ||||||
270 | |||||||
271 | =head1 COPYRIGHT & LICENSE | ||||||
272 | |||||||
273 | Copyright 2007 Peter Gordon, all rights reserved. | ||||||
274 | |||||||
275 | This program is free software; you can redistribute it and/or modify it | ||||||
276 | under the same terms as Perl itself. | ||||||
277 | |||||||
278 | =cut | ||||||
279 | |||||||
280 | 1; # End of JQuery::Tabs | ||||||
281 | |||||||
282 |