PDA

View Full Version : Contractible Headers--Question



brewbaker
01-09-2007, 05:11 PM
1) Script Title: Contractible Headers

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex1/navigate2.htm

3) Describe problem: As described in the instruction material:

"Persistence feature. You can specify whether the script should remember the state of the header structure when the user navigates away to a different page. When enabled, returning to the page will cause the script to return the header to its last state"

What exactly do I change in the script to enable this feature? How to enable?

jscheuer1
01-09-2007, 05:30 PM
That feature is enabled in the default installation of the script.

brewbaker
01-09-2007, 06:39 PM
That feature is enabled in the default installation of the script.

In my copy of the script this portion (which I assume is where the enable choice is made) is like this by default:

var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

This causes the menu to contract everytime yo goo to a new page. When "enablepersist="on" is used, the menu stays open when you go to a new page but it's kind of random. Sometimes it does and sometimes it doesn't. Also it opens on its own when you go to other pages even if it wasn't open to begin with.

I just want it to stay open until you click again to close it.
Am I making the correct change?

jscheuer1
01-09-2007, 09:19 PM
Yes, and it depends upon what you mean by 'my copy' and perhaps other considerations as well. If it is a modified version of the script to begin with, try out the default script from the demo page. Also, be aware that the persistence is designed for session and page only. This means that once the browser is closed completely, the script will forget what its previous state was and it also means that if you have the same script on two pages, any given page will only remember its own previous state. Furthermore, persistence is just that, it will remember the state, not force a given arbitrary state - sounds to me that you want it always open on page load or something like that. That could be arranged but, has nothing to do with persistence and would work better, once arranged, with persistence off.

If what you really want is a default state with no memory of user changes, let me know what it is and I'll modify it for you if it is different than the default state of the script without persistence.

brewbaker
01-09-2007, 09:56 PM
Yes, and it depends upon what you mean by 'my copy' and perhaps other considerations as well. If it is a modified version of the script to begin with, try out the default script from the demo page. Also, be aware that the persistence is designed for session and page only. This means that once the browser is closed completely, the script will forget what its previous state was and it also means that if you have the same script on two pages, any given page will only remember its own previous state. Furthermore, persistence is just that, it will remember the state, not force a given arbitrary state - sounds to me that you want it always open on page load or something like that. That could be arranged but, has nothing to do with persistence and would work better, once arranged, with persistence off.

If what you really want is a default state with no memory of user changes, let me know what it is and I'll modify it for you if it is different than the default state of the script without persistence.

Thanks for your reply. I'm using the script in an "include" file for navigation so it applies to all pages. See - http://www.whitechicken.com/staging - click on "Web Content Development in the left column. I want the menu to stay open when you're surfing those subpages but to be closed on all other pages. Now, because of the memory, if you click on Web Content Development from any page and then return to that page, it's still open. What do you think?

jscheuer1
01-10-2007, 10:46 AM
First off:

Your page is in violation of Dynamic Drive's usage terms (http://www.dynamicdrive.com/notice.htm), which, among other things, state that the script credit must appear in the source code of each page using the script. Please reinstate the notice first.

You can do that like so -

Replace:


<script src="includes/common_scripts.js" type="text/javascript"></script>


with:


<script src="includes/common_scripts.js" type="text/javascript">
//Includes:
/***********************************************
* Contractible Headers script- Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated Mar 23rd, 2004.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>


on whichever pages actually use this script, or in the include/template, if this is from an include/template.

On to your problem - Where you have:


<a href="#null" onClick="expandcontent('sc1');"><img src="images/nav/left_nav_home_02.gif" alt="" width="199" height="21" hspace="0" vspace="0" border="0"></a>

It should be:


<span onclick="expandcontent('sc1');" style="cursor:pointer;"><img src="images/nav/left_nav_home_02.gif" alt="" width="199" height="21" hspace="0" vspace="0" border="0"></span>

This prevents those browsers which otherwise would, from reloading the page, important once we turn persistence off. You can further style this span, if need be, using the inline style, an id or class name to make it look like the links in this section.

What I think you need is a test of the location.href of the page to decide if that header should be expanded or not. Set persistence to off. Find this part of the script:


function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
getElementbyClass("switchcontent")
if (enablepersist=="on" && typeof ccollect!="undefined"){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0"
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
var tests=[/web_writing\.php/, /seo\.php/, /blog\.php/, /pr\.php/]
for (var i_tem = 0; i_tem < tests.length; i_tem++)
if(tests[i_tem].test(location.href))
expandcontent('sc1')
}

Add the red parts. That should do it.