This function allows you set an alert to test that main menus are drawn before calling your routines.
To use the mm_setTimeOut():
-
Place the following code at the top of your menu_data.js file
var runWhenOpenedTimer = 0; function mm_isOpen(menuName) { menuObj = gmobj("menu" + getMenuByName(menuName)); if (ns4) { return (menuObj.visibility == "show"); } else { return (menuObj.style.visibility != "hidden"); } } function mm_runWhenOpened(menuName, functionToRun) { var checkInterval = 100; //msec var funcStr = "mm_runWhenOpened(\"" + menuName + "\", " + "\"" + functionToRun + "\")"; if (! mm_isOpen(menuName)) { runWhenOpenedTimer = setTimeout(funcStr, checkInterval); } else { clearTimeout(runWhenOpenedTimer); runWhenOpenedTimer = setTimeout(functionToRun, 0); } } function testFunction(menuName) { alert("I'm now doing whatever with the menu named: " + menuName); }
- mm_isOpen(menuName) is a function that checks to see if a menu is open. It takes one parameter, menuName, which is the name of the menu to check. e.g., mm_isOpen("Main Menu") will return true if the menu named "Main Menu" is open, false if not.
- mm_runWhenOpened(menuName, functionToRun) is a recursive function that will check to see if a named menu is open, and after the named menu is open will run a specified function. The mm_runWhenOpened() takes two parameters.
.
- menuName is the name of the menu to wait for (wait until it's opened)
- functionToRun is the function that you want to run once the named menu is open. funcitonToRun must be a string expression, with any passed parameters specified literally. If you want to include variable in the parameters to pass, then build functionToRun as a separate string before passing it to mm_runWhenOpened().
- mm_isOpen(menuName) is a function that checks to see if a menu is open. It takes one parameter, menuName, which is the name of the menu to check. e.g., mm_isOpen("Main Menu") will return true if the menu named "Main Menu" is open, false if not.
- In the above code, there's an example function called testFunction() placed there is simulate your function. You would replace this with your own function (i.e., whatever you want to run after the main menu appears).
- Place the following code at the bottom of your menu_data.js file after the call to drawMenus()
// first derive the name of the sub menu however you need to var subMenuName = "Partners"; // now build the function string to pass var functionString = "testFunction('" + subMenuName + "')"; // start the waiting... mm_runWhenOpened("Main Menu", functionString);