mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
switch paperDialogHashHandler from hashchange to pushstate
This commit is contained in:
parent
35a8a1611a
commit
00b18fdc5f
3 changed files with 80 additions and 42 deletions
|
@ -2,18 +2,21 @@
|
|||
|
||||
function paperDialogHashHandler(dlg, hash, resolve, lockDocumentScroll) {
|
||||
|
||||
var self = this;
|
||||
self.originalUrl = window.location.href;
|
||||
var activeElement = document.activeElement;
|
||||
|
||||
function onHashChange(e) {
|
||||
|
||||
var data = e.detail.state || {};
|
||||
var isActive = data.hash == '#' + hash;
|
||||
var isBack = self.originalUrl == window.location.href;
|
||||
|
||||
if (data.direction == 'back') {
|
||||
if (dlg) {
|
||||
if (!isActive) {
|
||||
dlg.close();
|
||||
dlg = null;
|
||||
}
|
||||
}
|
||||
if (isBack || !dlg.opened) {
|
||||
window.removeEventListener('popstate', onHashChange);
|
||||
}
|
||||
|
||||
if (isBack) {
|
||||
self.closedByBack = true;
|
||||
dlg.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,14 +26,29 @@
|
|||
Dashboard.onPopupClose();
|
||||
}
|
||||
|
||||
dlg = null;
|
||||
if (enableHashChange()) {
|
||||
window.removeEventListener('navigate', onHashChange);
|
||||
window.removeEventListener('popstate', onHashChange);
|
||||
|
||||
if (window.location.hash == '#' + hash) {
|
||||
if (!self.closedByBack) {
|
||||
var state = history.state || {};
|
||||
if (state.dialogId == hash) {
|
||||
history.back();
|
||||
}
|
||||
}
|
||||
|
||||
activeElement.focus();
|
||||
|
||||
if (dlg.getAttribute('data-removeonclose') == 'true') {
|
||||
dlg.parentNode.removeChild(dlg);
|
||||
}
|
||||
|
||||
//resolve();
|
||||
// if we just called history.back(), then use a timeout to allow the history events to fire first
|
||||
setTimeout(function () {
|
||||
resolve({
|
||||
element: dlg,
|
||||
closedByBack: self.closedByBack
|
||||
});
|
||||
}, 1);
|
||||
}
|
||||
|
||||
dlg.addEventListener('iron-overlay-closed', onDialogClosed);
|
||||
|
@ -40,23 +58,15 @@
|
|||
Dashboard.onPopupOpen();
|
||||
}
|
||||
|
||||
if (enableHashChange()) {
|
||||
var state = {
|
||||
dialogId: hash,
|
||||
navigate: false
|
||||
};
|
||||
history.pushState(state, "Dialog", hash);
|
||||
|
||||
window.location.hash = hash;
|
||||
jQuery.onStatePushed(state);
|
||||
|
||||
window.addEventListener('navigate', onHashChange);
|
||||
}
|
||||
}
|
||||
|
||||
function enableHashChange() {
|
||||
// It's not firing popstate in response to hashbang changes
|
||||
if (browserInfo.msie) {
|
||||
return false;
|
||||
}
|
||||
if (browserInfo.edge) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
window.addEventListener('popstate', onHashChange);
|
||||
}
|
||||
|
||||
function open(dlg) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue