1
votes

I would like to add a clickable button/image/div inside the html editor (not the navigation bar). But when I use the onBeforeSetContent.add function to filter content and add an element with an onclick tag, this tag gets stripped.

This is all done via a tinymce plugin btw since I'm using Wordpress.

//replace shortcode before editor content set
ed.onBeforeSetContent.add(function(ed, o) {
    o.content = t.filter_content(o.content);
});

...

filter_content : function(co) {
    return co.replace(/\[icitspot([^\]]*)\]/g, function(a,b){
        return '<img src="#" onclick="alert(\'abc\')" class="wpSpot mceItem" title="clickme" />';
    });
},
2

2 Answers

3
votes

Instead of using the onclick attribute, click events should be detected in general:

ed.onClick.add(function(ed, e) {
    console.log(e.target);
});

Now you can detect the element that was clicked and determine if it's your button/div.

1
votes

Either use your own solution or you will have to specify onclick as a valid attribute to prevent the stipping of this attribute using the tinymce valid_elements setting.

Example:

valid_elements: "@[id|class|title|style|onmouseover|onclick]," +
"a[name|href|target|title|alt]," +
"#p,blockquote,-ol,-ul,-li,br,img[src|height|width],-sub,-sup,-b,-i,-u," +
"-span[data-mce-type],hr",