Page 1 of 1

comments.tpl Javascript

Posted: Wed Sep 01, 2010 10:49 am
by yellowled
The default comments.tpl contains this onclick handler:

Code: Select all

<a class="comment_reply" href="#serendipity_CommentForm" id="serendipity_reply_{$comment.id}" onclick="document.getElementById('serendipity_replyTo').value='{$comment.id}'; {$comment_onchange}">{$CONST.REPLY}</a>
I'm trying to understand what this does -- it first sets the value of #serendipity_replyTo to the id of the corresponding link. But what does {$comment_onchange} do?

YL

Re: comments.tpl Javascript

Posted: Wed Sep 01, 2010 11:33 am
by garvinhicking
Hi!

comment_onchange is a plugin event handler so that other plugins can execute stuff there, like the livecommentpreview plugin.

Regards,
Garvin

Re: comments.tpl Javascript

Posted: Wed Sep 01, 2010 12:07 pm
by yellowled
garvinhicking wrote:comment_onchange is a plugin event handler so that other plugins can execute stuff there, like the livecommentpreview plugin.
Hm. I'm trying to build a template using as little inline JS and CSS as possible by putting them in external JS/CSS files as far as possible. I think I have figured out how to do the first part, but I have no idea how to handle the {$comment_onchange}, especially since I don't have access to smarty variables in external JS files. So it's probably pointless. Too bad.

YL

Re: comments.tpl Javascript

Posted: Wed Sep 01, 2010 1:49 pm
by garvinhicking
Hi!

You'd always need to place it inside your comment-tpl to stay compatible to those plugins.

What you could do is

Code: Select all

{if $comment_onchange != ''}
<a ... onclick="{$comment_onchange}">
{else}
<a>
{/if}
So if your jquery took care about injecting the onclick to getElementById, you only need to have a onclick inline handler, if users are using a plugin that would require it.

Regards,
Garvin

Re: comments.tpl Javascript

Posted: Wed Sep 01, 2010 2:09 pm
by yellowled

Code: Select all

<a class="comment_reply" href="#serendipity_CommentForm" id="serendipity_reply_{$comment.id}"{if $comment_onchange != ''} onclick="{$comment_onchange}"{/if}>{$CONST.REPLY}</a>
should work too, right? If so: Thanks a lot :)

YL

Re: comments.tpl Javascript

Posted: Wed Sep 01, 2010 2:24 pm
by garvinhicking
Yip