mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added lazyLoad support for auth pages
no-issue
This commit is contained in:
parent
ae32d3e2b5
commit
ee11ef5cf4
1 changed files with 13 additions and 2 deletions
|
@ -11,7 +11,7 @@ module.exports = function layer2(options) {
|
|||
container
|
||||
});
|
||||
|
||||
var loadAuth = loadFrame(authUrl, container).then(function (frame) {
|
||||
var loadAuth = lazyLoadFrame(authUrl, container).then(function (frame) {
|
||||
frame.style.position = 'fixed';
|
||||
frame.style.width = '100%';
|
||||
frame.style.height = '100%';
|
||||
|
@ -22,7 +22,7 @@ module.exports = function layer2(options) {
|
|||
});
|
||||
|
||||
function openAuth(hash, query = '') {
|
||||
return loadAuth.then(function (frame) {
|
||||
return loadAuth().then(function (frame) {
|
||||
return new Promise(function (resolve) {
|
||||
frame.src = `${authUrl}#${hash}?${query}`;
|
||||
frame.style.display = 'block';
|
||||
|
@ -71,6 +71,17 @@ module.exports = function layer2(options) {
|
|||
});
|
||||
};
|
||||
|
||||
function lazyLoadFrame(src, container) {
|
||||
let promise;
|
||||
return function getFrame() {
|
||||
if (promise) {
|
||||
return promise;
|
||||
}
|
||||
promise = loadFrame(src, container);
|
||||
return getFrame();
|
||||
}
|
||||
}
|
||||
|
||||
function loadFrame(src, container = document.body) {
|
||||
return new Promise(function (resolve) {
|
||||
const frame = document.createElement('iframe');
|
||||
|
|
Loading…
Add table
Reference in a new issue