SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    Swindon
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help changing code

    hi there, im working on an expanding/contracting menu which i found details of on the 456 Berea St website for and it works great,

    What i want to do is expand (no pun intended) it further so that if the <li> is of class "selected" then that nested ul will not be hidden.

    The js i have atm is

    Code:
    var toggleMenu = {
    	init : function(sContainerClass, sHiddenClass) {
    		if (!document.getElementById || !document.createTextNode) {return;} // Check for DOM support
    		var arrMenus = this.getElementsByClassName(document, 'ul', sContainerClass);
    		var arrSubMenus, oSubMenu, oLink;
    		for (var i = 0; i < arrMenus.length; i++) {
    			arrSubMenus = arrMenus[i].getElementsByTagName('ul');
    			for (var j = 0; j < arrSubMenus.length; j++) {
    				oSubMenu = arrSubMenus[j];
    				oLink = oSubMenu.parentNode.getElementsByTagName('a')[0];
    				oLink.onclick = function(){toggleMenu.toggle(this.parentNode.getElementsByTagName('ul')[0], sHiddenClass); return false;}
    				this.toggle(oSubMenu, sHiddenClass);
    			}
    		}
    	},
    	toggle : function(el, sHiddenClass) {
    		var oRegExp = new RegExp("(^|\\s)" + sHiddenClass + "(\\s|$)");
    		el.className = (oRegExp.test(el.className)) ? el.className.replace(oRegExp, '') : el.className + ' ' + sHiddenClass; // Add or remove the class name that hides the element
    	},
    /* addEvent function from http://www.quirksmode.org/blog/archi..._winner_1.html */
    	addEvent : function(obj, type, fn) {
    		if (obj.addEventListener)
    			obj.addEventListener(type, fn, false);
    		else if (obj.attachEvent) {
    			obj["e"+type+fn] = fn;
    			obj[type+fn] = function() {obj["e"+type+fn](window.event);}
    			obj.attachEvent("on"+type, obj[type+fn]);
    		}
    	},
    /*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
    */
    	getElementsByClassName : function(oElm, strTagName, strClassName){
    	    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    	    var arrReturnElements = new Array();
    	    strClassName = strClassName.replace(/\-/g, "\\-");
    	    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    	    var oElement;
    	    for(var i=0; i<arrElements.length; i++){
    	        oElement = arrElements[i];      
    	        if(oRegExp.test(oElement.className)){
    	            arrReturnElements.push(oElement);
    	        }   
    	    }
    	    return (arrReturnElements)
    	}
    };
    toggleMenu.addEvent(window, 'load', function(){toggleMenu.init('menu','hidden');});
    Im a total noob so im not even sure what im doing, i have the css and html working as it should

    any help would be greatly appreciated
    Last edited by billybrag; Nov 11, 2008 at 07:02. Reason: code tags

  2. #2
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    Swindon
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can anyone help with this, or suggest an alternative js that i can use?

  3. #3
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    Swindon
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all,

    I have tried to battle with this but to no avail.

    Can anyone help me at all?


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
  •