// ***************************************** // menu.js : dynamic hierarchical menu system // // (c) by E.F. de Moor (Creagraphy) ernst@creagraphy.nl // // date: april 8th 2002 // // // Following function are used for interfacing // // do_menu_sel : distribution function for menu selection // do_menu_over : distribution function for menu over // do_menu_out : distribution function for menu out // // my_menu_sel(id) : called when the user clicks a menu item in our own frame. // my_menu_over(id) : called when the mouse moves over a menu item of our own frame. // my_menu_out(id) : called when the mouse moves out a menu item of our own frame. // // menu_sel(id) : called when the user clicks a menu item in any frame. // menu_over(id) : called when the mouse moves over a menu item in any frame. // menu_out(id) : called when the mouse moves out a menu item in any frame. // set_page_info(sel, info) : called by the content frame, if the content changes. // // cms_onload(sel) : called once when this frame is loaded // // // Note about the my_menu... functions: // These functions are implemented in ../menu.inc. // // Note about the menu_sel, menu_over and menu_out functions: // Any frame is allowed to implement these (not just menu frames). This can be used // To give helpinformation (e.g. popup notes, textual explanations) in other frames // Whenever something happens with a menu button or whenever a new page is loaded // in the content frame. // // Note: Also new is that the content frame is now allowed to have a menu itself. This is // Handy to have a popup menu to appear over the content itself. // Remember the last selection // ------ Interface Functions ------- add_onload(onload_menu_popup); add_page_info(page_info_popup); add_menu_sel(menu_sel_popup); add_menu_over(menu_over_popup); add_menu_out(menu_out_popup); function onload_menu_popup(sel) { if(typeof(parent.selection) != "undefined") set_states_from_sel(parent.selection); else if(typeof(top.selection) != "undefined") set_states_from_sel(top.selection); else set_states_from_sel(sel); hide_popup(0,0,0,0,0); } function page_info_popup(sel, info) { hide_popup(0,0,0,0,0); } function menu_sel_popup(id, item_x, item_y) { hide_popup(id,0,0,0,0); } function menu_over_popup(id, item_x, item_y) { window.status = menu_tree[id].explanation; if((menu_tree[id].level >= menu_settings_popup.min_menu_level) && (menu_tree[id].level <= menu_settings_popup.max_menu_level)) { show_menu_item(id, 1, menu_tree[id].visible, menu_tree_parms[id].opacity_percentage); } show_popup(id, item_x, item_y); //Solve the IE6 bug: Force a refresh redraw = 'show_popup('+id+','+item_x+','+item_y+')'; setTimeout(redraw, 15); } function menu_out_popup(id, item_x, item_y) { window.status = ''; if((menu_tree[id].level >= menu_settings_popup.min_menu_level) && (menu_tree[id].level <= menu_settings_popup.max_menu_level)) show_menu_item(id, 0, 0, menu_tree_parms[id].opacity_percentage); setTimeout('hide_popup('+id+',1,'+item_x+','+item_y+',0)', 100); } // ------ Menu functions ------- var last_popup_id = -1 function show_popup(id, item_x, item_y) { var first_id = id; var last_id = id; var menu_height = 0; var menu_width = 0; var i=0; last_popup_id = id; // Start with all menuitems set to invisible for(var i=0; i= menu_settings_popup.min_menu_level && menu_tree[i].level <= menu_settings_popup.max_menu_level) menu_tree_parms[i].desired_vis = 0; // Show all previous items of the same level for(i=id; i>=0; i--) { if(menu_tree[i].level < menu_tree[id].level) break; if(menu_tree[i].level < menu_settings_popup.min_menu_level) break; if(menu_tree[i].level <= menu_settings_popup.max_menu_level) { first_id = i; if(menu_tree[i].level == menu_tree[id].level) menu_tree_parms[i].desired_vis = 1; } } // Show all next items of the same level for(i=parseInt(id)+1; i menu_width) menu_width = menu_tree_parms[i].width; } } } // Calculate all positions of children if(((menu_tree[id].level+1) >= menu_settings_popup.min_menu_level) && ((menu_tree[id].level+1) <= menu_settings_popup.max_menu_level)) { cur_x = calc_x(menu_settings_popup.x_pos[menu_tree[id].level+1], menu_settings_popup.x_align[menu_tree[id].level], item_x, menu_width); cur_y = calc_y(menu_settings_popup.y_pos[menu_tree[id].level+1], menu_settings_popup.y_align[menu_tree[id].level], item_y, menu_height); for(i=first_id; i<=last_id; i++) { if((menu_tree[i].level == (menu_tree[id].level+1)) && menu_tree_parms[i].desired_vis) { set_all_x(i,cur_x, 1); set_all_y(i,cur_y, 1); cur_y += menu_tree_parms[i].height; } } } // Make menu items visible if we don't use animation. if(!menu_settings_popup.animation_speed) { for(var i=0; i= menu_settings_popup.min_menu_level && menu_tree[i].level <= menu_settings_popup.max_menu_level) { if(menu_tree_parms[i].desired_vis) { mouse_over = (id == i) ? 1 : 0; show_menu_item(i, mouse_over, 1, 100); } else show_menu_item(i, 0, 0, 0); } } } // Call do_animate with a delay, to prevent mouse over conflicts if(menu_settings_popup.animation_speed) setTimeout('do_animate(0)', 25); } function hide_popup(id, animate,item_x,item_y,loop) { // Safety overlap (for borders that don't belong to the button etc!!!) // Take a few pixels around the actual menu button. if(animate && mouseX > (item_x) && mouseY > (item_y-2) && mouseX < (item_x + menu_tree_parms[id].width) && mouseY < (item_y + menu_tree_parms[id].height+2)) { setTimeout('hide_popup('+id+',1,'+item_x+','+item_y+',1)', 25); return; } // Prevent removing the menu too soon. if(animate && id != last_popup_id) return; for(var i=0; i= menu_settings_popup.min_menu_level) { if(menu_tree[i].level <= menu_settings_popup.max_menu_level) { if(animate && menu_settings_popup.animation_speed) menu_tree_parms[i].desired_vis = 0; else { show_menu_item(i, 0, 0, 0); if(!menu_settings_popup.animation_speed) menu_tree_parms[i].opacity_percentage = 100; } } } } // Call do_animate with a delay, to prevent mouse over conflicts if(animate && menu_settings_popup.animation_speed) setTimeout('do_animate(0)', 25); } var animating = false; function do_animate(from_timer) { var changed=0; if(animating && !from_timer) // Prevent multiple background loops return; animating = true; // Modify the opacity of the menu items. for(var i=0; i= menu_settings_popup.min_menu_level && menu_tree[i].level <= menu_settings_popup.max_menu_level) { mouse_over = (last_popup_id == i) ? 1 : 0; if(menu_tree_parms[i].desired_vis != menu_tree_parms[i].cur_vis) { changed++; if(typeof(menu_tree_parms[i].opacity_percentage) == "undefined") menu_tree_parms[i].opacity_percentage = 0; if(menu_tree_parms[i].desired_vis) menu_tree_parms[i].opacity_percentage+=menu_settings_popup.animation_speed; else menu_tree_parms[i].opacity_percentage-=menu_settings_popup.animation_speed; if(menu_tree_parms[i].opacity_percentage >= 100) { menu_tree_parms[i].opacity_percentage = 100; menu_tree_parms[i].cur_vis = 1; show_menu_item(i, mouse_over, 1, 100); } else if(menu_tree_parms[i].opacity_percentage <= 0) { menu_tree_parms[i].opacity_percentage = 0; menu_tree_parms[i].cur_vis = 0; show_menu_item(i, mouse_over, 0, 0); } else { show_menu_item(i, mouse_over, 1, menu_tree_parms[i].opacity_percentage); menu_tree_parms[i].cur_vis = -1; } } } } if(changed) setTimeout('do_animate(1)', 50); else animating = false; }