Greetings,
I ran into a little limitation in HTML::Pager and created a patch, which if
Sam feel's is useful, I hope can be included in a future version of
HTML::Pager.
HTML::Pager is a great tool for implementing navigation of large result sets
in web applications. Like most result set navigators, it provides the famous
"next" and "previous" navigation as well as "jump to" (to go to a specific
page or jump by several pages at once). HTML::Pager can hook into
HTML::Template and use TMPL_LOOP's and TMPL_VAR's to display templatized
output. This functionality is almost always needed in search applications,
and if you're already using HTML::Template, HTML::Pager is easy to adapt to
your application.
Here's the problem: Even though you can customize your result pages using
HTML::Template, you can't customize what the "next" and "previous" buttons
look like in the result set navigation. They are hardcoded as form buttons,
and they're ugly as heck.
Here's the solution: Now, if you're using HTML::Template to customize your
results pages, you can also use the new 'expose_buttons' parameter to
HTML::Pager's new() constructor. When expose_buttons is turned on (it is
turned off by default), rather than HTML::Pager putting entire <INPUT
TYPE=BUTTON onClick=... tags in your result set navgiation, it only puts in
the javascript, so you are free to implement any type of input you want,
including anchor href's and images. No more ugly grey box buttons!
Here's the patch, which covers POD for the new new() param, making sure
expose_buttons is only active when a template param is also supplied to
new(), and changes to the code that outputs the PAGER_NEXT and PAGER_PREV
TMPL_VAR's. This patch is based on HTML::Pager version 0.03.
cheers,
Daniel Packer
*** Pager.old Thu Mar 21 18:22:58 2002
--- Pager.pm Thu Mar 21 18:34:33 2002
***************
*** 69,75 ****
use integer;
use HTML::Template;
! $HTML::Pager::VERSION = '0.03';
=head1 METHODS
--- 69,75 ----
use integer;
use HTML::Template;
! $HTML::Pager::VERSION = '0.03_01';
=head1 METHODS
***************
*** 212,217 ****
--- 212,241 ----
</TMPL_LOOP>
...
+ =item *
+
+ expose_buttons - Pass a non-zero scalar, and in a customized
+ HTML::Template object, the TMPL_VAR's "PAGER_PREV" and
+ "PAGER_NEXT" will contain only the javascript necessary for
+ navigation, instead of complete HTML INPUT button tags. This
+ should only be used in conjunction with the template param
+ in the new() constructor. HTML::Pager will die with an error
+ upon calling new() if expose_buttons is set to a non-zero
+ value, but template is not set.
+
+ This allows you to customize the look and feel of the "previous"
+ and "next" buttons in the paging navigation. For example, to use
+ anchor href's instead of the standard buttons, you could do:
+
+ <TD ALIGN=CENTER>
+ <TMPL_IF PAGER_PREV><a href="javascript:<TMPL_VAR
NAME="PAGER_PREV">"><< Prev</a></TMPL_IF>
+ <TMPL_VAR NAME="PAGER_JUMP">
+ <TMPL_IF PAGER_NEXT><a href="javascript:<TMPL_VAR
NAME="PAGER_NEXT">">Next >></a></TMPL_IF>
+ </TD>
+
+ This would implement the "previous" and "next" buttons as html
+ anchor href links, rather than form buttons.
+
=item *
persist_vars - Pass a ref to an array of the names of the CGI form
***************
*** 339,350 ****
--- 363,377 ----
unless exists($self->{get_data_callback});
die ("Called $pkg->new() with a get_data_callback parameter that does
not appear to be a valid subroutine reference.")
if (!ref($self->{get_data_callback}) ||
!((ref($self->{get_data_callback}) ne 'CODE') ||
(ref($self->{get_data_callback}) ne 'ARRAY')));
+ die ("Called $pkg->new() with a expose_buttons parameter that requires a
template parameter but no template parameter is set.")
+ if exists($self->{expose_buttons}) && !(exists($self->{template}));
# set default parameters
$self->{debug} = 0 unless exists($self->{debug});
$self->{column_names} = undef unless exists($self->{column_names});
$self->{persist_vars} = [] unless exists($self->{persist_vars});
$self->{javascript_presubmit} = '' unless
exists($self->{javascript_presubmit});
+ $self->{expose_buttons} = 0 unless exists($self->{expose_buttons});
# Default colors
$self->{cell_space_color} = '#000000'
unless(exists($self->{cell_space_color}));
***************
*** 479,485 ****
# generate next and prev
if (($self->{offset} + $self->{page_size}) < $self->{rows}) {
my $next_offset = $self->{offset} + $self->{page_size};
! $template->param('PAGER_NEXT', "<INPUT TYPE=BUTTON VALUE='Next Page'
onClick=\"PAGER_set_offset_and_submit($next_offset);\">");
}
if ($self->{offset} > 0) {
my $prev_offset = $self->{offset} - $self->{page_size};
--- 506,516 ----
# generate next and prev
if (($self->{offset} + $self->{page_size}) < $self->{rows}) {
my $next_offset = $self->{offset} + $self->{page_size};
! if ($self->{expose_buttons}) {
! $template->param('PAGER_NEXT',
"PAGER_set_offset_and_submit($next_offset);");
! } else {
! $template->param('PAGER_NEXT', "<INPUT TYPE=BUTTON VALUE='Next Page'
onClick=\"PAGER_set_offset_and_submit($next_offset);\">");
! }
}
if ($self->{offset} > 0) {
my $prev_offset = $self->{offset} - $self->{page_size};
***************
*** 487,493 ****
$prev_offset = 0;
}
;
! $template->param('PAGER_PREV', "<INPUT TYPE=BUTTON VALUE='Previous
Page' onClick=\"PAGER_set_offset_and_submit($prev_offset);\">");
}
# generate jump zone
--- 518,528 ----
$prev_offset = 0;
}
;
! if ($self->{expose_buttons}) {
! $template->param('PAGER_PREV',
"PAGER_set_offset_and_submit($prev_offset);");
! } else {
! $template->param('PAGER_PREV', "<INPUT TYPE=BUTTON VALUE='Previous
Page' onClick=\"PAGER_set_offset_and_submit($prev_offset);\">");
! }
}
# generate jump zone
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]