Results 1 to 2 of 2

Thread: Accordion Conflicting with Hide/Show option

  1. #1
    Join Date
    Mar 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Accordion Conflicting with Hide/Show option

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

    Hey everyone,

    I'm new here, so sorry if this is out-of-place or not in any correct format.

    I recently installed a new menu (an Accordion menu) for my navigation. Along with that, I have a basic "Hide/Show" option to hide or show specific areas on the page, such as a certain news post, etc.

    As soon as I installed the Accordion menu, the Hide/Show buttons disappeared on all pages that were using both items. I recently was checking through the code to see if any specific line was causing the problem. Here's the code:

    Code:
    <script type="text/javascript"> var temp, temp2, cookieArray, cookieArray2, cookieCount;
    function initiate(){
      cookieCount=0;
      if(document.cookie){
        cookieArray=document.cookie.split(";");
        cookieArray2=new Array();
        for(i in cookieArray){
          cookieArray2[cookieArray[i].split("=")[0].replace(/ /g,"")]=cookieArray[i].split("=")[1].replace(/ /g,"");
        }
      }
      cookieArray=(document.cookie.indexOf("state=")>=0)?cookieArray2["state"].split(","):new Array();
      temp=document.getElementById("containerul");
      for(var o=0;o<temp.getElementsByTagName("li").length;o++){
        if(temp.getElementsByTagName("li")[o].getElementsByTagName("ul").length>0){
          temp2 = document.createElement("span");
          temp2.className = "symbols";
          temp2.style.backgroundImage = (cookieArray.length>0)?((cookieArray[cookieCount]=="true")?"url(minus.png)":"url(plus.png)"):"url(plus.png)";
          temp2.onclick=function(){
            showhide(this.parentNode);
            writeCookie();
          }
          temp.getElementsByTagName("li")[o].insertBefore(temp2,temp.getElementsByTagName("li")[o].firstChild)
          temp.getElementsByTagName("li")[o].getElementsByTagName("ul")[0].style.display = "none";
          if(cookieArray[cookieCount]=="true"){
            showhide(temp.getElementsByTagName("li")[o]);
          }
          cookieCount++;
        }
        else{
          temp2 = document.createElement("span");
          temp2.className = "symbols";
          temp2.style.backgroundImage = "url(page.png)";
          temp.getElementsByTagName("li")[o].insertBefore(temp2,temp.getElementsByTagName("li")[o].firstChild);
        }
      }
    }
    
    function showhide(el){
      el.getElementsByTagName("ul")[0].style.display=(el.getElementsByTagName("ul")[0].style.display=="block")?"none":"block";
      el.getElementsByTagName("span")[0].style.backgroundImage=(el.getElementsByTagName("ul")[0].style.display=="block")?"url(minus.png)":"url(plus.png)";
    }
    
    function writeCookie(){ // Runs through the menu and puts the "states" of each nested list into an array, the array is then joined together and assigned to a cookie.
      cookieArray=new Array()
      for(var q=0;q<temp.getElementsByTagName("li").length;q++){
        if(temp.getElementsByTagName("li")[q].childNodes.length>0){
          if(temp.getElementsByTagName("li")[q].childNodes[0].nodeName=="SPAN" && temp.getElementsByTagName("li")[q].getElementsByTagName("ul").length>0){
            cookieArray[cookieArray.length]=(temp.getElementsByTagName("li")[q].getElementsByTagName("ul")[0].style.display=="block");
          }
        }
      }
      document.cookie="state="+cookieArray.join(",")+";expires="+new Date(new Date().getTime() + 365*24*60*60*1000).toGMTString();
    }
    </script>
    
    	<script type="text/javascript" src="javascript/prototype.js"></script>
    	<script type="text/javascript" src="javascript/effects.js"></script>
    	<script type="text/javascript" src="javascript/accordion.js"></script>
        	<script type="text/javascript">
    			
    		//
    		//  In my case I want to load them onload, this is how you do it!
    		// 
    		Event.observe(window, 'load', loadAccordions, false);
    	
    		//
    		//	Set up all accordions
    		//
    		function loadAccordions() {
    			var topAccordion = new accordion('horizontal_container', {
    				classNames : {
    					toggle : 'horizontal_accordion_toggle',
    					toggleActive : 'horizontal_accordion_toggle_active',
    					content : 'horizontal_accordion_content'
    				},
    				defaultSize : {
    					width : 525
    				},
    				direction : 'horizontal'
    			});
    			
    			var bottomAccordion = new accordion('vertical_container');
    			
    			var nestedVerticalAccordion = new accordion('vertical_nested_container', {
    			  classNames : {
    					toggle : 'vertical_accordion_toggle',
    					toggleActive : 'vertical_accordion_toggle_active',
    					content : 'vertical_accordion_content'
    				}
    			});
    			
    			// Open first one
    			bottomAccordion.activate($$('#vertical_container .accordion_toggle')[0]);
    			
    			// Open second one
    			topAccordion.activate($$('#horizontal_container .horizontal_accordion_toggle')[2]);
    		}
    		
    	</script>
    The first script is for the Hide/Show buttons. The next four are all for the Accordion menu. After removing the "effects.js" and "prototype.js" scripts from the header, the Hide/Show buttons appeared once again, and, obviously, the accordion can't work.

    Here's the three scripts that are required for the Accordion to run (everything except the containerul.js):
    http://omgclan.com/javascript/

    I'm just assuming there's something in both the effects.js and prototype.js that is messing up the other code, but I'm still pretty new to javascript, so any help you can give would be awesome!

    Thanks again for your time and any help you can offer!
    Last edited by ddadmin; 03-16-2009 at 11:19 PM.

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

    Default

    Warning: Please include a link to the DD script in question in your post. See this thread for the proper posting format when asking a question.

    It's hard to say at a glance whether the issue is a conflict with the two libraries (Prototype and jQuery) themselves, or something within the two scripts based on these two libraries. Per the last solution mentioned on this page, at the very top of ddaccordion.js, try adding this line to it:

    Code:
     jQuery.noConflict();
    See if that changes anything.
    DD Admin

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
  •