mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 13:33:40 +08:00
c322cccd53
* Remove long-deprecated method * FIX: Memory Leaks when decorating posts Previously we'd keep creating mixins dynamically when decorating the same class. This code changes the API to recommend an `id` parameter for each decorator which will avoid leaks. All plugins should be updated to include this parameter, although if they don't in the meantime it'll just mean a warning in the console (and a continued leak.)
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
import showModal from "discourse/lib/show-modal";
|
|
|
|
function initializeDiscourseLocalDates(api) {
|
|
api.decorateCooked(
|
|
$elem => {
|
|
$(".discourse-local-date", $elem).applyLocalDates();
|
|
},
|
|
{ id: "discourse-local-date" }
|
|
);
|
|
|
|
api.onToolbarCreate(toolbar => {
|
|
toolbar.addButton({
|
|
title: "discourse_local_dates.title",
|
|
id: "local-dates",
|
|
group: "extras",
|
|
icon: "calendar-alt",
|
|
sendAction: event =>
|
|
toolbar.context.send("insertDiscourseLocalDate", event)
|
|
});
|
|
});
|
|
|
|
api.modifyClass("component:d-editor", {
|
|
actions: {
|
|
insertDiscourseLocalDate(toolbarEvent) {
|
|
showModal("discourse-local-dates-create-modal").setProperties({
|
|
toolbarEvent
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
export default {
|
|
name: "discourse-local-dates",
|
|
|
|
initialize(container) {
|
|
const siteSettings = container.lookup("site-settings:main");
|
|
if (siteSettings.discourse_local_dates_enabled) {
|
|
withPluginApi("0.8.8", initializeDiscourseLocalDates);
|
|
}
|
|
}
|
|
};
|