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

Annotation of /FigKernelPackages/SeedHTML.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (view) (download) (as text)

1 : overbeek 1.2 package SeedHTML;
2 : overbeek 1.1
3 : olson 1.3 use strict;
4 :    
5 :     # This is a SAS component.
6 :    
7 : overbeek 1.1 ########################### HTML Utilities ###########################
8 :    
9 :    
10 :     =head1 make_table
11 :    
12 :     The main method to convert an array into a table.
13 :    
14 :     The col_hdrs are set to the <th> headers, the $tab is an array of
15 :     arrays. The first is the rows, and the second is the columns. The
16 :     title is the title of the table.
17 :    
18 :     The options define the settings for the table such as border, width,
19 :     and class for css formatting.
20 :    
21 :     =cut
22 :    
23 :     sub make_table {
24 :     my($col_hdrs,$tab,$title, %options ) = @_;
25 :     my(@tab);
26 :    
27 :     my $border = defined $options{border} ? "border=\"$options{border}\"" : "border";
28 :     my $width = defined $options{width} ? "width=\"$options{width}\"" : "";
29 :     my $class = defined $options{class} ? "class=\"$options{class}\"" : "";
30 :     push( @tab, "\n<table $border $width $class>\n",
31 :     "\t<caption><b>$title</b></caption>\n",
32 :     "\t<tr>\n\t\t"
33 :     . join( "\n", map { &expand($_, "th") } @$col_hdrs )
34 :     . "\n\t</tr>\n"
35 :     );
36 :     my($i);
37 :    
38 :     my $row;
39 :     foreach $row (@$tab)
40 :     {
41 :     push( @tab, "\t<tr>\n"
42 :     . join( "\n", map { &expand($_) } @$row )
43 :     . "\n\t</tr>\n"
44 :     );
45 :     }
46 :     push(@tab,"</table>\n");
47 :     return join("",@tab);
48 :     }
49 :    
50 :     sub expand {
51 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
52 :     my( $x, $tag ) = @_;
53 :    
54 :     $tag = "td" unless $tag;
55 :     my $endtag = $tag;
56 :    
57 :     # RAE modified this so that you can pass in a reference to an array where
58 :     # the first element is the data to display and the second element is optional
59 :     # things like colspan and align. Note that in this case you need to include the td
60 :     # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]
61 :    
62 :     # per GJO's request modified this line so it can take any tag.
63 :     if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; $tag =~ /^(\S+)/; $endtag = $1 }
64 :    
65 :     if ( $x =~ /^\@([^:]+)\:(.*)$/ )
66 :     {
67 :     return "\t\t<$tag $1>$2</$endtag>";
68 :     }
69 :     else
70 :     {
71 :     return "\t\t<$tag>$x</$endtag>";
72 :     }
73 :     }
74 :    
75 :     sub show_page {
76 :     shift if UNIVERSAL::isa($_[0],__PACKAGE__);
77 : olson 1.3 my($cgi,$html) = @_;
78 : overbeek 1.1
79 :     # ARGUMENTS:
80 :     # $cgi is the CGI method
81 :     # $html is an array with all the html in it. It is just joined by "\n" (and not <br> or <p>
82 :    
83 : olson 1.3 print $cgi->header();
84 :     print "<html>\n";
85 :     print qq(<script src="http://theseed.uchicago.edu/FIG/Html/css/FIG.js" type="text/javascript"></script>\n);
86 :     print $_ for @$html;
87 :     print "</html>\n";
88 :     }
89 : overbeek 1.1
90 :    
91 : olson 1.3 #
92 :     # This was copied from FIGjs.pm
93 :     #
94 : overbeek 1.1
95 : olson 1.3 =head2 mouseover()
96 : overbeek 1.1
97 : olson 1.3 Generate a mouseover for your code.
98 : overbeek 1.1
99 : olson 1.3 You can use it like this:
100 :     push @$html, "<a " . FIGjs::mouseover("Title", "Body Text", "Menu", $parent, $title_bg_color, $text_bg_color) . " href='link.cgi'>a link</a>";
101 : overbeek 1.1
102 : olson 1.3 and the appropriate javascript will be added for you.
103 : overbeek 1.1
104 : olson 1.3 Title: The title of the popup that appears in bold
105 :     Body Text: The text to appear in the box.
106 :     Menu: This is probably the alternate menu that appears on the pinned regions page??
107 : overbeek 1.1
108 : olson 1.3 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.
109 :     The text strings supplied must already be HTML escaped (< or & will be treated as HTML, not text).
110 : overbeek 1.1
111 : olson 1.3 $parent is whether to place the box under the cursor or elsewhere on the page (e.g. top right corner)
112 :     Please note that there is an error at the moment and the value of parent doesn't affect anything.
113 :     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.
114 : overbeek 1.1
115 : olson 1.3 $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
116 :     $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
117 : overbeek 1.1
118 : olson 1.3 You don't need to supply the default colors, but can make the box red or green if you like.
119 : overbeek 1.1
120 : olson 1.3 =cut
121 : overbeek 1.1
122 :    
123 : olson 1.3 sub mouseover {
124 :     my ($title, $text, $menu, $parent, $hc, $bc) = @_;
125 : overbeek 1.1
126 : olson 1.3 defined( $title ) or $title = '';
127 :     $title =~ s/'/\\'/g; # escape '
128 :     $title =~ s/"/&quot;/g; # escape "
129 : overbeek 1.1
130 : olson 1.3 # Fixed incorrect quoting of $text (reversed single and double quote)
131 :     # -- GJO
132 : overbeek 1.1
133 : olson 1.3 defined( $text ) or $text = '';
134 :     $text =~ s/'/\\'/g; # escape '
135 :     $text =~ s/"/&quot;/g; # escape "
136 : overbeek 1.1
137 : olson 1.3 defined( $menu ) or $menu = '';
138 :     $menu =~ s/'/\\'/g; # escape '
139 :     $menu =~ s/"/&quot;/g; # escape "
140 : overbeek 1.1
141 : olson 1.3 qq( onMouseover="javascript:if(!this.tooltip) this.tooltip=new Popup_Tooltip(this,'$title','$text','$menu','$parent','$hc','$bc');this.tooltip.addHandler(); return false;" );
142 : overbeek 1.1 }
143 :    
144 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3