Tinymce not loading in toogle condition (livewire) - tinymce

component view:
#if ($rich)
<textarea name="content" class="tinymce">{{ $content }}</textarea>
#else
<textarea name="content">{{ $content }}</textarea>
#endif
I want that, if "$rich" found then show tinymce if not then show plain text. condition working fine. but the problem is first time load tinymce toolbar. after that in reverse the tinymce toolbar not loading.
So i don't understand how to load this.
thanks.

I solved my problem this way -
I made two separate child livewire and put the textarea code as per component.
a. simple (livewire)
b. tinymce (livewire)
these child livewire i called from one parent livewire in "if else" condition which i mentioned above post.
#if ($rich)
<livewire:common.tinymce>
#else
<livewire:common.simple>
#endif
in 'tinymce livewire' component view i wrote tinymce init script in "script" tag before content.
EXAMPLE: (tinymce component view)
<div>
<script>
tinymce.init({
selector: "textarea.tinymce",
menubar: false,
statusbar: true,
height: "159px",
paste_data_images: true,
plugins: [
"advlist lists link preview hr paste table",
],
toolbar: "styleselect bold italic bullist | blockquote hr | alignleft aligncenter alignright underline alignjustify | link unlink table",
autosave_interval: "30s",
browser_spellcheck: true,
style_formats: [
{title: "Header 1", format: "h1"},
{title: "Header 2", format: "h2"},
{title: "Header 3", format: "h3"},
{title: "Header 4", format: "h4"},
{title: "Header 5", format: "h5"},
{title: "Header 6", format: "h6"},
{title: "paragraph", format: "p"},
],
});
</script>
<div class="editorpad">
<p class="nm"> content </p>
<textarea name="content" class="tinymce">{{ $content ?? '' }}</textarea>
</div>
</div>
done!
all is working fine.

Related

tinymce adding extra ul tags on loading

Here is my issue plain and simple. I have an input field with this exact data:
<ul>
<li>test</li>
<li>test</li>
</ul>
On load of tinymce if I looked at the code it has in its field it shows this:
<br>
<ul>
<ul>
<li>test</li>
</ul>
</ul>
<br>
<ul>
<ul>
<li>test</li>
</ul>
</ul>
So, as you can see upon loading it is adding extra ul tags and breaks to the field.
Now here is my current config(Note I do have the latest tinymce version 4.8.5, but this also happens with an older version I have of 4.6.5):
tinyMCE.init({
mode : "exact",
elements : "ta_description, ta_restrictions",
// General options
forced_root_block : false,
theme : "modern",
width : "100%",
height : "250px",
menubar: false,
toolbar1: "undo redo styleselect fontselect fontsizeselect | bold italic forecolor backcolor",
toolbar2: "code image link table | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent",
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 moxiemanager"
]
});
This is causing an issue because everytime I save, the process repeats and it adds even more ul tags. Which is similar to why I have forced_root_block disabled because on save it kept adding more and more <p> tags. Now I have found that marking br tags as an invalid element prevents this behavior, but those are needed for linebreaks, I mention that because I am not sure if that helps narrow down where an issue may be.
Note: I am not using wordpress.
Update: This config ended up working for us.
<script defer="defer" type="text/javascript">
tinyMCE.init({
mode : "exact",
elements : "ta_description, ta_restrictions",
// General options
forced_root_block : 'div',
invalid_elements : 'br',
theme : "modern",
width : "100%",
height : "250px",
menubar: false,
toolbar1: "undo redo styleselect fontselect fontsizeselect | bold italic forecolor backcolor",
toolbar2: "code image link table | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent",
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 moxiemanager"
]
});
</script>
If I load your content into TinyMCE I don't see it making all of these extra tags:
http://fiddle.tinymce.com/d4gaab/5
I would suspect there is something in your pre/post processing of the content when its loaded into or extracted from the editor that is causing this to happen.

TinyMCE removes classes from <span> and <i> elements

In code (source) editor of TinyMCE, when I want to add some span or i element with classes (for example, when I want to add Font Awesome icon) - TinyMCE removes classes. For example, if I want to add:
<span class="fa fa-university"></span>
at the end I will have just:
<span></span>
Also, in source code editor I tried to add <i class="fa fa-university"></i> but the problem is same - classes are deleted by TinyMCE (<i></i>).
I am using TinyMCE v4.4.1 and these are my settings:
tinymce.init({
selector: '#body',
height: 500,
theme: 'modern',
plugins: [
'advlist autolink lists link image charmap preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime media nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern codesample fontawesome noneditable'
],
toolbar1: 'insertfile undo redo | formatselect fontselect fontsizeselect fontawesome',
toolbar2: 'bold italic underline strikethrough forecolor backcolor removeformat superscript subscript | alignleft aligncenter alignright alignjustify | outdent indent',
toolbar3: 'code preview | link unlink anchor image media | codesample | bullist numlist table blockquote hr nonbreaking | charmap emoticons | visualchars visualblocks',
image_advtab: true,
relative_urls: false,
extended_valid_elements: 'span',
content_css: '/css/all.css' // this includes fontwawesome...
});
Try adding the following to your TinyMCE configuration:
valid_elements: "*[*]"
When I do this I can add the <span> you reference without issue.
I know this is an old question but this worked for me
extended_valid_elements: 'span[*]'

Tinymce 4 duplicate div's when there are empty div's

This is my first post and I've been searching for a solution for this problem several weeks without any result. I hope you can help me!!!
I'm going to try to explain my problem:
I paste this code into the code editor
<div class="cta">
<div class="recomendado">
Te recomendamos
<div class="triangulo"></div>
</div>
</div>
And click in the OK button. If I click again in the code editor, the result is:
<div class="cta">
<div class="cta">
<div class="recomendado">Te recomendamos
<div class="triangulo"></div>
</div>
</div>
</div>
This is not posibble for my aplication and the html code is created by the client and is not possible to changed that.
In this few weeks, I see the problem are the empty div's. (this example is a short example of the real code).
Our version of tinymce is the 4.0.23 and this is my configuration:
tinymce.init({
selector: "textarea.-dlpe-html",
theme: "modern",
forced_root_block: false,
resize: false,
height: 450,
valid_children: "+h3[span|p|br],h2[span|p|br],h1[span|p|br],h4[span|p|br],h5[span|p|br],div[div|h3|h2|p],span[span|strong],p[div|p|span|strong]",
//extended_valid_elements: "+h3[span|p|br],h2[span|p|br],h1[span|p|br],h4[span|p|br],h5[span|p|br],div[h3|p]",
valid_elements: "* [ * ]",
extended_valid_elements: "* [ * ]", //the blanks are not in real code
cleanup: false,
plugins: [
"advlist autolink link lists charmap print hr anchor pagebreak",
"searchreplace visualblocks visualchars code fullscreen insertdatetime nonbreaking",
"save table contextmenu directionality paste textcolor"
],
toolbar: "undo redo | code | styleselect | bold italic forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link | print | fullscreen",
});
Please, I'm desperated with this bug. Thanks in advance (and sorry for my poor english).
Finally I can solved this problem.
After downgrade the tinymce version to 3.5, I notice that one of the lines in the configuration code was failling.
If you delete the "div[div|h3|h2|p]" part, the error no appear.
Thanks

add tinymce for new element loaded dynamicaly

My page is lodaed with 5 divs which can be edited by Tinymce inline editor. I've a peace of Jquery loding 5 new ones by clicking on a button (so dynamicaly). But of course the new ones are not affected by Tinymce, as the init has already been loaded... How can I manage to activate tinymce for new divs please?
My HTML :
<div id=\"billetdroit\">
<div id=\"divtitre\"><h1 class=\"editable\">blablabla</h1></div>
<div class=\"editable\" id=\"tiny_01\">blablabla2</div>
</div>
<div id=\"billetdroit\">
<div id=\"divtitre\"><h1 class=\"editable\">blablabla</h1></div>
<div class=\"editable\" id=\"tiny_02\">blablabla2</div>
</div>
<div id=\"billetdroit\">
<div id=\"divtitre\"><h1 class=\"editable\">blablabla</h1></div>
<div class=\"editable\" id=\"tiny_03\">blablabla2</div>
</div>
...
...
And a button: when you click, it make appears 5 more divs "billetdroit" dynamicaly
My tinymce init:
tinymce.init({
selector: "textarea",
language: 'fr_FR',
image_advtab: true,
menubar:false,
forced_root_block: false,
plugins: ["link","code","media","image","textcolor", "emoticons"],
toolbar: "bold italic forecolor backcolor alignleft aligncenter alignright alignjustify link unlink image media emoticons"
});
tinymce.init({
selector: "h1.editable",
language: 'fr_FR',
inline: true,
toolbar: "undo redo",
menubar: false
});
tinymce.init({
selector: "div.editable",
language: 'fr_FR',
image_advtab: true,
menubar:false,
inline: true,
forced_root_block: false,
plugins: ["link","code","media","image","textcolor", "emoticons"],
toolbar: "bold italic forecolor backcolor alignleft aligncenter alignright alignjustify link unlink image media emoticons"
});
Any solution?
Thanks
EDIT:
I tryied that:
$(document).ready(function() {
var track_click = 1; //track user click on "load more" button, righ now it is 0 click
var total_pages = Globals.total_pages;
// $('#results').load("loadmore.php", {'page':track_click}, function() {track_click++;}); //initial data to load
$(".load_more").click(function (e) { //user clicks on button
$(this).hide(); //hide load more button on click
$('.animation_image').show(); //show loading image
if(track_click <= total_pages) //user click number is still less than total pages
{
//post page number and load returned data into result element
$.post('loadmore.php',{'page': track_click}, function(data) {
$(".load_more").show(); //bring back load more button
$("#results").append(data); //append data received from server
//scroll page smoothly to button id
$("html, body").animate({scrollTop: $("#load_more_button").offset().top}, 500);
//hide loading image
$('.animation_image').hide(); //hide loading image once data is received
track_click++; //user click increment on load button
}).fail(function(xhr, ajaxOptions, thrownError) { //any errors?
alert(thrownError); //alert with HTTP error
$(".load_more").show(); //bring back load more button
$('.animation_image').hide(); //hide loading image once data is received
});
if(track_click >= total_pages-1) //compare user click with page number
{
//reached end of the page yet? disable load button
$(".load_more").attr("disabled", "disabled");
}
}
$.getScript('include/tinymce/tinymce.min.js', function() {
tinymce.init({
selector: "textarea",
language: 'fr_FR',
image_advtab: true,
menubar:false,
forced_root_block: false,
plugins: ["link","code","media","image","textcolor", "emoticons"],
toolbar: "bold italic forecolor backcolor alignleft aligncenter alignright alignjustify link unlink image media emoticons"
});
tinymce.init({
selector: "h1.editable",
language: 'fr_FR',
inline: true,
toolbar: "undo redo",
menubar: false
});
tinymce.init({
selector: "div.editable",
language: 'fr_FR',
image_advtab: true,
menubar:false,
inline: true,
forced_root_block: false,
plugins: ["link","code","media","image","textcolor", "emoticons"],
toolbar: "bold italic forecolor backcolor alignleft aligncenter alignright alignjustify link unlink image media emoticons"
});
});
});
});
But without success...
There is an easy way to init tinymce editors:
tinyMCE.execCommand("mceAddControl", false, 'your_div_id');

TinyMCE 4 theme_advanced_fonts

I'm trying to add custom font family in TinyMCE Editor version 4.0b1 and keep failing.
All default fonts show, custom fonts like 'Century Gothic' or 'Gill Sans MT' are not showing. Is theme_advanced_fonts not working in TinyMCE 4? I can't find any TinyMCE 4 documentation for this.
tinymce.init({
selector: "textarea",
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
toolbar: "undo redo | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist | link image | fontselect fontsizeselect | forecolor backcolor",
convert_urls: false,
content_css: 'http://www.mydomain.com/css/fonts.css',
theme_advanced_font_sizes : "8px,10px,12px,14px,16px,18px,20px,24px,32px,36px",
theme_advanced_fonts : "Andale Mono=andale mono,times;"+
"Arial=arial,helvetica,sans-serif;"+
"Arial Black=arial black,avant garde;"+
"Book Antiqua=book antiqua,palatino;"+
"Comic Sans MS=comic sans ms,sans-serif;"+
"Courier New=courier new,courier;"+
"Century Gothic=century_gothic;"+
"Georgia=georgia,palatino;"+
"Gill Sans MT=gill_sans_mt;"+
"Gill Sans MT Bold=gill_sans_mt_bold;"+
"Gill Sans MT BoldItalic=gill_sans_mt_bold_italic;"+
"Gill Sans MT Italic=gill_sans_mt_italic;"+
"Helvetica=helvetica;"+
"Impact=impact,chicago;"+
"Iskola Pota=iskoola_pota;"+
"Iskola Pota Bold=iskoola_pota_bold;"+
"Symbol=symbol;"+
"Tahoma=tahoma,arial,helvetica,sans-serif;"+
"Terminal=terminal,monaco;"+
"Times New Roman=times new roman,times;"+
"Trebuchet MS=trebuchet ms,geneva;"+
"Verdana=verdana,geneva;"+
"Webdings=webdings;"+
"Wingdings=wingdings,zapf dingbats"
});
Looks like TinyMCE 4 has been updated, custom fonts works now.
Check this link for the CSS font source:
http://www.tinymce.com/wiki.php/Configuration:content_css
Check this link for the custom font setting:
https://www.tinymce.com/docs/configure/content-formatting/#font_formats
The weird thing is, some of the fonts work (the font style on the custom font list name is correct - green), some not (custom font listed, but the style is not the supposed font style - red)
Looks like theme_advanced_fonts has problem and not fixed yet.
I'm using an alternative solution with style_formats to define fonts
tinymce.init({
...
toolbar: "styleselect",
style_formats: [
{title: 'Open Sans', inline: 'span', styles: { 'font-family':'Open Sans'}},
{title: 'Arial', inline: 'span', styles: { 'font-family':'arial'}},
{title: 'Book Antiqua', inline: 'span', styles: { 'font-family':'book antiqua'}},
{title: 'Comic Sans MS', inline: 'span', styles: { 'font-family':'comic sans ms,sans-serif'}},
{title: 'Courier New', inline: 'span', styles: { 'font-family':'courier new,courier'}},
{title: 'Georgia', inline: 'span', styles: { 'font-family':'georgia,palatino'}},
{title: 'Helvetica', inline: 'span', styles: { 'font-family':'helvetica'}},
{title: 'Impact', inline: 'span', styles: { 'font-family':'impact,chicago'}},
{title: 'Symbol', inline: 'span', styles: { 'font-family':'symbol'}},
{title: 'Tahoma', inline: 'span', styles: { 'font-family':'tahoma'}},
{title: 'Terminal', inline: 'span', styles: { 'font-family':'terminal,monaco'}},
{title: 'Times New Roman', inline: 'span', styles: { 'font-family':'times new roman,times'}},
{title: 'Verdana', inline: 'span', styles: { 'font-family':'Verdana'}}
],
...
});
result:
tinymce.init({
...
font_formats:
"Default='myFontFace', Arial, Helvetica, Tahoma, Verdana, sans-serif;"+
"Arial=arial,helvetica,sans-serif",
...
});
In tinymce 4, theme_advanced_fonts has been rename to font_formats.
You can find the detail from
https://www.tinymce.com/docs/configure/content-formatting/#font_formats
'advanced' and 'simple' theme is removed from tinyMCE 4. New theme added is called 'modern'.
http://www.tinymce.com/wiki.php/Tutorial:Migration_guide_from_3.x