Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-05-27 13:28:04

Iki
Member
From: New Hampshire
Registered: 2008-05-26
Posts: 22

Javascript help for comment smilies

Hello,

I’m trying to adapt some code I was using on my old MT blog to TXP. You can see it here. (Disregard all the sidebar errors/sytle problems… I had to shove this blog out of the way so TXP could take it’s place.)

As you can see, there are a bunch of smilies above the comment text area. When you click on one of these, it puts a bit of text in the text box. Then, when the comment is submitted, a macro script turns that code into an image. There are two parts to making this happen – the onlick javascript, and the macro code.

I’ve got the macro code working using the an7_filter plugin. You can see that it does replace strings with images on the TXP blog, so YAY! Now I’d like to get the clickable smilies back.

Here’s the javascript for the smilies the way it is now:

<!-- Script for clickable smilies -->
<script language="javascript">
<!--
function writeImgTag(code)
{
var cache = document.comments_form.text.value;
this.code = code;
document.comments_form.text.value = cache + " :" + code + ":";
document.comments_form.text.focus();
}
//-->
</script>

Then on the comment form you put this:

<img onClick="writeImgTag('mad')" src="http://www.afterhourspub.com/smile/mad.gif" width="16" height="16" border=0>
<img onClick="writeImgTag('smitten')" src="http://www.afterhourspub.com/smile/smitten.gif" width="39" height="35" border=0>
etc...

And you end up with something like :mad: in the comment text box.

What I think I can’t find is the name of the comment text box? In MT, the form is “comments_form”, and the text area name is “text”, so I think that’s where “document.comments_form.text.value” is coming from.

What would I have to change this to in order to make it see the TXP comment input text box?


“Some days, even my lucky rocketship underpants don’t help.” — Calvin, Calvin & Hobbes

Offline

#2 2008-05-27 14:56:48

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Javascript help for comment smilies

Previously. name is old-school and invalid, and therefore not used in TXP (view HTML source). Use getElementById.

function writeImgTag(code)
    {
        var message = document.getElementById('message');
        if (message)
        {
            message.value = message.value + '!/smilies/' + code + '.gif!';
            message.focus();
        }
    }

Your onclick value (not onClick) should be writeImgTag(':emotName:').

Edit: Someone can’t type today!

Last edited by jm (2008-05-27 15:06:28)

Offline

#3 2008-05-28 15:47:21

Iki
Member
From: New Hampshire
Registered: 2008-05-26
Posts: 22

Re: Javascript help for comment smilies

Thanks, jm, I appreciate the help!


“Some days, even my lucky rocketship underpants don’t help.” — Calvin, Calvin & Hobbes

Offline

Board footer

Powered by FluxBB