discourse/plugins/discourse-details/assets/javascripts/initializers/apply-details.js.es6
Robin Ward c322cccd53 FIX: Memory Leaks when decorating posts (#7749)
* 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.)
2019-06-11 17:21:23 +02:00

37 lines
785 B
JavaScript

import { withPluginApi } from "discourse/lib/plugin-api";
function initializeDetails(api) {
api.decorateCooked($elem => $("details", $elem).details(), {
id: "discourse-details"
});
api.addToolbarPopupMenuOptionsCallback(() => {
return {
action: "insertDetails",
icon: "caret-right",
label: "details.title"
};
});
api.modifyClass("controller:composer", {
actions: {
insertDetails() {
this.toolbarEvent.applySurround(
"\n" + `[details="${I18n.t("composer.details_title")}"]` + "\n",
"\n[/details]\n",
"details_text",
{ multiline: false }
);
}
}
});
}
export default {
name: "apply-details",
initialize() {
withPluginApi("0.8.7", initializeDetails);
}
};