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 --- .../oojs/oojs-ui/php/widgets/TextInputWidget.php | 151 +++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 vendor/oojs/oojs-ui/php/widgets/TextInputWidget.php (limited to 'vendor/oojs/oojs-ui/php/widgets/TextInputWidget.php') diff --git a/vendor/oojs/oojs-ui/php/widgets/TextInputWidget.php b/vendor/oojs/oojs-ui/php/widgets/TextInputWidget.php new file mode 100644 index 00000000..a5f31f74 --- /dev/null +++ b/vendor/oojs/oojs-ui/php/widgets/TextInputWidget.php @@ -0,0 +1,151 @@ + false, + 'autofocus' => false, + 'required' => false, + ), $config ); + + // Parent constructor + parent::__construct( $config ); + + // Properties + $this->multiline = isset( $config['multiline'] ) ? (bool)$config['multiline'] : false; + + // Mixins + $this->mixin( new IconElement( $this, $config ) ); + $this->mixin( new IndicatorElement( $this, $config ) ); + + // Initialization + $this + ->addClasses( array( 'oo-ui-textInputWidget' ) ) + ->appendContent( $this->icon, $this->indicator ); + $this->setReadOnly( $config['readOnly'] ); + if ( isset( $config['placeholder'] ) ) { + $this->input->setAttributes( array( 'placeholder' => $config['placeholder'] ) ); + } + if ( isset( $config['maxLength'] ) ) { + $this->input->setAttributes( array( 'maxlength' => $config['maxLength'] ) ); + } + if ( $config['autofocus'] ) { + $this->input->setAttributes( array( 'autofocus' => 'autofocus' ) ); + } + if ( $config['required'] ) { + $this->input->setAttributes( array( 'required' => 'required', 'aria-required' => 'true' ) ); + } + } + + /** + * Check if the widget is read-only. + * + * @return boolean + */ + public function isReadOnly() { + return $this->readOnly; + } + + /** + * Set the read-only state of the widget. This should probably change the widget's appearance and + * prevent it from being used. + * + * @param boolean $state Make input read-only + * @chainable + */ + public function setReadOnly( $state ) { + $this->readOnly = (bool)$state; + if ( $this->readOnly ) { + $this->input->setAttributes( array( 'readonly' => 'readonly' ) ); + } else { + $this->input->removeAttributes( array( 'readonly' ) ); + } + return $this; + } + + protected function getInputElement( $config ) { + if ( isset( $config['multiline'] ) && $config['multiline'] ) { + return new Tag( 'textarea' ); + } else { + $type = isset( $config['type'] ) ? $config['type'] : 'text'; + $input = new Tag( 'input' ); + $input->setAttributes( array( 'type' => $type ) ); + return $input; + } + } + + /** + * Check if input supports multiple lines. + * + * @return boolean + */ + public function isMultiline() { + return (bool)$this->multiline; + } + + public function getConfig( &$config ) { + if ( $this->isMultiline() ) { + $config['multiline'] = true; + } else { + $type = $this->input->getAttribute( 'type' ); + if ( $type !== 'text' ) { + $config['type'] = $type; + } + } + if ( $this->isReadOnly() ) { + $config['readOnly'] = true; + } + $placeholder = $this->input->getAttribute( 'placeholder' ); + if ( $placeholder !== null ) { + $config['placeholder'] = $placeholder; + } + $maxlength = $this->input->getAttribute( 'maxlength' ); + if ( $maxlength !== null ) { + $config['maxLength'] = $maxlength; + } + $autofocus = $this->input->getAttribute( 'autofocus' ); + if ( $autofocus !== null ) { + $config['autofocus'] = true; + } + $required = $this->input->getAttribute( 'required' ); + $ariarequired = $this->input->getAttribute( 'aria-required' ); + if ( ( $required !== null ) || ( $ariarequired !== null ) ) { + $config['required'] = true; + } + return parent::getConfig( $config ); + } +} -- cgit v1.2.3-54-g00ecf