Skip to content

Commit

Permalink
Fix #19: Enhance header, closeButton, and toggleButton renderin…
Browse files Browse the repository at this point in the history
…g validation
  • Loading branch information
kartik-v committed Sep 22, 2017
1 parent 58837d6 commit e3b5d91
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
6 changes: 5 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
Change Log: `yii2-popover-x`
============================

## Version 1.3.4
## Version 1.3.5

**Date:** 22-Sep-2017

- (enh #19): Enhance `header`, `closeButton`, and `toggleButton` rendering validation.

**Date:** 08-Sep-2017

Expand Down
80 changes: 38 additions & 42 deletions PopoverX.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,43 +197,42 @@ public function runWidget()
}

/**
* Renders the header HTML markup of the popover dialog.
* Renders the opening tag of the popover dialog body.
*
* @return string the rendering result
*/
protected function renderHeader()
protected function renderBodyBegin()
{
$button = $this->renderCloseButton();
if ($button !== null) {
$this->header = $button . "\n" . $this->header;
}
if (!empty($this->header)) {
$tag = ArrayHelper::remove($this->headerOptions, 'tag', 'div');
Html::addCssClass($this->headerOptions, ['popover-header', 'popover-title']);
return Html::tag($tag, "\n" . $this->header . "\n", $this->headerOptions);
} else {
return null;
}
return Html::beginTag('div', ['class' => 'popover-body popover-content']);
}

/**
* Renders the opening tag of the popover dialog body.
* Renders the closing tag of the popover dialog body.
*
* @return string the rendering result
*/
protected function renderBodyBegin()
protected function renderBodyEnd()
{
return Html::beginTag('div', ['class' => 'popover-body popover-content']);
return $this->content . "\n" . Html::endTag('div');
}

/**
* Renders the closing tag of the popover dialog body.
* Renders the header HTML markup of the popover dialog.
*
* @return string the rendering result
*/
protected function renderBodyEnd()
protected function renderHeader()
{
return $this->content . "\n" . Html::endTag('div');
$button = $this->renderCloseButton();
if ($button !== '') {
$this->header = $button . "\n" . (empty($this->header) ? '' : $this->header);
}
if (empty($this->header)) {
return '';
}
$tag = ArrayHelper::remove($this->headerOptions, 'tag', 'div');
Html::addCssClass($this->headerOptions, ['popover-header', 'popover-title']);
return Html::tag($tag, "\n" . $this->header . "\n", $this->headerOptions);
}

/**
Expand All @@ -243,13 +242,12 @@ protected function renderBodyEnd()
*/
protected function renderFooter()
{
if (!empty($this->footer)) {
$tag = ArrayHelper::remove($this->footerOptions, 'tag', 'div');
Html::addCssClass($this->footerOptions, 'popover-footer');
return Html::tag($tag, "\n" . $this->footer . "\n", $this->footerOptions);
} else {
if (empty($this->footer)) {
return '';
}
$tag = ArrayHelper::remove($this->footerOptions, 'tag', 'div');
Html::addCssClass($this->footerOptions, 'popover-footer');
return Html::tag($tag, "\n" . $this->footer . "\n", $this->footerOptions);
}

/**
Expand All @@ -259,16 +257,15 @@ protected function renderFooter()
*/
protected function renderToggleButton()
{
if ($this->toggleButton !== null) {
$tag = ArrayHelper::remove($this->toggleButton, 'tag', 'button');
$label = ArrayHelper::remove($this->toggleButton, 'label', 'Show');
if ($tag === 'button' && !isset($this->toggleButton['type'])) {
$this->toggleButton['type'] = 'button';
}
return Html::tag($tag, $label, $this->toggleButton);
} else {
if (!is_array($this->toggleButton) || empty($this->toggleButton)) {
return '';
}
$tag = ArrayHelper::remove($this->toggleButton, 'tag', 'button');
$label = ArrayHelper::remove($this->toggleButton, 'label', 'Show');
if ($tag === 'button' && !isset($this->toggleButton['type'])) {
$this->toggleButton['type'] = 'button';
}
return Html::tag($tag, $label, $this->toggleButton);
}

/**
Expand All @@ -278,16 +275,15 @@ protected function renderToggleButton()
*/
protected function renderCloseButton()
{
if ($this->closeButton !== null) {
$tag = ArrayHelper::remove($this->closeButton, 'tag', 'button');
$label = ArrayHelper::remove($this->closeButton, 'label', '×');
if ($tag === 'button' && !isset($this->closeButton['type'])) {
$this->closeButton['type'] = 'button';
}
return Html::tag($tag, $label, $this->closeButton);
} else {
if (!is_array($this->toggleButton) || empty($this->closeButton)) {
return '';
}
$tag = ArrayHelper::remove($this->closeButton, 'tag', 'button');
$label = ArrayHelper::remove($this->closeButton, 'label', '×');
if ($tag === 'button' && !isset($this->closeButton['type'])) {
$this->closeButton['type'] = 'button';
}
return Html::tag($tag, $label, $this->closeButton);
}

/**
Expand All @@ -307,14 +303,14 @@ protected function initOptions()
if ($this->pluginOptions !== false) {
$this->pluginOptions = ArrayHelper::merge($this->pluginOptions, ['show' => false]);
}
if ($this->closeButton !== null) {
if ($this->closeButton !== null && is_array($this->closeButton)) {
$this->closeButton = ArrayHelper::merge($this->closeButton, [
'data-dismiss' => 'popover-x',
'aria-hidden' => 'true',
'class' => 'close',
]);
}
if ($this->toggleButton !== null) {
if ($this->toggleButton !== null && is_array($this->toggleButton)) {
$this->toggleButton = ArrayHelper::merge($this->toggleButton, [
'data-toggle' => 'popover-x',
'data-placement' => $this->placement
Expand Down

0 comments on commit e3b5d91

Please sign in to comment.