diff options
author | David Farning <dfarning@gmail.com> | 2009-03-03 23:54:43 (GMT) |
---|---|---|
committer | David Farning <dfarning@gmail.com> | 2009-03-03 23:54:43 (GMT) |
commit | 8c7441319b5e3ae55a341bcfb75c2b25cd9c72bd (patch) | |
tree | e025cec296ebde0fd8c551ef29872ae8375de633 /scripts/menu.js |
Diffstat (limited to 'scripts/menu.js')
-rw-r--r-- | scripts/menu.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/menu.js b/scripts/menu.js new file mode 100644 index 0000000..6d33bc6 --- /dev/null +++ b/scripts/menu.js @@ -0,0 +1,54 @@ +// JavaScript Document + +// DropDownMenu by Miha Hribar +// http://hribar.info + +function addLoadEvent(func) { + var oldonload = window.onload; + if (typeof window.onload != 'function') { + window.onload = func; + } else { + window.onload = function() { + oldonload(); + func(); + } + } +} + +function prepareMenu() { + // first lets make sure the browser understands the DOM methods we will be using + if (!document.getElementsByTagName) return false; + if (!document.getElementById) return false; + + // lets make sure the element exists + if (!document.getElementById("menu")) return false; + var menu = document.getElementById("menu"); + + // for each of the li on the root level check if the element has any children + // if so append a function that makes the element appear when hovered over + var root_li = menu.getElementsByTagName("li"); + for (var i = 0; i < root_li.length; i++) { + var li = root_li[i]; + // search for children + var child_ul = li.getElementsByTagName("ul"); + if (child_ul.length >= 1) { + // we have children - append hover function to the parent + li.onmouseover = function () { + if (!this.getElementsByTagName("ul")) return false; + var ul = this.getElementsByTagName("ul"); + ul[0].style.display = "block"; + return true; + } + li.onmouseout = function () { + if (!this.getElementsByTagName("ul")) return false; + var ul = this.getElementsByTagName("ul"); + ul[0].style.display = "none"; + return true; + } + } + } + + return true; +} + +addLoadEvent(prepareMenu);
\ No newline at end of file |