【问题标题】:Tinymce adding shortcuts for custom stylesTinymce 为自定义样式添加快捷方式
【发布时间】:2017-07-18 00:44:34
【问题描述】:

在我的 tinymce 初始化中,我使用我的预定义样式

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'}
]

这种预定义样式将选定的内容包装到 span 标签中并为其添加特定的类; 但现在我需要添加提供相同功能的快捷方式(热键)

为此,我创建了插件来定义我的热键

(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);
})();

它适用于块引用。但我在tinymce documentation 中没有找到任何有用的信息为我的自定义样式实现快捷方式。

谁能帮我实现这个功能? 我试着做

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

和

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

但它不起作用。

【问题讨论】:

  • 请问我在哪里可以将该代码粘贴到 Tinymce 3 中以将短代码添加到 Blockquote?我会感谢你的回答

标签: javascript tinymce


【解决方案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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-29
    • 2016-11-17
    • 1970-01-01
    • 2013-02-23
    相关资源
    最近更新 更多