コード例 #1
0
ファイル: InputWidget.php プロジェクト: oojs/oojs-ui
 /**
  * @param array $config Configuration options
  * @param string $config['name'] HTML input name (default: '')
  * @param string $config['value'] Input value (default: '')
  * @param string $config['dir'] The directionality of the input (ltr/rtl)
  */
 public function __construct(array $config = [])
 {
     // Parent constructor
     parent::__construct($config);
     // Properties
     $this->input = $this->getInputElement($config);
     // Traits
     $this->initializeFlaggedElement(array_merge($config, ['flagged' => $this]));
     $this->initializeTabIndexedElement(array_merge($config, ['tabIndexed' => $this->input]));
     $this->initializeTitledElement(array_merge($config, ['titled' => $this->input]));
     $this->initializeAccessKeyedElement(array_merge($config, ['accessKeyed' => $this->input]));
     // Initialization
     if (isset($config['name'])) {
         $this->input->setAttributes(['name' => $config['name']]);
     }
     if ($this->isDisabled()) {
         $this->input->setAttributes(['disabled' => 'disabled']);
     }
     $this->addClasses(['oo-ui-inputWidget'])->appendContent($this->input);
     $this->input->addClasses(['oo-ui-inputWidget-input']);
     $this->setValue(isset($config['value']) ? $config['value'] : null);
     if (isset($config['dir'])) {
         $this->setDir($config['dir']);
     }
 }
コード例 #2
0
ファイル: ProgressBarWidget.php プロジェクト: oojs/oojs-ui
 /**
  * @param array $config Configuration options
  * @param bool|int $config['progress'] The type of progress bar (determinate or indeterminate).
  *                                     To create a determinate progress bar,specify a number
  *                                     that reflects the initial percent complete.
  *                                     By default, the progress bar is indeterminate.
  */
 public function __construct(array $config = [])
 {
     parent::__construct($config);
     $this->bar = new Tag('div');
     $this->bar->addClasses(['oo-ui-progressBarWidget-bar']);
     $this->setProgress(array_key_exists('progress', $config) ? $config['progress'] : false);
     $this->setAttributes(['role' => 'progressbar', 'aria-valuemin' => 0, 'aria-valuemax' => 100])->addClasses(['oo-ui-progressBarWidget'])->appendContent($this->bar);
 }
コード例 #3
0
 /**
  * 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'));
     }
 }
コード例 #4
0
ファイル: IconElement.php プロジェクト: oojs/oojs-ui
 /**
  * Set icon name.
  *
  * @param string|null $icon Symbolic icon name
  * @return $this
  */
 public function setIcon($icon = null)
 {
     if ($this->iconName !== null) {
         $this->icon->removeClasses(['oo-ui-icon-' . $this->iconName]);
     }
     if ($icon !== null) {
         $this->icon->addClasses(['oo-ui-icon-' . $icon]);
     }
     $this->iconName = $icon;
     $this->toggleClasses(['oo-ui-iconElement'], (bool) $this->iconName);
     return $this;
 }
コード例 #5
0
ファイル: IndicatorElement.php プロジェクト: oojs/oojs-ui
 /**
  * Set indicator name.
  *
  * @param string|null $indicator Symbolic name of indicator to use or null for no indicator
  * @return $this
  */
 public function setIndicator($indicator = null)
 {
     if ($this->indicatorName !== null) {
         $this->indicator->removeClasses(['oo-ui-indicator-' . $this->indicatorName]);
     }
     if ($indicator !== null) {
         $this->indicator->addClasses(['oo-ui-indicator-' . $indicator]);
     }
     $this->indicatorName = $indicator;
     $this->toggleClasses(['oo-ui-indicatorElement'], (bool) $this->indicatorName);
     return $this;
 }
コード例 #6
0
ファイル: LabelElement.php プロジェクト: oojs/oojs-ui
 /**
  * @param array $config Configuration options
  * @param string|HtmlSnippet $config['label'] Label text
  */
 public function initializeLabelElement(array $config = [])
 {
     // Properties
     // FIXME 'labelElement' is a very stupid way to call '$label'
     $this->label = isset($config['labelElement']) ? $config['labelElement'] : new Tag('span');
     // Initialization
     $this->label->addClasses(['oo-ui-labelElement-label']);
     $this->setLabel(isset($config['label']) ? $config['label'] : null);
     $this->registerConfigCallback(function (&$config) {
         if ($this->labelValue !== null) {
             $config['label'] = $this->labelValue;
         }
     });
 }
コード例 #7
0
ファイル: ButtonElement.php プロジェクト: oojs/oojs-ui
 /**
  * @param array $config Configuration options
  * @param boolean $config['framed'] Render button with a frame (default: true)
  */
 public function initializeButtonElement(array $config = [])
 {
     // Properties
     if (!$this instanceof Element) {
         throw new Exception("ButtonElement trait can only be used on Element instances");
     }
     $target = isset($config['button']) ? $config['button'] : new Tag('a');
     $this->button = $target;
     // Initialization
     $this->addClasses(['oo-ui-buttonElement']);
     $this->button->addClasses(['oo-ui-buttonElement-button']);
     $this->toggleFramed(isset($config['framed']) ? $config['framed'] : true);
     // Add `role="button"` on `<a>` elements, where it's needed
     if (strtolower($this->button->getTag()) === 'a') {
         $this->button->setAttributes(['role' => 'button']);
     }
     $this->registerConfigCallback(function (&$config) {
         if ($this->framed !== true) {
             $config['framed'] = $this->framed;
         }
     });
 }