Me echáis un cable? Mil gracias
Código HTML:
// JavaScript Document
<!--
var toggleMenu = {
init : function(sContainerClass, sHiddenClass) {
if (!document.getElementById || !document.createTextNode) {
return;
} // Check for DOM support
// setting up the actual page url with NO variables attached to it
// check only the url itself ignoring the variables in the URL
// added by [email protected]
var CompleteUrl = window.document.location.toString();
var splitCompleteUrl = CompleteUrl.split("/");
var splitSplitUrl = splitCompleteUrl[splitCompleteUrl.length-1].split("?");
var actualPage = splitSplitUrl[0];
// END setting up the actual page url with NO variables attached to it
var arrMenus = this.getElementsByClassName(document, 'ul', sContainerClass);
var arrSubMenus, oSubMenu, oLink;
for (var i = 0; i < arrMenus.length; i++) {
// ULs - second level
arrSubMenus = arrMenus[i].getElementsByTagName('ul');
for (var j = 0; j < arrSubMenus.length; j++) {
// ULs - second level
oSubMenu = arrSubMenus[j];
// links(URL) first level
oLink = oSubMenu.parentNode.getElementsByTagName('a')[0];
// element 'A' - second level
oSubA = oSubMenu.getElementsByTagName('a');
// added by [email protected]
arrSubA = [];
for (var k = 0; k < oSubA.length; k++) {
// to correct a IE bug wich returns the full URL as ths href atribute
var splitLink = oSubA[k].attributes['href'].value.split("/")
arrSubA[k] = splitLink[splitLink.length-1];
}
// added by [email protected]
// test if there is a actualPage variable in the links array
if(this.arraySearch(actualPage, arrSubA) < 0){
oLink.onclick = function(){
toggleMenu.toggle(this.parentNode.getElementsByTagName('ul')[0], sHiddenClass);
return false;
}
this.toggle(oSubMenu, sHiddenClass);
} else {
oLink.onclick = function(){
toggleMenu.toggle(this.parentNode.getElementsByTagName('ul')[0], sHiddenClass);
return false;
}
this.toggle(oSubMenu, 'block');
// disabling the actualpage link
oSubA[this.arraySearch(actualPage, arrSubA)].onclick = function(){
return false;
}
// changing the class of the parent element
oSubA[this.arraySearch(actualPage, arrSubA)].parentNode.className = 'actualpage';
}
}
}
},
toggle : function(el, sHiddenClass) {
var oRegExp = new RegExp("(^|\\s)" + sHiddenClass + "(\\s|$)");
// Add or remove the class name that hides the element
el.className = (oRegExp.test(el.className)) ? el.className.replace(oRegExp, '') : el.className + ' ' + sHiddenClass;
},
// added by [email protected]
arraySearch : function(searchS, arraySA) {
var I = 0;
var minI = 0;
var maxI = arraySA.length - 1;
//
var s = "";
//
var foundB = false;
//
I = minI - 1;
while ((I <= maxI) && (!(foundB))) {
I = I + 1;
s = arraySA[I];
foundB = (searchS == s);
}
if (foundB) {
return(I);
}
else {
return(-1000); // some negative number indicating not found
}
},
/* addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_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','cuadrado');});
//-->