tags:

views:

649

answers:

1

I'm using TinyMCE & jQuery and am having a problem moving TinyMCE's external toolbar to another location in the DOM.

To further complicate things, there are multiple TinyMCE instances on the page. I only want the toolbar for the one that's currently being edited.

Here's some sample code:

$(textarea).tinymce({
  setup: function(ed) {setupMCEToolbar(ed, componentID, displaySettingsPane)}
  ,script_url: '/clubs/data/shared/scripts/tiny_mce/tiny_mce.js'
  ,theme : "advanced"
  ,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"
   ,theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect"
  ,theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor"
  ,theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen"
  ,theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak"
  ,theme_advanced_toolbar_location : "external"
  ,theme_advanced_toolbar_align : "left"
  ,theme_advanced_statusbar_location : "bottom"
  ,theme_advanced_resizing : true
 });

var setupMCEToolbar = function (mce, componentID, displaySettingsPane)
{
 mce.onClick.add(function(ed,e){
  displaySettingsPane($('#' + componentID));
  $('#' + componentID).fetch('.mceExternalToolbar').eq(0).appendTo('#settingsPaneContent');
 });
}

Basically, it seems as though the setupMCEToolbar function cannot track down the mceExternalToolbar to move it.

Has anyone ever had success trying to do something like this?

EDIT It's a Monday alright... it couldn't find the external toolbar because I was using children() instead of fetch().

There's still an issue in that: 1) Moving it is incredibly slow and 2) Once it moves, TinyMCE breaks.

EDIT 2 A bit more clarification: The modal is draggable, thus making any purely-CSS workarounds a bit awkward...

A: 

I have not had much success moving the element, however it should be fairly simple to remove and recreate the TinyMCE box in your toolbar.

I would do something like the following:

var content = tinyMCE.get('id_of_text_area').getContent();
tinyMCE.execCommand('mceFocus', false, 'id_of_text_area');
tinyMCE.execCommand('mceRemoveControl', false, 'id_of_text_area');

// pop up your new area
popup('new_area');

// Add a new textarea with the content
$('<textarea id="id_of_text_area" />')
  .val(content)
  .appendTo('#new_area')
  // initialize a new editor on this textarea
  .tinymce({..});
Alex Sexton
It looks like you're saying actually move the entire editing block into the popup? This might be what I eventually need to do, however I really want the content to stay within the flow of the page when it's being edited.
Nate Wagar
What about just repositioning it with css? I must have misunderstood the question initially.
Alex Sexton
Unfortunately, I have to be difficult... The modal popup is draggable. Repositioning the toolbar via CSS would be do-able, but updating it via JS while the modal is dragged would be sloppy. I should clarify that in my initial posting.
Nate Wagar