0

Very new to tinymce and attempting a sizeable (for me) customization - tried a search, but not clear enough to know what I'm looking for... working with the code below (just showing top half), everything is working great, except I cannot get the Shortcodes items to insert at the cursor loc upon click - I have tried a number of variations but nothing has worked. Is onclick still the appropriate method? Any thoughts greatly appreciated.

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"}
            ]},
wolff
  • 1
  • 2
  • have you tried http://stackoverflow.com/questions/1064089/inserting-a-text-where-cursor-is-using-javascript-jquery – enigma Sep 27 '15 at 21:21
  • 1
    Thanks, but that question is not targeted at tinymce, which is what I am trying to configure here. As such, I have only been trying variations provided for tinymce - something within this construct should work. 'insertContent' is as far as I know the proper method - but I'm evidently not calling it right... – wolff Sep 27 '15 at 21:53

1 Answers1

0

Determined the issue - I was trying to add the Shortcodes menu to the 'style formats' section, which is NOT correct. Instead, I needed to create it in a separate section:

  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= ]');}},
  ]});
wolff
  • 1
  • 2