2013-04-02 53 views
2

我已經能夠爲TinyMCE創建自己的字體顏色選擇器,但是調色板鏈接到原始顏色選擇器。我想要做的是使我的自定義顏色選擇器完全獨立於原來的(所以我可以同時顯示)。這裏是我當前的代碼,而這個工作,但調色板是兩個按鈕是相同的:創建自定義顏色集TinyMCE

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 

     }); 

回答

0

這實際上是通過發生了什麼事看完後非常容易。所有需要做是改變該行:

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

到 如果(V = ed.getParam( 'custom_colors'))o.colors = V;

然後在init方法中添加custom_colors定義。