@@ -3,8 +3,6 @@ |
||
| 3 | 3 | namespace Ajax\common\traits; |
| 4 | 4 | |
| 5 | 5 | use Ajax\service\JString; |
| 6 | -use Ajax\service\PhalconUtils; |
|
| 7 | -use Symfony\Component\Config\Definition\Exception\Exception; |
|
| 8 | 6 | trait JqueryAjaxTrait { |
| 9 | 7 | |
| 10 | 8 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
@@ -41,8 +41,9 @@ discard block |
||
| 41 | 41 | } |
| 42 | 42 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
| 43 | 43 | $retour.=$this->_getOnAjaxDone($responseElement, $jsCallback)."});\n"; |
| 44 | - if ($immediatly) |
|
| 45 | - $this->jquery_code_for_compile[]=$retour; |
|
| 44 | + if ($immediatly) { |
|
| 45 | + $this->jquery_code_for_compile[]=$retour; |
|
| 46 | + } |
|
| 46 | 47 | return $retour; |
| 47 | 48 | } |
| 48 | 49 | |
@@ -50,13 +51,15 @@ discard block |
||
| 50 | 51 | $url=$this->_correctAjaxUrl($url); |
| 51 | 52 | $retour="url='".$url."';\n"; |
| 52 | 53 | $slash="/"; |
| 53 | - if(JString::endswith($url, "/")===true) |
|
| 54 | - $slash=""; |
|
| 54 | + if(JString::endswith($url, "/")===true) { |
|
| 55 | + $slash=""; |
|
| 56 | + } |
|
| 55 | 57 | if(JString::isNotNull($attr)){ |
| 56 | - if ($attr=="value") |
|
| 57 | - $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
| 58 | - else if($attr!=null && $attr!=="") |
|
| 59 | - $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
| 58 | + if ($attr=="value") { |
|
| 59 | + $retour.="url=url+'".$slash."'+$(this).val();\n"; |
|
| 60 | + } else if($attr!=null && $attr!=="") { |
|
| 61 | + $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
|
| 62 | + } |
|
| 60 | 63 | } |
| 61 | 64 | return $retour; |
| 62 | 65 | } |
@@ -78,8 +81,9 @@ discard block |
||
| 78 | 81 | } |
| 79 | 82 | |
| 80 | 83 | protected function _correctAjaxUrl($url) { |
| 81 | - if ($url!=="/" && JString::endsWith($url, "/")===true) |
|
| 82 | - $url=substr($url, 0, strlen($url)-1); |
|
| 84 | + if ($url!=="/" && JString::endsWith($url, "/")===true) { |
|
| 85 | + $url=substr($url, 0, strlen($url)-1); |
|
| 86 | + } |
|
| 83 | 87 | if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
| 84 | 88 | $url=$this->jsUtils->getUrl($url); |
| 85 | 89 | } |
@@ -103,8 +107,9 @@ discard block |
||
| 103 | 107 | $retour.="\t".$jsCallback."\n". |
| 104 | 108 | "\t$(document).trigger('jsonReady',[data]);\n". |
| 105 | 109 | "});\n"; |
| 106 | - if ($immediatly) |
|
| 107 | - $this->jquery_code_for_compile[]=$retour; |
|
| 110 | + if ($immediatly) { |
|
| 111 | + $this->jquery_code_for_compile[]=$retour; |
|
| 112 | + } |
|
| 108 | 113 | return $retour; |
| 109 | 114 | } |
| 110 | 115 | |
@@ -143,7 +148,7 @@ discard block |
||
| 143 | 148 | if($context===null){ |
| 144 | 149 | $appendTo="\t\tnewElm.appendTo($('".$maskSelector."').parent());\n"; |
| 145 | 150 | $newElm = "$('#'+newId)"; |
| 146 | - }else{ |
|
| 151 | + } else{ |
|
| 147 | 152 | $appendTo="\t\tnewElm.appendTo(".$context.");\n"; |
| 148 | 153 | $newElm = $context.".find('#'+newId)"; |
| 149 | 154 | } |
@@ -153,8 +158,9 @@ discard block |
||
| 153 | 158 | $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"; |
| 154 | 159 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
| 155 | 160 | $retour.="\t".$jsCallback."\n"."});\n"; |
| 156 | - if ($immediatly) |
|
| 157 | - $this->jquery_code_for_compile[]=$retour; |
|
| 161 | + if ($immediatly) { |
|
| 162 | + $this->jquery_code_for_compile[]=$retour; |
|
| 163 | + } |
|
| 158 | 164 | return $retour; |
| 159 | 165 | } |
| 160 | 166 | /** |
@@ -195,8 +201,9 @@ discard block |
||
| 195 | 201 | }});\n"; |
| 196 | 202 | $retour.="$('#".$form."').submit();\n"; |
| 197 | 203 | } |
| 198 | - if ($immediatly) |
|
| 199 | - $this->jquery_code_for_compile[]=$retour; |
|
| 204 | + if ($immediatly) { |
|
| 205 | + $this->jquery_code_for_compile[]=$retour; |
|
| 206 | + } |
|
| 200 | 207 | return $retour; |
| 201 | 208 | } |
| 202 | 209 | |
@@ -43,8 +43,7 @@ discard block |
||
| 43 | 43 | foreach ($actions as $action){ |
| 44 | 44 | $this->addAction($action); |
| 45 | 45 | } |
| 46 | - } |
|
| 47 | - else{ |
|
| 46 | + } else{ |
|
| 48 | 47 | $this->addAction($actions); |
| 49 | 48 | } |
| 50 | 49 | return $this; |
@@ -60,8 +59,9 @@ discard block |
||
| 60 | 59 | $class="cancel"; |
| 61 | 60 | } |
| 62 | 61 | $action=new HtmlButton("action-".$this->identifier,$action); |
| 63 | - if($class!=="") |
|
| 64 | - $action->addToProperty("class", $class); |
|
| 62 | + if($class!=="") { |
|
| 63 | + $action->addToProperty("class", $class); |
|
| 64 | + } |
|
| 65 | 65 | } |
| 66 | 66 | return $this->addElementInPart($action, "actions"); |
| 67 | 67 | } |
@@ -165,8 +165,9 @@ discard block |
||
| 165 | 165 | * @see BaseHtml::run() |
| 166 | 166 | */ |
| 167 | 167 | public function run(JsUtils $js) { |
| 168 | - if(isset($this->_bsComponent)===false) |
|
| 169 | - $this->_bsComponent=$js->semantic()->modal("#".$this->identifier,$this->_params,$this->_paramParts); |
|
| 168 | + if(isset($this->_bsComponent)===false) { |
|
| 169 | + $this->_bsComponent=$js->semantic()->modal("#".$this->identifier,$this->_params,$this->_paramParts); |
|
| 170 | + } |
|
| 170 | 171 | $this->addEventsOnRun($js); |
| 171 | 172 | return $this->_bsComponent; |
| 172 | 173 | } |
@@ -181,9 +181,9 @@ |
||
| 181 | 181 | protected function createItem($value) { |
| 182 | 182 | $count=$this->count(); |
| 183 | 183 | $itemO=new HtmlSemDoubleElement("item-" . $this->identifier . "-" . $count, "a", "section"); |
| 184 | - if (\is_array($value)) |
|
| 185 | - $itemO->fromArray($value); |
|
| 186 | - else { |
|
| 184 | + if (\is_array($value)) { |
|
| 185 | + $itemO->fromArray($value); |
|
| 186 | + } else { |
|
| 187 | 187 | $itemO->setContent($value); |
| 188 | 188 | } |
| 189 | 189 | return $itemO; |
@@ -147,10 +147,12 @@ discard block |
||
| 147 | 147 | if (isset($param)) { |
| 148 | 148 | $param=$this->_prep_value($param); |
| 149 | 149 | $str="$({$element}).{$jQueryCall}({$param});"; |
| 150 | - } else |
|
| 151 | - $str="$({$element}).{$jQueryCall}();"; |
|
| 152 | - if ($immediatly) |
|
| 153 | - $this->jquery_code_for_compile[]=$str; |
|
| 150 | + } else { |
|
| 151 | + $str="$({$element}).{$jQueryCall}();"; |
|
| 152 | + } |
|
| 153 | + if ($immediatly) { |
|
| 154 | + $this->jquery_code_for_compile[]=$str; |
|
| 155 | + } |
|
| 154 | 156 | return $str; |
| 155 | 157 | } |
| 156 | 158 | /** |
@@ -165,8 +167,9 @@ discard block |
||
| 165 | 167 | $to=$this->_prep_element($to); |
| 166 | 168 | $element=$this->_prep_element($element); |
| 167 | 169 | $str="$({$to}).{$jQueryCall}({$element});"; |
| 168 | - if ($immediatly) |
|
| 169 | - $this->jquery_code_for_compile[]=$str; |
|
| 170 | + if ($immediatly) { |
|
| 171 | + $this->jquery_code_for_compile[]=$str; |
|
| 172 | + } |
|
| 170 | 173 | return $str; |
| 171 | 174 | } |
| 172 | 175 | |
@@ -222,12 +225,14 @@ discard block |
||
| 222 | 225 | if ($stopPropagation===true) { |
| 223 | 226 | $js="event.stopPropagation();\n".$js; |
| 224 | 227 | } |
| 225 | - if (array_search($event, $this->jquery_events)===false) |
|
| 226 | - $event="\n\t$(".$this->_prep_element($element).").bind('{$event}',function(event){\n\t\t{$js}\n\t});\n"; |
|
| 227 | - else |
|
| 228 | - $event="\n\t$(".$this->_prep_element($element).").{$event}(function(event){\n\t\t{$js}\n\t});\n"; |
|
| 229 | - if($immediatly) |
|
| 230 | - $this->jquery_code_for_compile[]=$event; |
|
| 228 | + if (array_search($event, $this->jquery_events)===false) { |
|
| 229 | + $event="\n\t$(".$this->_prep_element($element).").bind('{$event}',function(event){\n\t\t{$js}\n\t});\n"; |
|
| 230 | + } else { |
|
| 231 | + $event="\n\t$(".$this->_prep_element($element).").{$event}(function(event){\n\t\t{$js}\n\t});\n"; |
|
| 232 | + } |
|
| 233 | + if($immediatly) { |
|
| 234 | + $this->jquery_code_for_compile[]=$event; |
|
| 235 | + } |
|
| 231 | 236 | return $event; |
| 232 | 237 | } |
| 233 | 238 | |
@@ -355,7 +360,9 @@ discard block |
||
| 355 | 360 | } |
| 356 | 361 | |
| 357 | 362 | private function minify($input) { |
| 358 | - if(trim($input) === "") return $input; |
|
| 363 | + if(trim($input) === "") { |
|
| 364 | + return $input; |
|
| 365 | + } |
|
| 359 | 366 | return preg_replace( |
| 360 | 367 | array( |
| 361 | 368 | // Remove comment(s) |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | if(isset($router)===true){ |
| 14 | 14 | try { |
| 15 | 15 | $url=$router->generate($url); |
| 16 | - }catch (\Exception $e){ |
|
| 16 | + } catch (\Exception $e){ |
|
| 17 | 17 | return $router->getContext()->getBaseUrl(); |
| 18 | 18 | } |
| 19 | 19 | } |