Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/O Code)
 Allowed Members Listing with Show/Hide Option
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

dayve
Forum Moderator

USA
5820 Posts

Posted - 10 May 2003 :  23:26:21  Show Profile  Visit dayve's Homepage
I've had a mod on my forum for over a year now that will display the Allowed Members Names when viewing the main page of the forum. I do not display this to the public, but its been a nice way of quickly identifying who is in the private forum without having to Edit the forum to view the list.

The list has gotten quite big on a few of the private forums and the idea to make the list of names show and hide was brought up. However, I did not want to use ASP because I felt there was no need to reload the page every time I want to show or hide this info, so I am using some DHTML modeled after what Microsoft does at their website.

Screenshots:

Default View


Expanded View


Demo:
http://www.burningsoulsforum.com (scroll down to find Snitz Mod Demo. I did not hide this one so you can see how it works)

I am trying to figure out the best way to alternate a cookie and maintain state using javascript with my existing function. Here is the function I am using:


function ShowHide(elementName) {
	var HeaderElement = null;
	var BodyElement = null; 
	if(document.getElementsByName) {
		HeaderElement = document.getElementsByName(elementName+"Header");
		BodyElement = document.getElementsByName(elementName+"Body");
		UpImage = document.getElementsByName(elementName+"Up");
		DownImage = document.getElementsByName(elementName+"Down");
		
		if(BodyElement) {	
			if(BodyElement[0].style.display == "none") {
				BodyElement[0].style.display = "block";
				HeaderElement[0].className = "ListNuggetHeader";
				DownImage[0].style.display = "none";
				UpImage[0].style.display = "block";
			} else {
				BodyElement[0].style.display = "none";
				HeaderElement[0].className = "ListNuggetHeaderClosed";
				UpImage[0].style.display = "none";
				DownImage[0].style.display = "block";
			}
		}	
	}
}


I am sure I can figure this out, but if there are any javascript gurus out there that can give me a canned script that I can easily integrate into my existing routine, I'd greatly appreciate it.

If after I get that part done there are those wanting this mod, I will package it up. It is "fairly" easy to implement and only requires modifying default.asp and inc_header.asp.


dayve
Forum Moderator

USA
5820 Posts

Posted - 10 May 2003 :  23:46:59  Show Profile  Visit dayve's Homepage
I forgot to add that this mod is completely compatible with IE5/6 NS6/7 and OP6/7 on Windows machines. Not sure how it will look on a Mac, but I will know on Monday.

Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 12 May 2003 :  23:41:46  Show Profile  Visit dayve's Homepage
Updated code with javascript cookies. Now the only problem is retrieving the cookies to control the block:none attributes. What is the best way to read the entire collection of getElementsByName so I can use the elementName in the getCookie function?


function ShowHide(elementName) {
	var HeaderElement = null;
	var BodyElement = null; 
	if(document.getElementsByName) {
		HeaderElement = document.getElementsByName(elementName+"Header");
		BodyElement = document.getElementsByName(elementName+"Body");
		UpImage = document.getElementsByName(elementName+"Up");
		DownImage = document.getElementsByName(elementName+"Down");
		
		if(BodyElement) {	
			if(BodyElement[0].style.display == "none") {
				BodyElement[0].style.display = "block";
				HeaderElement[0].className = "ListNuggetHeader";
				DownImage[0].style.display = "none";
				UpImage[0].style.display = "block";
                                setCookie(elementName, '1', expiration);
			} else {
				BodyElement[0].style.display = "none";
				HeaderElement[0].className = "ListNuggetHeaderClosed";
				UpImage[0].style.display = "none";
				DownImage[0].style.display = "block";
                                setCookie(elementName, '0', expiration);
			}
		}	
	}
}

var expiration = new Date();
expiration.setTime(expiration.getTime() + 2592000000);

function getCookie(name){
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 13 May 2003 :  00:36:05  Show Profile
dayve, I'm not familiar with the javascript and dhtml things. my question is if I use such kind a code to show/hide certain content which is retrieved from the database. when it's hidden, is the db still be qurried?

Is it possible to call the db only when the user want to show the content?

Thanks in advance.
Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 13 May 2003 :  10:00:20  Show Profile  Visit dayve's Homepage
the db is queried normally and will not be queried again when the show/hide option is activated because the content is already loaded, just not shown. that's the nice thing about javascript and the document object model. you can do a lot of client side development with bells and whistles.... ONLY IF YOU HAVE PATIENCE! The one huge drawback is making sure it is cross browser compatible but things have gotten a lot better with Explorer, Netscape, Opera and Mozilla so its not as difficult as it used to be.

Go to Top of Page

dayve
Forum Moderator

USA
5820 Posts

Posted - 13 May 2003 :  10:02:47  Show Profile  Visit dayve's Homepage
quote:
Originally posted by bjlt

Is it possible to call the db only when the user want to show the content?



Yes, but I don't have sample code to show you. In theory you can load external pages into a <div> layer which will query the database. I believe Microsoft does something like this in their msdn menu's. When you expand the tree you will occasionally see a "Loading..." message.

Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 13 May 2003 :  10:10:38  Show Profile
thanks. I've seen "loading..." on threaded forums, which I think is a good method to reduce db calls and bandwidth used. I'll look into it.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.25 seconds. Powered By: Snitz Forums 2000 Version 3.4.07