From df025fc2bfa27c775cd523d361f9b13db10d51b7 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Fri, 24 May 2013 01:18:38 +0400 Subject: [PATCH 1/3] jQuery Accordion rework --- framework/yii/jui/Accordion.php | 65 ++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/framework/yii/jui/Accordion.php b/framework/yii/jui/Accordion.php index df9ba20..9b68a7e 100644 --- a/framework/yii/jui/Accordion.php +++ b/framework/yii/jui/Accordion.php @@ -19,13 +19,15 @@ use yii\helpers\Html; * ```php * echo Accordion::widget(array( * 'items' => array( - * 'Section 1' => array( + * array( + * 'header' => 'Section 1', * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', - * 'contentOptions' => array(...), * ), - * 'Section 2' => array( - * 'content' => 'Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus...', + * array( + * 'header' => 'Section 2', * 'headerOptions' => array(...), + * 'content' => 'Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus...', + * 'options' => array(...), * ), * ), * )); @@ -42,12 +44,13 @@ class Accordion extends Widget * section with the following structure: * * ```php - * // item key is the actual section header - * 'Section' => array( + * array( + * // required, the header (HTML) of the section + * 'header' => 'Section label', * // required, the content (HTML) of the section * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', * // optional the HTML attributes of the content section - * 'contentOptions'=> array(...), + * 'options'=> array(...), * // optional the HTML attributes of the header section * 'headerOptions'=> array(...), * ) @@ -62,46 +65,36 @@ class Accordion extends Widget public function run() { echo Html::beginTag('div', $this->options) . "\n"; - echo $this->renderItems() . "\n"; + echo $this->renderSections() . "\n"; echo Html::endTag('div') . "\n"; $this->registerWidget('accordion'); } /** - * Renders collapsible items as specified on [[items]]. + * Renders collapsible sections as specified on [[items]]. * @return string the rendering result. + * @throws InvalidConfigException. */ - public function renderItems() + protected function renderSections() { - $items = array(); - foreach ($this->items as $header => $item) { - $items[] = $this->renderItem($header, $item); - } + $sections = array(); + foreach ($this->items as $item) { + if (!isset($item['header'])) { + throw new InvalidConfigException("The 'header' option is required."); + } - return implode("\n", $items); - } + $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); + $sections[] = Html::tag('h3', $item['header'], $headerOptions); - /** - * Renders a single collapsible item section. - * @param string $header a label of the item section [[items]]. - * @param array $item a single item from [[items]]. - * @return string the rendering result. - * @throws InvalidConfigException. - */ - public function renderItem($header, $item) - { - if (isset($item['content'])) { - $contentOptions = ArrayHelper::getValue($item, 'contentOptions', array()); - $content = Html::tag('div', $item['content']) . "\n"; - } else { - throw new InvalidConfigException("The 'content' option is required."); - } + if (!isset($item['content'])) { + throw new InvalidConfigException("The 'content' option is required."); + } + + $options = ArrayHelper::getValue($item, 'options', array()); + $sections[] = Html::tag('div', $item['content'], $options);; - $group = array(); - $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); - $group[] = Html::tag('h3', $header, $headerOptions); - $group[] = Html::tag('div', $content, $contentOptions); + } - return implode("\n", $group); + return implode("\n", $sections); } } From be82ee81dbcbe4c3dca4914256d7f28e1c505ee6 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Fri, 24 May 2013 01:26:31 +0400 Subject: [PATCH 2/3] Comment fixes --- framework/yii/jui/Accordion.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/yii/jui/Accordion.php b/framework/yii/jui/Accordion.php index 9b68a7e..a4bae15 100644 --- a/framework/yii/jui/Accordion.php +++ b/framework/yii/jui/Accordion.php @@ -49,9 +49,9 @@ class Accordion extends Widget * 'header' => 'Section label', * // required, the content (HTML) of the section * 'content' => 'Mauris mauris ante, blandit et, ultrices a, suscipit eget...', - * // optional the HTML attributes of the content section + * // optional the HTML attributes of the section content container * 'options'=> array(...), - * // optional the HTML attributes of the header section + * // optional the HTML attributes of the section header container * 'headerOptions'=> array(...), * ) * ``` From fb9dbdb236d532820d8924131ef1576559abb892 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Fri, 24 May 2013 01:29:41 +0400 Subject: [PATCH 3/3] Cosmetic code move --- framework/yii/jui/Accordion.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/framework/yii/jui/Accordion.php b/framework/yii/jui/Accordion.php index a4bae15..6c5dd97 100644 --- a/framework/yii/jui/Accordion.php +++ b/framework/yii/jui/Accordion.php @@ -82,17 +82,13 @@ class Accordion extends Widget if (!isset($item['header'])) { throw new InvalidConfigException("The 'header' option is required."); } - - $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); - $sections[] = Html::tag('h3', $item['header'], $headerOptions); - if (!isset($item['content'])) { throw new InvalidConfigException("The 'content' option is required."); } - + $headerOptions = ArrayHelper::getValue($item, 'headerOptions', array()); + $sections[] = Html::tag('h3', $item['header'], $headerOptions); $options = ArrayHelper::getValue($item, 'options', array()); $sections[] = Html::tag('div', $item['content'], $options);; - } return implode("\n", $sections);