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!
- 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
- 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.
Posted by Ministry at 20:40
| 495 words