@@ -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 | } |
@@ -429,7 +429,7 @@ |
||
| 429 | 429 | * |
| 430 | 430 | * @access public |
| 431 | 431 | * @param array an associative array of key/values |
| 432 | - * @return array |
|
| 432 | + * @return string |
|
| 433 | 433 | * |
| 434 | 434 | */ |
| 435 | 435 | function assoc_to_uri($array) { |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @access public |
| 11 | 11 | * |
| 12 | 12 | */ |
| 13 | - var $keyval=array (); |
|
| 13 | + var $keyval=array(); |
|
| 14 | 14 | /** |
| 15 | 15 | * Current uri string |
| 16 | 16 | * |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * @access public |
| 27 | 27 | * |
| 28 | 28 | */ |
| 29 | - var $segments=array (); |
|
| 29 | + var $segments=array(); |
|
| 30 | 30 | /** |
| 31 | 31 | * Re-indexed list of uri segments |
| 32 | 32 | * Starts at 1 instead of 0 |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @access public |
| 36 | 36 | * |
| 37 | 37 | */ |
| 38 | - var $rsegments=array (); |
|
| 38 | + var $rsegments=array(); |
|
| 39 | 39 | var $permitted_uri_chars="a-z 0-9~%.:_\-"; |
| 40 | 40 | var $enable_query_strings=false; |
| 41 | 41 | |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | function _fetch_uri_string() { |
| 77 | 77 | $uri=""; |
| 78 | - if ($this->uri_protocol == 'AUTO') { |
|
| 78 | + if ($this->uri_protocol=='AUTO') { |
|
| 79 | 79 | // Is the request coming from the command line? |
| 80 | - if (php_sapi_name() == 'cli' or defined('STDIN')) { |
|
| 80 | + if (php_sapi_name()=='cli' or defined('STDIN')) { |
|
| 81 | 81 | $this->_set_uri_string($this->_parse_cli_args()); |
| 82 | 82 | return; |
| 83 | 83 | } |
@@ -91,20 +91,20 @@ discard block |
||
| 91 | 91 | // Is there a PATH_INFO variable? |
| 92 | 92 | // Note: some servers seem to have trouble with getenv() so we'll test it two ways |
| 93 | 93 | $path=(isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); |
| 94 | - if (trim($path, '/') != '' && $path != "/" . SELF) { |
|
| 94 | + if (trim($path, '/')!='' && $path!="/".SELF) { |
|
| 95 | 95 | $this->_set_uri_string($path); |
| 96 | 96 | return; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // No PATH_INFO?... What about QUERY_STRING? |
| 100 | 100 | $path=(isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); |
| 101 | - if (trim($path, '/') != '') { |
|
| 101 | + if (trim($path, '/')!='') { |
|
| 102 | 102 | $this->_set_uri_string($path); |
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // As a last ditch effort lets try using the $_GET array |
| 107 | - if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') { |
|
| 107 | + if (is_array($_GET) && count($_GET)==1 && trim(key($_GET), '/')!='') { |
|
| 108 | 108 | $this->_set_uri_string(key($_GET)); |
| 109 | 109 | return; |
| 110 | 110 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if ($uri == 'REQUEST_URI') { |
|
| 117 | + if ($uri=='REQUEST_URI') { |
|
| 118 | 118 | $this->_set_uri_string($this->_detect_uri()); |
| 119 | 119 | return; |
| 120 | 120 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | // $str = remove_invisible_characters($str, FALSE); |
| 139 | 139 | |
| 140 | 140 | // If the URI contains only a slash we'll kill it |
| 141 | - $this->uri_string=($str == '/') ? '' : $str; |
|
| 141 | + $this->uri_string=($str=='/') ? '' : $str; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // -------------------------------------------------------------------- |
@@ -159,15 +159,15 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | $uri=$_SERVER['REQUEST_URI']; |
| 162 | - if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) { |
|
| 162 | + if (strpos($uri, $_SERVER['SCRIPT_NAME'])===0) { |
|
| 163 | 163 | $uri=substr($uri, strlen($_SERVER['SCRIPT_NAME'])); |
| 164 | - } elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) { |
|
| 164 | + } elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME']))===0) { |
|
| 165 | 165 | $uri=substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct |
| 169 | 169 | // URI is found, and also fixes the QUERY_STRING server var and $_GET array. |
| 170 | - if (strncmp($uri, '?/', 2) === 0) { |
|
| 170 | + if (strncmp($uri, '?/', 2)===0) { |
|
| 171 | 171 | $uri=substr($uri, 2); |
| 172 | 172 | } |
| 173 | 173 | $parts=preg_split('#\?#i', $uri, 2); |
@@ -177,17 +177,17 @@ discard block |
||
| 177 | 177 | parse_str($_SERVER['QUERY_STRING'], $_GET); |
| 178 | 178 | } else { |
| 179 | 179 | $_SERVER['QUERY_STRING']=''; |
| 180 | - $_GET=array (); |
|
| 180 | + $_GET=array(); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if ($uri == '/' || empty($uri)) { |
|
| 183 | + if ($uri=='/' || empty($uri)) { |
|
| 184 | 184 | return '/'; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | $uri=parse_url($uri, PHP_URL_PATH); |
| 188 | 188 | |
| 189 | 189 | // Do some final cleaning of the URI and return it |
| 190 | - return str_replace(array ('//','../' ), '/', trim($uri, '/')); |
|
| 190 | + return str_replace(array('//', '../'), '/', trim($uri, '/')); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | // -------------------------------------------------------------------- |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | private function _parse_cli_args() { |
| 205 | 205 | $args=array_slice($_SERVER['argv'], 1); |
| 206 | 206 | |
| 207 | - return $args ? '/' . implode('/', $args) : ''; |
|
| 207 | + return $args ? '/'.implode('/', $args) : ''; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // -------------------------------------------------------------------- |
@@ -218,17 +218,17 @@ discard block |
||
| 218 | 218 | * |
| 219 | 219 | */ |
| 220 | 220 | function _filter_uri($str) { |
| 221 | - if ($str != '' && $this->permitted_uri_chars != '' && $this->enable_query_strings == FALSE) { |
|
| 221 | + if ($str!='' && $this->permitted_uri_chars!='' && $this->enable_query_strings==FALSE) { |
|
| 222 | 222 | // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards |
| 223 | 223 | // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern |
| 224 | - if (!preg_match("|^[" . str_replace(array ('\\-','\-' ), '-', preg_quote($this->permitted_uri_chars, '-')) . "]+$|i", $str)) { |
|
| 224 | + if (!preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->permitted_uri_chars, '-'))."]+$|i", $str)) { |
|
| 225 | 225 | show_error('The URI you submitted has disallowed characters.', 400); |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | // Convert programatic characters to entities |
| 230 | - $bad=array ('$','(',')','%28','%29' ); |
|
| 231 | - $good=array ('$','(',')','(',')' ); |
|
| 230 | + $bad=array('$', '(', ')', '%28', '%29'); |
|
| 231 | + $good=array('$', '(', ')', '(', ')'); |
|
| 232 | 232 | |
| 233 | 233 | return str_replace($bad, $good, $str); |
| 234 | 234 | } |
@@ -243,11 +243,11 @@ discard block |
||
| 243 | 243 | * |
| 244 | 244 | */ |
| 245 | 245 | function _explode_segments() { |
| 246 | - foreach ( explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val ) { |
|
| 246 | + foreach (explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) { |
|
| 247 | 247 | // Filter segments for security |
| 248 | 248 | $val=trim($this->_filter_uri($val)); |
| 249 | 249 | |
| 250 | - if ($val != '') { |
|
| 250 | + if ($val!='') { |
|
| 251 | 251 | $this->segments[]=$val; |
| 252 | 252 | } |
| 253 | 253 | } |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | * |
| 365 | 365 | */ |
| 366 | 366 | function _uri_to_assoc($n=3, $default=array(), $which='segment') { |
| 367 | - if ($which == 'segment') { |
|
| 367 | + if ($which=='segment') { |
|
| 368 | 368 | $total_segments='total_segments'; |
| 369 | 369 | $segment_array='segment_array'; |
| 370 | 370 | } else { |
@@ -380,25 +380,25 @@ discard block |
||
| 380 | 380 | return $this->keyval[$n]; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - if ($this->$total_segments() < $n) { |
|
| 384 | - if (count($default) == 0) { |
|
| 385 | - return array (); |
|
| 383 | + if ($this->$total_segments()<$n) { |
|
| 384 | + if (count($default)==0) { |
|
| 385 | + return array(); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - $retval=array (); |
|
| 389 | - foreach ( $default as $val ) { |
|
| 388 | + $retval=array(); |
|
| 389 | + foreach ($default as $val) { |
|
| 390 | 390 | $retval[$val]=FALSE; |
| 391 | 391 | } |
| 392 | 392 | return $retval; |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - $segments=array_slice($this->$segment_array(), ($n - 1)); |
|
| 395 | + $segments=array_slice($this->$segment_array(), ($n-1)); |
|
| 396 | 396 | |
| 397 | 397 | $i=0; |
| 398 | 398 | $lastval=''; |
| 399 | - $retval=array (); |
|
| 400 | - foreach ( $segments as $seg ) { |
|
| 401 | - if ($i % 2) { |
|
| 399 | + $retval=array(); |
|
| 400 | + foreach ($segments as $seg) { |
|
| 401 | + if ($i%2) { |
|
| 402 | 402 | $retval[$lastval]=$seg; |
| 403 | 403 | } else { |
| 404 | 404 | $retval[$seg]=FALSE; |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | $i++; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - if (count($default) > 0) { |
|
| 412 | - foreach ( $default as $val ) { |
|
| 411 | + if (count($default)>0) { |
|
| 412 | + foreach ($default as $val) { |
|
| 413 | 413 | if (!array_key_exists($val, $retval)) { |
| 414 | 414 | $retval[$val]=FALSE; |
| 415 | 415 | } |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | * |
| 434 | 434 | */ |
| 435 | 435 | function assoc_to_uri($array) { |
| 436 | - $temp=array (); |
|
| 437 | - foreach ( ( array ) $array as $key => $val ) { |
|
| 436 | + $temp=array(); |
|
| 437 | + foreach ((array)$array as $key => $val) { |
|
| 438 | 438 | $temp[]=$key; |
| 439 | 439 | $temp[]=$val; |
| 440 | 440 | } |
@@ -488,13 +488,13 @@ discard block |
||
| 488 | 488 | $leading='/'; |
| 489 | 489 | $trailing='/'; |
| 490 | 490 | |
| 491 | - if ($where == 'trailing') { |
|
| 491 | + if ($where=='trailing') { |
|
| 492 | 492 | $leading=''; |
| 493 | - } elseif ($where == 'leading') { |
|
| 493 | + } elseif ($where=='leading') { |
|
| 494 | 494 | $trailing=''; |
| 495 | 495 | } |
| 496 | 496 | |
| 497 | - return $leading . $this->$which($n) . $trailing; |
|
| 497 | + return $leading.$this->$which($n).$trailing; |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | // -------------------------------------------------------------------- |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | * |
| 573 | 573 | */ |
| 574 | 574 | function ruri_string() { |
| 575 | - return '/' . implode('/', $this->rsegment_array()); |
|
| 575 | + return '/'.implode('/', $this->rsegment_array()); |
|
| 576 | 576 | } |
| 577 | 577 | } |
| 578 | 578 | // END URI Class |
| 579 | 579 | \ No newline at end of file |
@@ -22,6 +22,11 @@ discard block |
||
| 22 | 22 | protected $_contentSeparator=""; |
| 23 | 23 | |
| 24 | 24 | |
| 25 | + /** |
|
| 26 | + * @param string $identifier |
|
| 27 | + * @param string $tagName |
|
| 28 | + * @param string $baseClass |
|
| 29 | + */ |
|
| 25 | 30 | public function __construct($identifier,$tagName,$baseClass){ |
| 26 | 31 | parent::__construct($identifier,$tagName,$baseClass); |
| 27 | 32 | $this->root=""; |
@@ -31,7 +36,7 @@ discard block |
||
| 31 | 36 | /** |
| 32 | 37 | * Associate an ajax get to the elements, displayed in $targetSelector |
| 33 | 38 | * @param string $targetSelector the target of the get |
| 34 | - * @return HtmlNavElement |
|
| 39 | + * @return HtmlSemNavElement |
|
| 35 | 40 | */ |
| 36 | 41 | public function autoGetOnClick($targetSelector){ |
| 37 | 42 | return $this->getOnClick($this->root, $targetSelector,array("attr"=>$this->attr)); |
@@ -63,7 +68,7 @@ discard block |
||
| 63 | 68 | /** |
| 64 | 69 | * Define the html attribute for each element url in ajax |
| 65 | 70 | * @param string $attr html attribute |
| 66 | - * @return HtmlNavElement |
|
| 71 | + * @return HtmlSemNavElement |
|
| 67 | 72 | */ |
| 68 | 73 | public function setAttr($attr) { |
| 69 | 74 | $this->attr = $attr; |
@@ -103,6 +108,9 @@ discard block |
||
| 103 | 108 | return $this; |
| 104 | 109 | } |
| 105 | 110 | |
| 111 | + /** |
|
| 112 | + * @param integer $index |
|
| 113 | + */ |
|
| 106 | 114 | protected function getContentDivider($index){ |
| 107 | 115 | if(\is_array($this->_contentSeparator)===true){ |
| 108 | 116 | return @$this->_contentSeparator[$index]; |
@@ -22,8 +22,8 @@ discard block |
||
| 22 | 22 | protected $_contentSeparator=""; |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - public function __construct($identifier,$tagName,$baseClass){ |
|
| 26 | - parent::__construct($identifier,$tagName,$baseClass); |
|
| 25 | + public function __construct($identifier, $tagName, $baseClass) { |
|
| 26 | + parent::__construct($identifier, $tagName, $baseClass); |
|
| 27 | 27 | $this->root=""; |
| 28 | 28 | $this->attr="data-ajax"; |
| 29 | 29 | } |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * @param string $targetSelector the target of the get |
| 34 | 34 | * @return HtmlNavElement |
| 35 | 35 | */ |
| 36 | - public function autoGetOnClick($targetSelector){ |
|
| 37 | - return $this->getOnClick($this->root, $targetSelector,array("attr"=>$this->attr)); |
|
| 36 | + public function autoGetOnClick($targetSelector) { |
|
| 37 | + return $this->getOnClick($this->root, $targetSelector, array("attr"=>$this->attr)); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public function contentAsString(){ |
|
| 40 | + public function contentAsString() { |
|
| 41 | 41 | return JArray::implode($this->_contentSeparator, $this->content); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -45,15 +45,15 @@ discard block |
||
| 45 | 45 | * Generate the jquery script to set the elements to the HtmlNavElement |
| 46 | 46 | * @param JsUtils $jsUtils |
| 47 | 47 | */ |
| 48 | - public function jsSetContent(JsUtils $jsUtils){ |
|
| 49 | - $jsUtils->html("#".$this->identifier,str_replace("\"","'", $this->contentAsString()),true); |
|
| 48 | + public function jsSetContent(JsUtils $jsUtils) { |
|
| 49 | + $jsUtils->html("#".$this->identifier, str_replace("\"", "'", $this->contentAsString()), true); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | public function getRoot() { |
| 53 | 53 | return $this->root; |
| 54 | 54 | } |
| 55 | 55 | public function setRoot($root) { |
| 56 | - $this->root = $root; |
|
| 56 | + $this->root=$root; |
|
| 57 | 57 | return $this; |
| 58 | 58 | } |
| 59 | 59 | public function getAttr() { |
@@ -66,12 +66,12 @@ discard block |
||
| 66 | 66 | * @return HtmlNavElement |
| 67 | 67 | */ |
| 68 | 68 | public function setAttr($attr) { |
| 69 | - $this->attr = $attr; |
|
| 69 | + $this->attr=$attr; |
|
| 70 | 70 | return $this; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | public function __call($method, $args) { |
| 74 | - if(isset($this->$method) && is_callable($this->$method)) { |
|
| 74 | + if (isset($this->$method) && is_callable($this->$method)) { |
|
| 75 | 75 | return call_user_func_array( |
| 76 | 76 | $this->$method, |
| 77 | 77 | $args |
@@ -79,32 +79,32 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - public abstract function fromDispatcher(JsUtils $js,$dispatcher, $startIndex=0); |
|
| 82 | + public abstract function fromDispatcher(JsUtils $js, $dispatcher, $startIndex=0); |
|
| 83 | 83 | |
| 84 | 84 | |
| 85 | - public function setContentDivider($divider,$index=NULL) { |
|
| 85 | + public function setContentDivider($divider, $index=NULL) { |
|
| 86 | 86 | $divider="<div class='divider'> {$divider} </div>"; |
| 87 | 87 | return $this->setDivider($divider, $index); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - public function setIconContentDivider($iconContentDivider,$index=NULL) { |
|
| 90 | + public function setIconContentDivider($iconContentDivider, $index=NULL) { |
|
| 91 | 91 | $contentDivider="<i class='".$iconContentDivider." icon divider'></i>"; |
| 92 | 92 | return $this->setDivider($contentDivider, $index); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - protected function setDivider($divider,$index){ |
|
| 96 | - if(isset($index)){ |
|
| 97 | - if(\is_array($this->_contentSeparator)===false) |
|
| 98 | - $this->_contentSeparator=array_fill (0, $this->count()-1,$this->_contentSeparator); |
|
| 95 | + protected function setDivider($divider, $index) { |
|
| 96 | + if (isset($index)) { |
|
| 97 | + if (\is_array($this->_contentSeparator)===false) |
|
| 98 | + $this->_contentSeparator=array_fill(0, $this->count()-1, $this->_contentSeparator); |
|
| 99 | 99 | $this->_contentSeparator[$index]=$divider; |
| 100 | - }else{ |
|
| 100 | + } else { |
|
| 101 | 101 | $this->_contentSeparator=$divider; |
| 102 | 102 | } |
| 103 | 103 | return $this; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - protected function getContentDivider($index){ |
|
| 107 | - if(\is_array($this->_contentSeparator)===true){ |
|
| 106 | + protected function getContentDivider($index) { |
|
| 107 | + if (\is_array($this->_contentSeparator)===true) { |
|
| 108 | 108 | return @$this->_contentSeparator[$index]; |
| 109 | 109 | } |
| 110 | 110 | return $this->_contentSeparator; |
@@ -94,10 +94,11 @@ |
||
| 94 | 94 | |
| 95 | 95 | protected function setDivider($divider,$index){ |
| 96 | 96 | if(isset($index)){ |
| 97 | - if(\is_array($this->_contentSeparator)===false) |
|
| 98 | - $this->_contentSeparator=array_fill (0, $this->count()-1,$this->_contentSeparator); |
|
| 97 | + if(\is_array($this->_contentSeparator)===false) { |
|
| 98 | + $this->_contentSeparator=array_fill (0, $this->count()-1,$this->_contentSeparator); |
|
| 99 | + } |
|
| 99 | 100 | $this->_contentSeparator[$index]=$divider; |
| 100 | - }else{ |
|
| 101 | + } else{ |
|
| 101 | 102 | $this->_contentSeparator=$divider; |
| 102 | 103 | } |
| 103 | 104 | return $this; |
@@ -12,12 +12,24 @@ |
||
| 12 | 12 | protected $_states=[ ]; |
| 13 | 13 | protected $_baseClass; |
| 14 | 14 | |
| 15 | + /** |
|
| 16 | + * @param string $name |
|
| 17 | + */ |
|
| 15 | 18 | protected abstract function setPropertyCtrl($name, $value, $typeCtrl); |
| 16 | 19 | |
| 20 | + /** |
|
| 21 | + * @param string $name |
|
| 22 | + */ |
|
| 17 | 23 | protected abstract function addToPropertyCtrl($name, $value, $typeCtrl); |
| 18 | 24 | |
| 25 | + /** |
|
| 26 | + * @param string $name |
|
| 27 | + */ |
|
| 19 | 28 | protected abstract function addToPropertyCtrlCheck($name, $value, $typeCtrl); |
| 20 | 29 | |
| 30 | + /** |
|
| 31 | + * @param string $name |
|
| 32 | + */ |
|
| 21 | 33 | public abstract function addToProperty($name, $value, $separator=" "); |
| 22 | 34 | |
| 23 | 35 | public function addVariation($variation) { |
@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | use Ajax\semantic\html\elements\HtmlIcon; |
| 9 | 9 | |
| 10 | 10 | trait BaseTrait { |
| 11 | - protected $_variations=[ ]; |
|
| 12 | - protected $_states=[ ]; |
|
| 11 | + protected $_variations=[]; |
|
| 12 | + protected $_states=[]; |
|
| 13 | 13 | protected $_baseClass; |
| 14 | 14 | |
| 15 | 15 | protected abstract function setPropertyCtrl($name, $value, $typeCtrl); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $this->setProperty("class", $this->_baseClass); |
| 38 | 38 | if (\is_string($variations)) |
| 39 | 39 | $variations=\explode(" ", $variations); |
| 40 | - foreach ( $variations as $variation ) { |
|
| 40 | + foreach ($variations as $variation) { |
|
| 41 | 41 | $this->addVariation($variation); |
| 42 | 42 | } |
| 43 | 43 | return $this; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | public function addVariations($variations=array()) { |
| 52 | 52 | if (\is_string($variations)) |
| 53 | 53 | $variations=\explode(" ", $variations); |
| 54 | - foreach ( $variations as $variation ) { |
|
| 54 | + foreach ($variations as $variation) { |
|
| 55 | 55 | $this->addVariation($variation); |
| 56 | 56 | } |
| 57 | 57 | return $this; |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | public function addStates($states=array()) { |
| 61 | 61 | if (\is_string($states)) |
| 62 | 62 | $states=\explode(" ", $states); |
| 63 | - foreach ( $states as $state ) { |
|
| 63 | + foreach ($states as $state) { |
|
| 64 | 64 | $this->addState($state); |
| 65 | 65 | } |
| 66 | 66 | return $this; |
@@ -70,14 +70,14 @@ discard block |
||
| 70 | 70 | $this->setProperty("class", $this->_baseClass); |
| 71 | 71 | if (\is_string($states)) |
| 72 | 72 | $states=\explode(" ", $states); |
| 73 | - foreach ( $states as $state ) { |
|
| 73 | + foreach ($states as $state) { |
|
| 74 | 74 | $this->addState($state); |
| 75 | 75 | } |
| 76 | 76 | return $this; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | public function addIcon($icon, $before=true) { |
| 80 | - return $this->addContent(new HtmlIcon("icon-" . $this->identifier, $icon), $before); |
|
| 80 | + return $this->addContent(new HtmlIcon("icon-".$this->identifier, $icon), $before); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | public function setFloated($direction="right") { |
| 130 | - return $this->addToPropertyCtrl("class", $direction . " floated", Direction::getConstantValues("floated")); |
|
| 130 | + return $this->addToPropertyCtrl("class", $direction." floated", Direction::getConstantValues("floated")); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | public function floatRight() { |
@@ -35,8 +35,9 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function setVariations($variations) { |
| 37 | 37 | $this->setProperty("class", $this->_baseClass); |
| 38 | - if (\is_string($variations)) |
|
| 39 | - $variations=\explode(" ", $variations); |
|
| 38 | + if (\is_string($variations)) { |
|
| 39 | + $variations=\explode(" ", $variations); |
|
| 40 | + } |
|
| 40 | 41 | foreach ( $variations as $variation ) { |
| 41 | 42 | $this->addVariation($variation); |
| 42 | 43 | } |
@@ -49,8 +50,9 @@ discard block |
||
| 49 | 50 | } |
| 50 | 51 | |
| 51 | 52 | public function addVariations($variations=array()) { |
| 52 | - if (\is_string($variations)) |
|
| 53 | - $variations=\explode(" ", $variations); |
|
| 53 | + if (\is_string($variations)) { |
|
| 54 | + $variations=\explode(" ", $variations); |
|
| 55 | + } |
|
| 54 | 56 | foreach ( $variations as $variation ) { |
| 55 | 57 | $this->addVariation($variation); |
| 56 | 58 | } |
@@ -58,8 +60,9 @@ discard block |
||
| 58 | 60 | } |
| 59 | 61 | |
| 60 | 62 | public function addStates($states=array()) { |
| 61 | - if (\is_string($states)) |
|
| 62 | - $states=\explode(" ", $states); |
|
| 63 | + if (\is_string($states)) { |
|
| 64 | + $states=\explode(" ", $states); |
|
| 65 | + } |
|
| 63 | 66 | foreach ( $states as $state ) { |
| 64 | 67 | $this->addState($state); |
| 65 | 68 | } |
@@ -68,8 +71,9 @@ discard block |
||
| 68 | 71 | |
| 69 | 72 | public function setStates($states) { |
| 70 | 73 | $this->setProperty("class", $this->_baseClass); |
| 71 | - if (\is_string($states)) |
|
| 72 | - $states=\explode(" ", $states); |
|
| 74 | + if (\is_string($states)) { |
|
| 75 | + $states=\explode(" ", $states); |
|
| 76 | + } |
|
| 73 | 77 | foreach ( $states as $state ) { |
| 74 | 78 | $this->addState($state); |
| 75 | 79 | } |
@@ -7,6 +7,10 @@ |
||
| 7 | 7 | trait IconTrait { |
| 8 | 8 | private $_hasIcon=false; |
| 9 | 9 | |
| 10 | + /** |
|
| 11 | + * @param string $name |
|
| 12 | + * @param string $value |
|
| 13 | + */ |
|
| 10 | 14 | protected abstract function addToPropertyCtrl($name, $value, $typeCtrl); |
| 11 | 15 | public abstract function addContent($content,$before=false); |
| 12 | 16 | |
@@ -8,18 +8,18 @@ discard block |
||
| 8 | 8 | private $_hasIcon=false; |
| 9 | 9 | |
| 10 | 10 | protected abstract function addToPropertyCtrl($name, $value, $typeCtrl); |
| 11 | - public abstract function addContent($content,$before=false); |
|
| 11 | + public abstract function addContent($content, $before=false); |
|
| 12 | 12 | |
| 13 | - public function addIcon($icon,$direction=Direction::LEFT){ |
|
| 14 | - if($this->_hasIcon===false){ |
|
| 13 | + public function addIcon($icon, $direction=Direction::LEFT) { |
|
| 14 | + if ($this->_hasIcon===false) { |
|
| 15 | 15 | $iconO=$icon; |
| 16 | - if(\is_string($icon)){ |
|
| 16 | + if (\is_string($icon)) { |
|
| 17 | 17 | $iconO=new HtmlIcon("icon-".$this->identifier, $icon); |
| 18 | 18 | } |
| 19 | 19 | $this->addToPropertyCtrl("class", $direction." icon", Direction::getConstantValues("icon")); |
| 20 | - $this->addContent($iconO,false); |
|
| 20 | + $this->addContent($iconO, false); |
|
| 21 | 21 | $this->_hasIcon=true; |
| 22 | - }else{ |
|
| 22 | + } else { |
|
| 23 | 23 | $iconO=$this->getIcon(); |
| 24 | 24 | $iconO->setIcon($icon); |
| 25 | 25 | $this->addToPropertyCtrl("class", $direction." icon", Direction::getConstantValues("icon")); |
@@ -27,10 +27,10 @@ discard block |
||
| 27 | 27 | return $iconO; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - public function getIcon(){ |
|
| 31 | - if(\is_array($this->content)){ |
|
| 32 | - foreach ($this->content as $item){ |
|
| 33 | - if($item instanceof HtmlIcon) |
|
| 30 | + public function getIcon() { |
|
| 31 | + if (\is_array($this->content)) { |
|
| 32 | + foreach ($this->content as $item) { |
|
| 33 | + if ($item instanceof HtmlIcon) |
|
| 34 | 34 | return $item; |
| 35 | 35 | } |
| 36 | 36 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | $this->addToPropertyCtrl("class", $direction." icon", Direction::getConstantValues("icon")); |
| 20 | 20 | $this->addContent($iconO,false); |
| 21 | 21 | $this->_hasIcon=true; |
| 22 | - }else{ |
|
| 22 | + } else{ |
|
| 23 | 23 | $iconO=$this->getIcon(); |
| 24 | 24 | $iconO->setIcon($icon); |
| 25 | 25 | $this->addToPropertyCtrl("class", $direction." icon", Direction::getConstantValues("icon")); |
@@ -30,8 +30,9 @@ discard block |
||
| 30 | 30 | public function getIcon(){ |
| 31 | 31 | if(\is_array($this->content)){ |
| 32 | 32 | foreach ($this->content as $item){ |
| 33 | - if($item instanceof HtmlIcon) |
|
| 34 | - return $item; |
|
| 33 | + if($item instanceof HtmlIcon) { |
|
| 34 | + return $item; |
|
| 35 | + } |
|
| 35 | 36 | } |
| 36 | 37 | } |
| 37 | 38 | } |