1
votes

In order to complete my Wordpress Plugin I want to make tinyMCE to switch between a custom Tag (Some|data|here) and a corresponding Image Display in the WYSIWYG-View.

The event should be triggered on load, safe, autosave, switch view etc. Threre are 4 different events defined, but none of them works as expected.

  1. onBeforeSetContent
  2. onGetContent
  3. onPostProcess
  4. onLoadContent

.

ed.onPostProcess.add(function(ed, o) {
    if (o.set){
       o.content = t._htmlToWysiwyg(o.content, url);
    }
    if (o.get){
       o.content = t._wysiwygToHtml(o.content, t);
    }
});

Anyon know the right way?

1
I want to have my WPG3-Tag saved to the Database and displayed in the HTML-View. On switch to WYSIWYG-View htmlToWysiwyg() will replace it with a Image-Tag and the other way round wysiwygToHtml(). I wanna know what hooks are made to archive this. - digitaldonkey
you will need a custom function to do the replacement (make sure your custom tags do not get stripped out the editor because they are not registered as valid elements). you may use all editor events as a hook - Thariama

1 Answers

0
votes

I do not know what you expect the 4 different events will do (?), but i can see some problems in your code.

1. The object o does not contain fields get and set - so o.get and o.set will never be true! Thus your code will never be called.

2. You are using the variable url, but this one is not defined here.

Working example: You may try to paste a string containing "a" into the editor. Use the following:

ed.onPostProcess.add(function(ed, o) {
    //console.log('o:', o);
    o.content = o.content.replace(/a/g, "A");
});

You should see that all lower 'a's get replaced by 'A's.