TinyMCE multiple CSS classes - tinymce

I’ve been looking for a way to do this. I have a style sheet that is loaded into TinyMCE. The style sheet is generated via my content management system based of the active template. Problem is I can not get TinyMCE to let me select multiple CSS classes to a signle element. Here is a example:
.left_round_thumb_small {
width:65px;
height:65px;
border-radius:35px;
-moz-border-radius:35px;
-webkit-border-radius:35px;
-khtml-border-radius:35px;
background:url(/skins/msc_2013/images/lines.png) repeat;
float:left;
margin:0 25px 0 0;
}
.center_round_thumb_large {
width:162px;
height:162px;
border-radius:85px;
-moz-border-radius:85px;
-webkit-border-radius:85px;
-khtml-border-radius:85px;
background:url(/skins/msc_2013/images/lines.png) repeat;
position:relative;
margin:0 25px 0 0;
}
.round_border_black {border:1px solid black;}
.round_border_red {border:1px solid red;}
.round_border_blue {border:1px solid #00aeef;}
.round_border_green {border:1px solid #3cb64b;}
Now I know I could go in and do something like:
tinyMCE.init({
style_formats : [
{title: 'Left Thumb Black', classes: 'left_round_thumb_small round_border_black'},
{title: 'Center Thumb Blue', classes: 'center_round_thumb_small round_border_blue'},
]
});
Now seeing that this style sheet loaded into TinyMCE is generated based of the CMS’s active template. If I were to change the template I would also have to change the style code. Which will be come a major hassle in the future.
So anyone knows of a code patch to the style selector or plugin that will let me do this?

see below usage of content_css for multiple css files
tinymce.init({
selector: 'textarea',
height: 500,
theme: 'modern',
plugins: [
'advlist autolink lists link image charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime media nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern imagetools'
],
toolbar1: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
toolbar2: 'print preview media | forecolor backcolor emoticons',
image_advtab: true,
templates: [
{ title: 'Test template 1', content: 'Test 1' },
{ title: 'Test template 2', content: 'Test 2' }
],
**content_css: [
'//fast.fonts.net/cssapi/e6dc9b99-64fe-4292-ad98-6974f93cd2a2.css',
'//www.tinymce.com/css/codepen.min.css']**
});

I know this is an old post, but here is what I do, in case someone else come looking.
style_formats: [
{
title: 'Button Styles', items: [
//{ title: 'Button Class (Must Select)', selector: 'a', classes: 'btn' },
{ title: 'Default Class', selector: 'a', classes: ['btn', 'btn-default'] },
{ title: 'Primary Class', selector: 'a', classes: ['btn', 'btn-primary'] },
{ title: 'Success Class', selector: 'a', classes: ['btn', 'btn-success'] },
{ title: 'Warning Class', selector: 'a', classes: ['btn', 'btn-warning'] },
{ title: 'Danger Class', selector: 'a', classes: ['btn', 'btn-danger'] },
{ title: 'Info Class', selector: 'a', classes: ['btn', 'btn-info'] },
{ title: 'Charcoal Class', selector: 'a', classes: ['btn', 'btn-charcoal'] },
{ title: 'Disabled Class', selector: 'a', classes: ['btn', 'btn disabled'] }]
}
]
As you can see, I wanted to include the 'btn' class with each of the Bootstrap button classes. All you have to do is wrap each class name in single-quotes, and separated each class name with a coma, then wrap all those class names in square brackets []
example: classes: ['btn','btn-default']
I hope this helps someone else.

Based on the name classes - being plural and also on other configuration setting example syntaxes, I would believe that it should look something like this:
tinyMCE.init({
style_formats : [
{title : 'Style1', classes : {'left_round_thumb_small','round_border_black'} },
{title : 'Style2', classes : {'center_round_thumb_small','round_border_blue'} },
]
});

Related

"Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'apply')" error in TinyMCE

I'm getthing this error message "Cannot read properties of undefined (reading 'apply')" when I applied TinyMCE and run in my webpage.
tinymce.min.js:9 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'apply')
at _x.execCallback (tinymce.min.js:9:366461)
at m1 (tinymce.min.js:9:332437)
at h1 (tinymce.min.js:9:333521)
at tinymce.min.js:9:340110
This is the error point but I don't know how can I fix this error message.
_x.prototype.execCallback = function(e) {
for (var t = [], n = 1; n < arguments.length; n++)
t[n - 1] = arguments[n];
var r, o = this.settings[e];
if (o)
return this.callbackLookup && (r = this.callbackLookup[e]) && (o = r.func,
r = r.scope),
"string" == typeof o && (r = (r = o.replace(/\.\w+$/, "")) ? Ex(r) : 0,
o = Ex(o),
this.callbackLookup = this.callbackLookup || {},
this.callbackLookup[e] = {
func: o,
scope: r
}),
o.apply(r || this, t)
}
This is the init value in TinyMCE. I copied default value in one of the free bootstrap templates.
var useDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
tinymce.init({
selector: 'textarea',
plugins: 'print preview paste importcss searchreplace autolink autosave save directionality code visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor insertdatetime advlist lists wordcount textpattern noneditable help charmap quickbars emoticons',
imagetools_cors_hosts: ['picsum.photos'],
menubar: 'file edit view insert format tools table help',
toolbar: 'undo redo | bold italic underline strikethrough | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | forecolor backcolor removeformat | pagebreak | charmap emoticons | fullscreen preview save print | insertfile image media template link anchor codesample | ltr rtl',
toolbar_sticky: true,
table_background_color_map: [
{title: 'Red', value: 'FF0000'},
{title: 'White', value: 'FFFFFF'},
{title: 'Yellow', value: 'F1C40F'}
],
table_border_styles: [
{title: 'Solid', value: 'solid'},
{title: 'Dotted', value: 'dotted'},
{title: 'Dashed', value: 'dashed'}
],
autosave_ask_before_unload: true,
autosave_interval: '30s',
autosave_prefix: '{path}{query}-{id}-',
autosave_restore_when_empty: false,
autosave_retention: '2m',
image_advtab: true,
link_list: [{
title: 'My page 1',
value: 'https://www.tiny.cloud'
},
{
title: 'My page 2',
value: 'http://www.moxiecode.com'
}
],
image_list: [{
title: 'My page 1',
value: 'https://www.tiny.cloud'
},
{
title: 'My page 2',
value: 'http://www.moxiecode.com'
}
],
image_class_list: [{
title: 'None',
value: ''
},
{
title: 'Some class',
value: 'class-name'
}
],
importcss_append: true,
file_picker_callback: function(callback, value, meta) {
/* Provide file and text for the link dialog */
if (meta.filetype === 'file') {
callback('https://www.google.com/logos/google.jpg', {
text: 'My text'
});
}
/* Provide image and alt text for the image dialog */
if (meta.filetype === 'image') {
callback('https://www.google.com/logos/google.jpg', {
alt: 'My alt text'
});
}
/* Provide alternative source and posted for the media dialog */
if (meta.filetype === 'media') {
callback('movie.mp4', {
source2: 'alt.ogg',
poster: 'https://www.google.com/logos/google.jpg'
});
}
},
templates: [{
title: 'New Table',
description: 'creates a new table',
content: '<div class="mceTmpl"><table width="98%%" border="0" cellspacing="0" cellpadding="0"><tr><th scope="col"> </th><th scope="col"> </th></tr><tr><td> </td><td> </td></tr></table></div>'
},
{
title: 'Starting my story',
description: 'A cure for writers block',
content: 'Once upon a time...'
},
{
title: 'New list with dates',
description: 'New List with dates',
content: '<div class="mceTmpl"><span class="cdate">cdate</span><br /><span class="mdate">mdate</span><h2>My List</h2><ul><li></li><li></li></ul></div>'
}
],
template_cdate_format: '[Date Created (CDATE): %m/%d/%Y : %H:%M:%S]',
template_mdate_format: '[Date Modified (MDATE): %m/%d/%Y : %H:%M:%S]',
height: 600,
image_caption: true,
quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quickimage quicktable',
noneditable_noneditable_class: 'mceNonEditable',
toolbar_mode: 'sliding',
contextmenu: 'link image table',
skin: useDarkMode ? 'oxide-dark' : 'oxide',
content_css: '../static/assets/js/mycontent.css',
content_style: 'body { font-family: Malgun Gothic; font-size:13px}',
font_formats: 'Gothic=Malgun Gothic, sans-serif',
init_instance_callback: 'insert_contents'
});
The problem appears to be caused by this line:
init_instance_callback: 'insert_contents'
In there you're telling TinyMCE to call a function called insert_contents in the global scope when the editor initializes, however in the examples you've given that's never defined. This would then explain why the o variable is undefined as TinyMCE is unable to lookup that function and execute it as part of its initialization sequence.
I'm not sure what your expected behavior is there, but the simplest solution is likely going to be to just remove it.

TinyMCE "Add Class" Input Field to Link Dialog

link_class_list plugin allows to create a list of classes to choose when adding a link. Is there a way to add an open input instead of a dropdown so the user can enter any class?
These are the parameters on the documentation but there isn't any mention regarding an open input field.
tinymce.init({
selector: "textarea", // change this value according to your HTML
plugins: "link",
menubar: "insert",
toolbar: "link",
link_class_list: [
{title: 'None', value: ''},
{title: 'Dog', value: 'dog'},
{title: 'Cat', value: 'cat'}
]
});
<script>
tinymce.init({
selector: 'textarea',
menubar:false,
plugins: [
'advlist autolink link image lists charmap print preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
'save table contextmenu directionality emoticons template paste textcolor code pageembed codesample advcode '
],
toolbar: 'bold italic | link image preview media fullpage pageembed | code codesample forecolor backcolor | emoticons styleselect alignleft aligncenter alignright alignjustify bullist numlist outdent indent |table tabledelete | tableprops tablerowprops tablecellprops | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol',
default_link_target: '_blank',
style_formats: [{title: 'Button (Default)', selector: 'a', classes: ''}, {title: 'Button (primary)', selector: 'a', classes: 'btn btn-primary'}, {title: 'Button (success)', selector: 'a', classes: 'btn btn-success'}],
link_class_list: [{title:'Button (Default)', value:''}, {title:'Button (primary)', value:'btn btn-primary'}, {title:'Button (success)', value:'btn btn-success'}]
});
</script>
Try this.

TinyMCE "paste button" does not work

My question about TinyMCE editor.
In IE brower it works fine. But when I paste something in FF & Chrome I'm receiving the message: "Your browser doesn't support direct access to the clipboard. Please use the Ctrl+X/C/V keyboard shortcuts instead."
I've not found any documentation to solve this problem!
I need help ,Thanks!
I'm a little late to this, but I was having the same problem. I did some digging, and this configuration worked for me.
tinyMCE.init({
selector: "textarea",
language: editorLanguage,
plugins: [
"autolink lists link image anchor",
"searchreplace visualblocks",
"insertdatetime media contextmenu paste"
],
menu: {
edit: { title: 'Edit', items: 'undo redo | cut copy paste | selectall' },
insert: { title: 'Insert', items: 'link image' },
view: { title: 'View', items: 'visualaid' },
format: { title: 'Format', items: 'bold italic underline strikethrough superscript subscript | formats | removeformat' }
},
convert_urls: false,
paste_data_images: true
});
At a minimum though, all you need is this:
tinyMCE.init({
selector: "textarea",
plugins: "image,paste",
paste_data_images: true
});
This is working for me, using the cdn hosted version ( cdn.tinymce.com/4/tinymce.min.js )
Hope this helps someone!

TinyMCE 4 How change font-size styles?

I would like add change font-style for text;
For it I use this script:
tinymce.init({
selector: selector_id,
theme: "modern",
theme_modern_font_sizes: ["6px,7px,8px,9px,10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px,31px,32px,36px,38px,40px"],
font_size_style_values: ["6px,7px,8px,9px,10px,11px,12px,13px,14px,15px,16px,17px,18px,19px,20px,21px,22px,23px,24px,25px,26px,27px,28px,29px,30px,31px,32px,36px,38px,40px"],
/* width: 300,
height: 300, */
plugins: [
"advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"save table contextmenu directionality template paste textcolor"
],
content_css: "./style.css",
toolbar: "insertfile undo redo | fontsizeselect | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor",
style_formats: [
{title: 'Bold text', inline: 'b'},
{title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
{title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
{title: 'Example 1', inline: 'span', classes: 'example1'},
{title: 'Example 2', inline: 'span', classes: 'example2'},
{title: 'Table styles'},
{title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
],
file_browser_callback : elFinderBrowser ,
spellchecker_languages : '+Русский=ru,English=en'
});
But inside of my font-size(6px,7px,8px,9px an other) I see 8pt,10px,12pt and other.
Please tell me why I don't see my font size in select and how do I make it right?
Your setup seams to be for tinymce 3.x. Forget that, upgrade to 4.x and use as follow:
tinymce.init({
fontsize_formats: "8pt 9pt 10pt 11pt 12pt 26pt 36pt",
theme: 'modern',
and then in toolbar:
toolbar: "undo redo pastetext | styleselect | fontselect | fontsizeselect"
How to change font size in wordpress & tiny mce, no coding required...just -
1.Use the plugin 'TinyMCE Advanced'
Activate it in settings.
More detailed instructions here.
For version Version 4.1.9
You will need to edit your active theme functions.php with this:
// Customize mce editor font sizes
if ( ! function_exists( 'wpex_mce_text_sizes' ) ) {
function wpex_mce_text_sizes( $initArray ){
$initArray['fontsize_formats'] = "9px 10px 12px 13px 14px 16px 18px 21px 24px 28px 32px 36px";
return $initArray;
}
}
add_filter( 'tiny_mce_before_init', 'wpex_mce_text_sizes' );
Reference: http://www.wpexplorer.com/wordpress-tinymce-tweaks/

Remove menu and status bars in TinyMCE 4

I am trying to remove the menu and status bars from TinyMCE 4 because I want to setup a very basic editor. Is this possible?
The documentation for TinyMCE 3 does not seem to be relevant and I cannot find anything for version 4.
I looked at the source and it was fairly obvious:
tinyMCE.init({
menubar:false,
statusbar: false,
//etc
})
This removes both.
You can also customise what parts of the default menu bar are visible by specifying a string of enabled menus - e.g. menubar: 'file edit'
You can define your own menus like this:
menu : {
test: {title: 'Test Menu', items: 'newdocument'}
},
menubar: 'test'
If you want to remove entire Menu bar from top
tinymce.init({
menubar: false,
});
But if you want Custom menubar with some submenu
tinymce.init({
menu: {
file: {title: 'File', items: 'newdocument'},
edit: {title: 'Edit', items: 'undo redo | cut copy paste pastetext | selectall'},
insert: {title: 'Insert', items: 'link media | template hr'},
view: {title: 'View', items: 'visualaid'},
format: {title: 'Format', items: 'bold italic underline strikethrough superscript subscript | formats | removeformat'},
table: {title: 'Table', items: 'inserttable tableprops deletetable | cell row column'},
tools: {title: 'Tools', items: 'spellchecker code'}
}
});
see TinyMCE for more help.
So, It is clearly metioned in their docs that to make the values to false.
tinymce.init({
menubar: false,
branding: false,
statusbar: false,
})
In the latest update to v5
You can display menubar as such
tinymce.init({
menu: {
edit: { title: 'Edit', items: 'undo redo | cut copy paste pastetext | selectall searchreplace' },
insert: { title: 'Insert', items: 'image link charmap pagebreak' },
format: { title: 'Format', items: 'bold italic underline strikethrough superscript subscript | formats | removeformat' },
table: { title: 'Table', items: 'inserttable tableprops deletetable | cell row column' }
},
menubar: 'edit insert format table',
});
see https://www.tiny.cloud/docs/ for more details
If you want a completely clean text box, you could disable all the bars, including de "toolbar":
tinymce.init({
selector:'textarea',
branding: false,
menubar:false,
statusbar: false,
toolbar: false,
});
In the community edition I think you are not allowed to hide the statusbar (Powered by Tiny) branding part.
https://www.tiny.cloud/docs-4x/configure/editor-appearance/#branding