177 lines
4.8 KiB
HTML
177 lines
4.8 KiB
HTML
<script type="text/discourse-plugin" version="0.8">
|
|
const { iconNode } = require("discourse-common/lib/icon-library");
|
|
// TOOLBAR
|
|
api.onToolbarCreate(toolbar => {
|
|
toolbar.addButton({
|
|
id: "underline_button",
|
|
group: "fontStyles",
|
|
icon: "underline",
|
|
perform: e => e.applySurround('[u]', '[/u]', 'underline_text')
|
|
});
|
|
});
|
|
api.onToolbarCreate(toolbar => {
|
|
toolbar.addButton({
|
|
id: "strikethrough_button",
|
|
group: "fontStyles",
|
|
icon: "strikethrough",
|
|
perform: e => e.applySurround('<s>', '</s>', 'strikethrough_text')
|
|
});
|
|
});
|
|
api.onToolbarCreate(toolbar => {
|
|
toolbar.addButton({
|
|
id: "superscript_button",
|
|
group: "fontStyles",
|
|
icon: "superscript",
|
|
perform: e => e.applySurround('<sup>', '</sup>', 'superscript_text')
|
|
});
|
|
});
|
|
api.onToolbarCreate(toolbar => {
|
|
toolbar.addButton({
|
|
id: "subscript_button",
|
|
group: "fontStyles",
|
|
icon: "subscript",
|
|
perform: e => e.applySurround('<sub>', '</sub>', 'subscript_text')
|
|
});
|
|
});
|
|
api.onToolbarCreate(toolbar => {
|
|
toolbar.addButton({
|
|
id: "align_center_button",
|
|
group: "extras",
|
|
icon: "align-center",
|
|
perform: e => e.applySurround('[wrap="center"]\n', '\n[/wrap]', 'align_center_text')
|
|
});
|
|
});
|
|
api.onToolbarCreate(toolbar => {
|
|
toolbar.addButton({
|
|
id: "align_justify_button",
|
|
group: "extras",
|
|
icon: "align-justify",
|
|
perform: e => e.applySurround('[wrap="justify"]\n', '\n[/wrap]', 'align_justify_text')
|
|
});
|
|
});
|
|
|
|
// EXTRAS
|
|
api.addToolbarPopupMenuOptionsCallback(() => {
|
|
return {
|
|
action: "bleucolor",
|
|
icon: "palette",
|
|
label: "bleu_color_button"
|
|
};
|
|
});
|
|
api.addToolbarPopupMenuOptionsCallback(() => {
|
|
return {
|
|
action: "rosecolor",
|
|
icon: "palette",
|
|
label: "rose_color_button"
|
|
};
|
|
});
|
|
api.addToolbarPopupMenuOptionsCallback(() => {
|
|
return {
|
|
action: "jaunecolor",
|
|
icon: "palette",
|
|
label: "jaune_color_button"
|
|
};
|
|
});
|
|
api.addToolbarPopupMenuOptionsCallback(() => {
|
|
return {
|
|
action: "orangecolor",
|
|
icon: "palette",
|
|
label: "orange_color_button"
|
|
};
|
|
});
|
|
api.addToolbarPopupMenuOptionsCallback(() => {
|
|
return {
|
|
action: "rougecolor",
|
|
icon: "palette",
|
|
label: "rouge_color_button"
|
|
};
|
|
});
|
|
api.addToolbarPopupMenuOptionsCallback(() => {
|
|
return {
|
|
action: "vertcolor",
|
|
icon: "palette",
|
|
label: "vert_color_button"
|
|
};
|
|
});
|
|
|
|
api.modifyClass("controller:composer", {
|
|
actions: {
|
|
bleucolor() {
|
|
this.get("toolbarEvent").applySurround('[color=#068EEF]', '[/color]', "bleu_color_text");
|
|
},
|
|
rosecolor() {
|
|
this.get("toolbarEvent").applySurround('[color=#EF06A0]', '[/color]', "rose_color_text");
|
|
},
|
|
jaunecolor() {
|
|
this.get("toolbarEvent").applySurround('[color=#EFC906]', '[/color]', "jaune_color_text");
|
|
},
|
|
orangecolor() {
|
|
this.get("toolbarEvent").applySurround('[color=#EF8806]', '[/color]', "orange_color_text");
|
|
},
|
|
rougecolor() {
|
|
this.get("toolbarEvent").applySurround('[color=#EF0606]', '[/color]', "rouge_color_text");
|
|
},
|
|
vertcolor() {
|
|
this.get("toolbarEvent").applySurround('[color=#2A821C]', '[/color]', "vert_color_text");
|
|
},
|
|
}
|
|
});
|
|
|
|
// TEXTS
|
|
let translations = I18n.translations[I18n.currentLocale()].js;
|
|
if (!translations) {
|
|
translations = {};
|
|
}
|
|
if (!translations.composer) {
|
|
translations.composer = {};
|
|
}
|
|
|
|
// Define default values for buttons
|
|
const defaultButtons = {
|
|
underline_button: "Souligner",
|
|
underline_text: "Texte",
|
|
|
|
strikethrough_button: "Barrer",
|
|
strikethrough_text: "Texte",
|
|
|
|
superscript_button: "Exposant",
|
|
superscript_text: "Texte",
|
|
|
|
subscript_button: "Indice",
|
|
subscript_text: "Texte",
|
|
|
|
align_center_button: "Centrer",
|
|
align_center_text: "Texte",
|
|
|
|
align_justify_button: "Justifier",
|
|
align_justify_text: "Texte",
|
|
|
|
// Définissez les boutons de couleur avec un traitement spécial
|
|
bleu_color_button: "Colorer en bleu",
|
|
bleu_color_text: "Texte",
|
|
|
|
rose_color_button: "Colorer en rose",
|
|
rose_color_text: "Texte",
|
|
|
|
jaune_color_button: "Colorer en jaune",
|
|
jaune_color_text: "Texte",
|
|
|
|
orangecolor_button: "Colorer en orange",
|
|
orangecolor_text: "Texte",
|
|
|
|
rouge_color_button: "Colorer en rouge",
|
|
rouge_color_text: "Texte",
|
|
|
|
vert_color_button: "Colorer en vert",
|
|
vert_color_text: "Texte"
|
|
};
|
|
|
|
// Assign default values if translations are not present
|
|
Object.keys(defaultButtons).forEach(key => {
|
|
const settingKey = key.replace("_button", "");
|
|
translations.composer[key + "_title"] = settings[settingKey] && settings[settingKey].default ? settings[settingKey].default : defaultButtons[key];
|
|
translations.composer[key + "_text"] = settings[key + "_text"] && settings[key + "_text"].default ? settings[key + "_text"].default : defaultButtons[key];
|
|
});
|
|
|
|
</script>
|