Ghost/ghost/members-auth-pages/layer0.js
Fabien O'Carroll 07b6e73bd8 Added members lib module (#10260)
* 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
2019-05-07 17:15:50 +02:00

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};
};