blib/lib/JQuery/Splitter.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 6 | 111 | 5.4 |
branch | 0 | 30 | 0.0 |
condition | 0 | 18 | 0.0 |
subroutine | 2 | 28 | 7.1 |
pod | 20 | 26 | 76.9 |
total | 28 | 213 | 13.1 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package JQuery::Splitter ; | ||||||
2 | |||||||
3 | our $VERSION = '1.00'; | ||||||
4 | |||||||
5 | 1 | 1 | 1261 | use warnings; | |||
1 | 2 | ||||||
1 | 28 | ||||||
6 | 1 | 1 | 6 | use strict; | |||
1 | 1 | ||||||
1 | 1786 | ||||||
7 | |||||||
8 | sub new { | ||||||
9 | 0 | 0 | 1 | my $this = shift; | |||
10 | 0 | 0 | my $class = ref($this) || $this; | ||||
11 | 0 | my $my ; | |||||
12 | 0 | %{$my->{param}} = @_ ; | |||||
0 | |||||||
13 | 0 | 0 | die "No id defined for Splitter" unless $my->{param}{id} =~ /\S/ ; | ||||
14 | 0 | my $jquery = $my->{param}{addToJQuery} ; | |||||
15 | 0 | my $jqueryDir = $jquery->getJQueryDir ; | |||||
16 | 0 | $my->{fileDir} = "$jqueryDir/plugins/splitter" ; | |||||
17 | 0 | bless $my, $class; | |||||
18 | 0 | $my->add_to_jquery ; | |||||
19 | 0 | return $my ; | |||||
20 | } | ||||||
21 | |||||||
22 | sub add_to_jquery { | ||||||
23 | 0 | 0 | 0 | my $my = shift ; | |||
24 | 0 | my $jquery = $my->{param}{addToJQuery} ; | |||||
25 | 0 | 0 | if (defined $jquery) { | ||||
26 | 0 | $jquery->add($my) ; | |||||
27 | } | ||||||
28 | } | ||||||
29 | |||||||
30 | sub id { | ||||||
31 | 0 | 0 | 0 | my $my = shift ; | |||
32 | 0 | return $my->{param}{id} ; | |||||
33 | } | ||||||
34 | |||||||
35 | |||||||
36 | sub packages_needed { | ||||||
37 | 0 | 0 | 0 | my $my = shift ; | |||
38 | 0 | return ('dimensions/dimensions.js','splitter/splitter.js') ; | |||||
39 | } | ||||||
40 | |||||||
41 | 0 | 0 | 1 | sub panel1 { shift->{param}{panel1} } | |||
42 | 0 | 0 | 1 | sub panel2 { shift->{param}{panel2} ; } | |||
43 | 0 | 0 | 1 | sub panel1CSS { shift->{param}{panel1CSS} } | |||
44 | 0 | 0 | 1 | sub panel2CSS { shift->{param}{panel2CSS} ; } | |||
45 | 0 | 0 | 1 | sub HTML1 { shift->{param}{HTML1} ; } | |||
46 | 0 | 0 | 1 | sub HTML2 { shift->{param}{HTML2} ; } | |||
47 | 0 | 0 | 1 | sub splitBackGround { shift->{param}{splitBackGround} ; } | |||
48 | 0 | 0 | 1 | sub splitHeight { shift->{param}{splitHeight} ; } | |||
49 | 0 | 0 | 1 | sub splitActive { shift->{param}{splitActive} ; } | |||
50 | 0 | 0 | 0 | sub splitRepeat { shift->{param}{splitRepeat} ; } | |||
51 | 0 | 0 | 1 | sub mainPanelCSS { shift->{param}{mainPanelCSS} ; } | |||
52 | 0 | 0 | 1 | sub accessKey { shift->{param}{accessKey} ; } | |||
53 | 0 | 0 | 1 | sub browserFill { shift->{param}{browserFill} ; } | |||
54 | 0 | 0 | 1 | sub type { shift->{param}{type} } | |||
55 | 0 | 0 | 1 | sub panel1Params { shift->{param}{panel1Params} } | |||
56 | 0 | 0 | 1 | sub panel2Params { shift->{param}{panel2Params} } | |||
57 | 0 | 0 | 1 | sub internalPanel { shift->{param}{internalPanel} } | |||
58 | |||||||
59 | sub setHTML1 { | ||||||
60 | 0 | 0 | 1 | my $my = shift ; | |||
61 | 0 | $my->{param}{HTML1} = shift ; | |||||
62 | } | ||||||
63 | |||||||
64 | sub setHTML2 { | ||||||
65 | 0 | 0 | 1 | my $my = shift ; | |||
66 | 0 | $my->{param}{HTML2} = shift ; | |||||
67 | } | ||||||
68 | |||||||
69 | sub HTML { | ||||||
70 | 0 | 0 | 1 | my $my = shift ; | |||
71 | 0 | my $id = $my->id ; | |||||
72 | 0 | my $panel1 = $my->panel1 ; | |||||
73 | 0 | my $panel2 = $my->panel2 ; | |||||
74 | 0 | my $HTML1 = $my->HTML1 ; | |||||
75 | 0 | my $HTML2 = $my->HTML2 ; | |||||
76 | |||||||
77 | 0 | my $html ; | |||||
78 | 0 | 0 | if ($my->internalPanel) { | ||||
79 | 0 | $html = qq[ $HTML1 |
|||||
80 | $HTML2 |
||||||
81 | ] ; | ||||||
82 | } | ||||||
83 | 0 | 0 | if (!$my->internalPanel) { | ||||
84 | 0 | $html = qq[ |
|||||
85 | $HTML1 |
||||||
86 | $HTML2 |
||||||
87 | ] ; | ||||||
88 | } | ||||||
89 | 0 | return $html ; | |||||
90 | } | ||||||
91 | |||||||
92 | sub get_css { | ||||||
93 | 0 | 0 | 0 | my $my = shift ; | |||
94 | 0 | my $id = $my->id ; | |||||
95 | 0 | 0 | my $splitBackGround = $my->splitBackGround || 'gray'; | ||||
96 | 0 | 0 | my $splitHeight = $my->splitHeight || '6px' ; | ||||
97 | 0 | 0 | my $splitActive = $my->splitActive || 'blue' ; | ||||
98 | 0 | my $panel1 = $my->panel1 ; | |||||
99 | 0 | my $panel2 = $my->panel2 ; | |||||
100 | 0 | my $repeat = $my->splitRepeat ; | |||||
101 | 0 | my $repeatX = 'no-repeat' ; | |||||
102 | 0 | my $repeatY = 'no-repeat' ; | |||||
103 | 0 | 0 | if ($repeat) { | ||||
104 | 0 | $repeatX = "repeat-x" ; | |||||
105 | 0 | $repeatY = "repeat-y" ; | |||||
106 | } | ||||||
107 | |||||||
108 | |||||||
109 | 0 | my $headBodyMargins = '' ; | |||||
110 | |||||||
111 | 0 | my $scrollBarsHidden =< | |||||
112 | html, body | ||||||
113 | { | ||||||
114 | overflow: hidden; /* Remove scroll bars on browser window */ | ||||||
115 | } | ||||||
116 | EOD | ||||||
117 | |||||||
118 | 0 | 0 | if ($my->browserFill) { | ||||
119 | 0 | $headBodyMargins =< | |||||
120 | html, body | ||||||
121 | { | ||||||
122 | margin: 0; /* Remove body margin/padding */ | ||||||
123 | padding: 0; | ||||||
124 | overflow: hidden; /* Remove scroll bars on browser window */ | ||||||
125 | } | ||||||
126 | EOD | ||||||
127 | } | ||||||
128 | |||||||
129 | 0 | my $bars1=< | |||||
130 | #$id .vsplitbar { | ||||||
131 | width: $splitHeight; | ||||||
132 | background: $splitBackGround url(PLUGINS_DIR/vgrabber.gif) $repeatY center; | ||||||
133 | } | ||||||
134 | #$id .vsplitbar.active, #$id .vsplitbar:hover { | ||||||
135 | background: $splitActive url(PLUGINS_DIR/vgrabber.gif) $repeatY center; | ||||||
136 | } | ||||||
137 | #$id .hsplitbar { | ||||||
138 | height: $splitHeight; | ||||||
139 | background: $splitBackGround url( PLUGINS_DIR/hgrabber.gif) $repeatX center; | ||||||
140 | } | ||||||
141 | #$id .hsplitbar.active, #$id .hsplitbar:hover { | ||||||
142 | background: $splitActive url(PLUGINS_DIR/hgrabber.gif) $repeatX center; | ||||||
143 | } | ||||||
144 | EOD | ||||||
145 | |||||||
146 | |||||||
147 | 0 | my $bars2=< | |||||
148 | #$panel1 { /* Top nested in right pane */ | ||||||
149 | overflow: auto; | ||||||
150 | } | ||||||
151 | #$panel2 { | ||||||
152 | overflow: auto; /* Scroll bars appear as needed */ | ||||||
153 | } | ||||||
154 | $headBodyMargins | ||||||
155 | EOD | ||||||
156 | 0 | my $bars = $bars2 ; | |||||
157 | 0 | 0 | if (!$my->internalPanel) { | ||||
158 | 0 | $bars = "$bars1$bars2" ; | |||||
159 | } | ||||||
160 | 0 | $bars =~ s!PLUGINS_DIR!$my->{fileDir}!g ; | |||||
161 | 0 | my @css = ($bars,$my->mainPanelCSS,$my->panel1CSS,$my->panel2CSS); | |||||
162 | 0 | return \@css ; | |||||
163 | } | ||||||
164 | |||||||
165 | |||||||
166 | sub get_jquery_code { | ||||||
167 | 0 | 0 | 0 | my $my = shift ; | |||
168 | 0 | my $id = $my->id ; | |||||
169 | 0 | my $type = $my->type ; | |||||
170 | 0 | my $accessKey = $my->accessKey ; | |||||
171 | 0 | my $panel1 = $my->panel1 ; | |||||
172 | 0 | my $panel2 = $my->panel2 ; | |||||
173 | 0 | my $panel1Params = $my->panel1Params ; | |||||
174 | 0 | my $panel2Params = $my->panel2Params ; | |||||
175 | |||||||
176 | 0 | $type = qq[type: "$type"] ; | |||||
177 | 0 | 0 | my $minA = $panel1Params->{minA} =~ /\S/ ? qq[minA: $panel1Params->{minA}] : '' ; | ||||
178 | 0 | 0 | my $initA = $panel1Params->{initA} =~ /\S/ ? qq[initA: $panel1Params->{initA}] : '' ; | ||||
179 | 0 | 0 | my $maxA = $panel1Params->{maxA} =~ /\S/ ? qq[maxA: $panel1Params->{maxA}] : '' ; | ||||
180 | |||||||
181 | 0 | 0 | 0 | my $minB = (defined($panel2Params->{minB}) and $panel2Params->{minB} =~ /\S/) ? qq[minB: $panel2Params->{minB}] : '' ; | |||
182 | 0 | 0 | 0 | my $initB = (defined $panel2Params->{initB} and $panel2Params->{initB} =~ /\S/) ? qq[initB: $panel2Params->{initB}] : '' ; | |||
183 | 0 | 0 | 0 | my $maxB = (defined $panel2Params->{maxB} and $panel2Params->{maxB} =~ /\S/) ? qq[maxB: $panel2Params->{maxB}] : '' ; | |||
184 | 0 | 0 | $accessKey = $my->accessKey =~ /\S/ ? qq[accessKey: "$accessKey"] : '' ; | ||||
185 | 0 | my @items = ($type,$minA,$initA,$maxA,$minB,$initB,$maxB,$accessKey) ; | |||||
186 | 0 | @items = grep { /\S/ } @items ; | |||||
0 | |||||||
187 | |||||||
188 | 0 | my $params = join(', ',@items) ; | |||||
189 | |||||||
190 | 0 | my $function1=<<'EOD'; | |||||
191 | $("#ID").splitter({PARAMS}); | ||||||
192 | EOD | ||||||
193 | 0 | $function1 =~ s/ID/$id/ ; | |||||
194 | 0 | $function1 =~ s/PARAMS/$params/ ; | |||||
195 | |||||||
196 | =pod | ||||||
197 | |||||||
198 | $("#ID").splitter({ | ||||||
199 | type: "v", | ||||||
200 | minA: 100, initA: 150, maxA: 300, | ||||||
201 | accessKey: "|" | ||||||
202 | }) | ||||||
203 | |||||||
204 | =cut | ||||||
205 | |||||||
206 | 0 | my $function2=<<'EOD'; | |||||
207 | |||||||
208 | // Manually set the outer splitter's height to fill the browser window. | ||||||
209 | // This must be re-done any time the browser window is resized. | ||||||
210 | $(window).bind("resize", function(){ | ||||||
211 | var $ms = $("#ID"); | ||||||
212 | var top = $ms.offset().top; // from dimensions.js | ||||||
213 | var wh = $(window).height(); | ||||||
214 | // Account for margin or border on the splitter container | ||||||
215 | var mrg = parseInt($ms.css("marginBottom")) || 0; | ||||||
216 | var brd = parseInt($ms.css("borderBottomWidth")) || 0; | ||||||
217 | $ms.css("height", (wh-top-mrg-brd)+"px"); | ||||||
218 | // IE fires resize for splitter; others don't so do it here | ||||||
219 | if ( !jQuery.browser.msie ) | ||||||
220 | $ms.trigger("resize"); | ||||||
221 | }).trigger("resize"); | ||||||
222 | EOD | ||||||
223 | 0 | $function2 =~ s/#ID/#$id/ ; | |||||
224 | 0 | 0 | $function2 = '' unless $my->browserFill ; | ||||
225 | |||||||
226 | 0 | return $function1 . $function2 ; | |||||
227 | } | ||||||
228 | 1; | ||||||
229 | |||||||
230 | =head1 NAME | ||||||
231 | |||||||
232 | JQuery::Splitter - Split into panes | ||||||
233 | |||||||
234 | =head1 VERSION | ||||||
235 | |||||||
236 | Version 1.00 | ||||||
237 | |||||||
238 | =cut | ||||||
239 | |||||||
240 | =head1 SYNOPSIS | ||||||
241 | |||||||
242 | JQuery::Splitter is used to split an area into two panes. This can be | ||||||
243 | extended to three or more by nesting | ||||||
244 | |||||||
245 | use JQuery; | ||||||
246 | use JQuery::Splitter ; | ||||||
247 | my $splitter1 = JQuery::Splitter->new(id => 'MySplitter', | ||||||
248 | addToJQuery => $jquery, | ||||||
249 | browserFill => 1, | ||||||
250 | type => 'v', | ||||||
251 | HTML1 => $leftHTML, HTML2 => $rightHTML) ; | ||||||
252 | |||||||
253 | |||||||
254 | =head1 DESCRIPTION | ||||||
255 | |||||||
256 | This module is a bit more complicated than others, since CSS needs to | ||||||
257 | be set to get good results. For complete information see L |
||||||
258 | |||||||
259 | my $mainPanelCSS = new JQuery::CSS(hash => {'#MySplitter' => {'min-width' => '500px', 'min-height' => '300px', border => '4px solid #669'}}) ; | ||||||
260 | my $panel1CSS = new JQuery::CSS(hash => { '#LeftPanel' => {background => 'blue', padding => '8px'}}) ; | ||||||
261 | my $panel2CSS = new JQuery::CSS(hash => { '#RightPanel' => {background => 'yellow', padding => '4px'}}) ; | ||||||
262 | my $splitter1 = JQuery::Splitter->new(id => 'MySplitter', | ||||||
263 | addToJQuery => $jquery, | ||||||
264 | browserFill => 1, | ||||||
265 | type => 'v', accessKey => "I", panel1 => 'LeftPanel', panel2 => 'RightPanel', | ||||||
266 | mainPanelCSS => $mainPanelCSS, | ||||||
267 | panel1CSS => $panel1CSS, | ||||||
268 | panel2CSS => $panel2CSS, | ||||||
269 | panel1Params => {minA => 100, initA => 100, maxA => 1000}, | ||||||
270 | splitBackGround => 'pink', | ||||||
271 | splitActive => 'red', | ||||||
272 | splitHeight => '6px', | ||||||
273 | splitRepeat => 1, | ||||||
274 | HTML1 => $leftHTML, HTML2 => $rightHTML) ; | ||||||
275 | |||||||
276 | Have a look at the splitter examples. | ||||||
277 | |||||||
278 | =over | ||||||
279 | |||||||
280 | =item addToJQuery | ||||||
281 | |||||||
282 | Add the item to JQuery | ||||||
283 | |||||||
284 | =item browserFill | ||||||
285 | |||||||
286 | Set this to 1 if you want the panel to fill the whole page | ||||||
287 | |||||||
288 | =item type | ||||||
289 | |||||||
290 | Set to h for horizontal split and v for vertical split | ||||||
291 | |||||||
292 | =item accessKey | ||||||
293 | |||||||
294 | Allows user access to a splitter bar through the keyboard | ||||||
295 | |||||||
296 | =item panel1 | ||||||
297 | |||||||
298 | Give an id to the left/top panel | ||||||
299 | |||||||
300 | =item panel2 | ||||||
301 | |||||||
302 | Give an id to the right/bottom panel | ||||||
303 | |||||||
304 | =item mainPanelCSS | ||||||
305 | |||||||
306 | Define CSS for the main panel | ||||||
307 | |||||||
308 | =item panel1CSS | ||||||
309 | |||||||
310 | Define CSS for the left/top panel | ||||||
311 | |||||||
312 | =item panel2CSS | ||||||
313 | |||||||
314 | Define CSS for the right/bottom panel | ||||||
315 | |||||||
316 | =item panel1Params | ||||||
317 | |||||||
318 | =over | ||||||
319 | |||||||
320 | =item minA | ||||||
321 | |||||||
322 | Minimum size for the panel | ||||||
323 | |||||||
324 | =item initA | ||||||
325 | |||||||
326 | Initial size for the panel | ||||||
327 | |||||||
328 | =item maxA | ||||||
329 | |||||||
330 | Maximum size for the panel | ||||||
331 | |||||||
332 | =back | ||||||
333 | |||||||
334 | =item panel2Params | ||||||
335 | |||||||
336 | =over | ||||||
337 | |||||||
338 | =item minB | ||||||
339 | |||||||
340 | Minimum size for the panel | ||||||
341 | |||||||
342 | =item initB | ||||||
343 | |||||||
344 | Initial size for the panel | ||||||
345 | |||||||
346 | =item maxB | ||||||
347 | |||||||
348 | Maximum size for the panel | ||||||
349 | |||||||
350 | =back | ||||||
351 | |||||||
352 | =item splitBackGround | ||||||
353 | |||||||
354 | Define the colour for the background of the splitter bar | ||||||
355 | |||||||
356 | =item splitActive | ||||||
357 | |||||||
358 | Define the colour for the splitter bar when it is active | ||||||
359 | |||||||
360 | =item splitHeight | ||||||
361 | |||||||
362 | Define the size of the splitter bar | ||||||
363 | |||||||
364 | =item HTML1 | ||||||
365 | |||||||
366 | Set the HTML for the top/left panel | ||||||
367 | |||||||
368 | =item HTML2 | ||||||
369 | |||||||
370 | Set the HTML for the bottom/right panel | ||||||
371 | |||||||
372 | =item internalPanel | ||||||
373 | |||||||
374 | If panels are put one inside another, the internal panels must have | ||||||
375 | this flag set. The splitter bars take all their definitions from the | ||||||
376 | outermost panel. That is, they cannot be changed. | ||||||
377 | |||||||
378 | =back | ||||||
379 | |||||||
380 | =head1 FUNCTIONS | ||||||
381 | |||||||
382 | =over | ||||||
383 | |||||||
384 | =item HTML | ||||||
385 | |||||||
386 | Get the HTML for the object | ||||||
387 | |||||||
388 | =item new | ||||||
389 | |||||||
390 | Instantiate the object | ||||||
391 | |||||||
392 | =item setHTML1 | ||||||
393 | |||||||
394 | Set HTML1 for the object | ||||||
395 | |||||||
396 | =item setHTML2 | ||||||
397 | |||||||
398 | Set HTML2 for the object | ||||||
399 | |||||||
400 | =back | ||||||
401 | |||||||
402 | =head1 AUTHOR | ||||||
403 | |||||||
404 | Peter Gordon, C<< |
||||||
405 | |||||||
406 | =head1 BUGS | ||||||
407 | |||||||
408 | Please report any bugs or feature requests to | ||||||
409 | C |
||||||
410 | L |
||||||
411 | I will be notified, and then you'll automatically be notified of progress on | ||||||
412 | your bug as I make changes. | ||||||
413 | |||||||
414 | =head1 SUPPORT | ||||||
415 | |||||||
416 | You can find documentation for this module with the perldoc command. | ||||||
417 | |||||||
418 | perldoc JQuery | ||||||
419 | |||||||
420 | You can also look for information at: | ||||||
421 | |||||||
422 | =over 4 | ||||||
423 | |||||||
424 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||
425 | |||||||
426 | L |
||||||
427 | |||||||
428 | =item * CPAN Ratings | ||||||
429 | |||||||
430 | L |
||||||
431 | |||||||
432 | =item * RT: CPAN's request tracker | ||||||
433 | |||||||
434 | L |
||||||
435 | |||||||
436 | =item * Search CPAN | ||||||
437 | |||||||
438 | L |
||||||
439 | |||||||
440 | =back | ||||||
441 | |||||||
442 | =head1 ACKNOWLEDGEMENTS | ||||||
443 | |||||||
444 | =head1 COPYRIGHT & LICENSE | ||||||
445 | |||||||
446 | Copyright 2007 Peter Gordon, all rights reserved. | ||||||
447 | |||||||
448 | This program is free software; you can redistribute it and/or modify it | ||||||
449 | under the same terms as Perl itself. | ||||||
450 | |||||||
451 | =cut | ||||||
452 | |||||||
453 | 1; # End of JQuery::Taconite |