// Class prototype // --------------- function vMenu() { // Initialize functions // -------------------- this.system = _vMenu_system; this.show = _vMenu_show; this.showFromButton = _vMenu_showFromButton; this.createMenu = _vMenu_createMenu; this.openSubMenu = _vMenu_openSubMenu; this.closeMenu = _vMenu_closeMenu; this.events = _vMenu_events; // Initialize properties // --------------------- this.openMenus = new Array(); this.sourceMenu; this.timer; // The variables below are used to inform vOS/vWindow if a menu is opened and // also if the menu is appended to a menu button on a vWindow. this.selectedMenuButton; this.selectedMenuButtonID; this.menu_click = false; // Functions prototype // ------------------- function _vMenu_system(_vMenu_top, _vMenu_left, _vMenu_menu_array) { // ---------------------------------------------------------------------------- // This function will create a menu at a position of _vMenu_top and _vMenu_left // Creates a menu from a vApp with vOS.vMenu.system(). Code in // _vMenu_menu_array will be automaticly executed // ---------------------------------------------------------------------------- // Start by closing old menus vOS.vMenu.closeMenu(); // Initialize variables this.vApp_pid = ""; this.vWindow_id = ""; this.button_name = ""; this.top = _vMenu_top; this.left = _vMenu_left; this.appendTo = ""; this.menu_array = _vMenu_menu_array; this.menu_type = "vOS"; // Use the internal createMenu function to generate the menu this.createMenu(this.menu_type); } function _vMenu_show(_vMenu_vApp_pid, _vMenu_button_name, _vMenu_top, _vMenu_left, _vMenu_menu_array) { // ---------------------------------------------------------------------------- // This function will create a menu at a position of _vMenu_top and _vMenu_left // Creates a menu from a vApp with vOS.vMenu.show() // ---------------------------------------------------------------------------- // Start by closing old menus vOS.vMenu.closeMenu(); // Initialize variables this.vApp_pid = _vMenu_vApp_pid; this.vWindow_id = ""; this.button_name = _vMenu_button_name; this.top = _vMenu_top; this.left = _vMenu_left; this.appendTo = ""; this.menu_array = _vMenu_menu_array; this.menu_type = "vApp"; // Use the internal createMenu function to generate the menu this.createMenu(this.menu_type); } function _vMenu_showFromButton(_vMenu_vApp_pid, _vMenu_vWindow_id, _vMenu_button_name, _vMenu_menu_array) { // ---------------------------------------------------------------------------- // This function will create a menu which is attached to the element // _vMenu_button_name from the vWindow _vMenu_vWindow_id. // vOS.arr_vWindows[_vMenu_vWindow_id].menus[_vMenu_button_name] can be used // to get the position of the menu // Creates a menu from a vWindow with vwindowname.showFromButton() // ---------------------------------------------------------------------------- // Start by closing old menus vOS.vMenu.closeMenu(); // Initialize variables this.vApp_pid = _vMenu_vApp_pid; this.vWindow_id = _vMenu_vWindow_id; this.button_name = _vMenu_button_name; this.top = ""; this.left = ""; this.appendTo = vOS.arr_vWindows[_vMenu_vWindow_id].menus[_vMenu_button_name]; this.menu_array = _vMenu_menu_array; this.menu_type = "vWindow"; // Save the menu which is currently opened in a variable, so that the menu button // will be highlighted vOS.vMenu.selectedMenuButton = this.appendTo; vOS.vMenu.selectedMenuButtonID = this.appendTo.menu_name; // Use the internal createMenu function to generate the menu this.createMenu(this.menu_type); } function _vMenu_createMenu(_vMenu_type, _vMenu_path) { if (_vMenu_type == "vWindow") { // Calculate the position of the menu if it is opened by a vWindow var _vMenu_temp_object = this.appendTo; var _vMenu_top = 0; var _vMenu_left = (typeof _vMenu_temp_object.clientLeft == "undefined" ? _vTheme_padding_left * -1 : 0); while (_vMenu_temp_object.offsetParent) { _vMenu_top += _vMenu_temp_object.offsetTop + (_vMenu_temp_object.clientTop ? _vMenu_temp_object.clientTop : 0); _vMenu_left += _vMenu_temp_object.offsetLeft + (_vMenu_temp_object.clientLeft ? _vMenu_temp_object.clientLeft : 0); _vMenu_temp_object = _vMenu_temp_object.offsetParent; } _vMenu_top += this.appendTo.offsetHeight; } else { // If the menu is created by vOS, vApp or a submenu, the // position is already specified var _vMenu_top = this.top; var _vMenu_left = this.left; } // Check if the vMenu_path variable is empty. if (typeof _vMenu_path == "undefined") { _vMenu_path = ""; } // Create the menu div _vMenu_temp_id = this.openMenus.length; this.openMenus[_vMenu_temp_id] = document.createElement("DIV"); this.openMenus[_vMenu_temp_id].style.position = "absolute"; this.openMenus[_vMenu_temp_id].style.zIndex = "9999997"; this.openMenus[_vMenu_temp_id].className = "vMenu"; this.openMenus[_vMenu_temp_id].vMenu_path = _vMenu_path; // Make sure that the menu will not close if people click on the borders, empty places // or on disabled items this.openMenus[_vMenu_temp_id].onmousedown = function () { vOS.vMenu.menu_click = true; } // Store the "path" to the current menu in a temporary variable if (_vMenu_path) { // Sub menu eval("_vMenu_temp_array = this.menu_array" + _vMenu_path + ";"); } else { // Main menu _vMenu_temp_array = this.menu_array; } // Add all menu items for (x = 0; x < _vMenu_temp_array.length; x++) { // Add menu item var temp = document.createElement("DIV"); temp.style.cursor = "default"; temp.style.whiteSpace = "nowrap"; if (_vMenu_temp_array[x][0] == "-") { temp.className = "vMenuHr"; } else { temp.className = "vMenuSub"; temp.vMenu_path = _vMenu_path + "[" + x + "]"; var menu_left = document.createElement("SPAN"); menu_left.className = "vMenu_left"; if (_vMenu_temp_array[x][1]) { menu_left.innerHTML = ""; } temp.appendChild(menu_left); var menu_text = document.createElement("SPAN"); menu_text.className = "vMenu_text"; menu_text.innerHTML = _vMenu_temp_array[x][0]; temp.appendChild(menu_text); // Menu item has got a submenu, add an arrow if (typeof _vMenu_temp_array[x][2] == "object") { var menu_arrow = document.createElement("SPAN"); menu_arrow.className = "vMenu_arrow"; temp.appendChild(menu_arrow); } // If the menu item is disabled, do not apply any events to it. Insteed, // change the classname to vMenu_disabled so that the item can be grayed // out if (_vMenu_temp_array[x][3] == true) { // Events temp.onmouseover = function () { this.className = "vMenuSub_disabled_hover"; } temp.onmouseout = function () { this.className = "vMenuSub_disabled"; } // Set the class to the disabled versions. Only set the menu_arrow // to disabled if the menu item has got a submenu temp.className = "vMenuSub_disabled"; if (typeof _vMenu_temp_array[x][2] == "object") { menu_arrow.className = "vMenu_arrow_disabled"; } } else { // Events temp.onmouseover = vOS.vMenu.events; temp.onmouseout = vOS.vMenu.events; temp.onmousedown = vOS.vMenu.events; temp.onmouseup = vOS.vMenu.events; } } // Add to the menu div this.openMenus[_vMenu_temp_id].appendChild(temp); } // Show the menu out of sight, so the position can be adjusted this.openMenus[_vMenu_temp_id].style.left = "9999px"; vOS.screen_container.appendChild(this.openMenus[_vMenu_temp_id]); // Position the menu if (_vMenu_type == "submenu") { // A submenu, check if the menu won't go out of the screen, otherwise correct it if (_vMenu_left + this.openMenus[_vMenu_temp_id].offsetWidth > vOS.width()) { _vMenu_left = _vMenu_left - (this.openMenus[_vMenu_temp_id].offsetWidth * 2) + (_vTheme_menu * 2); } if (_vMenu_top + this.openMenus[_vMenu_temp_id].offsetHeight > vOS.height()) { _vMenu_top = _vMenu_top - this.openMenus[_vMenu_temp_id].offsetHeight + this.openMenus[_vMenu_temp_id].firstChild.offsetHeight + _vTheme_menu * 4; } } else { // The main menu, check if it won't go out of the screen, otherwise correct it if (_vMenu_left + this.openMenus[_vMenu_temp_id].offsetWidth > vOS.width()) { // Check if the menu is created by clicking on a menu button on a window, or // with another method if (_vMenu_type == "vOS") { _vMenu_left = _vMenu_left - this.openMenus[_vMenu_temp_id].offsetWidth; } else if (_vMenu_type == "vApp") { _vMenu_left = _vMenu_left - this.openMenus[_vMenu_temp_id].offsetWidth; } else if (_vMenu_type == "vWindow") { _vMenu_left = vOS.width() - this.openMenus[_vMenu_temp_id].offsetWidth; } } if (_vMenu_top + this.openMenus[_vMenu_temp_id].offsetHeight > vOS.height()) { // Check if the menu is created by clicking on a menu button on a window, or // with another method if (_vMenu_type == "vOS") { _vMenu_top = _vMenu_top - this.openMenus[_vMenu_temp_id].offsetHeight; } else if (_vMenu_type == "vApp") { _vMenu_top = _vMenu_top - this.openMenus[_vMenu_temp_id].offsetHeight; } else if (_vMenu_type == "vWindow") { _vMenu_top = _vMenu_top - this.openMenus[_vMenu_temp_id].offsetHeight - vOS.vMenu.appendTo.clientHeight; } } } this.openMenus[_vMenu_temp_id].menu_top = _vMenu_top; this.openMenus[_vMenu_temp_id].menu_left = _vMenu_left; this.openMenus[_vMenu_temp_id].style.top = _vMenu_top + "px"; this.openMenus[_vMenu_temp_id].style.left = _vMenu_left + "px"; } function _vMenu_openSubMenu(sourceMenu) { var _vMenu_temp_array = eval("vOS.vMenu.menu_array" + sourceMenu.vMenu_path); // Check if it really is a sub menu if (typeof _vMenu_temp_array[2] == "object") { // Check if a submenu has been created before, if so, close it if (vOS.vMenu.openMenus[vOS.vMenu.openMenus.length - 1].vMenu_path.length > sourceMenu.vMenu_path.length) { // Close submenus vOS.vMenu.closeMenu(sourceMenu.vMenu_path) } // Open submenu this.top = sourceMenu.parentNode.menu_top + sourceMenu.offsetTop - _vTheme_menu; this.left = sourceMenu.parentNode.menu_left + sourceMenu.parentNode.clientWidth + _vTheme_menu; vOS.vMenu.createMenu("submenu", sourceMenu.vMenu_path + "[2]"); // Highlight the menu item which opened this submenu sourceMenu.className = "vMenuSub_down"; sourceMenu.childNodes[2].className = "vMenu_arrow_hover"; sourceMenu.hasChildMenu = true; } } function _vMenu_closeMenu(_vMenu_path) { // When a menu is closed, stop the vMenu timer in case a submenu was about // to be opened window.clearTimeout(vOS.vMenu.timer); // Check to see if the whole menu needs to be closed or just some submenus if (typeof _vMenu_path == "string") { // Close all submenus until the level of the new path _vMenu_temp_id = vOS.vMenu.openMenus.length - 1; if (_vMenu_temp_id >= 0) { while (vOS.vMenu.openMenus[_vMenu_temp_id].vMenu_path.length >= _vMenu_path.length) { // Remove the highlighting of the menu item which opened this submenu _vMenu_temp = vOS.vMenu.openMenus[_vMenu_temp_id].vMenu_path; _vMenu_temp = _vMenu_temp.substr(0, _vMenu_temp.lastIndexOf("]") - 1); _vMenu_temp = _vMenu_temp.substr(0, _vMenu_temp.lastIndexOf("]")); _vMenu_temp = _vMenu_temp.substr(_vMenu_temp.lastIndexOf("[") + 1); vOS.vMenu.openMenus[_vMenu_temp_id - 1].childNodes[_vMenu_temp].className = "vMenuSub"; vOS.vMenu.openMenus[_vMenu_temp_id - 1].childNodes[_vMenu_temp].childNodes[2].className = "vMenu_arrow"; vOS.vMenu.openMenus[_vMenu_temp_id - 1].childNodes[_vMenu_temp].hasChildMenu = false; // Remove the menu from the screen vOS.vMenu.openMenus[_vMenu_temp_id].parentNode.removeChild(vOS.vMenu.openMenus[_vMenu_temp_id]); // And remove the menu from the array which keeps a record of // all opened menus vOS.vMenu.openMenus.pop(); _vMenu_temp_id--; } } } else { if (_vMenu_path == true) { if (typeof vOS.vMenu.selectedMenuButton == "object") { vOS.vMenu.selectedMenuButton.className = "window_menu_button"; vOS.vMenu.selectedMenuButtonID = false; } } // Close all submenus and the main menu _vMenu_temp_id = vOS.vMenu.openMenus.length - 1; while (_vMenu_temp_id >= 0) { // Remove all menu's from the screen vOS.vMenu.openMenus[_vMenu_temp_id].parentNode.removeChild(vOS.vMenu.openMenus[_vMenu_temp_id]); _vMenu_temp_id--; } // Clear the array which keeps a record of all opened menus vOS.vMenu.openMenus = new Array(); vOS.vMenu.vWindow_id = ""; vOS.vMenu.vApp_pid = ""; } } function _vMenu_events(e) { // Get the div on which is clicked if (!e) { var e = window.event; } var _vMenu_event_button = e.which ? e.which : e.button; var targ = vOS.event(e); // Loop through the objects until you reach the div while (targ.tagName != "DIV") { targ = targ.parentNode; } switch (e.type) { case "mouseover": if (targ.hasChildMenu != true) { targ.className = "vMenuSub_hover"; } _vMenu_temp_array = eval("vOS.vMenu.menu_array" + targ.vMenu_path); // Check to see if this item contains a submenu if (typeof _vMenu_temp_array[2] == "object") { targ.childNodes[2].className = "vMenu_arrow_hover"; vOS.vMenu.sourceMenu = targ; vOS.vMenu.timer = window.setTimeout("vOS.vMenu.openSubMenu(vOS.vMenu.sourceMenu);", 500); } else { window.clearTimeout(vOS.vMenu.timer); vOS.vMenu.timer = window.setTimeout("vOS.vMenu.closeMenu(\"" + targ.vMenu_path + "\")", 500); } break; case "mouseout": if (targ.hasChildMenu != true) { targ.className = "vMenuSub"; _vMenu_temp_array = eval("vOS.vMenu.menu_array" + targ.vMenu_path); if (typeof _vMenu_temp_array[2] == "object") { targ.childNodes[2].className = "vMenu_arrow"; } } window.clearTimeout(vOS.vMenu.timer); break; case "mousedown": // If another mousebutton than the left one is used, do not respond if (_vMenu_event_button != 1) { return; } if (targ.hasChildMenu != true) { targ.className = "vMenuSub_hover"; } vOS.vMenu.menu_click = true; break; case "mouseup": // If another mousebutton than the left one is used, do not respond if (_vMenu_event_button != 1) { return; } targ.className = "vMenuSub_down"; _vMenu_temp_array = eval("vOS.vMenu.menu_array" + targ.vMenu_path); if (typeof _vMenu_temp_array[2] == "object") { // Open submenu, be sure to also stop the timer which was started // by the mouseover command, to prevent the menu from opening twice window.clearTimeout(vOS.vMenu.timer); vOS.vMenu.openSubMenu(targ); } else { // Stop the timer to prevent errors if a menu is about to be opened window.clearTimeout(vOS.vMenu.timer); // Store all needed variables in temporary variables, since the closeMenu() // function will clear them otherwise var _vMenu_temp_vApp_pid = vOS.vMenu.vApp_pid; var _vMenu_temp_vWindow_id = vOS.vMenu.vWindow_id; var _vMenu_temp_button_name = vOS.vMenu.button_name; var _vMenu_temp_menu_type = vOS.vMenu.menu_type; // Remove the menu vOS.vMenu.closeMenu(true); // Execute item based on the menu_type to see how it should be handled if (_vMenu_temp_menu_type == "vOS") { eval(_vMenu_temp_array[2]); } else if (_vMenu_temp_menu_type == "vApp") { eval("vOS.arr_vApps[" + _vMenu_temp_vApp_pid + "].onEvent(null, '" + _vMenu_temp_button_name + "', '" + _vMenu_temp_array[2] + "');"); } else if (_vMenu_temp_menu_type == "vWindow") { eval("vOS.arr_vApps[" + _vMenu_temp_vApp_pid + "].onEvent('" + vOS.arr_vWindows[_vMenu_temp_vWindow_id].vWindow_name + "', '" + _vMenu_temp_button_name + "', '" + _vMenu_temp_array[2] + "');"); } } break; } } } add_counter(10);