diff options
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-dialogs/www/notification.js')
| -rw-r--r--[-rwxr-xr-x] | StoneIsland/plugins/cordova-plugin-dialogs/www/notification.js | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-dialogs/www/notification.js b/StoneIsland/plugins/cordova-plugin-dialogs/www/notification.js index c3f70d07..4db8f0f2 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-dialogs/www/notification.js +++ b/StoneIsland/plugins/cordova-plugin-dialogs/www/notification.js @@ -37,9 +37,10 @@ module.exports = { * @param {String} buttonLabel Label of the close button (default: OK) */ alert: function(message, completeCallback, title, buttonLabel) { - var _title = (title || "Alert"); + var _message = (typeof message === "string" ? message : JSON.stringify(message)); + var _title = (typeof title === "string" ? title : "Alert"); var _buttonLabel = (buttonLabel || "OK"); - exec(completeCallback, null, "Notification", "alert", [message, _title, _buttonLabel]); + exec(completeCallback, null, "Notification", "alert", [_message, _title, _buttonLabel]); }, /** @@ -52,7 +53,8 @@ module.exports = { * @param {Array} buttonLabels Array of the labels of the buttons (default: ['OK', 'Cancel']) */ confirm: function(message, resultCallback, title, buttonLabels) { - var _title = (title || "Confirm"); + var _message = (typeof message === "string" ? message : JSON.stringify(message)); + var _title = (typeof title === "string" ? title : "Confirm"); var _buttonLabels = (buttonLabels || ["OK", "Cancel"]); // Strings are deprecated! @@ -60,23 +62,9 @@ module.exports = { console.log("Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array)."); } - // Some platforms take an array of button label names. - // Other platforms take a comma separated list. - // For compatibility, we convert to the desired type based on the platform. - if (platform.id == "amazon-fireos" || platform.id == "android" || platform.id == "ios" || - platform.id == "windowsphone" || platform.id == "firefoxos" || platform.id == "ubuntu" || - platform.id == "windows8" || platform.id == "windows") { + _buttonLabels = convertButtonLabels(_buttonLabels); - if (typeof _buttonLabels === 'string') { - _buttonLabels = _buttonLabels.split(","); // not crazy about changing the var type here - } - } else { - if (Array.isArray(_buttonLabels)) { - var buttonLabelArray = _buttonLabels; - _buttonLabels = buttonLabelArray.toString(); - } - } - exec(resultCallback, null, "Notification", "confirm", [message, _title, _buttonLabels]); + exec(resultCallback, null, "Notification", "confirm", [_message, _title, _buttonLabels]); }, /** @@ -92,9 +80,17 @@ module.exports = { * @param {String} defaultText Textbox input value (default: empty string) */ prompt: function(message, resultCallback, title, buttonLabels, defaultText) { - var _message = (message || "Prompt message"); - var _title = (title || "Prompt"); + var _message = (typeof message === "string" ? message : JSON.stringify(message)); + var _title = (typeof title === "string" ? title : "Prompt"); var _buttonLabels = (buttonLabels || ["OK","Cancel"]); + + // Strings are deprecated! + if (typeof _buttonLabels === 'string') { + console.log("Notification.prompt(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array)."); + } + + _buttonLabels = convertButtonLabels(_buttonLabels); + var _defaultText = (defaultText || ""); exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels, _defaultText]); }, @@ -110,3 +106,25 @@ module.exports = { exec(null, null, "Notification", "beep", [ defaultedCount ]); } }; + +function convertButtonLabels(buttonLabels) { + + // Some platforms take an array of button label names. + // Other platforms take a comma separated list. + // For compatibility, we convert to the desired type based on the platform. + if (platform.id == "amazon-fireos" || platform.id == "android" || platform.id == "ios" || + platform.id == "windowsphone" || platform.id == "firefoxos" || platform.id == "ubuntu" || + platform.id == "windows8" || platform.id == "windows") { + + if (typeof buttonLabels === 'string') { + buttonLabels = buttonLabels.split(","); // not crazy about changing the var type here + } + } else { + if (Array.isArray(buttonLabels)) { + var buttonLabelArray = buttonLabels; + buttonLabels = buttonLabelArray.toString(); + } + } + + return buttonLabels; +} |
