11<?php
2- // $Id: accordion.inc.php,v 1.4 2021/07/06 00:00:00 K Exp $
2+ // $Id: accordion.inc.php,v 1.5 2021/07/06 00:00:00 K Exp $
33
44/**
55* @link http://pkom.ml/?%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3/accordion.inc.php
88*/
99
1010// region.inc.php(author:xxxxx) https://pukiwiki.osdn.jp/?%E8%87%AA%E4%BD%9C%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3/region.inc.php
11+ // 七海改修版参考 https://nanami.cute.bz/download/accordion.inc.zip
1112
1213//-Accordionプラグインの定義
1314
2021// スタイルシートの定義
2122define ('PLUGIN_ACCORDION_STYLE ' ,
2223<<<EOD
23- # acd_btn {
24+ . acd_btn {
2425 cursor:pointer;
2526}
26- # acd_btn span {
27+ . acd_btn span {
2728 cursor:pointer;
2829 font-family: "MS Pゴシック", "MS PGothic", "ヒラギノ角ゴ Pro W3","Hiragino Kaku Gothic Pro", Osaka, arial, verdana, sans-serif;
2930 padding:1px 4px;
3031 border:gray 1px solid;
3132 color:gray;
32- }
3333EOD );
3434
35+ // false→table,display:inline
36+ // true→div,display:block
37+ define ('PLUGIN_ACCORDION_DISPLAY ' , true );
38+
3539function plugin_accordion_convert () {
3640 static $ builder = 0 ;
3741 if ($ builder == 0 ) $ builder = new AccordionPlugin ();
@@ -57,7 +61,7 @@ function plugin_accordion_convert() {
5761 $ contents = explode ("\n" , $ contents );
5862 return $ builder -> build ()
5963 .convert_html ($ contents )
60- .'</td></tr></table> ' ;
64+ .( PLUGIN_ACCORDION_DISPLAY ? '</div> ' : ' </ td></tr></table> ') ;
6165}
6266
6367class AccordionPlugin {
@@ -66,6 +70,7 @@ class AccordionPlugin {
6670 private $ isOpened ;
6771 private $ scriptVarName ;
6872 private $ callCount ;
73+ private $ display ;
6974
7075 public function __construct () {
7176 $ this -> callCount = 0 ;
@@ -76,6 +81,7 @@ public function setDefaultSettings() {
7681 $ this -> description = "... " ;
7782 $ this -> heading = "h2 " ;
7883 $ this -> isOpened = false ;
84+ $ this -> display = PLUGIN_ACCORDION_DISPLAY ? $ display = "block " : $ display = "inline " ;
7985 }
8086
8187 public function setClosed () { $ this -> isOpened = false ; }
@@ -88,10 +94,10 @@ public function setDescription($description) {
8894 }
8995
9096 public function setHeading ($ heading ) {
91- if (( $ heading == "1 " ) || ( $ heading == "* " )) $ this -> heading = "h2 " ;
92- if (( $ heading == "2 " ) || ( $ heading == "** " )) $ this -> heading = "h3 " ;
93- if (( $ heading == "3 " ) || ( $ heading == "*** " )) $ this -> heading = "h4 " ;
94- if (( $ heading == "4 " ) || ( $ heading == "**** " )) $ this -> heading = "h5 " ;
97+ if ($ heading == "1 " || !( strcmp ( $ heading, "* " ) )) $ this -> heading = "h2 " ;
98+ if ($ heading == "2 " || !( strcmp ( $ heading, "** " ) )) $ this -> heading = "h3 " ;
99+ if ($ heading == "3 " || !( strcmp ( $ heading, "*** " ) )) $ this -> heading = "h4 " ;
100+ if ($ heading == "4 " || !( strcmp ( $ heading, "**** " ) )) $ this -> heading = "h5 " ;
95101 }
96102
97103 public function build () {
@@ -113,11 +119,10 @@ public function build() {
113119
114120 private function buildButtonHtml () {
115121 $ button = ($ this -> isOpened ) ? "- " : "+ " ;
116-
117122 $ onClick = <<<EOD
118123 onclick="
119- if(document.getElementById('acd_content {$ this -> callCount }').style.display!='inline '){
120- document.getElementById('acd_content {$ this -> callCount }').style.display='inline ';
124+ if(document.getElementById('acd_content {$ this -> callCount }').style.display!=' { $ this -> display } '){
125+ document.getElementById('acd_content {$ this -> callCount }').style.display=' { $ this -> display } ';
121126 document.getElementById('acd_button {$ this -> callCount }').innerHTML='-';
122127 }else{
123128 document.getElementById('acd_content {$ this -> callCount }').style.display='none';
@@ -134,18 +139,20 @@ private function buildButtonHtml() {
134139 $ onSpanClick = $ onClick ;
135140 EOD ;
136141 }
142+ $ startTag = PLUGIN_ACCORDION_DISPLAY ? "" : "<table><tr> " ;
137143 return <<<EOD
138- < {$ this -> heading } id ="acd_btn" $ onHeaderClick>
144+ < {$ this -> heading } class ="acd_btn" $ onHeaderClick>
139145 <span id=acd_button {$ this -> callCount } $ onSpanClick> $ button</span> {$ this -> description }
140146 </ {$ this -> heading }>
141- <table><tr>
147+ { $ startTag }
142148 EOD ;
143149 }
144150
145151 private function buildContentHtml () {
146- $ contentStyle = ($ this -> isOpened ) ? "display:inline; " : "display:none; " ;
152+ $ startTag = PLUGIN_ACCORDION_DISPLAY ? "div " : "td " ;
153+ $ contentStyle = ($ this -> isOpened ) ? "display: {$ this -> display }; " : "display:none; " ;
147154 return <<<EOD
148- <td id=acd_content {$ this -> callCount } style=" {$ contentStyle }">
155+ < { $ startTag } id=acd_content {$ this -> callCount } style=" {$ contentStyle }">
149156 EOD ;
150157 }
151158}
0 commit comments