keep trying to parse the hash until it works
parent
a34d1793e0
commit
be8ea4102e
@ -1,30 +1,40 @@
|
|||||||
// Stage 0, this gets cached which means we can't change it. boot2-sframe.js is changable.
|
// Stage 0, this gets cached which means we can't change it. boot2-sframe.js is changable.
|
||||||
// Note that this file is meant to be executed only inside of a sandbox iframe.
|
// Note that this file is meant to be executed only inside of a sandbox iframe.
|
||||||
;(function () {
|
;(function () {
|
||||||
var req = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
|
var afterLoaded = function (req) {
|
||||||
req.cfg = req.cfg || {};
|
req.cfg = req.cfg || {};
|
||||||
if (req.pfx) {
|
if (req.pfx) {
|
||||||
req.cfg.onNodeCreated = function (node /*, config, module, path*/) {
|
req.cfg.onNodeCreated = function (node /*, config, module, path*/) {
|
||||||
node.setAttribute('src', req.pfx + node.getAttribute('src'));
|
node.setAttribute('src', req.pfx + node.getAttribute('src'));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
require.config(req.cfg);
|
||||||
|
var txid = Math.random().toString(16).replace('0.', '');
|
||||||
|
var intr;
|
||||||
|
var ready = function () {
|
||||||
|
intr = setInterval(function () {
|
||||||
|
if (typeof(txid) !== 'string') { return; }
|
||||||
|
window.parent.postMessage(JSON.stringify({ q: 'READY', txid: txid }), '*');
|
||||||
|
}, 1);
|
||||||
};
|
};
|
||||||
}
|
if (req.req) { require(req.req, ready); } else { ready(); }
|
||||||
require.config(req.cfg);
|
var onReply = function (msg) {
|
||||||
var txid = Math.random().toString(16).replace('0.', '');
|
var data = JSON.parse(msg.data);
|
||||||
var intr;
|
if (data.txid !== txid) { return; }
|
||||||
var ready = function () {
|
clearInterval(intr);
|
||||||
intr = setInterval(function () {
|
txid = {};
|
||||||
if (typeof(txid) !== 'string') { return; }
|
window.removeEventListener('message', onReply);
|
||||||
window.parent.postMessage(JSON.stringify({ q: 'READY', txid: txid }), '*');
|
require(['/common/sframe-boot2.js'], function () { });
|
||||||
}, 1);
|
};
|
||||||
};
|
window.addEventListener('message', onReply);
|
||||||
if (req.req) { require(req.req, ready); } else { ready(); }
|
|
||||||
var onReply = function (msg) {
|
|
||||||
var data = JSON.parse(msg.data);
|
|
||||||
if (data.txid !== txid) { return; }
|
|
||||||
clearInterval(intr);
|
|
||||||
txid = {};
|
|
||||||
window.removeEventListener('message', onReply);
|
|
||||||
require(['/common/sframe-boot2.js'], function () { });
|
|
||||||
};
|
};
|
||||||
window.addEventListener('message', onReply);
|
|
||||||
|
var intr = setInterval(function () {
|
||||||
|
try {
|
||||||
|
var req = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
|
||||||
|
clearInterval(intr);
|
||||||
|
afterLoaded(req);
|
||||||
|
} catch (e) { console.error(e); }
|
||||||
|
}, 100);
|
||||||
|
|
||||||
}());
|
}());
|
Loading…
Reference in New Issue