jellyfin-web/dashboard-ui/components/paperdialoghelper.js
2015-09-18 13:50:24 -04:00

59 lines
1.3 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;
$(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();
}
window.location.hash = hash;
$(window).on('navigate', onHashChange);
}
function openWithHash(dlg, hash, lockDocumentScroll) {
new paperDialogHashHandler(dlg, hash, lockDocumentScroll);
}
globalScope.PaperDialogHelper = {
openWithHash: openWithHash
};
})(this);