diff --git a/src/product.js b/src/product.js new file mode 100644 index 0000000..8ecb5ff --- /dev/null +++ b/src/product.js @@ -0,0 +1,73 @@ +/* global tinymce */ + +tinymce.PluginManager.add('product', function (editor, url) { + const openDialog = function () { + return editor.windowManager.open({ + title: 'Product', + body: { + type: 'panel', + items: [ + { + type: 'input', + inputMode: 'numeric', + name: 'id', + label: 'Add the product ID', + }, + { + type: 'input', + inputMode: 'text', + name: 'label', + label: 'Add the product label', + } + ] + }, + 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(`[product id="${data.id}" label="${data.label}"]`) + api.close() + } + }) + } + + /* Add icon */ + editor.ui.registry.addIcon('product', '') + + /* Add a button that opens a window */ + editor.ui.registry.addButton('product', { + icon: 'product', + tooltip: 'Add product', + 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('product', { + text: 'Product', + onAction: function () { + /* Open window */ + openDialog() + } + }) + /* Return the metadata for the help plugin */ + return { + getMetadata: function () { + return { + name: 'Product Shortcode', + url: 'https://github.com/The-3Labs-Team/tinymce-laravel-shortcode-plus' + } + } + } +})