diff --git a/src/MyCLabs/MUIH/Collapse.php b/src/MyCLabs/MUIH/Collapse.php index 2597f8f..3752446 100644 --- a/src/MyCLabs/MUIH/Collapse.php +++ b/src/MyCLabs/MUIH/Collapse.php @@ -50,7 +50,7 @@ public function __construct($id='', $title=null, $content=null) { $this->addClass('collapse-wrapper'); - $this->link = new GenericTag('a', $title); + $this->link = new GenericTag('a'); $this->link->setAttribute('data-toggle', 'collapse'); $this->title = new GenericTag('legend', $this->link); @@ -61,6 +61,8 @@ public function __construct($id='', $title=null, $content=null) $this->setCollapseStateIndicators(); parent::__construct('fieldset', $content); + + $this->setTitleContent($title); } /** diff --git a/src/MyCLabs/MUIH/Modal.php b/src/MyCLabs/MUIH/Modal.php index 2284087..63de075 100644 --- a/src/MyCLabs/MUIH/Modal.php +++ b/src/MyCLabs/MUIH/Modal.php @@ -8,6 +8,7 @@ */ class Modal extends GenericTag { + public static $defaultDismiss = ''; /** * @var GenericTag @@ -39,15 +40,16 @@ class Modal extends GenericTag * @param string $content * @param string $header * @param string $footer + * @param bool $withDismissButton */ - public function __construct($content=null, $header=null, $footer=null) + public function __construct($content=null, $header=null, $footer=null, $withDismissButton=true) { $this->addClass('modal'); - $this->header = new GenericTag('div', $header); + $this->header = new GenericTag('div'); $this->header->addClass('modal-header'); - $this->footer = new GenericTag('div', $footer); + $this->footer = new GenericTag('div'); $this->footer->addClass('modal-footer'); $this->body = new GenericTag('div'); @@ -61,6 +63,16 @@ public function __construct($content=null, $header=null, $footer=null) parent::__construct('div', $content); + + if ($header !== null) { + $this->addTitle($header); + } + if ($footer !== null) { + $this->setFooterContent($footer); + } + if ($header !== null && $withDismissButton) { + $this->addDefaultDismissButton(); + } } /** @@ -187,6 +199,41 @@ public function getContentAsString() return (string) $modalDialog; } + /** + * @return $this + */ + public function addDefaultDismissButton() + { + $this->getHeader()->prependContent(self::$defaultDismiss); + + return $this; + } + + /** + * @param GenericTag|string $dismissButton + * @return $this + */ + public function addDismissButton($dismissButton) + { + $this->getHeader()->prependContent($dismissButton); + + return $this; + } + + /** + * @param string $title + * @param string $level + * @return $this + */ + public function addTitle($title, $level='h4') + { + $titleWrapper = new GenericTag($level, $title); + $titleWrapper->addClass('modal-title'); + $this->getHeader()->appendContent($titleWrapper); + + return $this; + } + /** * @param bool $replaceBodyOnly * @return $this diff --git a/src/MyCLabs/MUIH/Panel.php b/src/MyCLabs/MUIH/Panel.php index afff0f4..8c185de 100644 --- a/src/MyCLabs/MUIH/Panel.php +++ b/src/MyCLabs/MUIH/Panel.php @@ -50,16 +50,23 @@ public function __construct($content=null, $header=null, $footer=null, $type=se } $this->addClass('panel-' . $type); - $this->header = new GenericTag('div', $header); + $this->header = new GenericTag('div'); $this->header->addClass('panel-header'); - $this->footer = new GenericTag('div', $footer); + $this->footer = new GenericTag('div'); $this->footer->addClass('panel-footer'); $this->content= new GenericTag('div'); $this->content->addClass('panel-body'); parent::__construct('div', $content); + + if ($header !== null) { + $this->addTitle($header); + } + if ($footer !== null) { + $this->setFooterContent($footer); + } } /** @@ -168,4 +175,18 @@ public function getContentAsString() return $content; } + + /** + * @param string $title + * @param string $level + * @return $this + */ + public function addTitle($title, $level='h3') + { + $titleWrapper = new GenericTag($level, $title); + $titleWrapper->addClass('panel-title'); + $this->getHeader()->appendContent($titleWrapper); + + return $this; + } } diff --git a/tests/MUIHTest/MUIH/ModalTest.php b/tests/MUIHTest/MUIH/ModalTest.php index 60275bc..e2a2555 100644 --- a/tests/MUIHTest/MUIH/ModalTest.php +++ b/tests/MUIHTest/MUIH/ModalTest.php @@ -35,7 +35,27 @@ public function testConstructor() '