在Tiny MCE自定义按钮中使用现有图标

Wil*_*lis 3 javascript css tinymce

我们可以使用现有的图标自定义按钮吗?(不是图像)

我试过这个,但它不起作用:

tinymce.init({
   ...

   toolbar: 'example'

   setup: function(ed) {
      ed.addButton('example', {
         title: 'My title',
         image: '../js/tinymce/plugins/example/img/example.gif',
         classes: 'mce-ico mce-i-image',
         onclick: function() {
            ed.insertContent('Hello world!!');
         }
      });
   }
});
Run Code Online (Sandbox Code Playgroud)

小智 6

是的,您可以使用现有图标.

您可以从现有按钮中取出类名 - 例如"mce-i-image" - 然后,不要将其应用于新按钮的类名,而是剥离"mce-i-"前缀并使用余数 - 在这种情况下为"image" - 作为图标键.

我在下面修改了你的例子.

例如

setup: function(ed) {
  ed.addButton('example', {
    title: 'My title',
    icon: 'image',  // This line sets the icon key.
    onclick: function() {
      ed.insertContent('Hello world!!');
    }
  });
}
Run Code Online (Sandbox Code Playgroud)