Thursday, May 21, 2015

Changing the default font-size used by TinyMCE

Continued to work on #237. My problem is: I think I did exactly as explained under content_css, but my custom css file is being ignored.

In the <head> section of the main HTML document I have:

<script type="text/javascript" src="/static/byteforce/Ext.ux.TinyMCE.js"></script>
<script language="javascript" type="text/javascript">
        content_css : "/static/tinymce_content.css",
        theme_advanced_font_sizes : "12px,13px,14px,16px,18px,20px,24px",
        font_size_style_values : "12px,13px,14px,16px,18px,20px,24px",
        theme : "advanced",
        mode : "textareas"

This is generated by the get_head_lines method of lino.modlib.tinymce.

I created lino/modlib/tinymce/static/tinymce_content.css as a copy of tiny_mce/themes/advanced/skins/default/content.css, changed the font-size in the first line:

body, td, pre {color:#000; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:8px;}

I tested whether the development server delivers the content of that file under /static/tinymce_content.css.

The TinyMCE editor itself works.

But the default font continues to have a size of 10pt, not 12px.

When I inspect the DOM, I see that the editor is rendered as an iframe:

<iframe style="width: 668px; height: 159px; display: block;" title="Texte richeFaites ALT-F10 pour accéder à la barre d'outils. Faites ALT-0 pour accéder à l'aide" allowtransparency="true" src="javascript:&quot;&quot;" id="ext-comp-3452_ifr" frameborder="0">

<head xmlns="">
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link type="text/css" rel="stylesheet" href="">
  <link type="text/css" rel="stylesheet" href="">
<body dir="ltr" spellcheck="false" id="tinymce" class="mceContentBody " onload="window.parent.tinyMCE.get('ext-comp-3452').onLoad.dispatch();" contenteditable="true">
  <p>foo<br data-mce-bogus="1"></p>


And indeed, there is no mention of the custom css file specified in my content_css option.

Tilt! the explanation was that the call to tinyMCE.init() in my page source code (the one generated by get_head_lines) had no effect at all because TinyMCE initialization is done again by Lino.RichTextPanel (defined in lino/modlib/tinymce/config/tinymce/tinymce.js, i.e. the code snippet included with the lino_*.js). I can even remove the get_head_lines method of lino.modlib.tinymce.