From aad5c84f58b5f5bc8ddc1468d064d95c9dfe66c0 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Sun, 26 May 2013 18:26:59 +0400 Subject: [PATCH 1/3] jQuery UI accordion rework --- framework/yii/jui/Accordion.php | 51 +++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/framework/yii/jui/Accordion.php b/framework/yii/jui/Accordion.php index f2e76f6..79ba350 100644 --- a/framework/yii/jui/Accordion.php +++ b/framework/yii/jui/Accordion.php @@ -40,23 +40,20 @@ use yii\helpers\Html; class Accordion extends Widget { /** - * @var array list of sections in the accordion widget. Each array element represents a single - * section with the following structure: - * - * ```php - * 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 section content container - * 'options'=> array(...), - * // optional the HTML attributes of the section header container - * 'headerOptions'=> array(...), - * ) - * ``` + * @var array. + * @todo comments. */ public $items = array(); + /** + * @var array. + * @todo comments. + */ + public $itemOptions = array(); + /** + * @var array. + * @todo comments. + */ + public $headerOptions = array(); /** @@ -64,9 +61,11 @@ class Accordion extends Widget */ public function run() { - echo Html::beginTag('div', $this->options) . "\n"; - echo $this->renderSections() . "\n"; - echo Html::endTag('div') . "\n"; + $options = $this->options; + $tag = ArrayHelper::remove($options, 'tag', 'div'); + echo Html::beginTag($tag, $options) . "\n"; + echo $this->renderItems() . "\n"; + echo Html::endTag($tag) . "\n"; $this->registerWidget('accordion'); } @@ -75,9 +74,9 @@ class Accordion extends Widget * @return string the rendering result. * @throws InvalidConfigException. */ - protected function renderSections() + protected function renderItems() { - $sections = array(); + $items = array(); foreach ($this->items as $item) { if (!isset($item['header'])) { throw new InvalidConfigException("The 'header' option is required."); @@ -85,12 +84,14 @@ class Accordion extends Widget 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);; + $headerOptions = array_merge($this->headerOptions, ArrayHelper::getValue($item, 'headerOptions', array())); + $headerTag = ArrayHelper::remove($headerOptions, 'tag', ArrayHelper::remove($headerOptions, 'tag', 'h3')); + $items[] = Html::tag($headerTag, $item['header'], $headerOptions); + $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', array())); + $tag = ArrayHelper::remove($options, 'tag', ArrayHelper::remove($options, 'tag', 'div')); + $items[] = Html::tag($tag, $item['content'], $options);; } - return implode("\n", $sections); + return implode("\n", $items); } } From 645969769e9fff642cef1483cfb585eb371ca730 Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Sun, 26 May 2013 18:47:28 +0400 Subject: [PATCH 2/3] Overcoding removed ;) --- 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 79ba350..e12972a 100644 --- a/framework/yii/jui/Accordion.php +++ b/framework/yii/jui/Accordion.php @@ -85,10 +85,10 @@ class Accordion extends Widget throw new InvalidConfigException("The 'content' option is required."); } $headerOptions = array_merge($this->headerOptions, ArrayHelper::getValue($item, 'headerOptions', array())); - $headerTag = ArrayHelper::remove($headerOptions, 'tag', ArrayHelper::remove($headerOptions, 'tag', 'h3')); + $headerTag = ArrayHelper::remove($headerOptions, 'tag', 'h3'); $items[] = Html::tag($headerTag, $item['header'], $headerOptions); $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'options', array())); - $tag = ArrayHelper::remove($options, 'tag', ArrayHelper::remove($options, 'tag', 'div')); + $tag = ArrayHelper::remove($options, 'tag', 'div'); $items[] = Html::tag($tag, $item['content'], $options);; } From 8582f46d1abf0b279d1abc325a795adb565b242b Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Sun, 26 May 2013 19:15:36 +0400 Subject: [PATCH 3/3] Example from comments changed --- framework/yii/jui/Accordion.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/framework/yii/jui/Accordion.php b/framework/yii/jui/Accordion.php index e12972a..1a83f28 100644 --- a/framework/yii/jui/Accordion.php +++ b/framework/yii/jui/Accordion.php @@ -25,11 +25,27 @@ use yii\helpers\Html; * ), * array( * 'header' => 'Section 2', - * 'headerOptions' => array(...), + * 'headerOptions' => array( + * 'tag' => 'h3', + * ), * 'content' => 'Sed non urna. Phasellus eu ligula. Vestibulum sit amet purus...', - * 'options' => array(...), + * 'options' => array( + * 'tag' => 'div', + * ), * ), * ), + * 'options' => array( + * 'tag' => 'div', + * ), + * 'itemOptions' => array( + * 'tag' => 'div', + * ), + * 'headerOptions' => array( + * 'tag' => 'h3', + * ), + * 'clientOptions' => array( + * 'collapsible' => false, + * ), * )); * ``` * @@ -40,18 +56,15 @@ use yii\helpers\Html; class Accordion extends Widget { /** - * @var array. - * @todo comments. + * @var array list of collapsible sections. */ public $items = array(); /** - * @var array. - * @todo comments. + * @var array list of individual collabsible section default options. */ public $itemOptions = array(); /** - * @var array. - * @todo comments. + * @var array list of individual collabsible section header default options. */ public $headerOptions = array();