Code listing for m.js
- /*
- * date: 2002-10-14
- * info: http://inspire.server101.com/js/m/
- */
- var mItem = [];
- var mTime = [];
- var mWait = 250;
- function mSet(ul, c) {
- if (document.getElementById) {
- ul = document.getElementById(ul).getElementsByTagName('ul');
- var i, j, e, a, f, b;
- var m = mItem.length;
- for (i = 0; i < ul.length; i++) {
- if (e = ul[i].getAttribute('id')) {
- mItem[m] = e;
- e = ul[i].parentNode;
- e.className = c;
- f = new Function('mShow(\'' + mItem[m] + '\');');
- b = new Function('mBlur(\'' + mItem[m] + '\');');
- e.onmouseover = f;
- e.onmouseout = b;
- a = e.getElementsByTagName('a');
- for (j = 0; j < a.length; j++) {
- a[j].onfocus = f;
- a[j].onblur = b;
- }
- m++;
- }
- }
- }}
- function mShow(id) {
- for (var i = 0; i < mItem.length; i++) {
- if (document.getElementById(mItem[i]).style.display != 'none') {
- if (mItem[i] != id) mHide(mItem[i]);
- else mClear(mItem[i]);
- }
- }
- document.getElementById(id).style.display = 'block';
- }
- function mHide(id) {
- mClear(id);
- document.getElementById(id).style.display = 'none';
- }
- function mBlur(id) {
- mTime[id] = setTimeout('mHide(\'' + id + '\');', mWait);
- }
- function mClear(id) {
- if (mTime[id]) {
- clearTimeout(mTime[id]);
- mTime[id] = null;
- }
- }
function mSet(ul, c)
Transforms <ul> elements into a popup menu.
Creates mouse and keyboard event triggers and adjusts classes
to allow the menu style to be altered upon success.
- ul
- String: id the menu items’ parent in the HTML source.
- c
- String: class name applied to menu items.
function mShow(id)
Hides all open menus, then opens the specified menu.
Cancels any timeout set to close the specified menu.
- id
- String: id of menu item to show (pop up).
function mHide(id)
Internal function triggered by timeouts set in mBlur.
Immediately hides a menu.
Calling this directly from menu events would cause the menu to disappear
when tabbing through menu links, or moving the mouse too far too fast.
- id
- String: id of menu item to hide.
function mBlur(id)
Creates a timeout to hide this menu.
Timeouts are used to detect when the mouse or keyboard focus leaves a menu.
If the mouse/keyboard focus returns to the menu, the timeout is cancelled
(therefore the menu is never hidden).
- id
- String: id of menu item to hide.
function mClear(id)
Internal function used by mShow and mHide
to clear timeouts. One timeout per menu is allowed in the mTime (hash) array.
Timeouts are set to null to enable accurate detection of whether a given timeout is set.
- id
- String: id of menu item.