Medium-editor: How to add a button to change the font

Created on 7 Dec 2016  路  8Comments  路  Source: yabwe/medium-editor

Hi, can someone please show me how to use the fontName extension to add a button which will change the font? I was unable to figure out how to use that extension.

Most helpful comment

Yep, you can do this.

var fontsList = ['', 'Arail', 'Open Sans', 'sans-serif', 'Your Font Name'];

var editor = new MediumEditor('.editable', {
  toolbar: {
    buttons: [{
      name: 'fontname',
      action: 'fontName',
      aria: 'change font name',
      contentDefault: '±', // 卤
      contentFA: '<i class="fa fa-font"></i>',

      fonts: fontsList
    }]
  }
});

All 8 comments

Anyone?

Hi @THPubs :v:

It seems that fontname is a bult-in extension, so you can just override default toolbar options like this:

var editor = new MediumEditor('.editable', {
  toolbar: {
    buttons: [
      'fontname'
    ]
  }
});

Here is more complex example on JSFiddle: https://jsfiddle.net/ypcgaomL/2/

Cool is it possible to define the exact fonts we need?

Yep, you can do this.

var fontsList = ['', 'Arail', 'Open Sans', 'sans-serif', 'Your Font Name'];

var editor = new MediumEditor('.editable', {
  toolbar: {
    buttons: [{
      name: 'fontname',
      action: 'fontName',
      aria: 'change font name',
      contentDefault: '&#xB1;', // 卤
      contentFA: '<i class="fa fa-font"></i>',

      fonts: fontsList
    }]
  }
});

Perfect thanks!

Thanks @geekiam !

@nmielnik you're welcome :wink:

Guys adding custom fonts seems to not work for me please help.

https://jsfiddle.net/ypcgaomL/3/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

subatomicglue picture subatomicglue  路  4Comments

DylanPiercey picture DylanPiercey  路  5Comments

ahmadyousefdev picture ahmadyousefdev  路  3Comments

jimmyadaro picture jimmyadaro  路  6Comments

sPaCeMoNk3yIam picture sPaCeMoNk3yIam  路  5Comments