I use this code to create a custom tinymce button that changes the class of an image. It is located in the tuner.
ed.addButton('cust_setimgaspreview', { title : 'Set image as a preview image', image : 'ikony/previews.png', onclick : function() { if(ed.selection.getNode().tagName == 'IMG') { ed.selection.getNode().className = 'preview'; } else { alert('You need to select an image.'); } } });
As you can see, I use the "ugly approach" to disable class change for elements other than the image. How can I disable / enable a button in the same way as tinymce using the default buttons (for example, edit an image or edit a link)? I think I need to somehow catch the change in the selection, and then change the state of the button depending on the choice, but I have no ideal how to do this.
source share