1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\bootstrap\html; |
4
|
|
|
|
5
|
|
|
use Ajax\bootstrap\html\HtmlDropdown; |
6
|
|
|
use Ajax\bootstrap\html\base\CssRef; |
7
|
|
|
use Ajax\JsUtils; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Twitter Bootstrap HTML Splitbutton component |
11
|
|
|
* @author jc |
12
|
|
|
* @version 1.001 |
13
|
|
|
*/ |
14
|
|
|
class HtmlSplitbutton extends HtmlDropdown { |
15
|
|
|
|
16
|
|
|
public function __construct($identifier, $value=" ", $items=array(), $cssStyle="btn-default", $onClick=null) { |
17
|
|
|
parent::__construct($identifier, $value, $items, $cssStyle, $onClick); |
18
|
|
|
$this->asButton($cssStyle); |
19
|
|
|
$this->_template=include 'templates/tplSplitbutton.php'; |
20
|
|
|
$this->mClass="btn-group"; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* (non-PHPdoc) |
25
|
|
|
* @see \Ajax\bootstrap\html\HtmlDropdown::setSize() |
26
|
|
|
* @return HtmlSplitbutton |
27
|
|
|
*/ |
28
|
|
|
public function setSize($size) { |
29
|
|
|
if (is_int($size)) { |
30
|
|
|
return $this->addToMember($this->mClass, CssRef::sizes("btn-group")[$size]); |
31
|
|
|
} |
32
|
|
|
return $this->addToMemberCtrl($this->mClass, $size, CssRef::sizes("btn-group")); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function onButtonClick($jsCode) { |
36
|
|
|
$this->addEvent("buttonClick", $jsCode); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/* |
40
|
|
|
* (non-PHPdoc) |
41
|
|
|
* @see BaseHtml::run() |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
public function run(JsUtils $js) { |
|
|
|
|
44
|
|
|
if ($this->getProperty("role")==="nav") { |
45
|
|
|
foreach ( $this->items as $dropdownItem ) { |
46
|
|
|
$dropdownItem->runNav($js); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
$this->_bsComponent=$js->bootstrap()->splitbutton("#".$this->identifier); |
50
|
|
|
$this->addEventsOnRun($js); |
51
|
|
|
return $this->_bsComponent; |
52
|
|
|
} |
53
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.