/
poll-ui.js.es6
90 lines (82 loc) · 2.43 KB
/
poll-ui.js.es6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { withPluginApi } from 'discourse/lib/plugin-api';
import { onToolbarCreate } from 'discourse/components/d-editor';
import NewComposer from 'discourse/components/d-editor';
import showModal from 'discourse/lib/show-modal';
import ApplicationRoute from 'discourse/routes/application';
import ComposerView from 'discourse/views/composer';
function priorToApi(container)
{
const siteSettings = container.lookup('site-settings:main');
if (siteSettings.poll_ui_enabled) {
if (NewComposer !== "undefined") {
NewComposer.reopen({
actions: {
showPollUI: function() {
showModal('poll-ui').setProperties({composerView: this});
}
}
});
onToolbarCreate(toolbar => {
toolbar.addButton({
id: "poll_ui_button",
group: "extras",
icon: "bar-chart",
action: 'showPollUI'
});
});
} else {
ApplicationRoute.reopen({
actions: {
showPollUI: function (composerView) {
showModal('poll-ui');
this.controllerFor('poll-ui').setProperties({composerViewOld: composerView});
}
}
});
ComposerView.reopen({
initEditor: function () {
// overwrite and wrap.
this._super();
var view = this;
var button_text = I18n.t("poll_ui.composer_button_text");
var btn = $('<button class="wmd-button wmd-poll-ui-button" title="' + button_text + '" aria-label="' + button_text + '"></button>');
btn.click(function () {
view.get("controller").send("showPollUI", view);
});
$("#wmd-button-row,.wmd-button-row").append(btn);
}
});
}
}
}
function initializePlugin(api)
{
const siteSettings = api.container.lookup('site-settings:main');
if (siteSettings.poll_ui_enabled) {
if (NewComposer !== "undefined") {
NewComposer.reopen({
actions: {
showPollUI: function () {
showModal('poll-ui').setProperties({composerView: this});
}
}
});
api.onToolbarCreate(toolbar => {
toolbar.addButton({
id: "poll_ui_button",
group: "extras",
icon: "bar-chart",
action: 'showPollUI'
});
});
}
}
}
export default
{
name: 'poll-ui',
initialize(container)
{
withPluginApi('0.1', api => initializePlugin(api), { noApi: () => priorToApi(container) });
}
};