[thelist] MetaFilter JS

andre torrez andre at torrez.org
Thu Aug 16 23:56:00 CDT 2001


At 08:20 PM 8/16/2001 -0700, you wrote:
>I had big plans tonight to use some JS code used found on 
>MetaFilter.  Small Problem.  The site is currently in hibernation mode 
>while Matt is away on vacation.

BUT he still does a JavaScript include on the comment pages.
First in your body tag, put this: onkeypress="shortCuts();
then put this JS on the page. you're going to have to name your form 
elements accordingly.
I hope Matt doesn't mind me swiping his code. OH MeFi, please come back.


function shortCuts() {
         if (event.ctrlKey != true) return;
         strSelection = document.selection.createRange().text;
         if (event.keyCode == 1) ahrefThis();
         if (event.keyCode == 2) boldThis(2);
         if (event.keyCode == 20) italicThis(2);
}

function ahrefThis() {
         strSelection = document.selection.createRange().text
         if (strSelection == "") document.mefi.comment.focus()
         strHref = prompt("Enter the URL you want to link to:","http://")
         if (strHref == null) return;
         document.selection.createRange().text = "<a href=\"" + strHref + 
"\">" + strSelection + "</a>"
         return;
}

function boldThis(from) {
         strSelection = document.selection.createRange().text
         if (strSelection == "") {
                 document.mefi.comment.focus()
                 if (from == 2) document.mefi.comment.select()
                 strSelection = document.selection.createRange().text
                 document.selection.createRange().text = strSelection + 
"<b></b>"
         }
         else document.selection.createRange().text = "<b>" + strSelection 
+ "</b>"
         return;
}

function italicThis(from) {
         strSelection = document.selection.createRange().text
         if (strSelection == "") {
                 document.mefi.comment.focus()
                 if (from == 2) document.mefi.comment.select()
                 strSelection = document.selection.createRange().text
                 document.selection.createRange().text = strSelection + 
"<i></i>"
         }
         else document.selection.createRange().text = "<i>" + strSelection 
+ "</i>"
         return;
}





More information about the thelist mailing list