tinymce插入内容 - onclick

时间:2015-09-27 21:11:22

标签: javascript tinymce-4

非常新的想法和尝试相当大的(对我来说)定制 - 尝试搜索,但不够清楚,不知道我在寻找什么...使用下面的代码(只显示上半部分),一切都很好,除了我点击时无法在光标位置插入Shortcodes项目 - 我尝试了很多变化,但没有任何效果。 onclick仍然是合适的方法吗?任何想法都非常感激。

TxtEdit = new tinymce.Editor(id, {
        inline: true,
        plugins: [
            "autolink lists link image charmap code insertdatetime table",
            "contextmenu paste textcolor colorpicker textpattern",
        ], 
        toolbar: "undo redo | styleselect | formatselect | pastetext | bold italic underline | alignleft aligncenter alignright | forecolor backcolor | bullist numlist | link | removeformat | fontselect fontsizeselect | code",
        menubar: false,
        paste_word_valid_elements: "b,strong,i,em,h1,h2",
        relative_urls : false,
        convert_urls : false,
        style_formats: [
            {title: "Shortcodes", items: [
                {title: 'Name', onclick: function() {editor.insertContent('[st_user_name_style target= ]');}},
                {title: 'Email', onclick: function() {editor.insertContent('[st_user_email_1_style target= ]');}}
            ]},
            {title: "Inline", items: [
                {title: "Strikethrough", icon: "strikethrough", format: "strikethrough"},
                {title: "Superscript", icon: "superscript", format: "superscript"},
                {title: "Subscript", icon: "subscript", format: "subscript"},
                {title: "Code", icon: "code", format: "code"}
            ]},
            {title: "Blocks", items: [
                {title: "Blockquote", format: "blockquote"},
                {title: "Div", format: "div"},
                {title: "Pre", format: "pre"}
            ]},

1 个答案:

答案 0 :(得分:0)

确定问题 - 我正在尝试将“短代码”菜单添加到“#style”格式'部分,这是不正确的。相反,我需要在一个单独的部分创建它:

  editor.addButton('shortcodes', {
  type: 'menubutton',
  text: 'Shortcodes',
  icon: false,
  menu: [
  { text: 'Name', onclick: function() {editor.insertContent('[st_user_name_style target= ]');}},
  { text: 'Email', onclick: function() {editor.insertContent('[st_user_email_1_style target= ]');}},
  ]});