@@ -2,9 +2,9 @@ discard block |
||
2 | 2 | namespace Ajax\common\traits; |
3 | 3 | use Ajax\common\BaseGui; |
4 | 4 | |
5 | -trait JsUtilsInternalTrait{ |
|
5 | +trait JsUtilsInternalTrait { |
|
6 | 6 | |
7 | - protected $jquery_code_for_compile=array (); |
|
7 | + protected $jquery_code_for_compile=array(); |
|
8 | 8 | |
9 | 9 | protected function _addToCompile($jsScript) { |
10 | 10 | $this->jquery_code_for_compile[]=$jsScript; |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | * @param BaseGui $library |
15 | 15 | * @param mixed $view |
16 | 16 | */ |
17 | - protected function _compileLibrary($library, &$view=NULL){ |
|
17 | + protected function _compileLibrary($library, &$view=NULL) { |
|
18 | 18 | if ($library!=NULL) { |
19 | - if(isset($view)) |
|
19 | + if (isset($view)) |
|
20 | 20 | $library->compileHtml($this, $view); |
21 | 21 | if ($library->isAutoCompile()) { |
22 | 22 | $library->compile(true); |
@@ -24,20 +24,20 @@ discard block |
||
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
27 | - protected function defer($script){ |
|
27 | + protected function defer($script) { |
|
28 | 28 | $result="window.defer=function (method) {if (window.jQuery) method(); else setTimeout(function() { defer(method) }, 50);};"; |
29 | 29 | $result.="window.defer(function(){".$script."})"; |
30 | 30 | return $result; |
31 | 31 | } |
32 | 32 | |
33 | - protected function ready($script){ |
|
33 | + protected function ready($script) { |
|
34 | 34 | $result='$(document).ready(function() {'."\n"; |
35 | 35 | $result.=$script.'})'; |
36 | 36 | return $result; |
37 | 37 | } |
38 | 38 | |
39 | 39 | protected function minify($input) { |
40 | - if(trim($input) === "") return $input; |
|
40 | + if (trim($input)==="") return $input; |
|
41 | 41 | return preg_replace( |
42 | 42 | array( |
43 | 43 | // Remove comment(s) |
@@ -11,11 +11,11 @@ discard block |
||
11 | 11 | trait JsUtilsEventsTrait { |
12 | 12 | |
13 | 13 | |
14 | - protected $jquery_events=array ( |
|
15 | - "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" |
|
14 | + protected $jquery_events=array( |
|
15 | + "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" |
|
16 | 16 | ); |
17 | 17 | |
18 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
18 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Outputs a javascript library blur event |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function click($element='this', $js='', $ret_false=TRUE) { |
51 | 51 | if (!is_array($js)) { |
52 | - $js=array ( |
|
52 | + $js=array( |
|
53 | 53 | $js |
54 | 54 | ); |
55 | 55 | } |
@@ -16,19 +16,19 @@ discard block |
||
16 | 16 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
17 | 17 | |
18 | 18 | abstract public function getUrl($url); |
19 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
19 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
20 | 20 | |
21 | - protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
22 | - if(JString::isNull($params)){$params="{}";} |
|
21 | + protected function _ajax($method, $url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
22 | + if (JString::isNull($params)) {$params="{}"; } |
|
23 | 23 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
24 | 24 | $retour=$this->_getAjaxUrl($url, $attr); |
25 | 25 | $responseElement=$this->_getResponseElement($responseElement); |
26 | 26 | $retour.="var self=this;\n"; |
27 | - if($hasLoader===true){ |
|
27 | + if ($hasLoader===true) { |
|
28 | 28 | $this->addLoading($retour, $responseElement); |
29 | 29 | } |
30 | 30 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
31 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
31 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
32 | 32 | if ($immediatly) |
33 | 33 | $this->jquery_code_for_compile[]=$retour; |
34 | 34 | return $retour; |
@@ -36,33 +36,33 @@ discard block |
||
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | - protected function _getAjaxUrl($url,$attr){ |
|
39 | + protected function _getAjaxUrl($url, $attr) { |
|
40 | 40 | $url=$this->_correctAjaxUrl($url); |
41 | 41 | $retour="url='".$url."';"; |
42 | 42 | $slash="/"; |
43 | - if(JString::endswith($url, "/")===true) |
|
43 | + if (JString::endswith($url, "/")===true) |
|
44 | 44 | $slash=""; |
45 | - if(JString::isNotNull($attr)){ |
|
45 | + if (JString::isNotNull($attr)) { |
|
46 | 46 | if ($attr==="value") |
47 | 47 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
48 | 48 | elseif ($attr==="html") |
49 | 49 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
50 | - elseif($attr!==null && $attr!=="") |
|
50 | + elseif ($attr!==null && $attr!=="") |
|
51 | 51 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
52 | 52 | } |
53 | 53 | return $retour; |
54 | 54 | } |
55 | 55 | |
56 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback){ |
|
57 | - $retour="";$call=null; |
|
56 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) { |
|
57 | + $retour=""; $call=null; |
|
58 | 58 | if ($responseElement!=="") { |
59 | - if(isset($ajaxTransition)){ |
|
59 | + if (isset($ajaxTransition)) { |
|
60 | 60 | $call=$this->setAjaxDataCall($ajaxTransition); |
61 | - }elseif(isset($this->ajaxTransition)){ |
|
61 | + }elseif (isset($this->ajaxTransition)) { |
|
62 | 62 | $call=$this->ajaxTransition; |
63 | 63 | } |
64 | - if(\is_callable($call)) |
|
65 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
64 | + if (\is_callable($call)) |
|
65 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
66 | 66 | else |
67 | 67 | $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
68 | 68 | } |
@@ -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=Javascript::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->getUrl($url); |
85 | 85 | } |
86 | 86 | return $url; |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | $retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n"; |
99 | 99 | } |
100 | 100 | |
101 | - protected function setAjaxDataCall($params){ |
|
101 | + protected function setAjaxDataCall($params) { |
|
102 | 102 | $result=null; |
103 | - if(!\is_callable($params)){ |
|
104 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
105 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
103 | + if (!\is_callable($params)) { |
|
104 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
105 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
106 | 106 | }; |
107 | 107 | } |
108 | 108 | return $result; |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
123 | 123 | * @param string|callable $ajaxTransition |
124 | 124 | */ |
125 | - private function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
126 | - return $this->_ajax("get", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
125 | + private function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
126 | + return $this->_ajax("get", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
137 | 137 | * @param string|callable $ajaxTransition |
138 | 138 | */ |
139 | - public function get($url, $responseElement="", $params="{}", $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
140 | - return $this->_get($url,$params,$responseElement,$jsCallback,null,$hasLoader,$jqueryDone,$ajaxTransition,true); |
|
139 | + public function get($url, $responseElement="", $params="{}", $jsCallback=NULL, $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
140 | + return $this->_get($url, $params, $responseElement, $jsCallback, null, $hasLoader, $jqueryDone, $ajaxTransition, true); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @param string $context |
151 | 151 | * @param boolean $immediatly |
152 | 152 | */ |
153 | - private function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
153 | + private function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
154 | 154 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
155 | 155 | $retour=$this->_getAjaxUrl($url, $attr); |
156 | 156 | $retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * @param string $context |
174 | 174 | * @param boolean $immediatly |
175 | 175 | */ |
176 | - public function json($url, $method="get", $params="{}", $jsCallback=NULL,$context="document",$immediatly=false) { |
|
177 | - return $this->_json($url,$method,$params,$jsCallback,NULL,$context,$immediatly); |
|
176 | + public function json($url, $method="get", $params="{}", $jsCallback=NULL, $context="document", $immediatly=false) { |
|
177 | + return $this->_json($url, $method, $params, $jsCallback, NULL, $context, $immediatly); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * @param string $url the request address |
185 | 185 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
186 | 186 | */ |
187 | - public function jsonOn($event,$element, $url,$parameters=array()) { |
|
187 | + public function jsonOn($event, $element, $url, $parameters=array()) { |
|
188 | 188 | $preventDefault=true; |
189 | 189 | $stopPropagation=true; |
190 | 190 | $jsCallback=null; |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | $params="{}"; |
195 | 195 | $immediatly=true; |
196 | 196 | extract($parameters); |
197 | - return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
197 | + return $this->_add_event($element, $this->_json($url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | * @param string $jsCallback javascript code to execute after the request |
206 | 206 | * @param string $context jquery DOM element, array container. |
207 | 207 | */ |
208 | - public function jsonDeferred($url, $method="get", $params="{}", $jsCallback=NULL,$context=NULL) { |
|
209 | - return $this->json($url, $method, $params, $jsCallback, $context,false); |
|
208 | + public function jsonDeferred($url, $method="get", $params="{}", $jsCallback=NULL, $context=NULL) { |
|
209 | + return $this->json($url, $method, $params, $jsCallback, $context, false); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -219,22 +219,22 @@ discard block |
||
219 | 219 | * @param string $rowClass the css class for the new element |
220 | 220 | * @param boolean $immediatly |
221 | 221 | */ |
222 | - private function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL,$attr="id",$immediatly=false) { |
|
222 | + private function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL, $attr="id", $immediatly=false) { |
|
223 | 223 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
224 | 224 | $retour=$this->_getAjaxUrl($url, $attr); |
225 | - if($context===null){ |
|
225 | + if ($context===null) { |
|
226 | 226 | $parent="$('".$maskSelector."').parent()"; |
227 | - $newElm = "$('#'+newId)"; |
|
228 | - }else{ |
|
227 | + $newElm="$('#'+newId)"; |
|
228 | + } else { |
|
229 | 229 | $parent=$context; |
230 | - $newElm = $context.".find('#'+newId)"; |
|
230 | + $newElm=$context.".find('#'+newId)"; |
|
231 | 231 | } |
232 | 232 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
233 | 233 | $retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
234 | 234 | $retour.=$parent.".find('._json').remove();"; |
235 | 235 | $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(); |
236 | 236 | newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ var newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n"; |
237 | - $retour.= $appendTo; |
|
237 | + $retour.=$appendTo; |
|
238 | 238 | $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"; |
239 | 239 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
240 | 240 | $retour.="\t".$jsCallback."\n"."});\n"; |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | * @param string $context jquery DOM element, array container. |
254 | 254 | * @param boolean $immediatly |
255 | 255 | */ |
256 | - public function jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL,$immediatly=false) { |
|
257 | - return $this->_jsonArray($maskSelector, $url,$method,$params,$jsCallback,$rowClass,$context,NULL,$immediatly); |
|
256 | + public function jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL, $immediatly=false) { |
|
257 | + return $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, NULL, $immediatly); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | * @param string $rowClass the css class for the new element |
268 | 268 | * @param string $context jquery DOM element, array container. |
269 | 269 | */ |
270 | - public function jsonArrayDeferred($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL) { |
|
271 | - return $this->jsonArray($maskSelector, $url, $method, $params, $jsCallback,$rowClass,$context,false); |
|
270 | + public function jsonArrayDeferred($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL) { |
|
271 | + return $this->jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, false); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -278,18 +278,18 @@ discard block |
||
278 | 278 | * @param string $url the request url |
279 | 279 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
280 | 280 | */ |
281 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$parameters=array()) { |
|
281 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
282 | 282 | $preventDefault=true; |
283 | 283 | $stopPropagation=true; |
284 | 284 | $jsCallback=null; |
285 | 285 | $attr="id"; |
286 | 286 | $method="get"; |
287 | - $context = null; |
|
287 | + $context=null; |
|
288 | 288 | $params="{}"; |
289 | 289 | $immediatly=true; |
290 | 290 | $rowClass="_json"; |
291 | 291 | extract($parameters); |
292 | - return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $rowClass, $context,$attr), $event, $preventDefault, $stopPropagation,$immediatly); |
|
292 | + return $this->_add_event($element, $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, $attr), $event, $preventDefault, $stopPropagation, $immediatly); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
304 | 304 | * @param string|callable $ajaxTransition |
305 | 305 | */ |
306 | - public function getDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL,$attr="id",$jqueryDone="html",$ajaxTransition=null) { |
|
307 | - return $this->_get($url, $params,$responseElement,$jsCallback,$attr,false,$jqueryDone,$ajaxTransition); |
|
306 | + public function getDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL, $attr="id", $jqueryDone="html", $ajaxTransition=null) { |
|
307 | + return $this->_get($url, $params, $responseElement, $jsCallback, $attr, false, $jqueryDone, $ajaxTransition); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | $ajaxTransition=null; |
328 | 328 | $params="{}"; |
329 | 329 | extract($parameters); |
330 | - return $this->_add_event($element, $this->_get($url, $params,$responseElement,$jsCallback,$attr, $hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
330 | + return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
@@ -342,8 +342,8 @@ discard block |
||
342 | 342 | return $this->getOn("click", $element, $url, $responseElement, $parameters); |
343 | 343 | } |
344 | 344 | |
345 | - private function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
346 | - return $this->_ajax("post", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
345 | + private function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
346 | + return $this->_ajax("post", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
357 | 357 | * @param string|callable $ajaxTransition |
358 | 358 | */ |
359 | - public function post($url, $responseElement="", $params="{}", $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
360 | - return $this->_post($url, $params, $responseElement, $jsCallback, NULL, $hasLoader,$jqueryDone,$ajaxTransition,true); |
|
359 | + public function post($url, $responseElement="", $params="{}", $jsCallback=NULL, $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
360 | + return $this->_post($url, $params, $responseElement, $jsCallback, NULL, $hasLoader, $jqueryDone, $ajaxTransition, true); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
373 | 373 | * @param string|callable $ajaxTransition |
374 | 374 | */ |
375 | - public function postDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL, $attr="id",$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
376 | - return $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader,$jqueryDone,$ajaxTransition,false); |
|
375 | + public function postDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
376 | + return $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, false); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | $jqueryDone="html"; |
397 | 397 | $ajaxTransition=null; |
398 | 398 | extract($parameters); |
399 | - return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
399 | + return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
@@ -412,17 +412,17 @@ discard block |
||
412 | 412 | return $this->postOn("click", $element, $url, $params, $responseElement, $parameters); |
413 | 413 | } |
414 | 414 | |
415 | - private function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
415 | + private function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
416 | 416 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
417 | 417 | $retour=$this->_getAjaxUrl($url, $attr); |
418 | 418 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
419 | 419 | $responseElement=$this->_getResponseElement($responseElement); |
420 | 420 | $retour.="var self=this;\n"; |
421 | - if($hasLoader===true){ |
|
421 | + if ($hasLoader===true) { |
|
422 | 422 | $this->addLoading($retour, $responseElement); |
423 | 423 | } |
424 | 424 | $retour.="$.post(url,params).done(function( data ) {\n"; |
425 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
425 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
426 | 426 | |
427 | 427 | if ($validation) { |
428 | 428 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
446 | 446 | * @param string|callable $ajaxTransition |
447 | 447 | */ |
448 | - public function postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
449 | - return $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, NULL, $hasLoader,$jqueryDone,$ajaxTransition,true); |
|
448 | + public function postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
449 | + return $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, NULL, $hasLoader, $jqueryDone, $ajaxTransition, true); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | /** |
@@ -461,8 +461,8 @@ discard block |
||
461 | 461 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
462 | 462 | * @param string|callable $ajaxTransition |
463 | 463 | */ |
464 | - public function postFormDeferred($url, $form, $responseElement, $validation=false, $jsCallback=NULL,$attr="id",$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
465 | - return $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader,$jqueryDone,$ajaxTransition,false); |
|
464 | + public function postFormDeferred($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
465 | + return $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, false); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | $jqueryDone="html"; |
487 | 487 | $ajaxTransition=null; |
488 | 488 | extract($parameters); |
489 | - return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
489 | + return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | /** |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | trait JsUtilsActionsTrait { |
12 | 12 | |
13 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
13 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
14 | 14 | /** |
15 | 15 | * show or hide with effect |
16 | 16 | * |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param boolean $immediatly defers the execution if set to false |
22 | 22 | * @return string |
23 | 23 | */ |
24 | - protected function _showHideWithEffect($action,$element='this', $speed='', $callback='', $immediatly=false) { |
|
24 | + protected function _showHideWithEffect($action, $element='this', $speed='', $callback='', $immediatly=false) { |
|
25 | 25 | $element=Javascript::prep_element($element); |
26 | 26 | $speed=$this->_validate_speed($speed); |
27 | 27 | if ($callback!='') { |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * @return string |
39 | 39 | */ |
40 | 40 | private function _validate_speed($speed) { |
41 | - if (in_array($speed, array ( |
|
42 | - 'slow','normal','fast' |
|
41 | + if (in_array($speed, array( |
|
42 | + 'slow', 'normal', 'fast' |
|
43 | 43 | ))) { |
44 | 44 | $speed='"'.$speed.'"'; |
45 | 45 | } elseif (preg_match("/[^0-9]/", $speed)) { |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @param string $param |
57 | 57 | * @param boolean $immediatly delayed if false |
58 | 58 | */ |
59 | - public function _genericCallValue($jQueryCall,$element='this', $param="", $immediatly=false) { |
|
59 | + public function _genericCallValue($jQueryCall, $element='this', $param="", $immediatly=false) { |
|
60 | 60 | $element=Javascript::prep_element($element); |
61 | 61 | if (isset($param)) { |
62 | 62 | $param=Javascript::prep_value($param); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param boolean $immediatly delayed if false |
77 | 77 | * @return string |
78 | 78 | */ |
79 | - public function _genericCallElement($jQueryCall,$to='this', $element, $immediatly=false) { |
|
79 | + public function _genericCallElement($jQueryCall, $to='this', $element, $immediatly=false) { |
|
80 | 80 | $to=Javascript::prep_element($to); |
81 | 81 | $element=Javascript::prep_element($element); |
82 | 82 | $str="$({$to}).{$jQueryCall}({$element});"; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @return string |
94 | 94 | */ |
95 | 95 | public function addClass($element='this', $class='', $immediatly=false) { |
96 | - return $this->_genericCallValue('addClass',$element, $class, $immediatly); |
|
96 | + return $this->_genericCallValue('addClass', $element, $class, $immediatly); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * @param boolean $immediatly defers the execution if set to false |
104 | 104 | * @return string |
105 | 105 | */ |
106 | - public function after($to, $element, $immediatly=false){ |
|
107 | - return $this->_genericCallElement('after',$to, $element, $immediatly); |
|
106 | + public function after($to, $element, $immediatly=false) { |
|
107 | + return $this->_genericCallElement('after', $to, $element, $immediatly); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * @param boolean $immediatly defers the execution if set to false |
115 | 115 | * @return string |
116 | 116 | */ |
117 | - public function before($to, $element, $immediatly=false){ |
|
118 | - return $this->_genericCallElement('before',$to, $element, $immediatly); |
|
117 | + public function before($to, $element, $immediatly=false) { |
|
118 | + return $this->_genericCallElement('before', $to, $element, $immediatly); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | * @param string $value |
144 | 144 | * @param boolean $immediatly defers the execution if set to false |
145 | 145 | */ |
146 | - public function val($element='this',$value='',$immediatly=false){ |
|
147 | - return $this->_genericCallValue('val',$element,$value,$immediatly); |
|
146 | + public function val($element='this', $value='', $immediatly=false) { |
|
147 | + return $this->_genericCallValue('val', $element, $value, $immediatly); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @param boolean $immediatly defers the execution if set to false |
155 | 155 | */ |
156 | 156 | public function html($element='this', $value='', $immediatly=false) { |
157 | - return $this->_genericCallValue('html',$element, $value, $immediatly); |
|
157 | + return $this->_genericCallValue('html', $element, $value, $immediatly); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | |
174 | 174 | $animations="\t\t\t"; |
175 | 175 | if (\is_array($params)) { |
176 | - foreach ( $params as $param => $value ) { |
|
176 | + foreach ($params as $param => $value) { |
|
177 | 177 | $animations.=$param.': \''.$value.'\', '; |
178 | 178 | } |
179 | 179 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @return string |
203 | 203 | */ |
204 | 204 | public function append($to, $element, $immediatly=false) { |
205 | - return $this->_genericCallElement('append',$to, $element, $immediatly); |
|
205 | + return $this->_genericCallElement('append', $to, $element, $immediatly); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @return string |
214 | 214 | */ |
215 | 215 | public function prepend($to, $element, $immediatly=false) { |
216 | - return $this->_genericCallElement('prepend',$to, $element, $immediatly); |
|
216 | + return $this->_genericCallElement('prepend', $to, $element, $immediatly); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @return string |
227 | 227 | */ |
228 | 228 | public function fadeIn($element='this', $speed='', $callback='', $immediatly=false) { |
229 | - return $this->_showHideWithEffect("fadeIn",$element,$speed,$callback,$immediatly); |
|
229 | + return $this->_showHideWithEffect("fadeIn", $element, $speed, $callback, $immediatly); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @return string |
240 | 240 | */ |
241 | 241 | public function fadeOut($element='this', $speed='', $callback='', $immediatly=false) { |
242 | - return $this->_showHideWithEffect("fadeOut",$element,$speed,$callback,$immediatly); |
|
242 | + return $this->_showHideWithEffect("fadeOut", $element, $speed, $callback, $immediatly); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @return string |
253 | 253 | */ |
254 | 254 | public function slideUp($element='this', $speed='', $callback='', $immediatly=false) { |
255 | - return $this->_showHideWithEffect("slideUp",$element,$speed,$callback,$immediatly); |
|
255 | + return $this->_showHideWithEffect("slideUp", $element, $speed, $callback, $immediatly); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | * @return string |
265 | 265 | */ |
266 | 266 | public function removeClass($element='this', $class='', $immediatly=false) { |
267 | - return $this->_genericCall('removeClass',$element, $class, $immediatly); |
|
267 | + return $this->_genericCall('removeClass', $element, $class, $immediatly); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @return string |
278 | 278 | */ |
279 | 279 | public function slideDown($element='this', $speed='', $callback='', $immediatly=false) { |
280 | - return $this->_showHideWithEffect("slideDown",$element,$speed,$callback,$immediatly); |
|
280 | + return $this->_showHideWithEffect("slideDown", $element, $speed, $callback, $immediatly); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @return string |
291 | 291 | */ |
292 | 292 | public function slideToggle($element='this', $speed='', $callback='', $immediatly=false) { |
293 | - return $this->_showHideWithEffect("slideToggle",$element,$speed,$callback,$immediatly); |
|
293 | + return $this->_showHideWithEffect("slideToggle", $element, $speed, $callback, $immediatly); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | * @return string |
304 | 304 | */ |
305 | 305 | public function hide($element='this', $speed='', $callback='', $immediatly=false) { |
306 | - return $this->_showHideWithEffect("hide",$element,$speed,$callback,$immediatly); |
|
306 | + return $this->_showHideWithEffect("hide", $element, $speed, $callback, $immediatly); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @return string |
317 | 317 | */ |
318 | 318 | public function toggle($element='this', $speed='', $callback='', $immediatly=false) { |
319 | - return $this->_showHideWithEffect("toggle",$element,$speed,$callback,$immediatly); |
|
319 | + return $this->_showHideWithEffect("toggle", $element, $speed, $callback, $immediatly); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | * @return string |
328 | 328 | */ |
329 | 329 | public function toggleClass($element='this', $class='', $immediatly=false) { |
330 | - return $this->_genericCallValue('toggleClass',$element, $class, $immediatly); |
|
330 | + return $this->_genericCallValue('toggleClass', $element, $class, $immediatly); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * @return string |
356 | 356 | */ |
357 | 357 | public function show($element='this', $speed='', $callback='', $immediatly=false) { |
358 | - return $this->_showHideWithEffect("show",$element,$speed,$callback,$immediatly); |
|
358 | + return $this->_showHideWithEffect("show", $element, $speed, $callback, $immediatly); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -367,8 +367,8 @@ discard block |
||
367 | 367 | */ |
368 | 368 | public function sortable($element, $options=array()) { |
369 | 369 | if (count($options)>0) { |
370 | - $sort_options=array (); |
|
371 | - foreach ( $options as $k => $v ) { |
|
370 | + $sort_options=array(); |
|
371 | + foreach ($options as $k => $v) { |
|
372 | 372 | $sort_options[]="\n\t\t".$k.': '.$v.""; |
373 | 373 | } |
374 | 374 | $sort_options=implode(",", $sort_options); |
@@ -465,8 +465,8 @@ discard block |
||
465 | 465 | * @param boolean $immediatly |
466 | 466 | * @return string |
467 | 467 | */ |
468 | - private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="",$immediatly=true) { |
|
469 | - return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation,$immediatly); |
|
468 | + private function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="", $immediatly=true) { |
|
469 | + return $this->_add_event($element, $this->_doJQuery($elementToModify, $jqueryCall, $param, $jsCallback), $event, $preventDefault, $stopPropagation, $immediatly); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | /** |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | $preventDefault=false; |
485 | 485 | $immediatly=true; |
486 | 486 | extract($parameters); |
487 | - return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback,$immediatly); |
|
487 | + return $this->_doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param, $preventDefault, $stopPropagation, $jsCallback, $immediatly); |
|
488 | 488 | } |
489 | 489 | |
490 | 490 | /** |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | $preventDefault=false; |
514 | 514 | $immediatly=true; |
515 | 515 | extract($parameters); |
516 | - $script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation,$immediatly); |
|
516 | + $script=$this->_add_event($element, $this->exec($js), $event, $preventDefault, $stopPropagation, $immediatly); |
|
517 | 517 | return $script; |
518 | 518 | } |
519 | 519 | } |