Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Multiple DD Scripts Conflict

  1. #1
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Multiple DD Scripts Conflict

    1) Script Title: Swith Content II and Slashdot Menu

    2) Script URL (on DD):

    http://www.dynamicdrive.com/dynamici...chcontent2.htm

    and

    http://www.dynamicdrive.com/dynamicindex1/slashdot.htm

    3) Describe problem: I'm trying to leverage both scripts on one page and they are some how conflicting... The Switch Content II script won't remember the states. If I take away the slashdot menu script, the Switch Content II will remember the states.

    It's obviously the way they're both writing the cookies because whichever script i include first, remembers the states and the script below it doesn't work.

    Anyone have a quickfix to the way one of them is writing cookies?

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Sounds to me that you are having trouble with variable(s) / function(s) overlapping. Take a look at the code and if that is the case just rename one of the duplicate names and be sure to make the change throughout the entire script and it should fix your problem

  3. #3
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I checked all the functions and variables, but don't see any overlap. I'm not sure how the onload and onunload events work, but I tried also combining both scripts to each pages onload and onunload event. so onload = one; two; ... onunload = one; two;

    Still a no go...

  4. #4
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    anyone?

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Um... Don't try to combine these scripts. They're completely different, I suggest using the slash dot menu, and use cookies (mmm... cookies) to save the info on the user's computer.
    - Mike

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I'm working on how to get a cookie to save the data
    - Mike

  7. #7
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    They are completely different, but I have two very necessary uses for them on the same page.

    I'm using the slashdot menu for navigation across multiple pages.

    The switch content II to allow the showing and hidding of long pieces of content to my viewers.

    One of the business requirements is to have them both remember the users last state, which both of these scripts do flawlessly... by themselves.

    I thought someone might have an easy answer as to why they weren't working together and maybe I could debug it somehow...

    I'll keep praying I can figure it out.

  8. #8
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    is that a no?

  9. #9
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    The following code is untested, but should work...
    Code:
    <script type="text/javascript">
    
    /***********************************************
    * Switch Content script II- &#169; Dynamic Drive (www.dynamicdrive.com)
    * This notice must stay intact for legal use. Last updated April 2nd, 2005.
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
    var memoryduration="7" //persistence in # of days
    
    var contractsymbol='minus.gif' //Path to image to represent contract state.
    var expandsymbol='plus.gif' //Path to image to represent expand state.
    
    /////No need to edit beyond here //////////////////////////
    
    function getElementbyClass(rootobj, classname){
    var temparray=new Array()
    var inc=0
    var rootlength=rootobj.length
    for (i=0; i<rootlength; i++){
    if (rootobj[i].className==classname)
    temparray[inc++]=rootobj[i]
    }
    return temparray
    }
    
    function sweeptoggle(ec){
    var inc=0
    while (ccollect[inc]){
    ccollect[inc].style.display=(ec=="contract")? "none" : ""
    inc++
    }
    revivestatus()
    }
    
    
    function expandcontent(curobj, cid){
    if (ccollect.length>0){
    document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="none")? "none" : ""
    curobj.src=(document.getElementById(cid).style.display=="none")? expandsymbol : contractsymbol
    }
    }
    
    function revivecontent(){
    selectedItem=getselectedItem()
    selectedComponents=selectedItem.split("|")
    for (i=0; i<selectedComponents.length-1; i++)
    document.getElementById(selectedComponents[i]).style.display="none"
    }
    
    function revivestatus(){
    var inc=0
    while (statecollect[inc]){
    if (ccollect[inc].style.display=="none")
    statecollect[inc].src=expandsymbol
    else
    statecollect[inc].src=contractsymbol
    inc++
    }
    }
    
    function get_cookie(Name) { 
    Name = 'switch';
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { 
    offset += search.length
    end = document.cookie.indexOf(";", offset);
    if (end == -1) end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }
    
    function getselectedItem(){
    if (get_cookie(window.location.pathname) != ""){
    selectedItem=get_cookie(window.location.pathname)
    return selectedItem
    }
    else
    return ""
    }
    
    function saveswitchstate(){
    var inc=0, selectedItem=""
    while (ccollect[inc]){
    if (ccollect[inc].style.display=="none")
    selectedItem+=ccollect[inc].id+"|"
    inc++
    }
    if (get_cookie(window.location.pathname)!=selectedItem){ //only update cookie if current states differ from cookie's
    var expireDate = new Date()
    expireDate.setDate(expireDate.getDate()+parseInt(memoryduration))
    document.cookie = 'switch'+"="+selectedItem+";path=/;expires=" + expireDate.toGMTString()
    }
    }
    
    function do_onload(){
    uniqueidn=window.location.pathname+"firsttimeload"
    var alltags=document.all? document.all : document.getElementsByTagName("*")
    ccollect=getElementbyClass(alltags, "switchcontent")
    statecollect=getElementbyClass(alltags, "showstate")
    if (enablepersist=="on" && get_cookie(window.location.pathname)!="" && ccollect.length>0)
    revivecontent()
    if (ccollect.length>0 && statecollect.length>0)
    revivestatus()
    }
    
    if (window.addEventListener)
    window.addEventListener("load", do_onload, false)
    else if (window.attachEvent)
    window.attachEvent("onload", do_onload)
    else if (document.getElementById)
    window.onload=do_onload
    
    if (enablepersist=="on" && document.getElementById)
    window.onunload=saveswitchstate
    
    </script>

  10. #10
    Join Date
    Jul 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That, actually, did not work. I was completely off when I said it was a cookies problem...

    The real problem was because both scripts were in seperate .js include files, both trying to call seperate onload and onunload calls, which conflicted...

    The solution was to combine both scripts into one .js include file and merge the onload / onunload calls

    Just incase anyone wants to use both of these scripts... but that's proabably doubtful... Thanks for the inspiration people!

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
  •