に、trueでにスタイルの要素を生成します define('PLUGIN_REGION2_COMPATIBILITY_STYLE', false); // スタイルシートの定義 define('PLUGIN_REGION2_STYLE', << setDefaultSettings(); if (func_num_args() >= 2) { $args = func_get_args(); $builder -> setDescription( array_shift($args) ); foreach( $args as $value ) { if (preg_match("/^open/i", $value)) { $builder -> setOpened(); continue; } if (preg_match("/^close/i", $value)) { $builder -> setClosed(); continue; } } } $args = func_get_args(); $contents = $args[func_num_args()-1]; $contents = preg_replace("/\r\n|\r/", "\n", $contents); $contents = explode("\n", $contents); return $builder -> build() .convert_html($contents) .<< EOD; } class Region2Plugin { private $description; private $isOpened; private $scriptVarName; private $callCount; public function __construct() { $this -> callCount = 0; $this -> setDefaultSettings(); } public function setDefaultSettings() { $this -> description = "..."; $this -> isOpened = false; } public function setClosed() { $this -> isOpened = false; } public function setOpened() { $this -> isOpened = true; } public function setDescription($description) { $this -> description = convert_html($description); $this -> description = preg_replace( "/^

/i", "", $this -> description); $this -> description = preg_replace( "/<\/p>$/i", "", $this -> description); } public function build() { $this -> callCount++; $html = array(); if ($this -> callCount <= 1) { $style = "\n"; if (PLUGIN_REGION2_COMPATIBILITY_STYLE) { array_push($html, $style); } else { global $head_tags; $head_tags[] .= $style; } } array_push($html, $this -> buildButtonHtml()); array_push($html, $this -> buildBracketHtml()); array_push($html, $this -> buildSummaryHtml()); array_push($html, $this -> buildContentHtml()); return join($html); } private function buildButtonHtml() { $button = ($this -> isOpened) ? "-" : "+"; return <<

$button
EOD; } private function buildBracketHtml() { $bracketStyle = ($this -> isOpened) ? "border-style: solid none solid solid;" : "border-style:none;"; return << callCount} style="flex:none;font-size:1pt;border:gray 1px;{$bracketStyle}">  EOD; } private function buildSummaryHtml() { $summaryStyle = ($this -> isOpened) ? "display:none;" : "display:block;"; $onClick = PLUGIN_REGION2_CLICK_SUMMARY ? 'onclick="' . $this -> getJavaScriptTag() . '"' : ""; return << callCount} $onClick style="flex:0 1 auto;min-width:0;align-self:flex-start;{$summaryStyle}">{$this -> description} EOD; } private function buildContentHtml() { $contentStyle = ($this -> isOpened) ? "display:block;" : "display:none;"; return << callCount} style="flex:1 1 auto;min-width:0;{$contentStyle}"> EOD; } private function getJavaScriptTag() { return << callCount}').style.display!='none'){ document.getElementById('rgn2_summary{$this -> callCount}').style.display='none'; document.getElementById('rgn2_content{$this -> callCount}').style.display='block'; document.getElementById('rgn2_bracket{$this -> callCount}').style.borderStyle='solid none solid solid'; document.getElementById('rgn2_button{$this -> callCount}').innerHTML='-'; }else{ document.getElementById('rgn2_summary{$this -> callCount}').style.display='block'; document.getElementById('rgn2_content{$this -> callCount}').style.display='none'; document.getElementById('rgn2_bracket{$this -> callCount}').style.borderStyle='none'; document.getElementById('rgn2_button{$this -> callCount}').innerHTML='+'; } EOD; } }