Alternative to StartExpandCollapse tag -- Questions module example

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
michelG
Forum Members
Forum Members
Posts: 43
Joined: Tue Jul 17, 2007 1:25 pm
Location: Rochester, NY

Alternative to StartExpandCollapse tag -- Questions module example

Post by michelG »

If you are like me and do not like the behavior of the StartExpandCollapse tag -- which adds an anchor link to the collapsable element and always jumps to it -- here is an alternative using a simple javascript.

Code: Select all

{literal}
<__script__ type="text/JavaScript">
<!--
// TO COLLAPSE/EXPAND ELEMENT
function expand(ind)

{
 e = document.getElementById("ex_"+ ind);
 if (e.style.display == 'none')
 {
   e.style.display = 'block';
 }
 else if (e.style.display == 'block')
 {
   e.style.display = 'none';
 }
}
//-->
</__script>
{/literal}

{foreach from=$items item=entry}
	<div class="QandA-Question">
		<a href="javascript:expand({$entry->id})">{$entry->question}</a>
	</div>
	<div id="ex_{$entry->id}" style="display:none" class="QandA-Answer">
		{if $entry->answer}{$entry->answer}
		{else}<p>Question to be answered soon.</p>
		{/if}
	</div>
	<p class="QandA-RecordDetails">Category: {$param_category} | Question from {$entry->author} on {$entry->created|date_format}</p>
{/foreach}
It can also be helpful for those facing an issue of variables that -- it seems -- cannot be converted as strings in PHP 5.2.0+ as described in the following post:


http://forum.cmsmadesimple.org/index.php/topic,16483.msg81626.html#msg81626




michel
Last edited by michelG on Tue Nov 13, 2007 4:05 am, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Alternative to StartExpandCollapse tag -- Questions module example

Post by calguy1000 »

This should be trivial with jquery....
(untested, but should be close)

Code: Select all

{literal}
<__script__ type="text/JavaScript">
<!--
document.ready(function() {
  jQuery('.expandcollapse').click(function() {
     this.toggle('slow');
     return false;
  });
});
//-->
</__script>
{/literal}

{foreach from=$items item=entry}
	<div class="QandA-Question">
		<a class="expandcollapse" href="#">{$entry->question}</a>
	</div>
	<div id="ex_{$entry->id}" style="display:none" class="QandA-Answer">
		{if $entry->answer}{$entry->answer}
		{else}<p>Question to be answered soon.</p>
		{/if}
	</div>
	<p class="QandA-RecordDetails">Category: {$param_category} | Question from {$entry->author} on {$entry->created|date_format}</p>
{/foreach}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: Alternative to StartExpandCollapse tag -- Questions module example

Post by jmcgin51 »

thanks to you both, Calguy and nkoren!  The "jump" in the original startExpandCollapse tag has always irritated me, but I never had the time/inclination to fix it.

Perhaps one of these fixes should be applied to the startExpandCollapse tag in a future CMSMS release?  The disadvantage (I think, not having looked at the sEC code) is that both of these solutions require Javascript turned on, while the original code does not?  Or maybe the original does...
User avatar
blast2007
Power Poster
Power Poster
Posts: 508
Joined: Wed Aug 01, 2007 5:36 pm

Re: Alternative to StartExpandCollapse tag -- Questions module example

Post by blast2007 »

Only for reference: see also this related topic
http://forum.cmsmadesimple.org/index.php/topic,5385.msg96710.html#msg96710

regards
blast
JohnnyB
Dev Team Member
Dev Team Member
Posts: 729
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: Alternative to StartExpandCollapse tag -- Questions modu

Post by JohnnyB »

Post Reply

Return to “Tips and Tricks”