diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-06-04 07:31:04 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-06-04 07:58:39 +0200 |
commit | f6d65e533c62f6deb21342d4901ece24497b433e (patch) | |
tree | f28adf0362d14bcd448f7b65a7aaf38650f923aa /vendor/oojs/oojs-ui/php/layouts | |
parent | c27b2e832fe25651ef2410fae85b41072aae7519 (diff) |
Update to MediaWiki 1.25.1
Diffstat (limited to 'vendor/oojs/oojs-ui/php/layouts')
-rw-r--r-- | vendor/oojs/oojs-ui/php/layouts/FieldLayout.php | 140 | ||||
-rw-r--r-- | vendor/oojs/oojs-ui/php/layouts/FieldsetLayout.php | 32 | ||||
-rw-r--r-- | vendor/oojs/oojs-ui/php/layouts/FormLayout.php | 47 | ||||
-rw-r--r-- | vendor/oojs/oojs-ui/php/layouts/PanelLayout.php | 61 |
4 files changed, 280 insertions, 0 deletions
diff --git a/vendor/oojs/oojs-ui/php/layouts/FieldLayout.php b/vendor/oojs/oojs-ui/php/layouts/FieldLayout.php new file mode 100644 index 00000000..ef0d4c6c --- /dev/null +++ b/vendor/oojs/oojs-ui/php/layouts/FieldLayout.php @@ -0,0 +1,140 @@ +<?php + +namespace OOUI; + +/** + * Layout made of a field and optional label. + * + * Available label alignment modes include: + * - left: Label is before the field and aligned away from it, best for when the user will be + * scanning for a specific label in a form with many fields + * - right: Label is before the field and aligned toward it, best for forms the user is very + * familiar with and will tab through field checking quickly to verify which field they are in + * - top: Label is before the field and above it, best for when the user will need to fill out all + * fields from top to bottom in a form with few fields + * - inline: Label is after the field and aligned toward it, best for small boolean fields like + * checkboxes or radio buttons + */ +class FieldLayout extends Layout { + + /** + * Alignment. + * + * @var string + */ + protected $align; + + /** + * Field widget to be laid out. + * + * @var Widget + */ + protected $fieldWidget; + + private $field, $body, $help; + + /** + * @param Widget $fieldWidget Field widget + * @param array $config Configuration options + * @param string $config['align'] Alignment mode, either 'left', 'right', 'top' or 'inline' + * (default: 'left') + * @param string $config['help'] Explanatory text shown as a '?' icon. + */ + public function __construct( $fieldWidget, array $config = array() ) { + // Allow passing positional parameters inside the config array + if ( is_array( $fieldWidget ) && isset( $fieldWidget['fieldWidget'] ) ) { + $config = $fieldWidget; + $fieldWidget = $config['fieldWidget']; + } + + $hasInputWidget = $fieldWidget instanceof InputWidget; + + // Config initialization + $config = array_merge( array( 'align' => 'left' ), $config ); + + // Parent constructor + parent::__construct( $config ); + + // Properties + $this->fieldWidget = $fieldWidget; + $this->field = new Tag( 'div' ); + $this->body = new Tag( $hasInputWidget ? 'label' : 'div' ); + if ( isset( $config['help'] ) ) { + $this->help = new ButtonWidget( array( + 'classes' => array( 'oo-ui-fieldLayout-help' ), + 'framed' => false, + 'icon' => 'info', + 'title' => $config['help'], + ) ); + } else { + $this->help = ''; + } + + // Mixins + $this->mixin( new LabelElement( $this, $config ) ); + + // Initialization + $this + ->addClasses( array( 'oo-ui-fieldLayout' ) ) + ->appendContent( $this->help, $this->body ); + $this->body->addClasses( array( 'oo-ui-fieldLayout-body' ) ); + $this->field + ->addClasses( array( 'oo-ui-fieldLayout-field' ) ) + ->toggleClasses( array( 'oo-ui-fieldLayout-disable' ), $this->fieldWidget->isDisabled() ) + ->appendContent( $this->fieldWidget ); + + $this->setAlignment( $config['align'] ); + } + + /** + * Get the field. + * + * @return Widget Field widget + */ + public function getField() { + return $this->fieldWidget; + } + + /** + * Set the field alignment mode. + * + * @param string $value Alignment mode, either 'left', 'right', 'top' or 'inline' + * @chainable + */ + protected function setAlignment( $value ) { + if ( $value !== $this->align ) { + // Default to 'left' + if ( !in_array( $value, array( 'left', 'right', 'top', 'inline' ) ) ) { + $value = 'left'; + } + // Reorder elements + $this->body->clearContent(); + if ( $value === 'inline' ) { + $this->body->appendContent( $this->field, $this->label ); + } else { + $this->body->appendContent( $this->label, $this->field ); + } + // Set classes. The following classes can be used here: + // * oo-ui-fieldLayout-align-left + // * oo-ui-fieldLayout-align-right + // * oo-ui-fieldLayout-align-top + // * oo-ui-fieldLayout-align-inline + if ( $this->align ) { + $this->removeClasses( array( 'oo-ui-fieldLayout-align-' . $this->align ) ); + } + $this->addClasses( array( 'oo-ui-fieldLayout-align-' . $value ) ); + $this->align = $value; + } + + return $this; + } + + public function getConfig( &$config ) { + $config['fieldWidget'] = $this->fieldWidget; + $config['align'] = $this->align; + if ( $this->help !== '' ) { + $config['help'] = $this->help->getTitle(); + } + return parent::getConfig( $config ); + } +} diff --git a/vendor/oojs/oojs-ui/php/layouts/FieldsetLayout.php b/vendor/oojs/oojs-ui/php/layouts/FieldsetLayout.php new file mode 100644 index 00000000..f9faa353 --- /dev/null +++ b/vendor/oojs/oojs-ui/php/layouts/FieldsetLayout.php @@ -0,0 +1,32 @@ +<?php + +namespace OOUI; + +/** + * Layout made of a fieldset and optional legend. + * + * Just add FieldLayout items. + */ +class FieldsetLayout extends Layout { + /** + * @param array $config Configuration options + * @param FieldLayout[] $config['items'] Items to add + */ + public function __construct( array $config = array() ) { + // Parent constructor + parent::__construct( $config ); + + // Mixins + $this->mixin( new IconElement( $this, $config ) ); + $this->mixin( new LabelElement( $this, $config ) ); + $this->mixin( new GroupElement( $this, $config ) ); + + // Initialization + $this + ->addClasses( array( 'oo-ui-fieldsetLayout' ) ) + ->prependContent( $this->icon, $this->label, $this->group ); + if ( isset( $config['items'] ) ) { + $this->addItems( $config['items'] ); + } + } +} diff --git a/vendor/oojs/oojs-ui/php/layouts/FormLayout.php b/vendor/oojs/oojs-ui/php/layouts/FormLayout.php new file mode 100644 index 00000000..ebeb89de --- /dev/null +++ b/vendor/oojs/oojs-ui/php/layouts/FormLayout.php @@ -0,0 +1,47 @@ +<?php + +namespace OOUI; + +/** + * Layout with an HTML form. + */ +class FormLayout extends Layout { + + /* Static properties */ + + public static $tagName = 'form'; + + /** + * @param array $config Configuration options + * @param string $config['method'] HTML form `method` attribute + * @param string $config['action'] HTML form `action` attribute + * @param string $config['enctype'] HTML form `enctype` attribute + * @param FieldsetLayout[] $config['items'] Items to add + */ + public function __construct( array $config = array() ) { + // Parent constructor + parent::__construct( $config ); + + // Mixins + $this->mixin( new GroupElement( $this, array_merge( $config, array( 'group' => $this ) ) ) ); + + // Initialization + $attributeWhitelist = array( 'method', 'action', 'enctype' ); + $this + ->addClasses( array( 'oo-ui-formLayout' ) ) + ->setAttributes( array_intersect_key( $config, array_flip( $attributeWhitelist ) ) ); + if ( isset( $config['items'] ) ) { + $this->addItems( $config['items'] ); + } + } + + public function getConfig( &$config ) { + foreach ( array( 'method', 'action', 'enctype' ) as $attr ) { + $value = $this->getAttribute( $attr ); + if ( $value !== null ) { + $config[$attr] = $value; + } + } + return parent::getConfig( $config ); + } +} diff --git a/vendor/oojs/oojs-ui/php/layouts/PanelLayout.php b/vendor/oojs/oojs-ui/php/layouts/PanelLayout.php new file mode 100644 index 00000000..64931374 --- /dev/null +++ b/vendor/oojs/oojs-ui/php/layouts/PanelLayout.php @@ -0,0 +1,61 @@ +<?php + +namespace OOUI; + +/** + * Layout that expands to cover the entire area of its parent, with optional scrolling and padding. + */ +class PanelLayout extends Layout { + /** + * @param array $config Configuration options + * @param boolean $config['scrollable'] Allow vertical scrolling (default: false) + * @param boolean $config['padded'] Pad the content from the edges (default: false) + * @param boolean $config['expanded'] Expand size to fill the entire parent element + * (default: true) + * @param boolean $config['framed'] Wrap in a frame to visually separate from outside content + * (default: false) + */ + public function __construct( array $config = array() ) { + // Config initialization + $config = array_merge( array( + 'scrollable' => false, + 'padded' => false, + 'expanded' => true, + 'framed' => false, + ), $config ); + + // Parent constructor + parent::__construct( $config ); + + // Initialization + $this->addClasses( array( 'oo-ui-panelLayout' ) ); + if ( $config['scrollable'] ) { + $this->addClasses( array( 'oo-ui-panelLayout-scrollable' ) ); + } + if ( $config['padded'] ) { + $this->addClasses( array( 'oo-ui-panelLayout-padded' ) ); + } + if ( $config['expanded'] ) { + $this->addClasses( array( 'oo-ui-panelLayout-expanded' ) ); + } + if ( $config['framed'] ) { + $this->addClasses( array( 'oo-ui-panelLayout-framed' ) ); + } + } + public function getConfig( &$config ) { + if ( $this->hasClass( 'oo-ui-panelLayout-scrollable' ) ) { + $config['scrollable'] = true; + } + if ( $this->hasClass( 'oo-ui-panelLayout-padded' ) ) { + $config['padded'] = true; + } + if ( !$this->hasClass( 'oo-ui-panelLayout-expanded' ) ) { + $config['expanded'] = false; + } + if ( $this->hasClass( 'oo-ui-panelLayout-framed' ) ) { + $config['framed'] = true; + } + $config['content'] = $this->content; + return parent::getConfig( $config ); + } +} |