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