/** * @param bool|int $progress */ public function setProgress($progress) { $this->progress = $progress; if ($progress !== false) { $this->bar->setAttributes(['style' => 'width: ' . $this->progress . '%;']); $this->setAttributes(['aria-valuenow' => $this->progress]); } else { $this->removeAttributes(['aria-valuenow']); } $this->toggleClasses(['oo-ui-progressBarWidget-indeterminate'], $progress === false); }
/** * Set access key. * * @param string $accessKey Tag's access key, use empty string to remove * @return $this */ public function setAccessKey($accessKey) { $accessKey = is_string($accessKey) && strlen($accessKey) ? $accessKey : null; if ($this->accessKey !== $accessKey) { if ($accessKey !== null) { $this->accessKeyed->setAttributes(['accesskey' => $accessKey]); } else { $this->accessKeyed->removeAttributes(['accesskey']); } $this->accessKey = $accessKey; } return $this; }
protected function getInputElement($config) { $type = in_array($config['type'], array('button', 'submit', 'reset')) ? $config['type'] : 'button'; $input = new Tag($config['useInputTag'] ? 'input' : 'button'); $input->setAttributes(array('type' => $type)); return $input; }
/** * Set the options available for this input. * * @param array[] $options Array of menu options in the format * `array( 'data' => …, 'label' => … )` * @chainable */ public function setOptions($options) { $value = $this->getValue(); $isValueAvailable = false; $this->options = array(); // Rebuild the dropdown menu $this->input->clearContent(); foreach ($options as $opt) { $optValue = $this->cleanUpValue($opt['data']); $option = new Tag('option'); $option->setAttributes(array('value' => $optValue)); $option->appendContent(isset($opt['label']) ? $opt['label'] : $optValue); if ($value === $optValue) { $isValueAvailable = true; } $this->options[] = $option; $this->input->appendContent($option); } // Restore the previous value, or reset to something sensible if ($isValueAvailable) { // Previous value is still available $this->setValue($value); } else { // No longer valid, reset if (count($options)) { $this->setValue($options[0]['data']); } } return $this; }
public function _test_should_store_zero_strings_as_intergers() { $Tag = new Tag(array('name' => 'Ticket #21')); $this->assertTrue($Tag->save()); $this->assertEqual($Tag->get('score'), 100); $Tag->setAttributes(array('score' => '0')); $this->assertTrue($Tag->save()); $Tag = $Tag->find($Tag->id); $this->assertIdentical($Tag->get('score'), 0); }
public function testCreate() { $tag = new Tag(); $tag->setAttributes(array('name' => 'Apple', 'category' => 1)); $this->assertTrue($tag->save()); $tag2 = Tag::model()->findByPk($tag->id); $this->assertNotNull($tag2); $this->assertEquals($tag->name, $tag2->name); $this->assertEquals($tag->category, $tag2->category); $this->assertEquals(1, $tag2->frequency); $this->assertTrue(time() - $tag2->create_time <= 1); }
public function setDisabled($state) { parent::setDisabled($state); if (isset($this->input)) { if ($this->isDisabled()) { $this->input->setAttributes(['disabled' => 'disabled']); } else { $this->input->removeAttributes(['disabled']); } } return $this; }
/** * @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; } }); }
public function testAttributes() { $tag = new Tag('a'); $this->assertNull($tag->getAttribute('href')); $this->assertNull($tag->href); $tag->href = "#"; $this->assertSame('#', $tag->href); $this->assertSame('#', $tag->getAttribute('href')); $this->assertSame(array('href' => '#'), $tag->getAttributes()); $tag->setAttribute('href', 'javascript:void(0)'); $this->assertSame('javascript:void(0)', $tag->href); $this->assertSame('javascript:void(0)', $tag->getAttribute('href')); $this->assertSame(array('href' => 'javascript:void(0)'), $tag->getAttributes()); $tag->setAttributes(array('href' => '')); $this->assertSame('', $tag->href); $this->assertSame('', $tag->getAttribute('href')); $this->assertSame(array('href' => ''), $tag->getAttributes()); $tag->addClass('link'); $this->assertSame('link', $tag->class); $tag->addClass('link-external'); $this->assertSame('link link-external', $tag->class); $tag->removeClass('link'); $this->assertSame('link-external', $tag->class); }
protected function getInputElement($config) { $input = new Tag('input'); $input->setAttributes(array('type' => 'radio')); return $input; }
protected function getInputElement($config) { if (isset($config['multiline']) && $config['multiline']) { return new Tag('textarea'); } else { $type = in_array($config['type'], array('text', 'password', 'search', 'email', 'url')) ? $config['type'] : 'text'; $input = new Tag('input'); $input->setAttributes(array('type' => $type)); return $input; } }
protected function getInputElement($config) { $input = new Tag($config['useInputTag'] ? 'input' : 'button'); $input->setAttributes(array('type' => $config['type'])); return $input; }
protected function getInputElement($config) { if (isset($config['multiline']) && $config['multiline']) { return new Tag('textarea'); } else { $input = new Tag('input'); $input->setAttributes(array('type' => $this->getSaneType($config))); return $input; } }