Move alert/confirm/prompt to a new file, dialog.js (#5457)

* Migrate prompt/alert/confirm to dedicated module

* Update core/blockly.js to pass through calls to prompt/alert/confirm to core/dialog.js

* Update calls to Blockly.prompt/alert/confirm to dialog.prompt/alert/confirm

* Fix typo and errant redeclaration of Blockly.prompt

* Clarify JSDoc on customizing Blockly.dialog.alert/confirm/prompt
This commit is contained in:
Aaron Dodson
2021-09-14 08:19:53 -07:00
committed by GitHub
parent ff9320f8d9
commit ce8e7921a2
12 changed files with 174 additions and 60 deletions

View File

@@ -375,7 +375,7 @@ Code.checkAllGeneratorFunctionsDefined = function(generator) {
if (!valid) {
var msg = 'The generator code for the following blocks not specified for ' +
generator.name_ + ':\n - ' + missingBlockGenerators.join('\n - ');
Blockly.alert(msg); // Assuming synchronous. No callback.
Blockly.dialog.alert(msg); // Assuming synchronous. No callback.
}
return valid;
};

View File

@@ -13,16 +13,16 @@
*/
CustomDialog = {};
/** Override Blockly.alert() with custom implementation. */
Blockly.alert = function(message, callback) {
/** Override Blockly.dialog.alert() with custom implementation. */
Blockly.dialog.setAlert(function(message, callback) {
console.log('Alert: ' + message);
CustomDialog.show('Alert', message, {
onCancel: callback
});
};
});
/** Override Blockly.confirm() with custom implementation. */
Blockly.confirm = function(message, callback) {
/** Override Blockly.dialog.confirm() with custom implementation. */
Blockly.dialog.setConfirm(function(message, callback) {
console.log('Confirm: ' + message);
CustomDialog.show('Confirm', message, {
showOkay: true,
@@ -34,10 +34,10 @@ Blockly.confirm = function(message, callback) {
callback(false);
}
});
};
});
/** Override Blockly.prompt() with custom implementation. */
Blockly.prompt = function(message, defaultValue, callback) {
/** Override Blockly.dialog.prompt() with custom implementation. */
Blockly.dialog.setPrompt(function(message, defaultValue, callback) {
console.log('Prompt: ' + message);
CustomDialog.show('Prompt', message, {
showInput: true,
@@ -51,7 +51,7 @@ Blockly.prompt = function(message, defaultValue, callback) {
}
});
CustomDialog.inputField.value = defaultValue;
};
});
/** Hides any currently visible dialog. */
CustomDialog.hide = function() {

View File

@@ -70,7 +70,7 @@ CustomFields.FieldPitch.prototype.showEditor_ = function() {
var div = Blockly.WidgetDiv.getDiv();
if (!div.firstChild) {
// Mobile interface uses Blockly.prompt.
// Mobile interface uses Blockly.dialog.prompt.
return;
}
// Build the DOM.