trying to fix redirect to home bug

This commit is contained in:
Bachir Soussi Chiadmi
2018-04-04 14:51:47 +02:00
parent 7b11b8b1f0
commit dc315a0e24
4 changed files with 20 additions and 12 deletions
@@ -1,3 +1,4 @@
console.log('history');
// https://plainjs.com/javascript/utilities/set-cookie-get-cookie-and-delete-cookie-5/ // https://plainjs.com/javascript/utilities/set-cookie-get-cookie-and-delete-cookie-5/
function setCookie(name, value, days) { function setCookie(name, value, days) {
var d = new Date; var d = new Date;
@@ -7,6 +8,7 @@ function setCookie(name, value, days) {
// var edlp is provided by edlp_ajax.module file // var edlp is provided by edlp_ajax.module file
if(edlp.redirect){ if(edlp.redirect){
console.log('history redirect');
document.body.style.visibility = 'hidden'; document.body.style.visibility = 'hidden';
// record current (will be origin) sys_path in cookie // record current (will be origin) sys_path in cookie
var cookiename = "edlp_origin_path"; var cookiename = "edlp_origin_path";
@@ -15,5 +17,6 @@ if(edlp.redirect){
// redirect to home // redirect to home
window.location.replace(window.location.origin); window.location.replace(window.location.origin);
}else{ }else{
console.log('history do not redirect');
document.body.style.visibility = 'visible'; document.body.style.visibility = 'visible';
} }
@@ -16,7 +16,7 @@
// | || ' \| | _| // | || ' \| | _|
// |___|_||_|_|\__| // |___|_||_|_|\__|
function init(){ function init(){
// console.log("EdlpTheme init()"); console.log("EdlpTheme init()");
initHistory(); initHistory();
@@ -78,7 +78,6 @@
// }); // });
}; };
// _ _ // _ _
// /_\ (_)__ ___ __ // /_\ (_)__ ___ __
// / _ \ | / _` \ \ / // / _ \ | / _` \ \ /
@@ -130,7 +129,7 @@
_$body.removeClass('ajax-loading'); _$body.removeClass('ajax-loading');
}; };
function onAjaxLoaded(data, url, ajax_path, sys_path, selector){ 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) // reset all style may been added by other pages (like masonry for productions)
// and replace all content with newly loaded // and replace all content with newly loaded
@@ -261,14 +260,16 @@
if(origin_path){ if(origin_path){
var path_elements = origin_path.split('~~'); var path_elements = origin_path.split('~~');
console.log(path_elements); console.log(path_elements);
var sys_path = path_elements[0];
var url = path_elements[1];
// create history state // create history state
var state = { var state = {
ajax_path: parseAjaxSysPath(path_elements[0]), ajax_path: parseAjaxSysPath(sys_path),
sys_path: path_elements[0], sys_path: sys_path,
}; };
console.log('state', state); console.log('state', state);
// record history state // record history state
history.replaceState(state, null, path_elements[1]); history.replaceState(state, null, url);
// load content through ajax // load content through ajax
ajaxLoadContent(null, state.sys_path, state.ajax_path); ajaxLoadContent(null, state.sys_path, state.ajax_path);
// reset the cookie // reset the cookie
@@ -1,3 +1,4 @@
console.log('history');
// https://plainjs.com/javascript/utilities/set-cookie-get-cookie-and-delete-cookie-5/ // https://plainjs.com/javascript/utilities/set-cookie-get-cookie-and-delete-cookie-5/
function setCookie(name, value, days) { function setCookie(name, value, days) {
var d = new Date; var d = new Date;
@@ -7,6 +8,7 @@ function setCookie(name, value, days) {
// var edlp is provided by edlp_ajax.module file // var edlp is provided by edlp_ajax.module file
if(edlp.redirect){ if(edlp.redirect){
console.log('history redirect');
document.body.style.visibility = 'hidden'; document.body.style.visibility = 'hidden';
// record current (will be origin) sys_path in cookie // record current (will be origin) sys_path in cookie
var cookiename = "edlp_origin_path"; var cookiename = "edlp_origin_path";
@@ -15,5 +17,6 @@ if(edlp.redirect){
// redirect to home // redirect to home
window.location.replace(window.location.origin); window.location.replace(window.location.origin);
}else{ }else{
console.log('history do not redirect');
document.body.style.visibility = 'visible'; document.body.style.visibility = 'visible';
} }
@@ -16,7 +16,7 @@
// | || ' \| | _| // | || ' \| | _|
// |___|_||_|_|\__| // |___|_||_|_|\__|
function init(){ function init(){
// console.log("EdlpTheme init()"); console.log("EdlpTheme init()");
initHistory(); initHistory();
@@ -78,7 +78,6 @@
// }); // });
}; };
// _ _ // _ _
// /_\ (_)__ ___ __ // /_\ (_)__ ___ __
// / _ \ | / _` \ \ / // / _ \ | / _` \ \ /
@@ -130,7 +129,7 @@
_$body.removeClass('ajax-loading'); _$body.removeClass('ajax-loading');
}; };
function onAjaxLoaded(data, url, ajax_path, sys_path, selector){ 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) // reset all style may been added by other pages (like masonry for productions)
// and replace all content with newly loaded // and replace all content with newly loaded
@@ -261,14 +260,16 @@
if(origin_path){ if(origin_path){
var path_elements = origin_path.split('~~'); var path_elements = origin_path.split('~~');
console.log(path_elements); console.log(path_elements);
var sys_path = path_elements[0];
var url = path_elements[1];
// create history state // create history state
var state = { var state = {
ajax_path: parseAjaxSysPath(path_elements[0]), ajax_path: parseAjaxSysPath(sys_path),
sys_path: path_elements[0], sys_path: sys_path,
}; };
console.log('state', state); console.log('state', state);
// record history state // record history state
history.replaceState(state, null, path_elements[1]); history.replaceState(state, null, url);
// load content through ajax // load content through ajax
ajaxLoadContent(null, state.sys_path, state.ajax_path); ajaxLoadContent(null, state.sys_path, state.ajax_path);
// reset the cookie // reset the cookie