1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/components/paperdialoghelper.js

106 lines
2.6 KiB
JavaScript
Raw Normal View History

2015-09-17 12:04:04 -04:00
(function (globalScope) {
function paperDialogHashHandler(dlg, hash, lockDocumentScroll) {
2015-09-17 12:04:04 -04:00
function onHashChange(e, data) {
data = data.state;
2015-09-29 13:35:23 -04:00
var isActive = data.hash == '#' + hash;
2015-09-17 12:04:04 -04:00
if (data.direction == 'back') {
if (dlg) {
2015-09-17 13:24:23 -04:00
if (!isActive) {
2015-09-17 12:04:04 -04:00
dlg.close();
dlg = null;
}
}
}
}
function onDialogClosed() {
if (lockDocumentScroll !== false) {
Dashboard.onPopupClose();
}
2015-09-17 17:26:06 -04:00
2015-09-17 12:04:04 -04:00
dlg = null;
2015-09-29 12:29:06 -04:00
if (enableHashChange()) {
$(window).off('navigate', onHashChange);
2015-09-17 12:04:04 -04:00
2015-09-29 12:29:06 -04:00
if (window.location.hash == '#' + hash) {
history.back();
}
2015-09-17 12:04:04 -04:00
}
}
var self = this;
$(dlg).on('iron-overlay-closed', onDialogClosed);
dlg.open();
if (lockDocumentScroll !== false) {
Dashboard.onPopupOpen();
}
2015-09-17 12:04:04 -04:00
2015-09-29 12:29:06 -04:00
if (enableHashChange()) {
window.location.hash = hash;
$(window).on('navigate', onHashChange);
}
}
2015-09-17 12:04:04 -04:00
2015-09-29 12:29:06 -04:00
function enableHashChange() {
// It's not firing popstate in response to hashbang changes
if ($.browser.msie) {
return false;
}
return true;
2015-09-17 12:04:04 -04:00
}
function openWithHash(dlg, hash, lockDocumentScroll) {
2015-09-17 12:04:04 -04:00
new paperDialogHashHandler(dlg, hash, lockDocumentScroll);
2015-09-17 12:04:04 -04:00
}
2015-09-29 12:29:06 -04:00
function close(dlg) {
if (enableHashChange()) {
2015-10-02 02:14:04 -04:00
if (dlg.opened) {
history.back();
}
2015-09-29 12:29:06 -04:00
} else {
dlg.close();
}
}
2015-10-02 02:14:04 -04:00
function createDialog() {
var dlg = document.createElement('paper-dialog');
dlg.setAttribute('with-backdrop', 'with-backdrop');
dlg.setAttribute('role', 'alertdialog');
// without this safari will scroll the background instead of the dialog contents
// but not needed here since this is already on top of an existing dialog
dlg.setAttribute('modal', 'modal');
// seeing max call stack size exceeded in the debugger with this
dlg.setAttribute('noAutoFocus', 'noAutoFocus');
dlg.entryAnimation = 'scale-up-animation';
dlg.exitAnimation = 'fade-out-animation';
dlg.classList.add('fullscreen-editor-paper-dialog');
dlg.classList.add('ui-body-b');
dlg.classList.add('smoothScrollY');
return dlg;
}
2015-09-17 12:04:04 -04:00
globalScope.PaperDialogHelper = {
2015-09-29 12:29:06 -04:00
openWithHash: openWithHash,
2015-10-02 02:14:04 -04:00
close: close,
createDialog: createDialog
2015-09-17 12:04:04 -04:00
};
})(this);