Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
subbutton.php
1
<?php
2
namespace
Bitrix\UI\Buttons\Split
;
3
4
use
Bitrix\Main\NotSupportedException
;
5
use
Bitrix\UI\Buttons
;
6
7
class
SubButton
extends
Buttons\BaseButton
8
{
9
protected
$buttonType
= Type::MAIN;
11
protected
$splitButton
;
12
13
protected
function
init
(array $params = [])
14
{
15
$this->
removeClass
($this->
getBaseClass
());
16
17
if
(!empty($params[
'buttonType'
]))
18
{
19
$this->buttonType = $params[
'buttonType'
] === Type::MAIN? Type::MAIN : Type::MENU;
20
}
21
22
$this->baseClass =
$this->buttonType
;
23
parent::init($params);
24
25
if
($this->
isInputType
())
26
{
27
throw
new
NotSupportedException
(
"Split button cannot be an input tag."
);
28
}
29
}
30
31
public
static
function
getJsClass
()
32
{
33
return
'BX.UI.SplitSubButton'
;
34
}
35
36
protected
function
renderJavascript
()
37
{
38
return
""
;
39
}
40
41
protected
function
renderInner
()
42
{
43
return
$this->
isMenuButton
() ?
''
: parent::renderInner();
44
}
45
49
public
function
isMainButton
()
50
{
51
return
$this->
getButtonType
() === Type::MAIN;
52
}
53
57
public
function
isMenuButton
()
58
{
59
return
$this->
getButtonType
() === Type::MENU;
60
}
61
65
public
function
getButtonType
()
66
{
67
return
$this->buttonType
;
68
}
69
73
public
function
getSplitButton
()
74
{
75
return
$this->splitButton
;
76
}
77
83
public
function
setSplitButton
(
$splitButton
)
84
{
85
$this->splitButton =
$splitButton
;
86
87
return
$this;
88
}
89
95
public
function
setActive
($flag =
true
)
96
{
97
return
$this->
toggleState
($flag,
State::ACTIVE
,
State::MAIN_ACTIVE
,
State::MENU_ACTIVE
);
98
}
99
103
public
function
isActive
()
104
{
105
$state = $this->
getSplitButton
()->getState();
106
if
($state ===
State::ACTIVE
)
107
{
108
return
true
;
109
}
110
111
if
($this->
isMainButton
())
112
{
113
return
$state ===
State::MAIN_ACTIVE
;
114
}
115
else
116
{
117
return
$state ===
State::MENU_ACTIVE
;
118
}
119
}
120
126
public
function
setDisabled
($flag =
true
)
127
{
128
$this->
toggleState
($flag,
State::DISABLED
,
State::MAIN_DISABLED
,
State::MENU_DISABLED
);
129
130
return
parent::setDisabled($flag);
131
}
132
138
public
function
setHovered
($flag =
true
)
139
{
140
return
$this->
toggleState
($flag,
State::HOVER
,
State::MAIN_HOVER
,
State::MENU_HOVER
);;
141
}
142
146
public
function
isHovered
()
147
{
148
$state = $this->
getSplitButton
()->getState();
149
if
($state ===
State::HOVER
)
150
{
151
return
true
;
152
}
153
154
if
($this->
isMainButton
())
155
{
156
return
$state ===
State::MAIN_HOVER
;
157
}
158
else
159
{
160
return
$state ===
State::MENU_HOVER
;
161
}
162
}
163
172
public
function
toggleState
($flag, $globalState, $mainState, $menuState)
173
{
174
$state = $this->
getSplitButton
()->getState();
175
if
($flag ===
false
)
176
{
177
if
($state === $globalState)
178
{
179
$this->
getSplitButton
()->setState($this->
isMainButton
()? $menuState : $mainState);
180
}
181
else
182
{
183
$this->
getSplitButton
()->setState(
null
);
184
}
185
}
186
else
187
{
188
if
($state === $mainState && $this->
isMenuButton
())
189
{
190
$this->
getSplitButton
()->setState($globalState);
191
}
192
else
if
($state === $menuState && $this->
isMainButton
())
193
{
194
$this->
getSplitButton
()->setState($globalState);
195
}
196
else
if
($state !== $globalState)
197
{
198
$this->
getSplitButton
()->setState($this->
isMainButton
()? $mainState : $menuState);
199
}
200
}
201
202
return
$this;
203
}
204
}
Bitrix\Main\NotSupportedException
Definition
exception.php:159
Bitrix\UI\Buttons\BaseButton
Definition
basebutton.php:17
Bitrix\UI\Buttons\BaseButton\removeClass
removeClass($className)
Definition
basebutton.php:341
Bitrix\UI\Buttons\BaseButton\getBaseClass
getBaseClass()
Definition
basebutton.php:470
Bitrix\UI\Buttons\BaseButton\isInputType
isInputType()
Definition
basebutton.php:224
Bitrix\UI\Buttons\Split\State\MAIN_DISABLED
const MAIN_DISABLED
Definition
state.php:13
Bitrix\UI\Buttons\Split\State\MAIN_HOVER
const MAIN_HOVER
Definition
state.php:9
Bitrix\UI\Buttons\Split\State\MENU_ACTIVE
const MENU_ACTIVE
Definition
state.php:12
Bitrix\UI\Buttons\Split\State\MAIN_ACTIVE
const MAIN_ACTIVE
Definition
state.php:11
Bitrix\UI\Buttons\Split\State\MENU_DISABLED
const MENU_DISABLED
Definition
state.php:14
Bitrix\UI\Buttons\Split\State\MENU_HOVER
const MENU_HOVER
Definition
state.php:10
Bitrix\UI\Buttons\Split\SubButton
Definition
subbutton.php:8
Bitrix\UI\Buttons\Split\SubButton\renderJavascript
renderJavascript()
Definition
subbutton.php:36
Bitrix\UI\Buttons\Split\SubButton\setActive
setActive($flag=true)
Definition
subbutton.php:95
Bitrix\UI\Buttons\Split\SubButton\isMainButton
isMainButton()
Definition
subbutton.php:49
Bitrix\UI\Buttons\Split\SubButton\$buttonType
$buttonType
Definition
subbutton.php:9
Bitrix\UI\Buttons\Split\SubButton\renderInner
renderInner()
Definition
subbutton.php:41
Bitrix\UI\Buttons\Split\SubButton\toggleState
toggleState($flag, $globalState, $mainState, $menuState)
Definition
subbutton.php:172
Bitrix\UI\Buttons\Split\SubButton\$splitButton
$splitButton
Definition
subbutton.php:11
Bitrix\UI\Buttons\Split\SubButton\setSplitButton
setSplitButton($splitButton)
Definition
subbutton.php:83
Bitrix\UI\Buttons\Split\SubButton\getButtonType
getButtonType()
Definition
subbutton.php:65
Bitrix\UI\Buttons\Split\SubButton\setHovered
setHovered($flag=true)
Definition
subbutton.php:138
Bitrix\UI\Buttons\Split\SubButton\getJsClass
static getJsClass()
Definition
subbutton.php:31
Bitrix\UI\Buttons\Split\SubButton\isHovered
isHovered()
Definition
subbutton.php:146
Bitrix\UI\Buttons\Split\SubButton\isActive
isActive()
Definition
subbutton.php:103
Bitrix\UI\Buttons\Split\SubButton\setDisabled
setDisabled($flag=true)
Definition
subbutton.php:126
Bitrix\UI\Buttons\Split\SubButton\isMenuButton
isMenuButton()
Definition
subbutton.php:57
Bitrix\UI\Buttons\Split\SubButton\init
init(array $params=[])
Definition
subbutton.php:13
Bitrix\UI\Buttons\Split\SubButton\getSplitButton
getSplitButton()
Definition
subbutton.php:73
Bitrix\UI\Buttons\State\DISABLED
const DISABLED
Definition
state.php:9
Bitrix\UI\Buttons\State\HOVER
const HOVER
Definition
state.php:7
Bitrix\UI\Buttons\State\ACTIVE
const ACTIVE
Definition
state.php:8
Bitrix\UI\Buttons\Split
Definition
addbutton.php:3
Bitrix\UI\Buttons
Definition
addbutton.php:3
modules
ui
lib
buttons
split
subbutton.php
Создано системой
1.10.0