Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1430433
ButtonElement.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ButtonElement.php
View Options
<?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
*/
trait
ButtonElement
{
/**
* Button is framed.
*
* @var bool
*/
protected
$framed
=
false
;
/**
* @var Tag
*/
protected
$button
;
/**
* @param array $config Configuration options
* - bool $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
=
$config
[
'button'
]
??
new
Tag
(
'a'
);
$this
->
button
=
$target
;
// Initialization
$this
->
addClasses
(
[
'oo-ui-buttonElement'
]
);
$this
->
button
->
addClasses
(
[
'oo-ui-buttonElement-button'
]
);
$this
->
toggleFramed
(
$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
;
}
}
);
}
/**
* Toggle frame.
*
* @param bool|null $framed Make button framed, omit to toggle
* @return $this
*/
public
function
toggleFramed
(
$framed
=
null
)
{
$this
->
framed
=
$framed
!==
null
?
(
bool
)
$framed
:
!
$this
->
framed
;
$this
->
toggleClasses
(
[
'oo-ui-buttonElement-framed'
],
$this
->
framed
);
$this
->
toggleClasses
(
[
'oo-ui-buttonElement-frameless'
],
!
$this
->
framed
);
return
$this
;
}
/**
* Check if button has a frame.
*
* @return bool Button is framed
*/
public
function
isFramed
()
{
return
$this
->
framed
;
}
/**
* Toggle CSS classes.
*
* @param array $classes List of classes to add
* @param bool|null $toggle Add classes
* @return $this
*/
abstract
public
function
toggleClasses
(
array
$classes
,
$toggle
=
null
);
/**
* @param callable $func
*/
abstract
public
function
registerConfigCallback
(
callable
$func
);
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 18:44 (5 h, 47 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
7e/04/e67661c7bbf0fbacb7b544e8381b
Default Alt Text
ButtonElement.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment