Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-07-17 23:31:54

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Show and hide comments_input form behind a link

I want to hide the comments input form behind a link.
Only if a user wants to leave a comment and clicks the link the comment-input-form should be shown within the page.
I didn’t find any description how to achieve that.
(But maybe my english or my css is too bad).

Thank you for any hints.

Michael

Offline

#2 2006-07-18 12:47:16

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Show and hide comments_input form behind a link

Like this?

Offline

#3 2006-07-19 09:49:48

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: Show and hide comments_input form behind a link

Hi,
@els
I think so,
but unfortunately I’m quite in a hurry leaving to a conference.
I’m back on friday.
My main question so far: Isn’t it possible without any (java)script?
There is no txp-function?

Thanks so far,
Michael

Offline

#4 2006-07-19 10:35:41

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Show and hide comments_input form behind a link

Textpattern and all txp-functions run server-side, you cannot change a page that is already at the client’s end without any javascript.

The only way to do without client-side scripting (and without cookies), is to provide two different permalinks for every article, one without the comment-form, and one with the comment-form. Textpattern does not have this functionality built-in, but it can be done very easily with a plugin. I wouldn’t really recommend it, though.

You can built a javascript-version, which degrades to always showing the comment-form when javascript is disabled. So there wouldn’t really be any restrictions in terms of site-functionality.

Offline

#5 2006-07-21 17:03:35

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: Show and hide comments_input form behind a link

Vielen Dank! – Thanks a lot!
Michael

Offline

#6 2006-07-24 09:35:46

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: Show and hide comments_input form behind a link

Maybe I’m stupid at the moment, but I can’t figure out how to solve this:

You can built a javascript-version, which degrades to always showing the comment-form when javascript is disabled. So there wouldn’t really be any restrictions in terms of site-functionality.

I tried with setting the initial css-setting display=block to “none” by an “onload”-function (and later toggling by the link).
But then there is the problem with preview: The comment-input-field will be hidden showing the preview and you have to click on the link to make it visible. (Also if there is a comment-error).

So how can I leave a css showing the fields without javascript and hiding when javascript is enabled – and this should only be done ONCE – since it should hold the toggle status between loading preview or showing error-messages?

At the moment I have no idea and would be happy to get any hints.

Thank you,
Michael

Offline

#7 2006-07-24 10:11:53

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Show and hide comments_input form behind a link

We have a comment conditional called <txp:if_comments_preview> – you could embed javascript-calls into your html depending on it.

Alternative way is to set an id- and time-bound cookie when the comment-form is expanded.

There are probably other solutions as well, those were just from the top of my head.

Offline

#8 2006-07-24 16:31:22

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: Show and hide comments_input form behind a link

@sencer
Thank you very much, that helps a lot. I managed to make my calls conditional, and preview now is visible.
Now a small problem is left:
After sending/submitting a comment, the page gets reloaded completely, and normally you would see the message “Thank you for commenting” (or something like that) in a paragraph marked by the id of the comment-form (“txpCommentInputForm”).
It is no longer “preview” – so in my code it is hidden like the comment-input-form.

Since toggling display on/off depends on the “id” there seems to be no way to keep it apart from hiding.

Is there any txp-tag for the “thank-you-message” after sending a comment?
Or is it possible to change its “id” so it is different from the input-form?

Offline

#9 2006-07-24 16:35:26

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Show and hide comments_input form behind a link

Would this help?

Edit: oh sorry, it’s about error messages, not thank you messages :(

Last edited by els (2006-07-24 16:36:17)

Offline

#10 2006-07-24 17:17:00

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Show and hide comments_input form behind a link

The thank you message will appear when the URL contains a “commented=1” parameter. You could use that either in Javascript, or as a small php-snippet/conditional.

Offline

#11 2006-07-25 05:04:42

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: Show and hide comments_input form behind a link

Thank you very much, everything is fine now.

In the CSS the Input-Form is visible (“display: block;”)
The Link pointing to the form will call a JavaScript-function which toggles “display: none”

<code><a href=“javascript:toggleLayer(‘txpCommentInputForm’);” class=“CommentInputLink” title=“add comment”>add comment</a></code>

“onload” the comment input form will be toggled to ‘hidden’ – except

1) if_comment_preview is true:

<body <txp:if_comments_preview><txp:else />onload="javascript:toggleLayer('txpCommentInputForm');" </txp:if_comments_preview>class="<txp:section />">

or
2) except the url-parameter “comment=1” exists, indicating there is a “thank-you-message” instead of the input form.
This is done by including an additional condition before toggling anything, here the toggle-script:

<code>function toggleLayer(whichLayer)
{ if (window.location.search == “?commented=1”) { // if thank-you-message do nothing } else if (document.getElementById) { // this is the way the standards work var style2 = document.getElementById(whichLayer).style; style2.display = style2.display? “”:“none”; } else if (document.all) { // this is the way old msie versions work var style2 = document.all[whichLayer].style; style2.display = style2.display? “”:“none”; } else if (document.layers) { // this is the way nn4 works var style2 = document.layers[whichLayer].style; style2.display = style2.display? “”:“none”; }
} </code>

EDIT: inclusion of thank-you-condition into the script.

Last edited by saccade (2006-07-25 08:07:01)

Offline

#12 2006-07-25 10:07:28

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Show and hide comments_input form behind a link

Thank you, saccade, for sharing your solution. I am sure people will be interested in it.

Offline

Board footer

Powered by FluxBB