Create Custom Color Set TinyMCE

一曲冷凌霜 提交于 2020-01-15 07:51:26

问题


I have been able to create my own Font color picker for TinyMCE, but but the color palette is linked to the original color picker. What I am trying to do is make my custom color picker totally independent of the original one (so I can show both). Here is my current code, and this works, but the color palette is the same for both buttons:

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 = '<?php echo $university->getDto()->getIcoFile();?>',
                   o.onclick = function (color) { ed.execCommand('Forecolor', false, 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);*/

                       // execute the same command that the regular forecolor plugin uses (choosen theme needs to be advanced! in order to work)
                       ed.execCommand('ForeColor', false, color);
                   };
                   // limit the colors using own setting
                   if (v = ed.getParam('theme_advanced_text_colors')) o.colors = v;

                    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,|,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,
        theme_advanced_text_colors :"<?php echo implode(',', $university->getDto()->getColors());?>" // example

        });

回答1:


To apply custom fonts see this fiddle: http://fiddle.tinymce.com/jYcaab/2




回答2:


This was actually very easy after reading through what was happening. All that needed to be done was alter this line:

 if (v = ed.getParam('theme_advanced_text_colors')) o.colors = v;

to if (v = ed.getParam('custom_colors')) o.colors = v;

then add add custom_colors definition in init method.



来源:https://stackoverflow.com/questions/15768671/create-custom-color-set-tinymce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!