Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Doesn't work with multiple instances of TinyMCE (e.g. ACF) #1

Open
chrisgoddard opened this issue Sep 12, 2014 · 0 comments
Open

Doesn't work with multiple instances of TinyMCE (e.g. ACF) #1

chrisgoddard opened this issue Sep 12, 2014 · 0 comments

Comments

@chrisgoddard
Copy link

Hey there,

Quick issue I found - when you have multiple WYSIWYG editors - like you can with Advanced Custom Fields, the setActiveColor function is only working with the first editor window.

If you add an additional context argument - and pass it the element it's being called from, it will work.

I did it like this:

function setActiveColor( instance, property, color, recalc ) {

        var colors = $(instance).find( '.tinymce-cp-body-' + property + ' .iris-palette' ).removeClass( 'active' );
        color = color || editor.dom.toHex( editor.dom.getStyle( editor.selection.getNode(), property ) );

        if ( recalc ) {
            colors.each( function() {
                var hex = editor.dom.toHex( $( this ).css( 'background-color' ) );
                $( this ).addClass( property + '-' + hex.slice( 1, 7 ) ).data( 'color', hex );
            } );
        }

        if ( color ) {
            colors.filter( '.' + property + '-' + color.slice( 1, 7 ) ).first().addClass( 'active' );
        }
    }

Then passed it either the panel or $(this) property within $( '.mce-colorbutton .mce-open' ).on( 'click'..

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant