Question

I am using TinyMCE to for an WYSIWYG editor on my site, and I want to add a custom color picker to the editor in addition to the existing colorpicker using forecolor. I found this http://fiddle.tinymce.com/lwcaab/16 and used it to get the button to show up, but there are 2 problems. I need to filter the colors that show up in that button (only show a couple of colors), and when you click the color, it doesn't change the font color in the editor.

tinymce.create('tinymce.plugins.ExamplePlugin', {
    createControl: function(n, cm) 
        {
            switch(n)
            {
            case "universityColors":
               var o = {};
               ed=tinyMCE.activeEditor;
               o.scriptURL = ed.baseURI.getURI();
               o['class'] = 'mce_forecolor';
               o.title='University Font Colors';
               o.scope=this;
               o.image = '../images/uor.ico',
               o.onclick = function (color) { console.log('clicked',color);/*this.cs.showMenu(); if (this.o.onClick) this.o.onClick(c);*/};
               o.onselect = function (color) {console.log('selected',color); /*this.color=this.o.color=c; if (this.o.onSelect) this.o.onSelect(c);*/};

                var mcsb = cm.createColorSplitButton('universityColors', o);

                // return the new ColorSplitButton instance
                return mcsb;
            }
            return null;
        }
   });
tinymce.PluginManager.add('universityColorPicker', tinymce.plugins.ExamplePlugin);
tinyMCE.init({
    mode: "specific_textareas",
    editor_selector: "tinyMCE",
    theme : "advanced",
    plugins : "emotions,spellchecker,advhr,insertdatetime,preview, -universityColorPicker", 

     // Theme options - button# indicated the row# only
    theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,fontselect,fontsizeselect,formatselect",
    theme_advanced_buttons2 : "cut,copy,paste,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,|,code,preview,|,forecolor,backcolor, universityColors",
    theme_advanced_buttons3 : "insertdate,inserttime,|,spellchecker,advhr,,removeformat,|,sub,sup,|,charmap,emotions",      
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,


    });

I have made a fiddle to work of of also at: http://fiddle.tinymce.com/jYcaab

Était-ce utile?

La solution

I made that older fiddle :) Here your modified fiddle that limits the colors: http://fiddle.tinymce.com/jYcaab/1

Applying the font to the content is another story. Update: The font gets applied now: http://fiddle.tinymce.com/jYcaab/2

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top