@@ -2,10 +2,10 @@ 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 (); |
|
8 | - protected $jquery_code_for_compile_at_last=array (); |
|
7 | + protected $jquery_code_for_compile=array(); |
|
8 | + protected $jquery_code_for_compile_at_last=array(); |
|
9 | 9 | |
10 | 10 | protected function _addToCompile($jsScript) { |
11 | 11 | $this->jquery_code_for_compile[]=$jsScript; |
@@ -15,29 +15,29 @@ discard block |
||
15 | 15 | * @param BaseGui $library |
16 | 16 | * @param mixed $view |
17 | 17 | */ |
18 | - protected function _compileLibrary(BaseGui $library, &$view=NULL){ |
|
19 | - if(isset($view)) |
|
18 | + protected function _compileLibrary(BaseGui $library, &$view=NULL) { |
|
19 | + if (isset($view)) |
|
20 | 20 | $library->compileHtml($this, $view); |
21 | 21 | if ($library->isAutoCompile()) { |
22 | 22 | $library->compile(true); |
23 | 23 | } |
24 | 24 | } |
25 | 25 | |
26 | - protected function defer($script){ |
|
26 | + protected function defer($script) { |
|
27 | 27 | $result="window.defer=function (method) {if (window.jQuery) method(); else setTimeout(function() { defer(method) }, 50);};"; |
28 | 28 | $result.="window.defer(function(){".$script."})"; |
29 | 29 | return $result; |
30 | 30 | } |
31 | 31 | |
32 | - protected function ready($script){ |
|
32 | + protected function ready($script) { |
|
33 | 33 | $result='$(document).ready(function() {'."\n"; |
34 | 34 | $result.=$script.'})'; |
35 | 35 | return $result; |
36 | 36 | } |
37 | 37 | |
38 | 38 | protected function minify($input) { |
39 | - if(trim($input) === "") return $input; |
|
40 | - $input= preg_replace( |
|
39 | + if (trim($input)==="") return $input; |
|
40 | + $input=preg_replace( |
|
41 | 41 | array( |
42 | 42 | // Remove comment(s) |
43 | 43 | '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | * @property string identifier |
12 | 12 | * @property BaseHtml _self |
13 | 13 | */ |
14 | -trait BaseHtmlEventsTrait{ |
|
14 | +trait BaseHtmlEventsTrait { |
|
15 | 15 | |
16 | - protected $_events=array (); |
|
16 | + protected $_events=array(); |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @param string $event |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | * @return BaseHtml |
24 | 24 | */ |
25 | 25 | public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false) { |
26 | - if ($stopPropagation === true) { |
|
27 | - $jsCode=Javascript::$stopPropagation . $jsCode; |
|
26 | + if ($stopPropagation===true) { |
|
27 | + $jsCode=Javascript::$stopPropagation.$jsCode; |
|
28 | 28 | } |
29 | - if ($preventDefault === true) { |
|
30 | - $jsCode=Javascript::$preventDefault . $jsCode; |
|
29 | + if ($preventDefault===true) { |
|
30 | + $jsCode=Javascript::$preventDefault.$jsCode; |
|
31 | 31 | } |
32 | 32 | return $this->_addEvent($event, $jsCode); |
33 | 33 | } |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | public function _addEvent($event, $jsCode) { |
41 | 41 | if (array_key_exists($event, $this->_events)) { |
42 | 42 | if (\is_array($this->_events[$event])) { |
43 | - if(array_search($jsCode, $this->_events[$event])===false){ |
|
43 | + if (array_search($jsCode, $this->_events[$event])===false) { |
|
44 | 44 | $this->_events[$event][]=$jsCode; |
45 | 45 | } |
46 | 46 | } else { |
47 | - $this->_events[$event]=array ($this->_events[$event],$jsCode ); |
|
47 | + $this->_events[$event]=array($this->_events[$event], $jsCode); |
|
48 | 48 | } |
49 | 49 | } else { |
50 | 50 | $this->_events[$event]=$jsCode; |
@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | return $this->onClick($jsCode); |
72 | 72 | } |
73 | 73 | |
74 | - public function onCreate($jsCode){ |
|
75 | - if(isset($this->_events["_create"])){ |
|
74 | + public function onCreate($jsCode) { |
|
75 | + if (isset($this->_events["_create"])) { |
|
76 | 76 | $this->_events["_create"][]=$jsCode; |
77 | - }else{ |
|
77 | + } else { |
|
78 | 78 | $this->_events["_create"]=[$jsCode]; |
79 | 79 | } |
80 | 80 | return $this; |
@@ -83,15 +83,15 @@ discard block |
||
83 | 83 | public function addEventsOnRun(JsUtils $js=NULL) { |
84 | 84 | $this->_eventsOnCreate($js); |
85 | 85 | if (isset($this->_bsComponent)) { |
86 | - foreach ( $this->_events as $event => $jsCode ) { |
|
86 | + foreach ($this->_events as $event => $jsCode) { |
|
87 | 87 | $code=$jsCode; |
88 | 88 | if (\is_array($jsCode)) { |
89 | 89 | $code=""; |
90 | - foreach ( $jsCode as $jsC ) { |
|
90 | + foreach ($jsCode as $jsC) { |
|
91 | 91 | if ($jsC instanceof AjaxCall) { |
92 | - $code.="\n" . $jsC->compile($js); |
|
92 | + $code.="\n".$jsC->compile($js); |
|
93 | 93 | } else { |
94 | - $code.="\n" . $jsC; |
|
94 | + $code.="\n".$jsC; |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | } elseif ($jsCode instanceof AjaxCall) { |
@@ -99,18 +99,18 @@ discard block |
||
99 | 99 | } |
100 | 100 | $this->_bsComponent->addEvent($event, $code); |
101 | 101 | } |
102 | - $this->_events=array (); |
|
102 | + $this->_events=array(); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | - protected function _eventsOnCreate(JsUtils $js=NULL){ |
|
107 | - if(isset($this->_events["_create"])){ |
|
106 | + protected function _eventsOnCreate(JsUtils $js=NULL) { |
|
107 | + if (isset($this->_events["_create"])) { |
|
108 | 108 | $create=$this->_events["_create"]; |
109 | - if(\is_array($create)){ |
|
109 | + if (\is_array($create)) { |
|
110 | 110 | $create=\implode("", $create); |
111 | 111 | } |
112 | - if(isset($js) && $create!=="") |
|
113 | - $js->exec($create,true); |
|
112 | + if (isset($js) && $create!=="") |
|
113 | + $js->exec($create, true); |
|
114 | 114 | unset($this->_events["_create"]); |
115 | 115 | } |
116 | 116 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * @return $this |
125 | 125 | */ |
126 | 126 | public function _ajaxOn($operation, $event, $url, $responseElement="", $parameters=array()) { |
127 | - $params=array ("url" => $url,"responseElement" => $responseElement ); |
|
127 | + $params=array("url" => $url, "responseElement" => $responseElement); |
|
128 | 128 | $params=array_merge($params, $parameters); |
129 | 129 | $this->_addEvent($event, new AjaxCall($operation, $params)); |
130 | 130 | return $this; |
@@ -167,10 +167,10 @@ discard block |
||
167 | 167 | **/ |
168 | 168 | public function postOn($event, $url, $params="{}", $responseElement="", $parameters=array()) { |
169 | 169 | $allParameters=[]; |
170 | - if(isset($parameters["params"])){ |
|
170 | + if (isset($parameters["params"])) { |
|
171 | 171 | $allParameters[]=JsUtils::_correctParams($parameters["params"]); |
172 | 172 | } |
173 | - if(isset($params)){ |
|
173 | + if (isset($params)) { |
|
174 | 174 | $allParameters[]=JsUtils::_correctParams($params); |
175 | 175 | } |
176 | 176 | $parameters["params"]=\implode("+'&'+", $allParameters); |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | } |
218 | 218 | |
219 | 219 | public function jsDoJquery($jqueryCall, $param="") { |
220 | - return "$('#" . $this->identifier . "')." . $jqueryCall . "(" . Javascript::prep_value($param) . ");"; |
|
220 | + return "$('#".$this->identifier."').".$jqueryCall."(".Javascript::prep_value($param).");"; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | public function executeOnRun($jsCode) { |
@@ -237,6 +237,6 @@ discard block |
||
237 | 237 | } |
238 | 238 | |
239 | 239 | public function jsToggle($value) { |
240 | - return $this->jsDoJquery("toggle",$value); |
|
240 | + return $this->jsDoJquery("toggle", $value); |
|
241 | 241 | } |
242 | 242 | } |
@@ -6,16 +6,16 @@ discard block |
||
6 | 6 | public static $preventDefault="\nif(event && event.preventDefault) event.preventDefault();\n"; |
7 | 7 | public static $stopPropagation="\nif(event && event.stopPropagation) event.stopPropagation();\n"; |
8 | 8 | |
9 | - public static function draggable($attr="id"){ |
|
9 | + public static function draggable($attr="id") { |
|
10 | 10 | return 'var dt=event.dataTransfer || event.originalEvent.dataTransfer;dt.setData("text/plain",JSON.stringify({id:$(event.target).attr("id"),data:$(event.target).attr("'.$attr.'")}));'; |
11 | 11 | } |
12 | 12 | |
13 | - public static function dropZone($jqueryDone,$jsCallback=""){ |
|
13 | + public static function dropZone($jqueryDone, $jsCallback="") { |
|
14 | 14 | return 'var dt=event.dataTransfer || event.originalEvent.dataTransfer;var _data=JSON.parse(dt.getData("text/plain"));$(event.target).'.$jqueryDone.'($("#"+_data.id));var data=_data.data;'.$jsCallback; |
15 | 15 | } |
16 | 16 | |
17 | - public static function containsCode($expression){ |
|
18 | - return strrpos($expression, 'this')!==false||strrpos($expression, 'event')!==false||strrpos($expression, 'self')!==false; |
|
17 | + public static function containsCode($expression) { |
|
18 | + return strrpos($expression, 'this')!==false || strrpos($expression, 'event')!==false || strrpos($expression, 'self')!==false; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -46,14 +46,14 @@ discard block |
||
46 | 46 | $value=implode(",", $value); |
47 | 47 | } |
48 | 48 | if (self::containsCode($value)===false) { |
49 | - $value=\str_replace(["\\","\""], ["\\\\","\\\""], $value); |
|
49 | + $value=\str_replace(["\\", "\""], ["\\\\", "\\\""], $value); |
|
50 | 50 | $value='"'.$value.'"'; |
51 | 51 | } |
52 | - return trim($value,"%"); |
|
52 | + return trim($value, "%"); |
|
53 | 53 | } |
54 | 54 | |
55 | - public static function prep_jquery_selector($value){ |
|
56 | - if(JString::startswith($value, '$(')===false){ |
|
55 | + public static function prep_jquery_selector($value) { |
|
56 | + if (JString::startswith($value, '$(')===false) { |
|
57 | 57 | return '$('.self::prep_value($value).')'; |
58 | 58 | } |
59 | 59 | return $value; |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
18 | 18 | |
19 | 19 | abstract public function getUrl($url); |
20 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
20 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
21 | 21 | |
22 | - protected function _ajax($method,$url,$responseElement="",$parameters=[]) { |
|
23 | - if(isset($this->params["ajax"])){ |
|
22 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
23 | + if (isset($this->params["ajax"])) { |
|
24 | 24 | extract($this->params["ajax"]); |
25 | 25 | } |
26 | 26 | extract($parameters); |
@@ -30,109 +30,109 @@ discard block |
||
30 | 30 | $originalSelector=$responseElement; |
31 | 31 | $responseElement=$this->_getResponseElement($responseElement); |
32 | 32 | $retour.="var self=this;\n"; |
33 | - if($hasLoader===true && JString::isNotNull($responseElement)){ |
|
34 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
35 | - }elseif($hasLoader==="internal"){ |
|
33 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
34 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
35 | + }elseif ($hasLoader==="internal") { |
|
36 | 36 | $retour.="\n$(this).addClass('loading');"; |
37 | 37 | } |
38 | - $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
|
38 | + $ajaxParameters=["url"=>"url", "method"=>"'".\strtoupper($method)."'"]; |
|
39 | 39 | |
40 | - $ajaxParameters["async"]=($async?"true":"false"); |
|
40 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
41 | 41 | |
42 | - if(isset($params)){ |
|
42 | + if (isset($params)) { |
|
43 | 43 | $ajaxParameters["data"]=self::_correctParams($params); |
44 | 44 | } |
45 | - if(isset($headers)){ |
|
45 | + if (isset($headers)) { |
|
46 | 46 | $ajaxParameters["headers"]=$headers; |
47 | 47 | } |
48 | 48 | $this->createAjaxParameters($ajaxParameters, $parameters); |
49 | 49 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
50 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader,($historize?$originalSelector:null))."});\n"; |
|
51 | - $retour=$this->_addJsCondition($jsCondition,$retour); |
|
50 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
51 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
52 | 52 | if ($immediatly) |
53 | 53 | $this->jquery_code_for_compile[]=$retour; |
54 | 54 | return $retour; |
55 | 55 | } |
56 | 56 | |
57 | - protected function createAjaxParameters(&$original,$parameters){ |
|
58 | - $validParameters=["dataType"=>"'%value%'","beforeSend"=>"function(jqXHR,settings){%value%}","complete"=>"function(jqXHR){%value%}"]; |
|
59 | - foreach ($validParameters as $param=>$mask){ |
|
60 | - if(isset($parameters[$param])){ |
|
57 | + protected function createAjaxParameters(&$original, $parameters) { |
|
58 | + $validParameters=["dataType"=>"'%value%'", "beforeSend"=>"function(jqXHR,settings){%value%}", "complete"=>"function(jqXHR){%value%}"]; |
|
59 | + foreach ($validParameters as $param=>$mask) { |
|
60 | + if (isset($parameters[$param])) { |
|
61 | 61 | $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
62 | 62 | } |
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
66 | - protected function implodeAjaxParameters($ajaxParameters){ |
|
67 | - $s = ''; foreach ($ajaxParameters as $k=>$v) { if ($s !== '') { $s .= ','; } $s .= "'{$k}':{$v}"; } |
|
66 | + protected function implodeAjaxParameters($ajaxParameters) { |
|
67 | + $s=''; foreach ($ajaxParameters as $k=>$v) { if ($s!=='') { $s.=','; } $s.="'{$k}':{$v}"; } |
|
68 | 68 | return $s; |
69 | 69 | } |
70 | 70 | |
71 | - protected function _addJsCondition($jsCondition,$jsSource){ |
|
72 | - if(isset($jsCondition)){ |
|
71 | + protected function _addJsCondition($jsCondition, $jsSource) { |
|
72 | + if (isset($jsCondition)) { |
|
73 | 73 | return "if(".$jsCondition."){\n".$jsSource."\n}"; |
74 | 74 | } |
75 | 75 | return $jsSource; |
76 | 76 | } |
77 | 77 | |
78 | 78 | |
79 | - protected function _getAjaxUrl($url,$attr){ |
|
79 | + protected function _getAjaxUrl($url, $attr) { |
|
80 | 80 | $url=$this->_correctAjaxUrl($url); |
81 | 81 | $retour="url='".$url."';"; |
82 | 82 | $slash="/"; |
83 | - if(JString::endswith($url, "/")===true){ |
|
83 | + if (JString::endswith($url, "/")===true) { |
|
84 | 84 | $slash=""; |
85 | 85 | } |
86 | - if(JString::isNotNull($attr)){ |
|
87 | - if ($attr==="value"){ |
|
86 | + if (JString::isNotNull($attr)) { |
|
87 | + if ($attr==="value") { |
|
88 | 88 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
89 | - }elseif ($attr==="html"){ |
|
89 | + }elseif ($attr==="html") { |
|
90 | 90 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
91 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
91 | + }elseif (\substr($attr, 0, 3)==="js:") { |
|
92 | 92 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
93 | - }elseif($attr!==null && $attr!=="") |
|
93 | + }elseif ($attr!==null && $attr!=="") |
|
94 | 94 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
95 | 95 | } |
96 | 96 | return $retour; |
97 | 97 | } |
98 | 98 | |
99 | - protected function onPopstate(){ |
|
99 | + protected function onPopstate() { |
|
100 | 100 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
101 | 101 | } |
102 | 102 | |
103 | - protected function autoActiveLinks($previousURL="window.location.href"){ |
|
104 | - $result= "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
103 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
104 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
105 | 105 | $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
106 | 106 | return $result; |
107 | 107 | } |
108 | 108 | |
109 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback,$hasLoader=false,$history=null){ |
|
110 | - $retour="";$call=null; |
|
109 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
110 | + $retour=""; $call=null; |
|
111 | 111 | if (JString::isNotNull($responseElement)) { |
112 | - if(isset($ajaxTransition)){ |
|
112 | + if (isset($ajaxTransition)) { |
|
113 | 113 | $call=$this->setAjaxDataCall($ajaxTransition); |
114 | - }elseif(isset($this->ajaxTransition)){ |
|
114 | + }elseif (isset($this->ajaxTransition)) { |
|
115 | 115 | $call=$this->ajaxTransition; |
116 | 116 | } |
117 | - if(\is_callable($call)) |
|
118 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
117 | + if (\is_callable($call)) |
|
118 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
119 | 119 | else |
120 | 120 | $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
121 | 121 | } |
122 | - if(isset($history)){ |
|
123 | - if($this->params["autoActiveLinks"]){ |
|
122 | + if (isset($history)) { |
|
123 | + if ($this->params["autoActiveLinks"]) { |
|
124 | 124 | $retour.=$this->autoActiveLinks("url"); |
125 | 125 | } |
126 | 126 | $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
127 | 127 | } |
128 | - if($hasLoader==="internal"){ |
|
128 | + if ($hasLoader==="internal") { |
|
129 | 129 | $retour.="\n$(self).removeClass('loading');"; |
130 | 130 | } |
131 | 131 | $retour.="\t".$jsCallback."\n"; |
132 | 132 | return $retour; |
133 | 133 | } |
134 | 134 | |
135 | - protected function _getResponseElement($responseElement){ |
|
135 | + protected function _getResponseElement($responseElement) { |
|
136 | 136 | if (JString::isNotNull($responseElement)) { |
137 | 137 | $responseElement=Javascript::prep_jquery_selector($responseElement); |
138 | 138 | } |
@@ -142,33 +142,33 @@ discard block |
||
142 | 142 | protected function _correctAjaxUrl($url) { |
143 | 143 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
144 | 144 | $url=substr($url, 0, strlen($url)-1); |
145 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
145 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
146 | 146 | $url=$this->getUrl($url); |
147 | 147 | } |
148 | 148 | return $url; |
149 | 149 | } |
150 | 150 | |
151 | - public static function _correctParams($params){ |
|
152 | - if(JString::isNull($params)){ |
|
151 | + public static function _correctParams($params) { |
|
152 | + if (JString::isNull($params)) { |
|
153 | 153 | return ""; |
154 | 154 | } |
155 | - if(\preg_match("@^\{.*?\}$@", $params)){ |
|
155 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
156 | 156 | return '$.param('.$params.')'; |
157 | 157 | } |
158 | 158 | return $params; |
159 | 159 | } |
160 | 160 | |
161 | - public static function _implodeParams($parameters){ |
|
161 | + public static function _implodeParams($parameters) { |
|
162 | 162 | $allParameters=[]; |
163 | - foreach ($parameters as $params){ |
|
164 | - if(isset($params)) |
|
163 | + foreach ($parameters as $params) { |
|
164 | + if (isset($params)) |
|
165 | 165 | $allParameters[]=self::_correctParams($params); |
166 | 166 | } |
167 | 167 | return \implode("+'&'+", $allParameters); |
168 | 168 | } |
169 | 169 | |
170 | - protected function addLoading(&$retour, $responseElement,$ajaxLoader=null) { |
|
171 | - if(!isset($ajaxLoader)){ |
|
170 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
171 | + if (!isset($ajaxLoader)) { |
|
172 | 172 | $ajaxLoader=$this->ajaxLoader; |
173 | 173 | } |
174 | 174 | $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
@@ -176,19 +176,19 @@ discard block |
||
176 | 176 | $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
177 | 177 | } |
178 | 178 | |
179 | - protected function setAjaxDataCall($params){ |
|
179 | + protected function setAjaxDataCall($params) { |
|
180 | 180 | $result=null; |
181 | - if(!\is_callable($params)){ |
|
182 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
183 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
181 | + if (!\is_callable($params)) { |
|
182 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
183 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
184 | 184 | }; |
185 | 185 | } |
186 | 186 | return $result; |
187 | 187 | } |
188 | 188 | |
189 | - protected function setDefaultParameters(&$parameters,$default){ |
|
190 | - foreach ($default as $k=>$v){ |
|
191 | - if(!isset($parameters[$k])) |
|
189 | + protected function setDefaultParameters(&$parameters, $default) { |
|
190 | + foreach ($default as $k=>$v) { |
|
191 | + if (!isset($parameters[$k])) |
|
192 | 192 | $parameters[$k]=$v; |
193 | 193 | } |
194 | 194 | } |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | * @param string $url The url of the request |
203 | 203 | * @param string $responseElement selector of the HTML element displaying the answer |
204 | 204 | */ |
205 | - private function _get($url, $responseElement="",$parameters=[]) { |
|
206 | - return $this->_ajax("get", $url,$responseElement,$parameters); |
|
205 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
206 | + return $this->_ajax("get", $url, $responseElement, $parameters); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | * @param string $responseElement selector of the HTML element displaying the answer |
213 | 213 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
214 | 214 | */ |
215 | - public function get($url, $responseElement="",$parameters=[]) { |
|
215 | + public function get($url, $responseElement="", $parameters=[]) { |
|
216 | 216 | $parameters["immediatly"]=true; |
217 | - return $this->_get($url,$responseElement,$parameters); |
|
217 | + return $this->_get($url, $responseElement, $parameters); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -224,9 +224,9 @@ discard block |
||
224 | 224 | * @param string $responseElement selector of the HTML element displaying the answer |
225 | 225 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
226 | 226 | */ |
227 | - public function ajax($method,$url, $responseElement="", $parameters=[]) { |
|
227 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
228 | 228 | $parameters["immediatly"]=true; |
229 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
229 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | * @param string $responseElement selector of the HTML element displaying the answer |
237 | 237 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
238 | 238 | */ |
239 | - public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) { |
|
239 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
240 | 240 | $parameters["immediatly"]=false; |
241 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
241 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -247,15 +247,15 @@ discard block |
||
247 | 247 | * @param string $method Method used |
248 | 248 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
249 | 249 | */ |
250 | - private function _json($url, $method="get",$parameters=[]) { |
|
251 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
250 | + private function _json($url, $method="get", $parameters=[]) { |
|
251 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
252 | 252 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
253 | 253 | $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
254 | 254 | $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";\n\tfor(var key in data){" |
255 | 255 | ."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
256 | 256 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
257 | 257 | $parameters["jsCallback"]=$retour; |
258 | - return $this->_ajax($method, $url,null,$parameters); |
|
258 | + return $this->_ajax($method, $url, null, $parameters); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false) |
266 | 266 | */ |
267 | 267 | public function json($url, $method="get", $parameters=[]) { |
268 | - return $this->_json($url,$method,$parameters); |
|
268 | + return $this->_json($url, $method, $parameters); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | * @param string $method default get |
277 | 277 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
278 | 278 | */ |
279 | - public function jsonOn($event,$element, $url,$method="get",$parameters=array()) { |
|
280 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
281 | - return $this->_add_event($element, $this->jsonDeferred($url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
279 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
280 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
281 | + return $this->_add_event($element, $this->jsonDeferred($url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function jsonDeferred($url, $method="get", $parameters=[]) { |
291 | 291 | $parameters["immediatly"]=false; |
292 | - return $this->_json($url,$method,$parameters); |
|
292 | + return $this->_json($url, $method, $parameters); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -300,26 +300,26 @@ discard block |
||
300 | 300 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
301 | 301 | */ |
302 | 302 | private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
303 | - $parameters=\array_merge($parameters,["hasLoader"=>false]); |
|
303 | + $parameters=\array_merge($parameters, ["hasLoader"=>false]); |
|
304 | 304 | $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
305 | 305 | $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
306 | 306 | $context=isset($parameters['context']) ? $parameters['context'] : null; |
307 | - if($context===null){ |
|
307 | + if ($context===null) { |
|
308 | 308 | $parent="$('".$maskSelector."').parent()"; |
309 | - $newElm = "$('#'+newId)"; |
|
310 | - }else{ |
|
309 | + $newElm="$('#'+newId)"; |
|
310 | + } else { |
|
311 | 311 | $parent=$context; |
312 | - $newElm = $context.".find('#'+newId)"; |
|
312 | + $newElm=$context.".find('#'+newId)"; |
|
313 | 313 | } |
314 | 314 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
315 | 315 | $retour=$parent.".find('.{$rowClass}').remove();"; |
316 | 316 | $retour.="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";\n$.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(); |
317 | 317 | 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"; |
318 | - $retour.= $appendTo; |
|
318 | + $retour.=$appendTo; |
|
319 | 319 | $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"; |
320 | 320 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
321 | 321 | $parameters["jsCallback"]=$retour; |
322 | - return $this->_ajax($method, $url,null,$parameters); |
|
322 | + return $this->_ajax($method, $url, null, $parameters); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json") |
331 | 331 | */ |
332 | 332 | public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
333 | - return $this->_jsonArray($maskSelector, $url,$method,$parameters); |
|
333 | + return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -353,9 +353,9 @@ discard block |
||
353 | 353 | * @param string $method Method used, default : get |
354 | 354 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
355 | 355 | */ |
356 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$method="get",$parameters=array()) { |
|
357 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
358 | - return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector,$url,$method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
356 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
357 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
358 | + return $this->_add_event($element, $this->jsonArrayDeferred($maskSelector, $url, $method, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | */ |
368 | 368 | public function getDeferred($url, $responseElement="", $parameters=[]) { |
369 | 369 | $parameters["immediatly"]=false; |
370 | - return $this->_get($url, $responseElement,$parameters); |
|
370 | + return $this->_get($url, $responseElement, $parameters); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -380,8 +380,8 @@ discard block |
||
380 | 380 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false) |
381 | 381 | */ |
382 | 382 | public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
383 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
384 | - return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
383 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
384 | + return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @param array $parameters default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
395 | 395 | */ |
396 | 396 | public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
397 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]); |
|
398 | - return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
397 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]); |
|
398 | + return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
@@ -429,15 +429,15 @@ discard block |
||
429 | 429 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>true) |
430 | 430 | * @return $this |
431 | 431 | */ |
432 | - public function getHref($element,$responseElement="",$parameters=array()){ |
|
432 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
433 | 433 | $parameters["attr"]="href"; |
434 | - if(JString::isNull($responseElement)){ |
|
434 | + if (JString::isNull($responseElement)) { |
|
435 | 435 | $responseElement='%$(self).attr("data-target")%'; |
436 | 436 | } |
437 | - if(!isset($parameters["historize"])){ |
|
437 | + if (!isset($parameters["historize"])) { |
|
438 | 438 | $parameters["historize"]=true; |
439 | 439 | } |
440 | - return $this->getOnClick($element, "",$responseElement,$parameters); |
|
440 | + return $this->getOnClick($element, "", $responseElement, $parameters); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -447,20 +447,20 @@ discard block |
||
447 | 447 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"href","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
448 | 448 | * @return $this |
449 | 449 | */ |
450 | - public function postHref($element,$responseElement="",$parameters=array()){ |
|
450 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
451 | 451 | $parameters["attr"]="href"; |
452 | - if(JString::isNull($responseElement)){ |
|
452 | + if (JString::isNull($responseElement)) { |
|
453 | 453 | $responseElement='%$(this).attr("data-target")%'; |
454 | 454 | } |
455 | - if(!isset($parameters["historize"])){ |
|
455 | + if (!isset($parameters["historize"])) { |
|
456 | 456 | $parameters["historize"]=true; |
457 | 457 | } |
458 | - return $this->postOnClick($element, "","{}",$responseElement,$parameters); |
|
458 | + return $this->postOnClick($element, "", "{}", $responseElement, $parameters); |
|
459 | 459 | } |
460 | 460 | |
461 | - private function _post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
461 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
462 | 462 | $parameters["params"]=$params; |
463 | - return $this->_ajax("POST", $url,$responseElement,$parameters); |
|
463 | + return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -470,8 +470,8 @@ discard block |
||
470 | 470 | * @param string $params JSON parameters |
471 | 471 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
472 | 472 | */ |
473 | - public function post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
474 | - return $this->_post($url, $params,$responseElement, $parameters); |
|
473 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
474 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | * @param string $responseElement selector of the HTML element displaying the answer |
483 | 483 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
484 | 484 | */ |
485 | - public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) { |
|
485 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
486 | 486 | $parameters["immediatly"]=false; |
487 | 487 | return $this->_post($url, $params, $responseElement, $parameters); |
488 | 488 | } |
@@ -498,8 +498,8 @@ discard block |
||
498 | 498 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false) |
499 | 499 | */ |
500 | 500 | public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
501 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
502 | - return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
501 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
502 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | /** |
@@ -516,33 +516,33 @@ discard block |
||
516 | 516 | } |
517 | 517 | |
518 | 518 | private function _postForm($url, $form, $responseElement, $parameters=[]) { |
519 | - if(isset($this->params["ajax"])){ |
|
519 | + if (isset($this->params["ajax"])) { |
|
520 | 520 | extract($this->params["ajax"]); |
521 | 521 | } |
522 | - $params="{}";$validation=false; |
|
522 | + $params="{}"; $validation=false; |
|
523 | 523 | \extract($parameters); |
524 | - $async=($async)?"true":"false"; |
|
524 | + $async=($async) ? "true" : "false"; |
|
525 | 525 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
526 | 526 | $retour=$this->_getAjaxUrl($url, $attr); |
527 | 527 | $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
528 | 528 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
529 | - if(isset($params)){ |
|
529 | + if (isset($params)) { |
|
530 | 530 | $retour.="params+='&'+".self::_correctParams($params).";\n"; |
531 | 531 | } |
532 | 532 | $responseElement=$this->_getResponseElement($responseElement); |
533 | 533 | $retour.="var self=this;\n"; |
534 | - if($hasLoader===true){ |
|
535 | - $this->addLoading($retour, $responseElement,$ajaxLoader); |
|
536 | - }elseif($hasLoader==="internal"){ |
|
534 | + if ($hasLoader===true) { |
|
535 | + $this->addLoading($retour, $responseElement, $ajaxLoader); |
|
536 | + }elseif ($hasLoader==="internal") { |
|
537 | 537 | $retour.="\n$(this).addClass('loading');"; |
538 | 538 | } |
539 | - $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params","async"=>$async]; |
|
540 | - if(isset($headers)){ |
|
539 | + $ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params", "async"=>$async]; |
|
540 | + if (isset($headers)) { |
|
541 | 541 | $ajaxParameters["headers"]=$headers; |
542 | 542 | } |
543 | 543 | $this->createAjaxParameters($ajaxParameters, $parameters); |
544 | 544 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
545 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback,$hasLoader)."});\n"; |
|
545 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
546 | 546 | |
547 | 547 | if ($validation) { |
548 | 548 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -592,8 +592,8 @@ discard block |
||
592 | 592 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null,"historize"=>false) |
593 | 593 | */ |
594 | 594 | public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
595 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
596 | - return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
595 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
596 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | /** |