You are not logged in.
#1 2008-02-15 02:28:50
Single Menu - Multiple TinyMCE Editors
Hello forum,
I was wondering if somebody could help me control multiple TinyMCE editors from a single TinyMCE menu?
Will I have to manually make my own TinyMCE menu something like this:
Code:
<script language="javascript>
function customTinyMCE(func){
current_tinymce_editor = getTheEditorThatHasFocusSomeHow();
tinyMCE.execInstanceCommand(current_tinymce_editor,func,false);
}
</script>
<!-- start custom menu -->
<a href="javascript:customTinyMCE('Bold');">B</a>
<a href="javascript:customTinyMCE('Italic');">I</a>
etc...or is there a way to have a single menu control multiple editors natively?
thank you heaps!
Dave
Offline
#2 2008-02-15 03:27:48
Re: Single Menu - Multiple TinyMCE Editors
Or could I do something like:
Code:
tinyMCE.init({
...
theme_advanced_toolbar_location: "external",
...
});And then somehow set a handler on each tinyMCE instance so when it gets focus it displays only it's toolbar at the top:
Code:
set all external toolbars to the same position, and hide them all by default:
<style type="text/css">
.mceToolbarExternal{
display: none;
position: absolute;
top: 20px;
}
</style>then I can just control each individual menu by:
document.getElementById('mce_editor_0_toolbar').style.display=''; etc...
is there a way to set a listener on a tinyMCE instance to fire off a javascript function when it gets focus?
Offline
#3 2008-02-15 06:35:55
Re: Single Menu - Multiple TinyMCE Editors
Solution:
Here we have a parent window with the TinyMCE toolbars in it and a <iframe> through to the actual page that contains the TinyMCE <textarea>'s
The TinyMCE toolbar controls the <textarea>'s inside the <iframe>
How I did it is below:
(note: I use the jQuery javascript library - although it should be possible without it)
parent window:
Code:
<script language="javascript" type="text/javascript" src="/js/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
theme : "advanced",
mode : "none",
plugins : "table,paste,nonbreaking",
theme_advanced_toolbar_location : "external",
theme_advanced_toolbar_align : "left",
theme_advanced_buttons1: "bold,italic,underline,|,justifyleft,justifycenter,justifyright,|,link,unlink,|,forecolor,backcolor,|,bullist,numlist,|,hr,blockquote,charmap,code,|,styleselect,formatselect",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
add_unload_trigger : false,
remove_linebreaks : false,
debug : false,
width: "100%",
handle_event_callback : "set_current_editor"
});
function set_current_editor(e) {
// this only shows the tinymce menu for the current tinymce editor
var editorid = e.target.editorId; // grab the id of the current editor
if(editorid){
$('.mceToolbarExternal').hide(); // use jquery to hide all the tinymce toolbars
if(e.type!="blur"){
// if the user is still in the editor - we show its toolbar - again using jquery
$('#'+editorid+"_toolbar").show();
}
}
return true; // Continue handling
}
function editor_init(){
// use jquery to find all <textarea class="editor"> elements inside the iframe
// and then add tinymce to them
$(".editor",editor_frame.document).each(
function(){
tinyMCE.addMCEControl(this,$(this).attr('id'),editor_frame.document);
}
);
}
</script>
<iframe src="path/to/editable/page.php" name="editor_frame" id="editor_frame">and this is the code inside the iframe (path/to/editable/page.php):
Code:
<script>
// use jquery to call the parent editor_init()
// when the inner iframe is ready
$(window).ready(function(){
parent.editor_init();
});
</script>
<textarea class="editor">some content for editor number 1</textarea>
<textarea class="editor">some content for editor number 2</textarea>
<textarea class="editor">some content for editor number 3</textarea>
<textarea class="editor">some content for editor number 4</textarea>i hope this helps someone out ![]()
Offline
#4 2008-02-16 05:47:10
- krijn
- Member
- From: Holland
- Registered: 2008-01-02
- Posts: 9
Re: Single Menu - Multiple TinyMCE Editors
@dtbaker
Hi, i have tryd your code but i diddent get it working can you send me a working sample on my email.
greats Krijn
Offline
#5 2008-02-16 07:11:39
Re: Single Menu - Multiple TinyMCE Editors
You will also need to download jquery from http://jquery.com/ and include it in both the parent and iframe window:
Code:
<script language="javascript" src="/js/jquery.js"></script>
Here is a link to a working example I just put together:
TinyMCE with iframe / multiple menus displaying in a single location (excuse the slow hosting)
have a look at the source code
(note: for some weird reason - this works in my cms using tinymce3 - but in that demo i put together it would only work with version 2 - weird )
dave
Offline
#6 2008-02-16 08:40:03
- krijn
- Member
- From: Holland
- Registered: 2008-01-02
- Posts: 9
Re: Single Menu - Multiple TinyMCE Editors
Hi dave,
thank you verry much, it worked to bad of the older version but thats oke, you can edit divs now alse jquery rules.
i have one last question is an editors field is not selected your toolbar disapairs is it a nice idea to to display the current toolbar but at non editable mode. ( the gray non clickable toolbar ) and if how would i do that.
if you know i hope you would like to tell me.
Thnx in advance.
Krijn
Offline
#7 2008-02-16 09:04:40
Re: Single Menu - Multiple TinyMCE Editors
Hi Krijn,
There is actually now multiple menu's - one for each <textarea> - they just all appear in the same location. Giving the imitation of a single menu.
If no editable regions are selected, then we do not show a menu. As soon as one is selected - then its menu is displayed.
I could not find a way to make tinymce control multiple textarea's from a single menu out of the box.
If somebody knows of a way... please let me know.
Cheers heaps,
Dave
Offline
#8 2008-02-16 14:38:54
- krijn
- Member
- From: Holland
- Registered: 2008-01-02
- Posts: 9
Re: Single Menu - Multiple TinyMCE Editors
Hi Dave,
It works great, used it to avoid the non editabe plugin now i give the parts i whant to edit the editor class and it works flawless.
manny thanks
Krijn
Offline
#9 2008-02-21 18:29:50
- krijn
- Member
- From: Holland
- Registered: 2008-01-02
- Posts: 9
Re: Single Menu - Multiple TinyMCE Editors
Hey dave,
I have been trying some things but how do you get the content of those 3 editors in the iframe and save it.
I hope you have a nice salution and i am using div's instead of teaxarea's i hope thats not to hard?
I hope to hear from you.
Manny thx in advance.
Krijn
Offline
#10 2008-03-28 11:36:01
- lordali
- Member
- Registered: 2008-01-18
- Posts: 22
Re: Single Menu - Multiple TinyMCE Editors
Hi dtbaker ,
Your solution is very good but when I try to use it in Frames its not working. Like I have index.html, Toolbra.html and body.html and I want toolbar to be in toolbar and editable contents in body page and index have Frameset for the 2 pages. Can you please give me any idea that help applying your solution in Frames
Thanks
Offline
#11 2008-03-28 13:10:59
Re: Single Menu - Multiple TinyMCE Editors
Hi lordali,
Yes doing such a thing is indeed possible. It requires slight modification to the javascript in my previous iframe example.
- the main frameset file index.html will contain some code that knows when both frames have loaded completely.
- the frame body.html contains the <textarea>'s you want tinymce to bind to.
- the frame Toolbar.html contains the tinymce code. this code needs to reference the <textarea>'s within the "body.html" frame
It was easier to just do it than try to explain how to do it.
So here ya go: TinyMCE frameset example
There is probably a more elegant solution for finding when all frames within a frameset have loaded than the one I created.
Good luck.
--
David Baker
http://dtbaker.com.au
Offline
#12 2008-03-28 21:06:59
- lordali
- Member
- Registered: 2008-01-18
- Posts: 22
Re: Single Menu - Multiple TinyMCE Editors
Thanks alot dtbaker,
really gratefull for your reply. But there is problem with the example you have used with Frames. If you check you will find that Bold, Italic etc button not working and you lose focus on selected text once you apply these. Could you pleaseee fix this?
Thanks alot and waiting for your reply
Offline
#14 2008-03-29 02:20:29
Re: Single Menu - Multiple TinyMCE Editors
@krijn if you are still around.
Simply wrap a single <form> around all your editable regions inside the iframe:
Code:
<form action="save.php" method="post">
<textarea class="editable"></textarea>
<textarea class="editable"></textarea>
<textarea class="editable"></textarea>
</form>Load the 'save' plugin for tinymce and register the 'save' button on the menu:
Code:
plugins : "save,table,...
theme_advanced_buttons1: "save,|,bold,....now when you click the save button on any of the menu's, it should submit the single form containing all the editable regions.
Offline
#15 2008-03-29 18:46:19
- lordali
- Member
- Registered: 2008-01-18
- Posts: 22
Re: Single Menu - Multiple TinyMCE Editors
Thanks dtbaker,
I confirmed the problem again. Actually your Frame solution is not working in IE7 but working in firefox. Any idea why this different? . Can you please fix this problem?
Thanks alot and waiting for your reply
-Oh and no Javascript error as well. I tried again clearing browser cache etc but no success in IE7
Last edited by lordali (2008-03-29 18:54:01)
Offline
#16 2008-03-31 14:37:52
- lordali
- Member
- Registered: 2008-01-18
- Posts: 22
Re: Single Menu - Multiple TinyMCE Editors
Hello dtbaker,
Sorry to ask you again and again. But please can you tell me is that bug that Toolbar functions not working in IE7 like bold, italic etc in your above Frame based solution?
Please help.
Thanks
Offline
#17 2008-04-07 08:58:54
- lordali
- Member
- Registered: 2008-01-18
- Posts: 22
Re: Single Menu - Multiple TinyMCE Editors
Hello dtbaker,
I have solved the focus problem in IE7. There is onething that I wanted to ask in your code. I want to use version 3 of TinyMCE. In your code
tinyMCE.addMCEControl(this,$(this).attr('id'),parent.bodyframe.document);
is changed to
tinyMCE.execCommand('mceAddControl', false, $(this).attr('id'));
but its not working. Any work around to that please. This is my last question and dont want to bother. please
thanks
Offline
#18 2008-04-07 12:45:04
Re: Single Menu - Multiple TinyMCE Editors
Evening lordali,
Last time I tried, tinymce 3 did not have frame support.
Have a look in the version 3 tiny_mce_src.js file, see if you can find "mceAddFrameControl".
IIRC there was a comment in the code that said it was still a TODO.
Have a search of the forums and see if you can dig up when it is expected.
Dave
Offline
#20 2008-04-07 13:45:55
- lordali
- Member
- Registered: 2008-01-18
- Posts: 22
Re: Single Menu - Multiple TinyMCE Editors
Thanks spocke for the reply,
I researched on the info provided by you.
I am using the version you have mentioned and looked for the add command and found this link http://wiki.moxiecode.com/index.php/TinyMCE:Commands
I am using frame so I try to use this command
function editor_init(){
$(".editor",parent.bodyframe.document).each(
function(){
//alert("Binding to id: "+$(this).attr('id'));
tinyMCE.execCommand('mceAddFrameControl', false, parent.bodyframe.document, $(this).attr('id'));
}
);
}
$(this).attr('id') get the right Id but div is not coming in edit mode. Page is empty and no control is on the page. Any help please
thanks
Offline
#21 2008-04-07 13:51:58
Re: Single Menu - Multiple TinyMCE Editors
Updated the commands it now takes the element_id and window options.
http://wiki.moxiecode.com/index.php/Tin … l_commands
Best regards,
Spocke - Main developer of TinyMCE
Offline
#22 2008-04-07 13:55:18
- lordali
- Member
- Registered: 2008-01-18
- Posts: 22
Re: Single Menu - Multiple TinyMCE Editors
thanks but now how I write my command keeping in mind above code?
please
Command is
tinyMCE.execCommand('mceAddFrameControl',false,{element_id:'someid', window:frame.window, other_init_option:'xyz'});
My parameters are
element_id:$(this).attr('id')
Frame is = parent.bodyframe.document
used this command and tried many way but not working.
tinyMCE.execCommand('mceAddFrameControl',false,$(this).attr('id'), window.parent.bodyframe);
Tried both below commands but nothing works ![]()
tinyMCE.execCommand('mceAddFrameControl', false, {document:parent.bodyframe.document,element:$(this).attr('id')});
tinyMCE.execCommand('mceAddFrameControl', false, {window:parent.bodyframe.window,element:$(this).attr('id')});
please help
Last edited by lordali (2008-04-08 11:26:47)
Offline
#23 2008-04-17 17:22:24
Re: Single Menu - Multiple TinyMCE Editors
lordali,
I think you have two problems:
1. "element" should be "element_id"
2. You need to pass the iframe's window object which is available via the contentWindow property.
Here is how the code should look:
Code:
tinyMCE.execCommand('mceAddFrameControl', false, {window:parent.bodyframe.contentWindow,element_id:$(this).attr('id')});If you find that "parent.bodyframe.contentWindow" is undefined, try using parent.document.getElementById('bodyframe').contentWindow.
Offline
#24 2008-04-21 08:52:16
- lordali
- Member
- Registered: 2008-01-18
- Posts: 22
Re: Single Menu - Multiple TinyMCE Editors
Thanks mbajema,
I did what you said and I get the error 'DOM.get{...}' is null or not an object.
Here is the URL to see the error http://test.qcvc.net/TinyMCE/index.html
please help
Offline
#25 2008-04-23 22:36:16
Re: Single Menu - Multiple TinyMCE Editors
There is a small bug in IE. Try changing line 2547 from:
Code:
DOM.get("__ie_onload").onreadystatechange = nullto:
Code:
this.onreadystatechange = null
The problem is that the DOM's window/document are changed when you call the 'mceAddFrameControl' command and so DOM.get is looking in the wrong location.
Offline

© 2003-2010