Site Builder
Editing:
promptinator-tinymce.js
writable 0666
/* global tinymce, promptinatorL10n */ (function () { 'use strict'; /** * Promptinator TinyMCE plugin * Adds a single “[P]” toolbar button that can create, edit or remove * <div class="Promptinator" data-edit="…" data-think="…"> wrappers. * * All user‑visible strings come from the promptinatorL10n object that * is printed by wp_localize_script() in promptinator‑shortcode.php. */ tinymce.PluginManager.add('promptinator', function (editor /* , url */) { /* ------------------------------------------------------------------ * Helper: main insert / manage button * ---------------------------------------------------------------- */ editor.addButton('promptinator', { text: '[P]', icon: false, title: promptinatorL10n.insertPrompt, onclick: function () { // 1) Are we inside an existing wrapper? var node = editor.selection.getNode(); var wrapper = editor.dom.getParent(node, '.Promptinator'); if (wrapper) { /* ------------------------------------------------------ * Manage existing wrapper: choose an action * ---------------------------------------------------- */ editor.windowManager.open({ title: promptinatorL10n.promptOptions, width: 300, body: [{ type: 'listbox', name: 'action', label: promptinatorL10n.action, values: [ { text: promptinatorL10n.selectAction, value: '' }, { text: promptinatorL10n.editPrompt, value: 'edit' }, { text: promptinatorL10n.removePromptinator, value: 'remove' } ], value: '', style: 'width:100%;' }], onsubmit: function (e) { if (e.data.action === 'remove') { // unwrap – keep inner HTML editor.dom.remove(wrapper, true); } else if (e.data.action === 'edit') { // pull existing attributes & content var inner = wrapper.innerHTML; var editVal = wrapper.getAttribute('data-edit') || '1'; var thinkVal = wrapper.getAttribute('data-think') || '1'; openDialog(inner, editVal, thinkVal, wrapper); } } }); return; // stop here when managing } /* ---------------------------------------------------------- * Normal insert path * ------------------------------------------------------- */ var sel = editor.selection.getContent({ format: 'html' }); if (!sel) { editor.windowManager.alert(promptinatorL10n.selectTextAlert); return; } openDialog(sel, '1', '1'); } }); /* ------------------------------------------------------------------ * shared insert / edit dialog * ---------------------------------------------------------------- */ function openDialog(content, editVal, thinkVal, targetDiv) { editor.windowManager.open({ title: promptinatorL10n.promptOptions, body: [ { type: 'textbox', name: 'content', label: promptinatorL10n.promptHtml, multiline: true, value: content }, { type: 'listbox', name: 'edit', label: promptinatorL10n.showEditor, values: [ { text: promptinatorL10n.yes, value: '1' }, { text: promptinatorL10n.no, value: '0' } ], value: editVal }, { type: 'listbox', name: 'think', label: promptinatorL10n.connectAI, values: [ { text: promptinatorL10n.yes, value: '1' }, { text: promptinatorL10n.no, value: '0' } ], value: thinkVal } ], onsubmit: function (e) { var html = '<div class="Promptinator" data-edit="' + e.data.edit + '" data-think="' + e.data.think + '">' + e.data.content + '</div>'; if (targetDiv) { // replace existing wrapper editor.selection.select(targetDiv); editor.selection.setContent(html); } else { // insert new wrapper editor.insertContent(html); } } }); } /* ------------------------------------------------------------------ * TinyMCE 4/5 compatibility – no extra controls required * ---------------------------------------------------------------- */ return {}; }); })();
Save changes
Create folder
writable 0777
Create
Cancel