From b912bb955fce64eab254ea5ffddf6e7e8459c7ec Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Mon, 31 Oct 2022 14:08:35 -0400 Subject: [PATCH] DEV: Mark `bootbox` as deprecated (#18795) --- .../app/initializers/jquery-plugins.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app/assets/javascripts/discourse/app/initializers/jquery-plugins.js b/app/assets/javascripts/discourse/app/initializers/jquery-plugins.js index 7bcf4275f9c..60487deb30b 100644 --- a/app/assets/javascripts/discourse/app/initializers/jquery-plugins.js +++ b/app/assets/javascripts/discourse/app/initializers/jquery-plugins.js @@ -1,5 +1,7 @@ import autocomplete from "discourse/lib/autocomplete"; import bootbox from "bootbox"; +import { getOwner } from "discourse-common/lib/get-owner"; +import deprecated from "discourse-common/lib/deprecated"; export default { name: "jquery-plugins", @@ -8,6 +10,36 @@ export default { bootbox.animate(false); bootbox.backdrop(true); + // Monkey-patching simple alerts + const originalAlert = bootbox.alert; + bootbox.alert = function () { + if (arguments.length === 1) { + const dialog = getOwner(this).lookup("service:dialog"); + if (dialog) { + deprecated( + "`bootbox.alert` is deprecated, please use the dialog service instead.", + { + dropFrom: "3.1.0.beta5", + } + ); + return dialog.alert(arguments[0]); + } + } + return originalAlert(...arguments); + }; + + // adding deprecation notice for all other dialogs + const originalDialog = bootbox.dialog; + bootbox.dialog = function () { + deprecated( + "`bootbox` is now deprecated, please use the dialog service instead.", + { + dropFrom: "3.1.0.beta5", + } + ); + return originalDialog(...arguments); + }; + // Initialize the autocomplete tool $.fn.autocomplete = autocomplete; },