In my tinymce initialization i use my predifined 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 predifined styles wraps selected content into span tag and adds specific class for it; But now i need to add shortcuts (hotkeys) that will provide the same functionality
for that purpose i've created plugin where my hotkeys 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 fine for blockquote. But i didn't find any useful information for me in tinymce documentation to implement shortcuts for my custom styles .
Can somebody help me how to implement this functionality? 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 it doesn't work.
I used this link ( http://www.tinymce.com/tryit/custom_formats.php ) to find solution.
In addition to
style_formats : [
{title : 'Date', inline : 'span', classes : 'date'}
]
I've added format to initalization:
formats: { mydateformat: {inline: 'span', classes : 'date'}}
After that code in plugin was very simple:
ed.addShortcut('ctrl+alt+3', 'Date format', function(){
ed.formatter.apply('mydateformat');
});
or with some improvement
ed.addShortcut('ctrl+alt+3', 'Date format', ['FormatBlock', false, 'mydateformat'], this);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.