Jquery TinyMCE添加格式

Jquery TinyMCE添加格式,jquery,tinymce,Jquery,Tinymce,我想在我的TinyMCE插件中添加自定义格式。我使用的是JQuery版本的插件 我发现,通过在我的主题映射中向编辑器_template.js添加以下代码 _createBlockFormats : function() { var k, i = { p : "advanced.paragraph", address : "advanced

我想在我的TinyMCE插件中添加自定义格式。我使用的是JQuery版本的插件

我发现,通过在我的主题映射中向编辑器_template.js添加以下代码

_createBlockFormats : function() {
                        var k, i = {
                            p : "advanced.paragraph",
                            address : "advanced.address",
                            pre : "advanced.pre",
                            h1 : "advanced.h1",
                            h2 : "advanced.h2",
                            h3 : "advanced.h3",
                            h4 : "advanced.h4",
                            h5 : "advanced.h5",
                            h6 : "advanced.h6",
                            div : "advanced.div",
                            blockquote : "advanced.blockquote",
                            code : "advanced.code",
                            dt : "advanced.dt",
                            dd : "advanced.dd",
                            samp : "advanced.samp",
                            **custom_format: "Custom Format"** THIS IS ADDED                        }
$('textarea.tinymce').tinymce({

    script_url : '<?=website_url.cmmdir?>js/tinymce/jscripts/tiny_mce/tiny_mce.js',

    //language: "nl",
    // General options
    mode : "exact",
    //elements : "ta_intro, ta_content",
    theme : "advanced",
    //plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,searchreplace,print,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
    plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template, imagemanager",

    theme_advanced_toolbar_align : "left",
    theme_advanced_toolbar_location : "top",        
    theme_advanced_resizing : false,

    // Theme options
    //plugins : "imagemanager,advimage,table,paste,media",
    content_css : "<?php echo website_url.cmmdir ?>tools/tinymce/style.css",

    theme_advanced_disable: "sup, sub, help, cleanup, anchor",
    theme_advanced_buttons1 : "bold,italic,underline,forecolor<?php if($RBAC->getCurrentRoleId() == super_user_id || $_SESSION['usr']->role_id == 4) { echo ",code"; } ?>,formatselect,removeformat",
    theme_advanced_buttons2 : "copy,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,cleanup,help,",
    theme_advanced_buttons3 : "cleanup,|,visualaid,tablecontrols",
    theme_advanced_blockformats : "p,h1,h2,h3,h4,custom_format",
    forced_root_block : false,
    force_br_newlines : true,
    force_p_newlines : false,
    paste_create_paragraphs : false,
    paste_create_linebreaks : false,
    paste_use_dialog : false,
    paste_auto_cleanup_on_paste : true,
    paste_convert_middot_lists : false,
    paste_unindented_list_class : "unindentedList",
    paste_convert_headers_to_strong : true,
    paste_insert_word_content_callback : "convertWord",
    relative_urls : false,
    width : "802px",

        // THIS IS THE PART WHERE I DECLARE A STYLE CLASS TO THE JUST CREATED FORMATS
    formats : {
        custom_format: {inline : 'span', 'classes' : 'custom_format'}
        }   
});
在将textarea设置为TinyMCE的文件中,我使用了以下代码

_createBlockFormats : function() {
                        var k, i = {
                            p : "advanced.paragraph",
                            address : "advanced.address",
                            pre : "advanced.pre",
                            h1 : "advanced.h1",
                            h2 : "advanced.h2",
                            h3 : "advanced.h3",
                            h4 : "advanced.h4",
                            h5 : "advanced.h5",
                            h6 : "advanced.h6",
                            div : "advanced.div",
                            blockquote : "advanced.blockquote",
                            code : "advanced.code",
                            dt : "advanced.dt",
                            dd : "advanced.dd",
                            samp : "advanced.samp",
                            **custom_format: "Custom Format"** THIS IS ADDED                        }
$('textarea.tinymce').tinymce({

    script_url : '<?=website_url.cmmdir?>js/tinymce/jscripts/tiny_mce/tiny_mce.js',

    //language: "nl",
    // General options
    mode : "exact",
    //elements : "ta_intro, ta_content",
    theme : "advanced",
    //plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,searchreplace,print,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
    plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template, imagemanager",

    theme_advanced_toolbar_align : "left",
    theme_advanced_toolbar_location : "top",        
    theme_advanced_resizing : false,

    // Theme options
    //plugins : "imagemanager,advimage,table,paste,media",
    content_css : "<?php echo website_url.cmmdir ?>tools/tinymce/style.css",

    theme_advanced_disable: "sup, sub, help, cleanup, anchor",
    theme_advanced_buttons1 : "bold,italic,underline,forecolor<?php if($RBAC->getCurrentRoleId() == super_user_id || $_SESSION['usr']->role_id == 4) { echo ",code"; } ?>,formatselect,removeformat",
    theme_advanced_buttons2 : "copy,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,cleanup,help,",
    theme_advanced_buttons3 : "cleanup,|,visualaid,tablecontrols",
    theme_advanced_blockformats : "p,h1,h2,h3,h4,custom_format",
    forced_root_block : false,
    force_br_newlines : true,
    force_p_newlines : false,
    paste_create_paragraphs : false,
    paste_create_linebreaks : false,
    paste_use_dialog : false,
    paste_auto_cleanup_on_paste : true,
    paste_convert_middot_lists : false,
    paste_unindented_list_class : "unindentedList",
    paste_convert_headers_to_strong : true,
    paste_insert_word_content_callback : "convertWord",
    relative_urls : false,
    width : "802px",

        // THIS IS THE PART WHERE I DECLARE A STYLE CLASS TO THE JUST CREATED FORMATS
    formats : {
        custom_format: {inline : 'span', 'classes' : 'custom_format'}
        }   
});
$('textarea.tinymce').tinymce({
脚本url:'js/tinymce/jscript/tiny_mce/tiny_mce.js',
//语言:“nl”,
//一般选择
模式:“精确”,
//元素:“ta_简介,ta_内容”,
主题:“高级”,
//插件:“safari、拼写检查器、分页符、样式、图层、表格、保存、advhr、advimage、advlink、情感、iSpell、inlinepopups、insertdatetime、预览、搜索替换、打印、上下文菜单、粘贴、方向性、不可编辑、visualchars、不可中断、xhtmlxtras、模板、imagemanager、文件管理器”,
插件:“safari、分页符、样式、图层、表格、保存、advhr、advimage、advlink、情绪、iSpell、inlinepopups、insertdatetime、预览、媒体、搜索替换、打印、上下文菜单、粘贴、方向性、全屏、不可编辑、visualchars、不可中断、xhtmlxtras、模板、imagemanager”,
主题\高级\工具栏\对齐:“左”,
主题\高级\工具栏\位置:“顶部”,
主题\u高级\u大小调整:错误,
//主题选项
//插件:“imagemanager、advimage、表、粘贴、媒体”,
content_css:“tools/tinymce/style.css”,
主题\u高级\u禁用:“辅助、辅助、帮助、清理、锚定”,
主题\高级\按钮1:“粗体、斜体、下划线、前景色、格式选择、删除格式”,
主题|高级|按钮2:“复制、|、布利斯特、numlist、|、撤消、重做、|、链接、取消链接、锚定、清理、帮助,”,
主题_高级_按钮3:“清理,|,可视化ID,表格控件”,
主题\u高级\u块格式:“p、h1、h2、h3、h4、自定义\u格式”,
强制根块:false,
force\u br\u新词:对,
force_p_新行:false,
粘贴\创建\段落:false,
粘贴\创建\换行符:false,
粘贴使用对话框:false,
粘贴上的自动清理粘贴:true,
粘贴转换中间列表:false,
粘贴\u未登入\u列表\u类:“未登入列表”,
粘贴\u将\u标题\u转换为\u strong:true,
粘贴\插入\单词\内容\回调:“convertWord”,
相对URL:false,
宽度:“802px”,
//这是我将样式类声明为刚创建的格式的部分
格式:{
自定义格式:{inline:'span','classes':'custom_format'}
}   
});

现在,我想去掉第一部分(编辑editor_template.js),在代码的第二部分中,是否有解决方案可以这样做?

您可以使用tinymce init和setup参数添加自定义样式

    // styles
    style_formats_paragraph: [
    {
        title: 'Royal Blue Text1',
        block: 'p',
        classes: 'royalbluetext',
        exact: true
    }, {
        title: 'Blue Text',
        block: 'p',
        classes: 'bluetext',
        exact: true
    }
    ],

    setup : function(ed) {


    // register styles (add them to the formatter)
    ed.onInit.add(function(ed, e) {
        ed.formatter.register(fmt.title, fmt);

        // registriere Absatzstile
        formats = ed.getParam('style_formats_paragraph');
        if (formats) {
            tinymce.each(formats, function(fmt) {
                ed.formatter.register(fmt.title, fmt);
            });
        }
    });
});