カテゴリ | |
---|---|
サマリ | テーブルの改造で特定の行に色をつける |
バージョン | 1.4.7 |
投稿者 | アベス |
状態 | 完了 |
投稿日 | 2008-02-14 (木) 01:41:30 |
|aaa|aaa|h
と作成すると、見出しになりますよね。 これの要領で
|aaa|aaa|o←アルファベットは適当
にすると この行だけ色を変更することはできないでしょうか?
|見出し|h |あいうえお| |BGCOLOR(#ffffff):かきくけこ| |さしすせそ| |BGCOLOR(#ffffff):たちつてと|
のように色を1行ごとによって変更したいのですが BGCOLORをいれると見にくくなる上に面倒なので
|かきくけこ|かきくけこ|o
でその行は全てBGCOLOR(#):が適用されると楽だなと思いました
|見出し|h |あいうえお| |BGCOLOR(#ffffff):|c |かきくけこ| |BGCOLOR():|c |さしすせそ| |BGCOLOR(#ffffff):|c |たちつてと|
見出し |
あいうえお |
かきくけこ |
さしすせそ |
たちつてと |
- function toString() + function toString($flag) { if ($this->rowspan == 0 || $this->colspan == 0) return ''; - $param = ' class="style_' . $this->tag . '"'; + if ($flag) { + $param = ' class="style_' . $this->tag . '1"'; + } else { + $param = ' class="style_' . $this->tag . '2"'; + } if ($this->rowspan > 1) $param .= ' rowspan="' . $this->rowspan . '"'; if ($this->colspan > 1) { $param .= ' colspan="' . $this->colspan . '"'; unset($this->style['width']); } if (! empty($this->style)) $param .= ' style="' . join(' ', $this->style) . '"'; return $this->wrap(parent::toString(), $this->tag, $param, FALSE); }
// toString $string = ''; foreach ($parts as $type => $part) { + $flag = FALSE; $part_string = ''; foreach (array_keys($this->elements) as $nrow) { if ($this->types[$nrow] != $type) continue; + $flag = ! $flag; $row = & $this->elements[$nrow]; $row_string = ''; foreach (array_keys($row) as $ncol) - $row_string .= $row[$ncol]->toString(); + $row_string .= $row[$ncol]->toString($flag); $part_string .= $this->wrap($row_string, 'tr'); } $string .= $this->wrap($part_string, $part); }
thead td.style_td1 thead td.style_td2 tfoot td.style_td1 tfoot td.style_td2 thead th.style_th1 thead th.style_th2 tfoot th.style_th1 tfoot th.style_th2 .style_th1 .style_th2 .style_td1 .style_td2
|~あいうえお|かきくけこ| |~|さしすせそ| |~たちつてと|なにぬねの| |~|はひふへほ| |~まみむめも|やゆよ| |~らりるれろ|わをん|
上記の場合、th1である「あ行」は正常ですが、th2となってほしい「た行」が一行またいだのでth1になってしまいます。
rowspanを使用していない「ま行」はth1、「ら行」はth2と当然動作してくれます。
さらに理想としては、「か行」と「さ行」はtd1に、「な行」と「は行」がtd2になりませんでしょうか?
表で表示すると
あいうえお | かきくけこ |
---|---|
さしすせそ | |
たちつてと | |
たちつてと | なにぬねの |
はひふへほ | |
まみむめも | |
アイウエオ | カキクケコ |
サシスセソ | |
タチツテト |
という風な形です。
もちろんこのままで十分満足なのですが、rowspanを使うことを考えて上記の様にできますでしょうか?
厳しそうならこのまま完了にしたいと思っています、わがまま言って申し訳ないです。 -- アベス 2008-02-17 (日) 22:34:23
// '|'-separated table function & Factory_Table(& $root, $text) { - if (! preg_match('/^\|(.+)\|([hHfFcC]?)$/', $text, $out)) { + if (! preg_match('/^\|(.+)\|([hHfFcC]?)([12]?)$/', $text, $out)) { return Factory_Inline($text); } else { return new Table($out); } }
- function toString() + function toString($flag) { if ($this->rowspan == 0 || $this->colspan == 0) return ''; - $param = ' class="style_' . $this->tag . '"'; + $param = ' class="style_' . $this->tag . $flag . '"'; if ($this->rowspan > 1) $param .= ' rowspan="' . $this->rowspan . '"'; if ($this->colspan > 1) {
class Table extends Element { var $type; var $types; var $col; // number of column + var $style; function Table($out) { parent::Element(); $cells = explode('|', $out[1]); $this->col = count($cells); $this->type = strtolower($out[2]); $this->types = array($this->type); + $this->style = array($out[3]); $is_template = ($this->type == 'c'); $row = array(); foreach ($cells as $cell)
function & insert(& $obj) { $this->elements[] = $obj->elements[0]; $this->types[] = $obj->type; + $this->style[] = $obj->style[0]; return $this; }
// Set colspan and style $stylerow = NULL; + $stylecss = ''; foreach (array_keys($this->elements) as $nrow) { $row = & $this->elements[$nrow]; - if ($this->types[$nrow] == 'c') + if ($this->types[$nrow] == 'c') { $stylerow = & $row; + $stylecss = & $this->style[$nrow]; + } else if ($stylecss != '' && $this->style[$nrow] == '') { + $this->style[$nrow] = $stylecss; + } $colspan = 1; foreach (array_keys($row) as $ncol) { if ($row[$ncol]->colspan == 0) {
// toString $string = ''; foreach ($parts as $type => $part) { + $flag = 0; $part_string = ''; foreach (array_keys($this->elements) as $nrow) { if ($this->types[$nrow] != $type) continue; + + switch ($flag) + { + case 1: + ++$flag; + break; + + default: + $flag = 1; + } + if ($this->style[$nrow] == '') { + $tmp = $flag; + } else { + $tmp = $this->style[$nrow]; + } $row = & $this->elements[$nrow]; $row_string = ''; foreach (array_keys($row) as $ncol) - $row_string .= $row[$ncol]->toString(); + $row_string .= $row[$ncol]->toString($tmp); $part_string .= $this->wrap($row_string, 'tr'); } $string .= $this->wrap($part_string, $part); }
|~style_th1|style_td1|1 |~|style_td1|1 |~|style_td1|1 ||COLOR(#666666):|c2 |~style_th2|style_td2| |~|style_td2| |~|style_td1|1 |||c |~自動設定|自動設定| |~|自動設定| |~|自動設定|
style_th1 | style_td1 |
---|---|
style_td1 | |
style_td1 | |
style_th2 | style_td2 |
style_td2 | |
style_td1 | |
自動設定 | 自動設定 |
自動設定 | |
自動設定 |