Rick de Graaf
Rick de Graaf

Reputation: 958

TinyMCE setActive to false advImage plugin

I have a custom youtube plugin that adds an image to my tinyMCE editor and gets replaced with embedded or other code on the server side.

The only thing thats left is when I select the image in the editor, both the advImage icon and my plugin icon get set to active. I want to set the advimage to non-active. I tried stuff like this:

 cm.setActive('image', false);

Thanks to Thariama (see answer below) I know the correct name should be 'image'. This is called from my youtube plugin editor_plugin.js file, and in the console I can see that on selecting an image that code is executed and image is the correct target.

How do I set the image plugin to non-active?

See comments below Thariama's answer for more information.

Upvotes: 1

Views: 1557

Answers (2)

Rick de Graaf
Rick de Graaf

Reputation: 958

After this I let it be for a while because it was not on top of my priority list. Now it was the last thing on my list and because of working more with tinyMCE and it codes I pretty quickly found a solution.

I figured that I needed to go to the root: editor_template.js. This is were image was set to active so I needed to change that.

My images for youtube (and now vimeo as well) have an alt attribbute to tell me if it's a youtube or vimeo video. Now I need to disable either one of those plugins as well.

I have put it on line 1117 after this code (which sets the active state for all img tags.

p = getParent('IMG');
if (c = cm.get('image'))
    c.setActive(!co && !!p && n.className.indexOf('mceItem') == -1);

And my code:

if(ed.selection.getNode())
            if(ed.selection.getNode().getAttribute('alt') === 'videoYoutube' || ed.selection.getNode().getAttribute('alt') === 'videoVimeo') // Get the current selection in the editor and compare
            {
                cm.setDisabled('image', true); // Change disable state
                cm.setActive('image', false); // Change active state state
            }
            else
            {
                cm.setDisabled('image', false);
            }
            if(ed.selection.getNode().getAttribute('alt') === 'videoYoutube')
            {
                cm.setDisabled('addvimeo', true);
            }
            else if(ed.selection.getNode().getAttribute('alt') === 'videoVimeo')
            {
                cm.setDisabled('addyoutube', true);
            }
            else
            {
                cm.setDisabled('addvimeo', false);
                cm.setDisabled('addyoutube', false);
            }

Upvotes: 0

Thariama
Thariama

Reputation: 50832

I will demonstrate the correct way to deactivate a button/control on the html button (the code plugin)

var cm = tinymce.get('my_editor_id').controlManager;
cm.get('code').setActive(0); // get the control named 'code'

To find out which controls are available you may log this to your console

console.log(cm.controls);

Upvotes: 2

Related Questions