Skip to content

Commit ccea9aa

Browse files
committed
Update prep_jquery_selector, add href auto active
1 parent fc9e055 commit ccea9aa

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Ajax/common/traits/JsUtilsAjaxTrait.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$
114114
$retour="\t{$responseElement}.{$jqueryDone}( data );\n";
115115
}
116116
if(isset($history)){
117-
$retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);";
117+
$retour.="\nfunction getHref(url) { return \$('a').filter(function(){return \$(this).prop('href') == url; });}";
118+
$retour.="\nif(window._previousURL) getHref(window._previousURL).removeClass('active');getHref(url).addClass('active');";
119+
$retour.="\nwindow.history.pushState({'html':data,'selector':".Javascript::prep_value($history).",'jqueryDone':'{$jqueryDone}'},'', url);window._previousURL=url;";
118120
}
119121
if($hasLoader==="internal"){
120122
$retour.="\n$(self).removeClass('loading');";
@@ -125,7 +127,6 @@ protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$
125127

126128
protected function _getResponseElement($responseElement){
127129
if (JString::isNotNull($responseElement)) {
128-
$responseElement=Javascript::prep_value($responseElement);
129130
$responseElement=Javascript::prep_jquery_selector($responseElement);
130131
}
131132
return $responseElement;
@@ -424,7 +425,7 @@ public function getOnClick($element, $url, $responseElement="", $parameters=arra
424425
public function getHref($element,$responseElement="",$parameters=array()){
425426
$parameters["attr"]="href";
426427
if(JString::isNull($responseElement)){
427-
$responseElement='$($(this).attr("data-target"))';
428+
$responseElement='%$(self).attr("data-target")%';
428429
}
429430
if(!isset($parameters["historize"])){
430431
$parameters["historize"]=true;
@@ -442,7 +443,7 @@ public function getHref($element,$responseElement="",$parameters=array()){
442443
public function postHref($element,$responseElement="",$parameters=array()){
443444
$parameters["attr"]="href";
444445
if(JString::isNull($responseElement)){
445-
$responseElement='$($(this).attr("data-target"))';
446+
$responseElement='%$(this).attr("data-target")%';
446447
}
447448
if(!isset($parameters["historize"])){
448449
$parameters["historize"]=true;

Ajax/service/Javascript.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ public static function prep_value($value) {
4949
$value=\str_replace(["\\","\""], ["\\\\","\\\""], $value);
5050
$value='"'.$value.'"';
5151
}
52-
return $value;
52+
return trim($value,"%");
5353
}
5454

5555
public static function prep_jquery_selector($value){
5656
if(JString::startswith($value, '$(')===false){
57-
return '$('.$value.')';
57+
return '$('.self::prep_value($value).')';
5858
}
5959
return $value;
6060
}

0 commit comments

Comments
 (0)