Как передать выделенный текст плагину WindowManager Tinymce 5 - PullRequest
0 голосов
/ 27 апреля 2020

Я сделал этот простой плагин ABBR для tinymce 5. Когда я выделю аббревиатуру в текстовой области и нажму на кнопку abbr, текст и объяснение должны быть помещены в editor.windowManager.open. Как это можно установить?

//Tags for acronyms abbr plugin
tinymce.PluginManager.add('abbr', function(editor, url) {

    var openDialog = function () {
    var node = editor.selection.getNode();
    var selectedText = editor.selection.getContent({ format: 'text' });

    if (node.nodeName == 'ABBR') {
        // If ABBR is already present then remove it
        editor.dom.remove(node, true);
    } else {
       return editor.windowManager.open({
          title: '<abbr> element',
           body: {
               type: 'panel',
               items: [
                   {
                       type: 'input',
                       name: 'title',
                       label: 'Word (a shortened word or phrase)'
                   },
                {
                       type: 'input',
                       name: 'explain',
                       label: 'Explain (full-text explanation)'
                }
               ]
           },
           buttons: [
               {
                   type: 'cancel',
                   text: 'Close'
               },
               {
                   type: 'submit',
                   text: 'Save',
                   primary: true
               }
           ],
           onSubmit: function (api) {
           var data = api.getData();
            if(data.title !== false && data.title != '' && data.explain !== false && data.explain != ''){
                //Insert content when the window form is submitted
                editor.insertContent('<abbr class="abbr" title="' + data.explain + '" tabindex="0">' + data.title + '</abbr>&nbsp;');
            }
               api.close();
           }
       });
     }
   };

    editor.ui.registry.addIcon('abbr', '<svg width="20" height="20"><path d="M17.926 4.474c-0.434-0.592-1.039-1.283-1.703-1.947s-1.356-1.269-1.947-1.703c-1.007-0.739-1.496-0.824-1.776-0.824h-9.688c-0.862 0-1.563 0.701-1.563 1.563v16.875c0 0.862 0.701 1.563 1.563 1.563h14.375c0.862 0 1.563-0.701 1.563-1.563v-12.188c0-0.28-0.085-0.769-0.824-1.776zM15.339 3.411c0.6 0.6 1.070 1.141 1.418 1.589h-3.007v-3.007c0.449 0.347 0.99 0.818 1.589 1.417zM17.5 18.438c0 0.169-0.143 0.313-0.313 0.313h-14.375c-0.169 0-0.313-0.143-0.313-0.313v-16.875c0-0.169 0.143-0.313 0.313-0.313 0 0 9.687-0 9.688 0v4.375c0 0.345 0.28 0.625 0.625 0.625h4.375v12.188z"></path><path d="M14.375 16.25h-8.75c-0.345 0-0.625-0.28-0.625-0.625s0.28-0.625 0.625-0.625h8.75c0.345 0 0.625 0.28 0.625 0.625s-0.28 0.625-0.625 0.625z"></path><path d="M14.375 13.75h-8.75c-0.345 0-0.625-0.28-0.625-0.625s0.28-0.625 0.625-0.625h8.75c0.345 0 0.625 0.28 0.625 0.625s-0.28 0.625-0.625 0.625z"></path><path d="M14.375 11.25h-8.75c-0.345 0-0.625-0.28-0.625-0.625s0.28-0.625 0.625-0.625h8.75c0.345 0 0.625 0.28 0.625 0.625s-0.28 0.625-0.625 0.625z"></path></svg>');

    // Add a button that opens a window
    editor.ui.registry.addButton('abbr', {
        icon: 'abbr',
        tooltip: 'Tags for acronyms',
        onAction: function () {
            // Open window
            openDialog();
        }
    });

    return {
        getMetadata: function () {
            return {
                name: "Acronyms abbr plugin",
                url: "https://www.cfconsultancy.nl"
            };
        }
    };
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...