menu: al ir a un modulo desde la hoja se quita antes su entrada del historial; volver atras ya no reabre la hoja
This commit is contained in:
parent
9e2716f69b
commit
9f8317baa3
1 changed files with 21 additions and 11 deletions
|
|
@ -1,21 +1,31 @@
|
||||||
// Pestaña Menu del movil: que el boton atras de Android cierre la hoja en vez de
|
// Hoja del menu (pestaña Menu de la barra de abajo). Abre y cierra con una casilla
|
||||||
// salir de la pagina. Al abrirla se apunta una entrada en el historial; atras la
|
// y CSS; esto solo hace que el boton atras de Android cierre la hoja en vez de
|
||||||
// quita y cierra la hoja. Sin este fichero el menu funciona igual (es una casilla
|
// cambiar de pagina. Ver docs/ESTUDIO_NAVEGACION.md.
|
||||||
// y CSS), solo que atras cambia de pagina. Ver docs/ESTUDIO_NAVEGACION.md.
|
|
||||||
(function () {
|
(function () {
|
||||||
var box = document.getElementById('oasis-menu-toggle');
|
var box = document.getElementById('oasis-menu-toggle');
|
||||||
if (!box || !window.history || !history.pushState) return;
|
if (!box || !window.history || !history.pushState) return;
|
||||||
// al volver atras a una pagina desde la que se abrio otra con el menu, la entrada
|
var sheet = document.querySelector('.menu-sheet');
|
||||||
// del historial es la del menu abierto: se ensena abierto y el siguiente atras lo cierra
|
var pending = null;
|
||||||
if (history.state && history.state.oasisMenu) box.checked = true;
|
if (history.state && history.state.oasisMenu) box.checked = true;
|
||||||
box.addEventListener('change', function () {
|
box.addEventListener('change', function () {
|
||||||
if (box.checked) {
|
if (box.checked) { history.pushState({ oasisMenu: true }, ''); }
|
||||||
history.pushState({ oasisMenu: true }, '');
|
else if (history.state && history.state.oasisMenu) { history.back(); }
|
||||||
} else if (history.state && history.state.oasisMenu) {
|
|
||||||
history.back();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
window.addEventListener('popstate', function () {
|
window.addEventListener('popstate', function () {
|
||||||
if (box.checked) box.checked = false;
|
if (box.checked) box.checked = false;
|
||||||
|
// se navega despues de que la vuelta atras termine (en WebView 69, si no, se
|
||||||
|
// perdia la entrada nueva)
|
||||||
|
if (pending) setTimeout(follow, 50);
|
||||||
|
});
|
||||||
|
function follow() { if (pending) { var go = pending; pending = null; location.href = go; } }
|
||||||
|
// al ir a un modulo desde la hoja, primero se quita la entrada de la hoja: si no,
|
||||||
|
// al volver atras desde el modulo la portada aparecia con la hoja abierta
|
||||||
|
if (sheet) sheet.addEventListener('click', function (e) {
|
||||||
|
var a = e.target.closest ? e.target.closest('a[href]') : null;
|
||||||
|
if (!a || !(history.state && history.state.oasisMenu)) return;
|
||||||
|
e.preventDefault();
|
||||||
|
pending = a.href;
|
||||||
|
history.back();
|
||||||
|
setTimeout(follow, 1000);
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue