This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/initializers/jquery-plugins.js
David Taylor 7e504a1489
DEV: Only patch bootbox methods once in tests (#19222)
We were re-patching the deprecated bootbox methods during every app initialization, which would lead to hundreds of deprecation messages being printed for a single invocation.
2022-11-28 18:14:35 +00:00

59 lines
1.6 KiB
JavaScript

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";
let jqueryPluginsConfigured = false;
export default {
name: "jquery-plugins",
initialize() {
if (jqueryPluginsConfigured) {
return;
}
// Settings for bootbox
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.",
{
id: "discourse.bootbox",
dropFrom: "3.1.0.beta5",
url: "https://meta.discourse.org/t/244902",
}
);
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.",
{
id: "discourse.bootbox",
dropFrom: "3.1.0.beta5",
url: "https://meta.discourse.org/t/244902",
}
);
return originalDialog(...arguments);
};
// Initialize the autocomplete tool
$.fn.autocomplete = autocomplete;
jqueryPluginsConfigured = true;
},
};