Browse Source

trying to fix redirect to home bug

Bachir Soussi Chiadmi 6 năm trước cách đây
mục cha
commit
dc315a0e24

+ 3 - 0
sites/all/themes/custom/edlptheme/assets/dist/scripts/history.min.js

@@ -1,3 +1,4 @@
+console.log('history');
 // https://plainjs.com/javascript/utilities/set-cookie-get-cookie-and-delete-cookie-5/
 function setCookie(name, value, days) {
   var d = new Date;
@@ -7,6 +8,7 @@ function setCookie(name, value, days) {
 
 // var edlp is provided by edlp_ajax.module file
 if(edlp.redirect){
+  console.log('history redirect');
   document.body.style.visibility = 'hidden';
   // record current (will be origin) sys_path in cookie
   var cookiename = "edlp_origin_path";
@@ -15,5 +17,6 @@ if(edlp.redirect){
   // redirect to home
   window.location.replace(window.location.origin);
 }else{
+  console.log('history do not redirect');
   document.body.style.visibility = 'visible';
 }

+ 7 - 6
sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js

@@ -16,7 +16,7 @@
     //  | || ' \| |  _|
     // |___|_||_|_|\__|
     function init(){
-      // console.log("EdlpTheme init()");
+      console.log("EdlpTheme init()");
 
       initHistory();
 
@@ -78,7 +78,6 @@
       // });
     };
 
-
     //    _    _
     //   /_\  (_)__ ___ __
     //  / _ \ | / _` \ \ /
@@ -130,7 +129,7 @@
       _$body.removeClass('ajax-loading');
     };
     function onAjaxLoaded(data, url, ajax_path, sys_path, selector){
-      // console.log('ajax loaded : data', data);
+      console.log('ajax loaded url:'+url+' ajax_path:'+ajax_path+' sys_path:'+sys_path+'  data', data);
 
       // reset all style may been added by other pages (like masonry for productions)
       // and replace all content with newly loaded
@@ -261,14 +260,16 @@
       if(origin_path){
         var path_elements = origin_path.split('~~');
         console.log(path_elements);
+        var sys_path = path_elements[0];
+        var url = path_elements[1];
         // create history state
         var state = {
-          ajax_path: parseAjaxSysPath(path_elements[0]),
-          sys_path: path_elements[0],
+          ajax_path: parseAjaxSysPath(sys_path),
+          sys_path: sys_path,
         };
         console.log('state', state);
         // record history state
-        history.replaceState(state, null, path_elements[1]);
+        history.replaceState(state, null, url);
         // load content through ajax
         ajaxLoadContent(null, state.sys_path, state.ajax_path);
         // reset the cookie

+ 3 - 0
sites/all/themes/custom/edlptheme/assets/scripts/history.js

@@ -1,3 +1,4 @@
+console.log('history');
 // https://plainjs.com/javascript/utilities/set-cookie-get-cookie-and-delete-cookie-5/
 function setCookie(name, value, days) {
   var d = new Date;
@@ -7,6 +8,7 @@ function setCookie(name, value, days) {
 
 // var edlp is provided by edlp_ajax.module file
 if(edlp.redirect){
+  console.log('history redirect');
   document.body.style.visibility = 'hidden';
   // record current (will be origin) sys_path in cookie
   var cookiename = "edlp_origin_path";
@@ -15,5 +17,6 @@ if(edlp.redirect){
   // redirect to home
   window.location.replace(window.location.origin);
 }else{
+  console.log('history do not redirect');
   document.body.style.visibility = 'visible';
 }

+ 7 - 6
sites/all/themes/custom/edlptheme/assets/scripts/main.js

@@ -16,7 +16,7 @@
     //  | || ' \| |  _|
     // |___|_||_|_|\__|
     function init(){
-      // console.log("EdlpTheme init()");
+      console.log("EdlpTheme init()");
 
       initHistory();
 
@@ -78,7 +78,6 @@
       // });
     };
 
-
     //    _    _
     //   /_\  (_)__ ___ __
     //  / _ \ | / _` \ \ /
@@ -130,7 +129,7 @@
       _$body.removeClass('ajax-loading');
     };
     function onAjaxLoaded(data, url, ajax_path, sys_path, selector){
-      // console.log('ajax loaded : data', data);
+      console.log('ajax loaded url:'+url+' ajax_path:'+ajax_path+' sys_path:'+sys_path+'  data', data);
 
       // reset all style may been added by other pages (like masonry for productions)
       // and replace all content with newly loaded
@@ -261,14 +260,16 @@
       if(origin_path){
         var path_elements = origin_path.split('~~');
         console.log(path_elements);
+        var sys_path = path_elements[0];
+        var url = path_elements[1];
         // create history state
         var state = {
-          ajax_path: parseAjaxSysPath(path_elements[0]),
-          sys_path: path_elements[0],
+          ajax_path: parseAjaxSysPath(sys_path),
+          sys_path: sys_path,
         };
         console.log('state', state);
         // record history state
-        history.replaceState(state, null, path_elements[1]);
+        history.replaceState(state, null, url);
         // load content through ajax
         ajaxLoadContent(null, state.sys_path, state.ajax_path);
         // reset the cookie