PDA

View Full Version : Accordion Content Default open



imogeen
06-15-2008, 06:27 PM
Accordion Content script (v1.4)

http://www.dynamicdrive.com/dynamicindex17/ddaccordion.htm

This great script works fine, only one thing i can't seem to figure out.
I want the first header (Projects) of the accordion menu to be open on page load (when someone comes to the page for the first time).

Now when when visiting http:///www.greyburn.net/index2.php all the headers in the menu are closed.

Hope to get feedback :)
Kind regards M.

thetestingsite
06-16-2008, 12:07 AM
When visiting your site in firefox, it appears that you have accomplished what you were asking. When I visit it in IE7 on Win XP Pro SP3, I get a blank page. It could just be my browser being that I never use it.

imogeen
06-16-2008, 09:13 AM
Ah i've changed nothing! Hehe weird.. But what about EI indeed! I didn't notice! Houw about that :s Do you by any change know what can causes this?

Thanks for notifying me.

maaaan! i despise EI :(

ddadmin
06-17-2008, 03:35 AM
Yep, your page appears totally blank in IE. The problem is because you have an opening comments tag in your first style sheet:


<style type="text/css">
<!--
.navCe

Remove the line in red to fix the problem. Regarding the 1st header for DD accordion not being open by default, are you sure? In IE at least, after fixing the above, the first header is open by default. To make it easier to debug, please turn off persistence of the header states inside the initialization code on your page first:


persiststate: false, //persist state of opened contents within browser session?

steve81k
06-26-2008, 04:52 PM
I have the same problem - everything works sweetly, except expanding sections by default.

I have, for example

defaultexpanded: [1], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.

which seems to be all that's needed, from your examples; and I've tried [0], or [0,1], to see what I can get to happen; but whatever I put in, no sections are expanded by default.

I have jquery 1.2.6 whereas the script page says 1.2.2, it couldnt be this causing the problem could it?

I would post the link but at the moment it's not on a publically accessible server, I will try and remedy that tomorrow if required

steve81k
06-27-2008, 01:32 PM
Seems to be an incompatibility between the persistence option and the default expand option.

If persistence is on, the values to persist are apparently stored as a string.

the following line appears to deal with this



// var expandedindices=ddaccordion.urlparamselect(config.headerclass) || ((config.persiststate && persistedheaders!=null)? persistedheaders : config.defaultexpanded)
var expandedindices=ddaccordion.urlparamselect(config.headerclass) || (config.defaultexpanded)
if (typeof expandedindices=='string') //test for string value (exception is config.defaultexpanded, which is an array)
expandedindices=expandedindices.replace(/c/ig, '').split(',') //transform string value to an array (ie: "c1,c2,c3" becomes [1,2,3]


but according to my observation, it doesnt work exactly as advertised - in fact it transforms the string into an array of strings. ie: "c1,c2,c3" becomes ["1","2","3"].

this seems to be the intended outcome since down here:



if (jQuery.inArray(index+'', expandedindices)!=-1){ //check for headers that should be expanded automatically (convert index to string first)


you deliberate convert the needle into string form... however... as the previous comment notes, config.defaultexpanded is an array of numbers... and there's nothing in this area of code to convert it to an array of strings? so if persistence is switched off/empty, expandedindices becomes an array of ints not an array of strings/

and therefore



if (jQuery.inArray(index+'', expandedindices)!=-1)


means we are trying to find a string in an array of ints; so when config.defaultexpanded is [1], expandedindices becomes [1], whereas with that coercion-to-string on index, we end up looking for "1" is in the array [1]. Which obviously always fails, and therefore I get no default expanded.

Solution, since I dont need persistence:

first line quoted above changes to:



var expandedindices=ddaccordion.urlparamselect(config.headerclass) || (config.defaultexpanded)


so that expandedindices always sticks with numbers. leaving the persistence stuff in the ternary seemed to override config.defaultexpanded, and make it turn into strings storing "expand nothing" magic value or something like that - not only even when I set persist to false in the init config, but even when I deleted the cookies so there should have been nothing to persist regardless... i donno, didnt look into this too hard, was easier just to get rid of it.

then second line changes to:



if (jQuery.inArray(index, expandedindices)!=-1){ //check for headers that should be expanded automatically (dont convert index to string first as it makes it not work)


I guess there would be a way of fixing this without ripping out persistence completely, by converting the defaultexpanded array to an array of strings, but this works for me, so I stopped there.

ddadmin
06-27-2008, 03:25 PM
You're right steve81k- nice explanation of the problem. :) More specifically though, the "defaultexpanded" feature only fails when used with jquery1.2.6 (versus the older jquery1.2.2) due to what you said about the array "defaultexpanded" being an array of numbers versus an array of strings as expected by the script. In jquery1.2.2, calling jQuery.inArray() doesn't distinguish between matched values of different data types, while in jquery1.2.6, it apparently now does.

The solution is just to feed jQuery.inArray() the proper needle (number or string) based on the data type contained in array "defaultexpanded". DD Accordion 1.5.1 adds this fix.

Thanks for the bug hunting. :)