diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:15:42 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:44:51 +0100 |
commit | a1789ddde42033f1b05cc4929491214ee6e79383 (patch) | |
tree | 63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/oojs/oojs-ui/php/mixins/LabelElement.php | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/oojs/oojs-ui/php/mixins/LabelElement.php')
-rw-r--r-- | vendor/oojs/oojs-ui/php/mixins/LabelElement.php | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/vendor/oojs/oojs-ui/php/mixins/LabelElement.php b/vendor/oojs/oojs-ui/php/mixins/LabelElement.php new file mode 100644 index 00000000..d5cf7bee --- /dev/null +++ b/vendor/oojs/oojs-ui/php/mixins/LabelElement.php @@ -0,0 +1,77 @@ +<?php + +namespace OOUI; + +/** + * Element containing a label. + * + * @abstract + */ +class LabelElement extends ElementMixin { + /** + * Label value. + * + * @var string|HtmlSnippet|null + */ + protected $label = null; + + public static $targetPropertyName = 'label'; + + /** + * @param Element $element Element being mixed into + * @param array $config Configuration options + * @param string|HtmlSnippet $config['label'] Label text + */ + public function __construct( Element $element, array $config = array() ) { + // Parent constructor + // FIXME 'labelElement' is a very stupid way to call '$label' + $target = isset( $config['labelElement'] ) ? $config['labelElement'] : new Tag( 'span' ); + parent::__construct( $element, $target, $config ); + + // Initialization + $this->target->addClasses( array( 'oo-ui-labelElement-label' ) ); + $this->setLabel( isset( $config['label'] ) ? $config['label'] : null ); + } + + /** + * Set the label. + * + * An empty string will result in the label being hidden. A string containing only whitespace will + * be converted to a single ` `. + * + * @param string|HtmlSnippet|null $label Label text + * @chainable + */ + public function setLabel( $label ) { + $this->label = $label; + + $this->target->clearContent(); + if ( $this->label !== null ) { + if ( is_string( $this->label ) && $this->label !== '' && trim( $this->label ) === '' ) { + $this->target->appendContent( new HtmlSnippet( ' ' ) ); + } else { + $this->target->appendContent( $label ); + } + } + + $this->element->toggleClasses( array( 'oo-ui-labelElement' ), !!$this->label ); + + return $this; + } + + /** + * Get the label. + * + * @return string|HtmlSnippet|null Label text + */ + public function getLabel() { + return $this->label; + } + + public function getConfig( &$config ) { + if ( $this->label !== null ) { + $config['label'] = $this->label; + } + return parent::getConfig( $config ); + } +} |