Skip to content

Commit 238ca71

Browse files
committed
add addPropertyValues to collection +fireOnInit on HtmlList
1 parent e9ba687 commit 238ca71

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

Ajax/common/html/HtmlCollection.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,29 @@ public function setPropertyValues($property,$values){
174174
}
175175
return $this;
176176
}
177+
178+
/**
179+
* Adds the values of a property for each item in the collection
180+
* @param string $property
181+
* @param array $values
182+
* @return HtmlCollection
183+
*/
184+
public function addPropertyValues($property,$values){
185+
$i=0;
186+
if(\is_array($values)===false){
187+
$values=\array_fill(0, $this->count(),$values);
188+
}
189+
foreach ($values as $value){
190+
$c=$this->content[$i++];
191+
if(isset($c)){
192+
$c->addToProperty($property,$value);
193+
}
194+
else{
195+
return $this;
196+
}
197+
}
198+
return $this;
199+
}
177200

178201
public function compile(JsUtils $js=NULL, &$view=NULL) {
179202
$index=0;

Ajax/semantic/components/jsTemplates/tplCheckedList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
;
88
$("%identifier% .list .child.checkbox")
99
.checkbox({
10-
fireOnInit : true,
10+
fireOnInit : %fireOnInit%,
1111
onChange : function() {
1212
var
1313
$listGroup = $(this).closest(".list"),

Ajax/semantic/html/elements/HtmlList.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
class HtmlList extends HtmlSemCollection {
1212
protected $_hasCheckedList;
13+
protected $_fireOnInit=true;
1314

1415
public function __construct($identifier, $items=array()) {
1516
parent::__construct($identifier, "div", "ui list");
@@ -71,11 +72,19 @@ public function run(JsUtils $js) {
7172
if ($this->_hasCheckedList === true) {
7273
$jsCode=include dirname(__FILE__) . '/../../components/jsTemplates/tplCheckedList.php';
7374
$jsCode=\str_replace("%identifier%", "#" . $this->identifier, $jsCode);
75+
$jsCode=\str_replace("%fireOnInit%", $this->_fireOnInit, $jsCode);
7476
$this->executeOnRun($jsCode);
7577
}
7678
return parent::run($js);
7779
}
7880

81+
/**
82+
* @param boolean $fireOnInit
83+
*/
84+
public function setFireOnInit($fireOnInit) {
85+
$this->_fireOnInit = $fireOnInit;
86+
}
87+
7988
public function setRelaxed() {
8089
return $this->addToProperty("class", "relaxed");
8190
}

0 commit comments

Comments
 (0)