diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
commit | 6dc1997577fab2c366781fd7048144935afa0012 (patch) | |
tree | 8918d28c7ab4342f0738985e37af1dfc42d0e93a /vendor/oojs/oojs-ui/php/mixins/IconElement.php | |
parent | 150f94f051128f367bc89f6b7e5f57eb2a69fc62 (diff) | |
parent | fa89acd685cb09cdbe1c64cbb721ec64975bbbc1 (diff) |
Merge commit 'fa89acd'
# Conflicts:
# .gitignore
# extensions/ArchInterWiki.sql
Diffstat (limited to 'vendor/oojs/oojs-ui/php/mixins/IconElement.php')
-rw-r--r-- | vendor/oojs/oojs-ui/php/mixins/IconElement.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/vendor/oojs/oojs-ui/php/mixins/IconElement.php b/vendor/oojs/oojs-ui/php/mixins/IconElement.php new file mode 100644 index 00000000..b6d27376 --- /dev/null +++ b/vendor/oojs/oojs-ui/php/mixins/IconElement.php @@ -0,0 +1,76 @@ +<?php + +namespace OOUI; + +/** + * Element containing an icon. + * + * Icons are graphics, about the size of normal text. They can be used to aid the user in locating + * a control or convey information in a more space efficient way. Icons should rarely be used + * without labels; such as in a toolbar where space is at a premium or within a context where the + * meaning is very clear to the user. + * + * @abstract + */ +class IconElement extends ElementMixin { + /** + * Symbolic icon name. + * + * @var string + */ + protected $icon = null; + + public static $targetPropertyName = 'icon'; + + /** + * @param Element $element Element being mixed into + * @param array $config Configuration options + * @param string $config['icon'] Symbolic icon name + */ + public function __construct( Element $element, array $config = array() ) { + // Parent constructor + // FIXME 'iconElement' is a very stupid way to call '$icon' + $target = isset( $config['iconElement'] ) ? $config['iconElement'] : new Tag( 'span' ); + parent::__construct( $element, $target, $config ); + + // Initialization + $this->target->addClasses( array( 'oo-ui-iconElement-icon' ) ); + $this->setIcon( isset( $config['icon'] ) ? $config['icon'] : null ); + } + + /** + * Set icon name. + * + * @param string|null $icon Symbolic icon name + * @chainable + */ + public function setIcon( $icon = null ) { + if ( $this->icon !== null ) { + $this->target->removeClasses( array( 'oo-ui-icon-' . $this->icon ) ); + } + if ( $icon !== null ) { + $this->target->addClasses( array( 'oo-ui-icon-' . $icon ) ); + } + + $this->icon = $icon; + $this->element->toggleClasses( array( 'oo-ui-iconElement' ), (bool)$this->icon ); + + return $this; + } + + /** + * Get icon name. + * + * @return string Icon name + */ + public function getIcon() { + return $this->icon; + } + + public function getConfig( &$config ) { + if ( $this->icon !== null ) { + $config['icon'] = $this->icon; + } + return parent::getConfig( $config ); + } +} |