@@ -6,8 +6,8 @@ discard block |
||
| 6 | 6 | public static $preventDefault="\nif(event && event.preventDefault) event.preventDefault();\n"; |
| 7 | 7 | public static $stopPropagation="\nif(event && event.stopPropagation) event.stopPropagation();\n"; |
| 8 | 8 | |
| 9 | - public static function containsCode($expression){ |
|
| 10 | - return strrpos($expression, 'this')!==false||strrpos($expression, 'event')!==false||strrpos($expression, 'self')!==false; |
|
| 9 | + public static function containsCode($expression) { |
|
| 10 | + return strrpos($expression, 'this')!==false || strrpos($expression, 'event')!==false || strrpos($expression, 'self')!==false; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | return $value; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public static function prep_jquery_selector($value){ |
|
| 47 | - if(JString::startswith($value, '$(')===false){ |
|
| 46 | + public static function prep_jquery_selector($value) { |
|
| 47 | + if (JString::startswith($value, '$(')===false) { |
|
| 48 | 48 | return '$('.$value.')'; |
| 49 | 49 | } |
| 50 | 50 | return $value; |
@@ -3,26 +3,26 @@ |
||
| 3 | 3 | use Ajax\semantic\html\base\constants\Transition; |
| 4 | 4 | |
| 5 | 5 | class AjaxTransition { |
| 6 | - public static function none($responseElement,$jqueryDone="html"){ |
|
| 6 | + public static function none($responseElement, $jqueryDone="html") { |
|
| 7 | 7 | return $responseElement.".".$jqueryDone."( data )"; |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | - public static function jqFade($responseElement,$jqueryDone="html"){ |
|
| 10 | + public static function jqFade($responseElement, $jqueryDone="html") { |
|
| 11 | 11 | return $responseElement.".hide().{$jqueryDone}( data ).fadeIn()"; |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | - public static function jqSlide($responseElement,$jqueryDone="html"){ |
|
| 14 | + public static function jqSlide($responseElement, $jqueryDone="html") { |
|
| 15 | 15 | return $responseElement.".hide().{$jqueryDone}( data ).slideDown()"; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public static function random($responseElement,$jqueryDone="html"){ |
|
| 18 | + public static function random($responseElement, $jqueryDone="html") { |
|
| 19 | 19 | $transitions=Transition::getConstantValues(); |
| 20 | - $transition=$transitions[\rand(0,\sizeof($transitions)-1)]; |
|
| 21 | - return self::__callStatic($transition, [$responseElement,$jqueryDone]); |
|
| 20 | + $transition=$transitions[\rand(0, \sizeof($transitions)-1)]; |
|
| 21 | + return self::__callStatic($transition, [$responseElement, $jqueryDone]); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public static function __callStatic($name, $arguments){ |
|
| 25 | - if(\sizeof($arguments)==2){ |
|
| 24 | + public static function __callStatic($name, $arguments) { |
|
| 25 | + if (\sizeof($arguments)==2) { |
|
| 26 | 26 | $responseElement=$arguments[0]; |
| 27 | 27 | $jqueryDone=$arguments[1]; |
| 28 | 28 | $name=JString::camelCaseToSeparated($name); |
@@ -16,9 +16,9 @@ discard block |
||
| 16 | 16 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
| 17 | 17 | |
| 18 | 18 | abstract public function getUrl($url); |
| 19 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
| 19 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
| 20 | 20 | |
| 21 | - protected function _ajax($method,$url,$responseElement="",$parameters=[]) { |
|
| 21 | + protected function _ajax($method, $url, $responseElement="", $parameters=[]) { |
|
| 22 | 22 | $jsCallback=null; |
| 23 | 23 | $attr="id"; |
| 24 | 24 | $hasLoader=true; |
@@ -34,78 +34,78 @@ discard block |
||
| 34 | 34 | $retour=$this->_getAjaxUrl($url, $attr); |
| 35 | 35 | $responseElement=$this->_getResponseElement($responseElement); |
| 36 | 36 | $retour.="var self=this;\n"; |
| 37 | - if($hasLoader===true && JString::isNotNull($responseElement)){ |
|
| 37 | + if ($hasLoader===true && JString::isNotNull($responseElement)) { |
|
| 38 | 38 | $this->addLoading($retour, $responseElement); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - $ajaxParameters=["url"=>"url","method"=>"'".\strtoupper($method)."'"]; |
|
| 42 | - if(isset($params)){ |
|
| 41 | + $ajaxParameters=["url"=>"url", "method"=>"'".\strtoupper($method)."'"]; |
|
| 42 | + if (isset($params)) { |
|
| 43 | 43 | $ajaxParameters["data"]=self::_correctParams($params); |
| 44 | 44 | } |
| 45 | - if(isset($headers)){ |
|
| 45 | + if (isset($headers)) { |
|
| 46 | 46 | $ajaxParameters["headers"]=$headers; |
| 47 | 47 | } |
| 48 | 48 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 49 | 49 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
| 50 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
| 51 | - $retour=$this->_addJsCondition($jsCondition,$retour); |
|
| 50 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
| 51 | + $retour=$this->_addJsCondition($jsCondition, $retour); |
|
| 52 | 52 | if ($immediatly) |
| 53 | 53 | $this->jquery_code_for_compile[]=$retour; |
| 54 | 54 | return $retour; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - protected function createAjaxParameters(&$original,$parameters){ |
|
| 58 | - $validParameters=["dataType"=>"'%value%'","beforeSend"=>"function(jqXHR,settings){%value%}","complete"=>"function(jqXHR){%value%}"]; |
|
| 59 | - foreach ($validParameters as $param=>$mask){ |
|
| 60 | - if(isset($parameters[$param])){ |
|
| 57 | + protected function createAjaxParameters(&$original, $parameters) { |
|
| 58 | + $validParameters=["dataType"=>"'%value%'", "beforeSend"=>"function(jqXHR,settings){%value%}", "complete"=>"function(jqXHR){%value%}"]; |
|
| 59 | + foreach ($validParameters as $param=>$mask) { |
|
| 60 | + if (isset($parameters[$param])) { |
|
| 61 | 61 | $original[$param]=\str_replace("%value%", $parameters[$param], $mask); |
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - protected function implodeAjaxParameters($ajaxParameters){ |
|
| 67 | - $s = ''; foreach ($ajaxParameters as $k=>$v) { if ($s !== '') { $s .= ','; } $s .= "'{$k}':{$v}"; } |
|
| 66 | + protected function implodeAjaxParameters($ajaxParameters) { |
|
| 67 | + $s=''; foreach ($ajaxParameters as $k=>$v) { if ($s!=='') { $s.=','; } $s.="'{$k}':{$v}"; } |
|
| 68 | 68 | return $s; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - protected function _addJsCondition($jsCondition,$jsSource){ |
|
| 72 | - if(isset($jsCondition)){ |
|
| 71 | + protected function _addJsCondition($jsCondition, $jsSource) { |
|
| 72 | + if (isset($jsCondition)) { |
|
| 73 | 73 | return "if(".$jsCondition."){\n".$jsSource."\n}"; |
| 74 | 74 | } |
| 75 | 75 | return $jsSource; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | |
| 79 | - protected function _getAjaxUrl($url,$attr){ |
|
| 79 | + protected function _getAjaxUrl($url, $attr) { |
|
| 80 | 80 | $url=$this->_correctAjaxUrl($url); |
| 81 | 81 | $retour="url='".$url."';"; |
| 82 | 82 | $slash="/"; |
| 83 | - if(JString::endswith($url, "/")===true){ |
|
| 83 | + if (JString::endswith($url, "/")===true) { |
|
| 84 | 84 | $slash=""; |
| 85 | 85 | } |
| 86 | - if(JString::isNotNull($attr)){ |
|
| 87 | - if ($attr==="value"){ |
|
| 86 | + if (JString::isNotNull($attr)) { |
|
| 87 | + if ($attr==="value") { |
|
| 88 | 88 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
| 89 | - }elseif ($attr==="html"){ |
|
| 89 | + }elseif ($attr==="html") { |
|
| 90 | 90 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
| 91 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
| 91 | + }elseif (\substr($attr, 0, 3)==="js:") { |
|
| 92 | 92 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
| 93 | - }elseif($attr!==null && $attr!=="") |
|
| 93 | + }elseif ($attr!==null && $attr!=="") |
|
| 94 | 94 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
| 95 | 95 | } |
| 96 | 96 | return $retour; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback){ |
|
| 100 | - $retour="";$call=null; |
|
| 99 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) { |
|
| 100 | + $retour=""; $call=null; |
|
| 101 | 101 | if ($responseElement!=="") { |
| 102 | - if(isset($ajaxTransition)){ |
|
| 102 | + if (isset($ajaxTransition)) { |
|
| 103 | 103 | $call=$this->setAjaxDataCall($ajaxTransition); |
| 104 | - }elseif(isset($this->ajaxTransition)){ |
|
| 104 | + }elseif (isset($this->ajaxTransition)) { |
|
| 105 | 105 | $call=$this->ajaxTransition; |
| 106 | 106 | } |
| 107 | - if(\is_callable($call)) |
|
| 108 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
| 107 | + if (\is_callable($call)) |
|
| 108 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 109 | 109 | else |
| 110 | 110 | $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
| 111 | 111 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | return $retour; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - protected function _getResponseElement($responseElement){ |
|
| 116 | + protected function _getResponseElement($responseElement) { |
|
| 117 | 117 | if ($responseElement!=="") { |
| 118 | 118 | $responseElement=Javascript::prep_value($responseElement); |
| 119 | 119 | $responseElement=Javascript::prep_jquery_selector($responseElement); |
@@ -124,26 +124,26 @@ discard block |
||
| 124 | 124 | protected function _correctAjaxUrl($url) { |
| 125 | 125 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
| 126 | 126 | $url=substr($url, 0, strlen($url)-1); |
| 127 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
| 127 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 128 | 128 | $url=$this->getUrl($url); |
| 129 | 129 | } |
| 130 | 130 | return $url; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - public static function _correctParams($params){ |
|
| 134 | - if(JString::isNull($params)){ |
|
| 133 | + public static function _correctParams($params) { |
|
| 134 | + if (JString::isNull($params)) { |
|
| 135 | 135 | return ""; |
| 136 | 136 | } |
| 137 | - if(\preg_match("@^\{.*?\}$@", $params)){ |
|
| 137 | + if (\preg_match("@^\{.*?\}$@", $params)) { |
|
| 138 | 138 | return '$.param('.$params.')'; |
| 139 | 139 | } |
| 140 | 140 | return $params; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - public static function _implodeParams($parameters){ |
|
| 143 | + public static function _implodeParams($parameters) { |
|
| 144 | 144 | $allParameters=[]; |
| 145 | - foreach ($parameters as $params){ |
|
| 146 | - if(isset($params)) |
|
| 145 | + foreach ($parameters as $params) { |
|
| 146 | + if (isset($params)) |
|
| 147 | 147 | $allParameters[]=self::_correctParams($params); |
| 148 | 148 | } |
| 149 | 149 | return \implode("+'&'+", $allParameters); |
@@ -161,19 +161,19 @@ discard block |
||
| 161 | 161 | $retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n"; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - protected function setAjaxDataCall($params){ |
|
| 164 | + protected function setAjaxDataCall($params) { |
|
| 165 | 165 | $result=null; |
| 166 | - if(!\is_callable($params)){ |
|
| 167 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
| 168 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
| 166 | + if (!\is_callable($params)) { |
|
| 167 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
| 168 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
| 169 | 169 | }; |
| 170 | 170 | } |
| 171 | 171 | return $result; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - protected function setDefaultParameters(&$parameters,$default){ |
|
| 175 | - foreach ($default as $k=>$v){ |
|
| 176 | - if(!isset($parameters[$k])) |
|
| 174 | + protected function setDefaultParameters(&$parameters, $default) { |
|
| 175 | + foreach ($default as $k=>$v) { |
|
| 176 | + if (!isset($parameters[$k])) |
|
| 177 | 177 | $parameters[$k]=$v; |
| 178 | 178 | } |
| 179 | 179 | } |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | * @param string $url The url of the request |
| 188 | 188 | * @param string $responseElement selector of the HTML element displaying the answer |
| 189 | 189 | */ |
| 190 | - private function _get($url, $responseElement="",$parameters=[]) { |
|
| 191 | - return $this->_ajax("get", $url,$responseElement,$parameters); |
|
| 190 | + private function _get($url, $responseElement="", $parameters=[]) { |
|
| 191 | + return $this->_ajax("get", $url, $responseElement, $parameters); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -197,9 +197,9 @@ discard block |
||
| 197 | 197 | * @param string $responseElement selector of the HTML element displaying the answer |
| 198 | 198 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
| 199 | 199 | */ |
| 200 | - public function get($url, $responseElement="",$parameters=[]) { |
|
| 200 | + public function get($url, $responseElement="", $parameters=[]) { |
|
| 201 | 201 | $parameters["immediatly"]=true; |
| 202 | - return $this->_get($url,$responseElement,$parameters); |
|
| 202 | + return $this->_get($url, $responseElement, $parameters); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -209,9 +209,9 @@ discard block |
||
| 209 | 209 | * @param string $responseElement selector of the HTML element displaying the answer |
| 210 | 210 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
| 211 | 211 | */ |
| 212 | - public function ajax($method,$url, $responseElement="", $parameters=[]) { |
|
| 212 | + public function ajax($method, $url, $responseElement="", $parameters=[]) { |
|
| 213 | 213 | $parameters["immediatly"]=true; |
| 214 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
| 214 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -221,9 +221,9 @@ discard block |
||
| 221 | 221 | * @param string $responseElement selector of the HTML element displaying the answer |
| 222 | 222 | * @param array $parameters default : array("params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
| 223 | 223 | */ |
| 224 | - public function ajaxDeferred($method,$url, $responseElement="", $parameters=[]) { |
|
| 224 | + public function ajaxDeferred($method, $url, $responseElement="", $parameters=[]) { |
|
| 225 | 225 | $parameters["immediatly"]=false; |
| 226 | - return $this->_ajax($method,$url,$responseElement,$parameters); |
|
| 226 | + return $this->_ajax($method, $url, $responseElement, $parameters); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * @param string $context |
| 237 | 237 | * @param boolean $immediatly |
| 238 | 238 | */ |
| 239 | - private function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
| 239 | + private function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
| 240 | 240 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 241 | 241 | $retour=$this->_getAjaxUrl($url, $attr); |
| 242 | 242 | $retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
@@ -259,8 +259,8 @@ discard block |
||
| 259 | 259 | * @param string $context |
| 260 | 260 | * @param boolean $immediatly |
| 261 | 261 | */ |
| 262 | - public function json($url, $method="get", $params="{}", $jsCallback=NULL,$context="document",$immediatly=false) { |
|
| 263 | - return $this->_json($url,$method,$params,$jsCallback,NULL,$context,$immediatly); |
|
| 262 | + public function json($url, $method="get", $params="{}", $jsCallback=NULL, $context="document", $immediatly=false) { |
|
| 263 | + return $this->_json($url, $method, $params, $jsCallback, NULL, $context, $immediatly); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @param string $url the request address |
| 271 | 271 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
| 272 | 272 | */ |
| 273 | - public function jsonOn($event,$element, $url,$parameters=array()) { |
|
| 273 | + public function jsonOn($event, $element, $url, $parameters=array()) { |
|
| 274 | 274 | $preventDefault=true; |
| 275 | 275 | $stopPropagation=true; |
| 276 | 276 | $jsCallback=null; |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | $params="{}"; |
| 281 | 281 | $immediatly=true; |
| 282 | 282 | extract($parameters); |
| 283 | - return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 283 | + return $this->_add_event($element, $this->_json($url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -291,8 +291,8 @@ discard block |
||
| 291 | 291 | * @param string $jsCallback javascript code to execute after the request |
| 292 | 292 | * @param string $context jquery DOM element, array container. |
| 293 | 293 | */ |
| 294 | - public function jsonDeferred($url, $method="get", $params="{}", $jsCallback=NULL,$context=NULL) { |
|
| 295 | - return $this->json($url, $method, $params, $jsCallback, $context,false); |
|
| 294 | + public function jsonDeferred($url, $method="get", $params="{}", $jsCallback=NULL, $context=NULL) { |
|
| 295 | + return $this->json($url, $method, $params, $jsCallback, $context, false); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -305,22 +305,22 @@ discard block |
||
| 305 | 305 | * @param string $rowClass the css class for the new element |
| 306 | 306 | * @param boolean $immediatly |
| 307 | 307 | */ |
| 308 | - private function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL,$attr="id",$immediatly=false) { |
|
| 308 | + private function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL, $attr="id", $immediatly=false) { |
|
| 309 | 309 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 310 | 310 | $retour=$this->_getAjaxUrl($url, $attr); |
| 311 | - if($context===null){ |
|
| 311 | + if ($context===null) { |
|
| 312 | 312 | $parent="$('".$maskSelector."').parent()"; |
| 313 | - $newElm = "$('#'+newId)"; |
|
| 314 | - }else{ |
|
| 313 | + $newElm="$('#'+newId)"; |
|
| 314 | + } else { |
|
| 315 | 315 | $parent=$context; |
| 316 | - $newElm = $context.".find('#'+newId)"; |
|
| 316 | + $newElm=$context.".find('#'+newId)"; |
|
| 317 | 317 | } |
| 318 | 318 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
| 319 | 319 | $retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
| 320 | 320 | $retour.=$parent.".find('._json').remove();"; |
| 321 | 321 | $retour.="\tdata=$.parseJSON(data);$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone(); |
| 322 | 322 | 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"; |
| 323 | - $retour.= $appendTo; |
|
| 323 | + $retour.=$appendTo; |
|
| 324 | 324 | $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"; |
| 325 | 325 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
| 326 | 326 | $retour.="\t".$jsCallback."\n"."});\n"; |
@@ -339,8 +339,8 @@ discard block |
||
| 339 | 339 | * @param string $context jquery DOM element, array container. |
| 340 | 340 | * @param boolean $immediatly |
| 341 | 341 | */ |
| 342 | - public function jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL,$immediatly=false) { |
|
| 343 | - return $this->_jsonArray($maskSelector, $url,$method,$params,$jsCallback,$rowClass,$context,NULL,$immediatly); |
|
| 342 | + public function jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL, $immediatly=false) { |
|
| 343 | + return $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, NULL, $immediatly); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | /** |
@@ -353,8 +353,8 @@ discard block |
||
| 353 | 353 | * @param string $rowClass the css class for the new element |
| 354 | 354 | * @param string $context jquery DOM element, array container. |
| 355 | 355 | */ |
| 356 | - public function jsonArrayDeferred($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL) { |
|
| 357 | - return $this->jsonArray($maskSelector, $url, $method, $params, $jsCallback,$rowClass,$context,false); |
|
| 356 | + public function jsonArrayDeferred($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL) { |
|
| 357 | + return $this->jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, false); |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -364,18 +364,18 @@ discard block |
||
| 364 | 364 | * @param string $url the request url |
| 365 | 365 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
| 366 | 366 | */ |
| 367 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$parameters=array()) { |
|
| 367 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
| 368 | 368 | $preventDefault=true; |
| 369 | 369 | $stopPropagation=true; |
| 370 | 370 | $jsCallback=null; |
| 371 | 371 | $attr="id"; |
| 372 | 372 | $method="get"; |
| 373 | - $context = null; |
|
| 373 | + $context=null; |
|
| 374 | 374 | $params="{}"; |
| 375 | 375 | $immediatly=true; |
| 376 | 376 | $rowClass="_json"; |
| 377 | 377 | extract($parameters); |
| 378 | - return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $rowClass, $context,$attr), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 378 | + return $this->_add_event($element, $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, $attr), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | */ |
| 388 | 388 | public function getDeferred($url, $responseElement="", $parameters=[]) { |
| 389 | 389 | $parameters["immediatly"]=false; |
| 390 | - return $this->_get($url, $responseElement,$parameters); |
|
| 390 | + return $this->_get($url, $responseElement, $parameters); |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | /** |
@@ -400,8 +400,8 @@ discard block |
||
| 400 | 400 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null) |
| 401 | 401 | */ |
| 402 | 402 | public function getOn($event, $element, $url, $responseElement="", $parameters=array()) { |
| 403 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 404 | - return $this->_add_event($element, $this->getDeferred($url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 403 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 404 | + return $this->_add_event($element, $this->getDeferred($url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | /** |
@@ -414,8 +414,8 @@ discard block |
||
| 414 | 414 | * @param array $parameters default : array("method"=>"get","preventDefault"=>true,"stopPropagation"=>true,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","jsCondition"=>NULL,"headers"=>null) |
| 415 | 415 | */ |
| 416 | 416 | public function ajaxOn($event, $element, $url, $responseElement="", $parameters=array()) { |
| 417 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true,"method"=>"get"]); |
|
| 418 | - return $this->_add_event($element, $this->ajaxDeferred($parameters["method"],$url,$responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 417 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true, "method"=>"get"]); |
|
| 418 | + return $this->_add_event($element, $this->ajaxDeferred($parameters["method"], $url, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | /** |
@@ -442,9 +442,9 @@ discard block |
||
| 442 | 442 | return $this->getOn("click", $element, $url, $responseElement, $parameters); |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - private function _post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
| 445 | + private function _post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 446 | 446 | $parameters["params"]=$params; |
| 447 | - return $this->_ajax("POST", $url,$responseElement,$parameters); |
|
| 447 | + return $this->_ajax("POST", $url, $responseElement, $parameters); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | /** |
@@ -454,8 +454,8 @@ discard block |
||
| 454 | 454 | * @param string $params JSON parameters |
| 455 | 455 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
| 456 | 456 | */ |
| 457 | - public function post($url, $params="{}",$responseElement="", $parameters=[]) { |
|
| 458 | - return $this->_post($url, $params,$responseElement, $parameters); |
|
| 457 | + public function post($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 458 | + return $this->_post($url, $params, $responseElement, $parameters); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | * @param string $responseElement selector of the HTML element displaying the answer |
| 467 | 467 | * @param array $parameters default : array("jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
| 468 | 468 | */ |
| 469 | - public function postDeferred($url, $params="{}",$responseElement="", $parameters=[]) { |
|
| 469 | + public function postDeferred($url, $params="{}", $responseElement="", $parameters=[]) { |
|
| 470 | 470 | $parameters["immediatly"]=false; |
| 471 | 471 | return $this->_post($url, $params, $responseElement, $parameters); |
| 472 | 472 | } |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>NULL,"headers"=>null) |
| 483 | 483 | */ |
| 484 | 484 | public function postOn($event, $element, $url, $params="{}", $responseElement="", $parameters=array()) { |
| 485 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 486 | - return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 485 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 486 | + return $this->_add_event($element, $this->postDeferred($url, $params, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -500,26 +500,26 @@ discard block |
||
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | private function _postForm($url, $form, $responseElement, $parameters=[]) { |
| 503 | - $params="{}";$validation=false;$jsCallback=NULL;$attr="id";$hasLoader=true;$jqueryDone="html";$ajaxTransition=null;$immediatly=false;$jsCondition=NULL;$headers=NULL; |
|
| 503 | + $params="{}"; $validation=false; $jsCallback=NULL; $attr="id"; $hasLoader=true; $jqueryDone="html"; $ajaxTransition=null; $immediatly=false; $jsCondition=NULL; $headers=NULL; |
|
| 504 | 504 | \extract($parameters); |
| 505 | 505 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 506 | 506 | $retour=$this->_getAjaxUrl($url, $attr); |
| 507 | 507 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
| 508 | - if(isset($params)){ |
|
| 508 | + if (isset($params)) { |
|
| 509 | 509 | $retour.="params+='&'+".self::_correctParams($params).";\n"; |
| 510 | 510 | } |
| 511 | 511 | $responseElement=$this->_getResponseElement($responseElement); |
| 512 | 512 | $retour.="var self=this;\n"; |
| 513 | - if($hasLoader===true){ |
|
| 513 | + if ($hasLoader===true) { |
|
| 514 | 514 | $this->addLoading($retour, $responseElement); |
| 515 | 515 | } |
| 516 | - $ajaxParameters=["url"=>"url","method"=>"'POST'","data"=>"params"]; |
|
| 517 | - if(isset($headers)){ |
|
| 516 | + $ajaxParameters=["url"=>"url", "method"=>"'POST'", "data"=>"params"]; |
|
| 517 | + if (isset($headers)) { |
|
| 518 | 518 | $ajaxParameters["headers"]=$headers; |
| 519 | 519 | } |
| 520 | 520 | $this->createAjaxParameters($ajaxParameters, $parameters); |
| 521 | 521 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data ) {\n"; |
| 522 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
| 522 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
| 523 | 523 | |
| 524 | 524 | if ($validation) { |
| 525 | 525 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -569,8 +569,8 @@ discard block |
||
| 569 | 569 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"params"=>"{}","jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true,"jqueryDone"=>"html","ajaxTransition"=>null,"jsCondition"=>null,"headers"=>null) |
| 570 | 570 | */ |
| 571 | 571 | public function postFormOn($event, $element, $url, $form, $responseElement="", $parameters=array()) { |
| 572 | - $this->setDefaultParameters($parameters, ["preventDefault"=>true,"stopPropagation"=>true,"immediatly"=>true]); |
|
| 573 | - return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement,$parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"],$parameters["immediatly"]); |
|
| 572 | + $this->setDefaultParameters($parameters, ["preventDefault"=>true, "stopPropagation"=>true, "immediatly"=>true]); |
|
| 573 | + return $this->_add_event($element, $this->postFormDeferred($url, $form, $responseElement, $parameters), $event, $parameters["preventDefault"], $parameters["stopPropagation"], $parameters["immediatly"]); |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -49,8 +49,9 @@ discard block |
||
| 49 | 49 | $retour.="$.ajax({".$this->implodeAjaxParameters($ajaxParameters)."}).done(function( data, textStatus, jqXHR ) {\n"; |
| 50 | 50 | $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
| 51 | 51 | $retour=$this->_addJsCondition($jsCondition,$retour); |
| 52 | - if ($immediatly) |
|
| 53 | - $this->jquery_code_for_compile[]=$retour; |
|
| 52 | + if ($immediatly) { |
|
| 53 | + $this->jquery_code_for_compile[]=$retour; |
|
| 54 | + } |
|
| 54 | 55 | return $retour; |
| 55 | 56 | } |
| 56 | 57 | |
@@ -86,12 +87,13 @@ discard block |
||
| 86 | 87 | if(JString::isNotNull($attr)){ |
| 87 | 88 | if ($attr==="value"){ |
| 88 | 89 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
| 89 | - }elseif ($attr==="html"){ |
|
| 90 | + } elseif ($attr==="html"){ |
|
| 90 | 91 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
| 91 | - }elseif(\substr($attr, 0,3)==="js:"){ |
|
| 92 | + } elseif(\substr($attr, 0,3)==="js:"){ |
|
| 92 | 93 | $retour.="url=url+'".$slash."'+".\substr($attr, 3).";\n"; |
| 93 | - }elseif($attr!==null && $attr!=="") |
|
| 94 | - $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
| 94 | + } elseif($attr!==null && $attr!=="") { |
|
| 95 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
| 96 | + } |
|
| 95 | 97 | } |
| 96 | 98 | return $retour; |
| 97 | 99 | } |
@@ -101,13 +103,14 @@ discard block |
||
| 101 | 103 | if ($responseElement!=="") { |
| 102 | 104 | if(isset($ajaxTransition)){ |
| 103 | 105 | $call=$this->setAjaxDataCall($ajaxTransition); |
| 104 | - }elseif(isset($this->ajaxTransition)){ |
|
| 106 | + } elseif(isset($this->ajaxTransition)){ |
|
| 105 | 107 | $call=$this->ajaxTransition; |
| 106 | 108 | } |
| 107 | - if(\is_callable($call)) |
|
| 108 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
| 109 | - else |
|
| 110 | - $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 109 | + if(\is_callable($call)) { |
|
| 110 | + $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
| 111 | + } else { |
|
| 112 | + $retour="\t{$responseElement}.{$jqueryDone}( data );\n"; |
|
| 113 | + } |
|
| 111 | 114 | } |
| 112 | 115 | $retour.="\t".$jsCallback."\n"; |
| 113 | 116 | return $retour; |
@@ -122,8 +125,9 @@ discard block |
||
| 122 | 125 | } |
| 123 | 126 | |
| 124 | 127 | protected function _correctAjaxUrl($url) { |
| 125 | - if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
| 126 | - $url=substr($url, 0, strlen($url)-1); |
|
| 128 | + if ($url!=="/" && JString::endsWith($url, "/")===true) { |
|
| 129 | + $url=substr($url, 0, strlen($url)-1); |
|
| 130 | + } |
|
| 127 | 131 | if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
| 128 | 132 | $url=$this->getUrl($url); |
| 129 | 133 | } |
@@ -143,8 +147,9 @@ discard block |
||
| 143 | 147 | public static function _implodeParams($parameters){ |
| 144 | 148 | $allParameters=[]; |
| 145 | 149 | foreach ($parameters as $params){ |
| 146 | - if(isset($params)) |
|
| 147 | - $allParameters[]=self::_correctParams($params); |
|
| 150 | + if(isset($params)) { |
|
| 151 | + $allParameters[]=self::_correctParams($params); |
|
| 152 | + } |
|
| 148 | 153 | } |
| 149 | 154 | return \implode("+'&'+", $allParameters); |
| 150 | 155 | } |
@@ -173,8 +178,9 @@ discard block |
||
| 173 | 178 | |
| 174 | 179 | protected function setDefaultParameters(&$parameters,$default){ |
| 175 | 180 | foreach ($default as $k=>$v){ |
| 176 | - if(!isset($parameters[$k])) |
|
| 177 | - $parameters[$k]=$v; |
|
| 181 | + if(!isset($parameters[$k])) { |
|
| 182 | + $parameters[$k]=$v; |
|
| 183 | + } |
|
| 178 | 184 | } |
| 179 | 185 | } |
| 180 | 186 | |
@@ -245,8 +251,9 @@ discard block |
||
| 245 | 251 | $retour.="\t".$jsCallback."\n". |
| 246 | 252 | "\t$(document).trigger('jsonReady',[data]);\n". |
| 247 | 253 | "});\n"; |
| 248 | - if ($immediatly) |
|
| 249 | - $this->jquery_code_for_compile[]=$retour; |
|
| 254 | + if ($immediatly) { |
|
| 255 | + $this->jquery_code_for_compile[]=$retour; |
|
| 256 | + } |
|
| 250 | 257 | return $retour; |
| 251 | 258 | } |
| 252 | 259 | |
@@ -311,7 +318,7 @@ discard block |
||
| 311 | 318 | if($context===null){ |
| 312 | 319 | $parent="$('".$maskSelector."').parent()"; |
| 313 | 320 | $newElm = "$('#'+newId)"; |
| 314 | - }else{ |
|
| 321 | + } else{ |
|
| 315 | 322 | $parent=$context; |
| 316 | 323 | $newElm = $context.".find('#'+newId)"; |
| 317 | 324 | } |
@@ -324,8 +331,9 @@ discard block |
||
| 324 | 331 | $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"; |
| 325 | 332 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
| 326 | 333 | $retour.="\t".$jsCallback."\n"."});\n"; |
| 327 | - if ($immediatly) |
|
| 328 | - $this->jquery_code_for_compile[]=$retour; |
|
| 334 | + if ($immediatly) { |
|
| 335 | + $this->jquery_code_for_compile[]=$retour; |
|
| 336 | + } |
|
| 329 | 337 | return $retour; |
| 330 | 338 | } |
| 331 | 339 | |
@@ -528,8 +536,9 @@ discard block |
||
| 528 | 536 | $retour.="$('#".$form."').submit();\n"; |
| 529 | 537 | } |
| 530 | 538 | $retour=$this->_addJsCondition($jsCondition, $retour); |
| 531 | - if ($immediatly) |
|
| 532 | - $this->jquery_code_for_compile[]=$retour; |
|
| 539 | + if ($immediatly) { |
|
| 540 | + $this->jquery_code_for_compile[]=$retour; |
|
| 541 | + } |
|
| 533 | 542 | return $retour; |
| 534 | 543 | } |
| 535 | 544 | |