Blockly.Extensions.buildTooltipForDropdown(..): Deferred validation. (#870)

Defer tooltip message string check until after load, when all Blockly.Msg should be loaded.
Avoids validation in headless mode, due to lack of document.readyState.
This commit is contained in:
Andrew n marshall
2017-01-26 15:12:32 -08:00
committed by GitHub
parent 5891288d60
commit 624afeee94
2 changed files with 34 additions and 4 deletions

View File

@@ -834,3 +834,25 @@ Blockly.utils.insertAfter_ = function(newNode, refNode) {
parentNode.appendChild(newNode);
}
};
/**
* Calls a function after the page has loaded, possibly immediately.
* @param {function()} fn Function to run.
* @throws Error Will throw if no global document can be found (e.g., Node.js).
*/
Blockly.utils.runAfterPageLoad = function(fn) {
if (!document) {
throw new Error('Blockly.utils.runAfterPageLoad() requires browser document.');
}
if (document.readyState === 'complete') {
fn(); // Page has already loaded. Call immediately.
} else {
// Poll readyState.
var readyStateCheckInterval = setInterval(function() {
if (document.readyState === 'complete') {
clearInterval(readyStateCheckInterval);
fn();
}
}, 10);
}
};