Someone requested the code for how to do that "Link", "Bold", and "Italic" shortcut links in the comments section. I first saw it on Dawn's blog sometime ago, and actually, the code in the MT-Entry template is very similar. In either case here it is:
In between your <HEAD> </HEAD> tags, put this:
<script language="javascript">
<!–
function ahrefThis() {
strSelection = document.selection.createRange().text
if (strSelection == "") document.text.text.focus()
strHref = prompt("Enter the URL of the site you to link:","http://")
if (strHref == null) return;
document.selection.createRange().text = "<a href=\"" + strHref + "\" target=\"_blank\" class=\"text\">" + strSelection + "</a>"
return;
}
function boldThis(from) {
strSelection = document.selection.createRange().text
if (strSelection == "") {
document.text.text.focus()
if (from == 2) document.text.text.select()
strSelection = document.selection.createRange().text
document.selection.createRange().text = strSelection + "<b></b>"
}
else document.selection.createRange().text = "<b>" + strSelection + "</b>"
return;
}
function clipThis(from) {
strSelection = document.selection.createRange().text;
document.text.text.focus();
var dummy = document.text.text.value;
document.text.text.value = "";
if (dummy) {
document.selection.createRange().text = dummy + "\n\n<i>" + strSelection + "</i>";
}
else {
document.selection.createRange().text = "<i>" + strSelection + "</i>";
}
return;
}
function italicThis(from) {
strSelection = document.selection.createRange().text
if (strSelection == "") {
document.text.text.focus()
if (from == 2) document.text.text.select()
strSelection = document.selection.createRange().text
document.selection.createRange().text = strSelection + "<i></i>"
}
else document.selection.createRange().text = "<i>" + strSelection + "</i>"
return;
}
//–>
</script>
Then where you want to offer the links for your comments box:
<script language="JavaScript">
<!–
if (document.selection) {
document.write('<span class="signature">highlight your text then click to <A title="Make a Link" href="javascript:ahrefThis();" target=_self>LINK</A>, <A title=Bold href="javascript:boldThis();" target=_self><B>BOLD</B></A> or <A title=Italicize href="javascript:italicThis();" target=_self><I>ITALICIZE</I></A></span><br>')
}
//–>
</script>
Since this code doesn't work with all browsers: I'm hiding it using the javascript "if document.selection". That way those that can't use it, won't see it.
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
scriptygoddess

