51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
/**
|
|
* Initialisation de TinyMCE avec des boutons personnalisés pour les titres h3 à h6.
|
|
*/
|
|
|
|
|
|
tinymce.init({
|
|
selector: "textarea",
|
|
height: 400,
|
|
language: "fr-FR",
|
|
branding: false,
|
|
menubar: false,
|
|
menu: {},
|
|
plugins: "link, lists fullscreen",
|
|
|
|
toolbar: "h3 h4 h5 h6 | undo redo | link | bold | bullist numlist | outdent indent | fullscreen",
|
|
license_key: 'gpl',
|
|
setup: function (editor) {
|
|
['h3', 'h4', 'h5', 'h6'].forEach(function (tag) {
|
|
editor.ui.registry.addToggleButton(tag, {
|
|
text: tag.toUpperCase(),
|
|
tooltip: 'Titre ' + tag.substring(1),
|
|
onAction: function () {
|
|
try {
|
|
if (editor.formatter && typeof editor.formatter.toggle === 'function') {
|
|
editor.formatter.toggle(tag);
|
|
} else {
|
|
editor.execCommand('FormatBlock', false, tag);
|
|
}
|
|
} catch (e) {
|
|
// fallback
|
|
editor.execCommand('FormatBlock', false, tag);
|
|
}
|
|
},
|
|
onSetup: function (api) {
|
|
var nodeChangeHandler = function () {
|
|
try {
|
|
api.setActive(editor.formatter ? !!editor.formatter.match(tag) : false);
|
|
} catch (e) {
|
|
api.setActive(false);
|
|
}
|
|
};
|
|
editor.on('NodeChange', nodeChangeHandler);
|
|
return function () {
|
|
editor.off('NodeChange', nodeChangeHandler);
|
|
};
|
|
}
|
|
});
|
|
});
|
|
}
|
|
});
|