mirror of
https://github.com/twisterarmy/twister-html.git
synced 2025-03-12 13:31:14 +00:00
fix modals' closing on window history navigation
This commit is contained in:
parent
3da830567d
commit
8608a9d235
@ -6,7 +6,7 @@
|
|||||||
// Post actions: submit, count characters
|
// Post actions: submit, count characters
|
||||||
|
|
||||||
var window_scrollY = 0;
|
var window_scrollY = 0;
|
||||||
var _watchHashChangeDontLoadModal = false;
|
var _watchHashChangeRelaxDontDoIt = window.location.hash === '' ? true : false;
|
||||||
var _minimizedModals = {};
|
var _minimizedModals = {};
|
||||||
|
|
||||||
function openModal(modal) {
|
function openModal(modal) {
|
||||||
@ -49,7 +49,10 @@ function openModal(modal) {
|
|||||||
function closeModal() {
|
function closeModal() {
|
||||||
closeModalHandler('.modal-wrapper');
|
closeModalHandler('.modal-wrapper');
|
||||||
|
|
||||||
window.location.hash = '#';
|
if (window.location.hash !== '') {
|
||||||
|
_watchHashChangeRelaxDontDoIt = true;
|
||||||
|
window.location.hash = '#';
|
||||||
|
}
|
||||||
window.scroll(window.pageXOffset, window_scrollY);
|
window.scroll(window.pageXOffset, window_scrollY);
|
||||||
$('body').css({
|
$('body').css({
|
||||||
'overflow': 'auto',
|
'overflow': 'auto',
|
||||||
@ -109,6 +112,7 @@ function minimizeModal(modal, switchMode) {
|
|||||||
modal.fadeOut('fast', function () {
|
modal.fadeOut('fast', function () {
|
||||||
minimize(modal, scroll);
|
minimize(modal, scroll);
|
||||||
|
|
||||||
|
_watchHashChangeRelaxDontDoIt = true;
|
||||||
window.location.hash = '#';
|
window.location.hash = '#';
|
||||||
window.scroll(window.pageXOffset, window_scrollY);
|
window.scroll(window.pageXOffset, window_scrollY);
|
||||||
$('body').css({
|
$('body').css({
|
||||||
@ -133,8 +137,10 @@ function resumeModal(event) {
|
|||||||
var modal = _minimizedModals[event.data.hashString];
|
var modal = _minimizedModals[event.data.hashString];
|
||||||
if (modal) {
|
if (modal) {
|
||||||
_minimizedModals[event.data.hashString] = undefined;
|
_minimizedModals[event.data.hashString] = undefined;
|
||||||
_watchHashChangeDontLoadModal = true;
|
if (window.location.hash !== event.data.hashString) {
|
||||||
window.location.hash = event.data.hashString;
|
_watchHashChangeRelaxDontDoIt = true;
|
||||||
|
window.location.hash = event.data.hashString;
|
||||||
|
}
|
||||||
modal.self.prependTo('body').fadeIn('fast', function () {
|
modal.self.prependTo('body').fadeIn('fast', function () {
|
||||||
// TODO also need reset modal height here maybe and then compute new scroll
|
// TODO also need reset modal height here maybe and then compute new scroll
|
||||||
if (modal.scroll)
|
if (modal.scroll)
|
||||||
@ -562,8 +568,8 @@ function watchHashChange(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_watchHashChangeDontLoadModal)
|
if (_watchHashChangeRelaxDontDoIt)
|
||||||
_watchHashChangeDontLoadModal = false;
|
_watchHashChangeRelaxDontDoIt = false;
|
||||||
else
|
else
|
||||||
loadModalFromHash();
|
loadModalFromHash();
|
||||||
}
|
}
|
||||||
@ -578,6 +584,10 @@ function loadModalFromHash() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var hashstring = decodeURIComponent(window.location.hash);
|
var hashstring = decodeURIComponent(window.location.hash);
|
||||||
|
if (hashstring === '') {
|
||||||
|
closeModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
var hashdata = hashstring.split(':');
|
var hashdata = hashstring.split(':');
|
||||||
|
|
||||||
if (hashdata[0] !== '#web+twister')
|
if (hashdata[0] !== '#web+twister')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user