From f6d65e533c62f6deb21342d4901ece24497b433e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 4 Jun 2015 07:31:04 +0200 Subject: Update to MediaWiki 1.25.1 --- vendor/oojs/oojs-ui/php/widgets/InputWidget.php | 144 ++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 vendor/oojs/oojs-ui/php/widgets/InputWidget.php (limited to 'vendor/oojs/oojs-ui/php/widgets/InputWidget.php') diff --git a/vendor/oojs/oojs-ui/php/widgets/InputWidget.php b/vendor/oojs/oojs-ui/php/widgets/InputWidget.php new file mode 100644 index 00000000..234d3145 --- /dev/null +++ b/vendor/oojs/oojs-ui/php/widgets/InputWidget.php @@ -0,0 +1,144 @@ +input = $this->getInputElement( $config ); + + // Mixins + $this->mixin( new FlaggedElement( $this, + array_merge( $config, array( 'flagged' => $this ) ) ) ); + $this->mixin( new TabIndexedElement( $this, + array_merge( $config, array( 'tabIndexed' => $this->input ) ) ) ); + + // Initialization + if ( isset( $config['name'] ) ) { + $this->input->setAttributes( array( 'name' => $config['name'] ) ); + } + if ( $this->isDisabled() ) { + $this->input->setAttributes( array( 'disabled' => 'disabled' ) ); + } + $this + ->addClasses( array( 'oo-ui-inputWidget' ) ) + ->appendContent( $this->input ); + $this->appendContent( new Tag( 'span' ) ); + $this->setValue( isset( $config['value'] ) ? $config['value'] : null ); + } + + /** + * Get input element. + * + * @param array $config Configuration options + * @return Tag Input element + */ + protected function getInputElement( $config ) { + return new Tag( 'input' ); + } + + /** + * Get the value of the input. + * + * @return string Input value + */ + public function getValue() { + return $this->value; + } + + /** + * Sets the direction of the current input, either RTL or LTR + * + * @param boolean $isRTL + */ + public function setRTL( $isRTL ) { + if ( $isRTL ) { + $this->input->removeClasses( array( 'oo-ui-ltr' ) ); + $this->input->addClasses( array( 'oo-ui-rtl' ) ); + } else { + $this->input->removeClasses( array( 'oo-ui-rtl' ) ); + $this->input->addClasses( array( 'oo-ui-ltr' ) ); + } + } + + /** + * Set the value of the input. + * + * @param string $value New value + * @chainable + */ + public function setValue( $value ) { + $this->value = $this->cleanUpValue( $value ); + $this->input->setValue( $this->value ); + return $this; + } + + /** + * Clean up incoming value. + * + * Ensures value is a string, and converts null to empty string. + * + * @param string $value Original value + * @return string Cleaned up value + */ + protected function cleanUpValue( $value ) { + if ( $value === null ) { + return ''; + } else { + return (string)$value; + } + } + + public function setDisabled( $state ) { + parent::setDisabled( $state ); + if ( isset( $this->input ) ) { + if ( $this->isDisabled() ) { + $this->input->setAttributes( array( 'disabled' => 'disabled' ) ); + } else { + $this->input->removeAttributes( array( 'disabled' ) ); + } + } + return $this; + } + + public function getConfig( &$config ) { + $name = $this->input->getAttribute( 'name' ); + if ( $name !== null ) { + $config['name'] = $name; + } + if ( $this->value !== '' ) { + $config['value'] = $this->value; + } + return parent::getConfig( $config ); + } +} -- cgit v1.2.3-54-g00ecf