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

Diff of /FigKernelPackages/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.46, Wed Jun 29 04:33:02 2005 UTC revision 1.47, Fri Jul 22 20:42:30 2005 UTC
# Line 270  Line 270 
270    
271      if (!$css || !$css->{'Default'})      if (!$css || !$css->{'Default'})
272      {      {
273         $css->{'Default'}="/FIG/Html/css/default.css";         $css->{'Default'}=$FIG_Config::cgi_url."/Html/css/default.css";
274      }      }
275      if (!$css->{"Sans Serif"})      if (!$css->{"Sans Serif"})
276      {      {
277         $css->{'Sans Serif'}="/FIG/Html/css/sanserif.css";         $css->{'Sans Serif'}=$FIG_Config::cgi_url."/Html/css/sanserif.css";
278      }      }
279      my $csstext = "<link rel='stylesheet' title='default' href='".$css->{'Default'}."' type='text/css'>\n";      my $csstext = "<link rel='stylesheet' title='default' href='".$css->{'Default'}."' type='text/css'>\n";
280      $csstext   .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";      $csstext   .= "<link rel='alternate stylesheet' title='Sans Serif' href='".$css->{'Sans Serif'}."' type='text/css'>\n";
# Line 454  Line 454 
454      # things like colspan and align. Note that in this case you need to include the td      # things like colspan and align. Note that in this case you need to include the td
455      # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]      # use something like ["some data to appear", "td colspan=4 bgcolor=gray"]
456    
457      if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; if ($tag =~ /td/) { $endtag = "td" } }      # per GJO's request modified this line so it can take any tag.
458        if ( ref($x) eq "ARRAY" ) { ($x, $tag) = @$x; $tag =~ /^(\S+)/; $endtag = $1 }
459    
460      if ( $x =~ /^\@([^:]+)\:(.*)$/ )      if ( $x =~ /^\@([^:]+)\:(.*)$/ )
461      {      {
# Line 466  Line 467 
467      }      }
468  }  }
469    
470    
471    sub merge_table_rows {
472     # RAE:
473     # Experimental piece of code. We often want to have rows or columns were cells are merged. It just looks so much nicer
474     # this block should merge adjacent rows that have the same text in them.
475     # use like this:
476     #      $tab=&HTML::merge_table_rows($tab);
477     # before you do a make_table call
478    
479     my $self=shift if UNIVERSAL::isa($_[0],__PACKAGE__);
480     my ($tab)=@_;
481    
482     my $newtable;
483     my $lastrow;
484     my $rowspan;
485     my $refs;
486    
487     for (my $y=0; $y <= $#$tab; $y++) {
488     #$y is the row in the table;
489      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
490       #$x is the column in the table
491       # if the column in the row we are looking at is the same as the column in the previous row, we don't add
492       # this cell to $newtable. Instead we increment the rowspan of the previous row by one
493    
494       # handle cells that are references to arrays
495       if (ref($tab->[$y]->[$x]) eq "ARRAY") {$refs->[$y]->[$x]=$tab->[$y]->[$x]->[1]; $tab->[$y]->[$x]=$tab->[$y]->[$x]->[0]}
496    
497       # now we go back through the table looking where to draw the merge line:
498       my $lasty=$y;
499       while ($tab->[$y]->[$x] eq $tab->[$lasty]->[$x]) {$lasty--}
500       $lasty++; # this is the last identical cell. If lasty==y it is the current cell, so we just save the data. Otherwise we increment the rowspan
501       if ($lasty == $y) {
502        # we always want to have something in rows that may otherwise be empty but should be there (see below)
503        unless ($tab->[$y]->[$x]) {$tab->[$y]->[$x]=" &nbsp; "}
504        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
505       }
506       else {$rowspan->[$lasty]->[$x]++}
507      }
508     }
509    
510     # now just join everything back together
511     for (my $y=0; $y <= $#$tab; $y++) {
512      for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
513       if ($rowspan->[$y]->[$x]) {
514        if ($refs->[$y]->[$x]) {$refs->[$y]->[$x] .= " rowspan=". ($rowspan->[$y]->[$x]+1)}
515        else {$refs->[$y]->[$x] = "td rowspan=". ($rowspan->[$y]->[$x]+1)}
516        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
517       }
518       elsif ($newtable->[$y]->[$x] && $refs->[$y]->[$x]) {
519        $newtable->[$y]->[$x]=[$newtable->[$y]->[$x], $refs->[$y]->[$x]];
520       }
521      }
522     }
523    
524    
525     # finally we have to remove any completely empty cells that have been added by the array mechanism
526     # (e.g. if you define $a->[2] then $a->[0] and $a->[1] are now undef).
527     # that is why in the loop above I replace empty cells with nbsp. They are now not undef!
528     # I am sure that Gary can do this in one line, but I am hacking.
529     my @trimmed;
530     foreach my $a (@$newtable) {
531      my @row;
532      foreach my $b (@$a) {
533       push @row, $b if ($b);
534      }
535      push @trimmed, \@row;
536     }
537    
538     return \@trimmed;
539    }
540    
541    
542    
543    
544  sub set_ec_links {  sub set_ec_links {
545      shift if UNIVERSAL::isa($_[0],__PACKAGE__);      shift if UNIVERSAL::isa($_[0],__PACKAGE__);
546      my($cgi,$x) = @_;      my($cgi,$x) = @_;

Legend:
Removed from v.1.46  
changed lines
  Added in v.1.47

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3