From fa39b952a616405e9b54bfdb77f3c8e6b2870fb3 Mon Sep 17 00:00:00 2001 From: Claudio-Emmolo Date: Tue, 2 Jan 2024 10:38:33 +0100 Subject: [PATCH] Create FAQ button --- src/faq.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/faq.js diff --git a/src/faq.js b/src/faq.js new file mode 100644 index 0000000..d5b9877 --- /dev/null +++ b/src/faq.js @@ -0,0 +1,72 @@ +/* global tinymce */ + +tinymce.PluginManager.add('faq', function (editor, url) { + const openDialog = function () { + return editor.windowManager.open({ + title: 'Faq', + body: { + type: 'panel', + items: [ + { + type: 'input', + inputMode: 'text', + name: 'title', + label: 'Add Title', + }, + { + type: 'textarea', + name: 'content', + label: 'Add Content', + } + ] + }, + buttons: [ + { + type: 'cancel', + text: 'Close' + }, + { + type: 'submit', + text: 'Save', + primary: true + } + ], + onSubmit: function (api) { + const data = api.getData() + /* Insert content when the window form is submitted */ + editor.insertContent('[faq title="' + data.title + '"]' + data.content + '[/faq]') + api.close() + } + }) + } + + /* Add a spoiler icon */ + editor.ui.registry.addIcon('faq', '') + + /* Add a button that opens a window */ + editor.ui.registry.addButton('faq', { + icon: 'faq', + tooltip: 'Add Faq', + onAction: function () { + /* Open window */ + openDialog() + } + }) + /* Adds a menu item, which can then be included in any menu via the menu/menubar configuration */ + editor.ui.registry.addMenuItem('faq', { + text: 'Faq', + onAction: function () { + /* Open window */ + openDialog() + } + }) + /* Return the metadata for the help plugin */ + return { + getMetadata: function () { + return { + name: 'Faq Shortcode', + url: 'https://github.com/The-3Labs-Team/tinymce-laravel-shortcode-plus' + } + } + } +})