Hi
Im using Javascript to expand a unordered list menu and it works on my pc in the latest versions of Opera, Safari, Firefox and IE. But i have been told that the buttons do not work in Safari on a MAC. It does however work in IE on a MAC.
Is there a difference between the way Safari on a MAC would read the code?
Many thanks
Im using Javascript to expand a unordered list menu and it works on my pc in the latest versions of Opera, Safari, Firefox and IE. But i have been told that the buttons do not work in Safari on a MAC. It does however work in IE on a MAC.
Is there a difference between the way Safari on a MAC would read the code?
Many thanks
Code:
var dMenu = (function(){
var menu;
function parentLi(el) {
do {
if (el.tagName.toLowerCase() == 'li') return el
} while (el = el.parentNode)
}
function openParentUls(el) {
while (el != menu) {
if (el.tagName.toLowerCase() == 'ul') el.style.display = '';
el = el.parentNode;
}
}
function closeAll(el) {
var el = el || menu;
var uls = el.getElementsByTagName('ul');
var i = uls.length;
while(i--){uls[i].style.display = 'none';}
}
return {
init: function (id) {
if (!document.getElementsByTagName ||
!document.getElementById ) {
return;
}
menu = document.getElementById(id);
if (menu) {
this.closeAll(menu);
var uls = menu.getElementsByTagName('ul');
var i = uls.length;
while (i--) {
parentLi(uls[i]).onclick = this.doClick;
}
}
},
closeAll: function (el) {
closeAll(el);
},
doClick: function(e) {
var e = e || window.event;
var tgt = e.target || e.srcElement;
if(tgt.tagName.toLowerCase()!='a') return;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
while (tgt != this) {
if (tgt.tagName.toLowerCase() == 'ul') return;
tgt = tgt.parentNode;
}
var firstUl = this.getElementsByTagName('ul')[0];
var firstUlDisplay = firstUl.style.display;
closeAll(menu);
openParentUls(this);
firstUl.style.display = ('none' == firstUlDisplay)? '' : 'none';
}
}
})();