@@ -15,61 +15,61 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | protected $ajaxTransition; |
| 17 | 17 | |
| 18 | - protected $ajaxLoader = "<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
| 18 | + protected $ajaxLoader="<div class=\"ui active centered inline text loader\">Loading</div>"; |
|
| 19 | 19 | |
| 20 | 20 | abstract public function getUrl($url); |
| 21 | 21 | |
| 22 | - abstract public function _add_event($element, $js, $event, $preventDefault = false, $stopPropagation = false, $immediatly = true); |
|
| 22 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
| 23 | 23 | |
| 24 | - abstract public function interval($jsCode, $time, $globalName = null, $immediatly = true); |
|
| 24 | + abstract public function interval($jsCode, $time, $globalName=null, $immediatly=true); |
|
| 25 | 25 | |
| 26 | - protected function _ajax($method, $url, $responseElement = "", $parameters = []) { |
|
| 26 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
| 27 | 27 | if (isset($this->params["ajax"])) { |
| 28 | 28 | extract($this->params["ajax"]); |
| 29 | 29 | } |
| 30 | 30 | extract($parameters); |
| 31 | 31 | |
| 32 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
| 33 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
| 34 | - $originalSelector = $responseElement; |
|
| 35 | - $responseElement = $this->_getResponseElement($responseElement); |
|
| 36 | - $retour .= "var self=this;\n"; |
|
| 37 | - $before = isset($before) ? $before : ""; |
|
| 38 | - $retour .= $before; |
|
| 39 | - if ($hasLoader === true && JString::isNotNull($responseElement)) { |
|
| 32 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
| 33 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 34 | + $originalSelector=$responseElement; |
|
| 35 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 36 | + $retour.="var self=this;\n"; |
|
| 37 | + $before=isset($before) ? $before : ""; |
|
| 38 | + $retour.=$before; |
|
| 39 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
| 40 | 40 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
| 41 | - } elseif ($hasLoader === "internal") { |
|
| 42 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 41 | + } elseif ($hasLoader==="internal") { |
|
| 42 | + $retour.="\n$(this).addClass('loading');"; |
|
| 43 | 43 | } |
| 44 | - $ajaxParameters = [ |
|
| 44 | + $ajaxParameters=[ |
|
| 45 | 45 | "url" => "url", |
| 46 | - "method" => "'" . \strtoupper($method) . "'" |
|
| 46 | + "method" => "'".\strtoupper($method)."'" |
|
| 47 | 47 | ]; |
| 48 | 48 | |
| 49 | - $ajaxParameters["async"] = ($async ? "true" : "false"); |
|
| 49 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
| 50 | 50 | |
| 51 | 51 | if (isset($params)) { |
| 52 | - $ajaxParameters["data"] = self::_correctParams($params, $parameters); |
|
| 52 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
| 53 | 53 | } |
| 54 | 54 | if (isset($headers)) { |
| 55 | - $ajaxParameters["headers"] = $headers; |
|
| 55 | + $ajaxParameters["headers"]=$headers; |
|
| 56 | 56 | } |
| 57 | 57 | if (isset($partial)) { |
| 58 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
| 59 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 58 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
| 59 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 60 | 60 | } |
| 61 | 61 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 62 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 63 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null)) . "});\n"; |
|
| 62 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 63 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."});\n"; |
|
| 64 | 64 | |
| 65 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
| 65 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 66 | 66 | if ($immediatly) |
| 67 | - $this->jquery_code_for_compile[] = $retour; |
|
| 67 | + $this->jquery_code_for_compile[]=$retour; |
|
| 68 | 68 | return $retour; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | protected function createAjaxParameters(&$original, $parameters) { |
| 72 | - $validParameters = [ |
|
| 72 | + $validParameters=[ |
|
| 73 | 73 | "contentType" => "%value%", |
| 74 | 74 | "dataType" => "'%value%'", |
| 75 | 75 | "beforeSend" => "function(jqXHR,settings){%value%}", |
@@ -78,21 +78,21 @@ discard block |
||
| 78 | 78 | ]; |
| 79 | 79 | foreach ($validParameters as $param => $mask) { |
| 80 | 80 | if (isset($parameters[$param])) { |
| 81 | - $original[$param] = \str_replace("%value%", $parameters[$param], $mask); |
|
| 81 | + $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | protected function implodeAjaxParameters($ajaxParameters) { |
| 87 | - $s = ''; |
|
| 87 | + $s=''; |
|
| 88 | 88 | foreach ($ajaxParameters as $k => $v) { |
| 89 | - if ($s !== '') { |
|
| 90 | - $s .= ','; |
|
| 89 | + if ($s!=='') { |
|
| 90 | + $s.=','; |
|
| 91 | 91 | } |
| 92 | 92 | if (is_array($v)) { |
| 93 | - $s .= "'{$k}':{" . self::implodeAjaxParameters($v) . "}"; |
|
| 93 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
| 94 | 94 | } else { |
| 95 | - $s .= "'{$k}':{$v}"; |
|
| 95 | + $s.="'{$k}':{$v}"; |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | return $s; |
@@ -100,27 +100,27 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | protected function _addJsCondition($jsCondition, $jsSource) { |
| 102 | 102 | if (isset($jsCondition)) { |
| 103 | - return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
| 103 | + return "if(".$jsCondition."){\n".$jsSource."\n}"; |
|
| 104 | 104 | } |
| 105 | 105 | return $jsSource; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | protected function _getAjaxUrl($url, $attr) { |
| 109 | - $url = $this->_correctAjaxUrl($url); |
|
| 110 | - $retour = "url='" . $url . "';"; |
|
| 111 | - $slash = "/"; |
|
| 112 | - if (JString::endswith($url, "/") === true) { |
|
| 113 | - $slash = ""; |
|
| 109 | + $url=$this->_correctAjaxUrl($url); |
|
| 110 | + $retour="url='".$url."';"; |
|
| 111 | + $slash="/"; |
|
| 112 | + if (JString::endswith($url, "/")===true) { |
|
| 113 | + $slash=""; |
|
| 114 | 114 | } |
| 115 | 115 | if (JString::isNotNull($attr)) { |
| 116 | - if ($attr === "value") { |
|
| 117 | - $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
|
| 118 | - } elseif ($attr === "html") { |
|
| 119 | - $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
|
| 120 | - } elseif (\substr($attr, 0, 3) === "js:") { |
|
| 121 | - $retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n"; |
|
| 122 | - } elseif ($attr !== null && $attr !== "") |
|
| 123 | - $retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n"; |
|
| 116 | + if ($attr==="value") { |
|
| 117 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
| 118 | + } elseif ($attr==="html") { |
|
| 119 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
| 120 | + } elseif (\substr($attr, 0, 3)==="js:") { |
|
| 121 | + $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
| 122 | + } elseif ($attr!==null && $attr!=="") |
|
| 123 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
| 124 | 124 | } |
| 125 | 125 | return $retour; |
| 126 | 126 | } |
@@ -129,91 +129,91 @@ discard block |
||
| 129 | 129 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - protected function autoActiveLinks($previousURL = "window.location.href") { |
|
| 133 | - $result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 134 | - $result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 132 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
| 133 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 134 | + $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 135 | 135 | return $result; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader = false, $history = null) { |
|
| 139 | - $retour = ""; |
|
| 140 | - $call = null; |
|
| 138 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
| 139 | + $retour=""; |
|
| 140 | + $call=null; |
|
| 141 | 141 | if (JString::isNotNull($responseElement)) { |
| 142 | 142 | if (isset($ajaxTransition)) { |
| 143 | - $call = $this->setAjaxDataCall($ajaxTransition); |
|
| 143 | + $call=$this->setAjaxDataCall($ajaxTransition); |
|
| 144 | 144 | } elseif (isset($this->ajaxTransition)) { |
| 145 | - $call = $this->ajaxTransition; |
|
| 145 | + $call=$this->ajaxTransition; |
|
| 146 | 146 | } |
| 147 | 147 | if (\is_callable($call)) |
| 148 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 148 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 149 | 149 | else |
| 150 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 150 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 151 | 151 | } |
| 152 | 152 | if (isset($history)) { |
| 153 | 153 | if ($this->params["autoActiveLinks"]) { |
| 154 | - $retour .= $this->autoActiveLinks("url"); |
|
| 154 | + $retour.=$this->autoActiveLinks("url"); |
|
| 155 | 155 | } |
| 156 | - $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value($history) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 156 | + $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 157 | 157 | } |
| 158 | - if ($hasLoader === "internal") { |
|
| 159 | - $retour .= "\n$(self).removeClass('loading');"; |
|
| 158 | + if ($hasLoader==="internal") { |
|
| 159 | + $retour.="\n$(self).removeClass('loading');"; |
|
| 160 | 160 | } |
| 161 | - $retour .= "\t" . $jsCallback . "\n"; |
|
| 161 | + $retour.="\t".$jsCallback."\n"; |
|
| 162 | 162 | return $retour; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | protected function _getResponseElement($responseElement) { |
| 166 | 166 | if (JString::isNotNull($responseElement)) { |
| 167 | - $responseElement = Javascript::prep_jquery_selector($responseElement); |
|
| 167 | + $responseElement=Javascript::prep_jquery_selector($responseElement); |
|
| 168 | 168 | } |
| 169 | 169 | return $responseElement; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | protected function _correctAjaxUrl($url) { |
| 173 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
| 174 | - $url = substr($url, 0, strlen($url) - 1); |
|
| 175 | - if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
|
| 176 | - $url = $this->getUrl($url); |
|
| 173 | + if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
| 174 | + $url=substr($url, 0, strlen($url)-1); |
|
| 175 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 176 | + $url=$this->getUrl($url); |
|
| 177 | 177 | } |
| 178 | 178 | return $url; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - public static function _correctParams($params, $ajaxParameters = []) { |
|
| 181 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
| 182 | 182 | if (JString::isNull($params)) { |
| 183 | 183 | return ""; |
| 184 | 184 | } |
| 185 | 185 | if (\preg_match("@^\{.*?\}$@", $params)) { |
| 186 | - if (! isset($ajaxParameters['contentType']) || ! JString::contains($ajaxParameters['contentType'], 'json')) { |
|
| 187 | - return '$.param(' . $params . ')'; |
|
| 186 | + if (!isset($ajaxParameters['contentType']) || !JString::contains($ajaxParameters['contentType'], 'json')) { |
|
| 187 | + return '$.param('.$params.')'; |
|
| 188 | 188 | } else { |
| 189 | - return 'JSON.stringify(' . $params . ')'; |
|
| 189 | + return 'JSON.stringify('.$params.')'; |
|
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | return $params; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | public static function _implodeParams($parameters) { |
| 196 | - $allParameters = []; |
|
| 196 | + $allParameters=[]; |
|
| 197 | 197 | foreach ($parameters as $params) { |
| 198 | 198 | if (isset($params)) |
| 199 | - $allParameters[] = self::_correctParams($params); |
|
| 199 | + $allParameters[]=self::_correctParams($params); |
|
| 200 | 200 | } |
| 201 | 201 | return \implode("+'&'+", $allParameters); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 205 | - if (! isset($ajaxLoader)) { |
|
| 206 | - $ajaxLoader = $this->ajaxLoader; |
|
| 204 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 205 | + if (!isset($ajaxLoader)) { |
|
| 206 | + $ajaxLoader=$this->ajaxLoader; |
|
| 207 | 207 | } |
| 208 | - $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
|
| 209 | - $retour .= "{$responseElement}.empty();\n"; |
|
| 210 | - $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 208 | + $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
| 209 | + $retour.="{$responseElement}.empty();\n"; |
|
| 210 | + $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | protected function setAjaxDataCall($params) { |
| 214 | - $result = null; |
|
| 215 | - if (! \is_callable($params)) { |
|
| 216 | - $result = function ($responseElement, $jqueryDone = "html") use ($params) { |
|
| 214 | + $result=null; |
|
| 215 | + if (!\is_callable($params)) { |
|
| 216 | + $result=function($responseElement, $jqueryDone="html") use ($params) { |
|
| 217 | 217 | return AjaxTransition::{$params}($responseElement, $jqueryDone); |
| 218 | 218 | }; |
| 219 | 219 | } |
@@ -222,13 +222,13 @@ discard block |
||
| 222 | 222 | |
| 223 | 223 | protected function setDefaultParameters(&$parameters, $default) { |
| 224 | 224 | foreach ($default as $k => $v) { |
| 225 | - if (! isset($parameters[$k])) |
|
| 226 | - $parameters[$k] = $v; |
|
| 225 | + if (!isset($parameters[$k])) |
|
| 226 | + $parameters[$k]=$v; |
|
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | public function setAjaxLoader($loader) { |
| 231 | - $this->ajaxLoader = $loader; |
|
| 231 | + $this->ajaxLoader=$loader; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * @param string $responseElement |
| 240 | 240 | * selector of the HTML element displaying the answer |
| 241 | 241 | */ |
| 242 | - private function _get($url, $responseElement = "", $parameters = []) { |
|
| 242 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
| 243 | 243 | return $this->_ajax("get", $url, $responseElement, $parameters); |
| 244 | 244 | } |
| 245 | 245 | |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | * @param array $parameters |
| 254 | 254 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 255 | 255 | */ |
| 256 | - public function get($url, $responseElement = "", $parameters = []) { |
|
| 257 | - $parameters["immediatly"] = true; |
|
| 256 | + public function get($url, $responseElement="", $parameters=[]) { |
|
| 257 | + $parameters["immediatly"]=true; |
|
| 258 | 258 | return $this->_get($url, $responseElement, $parameters); |
| 259 | 259 | } |
| 260 | 260 | |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | * @param array $parameters |
| 271 | 271 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 272 | 272 | */ |
| 273 | - public function ajax($method, $url, $responseElement = "", $parameters = []) { |
|
| 274 | - $parameters["immediatly"] = true; |
|
| 273 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
| 274 | + $parameters["immediatly"]=true; |
|
| 275 | 275 | return $this->_ajax($method, $url, $responseElement, $parameters); |
| 276 | 276 | } |
| 277 | 277 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | * $immediatly |
| 294 | 294 | * @return string |
| 295 | 295 | */ |
| 296 | - public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = "", $parameters = [], $immediatly = true) { |
|
| 296 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement="", $parameters=[], $immediatly=true) { |
|
| 297 | 297 | return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
| 298 | 298 | } |
| 299 | 299 | |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | * @param array $parameters |
| 310 | 310 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 311 | 311 | */ |
| 312 | - public function ajaxDeferred($method, $url, $responseElement = "", $parameters = []) { |
|
| 313 | - $parameters["immediatly"] = false; |
|
| 312 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
| 313 | + $parameters["immediatly"]=false; |
|
| 314 | 314 | return $this->_ajax($method, $url, $responseElement, $parameters); |
| 315 | 315 | } |
| 316 | 316 | |
@@ -324,15 +324,15 @@ discard block |
||
| 324 | 324 | * @param array $parameters |
| 325 | 325 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 326 | 326 | */ |
| 327 | - private function _json($url, $method = "get", $parameters = []) { |
|
| 328 | - $parameters = \array_merge($parameters, [ |
|
| 327 | + private function _json($url, $method="get", $parameters=[]) { |
|
| 328 | + $parameters=\array_merge($parameters, [ |
|
| 329 | 329 | "hasLoader" => false |
| 330 | 330 | ]); |
| 331 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 332 | - $context = isset($parameters['context']) ? $parameters['context'] : "document"; |
|
| 333 | - $retour = "\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t" . $jsCallback . ";" . "\n\tfor(var key in data){" . "if($('#'+key," . $context . ").length){ if($('#'+key," . $context . ").is('[value]')) { $('#'+key," . $context . ").val(data[key]);} else { $('#'+key," . $context . ").html(data[key]); }}};\n"; |
|
| 334 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 335 | - $parameters["jsCallback"] = $retour; |
|
| 331 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 332 | + $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
|
| 333 | + $retour="\tdata=($.isPlainObject(data))?data:JSON.parse(data);\t".$jsCallback.";"."\n\tfor(var key in data){"."if($('#'+key,".$context.").length){ if($('#'+key,".$context.").is('[value]')) { $('#'+key,".$context.").val(data[key]);} else { $('#'+key,".$context.").html(data[key]); }}};\n"; |
|
| 334 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 335 | + $parameters["jsCallback"]=$retour; |
|
| 336 | 336 | return $this->_ajax($method, $url, null, $parameters); |
| 337 | 337 | } |
| 338 | 338 | |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | * @param array $parameters |
| 347 | 347 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 348 | 348 | */ |
| 349 | - public function json($url, $method = "get", $parameters = []) { |
|
| 349 | + public function json($url, $method="get", $parameters=[]) { |
|
| 350 | 350 | return $this->_json($url, $method, $parameters); |
| 351 | 351 | } |
| 352 | 352 | |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | * @param array $parameters |
| 363 | 363 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null) |
| 364 | 364 | */ |
| 365 | - public function jsonOn($event, $element, $url, $method = "get", $parameters = array()) { |
|
| 365 | + public function jsonOn($event, $element, $url, $method="get", $parameters=array()) { |
|
| 366 | 366 | $this->setDefaultParameters($parameters, [ |
| 367 | 367 | "preventDefault" => true, |
| 368 | 368 | "stopPropagation" => true, |
@@ -381,8 +381,8 @@ discard block |
||
| 381 | 381 | * @param array $parameters |
| 382 | 382 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 383 | 383 | */ |
| 384 | - public function jsonDeferred($url, $method = "get", $parameters = []) { |
|
| 385 | - $parameters["immediatly"] = false; |
|
| 384 | + public function jsonDeferred($url, $method="get", $parameters=[]) { |
|
| 385 | + $parameters["immediatly"]=false; |
|
| 386 | 386 | return $this->_json($url, $method, $parameters); |
| 387 | 387 | } |
| 388 | 388 | |
@@ -397,29 +397,29 @@ discard block |
||
| 397 | 397 | * @param array $parameters |
| 398 | 398 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 399 | 399 | */ |
| 400 | - private function _jsonArray($maskSelector, $url, $method = "get", $parameters = []) { |
|
| 401 | - $parameters = \array_merge($parameters, [ |
|
| 400 | + private function _jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
|
| 401 | + $parameters=\array_merge($parameters, [ |
|
| 402 | 402 | "hasLoader" => false |
| 403 | 403 | ]); |
| 404 | - $rowClass = isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
| 405 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 406 | - $context = isset($parameters['context']) ? $parameters['context'] : null; |
|
| 407 | - if ($context === null) { |
|
| 408 | - $parent = "$('" . $maskSelector . "').parent()"; |
|
| 409 | - $newElm = "$('#'+newId)"; |
|
| 404 | + $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
| 405 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 406 | + $context=isset($parameters['context']) ? $parameters['context'] : null; |
|
| 407 | + if ($context===null) { |
|
| 408 | + $parent="$('".$maskSelector."').parent()"; |
|
| 409 | + $newElm="$('#'+newId)"; |
|
| 410 | 410 | } else { |
| 411 | - $parent = $context; |
|
| 412 | - $newElm = $context . ".find('#'+newId)"; |
|
| 411 | + $parent=$context; |
|
| 412 | + $newElm=$context.".find('#'+newId)"; |
|
| 413 | 413 | } |
| 414 | - $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
|
| 415 | - $retour = $parent . ".find('.{$rowClass}').remove();"; |
|
| 416 | - $retour .= "\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\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(); |
|
| 414 | + $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
| 415 | + $retour=$parent.".find('.{$rowClass}').remove();"; |
|
| 416 | + $retour.="\tdata=($.isPlainObject(data)||$.isArray(data))?data:JSON.parse(data);\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(); |
|
| 417 | 417 | 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"; |
| 418 | - $retour .= $appendTo; |
|
| 419 | - $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"; |
|
| 420 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 421 | - $retour .= "\t" . $jsCallback; |
|
| 422 | - $parameters["jsCallback"] = $retour; |
|
| 418 | + $retour.=$appendTo; |
|
| 419 | + $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"; |
|
| 420 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 421 | + $retour.="\t".$jsCallback; |
|
| 422 | + $parameters["jsCallback"]=$retour; |
|
| 423 | 423 | return $this->_ajax($method, $url, null, $parameters); |
| 424 | 424 | } |
| 425 | 425 | |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | * @param array $parameters |
| 435 | 435 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 436 | 436 | */ |
| 437 | - public function jsonArray($maskSelector, $url, $method = "get", $parameters = []) { |
|
| 437 | + public function jsonArray($maskSelector, $url, $method="get", $parameters=[]) { |
|
| 438 | 438 | return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
| 439 | 439 | } |
| 440 | 440 | |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | * @param array $parameters |
| 450 | 450 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
| 451 | 451 | */ |
| 452 | - public function jsonArrayDeferred($maskSelector, $url, $method = "get", $parameters) { |
|
| 453 | - $parameters["immediatly"] = false; |
|
| 452 | + public function jsonArrayDeferred($maskSelector, $url, $method="get", $parameters) { |
|
| 453 | + $parameters["immediatly"]=false; |
|
| 454 | 454 | return $this->jsonArray($maskSelector, $url, $method, $parameters); |
| 455 | 455 | } |
| 456 | 456 | |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | * @param array $parameters |
| 467 | 467 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null) |
| 468 | 468 | */ |
| 469 | - public function jsonArrayOn($event, $element, $maskSelector, $url, $method = "get", $parameters = array()) { |
|
| 469 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method="get", $parameters=array()) { |
|
| 470 | 470 | $this->setDefaultParameters($parameters, [ |
| 471 | 471 | "preventDefault" => true, |
| 472 | 472 | "stopPropagation" => true, |
@@ -486,8 +486,8 @@ discard block |
||
| 486 | 486 | * @param array $parameters |
| 487 | 487 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 488 | 488 | */ |
| 489 | - public function getDeferred($url, $responseElement = "", $parameters = []) { |
|
| 490 | - $parameters["immediatly"] = false; |
|
| 489 | + public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
| 490 | + $parameters["immediatly"]=false; |
|
| 491 | 491 | return $this->_get($url, $responseElement, $parameters); |
| 492 | 492 | } |
| 493 | 493 | |
@@ -506,7 +506,7 @@ discard block |
||
| 506 | 506 | * @param array $parameters |
| 507 | 507 | * 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,"before"=>null) |
| 508 | 508 | */ |
| 509 | - public function getOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
|
| 509 | + public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
| 510 | 510 | $this->setDefaultParameters($parameters, [ |
| 511 | 511 | "preventDefault" => true, |
| 512 | 512 | "stopPropagation" => true, |
@@ -530,7 +530,7 @@ discard block |
||
| 530 | 530 | * @param array $parameters |
| 531 | 531 | * 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,"before"=>null) |
| 532 | 532 | */ |
| 533 | - public function ajaxOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
|
| 533 | + public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
| 534 | 534 | $this->setDefaultParameters($parameters, [ |
| 535 | 535 | "preventDefault" => true, |
| 536 | 536 | "stopPropagation" => true, |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | * @param array $parameters |
| 554 | 554 | * 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,"before"=>null) |
| 555 | 555 | */ |
| 556 | - public function ajaxOnClick($element, $url, $responseElement = "", $parameters = array()) { |
|
| 556 | + public function ajaxOnClick($element, $url, $responseElement="", $parameters=array()) { |
|
| 557 | 557 | return $this->ajaxOn("click", $element, $url, $responseElement, $parameters); |
| 558 | 558 | } |
| 559 | 559 | |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | * @param array $parameters |
| 571 | 571 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 572 | 572 | */ |
| 573 | - public function getOnClick($element, $url, $responseElement = "", $parameters = array()) { |
|
| 573 | + public function getOnClick($element, $url, $responseElement="", $parameters=array()) { |
|
| 574 | 574 | return $this->getOn("click", $element, $url, $responseElement, $parameters); |
| 575 | 575 | } |
| 576 | 576 | |
@@ -585,15 +585,15 @@ discard block |
||
| 585 | 585 | * 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,"before"=>null) |
| 586 | 586 | * @return $this |
| 587 | 587 | */ |
| 588 | - public function getHref($element, $responseElement = "", $parameters = array()) { |
|
| 589 | - $parameters["attr"] = "href"; |
|
| 588 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
| 589 | + $parameters["attr"]="href"; |
|
| 590 | 590 | if (JString::isNull($responseElement)) { |
| 591 | - $responseElement = '%$(self).attr("data-target")%'; |
|
| 591 | + $responseElement='%$(self).attr("data-target")%'; |
|
| 592 | 592 | } else { |
| 593 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 593 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 594 | 594 | } |
| 595 | - if (! isset($parameters["historize"])) { |
|
| 596 | - $parameters["historize"] = true; |
|
| 595 | + if (!isset($parameters["historize"])) { |
|
| 596 | + $parameters["historize"]=true; |
|
| 597 | 597 | } |
| 598 | 598 | return $this->getOnClick($element, "", $responseElement, $parameters); |
| 599 | 599 | } |
@@ -609,21 +609,21 @@ discard block |
||
| 609 | 609 | * 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,"before"=>null) |
| 610 | 610 | * @return $this |
| 611 | 611 | */ |
| 612 | - public function postHref($element, $responseElement = "", $parameters = array()) { |
|
| 613 | - $parameters["attr"] = "href"; |
|
| 612 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
| 613 | + $parameters["attr"]="href"; |
|
| 614 | 614 | if (JString::isNull($responseElement)) { |
| 615 | - $responseElement = '%$(this).attr("data-target")%'; |
|
| 615 | + $responseElement='%$(this).attr("data-target")%'; |
|
| 616 | 616 | } else { |
| 617 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 617 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 618 | 618 | } |
| 619 | - if (! isset($parameters["historize"])) { |
|
| 620 | - $parameters["historize"] = true; |
|
| 619 | + if (!isset($parameters["historize"])) { |
|
| 620 | + $parameters["historize"]=true; |
|
| 621 | 621 | } |
| 622 | 622 | return $this->postOnClick($element, "", "{}", $responseElement, $parameters); |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | - private function _post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 626 | - $parameters["params"] = $params; |
|
| 625 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 626 | + $parameters["params"]=$params; |
|
| 627 | 627 | return $this->_ajax("POST", $url, $responseElement, $parameters); |
| 628 | 628 | } |
| 629 | 629 | |
@@ -639,7 +639,7 @@ discard block |
||
| 639 | 639 | * @param array $parameters |
| 640 | 640 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 641 | 641 | */ |
| 642 | - public function post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 642 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 643 | 643 | return $this->_post($url, $params, $responseElement, $parameters); |
| 644 | 644 | } |
| 645 | 645 | |
@@ -656,8 +656,8 @@ discard block |
||
| 656 | 656 | * @param array $parameters |
| 657 | 657 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 658 | 658 | */ |
| 659 | - public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 660 | - $parameters["immediatly"] = false; |
|
| 659 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 660 | + $parameters["immediatly"]=false; |
|
| 661 | 661 | return $this->_post($url, $params, $responseElement, $parameters); |
| 662 | 662 | } |
| 663 | 663 | |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | * @param array $parameters |
| 677 | 677 | * 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,"before"=>null) |
| 678 | 678 | */ |
| 679 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
| 679 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 680 | 680 | $this->setDefaultParameters($parameters, [ |
| 681 | 681 | "preventDefault" => true, |
| 682 | 682 | "stopPropagation" => true, |
@@ -699,64 +699,64 @@ discard block |
||
| 699 | 699 | * @param array $parameters |
| 700 | 700 | * 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,"before"=>null,"before"=>null) |
| 701 | 701 | */ |
| 702 | - public function postOnClick($element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
| 702 | + public function postOnClick($element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 703 | 703 | return $this->postOn("click", $element, $url, $params, $responseElement, $parameters); |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | - private function _postForm($url, $form, $responseElement, $parameters = []) { |
|
| 706 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 707 | 707 | if (isset($this->params["ajax"])) { |
| 708 | 708 | extract($this->params["ajax"]); |
| 709 | 709 | } |
| 710 | - $params = "{}"; |
|
| 711 | - $validation = false; |
|
| 710 | + $params="{}"; |
|
| 711 | + $validation=false; |
|
| 712 | 712 | \extract($parameters); |
| 713 | - $async = ($async) ? "true" : "false"; |
|
| 714 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
| 715 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
| 716 | - $retour .= "\n$('#" . $form . "').trigger('ajaxSubmit');"; |
|
| 717 | - if (! isset($contentType) || $contentType != 'false') { |
|
| 718 | - $retour .= "\nvar params=$('#" . $form . "').serialize();\n"; |
|
| 713 | + $async=($async) ? "true" : "false"; |
|
| 714 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
| 715 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 716 | + $retour.="\n$('#".$form."').trigger('ajaxSubmit');"; |
|
| 717 | + if (!isset($contentType) || $contentType!='false') { |
|
| 718 | + $retour.="\nvar params=$('#".$form."').serialize();\n"; |
|
| 719 | 719 | if (isset($params)) { |
| 720 | - $retour .= "params+='&'+" . self::_correctParams($params) . ";\n"; |
|
| 720 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
| 721 | 721 | } |
| 722 | 722 | } else { |
| 723 | - $retour .= "\nvar params=new FormData($('#" . $form . "')[0]);\n"; |
|
| 723 | + $retour.="\nvar params=new FormData($('#".$form."')[0]);\n"; |
|
| 724 | 724 | } |
| 725 | - $responseElement = $this->_getResponseElement($responseElement); |
|
| 726 | - $retour .= "var self=this;\n"; |
|
| 727 | - $before = isset($before) ? $before : ""; |
|
| 728 | - $retour .= $before; |
|
| 729 | - if ($hasLoader === true) { |
|
| 725 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 726 | + $retour.="var self=this;\n"; |
|
| 727 | + $before=isset($before) ? $before : ""; |
|
| 728 | + $retour.=$before; |
|
| 729 | + if ($hasLoader===true) { |
|
| 730 | 730 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
| 731 | - } elseif ($hasLoader === "internal") { |
|
| 732 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 731 | + } elseif ($hasLoader==="internal") { |
|
| 732 | + $retour.="\n$(this).addClass('loading');"; |
|
| 733 | 733 | } |
| 734 | - $ajaxParameters = [ |
|
| 734 | + $ajaxParameters=[ |
|
| 735 | 735 | "url" => "url", |
| 736 | 736 | "method" => "'POST'", |
| 737 | 737 | "data" => "params", |
| 738 | 738 | "async" => $async |
| 739 | 739 | ]; |
| 740 | 740 | if (isset($headers)) { |
| 741 | - $ajaxParameters["headers"] = $headers; |
|
| 741 | + $ajaxParameters["headers"]=$headers; |
|
| 742 | 742 | } |
| 743 | 743 | if (isset($partial)) { |
| 744 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
| 745 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 744 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
| 745 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 746 | 746 | } |
| 747 | 747 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 748 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n"; |
|
| 749 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader) . "});\n"; |
|
| 748 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
| 749 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."});\n"; |
|
| 750 | 750 | |
| 751 | 751 | if ($validation) { |
| 752 | - $retour = "$('#" . $form . "').validate({submitHandler: function(form) { |
|
| 753 | - " . $retour . " |
|
| 752 | + $retour="$('#".$form."').validate({submitHandler: function(form) { |
|
| 753 | + " . $retour." |
|
| 754 | 754 | }});\n"; |
| 755 | - $retour .= "$('#" . $form . "').submit();\n"; |
|
| 755 | + $retour.="$('#".$form."').submit();\n"; |
|
| 756 | 756 | } |
| 757 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
| 757 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 758 | 758 | if ($immediatly) |
| 759 | - $this->jquery_code_for_compile[] = $retour; |
|
| 759 | + $this->jquery_code_for_compile[]=$retour; |
|
| 760 | 760 | return $retour; |
| 761 | 761 | } |
| 762 | 762 | |
@@ -772,8 +772,8 @@ discard block |
||
| 772 | 772 | * @param array $parameters |
| 773 | 773 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 774 | 774 | */ |
| 775 | - public function postForm($url, $form, $responseElement, $parameters = []) { |
|
| 776 | - $parameters["immediatly"] = true; |
|
| 775 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 776 | + $parameters["immediatly"]=true; |
|
| 777 | 777 | return $this->_postForm($url, $form, $responseElement, $parameters); |
| 778 | 778 | } |
| 779 | 779 | |
@@ -790,8 +790,8 @@ discard block |
||
| 790 | 790 | * @param array $parameters |
| 791 | 791 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 792 | 792 | */ |
| 793 | - public function postFormDeferred($url, $form, $responseElement, $parameters = []) { |
|
| 794 | - $parameters["immediatly"] = false; |
|
| 793 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
| 794 | + $parameters["immediatly"]=false; |
|
| 795 | 795 | return $this->_postForm($url, $form, $responseElement, $parameters); |
| 796 | 796 | } |
| 797 | 797 | |
@@ -808,7 +808,7 @@ discard block |
||
| 808 | 808 | * @param array $parameters |
| 809 | 809 | * 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,"before"=>null) |
| 810 | 810 | */ |
| 811 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array()) { |
|
| 811 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 812 | 812 | $this->setDefaultParameters($parameters, [ |
| 813 | 813 | "preventDefault" => true, |
| 814 | 814 | "stopPropagation" => true, |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | * @param array $parameters |
| 830 | 830 | * 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,"before"=>null) |
| 831 | 831 | */ |
| 832 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array()) { |
|
| 832 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 833 | 833 | return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
| 834 | 834 | } |
| 835 | 835 | } |
@@ -63,8 +63,9 @@ discard block |
||
| 63 | 63 | $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null)) . "});\n"; |
| 64 | 64 | |
| 65 | 65 | $retour = $this->_addJsCondition($jsCondition, $retour); |
| 66 | - if ($immediatly) |
|
| 67 | - $this->jquery_code_for_compile[] = $retour; |
|
| 66 | + if ($immediatly) { |
|
| 67 | + $this->jquery_code_for_compile[] = $retour; |
|
| 68 | + } |
|
| 68 | 69 | return $retour; |
| 69 | 70 | } |
| 70 | 71 | |
@@ -119,8 +120,9 @@ discard block |
||
| 119 | 120 | $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
| 120 | 121 | } elseif (\substr($attr, 0, 3) === "js:") { |
| 121 | 122 | $retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n"; |
| 122 | - } elseif ($attr !== null && $attr !== "") |
|
| 123 | - $retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n"; |
|
| 123 | + } elseif ($attr !== null && $attr !== "") { |
|
| 124 | + $retour .= "url=url+'" . $slash . "'+($(this).attr('" . $attr . "')||'');\n"; |
|
| 125 | + } |
|
| 124 | 126 | } |
| 125 | 127 | return $retour; |
| 126 | 128 | } |
@@ -144,10 +146,11 @@ discard block |
||
| 144 | 146 | } elseif (isset($this->ajaxTransition)) { |
| 145 | 147 | $call = $this->ajaxTransition; |
| 146 | 148 | } |
| 147 | - if (\is_callable($call)) |
|
| 148 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 149 | - else |
|
| 150 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 149 | + if (\is_callable($call)) { |
|
| 150 | + $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 151 | + } else { |
|
| 152 | + $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 153 | + } |
|
| 151 | 154 | } |
| 152 | 155 | if (isset($history)) { |
| 153 | 156 | if ($this->params["autoActiveLinks"]) { |
@@ -170,8 +173,9 @@ discard block |
||
| 170 | 173 | } |
| 171 | 174 | |
| 172 | 175 | protected function _correctAjaxUrl($url) { |
| 173 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
| 174 | - $url = substr($url, 0, strlen($url) - 1); |
|
| 176 | + if ($url !== "/" && JString::endsWith($url, "/") === true) { |
|
| 177 | + $url = substr($url, 0, strlen($url) - 1); |
|
| 178 | + } |
|
| 175 | 179 | if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
| 176 | 180 | $url = $this->getUrl($url); |
| 177 | 181 | } |
@@ -195,8 +199,9 @@ discard block |
||
| 195 | 199 | public static function _implodeParams($parameters) { |
| 196 | 200 | $allParameters = []; |
| 197 | 201 | foreach ($parameters as $params) { |
| 198 | - if (isset($params)) |
|
| 199 | - $allParameters[] = self::_correctParams($params); |
|
| 202 | + if (isset($params)) { |
|
| 203 | + $allParameters[] = self::_correctParams($params); |
|
| 204 | + } |
|
| 200 | 205 | } |
| 201 | 206 | return \implode("+'&'+", $allParameters); |
| 202 | 207 | } |
@@ -222,8 +227,9 @@ discard block |
||
| 222 | 227 | |
| 223 | 228 | protected function setDefaultParameters(&$parameters, $default) { |
| 224 | 229 | foreach ($default as $k => $v) { |
| 225 | - if (! isset($parameters[$k])) |
|
| 226 | - $parameters[$k] = $v; |
|
| 230 | + if (! isset($parameters[$k])) { |
|
| 231 | + $parameters[$k] = $v; |
|
| 232 | + } |
|
| 227 | 233 | } |
| 228 | 234 | } |
| 229 | 235 | |
@@ -755,8 +761,9 @@ discard block |
||
| 755 | 761 | $retour .= "$('#" . $form . "').submit();\n"; |
| 756 | 762 | } |
| 757 | 763 | $retour = $this->_addJsCondition($jsCondition, $retour); |
| 758 | - if ($immediatly) |
|
| 759 | - $this->jquery_code_for_compile[] = $retour; |
|
| 764 | + if ($immediatly) { |
|
| 765 | + $this->jquery_code_for_compile[] = $retour; |
|
| 766 | + } |
|
| 760 | 767 | return $retour; |
| 761 | 768 | } |
| 762 | 769 | |