blob: b09c79416bc25410ae566a6077b6d7b29eff1ea0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
<?php
namespace OOUI;
/**
* Element with a button.
*
* Buttons are used for controls which can be clicked. They can be configured to use tab indexing
* and access keys for accessibility purposes.
*
* @abstract
*/
class ButtonElement extends ElementMixin {
/**
* Button is framed.
*
* @var boolean
*/
protected $framed = false;
public static $targetPropertyName = 'button';
/**
* @param Element $element Element being mixed into
* @param array $config Configuration options
* @param boolean $config['framed'] Render button with a frame (default: true)
*/
public function __construct( Element $element, array $config = array() ) {
// Parent constructor
$target = isset( $config['button'] ) ? $config['button'] : new Tag( 'a' );
parent::__construct( $element, $target, $config );
// Initialization
$this->element->addClasses( array( 'oo-ui-buttonElement' ) );
$this->target->addClasses( array( 'oo-ui-buttonElement-button' ) );
$this->toggleFramed( isset( $config['framed'] ) ? $config['framed'] : true );
$this->target->setAttributes( array(
'role' => 'button',
) );
}
/**
* Toggle frame.
*
* @param boolean $framed Make button framed, omit to toggle
* @chainable
*/
public function toggleFramed( $framed = null ) {
$this->framed = $framed !== null ? !!$framed : !$this->framed;
$this->element->toggleClasses( array( 'oo-ui-buttonElement-framed' ), $this->framed );
$this->element->toggleClasses( array( 'oo-ui-buttonElement-frameless' ), !$this->framed );
}
/**
* Check if button has a frame.
*
* @return boolean Button is framed
*/
public function isFramed() {
return $this->framed;
}
public function getConfig( &$config ) {
if ( $this->framed !== true ) {
$config['framed'] = $this->framed;
}
return parent::getConfig( $config );
}
}
|