How to customize tinyMCE built-in buttons like -silverstripe- CMS - plugins

when I had a look on http://demo.silverstripe.com/admin/ [user-name:admin ,password:admin]
I noticed that they have overridden the insert image button and also the insert flash buttonthey have replaced it with their own widget.
The Question is What is the easiest way achieve this or the best guide ?
note : I'm not using sliverstripe or any ready made CMS

Adding your own buttons is quite well described at the TinyMCE web: http://tinymce.moxiecode.com/tryit/custom_toolbar_button.php
Pasted from site:
tinyMCE.init({
mode : "textareas",
theme : "advanced",
theme_advanced_buttons1 : "mybutton,bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
plugins : 'inlinepopups',
setup : function(ed) {
// Add a custom button
ed.addButton('mybutton', {
title : 'My button',
image : 'img/example.gif',
onclick : function() {
// Add you own code to execute something on click
ed.focus();
ed.selection.setContent('Hello world!');
}
});
}
});
Just change this as you please.

Related

tinyMce reloading data with html tags

I'm having issue with TinyMCE.
After saving the contents of the editor and redisplaying it all the HTML tags are visible.
This is how I'm initializing the editor:
// Tinymce Config
tinyMCE.init({
// General options
mode : "specific_textareas",
editor_selector : "mceEditor",
language : "<?php echo $tinyMceLang?>",
setup : function(ed) {
ed.onActivate.add(tinyOnEdit);
},
theme : "advanced",
plugins : "table",
// Theme options
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontsizeselect,|,forecolor,backcolor,|,table,row_before,row_after,delete_row,col_before,col_after,delete_col,code",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_buttons4 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_path : false,
theme_advanced_resizing : true,
convert_fonts_to_spans : true,
//font_size_style_values : "0.7em,0.8em,1em,1.2em,1.5em,2em,3em",
//font_size_style_values : "8pt,10pt,12pt,14pt,18pt,24pt,36pt",
// content CSS (should be your site CSS)
content_css : "/css/tiny_content.css"
});
if i paste a content like this (With HTML tags):
<p><span style="color: #ff0000;">testing tinymce contents</span></p>
redisplayed as :
<p><span style="color: #ff0000;">testing tinymce contents</span></p> (With html tags)
but excepted result is :
testing tinymce contents (Text with red color)(Not to allow html tags)
Open the HTML Source Editor.
Paste your content (With HTML tags) at the desired place in the html source editor.
Click on update.
That's it.
In respond to your comment
Add paste in your list of plugins,also include this plugin option
plugins : "table,paste",
paste_remove_styles: true,
in your tinyMCE.init like
// Tinymce Config
tinyMCE.init({
// General options
mode : "specific_textareas",
editor_selector : "mceEditor",
language : "<?php echo $tinyMceLang?>",
setup : function(ed) {
ed.onActivate.add(tinyOnEdit);
},
theme : "advanced",
plugins : "table,paste",
paste_remove_styles: true,
// Theme options
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontsizeselect,|,forecolor,backcolor,|,table,row_before,row_after,delete_row,col_before,col_after,delete_col,code",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_buttons4 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_path : false,
theme_advanced_resizing : true,
convert_fonts_to_spans : true,
//font_size_style_values : "0.7em,0.8em,1em,1.2em,1.5em,2em,3em",
//font_size_style_values : "8pt,10pt,12pt,14pt,18pt,24pt,36pt",
// content CSS (should be your site CSS)
content_css : "/css/tiny_content.css"
});
Hope this helps,cheers!!

TinyMCE and BBCode plugin

I am trying to implement tinyMCE's BBCode plugin but not being able to make it work.
This is the init code:
$(textarea).tinymce({
script_url : '/js/tiny_mce/tiny_mce.js',
theme : "advanced",
plugins : "bbcode",
theme_advanced_buttons1 : "bold,italic,underline,forecolor,|,undo,redo,link,unlink,|,removeformat,cleanup",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_styles : "Code=codeStyle;Quote=quoteStyle",
entity_encoding : "raw",
remove_linebreaks : false,
forced_root_block : false,
force_br_newlines : true,
force_p_newlines : false,
convert_newlines_to_brs : true,
remove_redundant_brs : false,
width: '700px',
height: '250px'
});
The thing is that when I submit the form, HTML tags are being posted instead of BBCode. If I try tinyMCE.activeEditor.getContent() on the console, it brings BBCode.
I'm using an input[type=submit] to send the form (without any JS attached to it).
Why am I not getting BBCode posted?
Try passing the textarea content by a htmlentities function before sending it to the file that will handle the data!

TinyMCE generating compact spaces (160 in ASCII) (0xA0 in HEX) instead of

does anyone know how to configure tinyMCE to utilize instead of the compact spaces? Storing the data in die db causes character encoding issues. We are currently utilizing tinyMCE to send emails and when these characters are sent they create a bunch of question marks, because the encoding we use in emailing cannot handle the compact spaces.
Any help would be greatly appreciated.
See below snippet for init code
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
skin : "o2k7",
plugins : "spellchecker,style,layer,table,advhr,inlinepopups,insertdatetime,print,contextmenu,fullscreen,noneditable,visualchars,xhtmlxtras,wordcount,advlist,paste,tabfocus",
// Theme options
theme_advanced_buttons1 : "newdocument,spellchecker,|,print,|,styleselect,formatselect,fontselect,fontsizeselect,|,fullscreen",
theme_advanced_buttons2 : "bold,italic,underline,strikethrough,sub,sup,|,backcolor,forecolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,|,insertdate,inserttime,|,code,|,showmorebuttons,",
theme_advanced_buttons3 : "tablecontrols,|,insertlayer,moveforward,movebackward,absolute,|,styleprops,hr,removeformat,visualaid,|,charmap,advhr,",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
setup : function(ed) {
// Add a custom button
ed.addButton('showmorebuttons', {
title : 'Expand Advanced Toolbar',
image : '/img/email/toolbars.gif',
onclick : function() {
showMoreButtons(ed.id);
}
});
},
oninit : function(){
var tmpIdent = tinyMCE.activeEditor.id;
document.getElementById(tmpIdent + "_toolbar3").style.display = 'none';
var currentHeight = document.getElementById(tmpIdent+"_ifr").style.height;
currentHeight = currentHeight.substring(0, currentHeight.indexOf("px"));
currentHeight = (currentHeight*1)+15;
document.getElementById(tmpIdent+"_ifr").style.height=currentHeight+"px";
},
apply_source_formatting : false,
force_p_newlines : false,
remove_linebreaks : false,
forced_root_block : false,
force_br_newlines : true,
entity_encoding : "raw",
// Example content CSS (should be your site CSS)
content_css : "/tinymce/example/css/content.css",
relative_urls : false,
// Style formats
style_formats : [
{title : 'Word H1', block : 'h1', styles : {color : '#365f91', 'font-family' : 'cambria'}},
{title : 'Word H2', block : 'h2', styles : {color : '#4f81bd', 'font-family' : 'cambria'}},
{title : 'Word H3', block : 'h3', styles : {color : '#4f81bd', 'font-family' : 'cambria'}},
{title : 'Word H4', block : 'h4', styles : {color : '#4f81bd', 'font-family' : 'cambria', "font-style" : "italic"}}
]
});
Tinymce needs to insert protected spaces (U+00A0) because without them browsers would display only one single space (you may play around with the html in tinymce using the code plugin to see this behavior). This may lead to the problems you described. One solution to this could be to replace those protected spaces onSaveContent or before sending the content to the server. The second approach is to do the replace on server-side.

TinyMCE Configuration

I have following setup for tiny MCE. As you can see in image it shows a third row of buttons . I dont know where it comes from ! There is no setting in my javascript code for a third row still it shows that there.
tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,nonbreaking,xhtmlxtras,template,advlist,fullpage",
theme_advanced_buttons1 : "formatselect,fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,|,forecolor,backcolor",
theme_advanced_buttons2 : "mybutton,|,link,unlink,|,hr,removeformat,pastetext,pasteword,cleanup,|,undo,redo,|,code",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "none",
theme_advanced_resizing : true,
convert_urls : false,
fullpage_default_doctype: "",
content_css : "css/content.css",
cleanup : false,
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",
});
I had to add following line which fixed it.
theme_advanced_buttons3 : ""
Remove mybutton from the second row of buttons and the thing is gone.
I suspect you have an error in eigther the plugin-row or one of your button rows.

tinymce disable and enable editor and show text (not as html)

I have 2 editors inside my page. when i click a button i want them to become disabled.
If it is possible i would like it to become a regular textarea and to see the text inise of it as a regular text and not html.
I saw other questions for disabling but did not get them to work..
This is my code:
function create_text_editor()
{
$('#remarks1').tinymce(
{
script_url : 'resources/tinymce/jscripts/tiny_mce/tiny_mce.js',
theme : "advanced",
theme_advanced_buttons1 : "cut,copy,paste,|,bold,italic,underline,|,undo,redo,|,justifyleft,justifycenter,justifyright,justifyfull,|" ,
theme_advanced_buttons2 : "formatselect,fontselect,fontsizeselect,|,forecolor,backcolor,|",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
plugins : "paste" ,
oninit : on_editor_init });
$('#remarks2').tinymce(
{
script_url : 'resources/tinymce/jscripts/tiny_mce/tiny_mce.js',
theme : "advanced",
theme_advanced_buttons1 : "cut,copy,paste,|,bold,italic,underline,|,undo,redo,|,justifyleft,justifycenter,justifyright,justifyfull,|" ,
theme_advanced_buttons2 : "formatselect,fontselect,fontsizeselect,|,forecolor,backcolor,|",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
plugins : "paste" ,
oninit : on_editor_init });
}
'on_editor_init' is emtpy.
Any help will be appritiated,
Thank's In Advance.
You would need to call the save function and to shutdown tinymce. Of course you can execute this code when pushing a tinymce UI button (i guess you know how that works)
tinymce.get(editor_id).save();
tinymce.execCommand('mceRemoveControl', true, editor_id);
Now, you should be able to see the textarea that has been on the website before initializing tinymce.