Results 1 to 7 of 7

Thread: Accordion Content Default open

  1. #1
    Join Date
    May 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Accordion Content Default open

    Accordion Content script (v1.4)

    http://www.dynamicdrive.com/dynamici...daccordion.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.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    May 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  4. #4
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Yep, your page appears totally blank in IE. The problem is because you have an opening comments tag in your first style sheet:

    Code:
    <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:

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

  5. #5
    Join Date
    Jun 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  6. #6
    Join Date
    Jun 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

    Code:
    // 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:

    Code:
    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

    Code:
    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.

  7. #7
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •