Tinymce shortcut to add custom styles


cache

In my tinymce initialization I use a pre-defined style

style_formats : [ 
    {title : 'Date', inline : 'span', classes : 'date'},
    {title : 'Trend UP', inline : 'span', classes : 'trend_up'},
    {title : 'Trend DOWN', inline : 'span', classes : 'trend_down'},
    {title : 'Trend NO', inline : 'span', classes : 'trend_no'}
]

This pre-defined style wraps the selected content into a span tag and adds a specific class to it; style examplebut now I need to add shortcuts (hotkeys) that will provide the same functionality

For this I have created plugin in which my hotkey will be defined

(function(){

    tinymce.create('tinymce.plugins.MyShortcuts', {
        init : function(ed, url) {
            ed.addShortcut('ctrl+e','Format Blockquote', ['FormatBlock', false, 'blockquote'], this);
        }
    });

    // Register plugin with a short name
    tinymce.PluginManager.add('my_shortcuts', tinymce.plugins.MyShortcuts);
})();

And it works great with blockquote. But I didn't find any useful information in tinymce documentation to implement shortcuts for my custom styles .

Can someone help me how to implement this functionality? i try to do

ed.addShortcut('ctrl+e','Format Trend UP', ['FormatBlock', false, 'Trend UP'], this);

and

ed.addShortcut('ctrl+e','Format Trend UP', ['StylesBlock', false, 'Trend UP'], this);

But it doesn't work.

cache

I used this link ( http://www.tinymce.com/tryit/custom_formats.php ) to find a solution.

also

style_formats : [ 
    {title : 'Date', inline : 'span', classes : 'date'}
]

I've added the format to the initialization:

formats: { mydateformat: {inline: 'span', classes : 'date'}}

After that, the code in the plugin is very simple:

  ed.addShortcut('ctrl+alt+3', 'Date format', function(){
    ed.formatter.apply('mydateformat');
  });

or improved

ed.addShortcut('ctrl+alt+3', 'Date format', ['FormatBlock', false, 'mydateformat'], this);

Related


Add custom icon to tinyMCE button

captis I'm trying to add a Font-Awsome icon to a button I've added to tinyMCE, thus: ed.addButton('youtube', { title: 'Add Video' , icon: 'icon-youtube', onclick: function () { //do stuff here... } Using images like the docs is not accep

Add custom icon to tinyMCE button

captiz I'm trying to add a Font-Awsome icon to a button I've added to tinyMCE: ed.addButton('youtube', { title: 'Add Video' , icon: 'icon-youtube', onclick: function () { //do stuff here... } Using images like the docs is not acceptable,

TinyMCE add code/pre to toolbar/shortcut

free faller Using TinyMCE, is it possible to add toolbar buttons or shortcuts <code>and <pre>format them (so that they are the same as <b>, <i>etc )? Having to go through 4 clicks to get there (Format-> codeFormat->Inline->Code) and 4 more clicks to get to pre

How to add custom styles

Daniel I can't add my own styles, when I reload the page in the browser, my styles are not added CKEDITOR.addCss('a{color: inherit; text-decoration: none}') CKEDITOR.stylesSet.add([{ name: 'My Custom styles', element: 'span', styles:

How to add custom block in tinyMce

Tariq Hussein I want to add a custom format block for TinyMCE, I was able to do it using the following code. style_formats: [ {title : 'Code', block : 'pre', classes : 'pre-code', exact: true},] https://codepen.io/anon/pen/vWRGEg However, by adding this code,

How to add custom block in tinyMce

Tariq Hussein I want to add a custom format block for TinyMCE, I was able to do it using the following code. style_formats: [ {title : 'Code', block : 'pre', classes : 'pre-code', exact: true},] https://codepen.io/anon/pen/vWRGEg However, by adding this code,

Add custom icon to tinyMCE button

captis I'm trying to add a Font-Awsome icon to a button I've added to tinyMCE, thus: ed.addButton('youtube', { title: 'Add Video' , icon: 'icon-youtube', onclick: function () { //do stuff here... } Using images like the docs is not accep

TinyMCE Some custom text styles are not selectable, and some are

author EDIT: Reproducible fiddle for review : https://fiddle.tiny.cloud/P2haab I'm having trouble creating a custom style formatting configuration option, my text styles sometimes work and sometimes don't. Here are my current style_formats for reference: style

tinyMCE: How to add shortcut Ctrl+Enter

Stijn Sanders How can I add shortcut Ctrl+ Enterto tinyMCE (v4) so that it publishes a form that works with the editor? I've tried this, but it doesn't seem to work: <script><!-- $('#txtField1').tinymce({ script_url:"js/tinymce/tinymce.min.js", content_css:"cs

Add custom styles to the base

Sven I'm building my first site with the base. I installed base via npm. I think it's a good practice to keep the base styles and then override what needs to be adjusted. The base style will be included as an external include in the sass compilation job (using

How to add custom styles

Daniel I can't add my own styles, when I reload the page in the browser, my styles are not added CKEDITOR.addCss('a{color: inherit; text-decoration: none}') CKEDITOR.stylesSet.add([{ name: 'My Custom styles', element: 'span', styles:

Add icon to TinyMCE custom menu

work for life I'm modifying a plugin that adds a custom TinyMCE menu in WP. I need to be able to add icons to dropdown menu items and submenu items. I have icons enabled, which add space to it in the HTML, but can't figure out where JS can put them in. createC

Add icon to TinyMCE custom menu

work for life I'm modifying a plugin that adds a custom TinyMCE menu in WP. I need to be able to add icons to dropdown menu items and submenu items. I have icons enabled, which add space to it in the HTML, but can't figure out where JS can put them in. createC

Add Custom Buttons to TinyMCE in WordPress

John Smith I want to add a new button with a popup to TinyMCE. But I never see the button. I may be doing something wrong with this modification. How can I insert a new button on that TinyMCE code? I have this TinyMCE code to display in Wordpress frontend:

How to add custom bullets to tinyMCE?

Ennio I would like to add some extra options to the bullet dropdown in tinyMCE, is this possible? I would like to add ►Bullet type and different color options. (red, blue, etc...) username Yes. In the tinyMCE configuration you need to specify: style_formats: [

Tinymce shortcut to add custom styles

cache In my tinymce initialization I use a pre-defined style style_formats : [ {title : 'Date', inline : 'span', classes : 'date'}, {title : 'Trend UP', inline : 'span', classes : 'trend_up'}, {title : 'Trend DOWN', inline : 'span', classes : 'tre

Tinymce shortcut to add custom styles

cache In my tinymce initialization I use a pre-defined style style_formats : [ {title : 'Date', inline : 'span', classes : 'date'}, {title : 'Trend UP', inline : 'span', classes : 'trend_up'}, {title : 'Trend DOWN', inline : 'span', classes : 'tre

How to add custom bullets to tinyMCE?

Ennio I would like to add some extra options to the bullet dropdown in tinyMCE, is this possible? I would like to add ►Bullet type and different color options. (red, blue, etc...) username Yes. In the tinyMCE configuration you need to specify: style_formats: [

Add custom html and css in TinyMCE

shooter I'm using TinyMCE and I want to add custom html/css to the output. All bulleted lists created in the Tiny editor should have these css classes and a tag like <i>this : <ul class="iconlist"> <li><i class="icon-double-angle-right"></i> Item 1</li>

Add custom styles to the base

Sven I'm building my first site with the base. I installed base via npm. In my opinion, it's better to keep the base style and then override what needs to be adjusted. The base style will be included as an external include in the sass compilation job (using gu

How to add custom styles

Daniel I can't add my own styles, when I reload the page in the browser, my styles are not added CKEDITOR.addCss('a{color: inherit; text-decoration: none}') CKEDITOR.stylesSet.add([{ name: 'My Custom styles', element: 'span', styles:

TinyMCE Some custom text styles are not selectable, and some are

author EDIT: Reproducible fiddle for review : https://fiddle.tiny.cloud/P2haab I'm having trouble creating a custom style formatting configuration option, my text styles sometimes work and sometimes don't. Here are my current style_formats for reference: style

Add custom icon to tinyMCE button

captis I'm trying to add a Font-Awsome icon to a button I've added to tinyMCE, thus: ed.addButton('youtube', { title: 'Add Video' , icon: 'icon-youtube', onclick: function () { //do stuff here... } Using images like the docs is not accep

TinyMCE add code/pre to toolbar/shortcut

free faller Using TinyMCE, is it possible to add toolbar buttons or shortcuts <code>and <pre>format them (so that they are the same as <b>, <i>etc )? Having to go through 4 clicks to get there (Format-> codeFormat->Inline->Code) and 4 more clicks to get to pre

How to add custom styles

Daniel I can't add my own styles, when I reload the page in the browser, my styles are not added CKEDITOR.addCss('a{color: inherit; text-decoration: none}') CKEDITOR.stylesSet.add([{ name: 'My Custom styles', element: 'span', styles:

How to add custom styles

Daniel I can't add my own styles, when I reload the page in the browser, my styles are not added CKEDITOR.addCss('a{color: inherit; text-decoration: none}') CKEDITOR.stylesSet.add([{ name: 'My Custom styles', element: 'span', styles:

TinyMCE Some custom text styles are not selectable, and some are

author EDIT: Reproducible fiddle for review : https://fiddle.tiny.cloud/P2haab I'm having trouble creating a custom style formatting configuration option, my text styles sometimes work and sometimes don't. Here are my current style_formats for reference: style

TinyMCE Some custom text styles are not selectable, and some are

author EDIT: Reproducible fiddle for review : https://fiddle.tiny.cloud/P2haab I'm having trouble creating a custom style formatting configuration option, my text styles sometimes work and sometimes don't. Here are my current style_formats for reference: style

TinyMCE Some custom text styles are not selectable, and some are

author EDIT: Reproducible fiddle for review : https://fiddle.tiny.cloud/P2haab I'm having trouble creating a custom style formatting configuration option, my text styles sometimes work and sometimes don't. Here are my current style_formats for reference: style