trying to fix redirect to home bug : replaced cookie by localStorage
This commit is contained in:
@@ -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{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user