Remove obsolete parts from overlay
This commit is contained in:
+5
-17
@@ -4,10 +4,10 @@
|
|||||||
// low-level focus/Escape/bfcache patterns from modal.js rather than that
|
// low-level focus/Escape/bfcache patterns from modal.js rather than that
|
||||||
// component's panel chrome.
|
// component's panel chrome.
|
||||||
//
|
//
|
||||||
// openOverlay(node, opts) MOVES `node` (an existing rail <aside>) into the
|
// openOverlay(node) MOVES `node` (an existing rail <aside>) into the overlay
|
||||||
// overlay body and restores it to its original DOM position on close, so the
|
// body and restores it to its original DOM position on close, so the rail keeps
|
||||||
// rail keeps its state (expanded tree folders, rendered TOC). Only one overlay
|
// its state (expanded tree folders, rendered TOC). Only one overlay is open at
|
||||||
// is open at a time.
|
// a time.
|
||||||
(function () {
|
(function () {
|
||||||
var overlay = null;
|
var overlay = null;
|
||||||
var bodyEl = null;
|
var bodyEl = null;
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
var placeholder = null; // marks where to restore it
|
var placeholder = null; // marks where to restore it
|
||||||
var prevFocus = null;
|
var prevFocus = null;
|
||||||
var onKeydown = null;
|
var onKeydown = null;
|
||||||
var onCloseCb = null; // opts.onClose of the currently hosted node
|
|
||||||
|
|
||||||
function build() {
|
function build() {
|
||||||
overlay = document.createElement('div');
|
overlay = document.createElement('div');
|
||||||
@@ -51,13 +50,11 @@
|
|||||||
overlay.appendChild(bodyEl);
|
overlay.appendChild(bodyEl);
|
||||||
}
|
}
|
||||||
|
|
||||||
function open(node, opts) {
|
function open(node) {
|
||||||
if (overlay && overlay.parentNode) close();
|
if (overlay && overlay.parentNode) close();
|
||||||
if (!overlay) build();
|
if (!overlay) build();
|
||||||
opts = opts || {};
|
|
||||||
|
|
||||||
prevFocus = document.activeElement;
|
prevFocus = document.activeElement;
|
||||||
onCloseCb = typeof opts.onClose === 'function' ? opts.onClose : null;
|
|
||||||
hosted = node;
|
hosted = node;
|
||||||
placeholder = document.createComment('overlay-slot');
|
placeholder = document.createComment('overlay-slot');
|
||||||
node.parentNode.insertBefore(placeholder, node);
|
node.parentNode.insertBefore(placeholder, node);
|
||||||
@@ -72,9 +69,6 @@
|
|||||||
document.addEventListener('keydown', onKeydown);
|
document.addEventListener('keydown', onKeydown);
|
||||||
|
|
||||||
setTimeout(function () { closeBtn.focus(); }, 0);
|
setTimeout(function () { closeBtn.focus(); }, 0);
|
||||||
|
|
||||||
if (typeof opts.onOpen === 'function') opts.onOpen();
|
|
||||||
return { close: close };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
@@ -98,12 +92,6 @@
|
|||||||
if (toRestore && toRestore.focus) {
|
if (toRestore && toRestore.focus) {
|
||||||
try { toRestore.focus(); } catch (e) {}
|
try { toRestore.focus(); } catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fires after the node is back in its original spot, so the callback
|
|
||||||
// sees the final DOM.
|
|
||||||
var cb = onCloseCb;
|
|
||||||
onCloseCb = null;
|
|
||||||
if (cb) cb();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Belt-and-suspenders bfcache guard: force the overlay closed (restoring
|
// Belt-and-suspenders bfcache guard: force the overlay closed (restoring
|
||||||
|
|||||||
Reference in New Issue
Block a user