To the Ministry's main lobby The Ministry Blog
concert setlists

21 March, 2004

MT text formatting fixed

As mentioned earlier, the text formating buttons (bold, italic, underline and URL) of the Movable Type 'Create New Entry' interface only appear in Internet Explorer; in Mozilla Firefox, they're missing.  Having done a little research, there's a straightforward fix, which has been known for at least a year.  The following code and instructions are largely (and gratefully!) taken from a post at Kurcula.com, but significantly differs from that in two respects, so is worth presenting here too.

The file requiring amendment is "[MTPath]/tmpl/cms/edit_entry.tmpl" i.e. from the root directory of your MT installation, navigate to the /tmpl/ subdirectory, and the /cms/ subdirectory within that, then open file 'edit-entry.tmpl' in an editor (e.g. Notepad). Remember to make a backup copy of the unmodified file first!

  1. Place the following code into the script section of the <head> tag; I made it the very last item, immediately before the closing:
    //-->
    </script>
    </head>


    <TMPL_IF NAME=AGENT_MOZILLA>
    function getSelectStart(s) {
      return s.selectionStart;
    }
    function getSelectEnd(s) {
      return s.selectionEnd;
    }
    function getTextLength(s) {
      return s.textLength;
    }
    function getMozSelection(s) {
      return (s.value).substring(getSelectStart(s), getSelectEnd(s))
    }
    function setMozSelection(a,z) {
      s.selectionStart = a;
      s.selectionEnd = z;
    }
    function wrapSelection(v) {
      var s = document.forms['entry_form'].text
      var s1 = (s.value).substring(0,getSelectStart(s))
      var s2 = (s.value).substring(getSelectEnd(s),getTextLength(s))
      s.value = s1 + '<' + v + '>' + getMozSelection(s) + '</' + v + '>' + s2
    }
    function insertMozLink() {
      var s = document.forms['entry_form'].text
      var s1 = (s.value).substring(0,getSelectStart(s))
      var s2 = (s.value).substring(getSelectEnd(s),getTextLength(s))
      var my_link = prompt('Enter URL:', 'http://')
      if (my_link != null)
        s.value = s1 + '<a href="' + my_link + '" target="_blank">' + getMozSelection(s) + '</a>' + s2
    }
    </TMPL_IF>

    Note that this incorporates a secondary modification of standard MT code, causing all inserted URLs to open in new windows (as described earlier). If you don't want this to happen, replace the last line of the final function with:

        s.value = s1 + '<a href="' + my_link + '">' + getMozSelection(s) + '</a>' + s2

  2. Secondly, find the following line in the body of the file; it should be somewhere around line 410:

    <script language="javascript">
    if (document.selection) {

    This is the section which generates the buttons in the IE version, so the Mozilla equivalent goes in at the same place. Immediately after the closing </script> of that section, insert:

    <TMPL_IF NAME=AGENT_MOZILLA>
    <table border="0" cellspacing="0" cellpadding="0" width="107">
    <tr>
    <td width="24"><a href="javascript:wrapSelection('b')">
    <img src="<TMPL_VAR NAME=STATIC_URI>images/bold-button.gif" alt="bold" width="24" height="18" border="0"></a></td>
    <td width="24"><a href="javascript:wrapSelection('i')">
    <img src="<TMPL_VAR NAME=STATIC_URI>images/italic-button.gif" alt="italic" width="24" height="18" border="0"></a></td>
    <td width="24"><a href="javascript:wrapSelection('u')">
    <img src="<TMPL_VAR NAME=STATIC_URI>images/underline-button.gif" alt="underline" width="24" height="18" border="0"></a></td>
    <td width="26"><a href="javascript:insertMozLink()">
    <img src="<TMPL_VAR NAME=STATIC_URI>images/url-button.gif" alt="link" width="26" height="18" border="0"></a></td>
    </tr>
    </table>
    </TMPL_IF>

    To be absolutely clear: this follows the code for IE buttons, it doesn't replace it!

    This is slightly different to the Kurcula.com version, as that code didn't work for me.

In case you were concerned, this includes a browser detection feature, so will still work in IE too.

Comments

Thank you very much, I had been under the impression that there was still a bug making it impossible to achieve this with Mozilla. That has been pleasantly proven wrong. Rock on Mozilla!! (esp. Firefox)

Posted by Philip Ashlock at April 13, 2004 11:14 AM

Hi,

Just to say thanks for the Firefox text formatting fix.
Just one thing though theres a wee bug in the second part of the code.

>a href="javascript:insertMozLink()">
Should be

I might also point out that MT users who use a "Blog This" bookmarklet will also need to change bm_entry.tmpl using exactly the same code and it is located in the same folder as edit_entry.tmpl

Pip pip

Posted by LDMA at July 18, 2004 12:30 PM

Thanks. I've made the amendment, so it's safe to cut-and-paste.

Thanks also for the note about the 'Blog This!' bookmarklet - I don't use it myself, but now you've reminded me about it, I might give it a try.

Posted by NRT at July 18, 2004 05:17 PM
.
Site Home Tull Tour History Annotated Passion Play
.
Day in the life... Page design and original graphics © NRT, 2003