mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 12:53:13 +03:00
b219e26ea6
* Added members library inc. gateway refs #10213 * Added the auth pages and build steps for them refs #10213 * Cleaned up logs * Updated gruntfile to run yarn for member auth * Design refinements on members popups * UI refinements * Updated backend call to trigger only if frontend validation passes * Design refinements for error messages * Added error message for email failure * Updated request-password-reset to not attempt to send headers twice * Updated preact publicPath to relative path * Build auth pages on init
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
/* globals window */
|
|
module.exports = function layer0(frame) {
|
|
var getuid = (function (i) {
|
|
return function () {
|
|
return i += 1;
|
|
};
|
|
})(1);
|
|
var origin = new URL(frame.getAttribute('src')).origin;
|
|
var handlers = {};
|
|
var listener = function () {};
|
|
|
|
window.addEventListener('message', function (event) {
|
|
if (event.origin !== origin) {
|
|
return;
|
|
}
|
|
if (!event.data || !event.data.uid) {
|
|
if (event.data.event) {
|
|
return listener(event.data);
|
|
}
|
|
return;
|
|
}
|
|
var handler = handlers[event.data.uid];
|
|
if (!handler) {
|
|
return;
|
|
}
|
|
delete handlers[event.data.uid];
|
|
handler(event.data.error, event.data.data);
|
|
});
|
|
|
|
function call(method, options, cb) {
|
|
var uid = getuid();
|
|
var data = {uid, method, options};
|
|
handlers[uid] = cb;
|
|
frame.contentWindow.postMessage(data, origin);
|
|
}
|
|
|
|
function listen(fn) {
|
|
listener = fn;
|
|
}
|
|
|
|
return {call, listen};
|
|
};
|