mirror of
https://github.com/google/blockly.git
synced 2025-12-15 22:00:07 +01:00
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:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user