navigation improvement, fix #372

This commit is contained in:
2019-12-03 18:56:00 +01:00
parent fdcb29a4f9
commit 1081ca49a6
2 changed files with 135 additions and 12 deletions
@@ -22,6 +22,7 @@
var _is_loggedin = drupalSettings.user.uid === 0 ? false : true;
var _$log_form;
var _user_tokens;
var _states_history = [];
// ___ _ _
// |_ _|_ _ (_) |_
@@ -366,7 +367,14 @@
}else{
_$row.append($rendered);
}
}else{
}
else if(
(state.context == 'document-transcript' || state.context == 'document-artcile')
&& state.caller == "search"
){
_$row.append($rendered);
}
else{
_$row.removeAttr('style').html($rendered);
}
@@ -514,15 +522,12 @@
_$body.removeClass('ajax-loading');
// record the states history as we can't get them from history api
_states_history.unshift(state);
// url is null means that we are loading content on popState event
// so we don't record the state again
if(state.url){
// var state = {
// ajax_path:ajax_path,
// sys_path:sys_path,
// };
// console.log('url:'+url+' ; state',state);
// console.log(window.location);
// /!\ we can not pushestate with absolute url /!\
history.pushState(state, null, state.url);
@@ -584,6 +589,55 @@
function onCloseModal(e){
console.log("onCloseModal");
// check from production to audio text back to production
console.log("onCloseModal _states_history",_states_history);
if(['document-transcript', 'document-article'].indexOf(_states_history[0].context) != -1)
{
if (_states_history[0].caller == "production") {
for (var i = 0; i < _states_history.length; i++) {
if (_states_history[i].context == "production") {
// history.go(i*-1-1);
console.log("onCloseModal return to production", _states_history[i]);
ajaxLoadContent(_states_history[i]);
return;
}
}
}
if (_states_history[0].caller == "entree-index") {
for (var i = 0; i < _states_history.length; i++) {
if (_states_history[i].context == "entree-index") {
console.log("onCloseModal return to entree-index", _states_history[i]);
ajaxLoadContent(_states_history[i]);
return;
}
}
}
if (_states_history[0].caller == "entree-notice") {
for (var i = 0; i < _states_history.length; i++) {
if (_states_history[i].context == "entree-notice") {
console.log("onCloseModal return to entree-notice", _states_history[i]);
ajaxLoadContent(_states_history[i]);
return;
}
}
}
}
// return to productions home when closing a prod
// if(['production'].indexOf(_states_history[0].context) != -1)
// {
// var i = 0;
// while (_states_history[i].caller == "production-home") {
// if (_states_history[i].context == "production-home") {
// // history.go(i*-1-1);
// console.log("onCloseModal return to productions home", _states_history[i]);
// ajaxLoadContent(_states_history[i]);
// return;
// }
// i++;
// }
// }
// check for theme attribute and emmit event
var $col = $(this).parents('.col');
var theme = $col.attr('theme');
@@ -882,6 +936,64 @@
state.url += "#"+view_mode;
}
// get context for navigation purpose
// var contexts = state.url.match(/^.*\/(productions)\/.*/g);
var contexts = /^.*\/(productions|documents|entrees|search)(\/.*)?/g.exec(state.url);
console.log("onClickAjaxLink contexts", contexts);
if(contexts){
switch (contexts[1]) {
case 'productions':
// console.log("onClickAjaxLink is production");
// if (typeof contexts[2] !== 'undefined') {
state.context = "production"
// }else{
// state.context = "production-home"
// }
break;
case 'entrees':
switch(view_mode) {
case 'index':
state.context = "entree-index";
break;
case 'notice':
state.context = "entree-notice";
break;
}
break;
case 'search':
state.context = "search";
break;
case 'documents':
// console.log("onClickAjaxLink is production");
switch (view_mode) {
case 'transcript':
state.context = "document-transcript";
break;
case 'article':
state.context = "document-article";
break;
default:
state.context = "document";
}
// get the caller from pecedent context
if(typeof _states_history[0] != "undefined"){
if(_states_history[0].caller){
state.caller = _states_history[0].caller
}else{
state.caller = _states_history[0].context
}
}else{
state.caller = null;
}
break;
}
}else{
state.context = null;
state.context = caller;
}
if($link.is('[selector]')){
state.selector = $link.attr('selector');
}
@@ -1308,7 +1420,7 @@
.fail(this.onNodeLoadFail.bind(this));
},
onNodeLoaded(data){
console.log('AudioPlayer node loaded', data);
console.log('AudioPlayer node loaded');//, data);
this.$cartel.html(data.rendered).removeClass('loading');
_$body.trigger({'type':'new-audio-cartel-loaded'});
initAjaxLinks();