2018-05-04 14:51:41 +08:00
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
|
|
import showModal from "discourse/lib/show-modal";
|
|
|
|
|
|
|
|
function initializeDiscourseLocalDates(api) {
|
2019-06-11 23:21:23 +08:00
|
|
|
api.decorateCooked(
|
|
|
|
$elem => {
|
|
|
|
$(".discourse-local-date", $elem).applyLocalDates();
|
|
|
|
},
|
|
|
|
{ id: "discourse-local-date" }
|
|
|
|
);
|
2018-05-04 14:51:41 +08:00
|
|
|
|
2019-04-08 21:52:09 +08:00
|
|
|
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)
|
|
|
|
});
|
2018-05-04 14:51:41 +08:00
|
|
|
});
|
|
|
|
|
2019-04-08 21:52:09 +08:00
|
|
|
api.modifyClass("component:d-editor", {
|
2018-05-04 14:51:41 +08:00
|
|
|
actions: {
|
2019-04-08 21:52:09 +08:00
|
|
|
insertDiscourseLocalDate(toolbarEvent) {
|
2018-05-04 14:51:41 +08:00
|
|
|
showModal("discourse-local-dates-create-modal").setProperties({
|
2019-04-08 21:52:09 +08:00
|
|
|
toolbarEvent
|
2018-05-04 14:51:41 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|