Fix race condition with the iframe store

pull/1/head
yflory 8 years ago
parent 4aaaa2f647
commit 1e2cc6bea4

@ -696,50 +696,58 @@ define([
f(void 0, env); f(void 0, env);
}; };
storeToUse.ready(function (err, store) { var todo = function () {
common.store = env.store = store; storeToUse.ready(function (err, store) {
if (USE_FS_STORE) { common.store = env.store = store;
fsStore = store; if (USE_FS_STORE) {
} fsStore = store;
}
$(function() {
// Race condition : if document.body is undefined when alertify.js is loaded, Alertify
// won't work. We have to reset it now to make sure it uses a correct "body"
Alertify.reset();
// Load the new pad when the hash has changed
var oldHash = document.location.hash.slice(1);
window.onhashchange = function () {
var newHash = document.location.hash.slice(1);
var parsedOld = parseHash(oldHash);
var parsedNew = parseHash(newHash);
if (parsedOld && parsedNew && (
parsedOld.channel !== parsedNew.channel
|| parsedOld.mode !== parsedNew.mode
|| parsedOld.key !== parsedNew.key)) {
document.location.reload();
return;
}
if (parsedNew) {
oldHash = newHash;
}
};
// Everything's ready, continue... $(function() {
if($('#pad-iframe').length) { // Race condition : if document.body is undefined when alertify.js is loaded, Alertify
var $iframe = $('#pad-iframe'); // won't work. We have to reset it now to make sure it uses a correct "body"
var iframe = $iframe[0]; Alertify.reset();
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
if (iframeDoc.readyState === 'complete') { // Load the new pad when the hash has changed
cb(); var oldHash = document.location.hash.slice(1);
window.onhashchange = function () {
var newHash = document.location.hash.slice(1);
var parsedOld = parseHash(oldHash);
var parsedNew = parseHash(newHash);
if (parsedOld && parsedNew && (
parsedOld.channel !== parsedNew.channel
|| parsedOld.mode !== parsedNew.mode
|| parsedOld.key !== parsedNew.key)) {
document.location.reload();
return;
}
if (parsedNew) {
oldHash = newHash;
}
};
// Everything's ready, continue...
if($('#pad-iframe').length) {
var $iframe = $('#pad-iframe');
var iframe = $iframe[0];
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
if (iframeDoc.readyState === 'complete') {
cb();
return;
}
$iframe.load(cb);
return; return;
} }
$iframe.load(cb); cb();
return; });
} }, common);
cb(); };
}); // If we use the fs store, make sure the localStorage or iframe store is ready
}, common); if (USE_FS_STORE) {
Store.ready(todo);
return;
}
todo();
}; };
var errorHandlers = []; var errorHandlers = [];

Loading…
Cancel
Save