Link, Bold, Italic links in comment text area
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.
November 18th, 2002 at 2:11 pm
Scriptygoddess has come up with another great script - this one for adding bold, italics and links in the blog
November 19th, 2002 at 7:19 pm
I hope you don’t mind tht I edited the script a little to make it pMcode friendly for my comments in pMachine. There was much tweaking involved. just chaing the < to [ and the > to ]
November 19th, 2002 at 7:28 pm
Just changed a few things in the script to make it pMcode friendly.
November 19th, 2002 at 7:46 pm
that should have been there “wasn’t” much tweaking.
November 19th, 2002 at 7:54 pm
You’re always welcome to tweak and hack to your hearts delight, anything you find here…
November 21st, 2002 at 4:39 pm
Thanks, nice script!
November 22nd, 2002 at 1:42 pm
Don’t hit me for saying this…but users should be aware that this function does not work in Mozilla - there’s a known bug in createRange() for Mozilla, and it will probably be quite some time before it’s fixed. I ran into that while putting together something like this for Quarto, and it drove me crazy until I checked bugzilla.
I’m unsure if it works in Opera, but it merits checking.
December 11th, 2002 at 9:05 am
Hi, I’m just wondering if I can use your code for the buttons on the comments template by creating modules with the code and then put MT-Include in the right places in the comments template. Any thoughts on that?
December 11th, 2002 at 4:02 pm
As long as all the code gets included at some point, I don’t see why it wouldn’t work.
December 19th, 2002 at 9:38 am
This morning, around 11 a.m., the hubby told me to get ready because he had a surprise for me. As
March 27th, 2003 at 6:17 am
Woah, that rocks. I’m using it now, too.
March 30th, 2003 at 4:34 am
Hello,
I wanted a script which has to refresh only a
piece of text within the page and not the complete piece……………
Could u plz solve my problem……….
April 6th, 2003 at 1:58 pm
Check it out — I just spiffied up the comment form a bit
May 7th, 2003 at 4:42 pm
Hi. This is the script I’m looking for, but into which template do I paste it? The Main Index? The Comment Listing Template? Which script goes where? Also, how do you replace the words “Bold”, etc., with the little graphics for Bold, Highlight, and URL? Thanks in advance for any help you can provide - Randy
May 29th, 2003 at 3:15 am
From what I can tell, this script only works on IE on Windows. It doesn’t work on IE on the Mac, or Safari, or Netscape on Linux. I’d lay odds it doesn’t work anywhere on Netscape or Mozilla.
June 1st, 2003 at 12:50 pm
In the setup.php it says
In the form tag, search for this line:
action=”<$MTCGIPath$>mt-comments.cgi”
And replace it with this:
action=”http://divamaggie.com/subscribe/emailtolist.php”
In the Comment Listing Template it acually says
<form method=”post” action=”<$MTCGIPath$><$MTCommentScript$>” name=”comments_form” onsubmit=”if (this.bakecookie[0].checked) rememberMe(this)”>
When this step is completed what exactly gets changed? Or exactly how should that whole section look when changed? What I’m really getting at is does the <$MTCommentScript$> part of the code remain and if so, exactly how should the section look with the change implemented?
June 1st, 2003 at 12:51 pm
Also, is there a tutorial somewhere for the following script?
“Please wait… your comment is being submitted.”
June 1st, 2003 at 12:53 pm
Sorry…had two instances open of scriptygoddess. Please disregard my last two comments.
August 6th, 2003 at 3:26 am
scriptygodess, how I love you so.
September 14th, 2003 at 7:01 pm
Someone asked me which scripts I used to make all the cool things magically appear here on BB. I found nearly everything at Scriptygoddess –…
October 8th, 2003 at 12:42 am
I’m organizing BB and deleted the posts revolving around my techie mess from earlier in the week, since it was an easy fix. I like…
October 25th, 2003 at 12:48 pm
This works fine in my blog except that the links aren’t getting the target=”_blank” added to them and the urls are being opened in the comments window. The bold, italics works fine, and the link gets written, it just doesn’t include the target in the output as the script suggests. I was going to add the target myself, then I saw that it should be writing it out.
I’m using IE6, is there a known bug?
October 25th, 2003 at 12:52 pm
Even wierder, is that i just got the comments notification email, and the contents were:
trgtrg tr ttr
However, in the comments pop up and in my expandable comment area, it’s written as:
trgtrg tr ttr
What could be causing the target to be stripped out of the comments but emailed as the contents of the comments??????
October 25th, 2003 at 12:55 pm
If you’re using MT, and you’re using the default setting for “comment sanitizing” then MT itself may be stripping them out. Make sure you’re using a customized setting and allowing “target” as an attribute to “a” (as well as href, obviously) - and that should fix it.
October 25th, 2003 at 12:57 pm
Just an additional note… be careful what you put in the “customized” setting… make sure you include everything you want (and EXCLUDE everything you DON”T want…)
Here’s an example of my setting:
(This is all under Weblog Config -> Prefrences -> under Sanitize Spec):
i, a href target, b, br, p, strong, em, ul, li, blockquote, img src width height, h3
October 25th, 2003 at 1:09 pm
Thanks! That did it. I was reading the sanitize specs in the MT manual when I got your last email listing the allowed tags. That helped alot because I wasn’t sure what to include and the format with the commas and stuff
Now it works perfectly! :Kiss:
November 23rd, 2003 at 5:48 pm
I’m organizing BB and deleted the posts revolving around my techie mess from earlier in the week, since it was an easy fix. I like…
November 28th, 2003 at 5:14 pm
I’m not quite “back” from my break yet, but I did want to go ahead and tell you about the…
January 14th, 2004 at 7:03 am
hello!
i’ve got a web page with text, grids and images. what i need is to automatically highlight the words on my page that are on my DB.
what do i have to change in your code for it to parse my entire page and highlight what i want as soon as the page opens without having to click anything?
August 1st, 2004 at 5:21 am
Hiya. Do you know of any hacks to make this work in Firefox/Mozilla?
August 1st, 2004 at 6:50 am
It’s not exactly the same script - but it’s what I’m using on this site, and it does work in firefox/mozilla: See post here