自定义颜色选择器TinyMCE

问题描述:

我在我的网站上使用TinyMCE编辑WYSIWYG编辑器,除了使用forecolor的现有颜色选择器以外,我还想向编辑器添加自定义颜色选择器。我发现这个http://fiddle.tinymce.com/lwcaab/16,并用它来获得按钮显示,但有2个问题。我需要过滤出现在该按钮中的颜色(仅显示几种颜色),并且当您单击该颜色时,它不会更改编辑器中的字体颜色。自定义颜色选择器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 = '../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, 


    }); 

我已经做了小提琴在也的工作:http://fiddle.tinymce.com/jYcaab

我做了较旧的小提琴:) 这里修改后的小提琴限制颜色:http://fiddle.tinymce.com/jYcaab/1

应用的字体内容是另一回事。 更新:字体现在得到应用:http://fiddle.tinymce.com/jYcaab/2

+0

令人敬畏的Thariama。完美的作品。有什么方法可以使标准颜色选择器具有默认颜色,并且新颜色选择器仅具有我们正在寻找的特定颜色? – Mike 2013-03-28 15:41:10

+1

当然,你需要做的就是定义你自己的color_set在你的init中定义它,稍后再用editor.getParam('my_own_color_set') – Thariama 2013-04-02 06:52:08

+0

这里是我的关于如何创建color_set的问题的链接。如果你有机会,任何帮助,将不胜感激:http://*.com/questions/15768671/create-custom-color-set-tinymce – Mike 2013-04-02 15:58:43