0

I have function that creates textareas fields on the fly upon a click on a link

I want to convert these textareas into tinymce wysiwyg

here is the code

        $("body").delegate("a.add_tab","click",function(e){
               e.preventDefault();
                 var uniq = $(this).attr("uniqid");
               add_tab_ui($(this),uniq);
            }); 

            function add_tab_ui(elem,uniq){
              var content = "<div class='wrapTab'><label >Tab Title:<input type='text' name='tab-title-"+uniq+"' id='tab-title' value='' placeholder = 'Add Tab Title' />  </label><br/><br/>";
              content+= "<label>Tab Content: <textarea name='tab-content-"+uniq+"' class='tinymce_enabled' id='tab-content' ></textarea></label><br/><br/><a href='#' class='del_tab'>Delete Tab</a><br/><br/></div>"  
              $(content).appendTo(elem.parent()).parent().sortable({cursor:'move'});
                add_tmce();
            }


                function add_tmce(){
                 tinyMCE.init();
                 tinyMCE.execCommand("mceAddControl", false,'textarea#tab-content');
               }

The way I did does not work
what I am really looking for is a way to automatically replace every textarea with id "tab-content" into tinymce wysiwyg and that should happen ON THE FLY
Also note that I am working inside wordpress back end and I MUST use the javascript way to do it NOT the php way wp_editor() function which is built-in wordpress
Any thoughts are appreciated :)

1
Contributor
1
Reply
9
Views
3 Years
Discussion Span
Last Post by Amr87
0

found the solutions

It was like that

function add_tmce(){
      var i=1;
      jQuery('.tinymce_enabled').each(function(e)
          {
           var id = jQuery(this).attr('id');

             if (!id)
              {
                    id = 'customEditor-' + i++;
                    jQuery(this).attr('id',id);
               }

             tinyMCE.execCommand('mceAddControl', false, id);

          });
         }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.