Announcement: Be excellent to each other.


Caravel Forum : Caravel Boards : The Site : Collapsable Forums (A way to do it faster)
New Topic New Poll Post Reply
Poster Message
DiMono
Level: Smitemaster
Avatar
Rank Points: 1181
Registered: 09-13-2003
IP: Logged
icon Collapsable Forums (+1)  
Rather than loading a new page, there's an easier way to collapse/expand the forum listings without making a call to the server and using up bandwidth and MySQL requests:

1) Make sure each forum section has an inline id, say DROD and Other.

2) Change the anchor target from the URL to "javascript:switchVisibility('DROD');" (or ('Other'))

3) Make sure the + and - images are in spans that also have IDs, say img_DROD and img_Other

4) Write the following javascript:

boxes = new Array();
function switchVisibility(id) {
	panel = getElement(id);
	if (!boxes[id]) {
		boxes[id] = panel.innerHTML;
		panel.innerHTML = '';
		document['img_' + id].src = '/forum/images/caravelnet/expandPlus.gif';
	}
	else {
		panel.innerHTML = boxes[id];
		boxes[id] = false;
		document['img_' + id].src = '/forum/images/caravelnet/expandMinus.gif';
	}	
}
function getElement(name) {
	return document.getElementById?document.getElementById(name):document.all[name];
}


Voila, the forums collapse and expand without having to call the server again

____________________________
Deploy the... I think it's a yellow button... it's usually flashing... it makes the engines go... WHOOSH!
05-30-2005 at 04:12 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts This architect's holds Quote Reply
silver
Level: Smitemaster
Rank Points: 915
Registered: 01-18-2005
IP: Logged
icon Re: Collapsable Forums (0)  
I imagine he plaguishly avoids javascript so it doesn't become a "test on every different browser ever made" issue.


____________________________
:yinyang
05-30-2005 at 05:13 PM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
DiMono
Level: Smitemaster
Avatar
Rank Points: 1181
Registered: 09-13-2003
IP: Logged
icon Re: Collapsable Forums (0)  
Actually, it's pretty much the same thing he's been doing for secret messages, only I used functions so I could compensate for older browsers that don't understand getElementById()... and I used removing the contents and storing them rather than switching visibility, which I wanted to do but couldn't remember the function name. There's already javascript on the site, it's just not being used for the forum listing.

____________________________
Deploy the... I think it's a yellow button... it's usually flashing... it makes the engines go... WHOOSH!
05-30-2005 at 06:27 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts This architect's holds Quote Reply
silver
Level: Smitemaster
Rank Points: 915
Registered: 01-18-2005
IP: Logged
icon Re: Collapsable Forums (0)  
My bad. I agree that collapsing them the same way as secrets should be "good enough", as long as they default to uncollapsed for people who can't use the secrets, either :)


____________________________
:yinyang
05-30-2005 at 06:33 PM
View Profile Send Private Message to User Show all user's posts This architect's holds Quote Reply
Schik
Level: Legendary Smitemaster
Avatar
Rank Points: 5416
Registered: 02-04-2003
IP: Logged
icon Re: Collapsable Forums (0)  
I chose to do it this way so that it would remember how you have it set. I obviously know how to do it in Javascript if I so desired.

____________________________
The greatness of a nation and its moral progress can be judged by the way it treats its animals.
--Mahatma Gandhi
05-30-2005 at 07:33 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores Quote Reply
DiMono
Level: Smitemaster
Avatar
Rank Points: 1181
Registered: 09-13-2003
IP: Logged
icon Re: Collapsable Forums (0)  
What about Ajax? You could have the javascript function send a request to the server to update the database in the same way refreshing the page works.

A free Ajax implementation

____________________________
Deploy the... I think it's a yellow button... it's usually flashing... it makes the engines go... WHOOSH!
05-30-2005 at 09:26 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts This architect's holds Quote Reply
Schik
Level: Legendary Smitemaster
Avatar
Rank Points: 5416
Registered: 02-04-2003
IP: Logged
icon Re: Collapsable Forums (+1)  
DiMono wrote:
What about Ajax? You could have the javascript function send a request to the server to update the database in the same way refreshing the page works.
I really don't see it worth my time. I'd rather get hold updating to work, or work on any of a dozen other projects I've got in mind.

____________________________
The greatness of a nation and its moral progress can be judged by the way it treats its animals.
--Mahatma Gandhi
05-30-2005 at 09:58 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores Quote Reply
New Topic New Poll Post Reply
Caravel Forum : Caravel Boards : The Site : Collapsable Forums (A way to do it faster)
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.