jellyfin-web/dashboard-ui/components/paperdialoghelper.js
Luke Pulverenti 68e71b78db move tv data
2015-09-29 12:29:06 -04:00

82 lines
1.8 KiB
JavaScript

(function (globalScope) {
function paperDialogHashHandler(dlg, hash, lockDocumentScroll) {
var isActive = true;
function onHashChange(e, data) {
data = data.state;
isActive = data.hash == '#' + hash;
if (data.direction == 'back') {
if (dlg) {
if (!isActive) {
dlg.close();
dlg = null;
}
}
}
}
function onDialogClosed() {
if (lockDocumentScroll !== false) {
Dashboard.onPopupClose();
}
dlg = null;
if (enableHashChange()) {
$(window).off('navigate', onHashChange);
if (window.location.hash == '#' + hash) {
history.back();
}
}
}
var self = this;
$(dlg).on('iron-overlay-closed', onDialogClosed);
dlg.open();
if (lockDocumentScroll !== false) {
Dashboard.onPopupOpen();
}
if (enableHashChange()) {
window.location.hash = hash;
$(window).on('navigate', onHashChange);
}
}
function enableHashChange() {
// It's not firing popstate in response to hashbang changes
if ($.browser.msie) {
return false;
}
return true;
}
function openWithHash(dlg, hash, lockDocumentScroll) {
new paperDialogHashHandler(dlg, hash, lockDocumentScroll);
}
function close(dlg) {
if (enableHashChange()) {
history.back();
} else {
dlg.close();
}
}
globalScope.PaperDialogHelper = {
openWithHash: openWithHash,
close: close
};
})(this);