From 4529db50a870f843a545a57d82b1a54cece48255 Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Wed, 4 Apr 2018 15:13:35 +0200 Subject: [PATCH] trying to fix redirect to home bug : replaced cookie by localStorage --- .../assets/dist/scripts/history.min.js | 18 +++++++++-------- .../edlptheme/assets/dist/scripts/main.min.js | 20 +++++++++---------- .../edlptheme/assets/scripts/history.js | 18 +++++++++-------- .../custom/edlptheme/assets/scripts/main.js | 20 +++++++++---------- 4 files changed, 40 insertions(+), 36 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 2771636e8..48a7f69cf 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,19 +1,21 @@ 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; - d.setTime(d.getTime() + 24*60*60*1000*days); - document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString(); -} +// function setCookie(name, value, days) { +// var d = new Date; +// d.setTime(d.getTime() + 24*60*60*1000*days); +// document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString(); +// } // 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"; - var cookie_value = edlp.sys_path.replace(/^\//, '') + '~~' + window.location.pathname; - setCookie(cookiename, cookie_value, 1); + // var cookiename = "edlp_origin_path"; + // var cookie_value = edlp.sys_path.replace(/^\//, '') + '~~' + window.location.pathname; + // setCookie(cookiename, cookie_value, 1); + window.localStorage.setItem('edlp_origin_path', edlp.sys_path.replace(/^\//, '')); + window.localStorage.setItem('edlp_origin_url', window.location.pathname); // redirect to home window.location.replace(window.location.origin); }else{ 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 4ff9a5199..d5929c2ec 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 @@ -255,21 +255,21 @@ console.log('theme : initFirstLoad()', window.location); console.log(document.cookie); var url = window.location.pathname; - var origin_path = getCookie('edlp_origin_path'); - console.log('origin_path', origin_path); - if(origin_path){ - var path_elements = origin_path.split('~~'); - console.log(path_elements); - var sys_path = path_elements[0]; - var url = path_elements[1]; + // var origin_path = getCookie('edlp_origin_path'); + // console.log('origin_path', origin_path); + var origin_sys_path = window.localStorage.getItem('edlp_origin_path'); + console.log('origin_sys_path', origin_sys_path); + var origin_url = window.localStorage.getItem('edlp_origin_url'); + console.log('origin_url', origin_url); + if(origin_sys_path){ // create history state var state = { - ajax_path: parseAjaxSysPath(sys_path), - sys_path: sys_path, + ajax_path: parseAjaxSysPath(origin_sys_path), + sys_path: origin_sys_path, }; console.log('state', state); // record history state - history.replaceState(state, null, url); + history.replaceState(state, null, origin_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 2771636e8..48a7f69cf 100644 --- a/sites/all/themes/custom/edlptheme/assets/scripts/history.js +++ b/sites/all/themes/custom/edlptheme/assets/scripts/history.js @@ -1,19 +1,21 @@ 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; - d.setTime(d.getTime() + 24*60*60*1000*days); - document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString(); -} +// function setCookie(name, value, days) { +// var d = new Date; +// d.setTime(d.getTime() + 24*60*60*1000*days); +// document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString(); +// } // 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"; - var cookie_value = edlp.sys_path.replace(/^\//, '') + '~~' + window.location.pathname; - setCookie(cookiename, cookie_value, 1); + // var cookiename = "edlp_origin_path"; + // var cookie_value = edlp.sys_path.replace(/^\//, '') + '~~' + window.location.pathname; + // setCookie(cookiename, cookie_value, 1); + window.localStorage.setItem('edlp_origin_path', edlp.sys_path.replace(/^\//, '')); + window.localStorage.setItem('edlp_origin_url', window.location.pathname); // redirect to home window.location.replace(window.location.origin); }else{ diff --git a/sites/all/themes/custom/edlptheme/assets/scripts/main.js b/sites/all/themes/custom/edlptheme/assets/scripts/main.js index 4ff9a5199..d5929c2ec 100644 --- a/sites/all/themes/custom/edlptheme/assets/scripts/main.js +++ b/sites/all/themes/custom/edlptheme/assets/scripts/main.js @@ -255,21 +255,21 @@ console.log('theme : initFirstLoad()', window.location); console.log(document.cookie); var url = window.location.pathname; - var origin_path = getCookie('edlp_origin_path'); - console.log('origin_path', origin_path); - if(origin_path){ - var path_elements = origin_path.split('~~'); - console.log(path_elements); - var sys_path = path_elements[0]; - var url = path_elements[1]; + // var origin_path = getCookie('edlp_origin_path'); + // console.log('origin_path', origin_path); + var origin_sys_path = window.localStorage.getItem('edlp_origin_path'); + console.log('origin_sys_path', origin_sys_path); + var origin_url = window.localStorage.getItem('edlp_origin_url'); + console.log('origin_url', origin_url); + if(origin_sys_path){ // create history state var state = { - ajax_path: parseAjaxSysPath(sys_path), - sys_path: sys_path, + ajax_path: parseAjaxSysPath(origin_sys_path), + sys_path: origin_sys_path, }; console.log('state', state); // record history state - history.replaceState(state, null, url); + history.replaceState(state, null, origin_url); // load content through ajax ajaxLoadContent(null, state.sys_path, state.ajax_path); // reset the cookie