Skip to content

Commit 966ba4c

Browse files
committed
ajax getResponseElement refactoring
1 parent ef9455d commit 966ba4c

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Ajax/common/traits/JsUtilsAjaxTrait.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected function _ajax($method,$url,$responseElement="",$parameters=[]) {
3434
$retour=$this->_getAjaxUrl($url, $attr);
3535
$responseElement=$this->_getResponseElement($responseElement);
3636
$retour.="var self=this;\n";
37-
if($hasLoader===true){
37+
if($hasLoader===true && JString::isNotNull($responseElement)){
3838
$this->addLoading($retour, $responseElement);
3939
}
4040

@@ -107,7 +107,7 @@ protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$
107107
if(\is_callable($call))
108108
$retour="\t".$call($responseElement,$jqueryDone).";\n";
109109
else
110-
$retour="\t$({$responseElement}).{$jqueryDone}( data );\n";
110+
$retour="\t{$responseElement}.{$jqueryDone}( data );\n";
111111
}
112112
$retour.="\t".$jsCallback."\n";
113113
return $retour;
@@ -116,6 +116,7 @@ protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$
116116
protected function _getResponseElement($responseElement){
117117
if ($responseElement!=="") {
118118
$responseElement=Javascript::prep_value($responseElement);
119+
$responseElement=Javascript::prep_jquery_selector($responseElement);
119120
}
120121
return $responseElement;
121122
}
@@ -156,8 +157,8 @@ protected function addLoading(&$retour, $responseElement) {
156157
$loading_notifier.=$this->ajaxLoader;
157158
}
158159
$loading_notifier.='</div>';
159-
$retour.="$({$responseElement}).empty();\n";
160-
$retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n";
160+
$retour.="{$responseElement}.empty();\n";
161+
$retour.="\t\t{$responseElement}.prepend('{$loading_notifier}');\n";
161162
}
162163

163164
protected function setAjaxDataCall($params){

Ajax/service/AjaxTransition.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
class AjaxTransition {
66
public static function none($responseElement,$jqueryDone="html"){
7-
return "$({$responseElement}).{$jqueryDone}( data )";
7+
return $responseElement.".".$jqueryDone."( data )";
88
}
99

1010
public static function jqFade($responseElement,$jqueryDone="html"){
11-
return "$({$responseElement}).hide().{$jqueryDone}( data ).fadeIn()";
11+
return $responseElement.".hide().{$jqueryDone}( data ).fadeIn()";
1212
}
1313

1414
public static function jqSlide($responseElement,$jqueryDone="html"){
15-
return "$({$responseElement}).hide().{$jqueryDone}( data ).slideDown()";
15+
return $responseElement.".hide().{$jqueryDone}( data ).slideDown()";
1616
}
1717

1818
public static function random($responseElement,$jqueryDone="html"){
@@ -26,7 +26,7 @@ public static function __callStatic($name, $arguments){
2626
$responseElement=$arguments[0];
2727
$jqueryDone=$arguments[1];
2828
$name=JString::camelCaseToSeparated($name);
29-
return "$({$responseElement}).{$jqueryDone}( data ).transition('{$name} in')";
29+
return $responseElement.".".$jqueryDone."( data ).transition('{$name} in')";
3030
}
3131
}
3232
}

Ajax/service/Javascript.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@ public static function prep_value($value) {
4242
}
4343
return $value;
4444
}
45+
46+
public static function prep_jquery_selector($value){
47+
if(JString::startswith($value, '$(')===false){
48+
return '$('.$value.')';
49+
}
50+
return $value;
51+
}
4552
}

0 commit comments

Comments
 (0)