mirror of
https://github.com/twisterarmy/twister-html.git
synced 2025-03-12 05:21:18 +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
|
||||
|
||||
var window_scrollY = 0;
|
||||
var _watchHashChangeDontLoadModal = false;
|
||||
var _watchHashChangeRelaxDontDoIt = window.location.hash === '' ? true : false;
|
||||
var _minimizedModals = {};
|
||||
|
||||
function openModal(modal) {
|
||||
@ -49,7 +49,10 @@ function openModal(modal) {
|
||||
function closeModal() {
|
||||
closeModalHandler('.modal-wrapper');
|
||||
|
||||
window.location.hash = '#';
|
||||
if (window.location.hash !== '') {
|
||||
_watchHashChangeRelaxDontDoIt = true;
|
||||
window.location.hash = '#';
|
||||
}
|
||||
window.scroll(window.pageXOffset, window_scrollY);
|
||||
$('body').css({
|
||||
'overflow': 'auto',
|
||||
@ -109,6 +112,7 @@ function minimizeModal(modal, switchMode) {
|
||||
modal.fadeOut('fast', function () {
|
||||
minimize(modal, scroll);
|
||||
|
||||
_watchHashChangeRelaxDontDoIt = true;
|
||||
window.location.hash = '#';
|
||||
window.scroll(window.pageXOffset, window_scrollY);
|
||||
$('body').css({
|
||||
@ -133,8 +137,10 @@ function resumeModal(event) {
|
||||
var modal = _minimizedModals[event.data.hashString];
|
||||
if (modal) {
|
||||
_minimizedModals[event.data.hashString] = undefined;
|
||||
_watchHashChangeDontLoadModal = true;
|
||||
window.location.hash = event.data.hashString;
|
||||
if (window.location.hash !== event.data.hashString) {
|
||||
_watchHashChangeRelaxDontDoIt = true;
|
||||
window.location.hash = event.data.hashString;
|
||||
}
|
||||
modal.self.prependTo('body').fadeIn('fast', function () {
|
||||
// TODO also need reset modal height here maybe and then compute new scroll
|
||||
if (modal.scroll)
|
||||
@ -562,8 +568,8 @@ function watchHashChange(e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (_watchHashChangeDontLoadModal)
|
||||
_watchHashChangeDontLoadModal = false;
|
||||
if (_watchHashChangeRelaxDontDoIt)
|
||||
_watchHashChangeRelaxDontDoIt = false;
|
||||
else
|
||||
loadModalFromHash();
|
||||
}
|
||||
@ -578,6 +584,10 @@ function loadModalFromHash() {
|
||||
}
|
||||
|
||||
var hashstring = decodeURIComponent(window.location.hash);
|
||||
if (hashstring === '') {
|
||||
closeModal();
|
||||
return;
|
||||
}
|
||||
var hashdata = hashstring.split(':');
|
||||
|
||||
if (hashdata[0] !== '#web+twister')
|
||||
|
Loading…
x
Reference in New Issue
Block a user