From dc315a0e24847352e330555ea6f2dc6190684d4f Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Wed, 4 Apr 2018 14:51:47 +0200 Subject: [PATCH] trying to fix redirect to home bug --- .../edlptheme/assets/dist/scripts/history.min.js | 3 +++ .../edlptheme/assets/dist/scripts/main.min.js | 13 +++++++------ .../custom/edlptheme/assets/scripts/history.js | 3 +++ .../themes/custom/edlptheme/assets/scripts/main.js | 13 +++++++------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/sites/all/themes/custom/edlptheme/assets/dist/scripts/history.min.js b/sites/all/themes/custom/edlptheme/assets/dist/scripts/history.min.js index 8baf1625d..2771636e8 100644 --- a/sites/all/themes/custom/edlptheme/assets/dist/scripts/history.min.js +++ b/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'; } diff --git a/sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js b/sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js index 467beb398..4ff9a5199 100644 --- a/sites/all/themes/custom/edlptheme/assets/dist/scripts/main.min.js +++ b/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 diff --git a/sites/all/themes/custom/edlptheme/assets/scripts/history.js b/sites/all/themes/custom/edlptheme/assets/scripts/history.js index 8baf1625d..2771636e8 100644 --- a/sites/all/themes/custom/edlptheme/assets/scripts/history.js +++ b/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'; } diff --git a/sites/all/themes/custom/edlptheme/assets/scripts/main.js b/sites/all/themes/custom/edlptheme/assets/scripts/main.js index 467beb398..4ff9a5199 100644 --- a/sites/all/themes/custom/edlptheme/assets/scripts/main.js +++ b/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