Tinymce Adds Shortcuts For Custom Styles

In my tinymce initialization, I use my predefined styles

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 style prefix wraps the selected content in a span tag and adds a specific class to it; styles example But now I need to add shortcuts (hot keys) that will provide the same functionality

for this purpose I created a plugin where my hot keys 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 for blockquote. But I did not find any useful information for me in the tinymce documentation for creating shortcuts for my custom styles .

Can someone help me in implementing this feature? I tried 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 that will not work.

+4
1

(http://www.tinymce.com/tryit/custom_formats.php), .

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

:

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

:

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

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

Source: https://habr.com/ru/post/1523325/


All Articles