Skip to content

Commit

Permalink
Added modal subhead
Browse files Browse the repository at this point in the history
  • Loading branch information
jirisvoboda committed Oct 1, 2015
1 parent 6d55ce4 commit 3e103be
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions widgets/Modal.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @copyright Copyright (c) 2014 icron.org
* @license http://yii2metronic.icron.org/license.html
Expand Down Expand Up @@ -44,6 +43,11 @@ class Modal extends Widget {
*/
public $title;

/**
* @var string the subtitle in the modal window.
*/
public $subtitle;

/**
* @var string the footer content in the modal window.
*/
Expand Down Expand Up @@ -89,20 +93,20 @@ public function init()

$this->initOptions();

echo $this->renderToggleButton() . "\n";
echo Html::beginTag('div', $this->options) . "\n";
echo $this->renderHeader() . "\n";
echo $this->renderBodyBegin() . "\n";
echo $this->renderToggleButton()."\n";
echo Html::beginTag('div', $this->options)."\n";
echo $this->renderHeader()."\n";
echo $this->renderBodyBegin()."\n";
}

/**
* Renders the widget.
*/
public function run()
{
echo "\n" . $this->renderBodyEnd();
echo "\n" . $this->renderFooter();
echo "\n" . Html::endTag('div');
echo "\n".$this->renderBodyEnd();
echo "\n".$this->renderFooter();
echo "\n".Html::endTag('div');

ModalAsset::register($this->view);
//$this->registerPlugin('spinner');
Expand All @@ -114,14 +118,28 @@ public function run()
*/
protected function renderHeader()
{
$html = '';

$button = $this->renderCloseButton();

if ($button !== null)
{
$this->title = $button . "\n" . Html::tag('h4', $this->title, ['class' => 'modal-title']);
$html = $button;
}

if ($this->title !== null)
{
return Html::tag('div', "\n" . $this->title . "\n", ['class' => 'modal-header']);
$html .= Html::tag('h4', $this->title, ['class' => 'modal-title']);
}

if ($this->subtitle !== null)
{
$html .= Html::tag('p', $this->subtitle, ['class' => 'modal-subtitle']);
}

if ($html)
{
return Html::tag('div', "\n".$html."\n", ['class' => 'modal-header']);
}
else
{
Expand Down Expand Up @@ -155,7 +173,7 @@ protected function renderFooter()
{
if ($this->footer !== null)
{
return Html::tag('div', "\n" . $this->footer . "\n", ['class' => 'modal-footer']);
return Html::tag('div', "\n".$this->footer."\n", ['class' => 'modal-footer']);
}
else
{
Expand Down Expand Up @@ -210,7 +228,7 @@ protected function initOptions()
$this->options = array_merge([
'class' => 'fade',
'tabindex' => -1,
], $this->options);
], $this->options);
Html::addCssClass($this->options, 'modal');
if ($this->fullWidth)
{
Expand All @@ -231,19 +249,18 @@ protected function initOptions()
'data-dismiss' => 'modal',
'aria-hidden' => 'true',
'class' => 'close',
], $this->closeButton);
], $this->closeButton);
}

if (!empty($this->toggleButton))
{
$this->toggleButton = array_merge([
'options' => ['data-toggle' => 'modal'],
], $this->toggleButton);
], $this->toggleButton);
if (!isset($this->toggleButton['options']['data-target']) && !isset($this->toggleButton['options']['href']))
{
$this->toggleButton['options']['data-target'] = '#' . $this->options['id'];
$this->toggleButton['options']['data-target'] = '#'.$this->options['id'];
}
}
}

}
}

0 comments on commit 3e103be

Please sign in to comment.