@@ -19,6 +19,9 @@ discard block |
||
19 | 19 | protected $style=""; |
20 | 20 | protected $styleLimits=null; |
21 | 21 | |
22 | + /** |
|
23 | + * @param string $identifier |
|
24 | + */ |
|
22 | 25 | public function __construct($identifier, $style="info", $value=0, $max=100, $min=0) { |
23 | 26 | parent::__construct($identifier); |
24 | 27 | $this->_template=include 'templates/tplProgressbar.php'; |
@@ -28,6 +31,9 @@ discard block |
||
28 | 31 | $this->setStyle($style); |
29 | 32 | } |
30 | 33 | |
34 | + /** |
|
35 | + * @param boolean $value |
|
36 | + */ |
|
31 | 37 | public function setActive($value) { |
32 | 38 | if(is_array($this->content)){ |
33 | 39 | foreach ($this->content as $pb){ |
@@ -42,6 +48,9 @@ discard block |
||
42 | 48 | return $this; |
43 | 49 | } |
44 | 50 | |
51 | + /** |
|
52 | + * @param boolean $value |
|
53 | + */ |
|
45 | 54 | public function setStriped($value) { |
46 | 55 | if(is_array($this->content)){ |
47 | 56 | foreach ($this->content as $pb){ |
@@ -56,6 +65,9 @@ discard block |
||
56 | 65 | return $this; |
57 | 66 | } |
58 | 67 | |
68 | + /** |
|
69 | + * @param boolean $value |
|
70 | + */ |
|
59 | 71 | public function showCaption($value) { |
60 | 72 | if(is_array($this->content)){ |
61 | 73 | foreach ($this->content as $pb){ |
@@ -113,6 +125,9 @@ discard block |
||
113 | 125 | return $this->isStacked; |
114 | 126 | } |
115 | 127 | |
128 | + /** |
|
129 | + * @param boolean $isStacked |
|
130 | + */ |
|
116 | 131 | public function setIsStacked($isStacked) { |
117 | 132 | $this->isStacked=$isStacked; |
118 | 133 | return $this; |
@@ -121,7 +136,7 @@ discard block |
||
121 | 136 | /** |
122 | 137 | * define the progressbar style |
123 | 138 | * avaible values : "success","info","warning","danger" |
124 | - * @param string|int $cssStyle |
|
139 | + * @param string $cssStyle |
|
125 | 140 | * @return \Ajax\bootstrap\html\HtmlProgressbar default : "" |
126 | 141 | */ |
127 | 142 | public function setStyle($cssStyle) { |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | public function setActive($value) { |
32 | - if(is_array($this->content)){ |
|
33 | - foreach ($this->content as $pb){ |
|
32 | + if (is_array($this->content)) { |
|
33 | + foreach ($this->content as $pb) { |
|
34 | 34 | $pb->setActive($value); |
35 | 35 | } |
36 | - }else{ |
|
36 | + } else { |
|
37 | 37 | if ($value===true) |
38 | 38 | $this->active="active"; |
39 | 39 | else |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | public function setStriped($value) { |
46 | - if(is_array($this->content)){ |
|
47 | - foreach ($this->content as $pb){ |
|
46 | + if (is_array($this->content)) { |
|
47 | + foreach ($this->content as $pb) { |
|
48 | 48 | $pb->setStriped($value); |
49 | 49 | } |
50 | - }else{ |
|
50 | + } else { |
|
51 | 51 | if ($value===true) |
52 | 52 | $this->striped="progress-bar-striped"; |
53 | 53 | else |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | public function showCaption($value) { |
60 | - if(is_array($this->content)){ |
|
61 | - foreach ($this->content as $pb){ |
|
60 | + if (is_array($this->content)) { |
|
61 | + foreach ($this->content as $pb) { |
|
62 | 62 | $pb->showCaption($value); |
63 | 63 | } |
64 | - }else{ |
|
64 | + } else { |
|
65 | 65 | if ($value===true) |
66 | 66 | $this->caption="%value%%"; |
67 | 67 | else |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $progressBar->setStriped($this->striped!=="" || $progressBar->isStriped()); |
82 | 82 | $progressBar->setActive($this->active==="active" || $progressBar->isActive()); |
83 | 83 | if (is_array($this->content)===false) { |
84 | - $this->content=array (); |
|
84 | + $this->content=array(); |
|
85 | 85 | } |
86 | 86 | $this->content []=$progressBar; |
87 | 87 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @return \Ajax\bootstrap\html\HtmlProgressbar default : "" |
126 | 126 | */ |
127 | 127 | public function setStyle($cssStyle) { |
128 | - return $this->setMemberCtrl($this->style,CssRef::getStyle($cssStyle, "progress-bar"), CssRef::Styles("progress-bar")); |
|
128 | + return $this->setMemberCtrl($this->style, CssRef::getStyle($cssStyle, "progress-bar"), CssRef::Styles("progress-bar")); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /* |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
136 | 136 | $actualStyle=$this->style; |
137 | - if(isset($this->styleLimits)&& JArray::isAssociative($this->styleLimits)){ |
|
138 | - foreach ($this->styleLimits as $k=>$v){ |
|
137 | + if (isset($this->styleLimits) && JArray::isAssociative($this->styleLimits)) { |
|
138 | + foreach ($this->styleLimits as $k=>$v) { |
|
139 | 139 | $actualStyle=$k; |
140 | - if($v>$this->value) |
|
140 | + if ($v>$this->value) |
|
141 | 141 | break; |
142 | 142 | } |
143 | 143 | } |
@@ -33,11 +33,12 @@ discard block |
||
33 | 33 | foreach ($this->content as $pb){ |
34 | 34 | $pb->setActive($value); |
35 | 35 | } |
36 | - }else{ |
|
37 | - if ($value===true) |
|
38 | - $this->active="active"; |
|
39 | - else |
|
40 | - $this->active=""; |
|
36 | + } else{ |
|
37 | + if ($value===true) { |
|
38 | + $this->active="active"; |
|
39 | + } else { |
|
40 | + $this->active=""; |
|
41 | + } |
|
41 | 42 | } |
42 | 43 | return $this; |
43 | 44 | } |
@@ -47,11 +48,12 @@ discard block |
||
47 | 48 | foreach ($this->content as $pb){ |
48 | 49 | $pb->setStriped($value); |
49 | 50 | } |
50 | - }else{ |
|
51 | - if ($value===true) |
|
52 | - $this->striped="progress-bar-striped"; |
|
53 | - else |
|
54 | - $this->striped=""; |
|
51 | + } else{ |
|
52 | + if ($value===true) { |
|
53 | + $this->striped="progress-bar-striped"; |
|
54 | + } else { |
|
55 | + $this->striped=""; |
|
56 | + } |
|
55 | 57 | } |
56 | 58 | return $this; |
57 | 59 | } |
@@ -61,11 +63,12 @@ discard block |
||
61 | 63 | foreach ($this->content as $pb){ |
62 | 64 | $pb->showCaption($value); |
63 | 65 | } |
64 | - }else{ |
|
65 | - if ($value===true) |
|
66 | - $this->caption="%value%%"; |
|
67 | - else |
|
68 | - $this->caption='<span class="sr-only">%value%% Complete (%style%)</span>'; |
|
66 | + } else{ |
|
67 | + if ($value===true) { |
|
68 | + $this->caption="%value%%"; |
|
69 | + } else { |
|
70 | + $this->caption='<span class="sr-only">%value%% Complete (%style%)</span>'; |
|
71 | + } |
|
69 | 72 | } |
70 | 73 | return $this; |
71 | 74 | } |
@@ -137,8 +140,9 @@ discard block |
||
137 | 140 | if(isset($this->styleLimits)&& JArray::isAssociative($this->styleLimits)){ |
138 | 141 | foreach ($this->styleLimits as $k=>$v){ |
139 | 142 | $actualStyle=$k; |
140 | - if($v>$this->value) |
|
141 | - break; |
|
143 | + if($v>$this->value) { |
|
144 | + break; |
|
145 | + } |
|
142 | 146 | } |
143 | 147 | } |
144 | 148 | $this->style=$actualStyle; |
@@ -5,7 +5,6 @@ |
||
5 | 5 | use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6 | 6 | use Ajax\JsUtils; |
7 | 7 | use Ajax\service\JArray; |
8 | - |
|
9 | 8 | use Ajax\semantic\html\base\constants\State; |
10 | 9 | |
11 | 10 | class HtmlProgress extends HtmlSemDoubleElement { |
@@ -16,6 +16,9 @@ |
||
16 | 16 | |
17 | 17 | trait BootstrapComponentsTrait { |
18 | 18 | |
19 | + /** |
|
20 | + * @param string|null $attachTo |
|
21 | + */ |
|
19 | 22 | public abstract function addComponent(SimpleComponent $component, $attachTo, $params); |
20 | 23 | /** |
21 | 24 | * |
@@ -11,7 +11,6 @@ |
||
11 | 11 | use Ajax\bootstrap\components\Tab; |
12 | 12 | use Ajax\bootstrap\components\Carousel; |
13 | 13 | use Ajax\bootstrap\components\Collapse; |
14 | -use Ajax\Bootstrap; |
|
15 | 14 | use Ajax\common\components\SimpleComponent; |
16 | 15 | |
17 | 16 | trait BootstrapComponentsTrait { |
@@ -124,6 +124,10 @@ discard block |
||
124 | 124 | return $this; |
125 | 125 | } |
126 | 126 | |
127 | + /** |
|
128 | + * @param string $name |
|
129 | + * @param string[] $typeCtrl |
|
130 | + */ |
|
127 | 131 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
128 | 132 | if ($this->ctrl($name, $value, $typeCtrl) === true) { |
129 | 133 | return $name=$value; |
@@ -139,22 +143,35 @@ discard block |
||
139 | 143 | return $this; |
140 | 144 | } |
141 | 145 | |
146 | + /** |
|
147 | + * @param string $name |
|
148 | + */ |
|
142 | 149 | protected function removePropertyValue($name, $value) { |
143 | 150 | $this->properties[$name]=\str_replace($value, "", $this->properties[$name]); |
144 | 151 | return $this; |
145 | 152 | } |
146 | 153 | |
154 | + /** |
|
155 | + * @param string $name |
|
156 | + */ |
|
147 | 157 | protected function removePropertyValues($name, $values) { |
148 | 158 | $this->removeOldValues($this->properties[$name], $values); |
149 | 159 | return $this; |
150 | 160 | } |
151 | 161 | |
162 | + /** |
|
163 | + * @param string $name |
|
164 | + */ |
|
152 | 165 | public function removeProperty($name) { |
153 | 166 | if (\array_key_exists($name, $this->properties)) |
154 | 167 | unset($this->properties[$name]); |
155 | 168 | return $this; |
156 | 169 | } |
157 | 170 | |
171 | + /** |
|
172 | + * @param string $name |
|
173 | + * @param string[] $typeCtrl |
|
174 | + */ |
|
158 | 175 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
159 | 176 | if ($this->ctrl($name, $value, $typeCtrl) === true) { |
160 | 177 | if (is_array($typeCtrl)) { |
@@ -165,6 +182,9 @@ discard block |
||
165 | 182 | return $this; |
166 | 183 | } |
167 | 184 | |
185 | + /** |
|
186 | + * @param string $name |
|
187 | + */ |
|
168 | 188 | protected function addToMember(&$name, $value, $separator=" ") { |
169 | 189 | $name=str_ireplace($value, "", $name) . $separator . $value; |
170 | 190 | return $this; |
@@ -179,6 +199,9 @@ discard block |
||
179 | 199 | return $this->addToProperty($name, $value); |
180 | 200 | } |
181 | 201 | |
202 | + /** |
|
203 | + * @param string $name |
|
204 | + */ |
|
182 | 205 | public function addToPropertyCtrl($name, $value, $typeCtrl) { |
183 | 206 | return $this->addToPropertyUnique($name, $value, $typeCtrl); |
184 | 207 | } |
@@ -327,14 +350,23 @@ discard block |
||
327 | 350 | return $this; |
328 | 351 | } |
329 | 352 | |
353 | + /** |
|
354 | + * @param string $event |
|
355 | + */ |
|
330 | 356 | public function getOn($event, $url, $responseElement="", $parameters=array()) { |
331 | 357 | return $this->_ajaxOn("get", $event, $url, $responseElement, $parameters); |
332 | 358 | } |
333 | 359 | |
360 | + /** |
|
361 | + * @param string $url |
|
362 | + */ |
|
334 | 363 | public function getOnClick($url, $responseElement="", $parameters=array()) { |
335 | 364 | return $this->getOn("click", $url, $responseElement, $parameters); |
336 | 365 | } |
337 | 366 | |
367 | + /** |
|
368 | + * @param string $event |
|
369 | + */ |
|
338 | 370 | public function postOn($event, $url, $params="{}", $responseElement="", $parameters=array()) { |
339 | 371 | $parameters["params"]=$params; |
340 | 372 | return $this->_ajaxOn("post", $event, $url, $responseElement, $parameters); |
@@ -344,6 +376,9 @@ discard block |
||
344 | 376 | return $this->postOn("click", $url, $params, $responseElement, $parameters); |
345 | 377 | } |
346 | 378 | |
379 | + /** |
|
380 | + * @param string $event |
|
381 | + */ |
|
347 | 382 | public function postFormOn($event, $url, $form, $responseElement="", $parameters=array()) { |
348 | 383 | $parameters["form"]=$form; |
349 | 384 | return $this->_ajaxOn("postForm", $event, $url, $responseElement, $parameters); |
@@ -371,6 +406,10 @@ discard block |
||
371 | 406 | return null; |
372 | 407 | } |
373 | 408 | |
409 | + /** |
|
410 | + * @param string $propertyName |
|
411 | + * @param string $value |
|
412 | + */ |
|
374 | 413 | protected function getElementByPropertyValue($propertyName,$value, $elements) { |
375 | 414 | if (is_array($elements)) { |
376 | 415 | $flag=false; |
@@ -411,6 +450,9 @@ discard block |
||
411 | 450 | return $value; |
412 | 451 | } |
413 | 452 | |
453 | + /** |
|
454 | + * @param string $jqueryCall |
|
455 | + */ |
|
414 | 456 | public function jsDoJquery($jqueryCall, $param="") { |
415 | 457 | return "$('#" . $this->identifier . "')." . $jqueryCall . "(" . $this->_prep_value($param) . ");"; |
416 | 458 | } |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | abstract class BaseHtml extends BaseWidget { |
17 | 17 | protected $_template; |
18 | 18 | protected $tagName; |
19 | - protected $properties=array (); |
|
20 | - protected $_events=array (); |
|
21 | - protected $_wrapBefore=array (); |
|
22 | - protected $_wrapAfter=array (); |
|
19 | + protected $properties=array(); |
|
20 | + protected $_events=array(); |
|
21 | + protected $_wrapBefore=array(); |
|
22 | + protected $_wrapAfter=array(); |
|
23 | 23 | protected $_bsComponent; |
24 | 24 | |
25 | 25 | public function getBsComponent() { |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | } |
33 | 33 | |
34 | 34 | protected function getTemplate(JsUtils $js=NULL) { |
35 | - return PropertyWrapper::wrap($this->_wrapBefore, $js) . $this->_template . PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
35 | + return PropertyWrapper::wrap($this->_wrapBefore, $js).$this->_template.PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public function getProperties() { |
@@ -56,13 +56,13 @@ discard block |
||
56 | 56 | |
57 | 57 | public function addToProperty($name, $value, $separator=" ") { |
58 | 58 | if (\is_array($value)) { |
59 | - foreach ( $value as $v ) { |
|
59 | + foreach ($value as $v) { |
|
60 | 60 | $this->addToProperty($name, $v, $separator); |
61 | 61 | } |
62 | - } else if ($value !== "" && $this->propertyContains($name, $value) === false) { |
|
62 | + } else if ($value!=="" && $this->propertyContains($name, $value)===false) { |
|
63 | 63 | $v=@$this->properties[$name]; |
64 | - if (isset($v) && $v !== "") |
|
65 | - $v=$v . $separator . $value; |
|
64 | + if (isset($v) && $v!=="") |
|
65 | + $v=$v.$separator.$value; |
|
66 | 66 | else |
67 | 67 | $v=$value; |
68 | 68 | |
@@ -78,19 +78,19 @@ discard block |
||
78 | 78 | |
79 | 79 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
80 | 80 | $result=$this->getTemplate($js); |
81 | - foreach ( $this as $key => $value ) { |
|
82 | - if (JString::startswith($key, "_") === false && $key !== "events") { |
|
81 | + foreach ($this as $key => $value) { |
|
82 | + if (JString::startswith($key, "_")===false && $key!=="events") { |
|
83 | 83 | if (is_array($value)) { |
84 | 84 | $v=PropertyWrapper::wrap($value, $js); |
85 | 85 | } else { |
86 | 86 | $v=$value; |
87 | 87 | } |
88 | - $result=str_ireplace("%" . $key . "%", $v, $result); |
|
88 | + $result=str_ireplace("%".$key."%", $v, $result); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | if (isset($js)===true) { |
92 | 92 | $this->run($js); |
93 | - if (isset($view) === true) { |
|
93 | + if (isset($view)===true) { |
|
94 | 94 | $js->addViewElement($this->identifier, $result, $view); |
95 | 95 | } |
96 | 96 | } |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | |
100 | 100 | protected function ctrl($name, $value, $typeCtrl) { |
101 | 101 | if (is_array($typeCtrl)) { |
102 | - if (array_search($value, $typeCtrl) === false) { |
|
103 | - throw new \Exception("La valeur passée `" . $value . "` à la propriété `" . $name . "` ne fait pas partie des valeurs possibles : {" . implode(",", $typeCtrl) . "}"); |
|
102 | + if (array_search($value, $typeCtrl)===false) { |
|
103 | + throw new \Exception("La valeur passée `".$value."` à la propriété `".$name."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}"); |
|
104 | 104 | } |
105 | 105 | } else { |
106 | 106 | if (!$typeCtrl($value)) { |
107 | - throw new \Exception("La fonction " . $typeCtrl . " a retourné faux pour l'affectation de la propriété " . $name); |
|
107 | + throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$name); |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | return true; |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | protected function setPropertyCtrl($name, $value, $typeCtrl) { |
122 | - if ($this->ctrl($name, $value, $typeCtrl) === true) |
|
122 | + if ($this->ctrl($name, $value, $typeCtrl)===true) |
|
123 | 123 | return $this->setProperty($name, $value); |
124 | 124 | return $this; |
125 | 125 | } |
126 | 126 | |
127 | 127 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
128 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
128 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
129 | 129 | return $name=$value; |
130 | 130 | } |
131 | 131 | return $this; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ") { |
135 | 135 | if (is_array($typeCtrl)) { |
136 | 136 | $this->removeOldValues($name, $typeCtrl); |
137 | - $name.=$separator . $value; |
|
137 | + $name.=$separator.$value; |
|
138 | 138 | } |
139 | 139 | return $this; |
140 | 140 | } |
@@ -156,17 +156,17 @@ discard block |
||
156 | 156 | } |
157 | 157 | |
158 | 158 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
159 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
159 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
160 | 160 | if (is_array($typeCtrl)) { |
161 | 161 | $this->removeOldValues($name, $typeCtrl); |
162 | 162 | } |
163 | - $name.=$separator . $value; |
|
163 | + $name.=$separator.$value; |
|
164 | 164 | } |
165 | 165 | return $this; |
166 | 166 | } |
167 | 167 | |
168 | 168 | protected function addToMember(&$name, $value, $separator=" ") { |
169 | - $name=str_ireplace($value, "", $name) . $separator . $value; |
|
169 | + $name=str_ireplace($value, "", $name).$separator.$value; |
|
170 | 170 | return $this; |
171 | 171 | } |
172 | 172 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | } |
185 | 185 | |
186 | 186 | public function addToPropertyCtrlCheck($name, $value, $typeCtrl) { |
187 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
187 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
188 | 188 | return $this->addToProperty($name, $value); |
189 | 189 | } |
190 | 190 | return $this; |
@@ -212,28 +212,28 @@ discard block |
||
212 | 212 | } |
213 | 213 | |
214 | 214 | public function fromArray($array) { |
215 | - foreach ( $this as $key => $value ) { |
|
215 | + foreach ($this as $key => $value) { |
|
216 | 216 | if (array_key_exists($key, $array) && !JString::startswith($key, "_")) { |
217 | - $setter="set" . ucfirst($key); |
|
217 | + $setter="set".ucfirst($key); |
|
218 | 218 | $this->$setter($array[$key]); |
219 | 219 | unset($array[$key]); |
220 | 220 | } |
221 | 221 | } |
222 | - foreach ( $array as $key => $value ) { |
|
222 | + foreach ($array as $key => $value) { |
|
223 | 223 | if (method_exists($this, $key)) { |
224 | 224 | try { |
225 | 225 | $this->$key($value); |
226 | 226 | unset($array[$key]); |
227 | - } catch ( \Exception $e ) { |
|
227 | + }catch (\Exception $e) { |
|
228 | 228 | // Nothing to do |
229 | 229 | } |
230 | 230 | } else { |
231 | - $setter="set" . ucfirst($key); |
|
231 | + $setter="set".ucfirst($key); |
|
232 | 232 | if (method_exists($this, $setter)) { |
233 | 233 | try { |
234 | 234 | $this->$setter($value); |
235 | 235 | unset($array[$key]); |
236 | - } catch ( \Exception $e ) { |
|
236 | + }catch (\Exception $e) { |
|
237 | 237 | // Nothing to do |
238 | 238 | } |
239 | 239 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | |
245 | 245 | public function fromDatabaseObjects($objects, $function) { |
246 | 246 | if (isset($objects)) { |
247 | - foreach ( $objects as $object ) { |
|
247 | + foreach ($objects as $object) { |
|
248 | 248 | $this->fromDatabaseObject($object, $function); |
249 | 249 | } |
250 | 250 | } |
@@ -264,11 +264,11 @@ discard block |
||
264 | 264 | } |
265 | 265 | |
266 | 266 | public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
267 | - if ($stopPropagation === true) { |
|
268 | - $jsCode="event.stopPropagation();" . $jsCode; |
|
267 | + if ($stopPropagation===true) { |
|
268 | + $jsCode="event.stopPropagation();".$jsCode; |
|
269 | 269 | } |
270 | - if ($preventDefault === true) { |
|
271 | - $jsCode="event.preventDefault();" . $jsCode; |
|
270 | + if ($preventDefault===true) { |
|
271 | + $jsCode="event.preventDefault();".$jsCode; |
|
272 | 272 | } |
273 | 273 | return $this->_addEvent($event, $jsCode); |
274 | 274 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | if (is_array($this->_events[$event])) { |
279 | 279 | $this->_events[$event][]=$jsCode; |
280 | 280 | } else { |
281 | - $this->_events[$event]=array ($this->_events[$event],$jsCode ); |
|
281 | + $this->_events[$event]=array($this->_events[$event], $jsCode); |
|
282 | 282 | } |
283 | 283 | } else { |
284 | 284 | $this->_events[$event]=$jsCode; |
@@ -300,15 +300,15 @@ discard block |
||
300 | 300 | |
301 | 301 | public function addEventsOnRun(JsUtils $js) { |
302 | 302 | if (isset($this->_bsComponent)) { |
303 | - foreach ( $this->_events as $event => $jsCode ) { |
|
303 | + foreach ($this->_events as $event => $jsCode) { |
|
304 | 304 | $code=$jsCode; |
305 | 305 | if (is_array($jsCode)) { |
306 | 306 | $code=""; |
307 | - foreach ( $jsCode as $jsC ) { |
|
307 | + foreach ($jsCode as $jsC) { |
|
308 | 308 | if ($jsC instanceof AjaxCall) { |
309 | - $code.="\n" . $jsC->compile($js); |
|
309 | + $code.="\n".$jsC->compile($js); |
|
310 | 310 | } else { |
311 | - $code.="\n" . $jsC; |
|
311 | + $code.="\n".$jsC; |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | } elseif ($jsCode instanceof AjaxCall) { |
@@ -316,12 +316,12 @@ discard block |
||
316 | 316 | } |
317 | 317 | $this->_bsComponent->addEvent($event, $code); |
318 | 318 | } |
319 | - $this->_events=array (); |
|
319 | + $this->_events=array(); |
|
320 | 320 | } |
321 | 321 | } |
322 | 322 | |
323 | 323 | public function _ajaxOn($operation, $event, $url, $responseElement="", $parameters=array()) { |
324 | - $params=array ("url" => $url,"responseElement" => $responseElement ); |
|
324 | + $params=array("url" => $url, "responseElement" => $responseElement); |
|
325 | 325 | $params=array_merge($params, $parameters); |
326 | 326 | $this->_addEvent($event, new AjaxCall($operation, $params)); |
327 | 327 | return $this; |
@@ -357,33 +357,33 @@ discard block |
||
357 | 357 | if (is_array($elements)) { |
358 | 358 | $flag=false; |
359 | 359 | $index=0; |
360 | - while ( !$flag && $index < sizeof($elements) ) { |
|
360 | + while (!$flag && $index<sizeof($elements)) { |
|
361 | 361 | if ($elements[$index] instanceof BaseHtml) |
362 | - $flag=($elements[$index]->getIdentifier() === $identifier); |
|
362 | + $flag=($elements[$index]->getIdentifier()===$identifier); |
|
363 | 363 | $index++; |
364 | 364 | } |
365 | - if ($flag === true) |
|
366 | - return $elements[$index - 1]; |
|
365 | + if ($flag===true) |
|
366 | + return $elements[$index-1]; |
|
367 | 367 | } elseif ($elements instanceof BaseHtml) { |
368 | - if ($elements->getIdentifier() === $identifier) |
|
368 | + if ($elements->getIdentifier()===$identifier) |
|
369 | 369 | return $elements; |
370 | 370 | } |
371 | 371 | return null; |
372 | 372 | } |
373 | 373 | |
374 | - protected function getElementByPropertyValue($propertyName,$value, $elements) { |
|
374 | + protected function getElementByPropertyValue($propertyName, $value, $elements) { |
|
375 | 375 | if (is_array($elements)) { |
376 | 376 | $flag=false; |
377 | 377 | $index=0; |
378 | - while ( !$flag && $index < sizeof($elements) ) { |
|
378 | + while (!$flag && $index<sizeof($elements)) { |
|
379 | 379 | if ($elements[$index] instanceof BaseHtml) |
380 | - $flag=($elements[$index]->propertyContains($propertyName, $value) === true); |
|
380 | + $flag=($elements[$index]->propertyContains($propertyName, $value)===true); |
|
381 | 381 | $index++; |
382 | 382 | } |
383 | - if ($flag === true) |
|
384 | - return $elements[$index - 1]; |
|
383 | + if ($flag===true) |
|
384 | + return $elements[$index-1]; |
|
385 | 385 | } elseif ($elements instanceof BaseHtml) { |
386 | - if ($elements->propertyContains($propertyName, $value) === true) |
|
386 | + if ($elements->propertyContains($propertyName, $value)===true) |
|
387 | 387 | return $elements; |
388 | 388 | } |
389 | 389 | return null; |
@@ -405,14 +405,14 @@ discard block |
||
405 | 405 | if (is_array($value)) { |
406 | 406 | $value=implode(",", $value); |
407 | 407 | } |
408 | - if (strrpos($value, 'this') === false && strrpos($value, 'event') === false) { |
|
409 | - $value='"' . $value . '"'; |
|
408 | + if (strrpos($value, 'this')===false && strrpos($value, 'event')===false) { |
|
409 | + $value='"'.$value.'"'; |
|
410 | 410 | } |
411 | 411 | return $value; |
412 | 412 | } |
413 | 413 | |
414 | 414 | public function jsDoJquery($jqueryCall, $param="") { |
415 | - return "$('#" . $this->identifier . "')." . $jqueryCall . "(" . $this->_prep_value($param) . ");"; |
|
415 | + return "$('#".$this->identifier."').".$jqueryCall."(".$this->_prep_value($param).");"; |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | public function executeOnRun($jsCode) { |
@@ -50,8 +50,9 @@ discard block |
||
50 | 50 | } |
51 | 51 | |
52 | 52 | public function getProperty($name) { |
53 | - if (array_key_exists($name, $this->properties)) |
|
54 | - return $this->properties[$name]; |
|
53 | + if (array_key_exists($name, $this->properties)) { |
|
54 | + return $this->properties[$name]; |
|
55 | + } |
|
55 | 56 | } |
56 | 57 | |
57 | 58 | public function addToProperty($name, $value, $separator=" ") { |
@@ -61,10 +62,11 @@ discard block |
||
61 | 62 | } |
62 | 63 | } else if ($value !== "" && $this->propertyContains($name, $value) === false) { |
63 | 64 | $v=@$this->properties[$name]; |
64 | - if (isset($v) && $v !== "") |
|
65 | - $v=$v . $separator . $value; |
|
66 | - else |
|
67 | - $v=$value; |
|
65 | + if (isset($v) && $v !== "") { |
|
66 | + $v=$v . $separator . $value; |
|
67 | + } else { |
|
68 | + $v=$value; |
|
69 | + } |
|
68 | 70 | |
69 | 71 | return $this->setProperty($name, $v); |
70 | 72 | } |
@@ -119,8 +121,9 @@ discard block |
||
119 | 121 | } |
120 | 122 | |
121 | 123 | protected function setPropertyCtrl($name, $value, $typeCtrl) { |
122 | - if ($this->ctrl($name, $value, $typeCtrl) === true) |
|
123 | - return $this->setProperty($name, $value); |
|
124 | + if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
125 | + return $this->setProperty($name, $value); |
|
126 | + } |
|
124 | 127 | return $this; |
125 | 128 | } |
126 | 129 | |
@@ -150,8 +153,9 @@ discard block |
||
150 | 153 | } |
151 | 154 | |
152 | 155 | public function removeProperty($name) { |
153 | - if (\array_key_exists($name, $this->properties)) |
|
154 | - unset($this->properties[$name]); |
|
156 | + if (\array_key_exists($name, $this->properties)) { |
|
157 | + unset($this->properties[$name]); |
|
158 | + } |
|
155 | 159 | return $this; |
156 | 160 | } |
157 | 161 | |
@@ -171,8 +175,9 @@ discard block |
||
171 | 175 | } |
172 | 176 | |
173 | 177 | protected function addToPropertyUnique($name, $value, $typeCtrl) { |
174 | - if (@class_exists($typeCtrl, true)) |
|
175 | - $typeCtrl=$typeCtrl::getConstants(); |
|
178 | + if (@class_exists($typeCtrl, true)) { |
|
179 | + $typeCtrl=$typeCtrl::getConstants(); |
|
180 | + } |
|
176 | 181 | if (is_array($typeCtrl)) { |
177 | 182 | $this->removeOldValues($this->properties[$name], $typeCtrl); |
178 | 183 | } |
@@ -358,15 +363,18 @@ discard block |
||
358 | 363 | $flag=false; |
359 | 364 | $index=0; |
360 | 365 | while ( !$flag && $index < sizeof($elements) ) { |
361 | - if ($elements[$index] instanceof BaseHtml) |
|
362 | - $flag=($elements[$index]->getIdentifier() === $identifier); |
|
366 | + if ($elements[$index] instanceof BaseHtml) { |
|
367 | + $flag=($elements[$index]->getIdentifier() === $identifier); |
|
368 | + } |
|
363 | 369 | $index++; |
364 | 370 | } |
365 | - if ($flag === true) |
|
366 | - return $elements[$index - 1]; |
|
371 | + if ($flag === true) { |
|
372 | + return $elements[$index - 1]; |
|
373 | + } |
|
367 | 374 | } elseif ($elements instanceof BaseHtml) { |
368 | - if ($elements->getIdentifier() === $identifier) |
|
369 | - return $elements; |
|
375 | + if ($elements->getIdentifier() === $identifier) { |
|
376 | + return $elements; |
|
377 | + } |
|
370 | 378 | } |
371 | 379 | return null; |
372 | 380 | } |
@@ -376,15 +384,18 @@ discard block |
||
376 | 384 | $flag=false; |
377 | 385 | $index=0; |
378 | 386 | while ( !$flag && $index < sizeof($elements) ) { |
379 | - if ($elements[$index] instanceof BaseHtml) |
|
380 | - $flag=($elements[$index]->propertyContains($propertyName, $value) === true); |
|
387 | + if ($elements[$index] instanceof BaseHtml) { |
|
388 | + $flag=($elements[$index]->propertyContains($propertyName, $value) === true); |
|
389 | + } |
|
381 | 390 | $index++; |
382 | 391 | } |
383 | - if ($flag === true) |
|
384 | - return $elements[$index - 1]; |
|
392 | + if ($flag === true) { |
|
393 | + return $elements[$index - 1]; |
|
394 | + } |
|
385 | 395 | } elseif ($elements instanceof BaseHtml) { |
386 | - if ($elements->propertyContains($propertyName, $value) === true) |
|
387 | - return $elements; |
|
396 | + if ($elements->propertyContains($propertyName, $value) === true) { |
|
397 | + return $elements; |
|
398 | + } |
|
388 | 399 | } |
389 | 400 | return null; |
390 | 401 | } |
@@ -4,6 +4,9 @@ |
||
4 | 4 | |
5 | 5 | trait HtmlLinkTrait { |
6 | 6 | |
7 | + /** |
|
8 | + * @param string $value |
|
9 | + */ |
|
7 | 10 | public function setHref($value) { |
8 | 11 | $this->setProperty("href", $value); |
9 | 12 | } |
@@ -84,6 +84,9 @@ discard block |
||
84 | 84 | return $this; |
85 | 85 | } |
86 | 86 | |
87 | + /** |
|
88 | + * @param integer $index |
|
89 | + */ |
|
87 | 90 | public function removeItem($index){ |
88 | 91 | return array_splice($this->content, $index, 1); |
89 | 92 | } |
@@ -99,6 +102,9 @@ discard block |
||
99 | 102 | return $this->addItem($function($object)); |
100 | 103 | } |
101 | 104 | |
105 | + /** |
|
106 | + * @param \Closure $callBack |
|
107 | + */ |
|
102 | 108 | public function apply($callBack){ |
103 | 109 | foreach ($this->content as $item){ |
104 | 110 | $callBack($item); |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use Ajax\common\html\HtmlDoubleElement; |
6 | 6 | use Ajax\service\JArray; |
7 | -use Ajax\JsUtils; |
|
8 | 7 | |
9 | 8 | /** |
10 | 9 | * Base class for Html collections |
@@ -13,36 +13,36 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class HtmlCollection extends HtmlDoubleElement { |
15 | 15 | |
16 | - public function __construct($identifier,$tagName="div"){ |
|
17 | - parent::__construct($identifier,$tagName); |
|
16 | + public function __construct($identifier, $tagName="div") { |
|
17 | + parent::__construct($identifier, $tagName); |
|
18 | 18 | $this->content=array(); |
19 | 19 | } |
20 | 20 | |
21 | - public function addItems($items){ |
|
22 | - if(JArray::isAssociative($items)){ |
|
23 | - foreach ($items as $k=>$v){ |
|
24 | - $this->addItem([$k,$v]); |
|
21 | + public function addItems($items) { |
|
22 | + if (JArray::isAssociative($items)) { |
|
23 | + foreach ($items as $k=>$v) { |
|
24 | + $this->addItem([$k, $v]); |
|
25 | 25 | } |
26 | - }else{ |
|
27 | - foreach ($items as $item){ |
|
26 | + } else { |
|
27 | + foreach ($items as $item) { |
|
28 | 28 | $this->addItem($item); |
29 | 29 | } |
30 | 30 | } |
31 | 31 | return $this; |
32 | 32 | } |
33 | 33 | |
34 | - public function setItems($items){ |
|
34 | + public function setItems($items) { |
|
35 | 35 | $this->content=$items; |
36 | 36 | return $this; |
37 | 37 | } |
38 | 38 | |
39 | - public function getItems(){ |
|
39 | + public function getItems() { |
|
40 | 40 | return $this->content; |
41 | 41 | } |
42 | 42 | |
43 | - protected function getItemToAdd($item){ |
|
43 | + protected function getItemToAdd($item) { |
|
44 | 44 | $itemO=$item; |
45 | - if($this->createCondition($item)===true){ |
|
45 | + if ($this->createCondition($item)===true) { |
|
46 | 46 | $itemO=$this->createItem($item); |
47 | 47 | } |
48 | 48 | return $itemO; |
@@ -53,15 +53,15 @@ discard block |
||
53 | 53 | * @param HtmlDoubleElement|string $item |
54 | 54 | * @return \Ajax\common\html\HtmlDoubleElement |
55 | 55 | */ |
56 | - public function addItem($item){ |
|
56 | + public function addItem($item) { |
|
57 | 57 | $itemO=$this->getItemToAdd($item); |
58 | 58 | $this->addContent($itemO); |
59 | 59 | return $itemO; |
60 | 60 | } |
61 | 61 | |
62 | - public function insertItem($item,$position=0){ |
|
62 | + public function insertItem($item, $position=0) { |
|
63 | 63 | $itemO=$this->getItemToAdd($item); |
64 | - \array_splice( $this->content, $position, 0, array($itemO)); |
|
64 | + \array_splice($this->content, $position, 0, array($itemO)); |
|
65 | 65 | return $itemO; |
66 | 66 | } |
67 | 67 | |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | return $this; |
85 | 85 | } |
86 | 86 | |
87 | - public function removeItem($index){ |
|
87 | + public function removeItem($index) { |
|
88 | 88 | return array_splice($this->content, $index, 1); |
89 | 89 | } |
90 | 90 | |
91 | - public function count(){ |
|
91 | + public function count() { |
|
92 | 92 | return \sizeof($this->content); |
93 | 93 | } |
94 | 94 | |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | return $this->addItem($function($object)); |
100 | 100 | } |
101 | 101 | |
102 | - public function apply($callBack){ |
|
103 | - foreach ($this->content as $item){ |
|
102 | + public function apply($callBack) { |
|
103 | + foreach ($this->content as $item) { |
|
104 | 104 | $callBack($item); |
105 | 105 | } |
106 | 106 | return $this; |
@@ -120,12 +120,12 @@ discard block |
||
120 | 120 | */ |
121 | 121 | protected abstract function createItem($value); |
122 | 122 | |
123 | - protected function createCondition($value){ |
|
123 | + protected function createCondition($value) { |
|
124 | 124 | return \is_object($value)===false; |
125 | 125 | } |
126 | 126 | |
127 | - protected function contentAs($tagName){ |
|
128 | - foreach ($this->content as $item){ |
|
127 | + protected function contentAs($tagName) { |
|
128 | + foreach ($this->content as $item) { |
|
129 | 129 | $item->setTagName($tagName); |
130 | 130 | } |
131 | 131 | return $this; |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | foreach ($items as $k=>$v){ |
24 | 24 | $this->addItem([$k,$v]); |
25 | 25 | } |
26 | - }else{ |
|
26 | + } else{ |
|
27 | 27 | foreach ($items as $item){ |
28 | 28 | $this->addItem($item); |
29 | 29 | } |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | * @return \Ajax\common\html\HtmlDoubleElement |
72 | 72 | */ |
73 | 73 | public function getItem($index) { |
74 | - if (is_int($index)) |
|
75 | - return $this->content[$index]; |
|
76 | - else { |
|
74 | + if (is_int($index)) { |
|
75 | + return $this->content[$index]; |
|
76 | + } else { |
|
77 | 77 | $elm=$this->getElementById($index, $this->content); |
78 | 78 | return $elm; |
79 | 79 | } |
@@ -3,7 +3,17 @@ discard block |
||
3 | 3 | namespace Ajax\common\traits; |
4 | 4 | |
5 | 5 | trait JqueryActionsTrait { |
6 | + |
|
7 | + /** |
|
8 | + * @param string $element |
|
9 | + * @param string $js |
|
10 | + * @param string $event |
|
11 | + */ |
|
6 | 12 | public abstract function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
13 | + |
|
14 | + /** |
|
15 | + * @param string $element |
|
16 | + */ |
|
7 | 17 | public abstract function _prep_element($element); |
8 | 18 | public abstract function _prep_value($value); |
9 | 19 | |
@@ -384,7 +394,7 @@ discard block |
||
384 | 394 | |
385 | 395 | /** |
386 | 396 | * Ensures the speed parameter is valid for jQuery |
387 | - * @param string|int $speed |
|
397 | + * @param string $speed |
|
388 | 398 | * @return string |
389 | 399 | */ |
390 | 400 | private function _validate_speed($speed) { |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace Ajax\common\traits; |
4 | 4 | |
5 | 5 | trait JqueryActionsTrait { |
6 | - public abstract function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
6 | + public abstract function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
7 | 7 | public abstract function _prep_element($element); |
8 | 8 | public abstract function _prep_value($value); |
9 | 9 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param boolean $immediatly defers the execution if set to false |
34 | 34 | * @return string |
35 | 35 | */ |
36 | - public function after($element='this', $value='', $immediatly=false){ |
|
36 | + public function after($element='this', $value='', $immediatly=false) { |
|
37 | 37 | $element=$this->_prep_element($element); |
38 | 38 | $value=$this->_prep_value($value); |
39 | 39 | $str="$({$element}).after({$value});"; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | |
59 | 59 | $animations="\t\t\t"; |
60 | 60 | if (is_array($params)) { |
61 | - foreach ( $params as $param => $value ) { |
|
61 | + foreach ($params as $param => $value) { |
|
62 | 62 | $animations.=$param.': \''.$value.'\', '; |
63 | 63 | } |
64 | 64 | } |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | * @param boolean $immediatly |
352 | 352 | * @return string |
353 | 353 | */ |
354 | - public function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="",$immediatly=true) { |
|
355 | - return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation,$immediatly); |
|
354 | + public function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="", $immediatly=true) { |
|
355 | + return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation, $immediatly); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -378,8 +378,8 @@ discard block |
||
378 | 378 | * @param boolean $immediatly |
379 | 379 | * @return String |
380 | 380 | */ |
381 | - public function _execOn($element, $event, $js, $preventDefault=false, $stopPropagation=false,$immediatly=true) { |
|
382 | - return $this->_add_event($element, $this->_exec($js), $event, $preventDefault, $stopPropagation,$immediatly); |
|
381 | + public function _execOn($element, $event, $js, $preventDefault=false, $stopPropagation=false, $immediatly=true) { |
|
382 | + return $this->_add_event($element, $this->_exec($js), $event, $preventDefault, $stopPropagation, $immediatly); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
@@ -388,8 +388,8 @@ discard block |
||
388 | 388 | * @return string |
389 | 389 | */ |
390 | 390 | private function _validate_speed($speed) { |
391 | - if (in_array($speed, array ( |
|
392 | - 'slow','normal','fast' |
|
391 | + if (in_array($speed, array( |
|
392 | + 'slow', 'normal', 'fast' |
|
393 | 393 | ))) { |
394 | 394 | $speed='"'.$speed.'"'; |
395 | 395 | } elseif (preg_match("/[^0-9]/", $speed)) { |
@@ -19,10 +19,12 @@ discard block |
||
19 | 19 | if (isset($value)) { |
20 | 20 | $value=$this->_prep_value($value); |
21 | 21 | $str="$({$element}).attr(\"$attributeName\",{$value});"; |
22 | - } else |
|
23 | - $str="$({$element}).attr(\"$attributeName\");"; |
|
24 | - if ($immediatly) |
|
25 | - $this->jquery_code_for_compile[]=$str; |
|
22 | + } else { |
|
23 | + $str="$({$element}).attr(\"$attributeName\");"; |
|
24 | + } |
|
25 | + if ($immediatly) { |
|
26 | + $this->jquery_code_for_compile[]=$str; |
|
27 | + } |
|
26 | 28 | return $str; |
27 | 29 | } |
28 | 30 | |
@@ -37,8 +39,9 @@ discard block |
||
37 | 39 | $element=$this->_prep_element($element); |
38 | 40 | $value=$this->_prep_value($value); |
39 | 41 | $str="$({$element}).after({$value});"; |
40 | - if ($immediatly) |
|
41 | - $this->jquery_code_for_compile[]=$str; |
|
42 | + if ($immediatly) { |
|
43 | + $this->jquery_code_for_compile[]=$str; |
|
44 | + } |
|
42 | 45 | return $str; |
43 | 46 | } |
44 | 47 | |
@@ -74,8 +77,9 @@ discard block |
||
74 | 77 | |
75 | 78 | $str="$({$element}).animate({\n$animations\n\t\t}".$speed.$extra.");"; |
76 | 79 | |
77 | - if ($immediatly) |
|
78 | - $this->jquery_code_for_compile[]=$str; |
|
80 | + if ($immediatly) { |
|
81 | + $this->jquery_code_for_compile[]=$str; |
|
82 | + } |
|
79 | 83 | return $str; |
80 | 84 | } |
81 | 85 | |
@@ -100,8 +104,9 @@ discard block |
||
100 | 104 | |
101 | 105 | $str="$({$element}).fadeIn({$speed}{$callback});"; |
102 | 106 | |
103 | - if ($immediatly) |
|
104 | - $this->jquery_code_for_compile[]=$str; |
|
107 | + if ($immediatly) { |
|
108 | + $this->jquery_code_for_compile[]=$str; |
|
109 | + } |
|
105 | 110 | return $str; |
106 | 111 | } |
107 | 112 | |
@@ -126,8 +131,9 @@ discard block |
||
126 | 131 | |
127 | 132 | $str="$({$element}).fadeOut({$speed}{$callback});"; |
128 | 133 | |
129 | - if ($immediatly) |
|
130 | - $this->jquery_code_for_compile[]=$str; |
|
134 | + if ($immediatly) { |
|
135 | + $this->jquery_code_for_compile[]=$str; |
|
136 | + } |
|
131 | 137 | return $str; |
132 | 138 | } |
133 | 139 | |
@@ -152,8 +158,9 @@ discard block |
||
152 | 158 | |
153 | 159 | $str="$({$element}).hide({$speed}{$callback});"; |
154 | 160 | |
155 | - if ($immediatly) |
|
156 | - $this->jquery_code_for_compile[]=$str; |
|
161 | + if ($immediatly) { |
|
162 | + $this->jquery_code_for_compile[]=$str; |
|
163 | + } |
|
157 | 164 | return $str; |
158 | 165 | } |
159 | 166 | |
@@ -180,8 +187,9 @@ discard block |
||
180 | 187 | |
181 | 188 | $str="$({$element}).slideUp({$speed}{$callback});"; |
182 | 189 | |
183 | - if ($immediatly) |
|
184 | - $this->jquery_code_for_compile[]=$str; |
|
190 | + if ($immediatly) { |
|
191 | + $this->jquery_code_for_compile[]=$str; |
|
192 | + } |
|
185 | 193 | return $str; |
186 | 194 | } |
187 | 195 | |
@@ -206,8 +214,9 @@ discard block |
||
206 | 214 | |
207 | 215 | $str="$({$element}).slideDown({$speed}{$callback});"; |
208 | 216 | |
209 | - if ($immediatly) |
|
210 | - $this->jquery_code_for_compile[]=$str; |
|
217 | + if ($immediatly) { |
|
218 | + $this->jquery_code_for_compile[]=$str; |
|
219 | + } |
|
211 | 220 | return $str; |
212 | 221 | } |
213 | 222 | |
@@ -232,8 +241,9 @@ discard block |
||
232 | 241 | |
233 | 242 | $str="$({$element}).slideToggle({$speed}{$callback});"; |
234 | 243 | |
235 | - if ($immediatly) |
|
236 | - $this->jquery_code_for_compile[]=$str; |
|
244 | + if ($immediatly) { |
|
245 | + $this->jquery_code_for_compile[]=$str; |
|
246 | + } |
|
237 | 247 | return $str; |
238 | 248 | } |
239 | 249 | |
@@ -250,8 +260,9 @@ discard block |
||
250 | 260 | $element=$this->_prep_element($element); |
251 | 261 | $str="$({$element}).toggle();"; |
252 | 262 | |
253 | - if ($immediatly) |
|
254 | - $this->jquery_code_for_compile[]=$str; |
|
263 | + if ($immediatly) { |
|
264 | + $this->jquery_code_for_compile[]=$str; |
|
265 | + } |
|
255 | 266 | return $str; |
256 | 267 | } |
257 | 268 | |
@@ -267,8 +278,9 @@ discard block |
||
267 | 278 | $element=$this->_prep_element($element); |
268 | 279 | $str="$({$element}).trigger(\"$event\");"; |
269 | 280 | |
270 | - if ($immediatly) |
|
271 | - $this->jquery_code_for_compile[]=$str; |
|
281 | + if ($immediatly) { |
|
282 | + $this->jquery_code_for_compile[]=$str; |
|
283 | + } |
|
272 | 284 | return $str; |
273 | 285 | } |
274 | 286 | |
@@ -293,8 +305,9 @@ discard block |
||
293 | 305 | |
294 | 306 | $str="$({$element}).show({$speed}{$callback});"; |
295 | 307 | |
296 | - if ($immediatly) |
|
297 | - $this->jquery_code_for_compile[]=$str; |
|
308 | + if ($immediatly) { |
|
309 | + $this->jquery_code_for_compile[]=$str; |
|
310 | + } |
|
298 | 311 | return $str; |
299 | 312 | } |
300 | 313 | |
@@ -312,8 +325,9 @@ discard block |
||
312 | 325 | $str.="else{".$jsCodeIfFalse."}"; |
313 | 326 | } |
314 | 327 | |
315 | - if ($immediatly) |
|
316 | - $this->jquery_code_for_compile[]=$str; |
|
328 | + if ($immediatly) { |
|
329 | + $this->jquery_code_for_compile[]=$str; |
|
330 | + } |
|
317 | 331 | return $str; |
318 | 332 | } |
319 | 333 | |
@@ -330,11 +344,13 @@ discard block |
||
330 | 344 | public function _doJQuery($element, $jqueryCall, $param="", $jsCallback="", $immediatly=false) { |
331 | 345 | $param=$this->_prep_value($param); |
332 | 346 | $callback=""; |
333 | - if ($jsCallback!="") |
|
334 | - $callback=", function(event){\n{$jsCallback}\n}"; |
|
347 | + if ($jsCallback!="") { |
|
348 | + $callback=", function(event){\n{$jsCallback}\n}"; |
|
349 | + } |
|
335 | 350 | $script="$(".$this->_prep_element($element).").".$jqueryCall."(".$param.$callback.");\n"; |
336 | - if ($immediatly) |
|
337 | - $this->jquery_code_for_compile[]=$script; |
|
351 | + if ($immediatly) { |
|
352 | + $this->jquery_code_for_compile[]=$script; |
|
353 | + } |
|
338 | 354 | return $script; |
339 | 355 | } |
340 | 356 | |
@@ -363,8 +379,9 @@ discard block |
||
363 | 379 | */ |
364 | 380 | public function _exec($js, $immediatly=false) { |
365 | 381 | $script=$js."\n"; |
366 | - if ($immediatly) |
|
367 | - $this->jquery_code_for_compile[]=$script; |
|
382 | + if ($immediatly) { |
|
383 | + $this->jquery_code_for_compile[]=$script; |
|
384 | + } |
|
368 | 385 | return $script; |
369 | 386 | } |
370 | 387 |
@@ -10,7 +10,17 @@ discard block |
||
10 | 10 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
11 | 11 | |
12 | 12 | public abstract function _prep_value($value); |
13 | + |
|
14 | + /** |
|
15 | + * @param string $element |
|
16 | + * @param string $js |
|
17 | + * @param string $event |
|
18 | + */ |
|
13 | 19 | public abstract function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
20 | + |
|
21 | + /** |
|
22 | + * @param string $retour |
|
23 | + */ |
|
14 | 24 | protected function addLoading(&$retour, $responseElement) { |
15 | 25 | $loading_notifier='<div class="ajax-loader">'; |
16 | 26 | if ($this->ajaxLoader=='') { |
@@ -23,13 +33,23 @@ discard block |
||
23 | 33 | $retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n"; |
24 | 34 | } |
25 | 35 | |
36 | + /** |
|
37 | + * @param string $url |
|
38 | + */ |
|
26 | 39 | public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
27 | 40 | return $this->_ajax("get", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$immediatly); |
28 | 41 | } |
42 | + |
|
43 | + /** |
|
44 | + * @param string $url |
|
45 | + */ |
|
29 | 46 | public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
30 | 47 | return $this->_ajax("post", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$immediatly); |
31 | 48 | } |
32 | 49 | |
50 | + /** |
|
51 | + * @param string $method |
|
52 | + */ |
|
33 | 53 | protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
34 | 54 | if(JString::isNull($params)){$params="{}";} |
35 | 55 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
@@ -46,6 +66,9 @@ discard block |
||
46 | 66 | return $retour; |
47 | 67 | } |
48 | 68 | |
69 | + /** |
|
70 | + * @param string $attr |
|
71 | + */ |
|
49 | 72 | protected function _getAjaxUrl($url,$attr){ |
50 | 73 | $url=$this->_correctAjaxUrl($url); |
51 | 74 | $retour="url='".$url."';\n"; |
@@ -177,6 +200,11 @@ discard block |
||
177 | 200 | return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation,$immediatly); |
178 | 201 | } |
179 | 202 | |
203 | + /** |
|
204 | + * @param string $url |
|
205 | + * @param string $form |
|
206 | + * @param string $responseElement |
|
207 | + */ |
|
180 | 208 | public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
181 | 209 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
182 | 210 | $retour=$this->_getAjaxUrl($url, $attr); |
@@ -3,8 +3,6 @@ |
||
3 | 3 | namespace Ajax\common\traits; |
4 | 4 | |
5 | 5 | use Ajax\service\JString; |
6 | -use Ajax\service\PhalconUtils; |
|
7 | -use Symfony\Component\Config\Definition\Exception\Exception; |
|
8 | 6 | trait JqueryAjaxTrait { |
9 | 7 | |
10 | 8 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
11 | 11 | |
12 | 12 | public abstract function _prep_value($value); |
13 | - public abstract function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
13 | + public abstract function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
14 | 14 | protected function addLoading(&$retour, $responseElement) { |
15 | 15 | $loading_notifier='<div class="ajax-loader">'; |
16 | 16 | if ($this->ajaxLoader=='') { |
@@ -23,20 +23,20 @@ discard block |
||
23 | 23 | $retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n"; |
24 | 24 | } |
25 | 25 | |
26 | - public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
|
27 | - return $this->_ajax("get", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$immediatly); |
|
26 | + public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $immediatly=false) { |
|
27 | + return $this->_ajax("get", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $immediatly); |
|
28 | 28 | } |
29 | - public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
|
30 | - return $this->_ajax("post", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$immediatly); |
|
29 | + public function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $immediatly=false) { |
|
30 | + return $this->_ajax("post", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $immediatly); |
|
31 | 31 | } |
32 | 32 | |
33 | - protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
|
34 | - if(JString::isNull($params)){$params="{}";} |
|
33 | + protected function _ajax($method, $url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $immediatly=false) { |
|
34 | + if (JString::isNull($params)) {$params="{}"; } |
|
35 | 35 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
36 | 36 | $retour=$this->_getAjaxUrl($url, $attr); |
37 | 37 | $responseElement=$this->_getResponseElement($responseElement); |
38 | 38 | $retour.="var self=this;\n"; |
39 | - if($hasLoader===true){ |
|
39 | + if ($hasLoader===true) { |
|
40 | 40 | $this->addLoading($retour, $responseElement); |
41 | 41 | } |
42 | 42 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
@@ -46,22 +46,22 @@ discard block |
||
46 | 46 | return $retour; |
47 | 47 | } |
48 | 48 | |
49 | - protected function _getAjaxUrl($url,$attr){ |
|
49 | + protected function _getAjaxUrl($url, $attr) { |
|
50 | 50 | $url=$this->_correctAjaxUrl($url); |
51 | 51 | $retour="url='".$url."';\n"; |
52 | 52 | $slash="/"; |
53 | - if(JString::endswith($url, "/")===true) |
|
53 | + if (JString::endswith($url, "/")===true) |
|
54 | 54 | $slash=""; |
55 | - if(JString::isNotNull($attr)){ |
|
55 | + if (JString::isNotNull($attr)) { |
|
56 | 56 | if ($attr=="value") |
57 | 57 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
58 | - else if($attr!=null && $attr!=="") |
|
58 | + else if ($attr!=null && $attr!=="") |
|
59 | 59 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
60 | 60 | } |
61 | 61 | return $retour; |
62 | 62 | } |
63 | 63 | |
64 | - protected function _getOnAjaxDone($responseElement,$jsCallback){ |
|
64 | + protected function _getOnAjaxDone($responseElement, $jsCallback) { |
|
65 | 65 | $retour=""; |
66 | 66 | if ($responseElement!=="") { |
67 | 67 | $retour="\t$({$responseElement}).html( data );\n"; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | return $retour; |
71 | 71 | } |
72 | 72 | |
73 | - protected function _getResponseElement($responseElement){ |
|
73 | + protected function _getResponseElement($responseElement) { |
|
74 | 74 | if ($responseElement!=="") { |
75 | 75 | $responseElement=$this->_prep_value($responseElement); |
76 | 76 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | protected function _correctAjaxUrl($url) { |
81 | 81 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
82 | 82 | $url=substr($url, 0, strlen($url)-1); |
83 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
83 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
84 | 84 | $url=$this->jsUtils->getUrl($url); |
85 | 85 | } |
86 | 86 | return $url; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param string $jsCallback javascript code to execute after the request |
95 | 95 | * @param boolean $immediatly |
96 | 96 | */ |
97 | - public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
97 | + public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
98 | 98 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
99 | 99 | $retour=$this->_getAjaxUrl($url, $attr); |
100 | 100 | $retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @param string $url the request address |
116 | 116 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
117 | 117 | */ |
118 | - public function _jsonOn($event,$element, $url,$parameters=array()) { |
|
118 | + public function _jsonOn($event, $element, $url, $parameters=array()) { |
|
119 | 119 | $preventDefault=true; |
120 | 120 | $stopPropagation=true; |
121 | 121 | $jsCallback=null; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | $params="{}"; |
126 | 126 | $immediatly=true; |
127 | 127 | extract($parameters); |
128 | - return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
128 | + return $this->_add_event($element, $this->_json($url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -137,19 +137,19 @@ discard block |
||
137 | 137 | * @param string $context jquery DOM element, array container. |
138 | 138 | * @param boolean $immediatly |
139 | 139 | */ |
140 | - public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null,$immediatly=false) { |
|
140 | + public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null, $immediatly=false) { |
|
141 | 141 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
142 | 142 | $retour=$this->_getAjaxUrl($url, $attr); |
143 | - if($context===null){ |
|
143 | + if ($context===null) { |
|
144 | 144 | $appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n"; |
145 | - $newElm = "$('#'+newId)"; |
|
146 | - }else{ |
|
145 | + $newElm="$('#'+newId)"; |
|
146 | + } else { |
|
147 | 147 | $appendTo="\t\tnewElm.appendTo(".$context.");\n"; |
148 | - $newElm = $context.".find('#'+newId)"; |
|
148 | + $newElm=$context.".find('#'+newId)"; |
|
149 | 149 | } |
150 | 150 | $retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
151 | 151 | $retour.="\tdata=$.parseJSON(data);$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone();newElm.attr('id',newId);\n"; |
152 | - $retour.= $appendTo; |
|
152 | + $retour.=$appendTo; |
|
153 | 153 | $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('[['+key+']]')>-1){\n"."\t\t\t\tcontent=$(html.split('[['+key+']]').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
154 | 154 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
155 | 155 | $retour.="\t".$jsCallback."\n"."});\n"; |
@@ -164,26 +164,26 @@ discard block |
||
164 | 164 | * @param string $url the request address |
165 | 165 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get", "context"=>null) |
166 | 166 | */ |
167 | - public function _jsonArrayOn($event,$element, $maskSelector,$url,$parameters=array()) { |
|
167 | + public function _jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
168 | 168 | $preventDefault=true; |
169 | 169 | $stopPropagation=true; |
170 | 170 | $jsCallback=null; |
171 | 171 | $attr="id"; |
172 | 172 | $method="get"; |
173 | - $context = null; |
|
173 | + $context=null; |
|
174 | 174 | $params="{}"; |
175 | 175 | $immediatly=true; |
176 | 176 | extract($parameters); |
177 | - return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
177 | + return $this->_add_event($element, $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
178 | 178 | } |
179 | 179 | |
180 | - public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
|
180 | + public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $immediatly=false) { |
|
181 | 181 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
182 | 182 | $retour=$this->_getAjaxUrl($url, $attr); |
183 | 183 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
184 | 184 | $responseElement=$this->_getResponseElement($responseElement); |
185 | 185 | $retour.="var self=this;\n"; |
186 | - if($hasLoader===true){ |
|
186 | + if ($hasLoader===true) { |
|
187 | 187 | $this->addLoading($retour, $responseElement); |
188 | 188 | } |
189 | 189 | $retour.="$.post(url,params).done(function( data ) {\n"; |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @param string $responseElement |
211 | 211 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true) |
212 | 212 | */ |
213 | - public function _getOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
213 | + public function _getOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
214 | 214 | $preventDefault=true; |
215 | 215 | $stopPropagation=true; |
216 | 216 | $jsCallback=null; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | $hasLoader=true; |
219 | 219 | $immediatly=true; |
220 | 220 | extract($parameters); |
221 | - return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr,$hasLoader), $event, $preventDefault, $stopPropagation,$immediatly); |
|
221 | + return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr, $hasLoader), $event, $preventDefault, $stopPropagation, $immediatly); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @param string $responseElement |
232 | 232 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true) |
233 | 233 | */ |
234 | - public function _postOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
234 | + public function _postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
235 | 235 | $preventDefault=true; |
236 | 236 | $stopPropagation=true; |
237 | 237 | $jsCallback=null; |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | $hasLoader=true; |
240 | 240 | $immediatly=true; |
241 | 241 | extract($parameters); |
242 | - return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr,$hasLoader), $event, $preventDefault, $stopPropagation,$immediatly); |
|
242 | + return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader), $event, $preventDefault, $stopPropagation, $immediatly); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @param string $responseElement |
253 | 253 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true) |
254 | 254 | */ |
255 | - public function _postFormOn($event,$element, $url, $form, $responseElement="", $parameters=array()) { |
|
255 | + public function _postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
256 | 256 | $preventDefault=true; |
257 | 257 | $stopPropagation=true; |
258 | 258 | $validation=false; |
@@ -261,6 +261,6 @@ discard block |
||
261 | 261 | $hasLoader=true; |
262 | 262 | $immediatly=true; |
263 | 263 | extract($parameters); |
264 | - return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader), $event, $preventDefault, $stopPropagation,$immediatly); |
|
264 | + return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader), $event, $preventDefault, $stopPropagation, $immediatly); |
|
265 | 265 | } |
266 | 266 | } |
267 | 267 | \ No newline at end of file |
@@ -41,8 +41,9 @@ discard block |
||
41 | 41 | } |
42 | 42 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
43 | 43 | $retour.=$this->_getOnAjaxDone($responseElement, $jsCallback)."});\n"; |
44 | - if ($immediatly) |
|
45 | - $this->jquery_code_for_compile[]=$retour; |
|
44 | + if ($immediatly) { |
|
45 | + $this->jquery_code_for_compile[]=$retour; |
|
46 | + } |
|
46 | 47 | return $retour; |
47 | 48 | } |
48 | 49 | |
@@ -50,13 +51,15 @@ discard block |
||
50 | 51 | $url=$this->_correctAjaxUrl($url); |
51 | 52 | $retour="url='".$url."';\n"; |
52 | 53 | $slash="/"; |
53 | - if(JString::endswith($url, "/")===true) |
|
54 | - $slash=""; |
|
54 | + if(JString::endswith($url, "/")===true) { |
|
55 | + $slash=""; |
|
56 | + } |
|
55 | 57 | if(JString::isNotNull($attr)){ |
56 | - if ($attr=="value") |
|
57 | - $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
58 | - else if($attr!=null && $attr!=="") |
|
59 | - $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
58 | + if ($attr=="value") { |
|
59 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
60 | + } else if($attr!=null && $attr!=="") { |
|
61 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
62 | + } |
|
60 | 63 | } |
61 | 64 | return $retour; |
62 | 65 | } |
@@ -78,8 +81,9 @@ discard block |
||
78 | 81 | } |
79 | 82 | |
80 | 83 | protected function _correctAjaxUrl($url) { |
81 | - if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
82 | - $url=substr($url, 0, strlen($url)-1); |
|
84 | + if ($url!=="/" && JString::endsWith($url, "/")===true) { |
|
85 | + $url=substr($url, 0, strlen($url)-1); |
|
86 | + } |
|
83 | 87 | if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
84 | 88 | $url=$this->jsUtils->getUrl($url); |
85 | 89 | } |
@@ -103,8 +107,9 @@ discard block |
||
103 | 107 | $retour.="\t".$jsCallback."\n". |
104 | 108 | "\t$(document).trigger('jsonReady',[data]);\n". |
105 | 109 | "});\n"; |
106 | - if ($immediatly) |
|
107 | - $this->jquery_code_for_compile[]=$retour; |
|
110 | + if ($immediatly) { |
|
111 | + $this->jquery_code_for_compile[]=$retour; |
|
112 | + } |
|
108 | 113 | return $retour; |
109 | 114 | } |
110 | 115 | |
@@ -143,7 +148,7 @@ discard block |
||
143 | 148 | if($context===null){ |
144 | 149 | $appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n"; |
145 | 150 | $newElm = "$('#'+newId)"; |
146 | - }else{ |
|
151 | + } else{ |
|
147 | 152 | $appendTo="\t\tnewElm.appendTo(".$context.");\n"; |
148 | 153 | $newElm = $context.".find('#'+newId)"; |
149 | 154 | } |
@@ -153,8 +158,9 @@ discard block |
||
153 | 158 | $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('[['+key+']]')>-1){\n"."\t\t\t\tcontent=$(html.split('[['+key+']]').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
154 | 159 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
155 | 160 | $retour.="\t".$jsCallback."\n"."});\n"; |
156 | - if ($immediatly) |
|
157 | - $this->jquery_code_for_compile[]=$retour; |
|
161 | + if ($immediatly) { |
|
162 | + $this->jquery_code_for_compile[]=$retour; |
|
163 | + } |
|
158 | 164 | return $retour; |
159 | 165 | } |
160 | 166 | /** |
@@ -195,8 +201,9 @@ discard block |
||
195 | 201 | }});\n"; |
196 | 202 | $retour.="$('#".$form."').submit();\n"; |
197 | 203 | } |
198 | - if ($immediatly) |
|
199 | - $this->jquery_code_for_compile[]=$retour; |
|
204 | + if ($immediatly) { |
|
205 | + $this->jquery_code_for_compile[]=$retour; |
|
206 | + } |
|
200 | 207 | return $retour; |
201 | 208 | } |
202 | 209 |
@@ -3,7 +3,16 @@ |
||
3 | 3 | namespace Ajax\common\traits; |
4 | 4 | |
5 | 5 | trait JqueryEventsTrait { |
6 | + |
|
7 | + /** |
|
8 | + * @param string $element |
|
9 | + */ |
|
6 | 10 | public abstract function _prep_element($element); |
11 | + |
|
12 | + /** |
|
13 | + * @param string $element |
|
14 | + * @param string $event |
|
15 | + */ |
|
7 | 16 | public abstract function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
8 | 17 | |
9 | 18 | /** |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | trait JqueryEventsTrait { |
6 | 6 | public abstract function _prep_element($element); |
7 | - public abstract function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
7 | + public abstract function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Blur |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function _click($element='this', $js=array(), $ret_false=TRUE) { |
48 | 48 | if (!is_array($js)) { |
49 | - $js=array ( |
|
49 | + $js=array( |
|
50 | 50 | $js |
51 | 51 | ); |
52 | 52 | } |
@@ -55,6 +55,9 @@ discard block |
||
55 | 55 | return $this->_semantic; |
56 | 56 | } |
57 | 57 | |
58 | + /** |
|
59 | + * @param JsUtils $jsUtils |
|
60 | + */ |
|
58 | 61 | public function __construct($params,$jsUtils) { |
59 | 62 | $this->params=array(); |
60 | 63 | foreach ( $params as $key => $val ) { |
@@ -175,7 +178,7 @@ discard block |
||
175 | 178 | * |
176 | 179 | * @param string $element |
177 | 180 | * @param array $options |
178 | - * @return void |
|
181 | + * @return string |
|
179 | 182 | */ |
180 | 183 | public function sortable($element, $options=array()) { |
181 | 184 | if (count($options)>0) { |
@@ -307,6 +310,7 @@ discard block |
||
307 | 310 | |
308 | 311 | /** |
309 | 312 | * A wrapper for writing document.ready() |
313 | + * @param string $js |
|
310 | 314 | * @return string |
311 | 315 | */ |
312 | 316 | public function _document_ready($js) { |
@@ -354,6 +358,9 @@ discard block |
||
354 | 358 | return $value; |
355 | 359 | } |
356 | 360 | |
361 | + /** |
|
362 | + * @param string $input |
|
363 | + */ |
|
357 | 364 | private function minify($input) { |
358 | 365 | if(trim($input) === "") return $input; |
359 | 366 | return preg_replace( |
@@ -17,21 +17,21 @@ discard block |
||
17 | 17 | * jQuery Class |
18 | 18 | */ |
19 | 19 | class Jquery { |
20 | - use JqueryEventsTrait,JqueryAjaxTrait,JqueryActionsTrait; |
|
20 | + use JqueryEventsTrait, JqueryAjaxTrait, JqueryActionsTrait; |
|
21 | 21 | protected $_ui; |
22 | 22 | protected $_bootstrap; |
23 | 23 | protected $_semantic; |
24 | 24 | protected $libraryFile; |
25 | 25 | protected $_javascript_folder='js'; |
26 | - protected $jquery_code_for_load=array (); |
|
27 | - protected $jquery_code_for_compile=array (); |
|
26 | + protected $jquery_code_for_load=array(); |
|
27 | + protected $jquery_code_for_compile=array(); |
|
28 | 28 | protected $jquery_corner_active=FALSE; |
29 | 29 | protected $jquery_table_sorter_active=FALSE; |
30 | 30 | protected $jquery_table_sorter_pager_active=FALSE; |
31 | 31 | protected $jsUtils; |
32 | 32 | |
33 | - protected $jquery_events=array ( |
|
34 | - "bind","blur","change","click","dblclick","delegate","die","error","focus","focusin","focusout","hover","keydown","keypress","keyup","live","load","mousedown","mousseenter","mouseleave","mousemove","mouseout","mouseover","mouseup","off","on","one","ready","resize","scroll","select","submit","toggle","trigger","triggerHandler","undind","undelegate","unload" |
|
33 | + protected $jquery_events=array( |
|
34 | + "bind", "blur", "change", "click", "dblclick", "delegate", "die", "error", "focus", "focusin", "focusout", "hover", "keydown", "keypress", "keyup", "live", "load", "mousedown", "mousseenter", "mouseleave", "mousemove", "mouseout", "mouseover", "mouseup", "off", "on", "one", "ready", "resize", "scroll", "select", "submit", "toggle", "trigger", "triggerHandler", "undind", "undelegate", "unload" |
|
35 | 35 | ); |
36 | 36 | |
37 | 37 | public function ui($ui=NULL) { |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | return $this->_semantic; |
56 | 56 | } |
57 | 57 | |
58 | - public function __construct($params,$jsUtils) { |
|
58 | + public function __construct($params, $jsUtils) { |
|
59 | 59 | $this->params=array(); |
60 | - foreach ( $params as $key => $val ) { |
|
60 | + foreach ($params as $key => $val) { |
|
61 | 61 | $this->params[$key]=$params[$key]; |
62 | 62 | } |
63 | 63 | $this->jsUtils=$jsUtils; |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function _output($array_js='') { |
127 | 127 | if (!is_array($array_js)) { |
128 | - $array_js=array ( |
|
128 | + $array_js=array( |
|
129 | 129 | $array_js |
130 | 130 | ); |
131 | 131 | } |
132 | 132 | |
133 | - foreach ( $array_js as $js ) { |
|
133 | + foreach ($array_js as $js) { |
|
134 | 134 | $this->jquery_code_for_compile[]="\t$js\n"; |
135 | 135 | } |
136 | 136 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param string $param |
143 | 143 | * @param boolean $immediatly delayed if false |
144 | 144 | */ |
145 | - public function _genericCallValue($jQueryCall,$element='this', $param="", $immediatly=false) { |
|
145 | + public function _genericCallValue($jQueryCall, $element='this', $param="", $immediatly=false) { |
|
146 | 146 | $element=$this->_prep_element($element); |
147 | 147 | if (isset($param)) { |
148 | 148 | $param=$this->_prep_value($param); |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @param boolean $immediatly delayed if false |
162 | 162 | * @return string |
163 | 163 | */ |
164 | - public function _genericCallElement($jQueryCall,$to='this', $element, $immediatly=false) { |
|
164 | + public function _genericCallElement($jQueryCall, $to='this', $element, $immediatly=false) { |
|
165 | 165 | $to=$this->_prep_element($to); |
166 | 166 | $element=$this->_prep_element($element); |
167 | 167 | $str="$({$to}).{$jQueryCall}({$element});"; |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function sortable($element, $options=array()) { |
181 | 181 | if (count($options)>0) { |
182 | - $sort_options=array (); |
|
183 | - foreach ( $options as $k => $v ) { |
|
182 | + $sort_options=array(); |
|
183 | + foreach ($options as $k => $v) { |
|
184 | 184 | $sort_options[]="\n\t\t".$k.': '.$v.""; |
185 | 185 | } |
186 | 186 | $sort_options=implode(",", $sort_options); |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * @param boolean $stopPropagation Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. |
213 | 213 | * @return string |
214 | 214 | */ |
215 | - public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true) { |
|
215 | + public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true) { |
|
216 | 216 | if (is_array($js)) { |
217 | 217 | $js=implode("\n\t\t", $js); |
218 | 218 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $event="\n\t$(".$this->_prep_element($element).").bind('{$event}',function(event){\n\t\t{$js}\n\t});\n"; |
227 | 227 | else |
228 | 228 | $event="\n\t$(".$this->_prep_element($element).").{$event}(function(event){\n\t\t{$js}\n\t});\n"; |
229 | - if($immediatly) |
|
229 | + if ($immediatly) |
|
230 | 230 | $this->jquery_code_for_compile[]=$event; |
231 | 231 | return $event; |
232 | 232 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | |
267 | 267 | // External references |
268 | 268 | $external_scripts=implode('', $this->jquery_code_for_load); |
269 | - extract(array ( |
|
269 | + extract(array( |
|
270 | 270 | 'library_src' => $external_scripts |
271 | 271 | )); |
272 | 272 | |
@@ -281,13 +281,13 @@ discard block |
||
281 | 281 | $script.='});'; |
282 | 282 | |
283 | 283 | $this->jquery_code_for_compile=array(); |
284 | - if($this->params["debug"]==false){ |
|
284 | + if ($this->params["debug"]==false) { |
|
285 | 285 | $script=$this->minify($script); |
286 | 286 | } |
287 | 287 | $output=($script_tags===FALSE) ? $script : $this->inline($script); |
288 | 288 | |
289 | - if ($view!==NULL){ |
|
290 | - $this->jsUtils->createScriptVariable($view,$view_var, $output); |
|
289 | + if ($view!==NULL) { |
|
290 | + $this->jsUtils->createScriptVariable($view, $view_var, $output); |
|
291 | 291 | } |
292 | 292 | return $output; |
293 | 293 | } |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | * @return void |
303 | 303 | */ |
304 | 304 | public function _clear_compile() { |
305 | - $this->jquery_code_for_compile=array (); |
|
305 | + $this->jquery_code_for_compile=array(); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -311,12 +311,12 @@ discard block |
||
311 | 311 | */ |
312 | 312 | public function _document_ready($js) { |
313 | 313 | if (!is_array($js)) { |
314 | - $js=array ( |
|
314 | + $js=array( |
|
315 | 315 | $js |
316 | 316 | ); |
317 | 317 | } |
318 | 318 | |
319 | - foreach ( $js as $script ) { |
|
319 | + foreach ($js as $script) { |
|
320 | 320 | $this->jquery_code_for_compile[]=$script; |
321 | 321 | } |
322 | 322 | } |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | * @return string |
331 | 331 | */ |
332 | 332 | public function _prep_element($element) { |
333 | - if (strrpos($element, 'this')===false&&strrpos($element, 'event')===false&&strrpos($element, 'self')===false) { |
|
333 | + if (strrpos($element, 'this')===false && strrpos($element, 'event')===false && strrpos($element, 'self')===false) { |
|
334 | 334 | $element='"'.addslashes($element).'"'; |
335 | 335 | } |
336 | 336 | return $element; |
@@ -348,14 +348,14 @@ discard block |
||
348 | 348 | if (is_array($value)) { |
349 | 349 | $value=implode(",", $value); |
350 | 350 | } |
351 | - if (strrpos($value, 'this')===false&&strrpos($value, 'event')===false&&strrpos($value, 'self')===false) { |
|
351 | + if (strrpos($value, 'this')===false && strrpos($value, 'event')===false && strrpos($value, 'self')===false) { |
|
352 | 352 | $value='"'.$value.'"'; |
353 | 353 | } |
354 | 354 | return $value; |
355 | 355 | } |
356 | 356 | |
357 | 357 | private function minify($input) { |
358 | - if(trim($input) === "") return $input; |
|
358 | + if (trim($input)==="") return $input; |
|
359 | 359 | return preg_replace( |
360 | 360 | array( |
361 | 361 | // Remove comment(s) |
@@ -147,10 +147,12 @@ discard block |
||
147 | 147 | if (isset($param)) { |
148 | 148 | $param=$this->_prep_value($param); |
149 | 149 | $str="$({$element}).{$jQueryCall}({$param});"; |
150 | - } else |
|
151 | - $str="$({$element}).{$jQueryCall}();"; |
|
152 | - if ($immediatly) |
|
153 | - $this->jquery_code_for_compile[]=$str; |
|
150 | + } else { |
|
151 | + $str="$({$element}).{$jQueryCall}();"; |
|
152 | + } |
|
153 | + if ($immediatly) { |
|
154 | + $this->jquery_code_for_compile[]=$str; |
|
155 | + } |
|
154 | 156 | return $str; |
155 | 157 | } |
156 | 158 | /** |
@@ -165,8 +167,9 @@ discard block |
||
165 | 167 | $to=$this->_prep_element($to); |
166 | 168 | $element=$this->_prep_element($element); |
167 | 169 | $str="$({$to}).{$jQueryCall}({$element});"; |
168 | - if ($immediatly) |
|
169 | - $this->jquery_code_for_compile[]=$str; |
|
170 | + if ($immediatly) { |
|
171 | + $this->jquery_code_for_compile[]=$str; |
|
172 | + } |
|
170 | 173 | return $str; |
171 | 174 | } |
172 | 175 | |
@@ -222,12 +225,14 @@ discard block |
||
222 | 225 | if ($stopPropagation===true) { |
223 | 226 | $js="event.stopPropagation();\n".$js; |
224 | 227 | } |
225 | - if (array_search($event, $this->jquery_events)===false) |
|
226 | - $event="\n\t$(".$this->_prep_element($element).").bind('{$event}',function(event){\n\t\t{$js}\n\t});\n"; |
|
227 | - else |
|
228 | - $event="\n\t$(".$this->_prep_element($element).").{$event}(function(event){\n\t\t{$js}\n\t});\n"; |
|
229 | - if($immediatly) |
|
230 | - $this->jquery_code_for_compile[]=$event; |
|
228 | + if (array_search($event, $this->jquery_events)===false) { |
|
229 | + $event="\n\t$(".$this->_prep_element($element).").bind('{$event}',function(event){\n\t\t{$js}\n\t});\n"; |
|
230 | + } else { |
|
231 | + $event="\n\t$(".$this->_prep_element($element).").{$event}(function(event){\n\t\t{$js}\n\t});\n"; |
|
232 | + } |
|
233 | + if($immediatly) { |
|
234 | + $this->jquery_code_for_compile[]=$event; |
|
235 | + } |
|
231 | 236 | return $event; |
232 | 237 | } |
233 | 238 | |
@@ -355,7 +360,9 @@ discard block |
||
355 | 360 | } |
356 | 361 | |
357 | 362 | private function minify($input) { |
358 | - if(trim($input) === "") return $input; |
|
363 | + if(trim($input) === "") { |
|
364 | + return $input; |
|
365 | + } |
|
359 | 366 | return preg_replace( |
360 | 367 | array( |
361 | 368 | // Remove comment(s) |