# ga_outline_lib.pl # library of routines for DHTML outlining for Google API scripts # see http://www.staggernation.com for info # By Kevin Shay, kevin [AT] staggernation [DOT] com # last modified 4/24/02 sub html_level_nav { # navigation line for a topic (includes errors) my ($params, $response, @fields) = @_; my ($first, $prev, $next, $spacer, $about, $err, $href, $start, $target); $spacer = html_spacer($params->{'level'}, 3); if ($response->{'err'}) { $err = $response->{'err'}; } elsif (!(defined $response->{'resultElements'} && @{$response->{'resultElements'}})) { $err = 'No results found.'; } if ($err) { return <<"EOH";
$spacer $err
EOH } # top level: target to our own frame; otherwise send results to hidden frame $target = ($params->{'level'} == 0) ? '' : ' target="hiddenframe"'; # put reload parameter in links to tell script to reload the subtopics for this topic $href = "$this_script?reload=1"; # copy the specified params to the link for (@fields) { $href .= "&$_=$params->{$_}" if ($params->{$_}); } # do we need a First link? if ($response->{'startIndex'} > 20) { $first = qq{  << First}; } # do we need a Previous link? if ($response->{'startIndex'} > 10) { $start = $response->{'startIndex'} - 11; $prev = qq{  < Previous}; } # do we need a Next link? if ($response->{'endIndex'} < $response->{'estimatedTotalResultsCount'}) { $next = <<"EOH";   Next > EOH } # searches are zero-based $start = $response->{'startIndex'} - 1; $google = <<"EOH"; View in Google EOH $about = $response->{'estimateIsExact'} ? '' : ' about'; $response->{'estimatedTotalResultsCount'} = insert_commas($response->{'estimatedTotalResultsCount'}); return <<"EOH";
$spacer $params->{'count_text'}$response->{'startIndex'}-$response->{'endIndex'} of$about $response->{'estimatedTotalResultsCount'}. $google$first$prev$next
EOH } sub html_spacer { # return a spacer GIF for a specified outline level my ($level, $extra) = @_; return '' unless $level; my $indwidth = 20 * $level; # any additional offset that was passed $indwidth += $extra; return <<"EOH"; EOH } sub html_js_funcs { # JavaScript to go at top of each page my ($framepage) = @_; # the outline scripts need to be framed, so pass a URL # to which we should redirect if we're not called in a frame if ($framepage) { $framepage = <<"EOH"; if (self == top) { top.location.href = '$framepage' } EOH } return <<"EOH";
EOH } sub html_js_expand { # JavaScript to print at the end of the script output for a subtopic # (when expanding); # tells calling frame it's time to grab the data in this frame my ($id) = shift; return <<"EOH"; EOH } sub html_js_reload { # JavaScript to print at the end of the script output for a subtopic # (when reloading, i.e. clicking Next, Previous, First); # tells calling frame it's time to grab the data in this frame my ($id) = shift; return <<"EOH"; EOH } 1;