Mozilla and IE decoder
History: I had previously written this decoder, but it wasn’t compatible with anything but IE. (A frustrating point since I’ve been using Firefox pretty religously). I saw that Mark had written one compatible with mozilla - but the only one there convereted EVERYTHING (making it difficult to go back an edit anything you decoded). I also saw Alex had published his quick tags. So I took a little bit of all of them and created the following script. It can’t be turned into a bookmarklet - because it requires having the fieldname passed to it - but at least I could add back the “decoder” button for comments here. (Although - Mark updated his post with the bookmarklet that will just encode brackets, etc.)
So here’s the javascript:
(This needs to go inside <script language=”JavaScript” type=”text/JavaScript”> </script> tags)
function decodeIt(textfield) {
strSelection = ""
if (document.selection) {
strSelection = document.selection.createRange().text;
strSelection = strSelection.replace(new RegExp("<","g"), "<");
strSelection = strSelection.replace(new RegExp(">","g"), ">");
document.selection.createRange().text = strSelection;
}
//MOZILLA/NETSCAPE support
else if (textfield.selectionStart || textfield.selectionStart == '0') {
textfield.focus();
var startPos = textfield.selectionStart;
var endPos = textfield.selectionEnd;
strSelection = textfield.value.substring(startPos, endPos)
strSelection = strSelection.replace(new RegExp("<","g"), "<");
strSelection = strSelection.replace(new RegExp(">","g"), ">");
textfield.value = textfield.value.substring(0, startPos) + strSelection + textfield.value.substring(endPos, textfield.value.length);
}
}
You could then call this script either using a button like this:
<input type="button" onclick="decodeIt(document.FORMNAME.TEXTAREANAME)" value="Decode it">
or in a simple link like this:
<a href="javascript:decodeIt(document.FORMNAME.TEXTAREANAME)">Decode it</a>
I’ve only tested this on IE6 and Firefox on the PC (winXP). When I get access to a mac or more browsers, I’ll test there too. This is the same script I have running for comments here - so if you want to test it on your local set up, please do - and let me know how/if it works.
June 9th, 2004 at 12:08 am
I fixed the bookmarklet.txt link.
June 9th, 2004 at 3:04 pm
Well the only browser I was able to get mine to work with on the Mac was Firefox… :\
Damn Macs!!!
June 11th, 2004 at 7:55 am
This is neat. I’ll need to think about adding this to my site. I’m in Mozilla on my mac and it works. I don’t understand why all the different browsers read javascript SO differently!
June 12th, 2004 at 11:16 am
would this be possible to add to the edit-form-advanced? I just don’t really get how to do it
August 18th, 2004 at 7:31 pm
A quick update to the Quicktag customisation : I just incorporated Scriptygoddess’ decodeIt function, which neatly translates ‘ into ‘>’. The original version of the function was IE-friendly only, however an update sees it working quite happ…
August 20th, 2004 at 8:35 am
Super I managed to make this work with Quicktags
Now I can encode within MT
Weeee
October 20th, 2004 at 6:41 am
With Movable Type 3.12, Six Apart built in a more powerful set of quicktags and on the whole they worked pretty well and looked quite nice too. I didn’t really want to go back to the clunky Quicktags of before….