[Bio] / FigKernelPackages / SeedHTML.pm Repository:
ViewVC logotype

View of /FigKernelPackages/SeedHTML.pm

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.3 - (download) (as text) (annotate)
Thu Dec 17 21:36:31 2009 UTC (10 years, 5 months ago) by olson
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, myrast_rel40, mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, rast_rel_2011_0119, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, rast_rel_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
Changes since 1.2: +45 -344 lines
More distro fixes.

package SeedHTML;

use strict;

# This is a SAS component.

########################### HTML Utilities ###########################

=head1 make_table

The main method to convert an array into a table.

The col_hdrs are set to the <th> headers, the $tab is an array of
arrays. The first is the rows, and the second is the columns. The
title is the title of the table.

The options define the settings for the table such as border, width,
and class for css formatting. 


sub make_table {
    my($col_hdrs,$tab,$title, %options ) = @_;

    my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";
    my $width = defined $options{width} ? "width=\"$options{width}\"" : "";
    my $class = defined $options{class} ? "class=\"$options{class}\"" : "";
    push( @tab, "\n<table $border $width $class>\n",
              . join( "\n", map { &expand($_, "th") } @$col_hdrs )
              . "\n\t</tr>\n"

    my $row;
    foreach $row (@$tab)
        push( @tab, "\t<tr>\n"
                  . join( "\n", map { &expand($_) } @$row )
                  . "\n\t</tr>\n"
    return join("",@tab);

sub expand {
    shift if UNIVERSAL::isa($_[0],__PACKAGE__);
    my( $x, $tag ) = @_;

    $tag = "td" unless $tag;
    my $endtag = $tag;

    # RAE modified this so that you can pass in a reference to an array where
    # the first element is the data to display and the second element is optional
    # things like colspan and align. Note that in this case you need to include the td
    # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]

    # per GJO's request modified this line so it can take any tag.
    if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; $tag =~ /^(\S+)/; $endtag = $1 }

    if ( $x =~ /^\@([^:]+)\:(.*)$/ )
        return "\t\t<$tag $1>$2</$endtag>";
        return "\t\t<$tag>$x</$endtag>";

sub show_page {
    shift if UNIVERSAL::isa($_[0],__PACKAGE__);
    my($cgi,$html) = @_;

    #     $cgi is the CGI method
    #     $html is an array with all the html in it. It is just joined by "\n" (and not <br> or <p>

    print $cgi->header();
    print "<html>\n";
    print qq(<script src="http://theseed.uchicago.edu/FIG/Html/css/FIG.js" type="text/javascript"></script>\n);
    print $_ for @$html;
    print "</html>\n";

# This was copied from FIGjs.pm

=head2 mouseover()

Generate a mouseover for your code.

You can use it like this: 
push @$html, "<a " . FIGjs::mouseover("Title", "Body Text", "Menu", $parent, $title_bg_color, $text_bg_color) . " href='link.cgi'>a link</a>";

and the appropriate javascript will be added for you.

Title: The title of the popup that appears in bold
Body Text: The text to appear in the box.
Menu: This is probably the alternate menu that appears on the pinned regions page??

Please note these should be HTML code so <b>text</b> will appear as bold. Also, please don't put linebreaks in the text since that breaks everything.
The text strings supplied must already be HTML escaped (< or & will be treated as HTML, not text). 

$parent is whether to place the box under the cursor or elsewhere on the page (e.g. top right corner)
Please note that there is an error at the moment and the value of parent doesn't affect anything. 
Note also that I (RAE) didn't add this, but I have left it here for compatability with mouseover calls that expect it to be here.

$title_bg_color is the color of the background for the title. The default blue color is #333399. Please include the # in describing the color
$text_bg_color is the color of the body of the text. The default body color is #CCCCFF. Please include the # in describing the color

You don't need to supply the default colors, but can make the box red or green if you like.


sub mouseover {
    my ($title, $text, $menu, $parent, $hc, $bc) = @_;

    defined( $title ) or $title = '';
    $title =~ s/'/\\'/g;    # escape '
    $title =~ s/"/&quot;/g; # escape "

    #  Fixed incorrect quoting of $text (reversed single and double quote)
    #  -- GJO

    defined( $text ) or $text = '';
    $text =~ s/'/\\'/g;    # escape '
    $text =~ s/"/&quot;/g; # escape "

    defined( $menu ) or $menu = '';
    $menu =~ s/'/\\'/g;    # escape '
    $menu =~ s/"/&quot;/g; # escape "

    qq( onMouseover="javascript:if(!this.tooltip) this.tooltip=new Popup_Tooltip(this,'$title','$text','$menu','$parent','$hc','$bc');this.tooltip.addHandler(); return false;" );


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3