@@ -15,75 +15,75 @@ 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, $listenerOn = false); |
|
| 22 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true, $listenerOn=false); |
|
| 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 === 'response') { |
|
| 41 | + } elseif ($hasLoader==='response') { |
|
| 42 | 42 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
| 43 | - } elseif ($hasLoader === 'internal-x') { |
|
| 43 | + } elseif ($hasLoader==='internal-x') { |
|
| 44 | 44 | $this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader); |
| 45 | - } elseif ($hasLoader === 'internal') { |
|
| 46 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 45 | + } elseif ($hasLoader==='internal') { |
|
| 46 | + $retour.="\n$(this).addClass('loading');"; |
|
| 47 | 47 | } elseif (\is_string($hasLoader)) { |
| 48 | 48 | $this->addLoading($retour, $hasLoader, $ajaxLoader); |
| 49 | 49 | } |
| 50 | - $ajaxParameters = [ |
|
| 50 | + $ajaxParameters=[ |
|
| 51 | 51 | "url" => "url", |
| 52 | - "method" => "'" . \strtoupper($method) . "'" |
|
| 52 | + "method" => "'".\strtoupper($method)."'" |
|
| 53 | 53 | ]; |
| 54 | 54 | |
| 55 | - $ajaxParameters["async"] = ($async ? "true" : "false"); |
|
| 55 | + $ajaxParameters["async"]=($async ? "true" : "false"); |
|
| 56 | 56 | |
| 57 | 57 | if (isset($params)) { |
| 58 | - $ajaxParameters["data"] = self::_correctParams($params, $parameters); |
|
| 58 | + $ajaxParameters["data"]=self::_correctParams($params, $parameters); |
|
| 59 | 59 | } |
| 60 | 60 | if (isset($headers)) { |
| 61 | - $ajaxParameters["headers"] = $headers; |
|
| 61 | + $ajaxParameters["headers"]=$headers; |
|
| 62 | 62 | } |
| 63 | 63 | if ($csrf) { |
| 64 | - $csrf = (is_string($csrf)) ? $csrf : 'csrf-token'; |
|
| 65 | - $parameters["beforeSend"] = "jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
| 64 | + $csrf=(is_string($csrf)) ? $csrf : 'csrf-token'; |
|
| 65 | + $parameters["beforeSend"]="jqXHR.setRequestHeader('{$csrf}', $('meta[name=\"{$csrf}\"]').attr('content'));"; |
|
| 66 | 66 | } |
| 67 | 67 | if (isset($partial)) { |
| 68 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
| 69 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 68 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
| 69 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 70 | 70 | } |
| 71 | 71 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 72 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 73 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null)) . "})"; |
|
| 72 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
|
| 73 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null))."})"; |
|
| 74 | 74 | if (isset($error)) { |
| 75 | - $retour .= '.fail(function( jqXHR, textStatus, errorThrown ){' . $error . '})'; |
|
| 75 | + $retour.='.fail(function( jqXHR, textStatus, errorThrown ){'.$error.'})'; |
|
| 76 | 76 | } |
| 77 | - $retour .= ";\n"; |
|
| 78 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
| 77 | + $retour.=";\n"; |
|
| 78 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 79 | 79 | if ($immediatly) { |
| 80 | - $this->jquery_code_for_compile[] = $retour; |
|
| 80 | + $this->jquery_code_for_compile[]=$retour; |
|
| 81 | 81 | } |
| 82 | 82 | return $retour; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | protected function createAjaxParameters(&$original, $parameters) { |
| 86 | - $validParameters = [ |
|
| 86 | + $validParameters=[ |
|
| 87 | 87 | "contentType" => "%value%", |
| 88 | 88 | "dataType" => "'%value%'", |
| 89 | 89 | "beforeSend" => "function(jqXHR,settings){%value%}", |
@@ -92,21 +92,21 @@ discard block |
||
| 92 | 92 | ]; |
| 93 | 93 | foreach ($validParameters as $param => $mask) { |
| 94 | 94 | if (isset($parameters[$param])) { |
| 95 | - $original[$param] = \str_replace("%value%", $parameters[$param], $mask); |
|
| 95 | + $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | protected function implodeAjaxParameters($ajaxParameters) { |
| 101 | - $s = ''; |
|
| 101 | + $s=''; |
|
| 102 | 102 | foreach ($ajaxParameters as $k => $v) { |
| 103 | - if ($s !== '') { |
|
| 104 | - $s .= ','; |
|
| 103 | + if ($s!=='') { |
|
| 104 | + $s.=','; |
|
| 105 | 105 | } |
| 106 | 106 | if (is_array($v)) { |
| 107 | - $s .= "'{$k}':{" . self::implodeAjaxParameters($v) . "}"; |
|
| 107 | + $s.="'{$k}':{".self::implodeAjaxParameters($v)."}"; |
|
| 108 | 108 | } else { |
| 109 | - $s .= "'{$k}':{$v}"; |
|
| 109 | + $s.="'{$k}':{$v}"; |
|
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | return $s; |
@@ -114,29 +114,29 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | protected function _addJsCondition($jsCondition, $jsSource) { |
| 116 | 116 | if (isset($jsCondition)) { |
| 117 | - return "if(" . $jsCondition . "){\n" . $jsSource . "\n}"; |
|
| 117 | + return "if(".$jsCondition."){\n".$jsSource."\n}"; |
|
| 118 | 118 | } |
| 119 | 119 | return $jsSource; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | protected function _getAjaxUrl($url, $attr) { |
| 123 | - $url = $this->_correctAjaxUrl($url); |
|
| 124 | - $retour = "url='" . $url . "';"; |
|
| 125 | - $slash = "/"; |
|
| 126 | - if (JString::endswith($url, "/") === true) { |
|
| 127 | - $slash = ""; |
|
| 123 | + $url=$this->_correctAjaxUrl($url); |
|
| 124 | + $retour="url='".$url."';"; |
|
| 125 | + $slash="/"; |
|
| 126 | + if (JString::endswith($url, "/")===true) { |
|
| 127 | + $slash=""; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | if (JString::isNotNull($attr)) { |
| 131 | - if ($attr === "value") { |
|
| 132 | - $retour .= "url=url+'" . $slash . "'+$(this).val();\n"; |
|
| 133 | - } elseif ($attr === "html") { |
|
| 134 | - $retour .= "url=url+'" . $slash . "'+$(this).html();\n"; |
|
| 135 | - } elseif (\substr($attr, 0, 3) === "js:") { |
|
| 136 | - $retour .= "url=url+'" . $slash . "'+" . \substr($attr, 3) . ";\n"; |
|
| 137 | - } elseif ($attr !== null && $attr !== "") { |
|
| 138 | - $retour .= "let elmUrl=$(this).attr('" . $attr . "')||'';"; |
|
| 139 | - $retour .= "url=(!/^((http|https|ftp):\/\/)/.test(elmUrl))?url+'" . $slash . "'+elmUrl:elmUrl;\n"; |
|
| 131 | + if ($attr==="value") { |
|
| 132 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
| 133 | + } elseif ($attr==="html") { |
|
| 134 | + $retour.="url=url+'".$slash."'+$(this).html();\n"; |
|
| 135 | + } elseif (\substr($attr, 0, 3)==="js:") { |
|
| 136 | + $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
|
| 137 | + } elseif ($attr!==null && $attr!=="") { |
|
| 138 | + $retour.="let elmUrl=$(this).attr('".$attr."')||'';"; |
|
| 139 | + $retour.="url=(!/^((http|https|ftp):\/\/)/.test(elmUrl))?url+'".$slash."'+elmUrl:elmUrl;\n"; |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | return $retour; |
@@ -146,110 +146,110 @@ discard block |
||
| 146 | 146 | return "window.onpopstate = function(e){if(e.state){var target=e.state.jqueryDone;$(e.state.selector)[target](e.state.html);}};"; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - protected function autoActiveLinks($previousURL = "window.location.href") { |
|
| 150 | - $result = "\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 151 | - $result .= "\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 149 | + protected function autoActiveLinks($previousURL="window.location.href") { |
|
| 150 | + $result="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}"; |
|
| 151 | + $result.="\nvar myurl={$previousURL};if(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(myurl).addClass('active');window._previousURL=myurl;"; |
|
| 152 | 152 | return $result; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader = false, $history = null) { |
|
| 156 | - $retour = ""; |
|
| 157 | - $call = null; |
|
| 155 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader=false, $history=null) { |
|
| 156 | + $retour=""; |
|
| 157 | + $call=null; |
|
| 158 | 158 | if (JString::isNotNull($responseElement)) { |
| 159 | 159 | if (isset($ajaxTransition)) { |
| 160 | - $call = $this->setAjaxDataCall($ajaxTransition); |
|
| 160 | + $call=$this->setAjaxDataCall($ajaxTransition); |
|
| 161 | 161 | } elseif (isset($this->ajaxTransition)) { |
| 162 | - $call = $this->ajaxTransition; |
|
| 162 | + $call=$this->ajaxTransition; |
|
| 163 | 163 | } |
| 164 | 164 | if (\is_callable($call)) |
| 165 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 165 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 166 | 166 | else |
| 167 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 167 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 168 | 168 | } |
| 169 | 169 | if (isset($history)) { |
| 170 | 170 | if ($this->params["autoActiveLinks"]) { |
| 171 | - $retour .= $this->autoActiveLinks("url"); |
|
| 171 | + $retour.=$this->autoActiveLinks("url"); |
|
| 172 | 172 | } |
| 173 | - $retour .= "\nwindow.history.pushState({'html':data,'selector':" . Javascript::prep_value($history) . ",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 173 | + $retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);"; |
|
| 174 | 174 | } |
| 175 | - if ($hasLoader === 'internal') { |
|
| 176 | - $retour .= "\n$(self).removeClass('loading');"; |
|
| 177 | - } elseif ($hasLoader === 'internal-x') { |
|
| 178 | - $retour .= "\n$(self).children('.ajax-loader').remove();"; |
|
| 175 | + if ($hasLoader==='internal') { |
|
| 176 | + $retour.="\n$(self).removeClass('loading');"; |
|
| 177 | + } elseif ($hasLoader==='internal-x') { |
|
| 178 | + $retour.="\n$(self).children('.ajax-loader').remove();"; |
|
| 179 | 179 | } else { |
| 180 | - $retour .= "\n$(self).find('.loading').removeClass('loading');"; |
|
| 180 | + $retour.="\n$(self).find('.loading').removeClass('loading');"; |
|
| 181 | 181 | } |
| 182 | - $retour .= "\t" . $jsCallback . "\n"; |
|
| 182 | + $retour.="\t".$jsCallback."\n"; |
|
| 183 | 183 | return $retour; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | protected function _getResponseElement($responseElement) { |
| 187 | 187 | if (JString::isNotNull($responseElement)) { |
| 188 | - $responseElement = Javascript::prep_jquery_selector($responseElement); |
|
| 188 | + $responseElement=Javascript::prep_jquery_selector($responseElement); |
|
| 189 | 189 | } |
| 190 | 190 | return $responseElement; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | protected function _getFormElement($formElement) { |
| 194 | 194 | if (JString::isNotNull($formElement)) { |
| 195 | - $formElement = Javascript::prep_value($formElement); |
|
| 195 | + $formElement=Javascript::prep_value($formElement); |
|
| 196 | 196 | } |
| 197 | 197 | return $formElement; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | protected function _correctAjaxUrl($url) { |
| 201 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
| 202 | - $url = substr($url, 0, strlen($url) - 1); |
|
| 203 | - if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
|
| 204 | - $url = $this->getUrl($url); |
|
| 201 | + if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
| 202 | + $url=substr($url, 0, strlen($url)-1); |
|
| 203 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 204 | + $url=$this->getUrl($url); |
|
| 205 | 205 | } |
| 206 | 206 | return $url; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - public static function _correctParams($params, $ajaxParameters = []) { |
|
| 209 | + public static function _correctParams($params, $ajaxParameters=[]) { |
|
| 210 | 210 | if (JString::isNull($params)) { |
| 211 | 211 | return ""; |
| 212 | 212 | } |
| 213 | 213 | if (\preg_match("@^\{.*?\}$@", $params)) { |
| 214 | - if (! isset($ajaxParameters['contentType']) || ! JString::contains($ajaxParameters['contentType'], 'json')) { |
|
| 215 | - return '$.param(' . $params . ')'; |
|
| 214 | + if (!isset($ajaxParameters['contentType']) || !JString::contains($ajaxParameters['contentType'], 'json')) { |
|
| 215 | + return '$.param('.$params.')'; |
|
| 216 | 216 | } else { |
| 217 | - return 'JSON.stringify(' . $params . ')'; |
|
| 217 | + return 'JSON.stringify('.$params.')'; |
|
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | return $params; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | public static function _implodeParams($parameters) { |
| 224 | - $allParameters = []; |
|
| 224 | + $allParameters=[]; |
|
| 225 | 225 | foreach ($parameters as $params) { |
| 226 | 226 | if (isset($params)) |
| 227 | - $allParameters[] = self::_correctParams($params); |
|
| 227 | + $allParameters[]=self::_correctParams($params); |
|
| 228 | 228 | } |
| 229 | 229 | return \implode("+'&'+", $allParameters); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - protected function addLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 233 | - if (! isset($ajaxLoader)) { |
|
| 234 | - $ajaxLoader = $this->ajaxLoader; |
|
| 232 | + protected function addLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 233 | + if (!isset($ajaxLoader)) { |
|
| 234 | + $ajaxLoader=$this->ajaxLoader; |
|
| 235 | 235 | } |
| 236 | - $loading_notifier = '<div class="ajax-loader ui active inverted dimmer">' . $ajaxLoader . '</div>'; |
|
| 237 | - $retour .= "\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
| 236 | + $loading_notifier='<div class="ajax-loader ui active inverted dimmer">'.$ajaxLoader.'</div>'; |
|
| 237 | + $retour.="\t\t{$responseElement}.append('{$loading_notifier}');\n"; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader = null) { |
|
| 241 | - if (! isset($ajaxLoader)) { |
|
| 242 | - $ajaxLoader = $this->ajaxLoader; |
|
| 240 | + protected function addResponseLoading(&$retour, $responseElement, $ajaxLoader=null) { |
|
| 241 | + if (!isset($ajaxLoader)) { |
|
| 242 | + $ajaxLoader=$this->ajaxLoader; |
|
| 243 | 243 | } |
| 244 | - $loading_notifier = '<div class="ajax-loader">' . $ajaxLoader . '</div>'; |
|
| 245 | - $retour .= "{$responseElement}.empty();\n"; |
|
| 246 | - $retour .= "\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 244 | + $loading_notifier='<div class="ajax-loader">'.$ajaxLoader.'</div>'; |
|
| 245 | + $retour.="{$responseElement}.empty();\n"; |
|
| 246 | + $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | protected function setAjaxDataCall($params) { |
| 250 | - $result = null; |
|
| 251 | - if (! \is_callable($params)) { |
|
| 252 | - $result = function ($responseElement, $jqueryDone = 'html') use ($params) { |
|
| 250 | + $result=null; |
|
| 251 | + if (!\is_callable($params)) { |
|
| 252 | + $result=function($responseElement, $jqueryDone='html') use ($params) { |
|
| 253 | 253 | return AjaxTransition::{$params}($responseElement, $jqueryDone); |
| 254 | 254 | }; |
| 255 | 255 | } |
@@ -258,13 +258,13 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | protected function setDefaultParameters(&$parameters, $default) { |
| 260 | 260 | foreach ($default as $k => $v) { |
| 261 | - if (! isset($parameters[$k])) |
|
| 262 | - $parameters[$k] = $v; |
|
| 261 | + if (!isset($parameters[$k])) |
|
| 262 | + $parameters[$k]=$v; |
|
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | public function setAjaxLoader($loader) { |
| 267 | - $this->ajaxLoader = $loader; |
|
| 267 | + $this->ajaxLoader=$loader; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | * @param string $responseElement |
| 276 | 276 | * selector of the HTML element displaying the answer |
| 277 | 277 | */ |
| 278 | - private function _get($url, $responseElement = '', $parameters = []) { |
|
| 278 | + private function _get($url, $responseElement='', $parameters=[]) { |
|
| 279 | 279 | return $this->_ajax('get', $url, $responseElement, $parameters); |
| 280 | 280 | } |
| 281 | 281 | |
@@ -289,8 +289,8 @@ discard block |
||
| 289 | 289 | * @param array $parameters |
| 290 | 290 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 291 | 291 | */ |
| 292 | - public function get($url, $responseElement = '', $parameters = []) { |
|
| 293 | - $parameters['immediatly'] = true; |
|
| 292 | + public function get($url, $responseElement='', $parameters=[]) { |
|
| 293 | + $parameters['immediatly']=true; |
|
| 294 | 294 | return $this->_get($url, $responseElement, $parameters); |
| 295 | 295 | } |
| 296 | 296 | |
@@ -306,8 +306,8 @@ discard block |
||
| 306 | 306 | * @param array $parameters |
| 307 | 307 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 308 | 308 | */ |
| 309 | - public function ajax($method, $url, $responseElement = '', $parameters = []) { |
|
| 310 | - $parameters['immediatly'] = true; |
|
| 309 | + public function ajax($method, $url, $responseElement='', $parameters=[]) { |
|
| 310 | + $parameters['immediatly']=true; |
|
| 311 | 311 | return $this->_ajax($method, $url, $responseElement, $parameters); |
| 312 | 312 | } |
| 313 | 313 | |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * $immediatly |
| 330 | 330 | * @return string |
| 331 | 331 | */ |
| 332 | - public function ajaxInterval($method, $url, $interval, $globalName = null, $responseElement = '', $parameters = [], $immediatly = true) { |
|
| 332 | + public function ajaxInterval($method, $url, $interval, $globalName=null, $responseElement='', $parameters=[], $immediatly=true) { |
|
| 333 | 333 | return $this->interval($this->ajaxDeferred($method, $url, $responseElement, $parameters), $interval, $globalName, $immediatly); |
| 334 | 334 | } |
| 335 | 335 | |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | * @param array $parameters |
| 346 | 346 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 347 | 347 | */ |
| 348 | - public function ajaxDeferred($method, $url, $responseElement = '', $parameters = []) { |
|
| 349 | - $parameters['immediatly'] = false; |
|
| 348 | + public function ajaxDeferred($method, $url, $responseElement='', $parameters=[]) { |
|
| 349 | + $parameters['immediatly']=false; |
|
| 350 | 350 | return $this->_ajax($method, $url, $responseElement, $parameters); |
| 351 | 351 | } |
| 352 | 352 | |
@@ -360,15 +360,15 @@ discard block |
||
| 360 | 360 | * @param array $parameters |
| 361 | 361 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 362 | 362 | */ |
| 363 | - private function _json($url, $method = "get", $parameters = []) { |
|
| 364 | - $parameters = \array_merge($parameters, [ |
|
| 363 | + private function _json($url, $method="get", $parameters=[]) { |
|
| 364 | + $parameters=\array_merge($parameters, [ |
|
| 365 | 365 | "hasLoader" => false |
| 366 | 366 | ]); |
| 367 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 368 | - $context = isset($parameters['context']) ? $parameters['context'] : "document"; |
|
| 369 | - $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"; |
|
| 370 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 371 | - $parameters["jsCallback"] = $retour; |
|
| 367 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 368 | + $context=isset($parameters['context']) ? $parameters['context'] : "document"; |
|
| 369 | + $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"; |
|
| 370 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 371 | + $parameters["jsCallback"]=$retour; |
|
| 372 | 372 | return $this->_ajax($method, $url, null, $parameters); |
| 373 | 373 | } |
| 374 | 374 | |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | * @param array $parameters |
| 383 | 383 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 384 | 384 | */ |
| 385 | - public function json($url, $method = "get", $parameters = []) { |
|
| 385 | + public function json($url, $method="get", $parameters=[]) { |
|
| 386 | 386 | return $this->_json($url, $method, $parameters); |
| 387 | 387 | } |
| 388 | 388 | |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * @param array $parameters |
| 399 | 399 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
| 400 | 400 | */ |
| 401 | - public function jsonOn($event, $element, $url, $method = 'get', $parameters = array()) { |
|
| 401 | + public function jsonOn($event, $element, $url, $method='get', $parameters=array()) { |
|
| 402 | 402 | $this->setDefaultParameters($parameters, [ |
| 403 | 403 | 'preventDefault' => true, |
| 404 | 404 | 'stopPropagation' => true, |
@@ -418,8 +418,8 @@ discard block |
||
| 418 | 418 | * @param array $parameters |
| 419 | 419 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>"document","jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"before"=>null) |
| 420 | 420 | */ |
| 421 | - public function jsonDeferred($url, $method = 'get', $parameters = []) { |
|
| 422 | - $parameters['immediatly'] = false; |
|
| 421 | + public function jsonDeferred($url, $method='get', $parameters=[]) { |
|
| 422 | + $parameters['immediatly']=false; |
|
| 423 | 423 | return $this->_json($url, $method, $parameters); |
| 424 | 424 | } |
| 425 | 425 | |
@@ -434,29 +434,29 @@ 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 | - private function _jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
| 438 | - $parameters = \array_merge($parameters, [ |
|
| 437 | + private function _jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 438 | + $parameters=\array_merge($parameters, [ |
|
| 439 | 439 | "hasLoader" => false |
| 440 | 440 | ]); |
| 441 | - $rowClass = isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
| 442 | - $jsCallback = isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 443 | - $context = isset($parameters['context']) ? $parameters['context'] : null; |
|
| 444 | - if ($context === null) { |
|
| 445 | - $parent = "$('" . $maskSelector . "').parent()"; |
|
| 446 | - $newElm = "$('#'+newId)"; |
|
| 441 | + $rowClass=isset($parameters['rowClass']) ? $parameters['rowClass'] : "_json"; |
|
| 442 | + $jsCallback=isset($parameters['jsCallback']) ? $parameters['jsCallback'] : ""; |
|
| 443 | + $context=isset($parameters['context']) ? $parameters['context'] : null; |
|
| 444 | + if ($context===null) { |
|
| 445 | + $parent="$('".$maskSelector."').parent()"; |
|
| 446 | + $newElm="$('#'+newId)"; |
|
| 447 | 447 | } else { |
| 448 | - $parent = $context; |
|
| 449 | - $newElm = $context . ".find('#'+newId)"; |
|
| 448 | + $parent=$context; |
|
| 449 | + $newElm=$context.".find('#'+newId)"; |
|
| 450 | 450 | } |
| 451 | - $appendTo = "\t\tnewElm.appendTo(" . $parent . ");\n"; |
|
| 452 | - $retour = $parent . ".find('.{$rowClass}').remove();"; |
|
| 453 | - $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(); |
|
| 451 | + $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
|
| 452 | + $retour=$parent.".find('.{$rowClass}').remove();"; |
|
| 453 | + $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(); |
|
| 454 | 454 | 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"; |
| 455 | - $retour .= $appendTo; |
|
| 456 | - $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"; |
|
| 457 | - $retour .= "\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 458 | - $retour .= "\t" . $jsCallback; |
|
| 459 | - $parameters["jsCallback"] = $retour; |
|
| 455 | + $retour.=$appendTo; |
|
| 456 | + $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"; |
|
| 457 | + $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
|
| 458 | + $retour.="\t".$jsCallback; |
|
| 459 | + $parameters["jsCallback"]=$retour; |
|
| 460 | 460 | return $this->_ajax($method, $url, null, $parameters); |
| 461 | 461 | } |
| 462 | 462 | |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | * @param array $parameters |
| 472 | 472 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"immediatly"=>false,"rowClass"=>"_json","before"=>null) |
| 473 | 473 | */ |
| 474 | - public function jsonArray($maskSelector, $url, $method = 'get', $parameters = []) { |
|
| 474 | + public function jsonArray($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 475 | 475 | return $this->_jsonArray($maskSelector, $url, $method, $parameters); |
| 476 | 476 | } |
| 477 | 477 | |
@@ -486,8 +486,8 @@ discard block |
||
| 486 | 486 | * @param array $parameters |
| 487 | 487 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","context"=>null,"jsCondition"=>NULL,"headers"=>null,"rowClass"=>"_json","before"=>null) |
| 488 | 488 | */ |
| 489 | - public function jsonArrayDeferred($maskSelector, $url, $method = 'get', $parameters = []) { |
|
| 490 | - $parameters['immediatly'] = false; |
|
| 489 | + public function jsonArrayDeferred($maskSelector, $url, $method='get', $parameters=[]) { |
|
| 490 | + $parameters['immediatly']=false; |
|
| 491 | 491 | return $this->jsonArray($maskSelector, $url, $method, $parameters); |
| 492 | 492 | } |
| 493 | 493 | |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | * @param array $parameters |
| 504 | 504 | * default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true,"before"=>null,"listenerOn"=>false) |
| 505 | 505 | */ |
| 506 | - public function jsonArrayOn($event, $element, $maskSelector, $url, $method = 'get', $parameters = array()) { |
|
| 506 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $method='get', $parameters=array()) { |
|
| 507 | 507 | $this->setDefaultParameters($parameters, [ |
| 508 | 508 | 'preventDefault' => true, |
| 509 | 509 | 'stopPropagation' => true, |
@@ -524,8 +524,8 @@ discard block |
||
| 524 | 524 | * @param array $parameters |
| 525 | 525 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 526 | 526 | */ |
| 527 | - public function getDeferred($url, $responseElement = "", $parameters = []) { |
|
| 528 | - $parameters['immediatly'] = false; |
|
| 527 | + public function getDeferred($url, $responseElement="", $parameters=[]) { |
|
| 528 | + $parameters['immediatly']=false; |
|
| 529 | 529 | return $this->_get($url, $responseElement, $parameters); |
| 530 | 530 | } |
| 531 | 531 | |
@@ -544,8 +544,8 @@ discard block |
||
| 544 | 544 | * @param array $parameters |
| 545 | 545 | * 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,"listenerOn"=>false) |
| 546 | 546 | */ |
| 547 | - public function getOn($event, $element, $url, $responseElement = "", $parameters = array()) { |
|
| 548 | - $parameters['method'] = 'get'; |
|
| 547 | + public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
|
| 548 | + $parameters['method']='get'; |
|
| 549 | 549 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
| 550 | 550 | } |
| 551 | 551 | |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | * @param array $parameters |
| 565 | 565 | * 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,"listenerOn"=>false) |
| 566 | 566 | */ |
| 567 | - public function ajaxOn($event, $element, $url, $responseElement = '', $parameters = array()) { |
|
| 567 | + public function ajaxOn($event, $element, $url, $responseElement='', $parameters=array()) { |
|
| 568 | 568 | $this->setDefaultParameters($parameters, [ |
| 569 | 569 | 'preventDefault' => true, |
| 570 | 570 | 'stopPropagation' => true, |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | * @param array $parameters |
| 589 | 589 | * 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,"listenerOn"=>false) |
| 590 | 590 | */ |
| 591 | - public function ajaxOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
| 591 | + public function ajaxOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
| 592 | 592 | return $this->ajaxOn('click', $element, $url, $responseElement, $parameters); |
| 593 | 593 | } |
| 594 | 594 | |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | * @param array $parameters |
| 606 | 606 | * 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,"listenerOn"=>false) |
| 607 | 607 | */ |
| 608 | - public function getOnClick($element, $url, $responseElement = '', $parameters = array()) { |
|
| 608 | + public function getOnClick($element, $url, $responseElement='', $parameters=array()) { |
|
| 609 | 609 | return $this->getOn('click', $element, $url, $responseElement, $parameters); |
| 610 | 610 | } |
| 611 | 611 | |
@@ -620,18 +620,18 @@ discard block |
||
| 620 | 620 | * 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,"listenerOn"=>false) |
| 621 | 621 | * @return $this |
| 622 | 622 | */ |
| 623 | - public function getHref($element, $responseElement = "", $parameters = array()) { |
|
| 624 | - $parameters['attr'] = 'href'; |
|
| 623 | + public function getHref($element, $responseElement="", $parameters=array()) { |
|
| 624 | + $parameters['attr']='href'; |
|
| 625 | 625 | if (JString::isNull($responseElement)) { |
| 626 | - $responseElement = '%$(self).attr("data-target")%'; |
|
| 626 | + $responseElement='%$(self).attr("data-target")%'; |
|
| 627 | 627 | } else { |
| 628 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 628 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 629 | 629 | } |
| 630 | - if (! isset($parameters['historize'])) { |
|
| 631 | - $parameters['historize'] = true; |
|
| 630 | + if (!isset($parameters['historize'])) { |
|
| 631 | + $parameters['historize']=true; |
|
| 632 | 632 | } |
| 633 | - if (! isset($parameters['jsCallback'])) { |
|
| 634 | - $parameters['jsCallback'] = 'var event = jQuery.Event( "getHref" );event.url = url;$(self).trigger(event);'; |
|
| 633 | + if (!isset($parameters['jsCallback'])) { |
|
| 634 | + $parameters['jsCallback']='var event = jQuery.Event( "getHref" );event.url = url;$(self).trigger(event);'; |
|
| 635 | 635 | } |
| 636 | 636 | return $this->getOnClick($element, "", $responseElement, $parameters); |
| 637 | 637 | } |
@@ -647,15 +647,15 @@ discard block |
||
| 647 | 647 | * 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,"listenerOn"=>false) |
| 648 | 648 | * @return $this |
| 649 | 649 | */ |
| 650 | - public function postHref($element, $responseElement = "", $parameters = array()) { |
|
| 651 | - $parameters['attr'] = 'href'; |
|
| 650 | + public function postHref($element, $responseElement="", $parameters=array()) { |
|
| 651 | + $parameters['attr']='href'; |
|
| 652 | 652 | if (JString::isNull($responseElement)) { |
| 653 | - $responseElement = '%$(this).attr("data-target")%'; |
|
| 653 | + $responseElement='%$(this).attr("data-target")%'; |
|
| 654 | 654 | } else { |
| 655 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 655 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 656 | 656 | } |
| 657 | - if (! isset($parameters['historize'])) { |
|
| 658 | - $parameters['historize'] = true; |
|
| 657 | + if (!isset($parameters['historize'])) { |
|
| 658 | + $parameters['historize']=true; |
|
| 659 | 659 | } |
| 660 | 660 | return $this->postOnClick($element, '', '{}', $responseElement, $parameters); |
| 661 | 661 | } |
@@ -671,29 +671,29 @@ discard block |
||
| 671 | 671 | * 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,"listenerOn"=>false) |
| 672 | 672 | * @return $this |
| 673 | 673 | */ |
| 674 | - public function postFormAction($element, $responseElement = "", $parameters = array()) { |
|
| 675 | - $parameters['attr'] = 'action'; |
|
| 674 | + public function postFormAction($element, $responseElement="", $parameters=array()) { |
|
| 675 | + $parameters['attr']='action'; |
|
| 676 | 676 | if (JString::isNull($responseElement)) { |
| 677 | - $responseElement = '%$(self).attr("data-target")%'; |
|
| 677 | + $responseElement='%$(self).attr("data-target")%'; |
|
| 678 | 678 | } else { |
| 679 | - $responseElement = '%$(self).attr("data-target") || "' . $responseElement . '"%'; |
|
| 679 | + $responseElement='%$(self).attr("data-target") || "'.$responseElement.'"%'; |
|
| 680 | 680 | } |
| 681 | - $formId = '%$(this).attr("id")%'; |
|
| 682 | - if (! isset($parameters['historize'])) { |
|
| 683 | - $parameters['historize'] = true; |
|
| 681 | + $formId='%$(this).attr("id")%'; |
|
| 682 | + if (!isset($parameters['historize'])) { |
|
| 683 | + $parameters['historize']=true; |
|
| 684 | 684 | } |
| 685 | - $parameters['preventDefault'] = true; |
|
| 686 | - if (! isset($parameters['hasLoader'])) { |
|
| 687 | - $parameters['hasLoader'] = '$(self).find("button, input[type=submit], input[type=button]")'; |
|
| 685 | + $parameters['preventDefault']=true; |
|
| 686 | + if (!isset($parameters['hasLoader'])) { |
|
| 687 | + $parameters['hasLoader']='$(self).find("button, input[type=submit], input[type=button]")'; |
|
| 688 | 688 | } |
| 689 | - if (! isset($parameters['jsCallback'])) { |
|
| 690 | - $parameters['jsCallback'] = 'var event = jQuery.Event( "postFormAction" );event.params = Object.fromEntries(new URLSearchParams(params));$(self).trigger(event);'; |
|
| 689 | + if (!isset($parameters['jsCallback'])) { |
|
| 690 | + $parameters['jsCallback']='var event = jQuery.Event( "postFormAction" );event.params = Object.fromEntries(new URLSearchParams(params));$(self).trigger(event);'; |
|
| 691 | 691 | } |
| 692 | 692 | return $this->postFormOn('submit', $element, '', $formId, $responseElement, $parameters); |
| 693 | 693 | } |
| 694 | 694 | |
| 695 | - private function _post($url, $params = '{}', $responseElement = '', $parameters = []) { |
|
| 696 | - $parameters['params'] = $params; |
|
| 695 | + private function _post($url, $params='{}', $responseElement='', $parameters=[]) { |
|
| 696 | + $parameters['params']=$params; |
|
| 697 | 697 | return $this->_ajax('POST', $url, $responseElement, $parameters); |
| 698 | 698 | } |
| 699 | 699 | |
@@ -709,8 +709,8 @@ discard block |
||
| 709 | 709 | * @param array $parameters |
| 710 | 710 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 711 | 711 | */ |
| 712 | - public function post($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 713 | - $parameters['immediatly'] = true; |
|
| 712 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 713 | + $parameters['immediatly']=true; |
|
| 714 | 714 | return $this->_post($url, $params, $responseElement, $parameters); |
| 715 | 715 | } |
| 716 | 716 | |
@@ -727,8 +727,8 @@ discard block |
||
| 727 | 727 | * @param array $parameters |
| 728 | 728 | * default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 729 | 729 | */ |
| 730 | - public function postDeferred($url, $params = "{}", $responseElement = "", $parameters = []) { |
|
| 731 | - $parameters['immediatly'] = false; |
|
| 730 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 731 | + $parameters['immediatly']=false; |
|
| 732 | 732 | return $this->_post($url, $params, $responseElement, $parameters); |
| 733 | 733 | } |
| 734 | 734 | |
@@ -747,9 +747,9 @@ discard block |
||
| 747 | 747 | * @param array $parameters |
| 748 | 748 | * 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,"listenerOn"=>false) |
| 749 | 749 | */ |
| 750 | - public function postOn($event, $element, $url, $params = "{}", $responseElement = "", $parameters = array()) { |
|
| 751 | - $parameters['method'] = 'post'; |
|
| 752 | - $parameters['params'] = $params; |
|
| 750 | + public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 751 | + $parameters['method']='post'; |
|
| 752 | + $parameters['params']=$params; |
|
| 753 | 753 | return $this->ajaxOn($event, $element, $url, $responseElement, $parameters); |
| 754 | 754 | } |
| 755 | 755 | |
@@ -767,74 +767,74 @@ discard block |
||
| 767 | 767 | * @param array $parameters |
| 768 | 768 | * 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,"listenerOn"=>false) |
| 769 | 769 | */ |
| 770 | - public function postOnClick($element, $url, $params = '{}', $responseElement = '', $parameters = array()) { |
|
| 770 | + public function postOnClick($element, $url, $params='{}', $responseElement='', $parameters=array()) { |
|
| 771 | 771 | return $this->postOn('click', $element, $url, $params, $responseElement, $parameters); |
| 772 | 772 | } |
| 773 | 773 | |
| 774 | - private function _postForm($url, $form, $responseElement, $parameters = []) { |
|
| 774 | + private function _postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 775 | 775 | if (isset($this->params['ajax'])) { |
| 776 | 776 | extract($this->params['ajax']); |
| 777 | 777 | } |
| 778 | - $params = '{}'; |
|
| 779 | - $validation = false; |
|
| 778 | + $params='{}'; |
|
| 779 | + $validation=false; |
|
| 780 | 780 | \extract($parameters); |
| 781 | - $async = ($async) ? 'true' : 'false'; |
|
| 782 | - $jsCallback = isset($jsCallback) ? $jsCallback : ""; |
|
| 783 | - $retour = $this->_getAjaxUrl($url, $attr); |
|
| 784 | - $form = $this->_getFormElement($form); |
|
| 785 | - $retour .= "\n$('#'+" . $form . ").trigger('ajaxSubmit');"; |
|
| 786 | - if (! isset($contentType) || $contentType != 'false') { |
|
| 787 | - $retour .= "\nvar params=$('#'+" . $form . ").serialize();\n"; |
|
| 781 | + $async=($async) ? 'true' : 'false'; |
|
| 782 | + $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
|
| 783 | + $retour=$this->_getAjaxUrl($url, $attr); |
|
| 784 | + $form=$this->_getFormElement($form); |
|
| 785 | + $retour.="\n$('#'+".$form.").trigger('ajaxSubmit');"; |
|
| 786 | + if (!isset($contentType) || $contentType!='false') { |
|
| 787 | + $retour.="\nvar params=$('#'+".$form.").serialize();\n"; |
|
| 788 | 788 | if (isset($params)) { |
| 789 | - $retour .= "params+='&'+" . self::_correctParams($params) . ";\n"; |
|
| 789 | + $retour.="params+='&'+".self::_correctParams($params).";\n"; |
|
| 790 | 790 | } |
| 791 | 791 | } else { |
| 792 | - $retour .= "\nvar params=new FormData($('#'+" . $form . ")[0]);\n"; |
|
| 792 | + $retour.="\nvar params=new FormData($('#'+".$form.")[0]);\n"; |
|
| 793 | 793 | } |
| 794 | - $responseElement = $this->_getResponseElement($responseElement); |
|
| 795 | - $retour .= "var self=this;\n"; |
|
| 796 | - $before = isset($before) ? $before : ""; |
|
| 797 | - $retour .= $before; |
|
| 798 | - if ($hasLoader === true) { |
|
| 794 | + $responseElement=$this->_getResponseElement($responseElement); |
|
| 795 | + $retour.="var self=this;\n"; |
|
| 796 | + $before=isset($before) ? $before : ""; |
|
| 797 | + $retour.=$before; |
|
| 798 | + if ($hasLoader===true) { |
|
| 799 | 799 | $this->addLoading($retour, $responseElement, $ajaxLoader); |
| 800 | - } elseif ($hasLoader === 'response') { |
|
| 800 | + } elseif ($hasLoader==='response') { |
|
| 801 | 801 | $this->addResponseLoading($retour, $responseElement, $ajaxLoader); |
| 802 | - } elseif ($hasLoader === 'internal-x') { |
|
| 802 | + } elseif ($hasLoader==='internal-x') { |
|
| 803 | 803 | $this->addLoading($retour, '$(this).closest(".item, .step")', $ajaxLoader); |
| 804 | - } elseif ($hasLoader === 'internal') { |
|
| 805 | - $retour .= "\n$(this).addClass('loading');"; |
|
| 804 | + } elseif ($hasLoader==='internal') { |
|
| 805 | + $retour.="\n$(this).addClass('loading');"; |
|
| 806 | 806 | } elseif (\is_string($hasLoader)) { |
| 807 | - $retour .= "\n$hasLoader.addClass('loading');"; |
|
| 807 | + $retour.="\n$hasLoader.addClass('loading');"; |
|
| 808 | 808 | } |
| 809 | - $ajaxParameters = [ |
|
| 809 | + $ajaxParameters=[ |
|
| 810 | 810 | "url" => "url", |
| 811 | 811 | "method" => "'POST'", |
| 812 | 812 | "data" => "params", |
| 813 | 813 | "async" => $async |
| 814 | 814 | ]; |
| 815 | 815 | if (isset($headers)) { |
| 816 | - $ajaxParameters["headers"] = $headers; |
|
| 816 | + $ajaxParameters["headers"]=$headers; |
|
| 817 | 817 | } |
| 818 | 818 | if (isset($partial)) { |
| 819 | - $ajaxParameters["xhr"] = "xhrProvider"; |
|
| 820 | - $retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };"; |
|
| 819 | + $ajaxParameters["xhr"]="xhrProvider"; |
|
| 820 | + $retour.="var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;".$partial.";}; };"; |
|
| 821 | 821 | } |
| 822 | 822 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 823 | - $retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n"; |
|
| 824 | - $retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader) . "})"; |
|
| 823 | + $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
|
| 824 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader)."})"; |
|
| 825 | 825 | if (isset($error)) { |
| 826 | - $retour .= '.fail(function( jqXHR, textStatus, errorThrown ){' . $error . '})'; |
|
| 826 | + $retour.='.fail(function( jqXHR, textStatus, errorThrown ){'.$error.'})'; |
|
| 827 | 827 | } |
| 828 | - $retour .= ";\n"; |
|
| 828 | + $retour.=";\n"; |
|
| 829 | 829 | if ($validation) { |
| 830 | - $retour = "$('#'+" . $form . ").validate({submitHandler: function(form) { |
|
| 831 | - " . $retour . " |
|
| 830 | + $retour="$('#'+".$form.").validate({submitHandler: function(form) { |
|
| 831 | + " . $retour." |
|
| 832 | 832 | }});\n"; |
| 833 | - $retour .= "$('#'+" . $form . ").submit();\n"; |
|
| 833 | + $retour.="$('#'+".$form.").submit();\n"; |
|
| 834 | 834 | } |
| 835 | - $retour = $this->_addJsCondition($jsCondition, $retour); |
|
| 835 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 836 | 836 | if ($immediatly) |
| 837 | - $this->jquery_code_for_compile[] = $retour; |
|
| 837 | + $this->jquery_code_for_compile[]=$retour; |
|
| 838 | 838 | return $retour; |
| 839 | 839 | } |
| 840 | 840 | |
@@ -850,8 +850,8 @@ discard block |
||
| 850 | 850 | * @param array $parameters |
| 851 | 851 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 852 | 852 | */ |
| 853 | - public function postForm($url, $form, $responseElement, $parameters = []) { |
|
| 854 | - $parameters['immediatly'] = true; |
|
| 853 | + public function postForm($url, $form, $responseElement, $parameters=[]) { |
|
| 854 | + $parameters['immediatly']=true; |
|
| 855 | 855 | return $this->_postForm($url, $form, $responseElement, $parameters); |
| 856 | 856 | } |
| 857 | 857 | |
@@ -868,8 +868,8 @@ discard block |
||
| 868 | 868 | * @param array $parameters |
| 869 | 869 | * default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"ajaxLoader"=>null,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null,"historize"=>false,"before"=>null) |
| 870 | 870 | */ |
| 871 | - public function postFormDeferred($url, $form, $responseElement, $parameters = []) { |
|
| 872 | - $parameters['immediatly'] = false; |
|
| 871 | + public function postFormDeferred($url, $form, $responseElement, $parameters=[]) { |
|
| 872 | + $parameters['immediatly']=false; |
|
| 873 | 873 | return $this->_postForm($url, $form, $responseElement, $parameters); |
| 874 | 874 | } |
| 875 | 875 | |
@@ -886,7 +886,7 @@ discard block |
||
| 886 | 886 | * @param array $parameters |
| 887 | 887 | * 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,"listenerOn"=>false) |
| 888 | 888 | */ |
| 889 | - public function postFormOn($event, $element, $url, $form, $responseElement = "", $parameters = array()) { |
|
| 889 | + public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 890 | 890 | $this->setDefaultParameters($parameters, [ |
| 891 | 891 | 'preventDefault' => true, |
| 892 | 892 | 'stopPropagation' => true, |
@@ -908,11 +908,11 @@ discard block |
||
| 908 | 908 | * @param array $parameters |
| 909 | 909 | * 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,"listenerOn"=>false) |
| 910 | 910 | */ |
| 911 | - public function postFormOnClick($element, $url, $form, $responseElement = "", $parameters = array()) { |
|
| 911 | + public function postFormOnClick($element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 912 | 912 | return $this->postFormOn("click", $element, $url, $form, $responseElement, $parameters); |
| 913 | 913 | } |
| 914 | 914 | |
| 915 | - public function addCsrf($name = 'csrf-token') { |
|
| 915 | + public function addCsrf($name='csrf-token') { |
|
| 916 | 916 | return " |
| 917 | 917 | $.ajaxSetup({ |
| 918 | 918 | beforeSend: function(xhr, settings) { |
@@ -161,10 +161,11 @@ discard block |
||
| 161 | 161 | } elseif (isset($this->ajaxTransition)) { |
| 162 | 162 | $call = $this->ajaxTransition; |
| 163 | 163 | } |
| 164 | - if (\is_callable($call)) |
|
| 165 | - $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 166 | - else |
|
| 167 | - $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 164 | + if (\is_callable($call)) { |
|
| 165 | + $retour = "\t" . $call($responseElement, $jqueryDone) . ";\n"; |
|
| 166 | + } else { |
|
| 167 | + $retour = "\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 168 | + } |
|
| 168 | 169 | } |
| 169 | 170 | if (isset($history)) { |
| 170 | 171 | if ($this->params["autoActiveLinks"]) { |
@@ -198,8 +199,9 @@ discard block |
||
| 198 | 199 | } |
| 199 | 200 | |
| 200 | 201 | protected function _correctAjaxUrl($url) { |
| 201 | - if ($url !== "/" && JString::endsWith($url, "/") === true) |
|
| 202 | - $url = substr($url, 0, strlen($url) - 1); |
|
| 202 | + if ($url !== "/" && JString::endsWith($url, "/") === true) { |
|
| 203 | + $url = substr($url, 0, strlen($url) - 1); |
|
| 204 | + } |
|
| 203 | 205 | if (strncmp($url, 'http://', 7) != 0 && strncmp($url, 'https://', 8) != 0) { |
| 204 | 206 | $url = $this->getUrl($url); |
| 205 | 207 | } |
@@ -223,8 +225,9 @@ discard block |
||
| 223 | 225 | public static function _implodeParams($parameters) { |
| 224 | 226 | $allParameters = []; |
| 225 | 227 | foreach ($parameters as $params) { |
| 226 | - if (isset($params)) |
|
| 227 | - $allParameters[] = self::_correctParams($params); |
|
| 228 | + if (isset($params)) { |
|
| 229 | + $allParameters[] = self::_correctParams($params); |
|
| 230 | + } |
|
| 228 | 231 | } |
| 229 | 232 | return \implode("+'&'+", $allParameters); |
| 230 | 233 | } |
@@ -258,8 +261,9 @@ discard block |
||
| 258 | 261 | |
| 259 | 262 | protected function setDefaultParameters(&$parameters, $default) { |
| 260 | 263 | foreach ($default as $k => $v) { |
| 261 | - if (! isset($parameters[$k])) |
|
| 262 | - $parameters[$k] = $v; |
|
| 264 | + if (! isset($parameters[$k])) { |
|
| 265 | + $parameters[$k] = $v; |
|
| 266 | + } |
|
| 263 | 267 | } |
| 264 | 268 | } |
| 265 | 269 | |
@@ -833,8 +837,9 @@ discard block |
||
| 833 | 837 | $retour .= "$('#'+" . $form . ").submit();\n"; |
| 834 | 838 | } |
| 835 | 839 | $retour = $this->_addJsCondition($jsCondition, $retour); |
| 836 | - if ($immediatly) |
|
| 837 | - $this->jquery_code_for_compile[] = $retour; |
|
| 840 | + if ($immediatly) { |
|
| 841 | + $this->jquery_code_for_compile[] = $retour; |
|
| 842 | + } |
|
| 838 | 843 | return $retour; |
| 839 | 844 | } |
| 840 | 845 | |