I'm on Modx 2.6.0 with TinyMCEWrapper 2.3.2.
I'm trying to setup a custom dialog that gets populated based on the selected text, similar to how you can "edit" an image that's already been placed. I'm pretty sure my issue is purely javascript/jquery related, but I figured I'd ask here anyway in case someone else is looking to do this in the future. I'm also open to any better ways to do this, but I couldn't find anything TinyMCE specific when searching around.
This is my full plugin javascript.
tinymce.PluginManager.add('doDontBox', function(editor, url) {
// Add a button that opens a window
editor.addButton('doDontBox', {
text: "Do Don't Box",
icon: false,
onclick: function() {
var selectedContent = editor.selection.getContent();
var errorText = '';
var textDo = '';
if (selectedContent.indexOf('&do=') >= 0 && selectedContent.indexOf('&dont=') >= 0 && selectedContent.indexOf('&summary=') >= 0){
errorText = 'All present.';
textDo = selectedContent.match('do=\\`(.*)\\`');
//textDo = selectedContent.match('do(.*)do');
console.log(textDo);
}else if(selectedContent.indexOf('&do=') >= 0 || selectedContent.indexOf('&dont=') >= 0 || selectedContent.indexOf('&summary=') >= 0){
errorText = 'Not all present.';
}else{
errorText = 'Nothing present.';
}
// Open window
editor.windowManager.open({
title: "Do Don't Box",
body: [
{type: 'label', name: 'erorrText', text: errorText},
{type: 'textbox', multiline: true, name: 'textDo', label: 'Do', value: textDo},
{type: 'textbox', multiline: true, name: 'title', label: 'Title', value: selectedContent},
{type: 'textbox', multiline: true, name: 'title', label: 'Title', value: selectedContent}
],
onsubmit: function(e) {
// Insert content when the window form is submitted
editor.insertContent('Title: ' + e.data.title);
}
});
}
});
});
This is the snippet code I'm trying to pull data from when selected. I'm posting the raw HTML Modx ends up wrapping it in, in case that's what's causing issues. The snippet itself is working as expected.
<p>[[!doDontBox? &title=`Title` &titleTag=`h4` &do=`</p>
<ul>
<li>Line 1</li>
<li>Line 2</li>
<li>Some more lines</li>
</ul>
<p>` &dont=`</p>
<ul>
<li>Line 1</li>
<li>Line 2</li>
<li>Some more lines</li>
</ul>
<p>` &summary=`</p>
<p>Some summary stuff!</p>
<p>`]]</p>
The problem area is
textDo = selectedContent.match('do=\\`(.*)\\`');. It doesn't return anything, and I can't figure out what's wrong with the code. I want to return everything inside the &do=`` parameter. I've tried escaping and not escaping various characters, with no luck.
If I use
textDo = selectedContent.match('do(.*)do');, I get back
doDontBox? &title=`Title` &titleTag=`h4` &do,DontBox? &title=`Title` &titleTag=`h4` &, so there's something wrong when I start adding special characters.
I appreciate any help!