diff --git a/forms/ToggleCompositeField.php b/forms/ToggleCompositeField.php index 8231c2d62..225c222dd 100644 --- a/forms/ToggleCompositeField.php +++ b/forms/ToggleCompositeField.php @@ -1,4 +1,5 @@ name = $name; $this->title = $title; @@ -24,30 +29,46 @@ class ToggleCompositeField extends CompositeField { parent::__construct($children); } + /** + * @param array $properties + * + * @return HTMLText + */ public function FieldHolder($properties = array()) { Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-ui/jquery-ui.js'); Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js'); Requirements::javascript(FRAMEWORK_DIR . '/javascript/ToggleCompositeField.js'); + Requirements::css(FRAMEWORK_DIR . '/thirdparty/jquery-ui-themes/smoothness/jquery.ui.css'); - $obj = $properties ? $this->customise($properties) : $this; - return $obj->renderWith($this->getTemplates()); + $context = $this; + + if(count($properties)) { + $context = $this->customise($properties); + } + + return $context->renderWith($this->getTemplates()); } + /** + * {@inheritdoc} + */ public function getAttributes() { + $attributes = array( + 'id' => $this->id(), + 'class' => $this->extraClass(), + ); + if($this->getStartClosed()) { - $class = 'ss-toggle ss-toggle-start-closed'; + $attributes['class'] .= ' ss-toggle ss-toggle-start-closed'; } else { - $class = 'ss-toggle'; + $attributes['class'] .= ' ss-toggle'; } return array_merge( $this->attributes, - array( - 'id' => $this->id(), - 'class' => $class . ' ' . $this->extraClass() - ) + $attributes ); } @@ -59,13 +80,15 @@ class ToggleCompositeField extends CompositeField { } /** - * Controls whether the field is open or closed by default. By default the - * field is closed. + * Controls whether the field is open or closed by default. By default the field is closed. * - * @param bool $bool + * @param bool $startClosed + * + * @return $this */ - public function setStartClosed($bool) { - $this->startClosed = (bool) $bool; + public function setStartClosed($startClosed) { + $this->startClosed = (bool) $startClosed; + return $this; } @@ -77,12 +100,13 @@ class ToggleCompositeField extends CompositeField { } /** - * @param int $level + * @param int $headingLevel + * + * @return $this */ - public function setHeadingLevel($level) { - $this->headingLevel = $level; + public function setHeadingLevel($headingLevel) { + $this->headingLevel = $headingLevel; + return $this; } - } -