PDA

View Full Version : Using collapsing Lists


tcadieux
06-14-2005, 09:04 PM
I want to build an ASP page that would loop through the number of messages in my DB, then create a Table that would have the MSG and any response i sent. I want to make these Tables Collapseable so i could save some screenspace....has anyone seen something like this?

vwphillips
06-14-2005, 10:17 PM
I want to make these Tables Collapseable


can you explain what you mean by this

do you want the ability to remove/ replace specific rows?

view rows against search results?

or view the top portion and then expand ?

or to scroll the table in an element?

or ....

tcadieux
06-15-2005, 01:30 PM
what i wanted basically was the ability to hit a + and see all my text, or hit - and hale all my text collapse into 1 line or so...basically like a windows Explorer function.

sftl99
06-15-2005, 03:22 PM
check out the site below and tell me if this is what you're looking for...
on the front page click the 'hide all' and 'show all' then try clicking each individual date (start w/ the 4th one down because the first two or three are always open). if this is what you're looking for i'll provide the code (though i didn't write it).

http://www.jasonpcarroll.com/cory/

tcadieux
06-15-2005, 04:29 PM
that's quite along the lines of what i'd like to do, i'd love if you could share that could, thank you!

sftl99
06-15-2005, 05:12 PM
Save this as collapse.js
var expandedTriggerClass='triggerexpanded';
var normalTriggerClass='triggernormal';
var hoverTriggerClass='triggerhover';
var normalElementClass='elementnormal';
var collapsedElementClass='elementcollapsed';
var collapsedElements=new Array();
var triggerElements=new Array();
function domCollapse()
{
if(document.getElementById && document.createTextNode)
{
//parentElementId='collapsesection';
//triggerelements='div';
var triggerClass=/trigger/;

var elms,tohide,colobj,elementsToCheck,triggerelements,parentElementId;
elementsToCheck=triggerelements?triggerelements:'*';
if(parentElementId)
{
elms=document.getElementById('parentElementId').getElementsByTagName(elementsToCheck);
} else {
elms=document.getElementsByTagName(elementsToCheck);
}
for (i=0;i<elms.length;i++)
{
if(triggerClass.test(elms[i].className))
{
tohide=elms[i].nextSibling;
while(tohide.nodeType!=1)
{
tohide=tohide.nextSibling;
}
collapsedElements.push(tohide)
triggerElements.push(elms[i])
juggleClass(tohide,normalElementClass,0);
juggleClass(tohide,collapsedElementClass,1);
elms[i].colobj=tohide;
elms[i].onmouseover=function(){doTriggerHover(this);}
elms[i].onmouseout=function(){juggleClass(this,hoverTriggerClass,0);}
elms[i].onclick=function(){doDomCollapse(this,this.colobj);return false}
elms[i].className=elms[i].className+' '+normalTriggerClass;
}
}
}
}
function doTriggerHover(o)
{
if(!checkClass(hoverTriggerClass,o) && !checkClass(expandedTriggerClass,o))
{
juggleClass(o,hoverTriggerClass,1);
}
}
function doDomCollapse(o,t)
{
if(t)
{
if(checkClass(collapsedElementClass,t))
{
juggleClass(t,collapsedElementClass,0);
juggleClass(t,normalElementClass,1);
juggleClass(o,normalTriggerClass,0);
juggleClass(o,expandedTriggerClass,1);
}else{
juggleClass(t,normalElementClass,0);
juggleClass(t,collapsedElementClass,1);
juggleClass(o,expandedTriggerClass,0);
juggleClass(o,normalTriggerClass,1);
}
}
}
function doDomCollapseAll(state){
var i,o,t;
for(i=0;i<collapsedElements.length;i++){
t=collapsedElements[i];
o=triggerElements[i];
if(state==1){
juggleClass(t,collapsedElementClass,0);
juggleClass(t,normalElementClass,1);
juggleClass(o,normalTriggerClass,0);
juggleClass(o,expandedTriggerClass,1);
} else {
juggleClass(t,normalElementClass,0);
juggleClass(t,collapsedElementClass,1);
juggleClass(o,expandedTriggerClass,0);
juggleClass(o,normalTriggerClass,1);
}
}
}
function juggleClass(o,c,s)
{
if(s==0)
{
o.className=o.className.replace(c,'');
}
if (s==1 && !checkClass(c,o))
{
o.className+=' '+c
}
}
function checkClass(c,o)
{
var re=new RegExp('\\b'+c+'\\b');
return re.test(o.className);
}

window.onload=domCollapse;

Then include this in your page <head>
<script type="text/javascript" src="collapse.js"></script>
Now, you need a stylesheet with these elements (don't forget to link your page to the saved stylesheet).
.triggerexpanded{
cursor:pointer;
}
.trigger{
color:#ba4b4f;
font-weight:bold;
text-decoration:underline;
cursor:pointer;
}
.triggernormal{
cursor:pointer;
}
.triggerhover{
cursor:pointer;
color:#000000;
}
.elementnormal{}
.elementcollapsed{display:none;}
Now, here is an example of the way it works...
<div class="trigger">Expand or Collapse</div>
<div>Here is your text</div>
Anything with "trigger" as the class with expand the very next element, whether it is a div (as in this case) or even a table (it should work at least).

Go http://www.onlinetools.org/tools/domcollapse/ <there for more details and for credits...I can't even remember who deserves the credit on this one because I've found it on a few sites. I've edited it to fit my site, but you'll see at the site I linked you to that you can customize the stylesheet to do a lot of neat things. Have fun!

vwphillips
06-15-2005, 07:43 PM
or if you prefer a simple life



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--

function Toggle(id){
obj=document.getElementById(id);
objS=obj.parentNode;
if (objS.style.height=='30px'){
objS.style.height=(obj.offsetHeight)+'px'
}
else {
objS.style.height='30px'
}
}
//-->
</script></head>

<body>

<input type="button" name="" value="Toggle" onclick="Toggle('MyTable');" ><br>
<div style=position:relative;overflow:hidden;width:210;height:30px;" >
<table id="MyTable" width="200" border="1">
<tr><td>Col 1</td></tr>
<tr><td>Col 2</td></tr>
<tr><td>Col 3</td></tr>
<tr><td>Col 4</td></tr>
<tr><td>Col 5</td></tr>
<tr><td>Col 6</td></tr>
<tr><td>Col 7</td></tr>
<tr><td>Col 8</td></tr>
<tr><td>Col 9</td></tr>
<tr><td>Col 10</td></tr>
<tr><td>Col 11</td></tr>
<tr><td>Col 12</td></tr>
<tr><td>Col 13</td></tr>
</table>
</div>
</body>

</html>

sftl99
06-15-2005, 07:57 PM
I realize the code I posted is very lengthy, but once set up, you have tons of customization ability and it's the easiet thing in the world to set up multiple collapsing elements (simply 'class' tag). If you see my example page you'll also see the "expand all" and "hide all" functions. Those are pretty handy.
Here is another simple version


<head>
<script language='javascript' type='text/javascript'>
function flip(rid)
{
current=(document.getElementById(rid).style.display == 'none') ? 'block' : 'none';
document.getElementById(rid).style.display = current;
}
</script>
</head>
<a href="#" onClick="flip('divid')">Change</a>
<div id="divid">
<script language='javascript' type='text/javascript'>flip('divid');</script>
This is your text, table, whatever
</div>

see http://www.jasonpcarroll.com/collapse.html