tinyMCE, change content depending on the link that opens it
I've got two links that opens a tinyMCE embedded inside a fancybox.
Now i'd like to change the content inside depending on what link the user clicks 开发者_Python百科on, the content that i want to show inside tinyMCE is the link that im clicking on.
I've tried to set $('.editor').html($(this).html()) and it works the first time, the right content gets shown.
BUT here's my problem, the content gets 'stuck', when i close my fancybox and clicks the other link then the first content is still there.
Is there anyway i can reset the tinyMCE? I've tried setting $('editor').text('') and that removes the content but it wont get back when i click the button.
it probably has something to do with the iframe that tinyMCE produces, but i can't get it to work...
Here is my current code...
HTML " />
<!--File2-->
<div class="title">
<a href="#mce" class="edit"><h2>Titel</h2></a>
</div>
<div class="content">
<a href="#mce" class="edit">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Ut aliquam diam eget elit tristique sit amet fringilla velit sagittis.
Nam aliquet, nisl eget elementum consectetur, felis arcu feugiat felis, vel fermentum mi ipsum vitae neque.
Suspendisse placerat leo dolor, ut mollis elit. Nullam bibendum posuere risus tempus viverra.
Aliquam in erat dui. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aenean auctor lacinia erat, ut facilisis lorem scelerisque eu.
Duis vitae ullamcorper felis. Pellentesque blandit tortor quis magna placerat eget iaculis velit commodo.
Nam imperdiet auctor scelerisque. Proin fermentum sem in nulla ornare euismod.
Maecenas faucibus facilisis cursus. Proin tincidunt luctus egestas.
Curabitur vestibulum aliquet viverra.
</p>
</a>
</div>
javascript
$('.editor').html('');
var content = $(this).html();
$('.editor').html(content);
$(this).fancybox(
{
'size' : 'auto',
'onComplete': function()
{
$('.editor').tinymce(
{
script_url : '/media/tiny_mce/tiny_mce.js',
theme : 'advanced',
height: 450,
plugins : 'ecmsimage,pagebreak,style,layer,table,save,advhr,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist',
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,cleanup,help,|,insertdate,inserttime,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,|,sub,sup,|,charmap,iespell,advhr,|,code,preview,fullscreen",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
theme_advanced_resize_horizontal: false
});
$('#fancybox-inner').width(550).height(500);
$('#fancybox-wrap').width(550).height(500);
$.fancybox.center();
}
});
You need to shut down tinymce correctly before closing the fancybox in order to be able to open the tinymce editor a second time. Use this to shut it down correctly
tinymce.EditorManager.execCommand('mceRemoveControl',true, editor_id);
The editorid equals the id of your html element for which you initialize your tinymce.
精彩评论