📄 popupmenu-script.js
字号:
aHtml.push ( "<td align=center unselectable='on' width=30 nowrap> " );
if( aItemData.icon ) {
aHtml.push ( "<img border=0 src=\"" + aItemData.icon + "\">" );
} else {
aHtml.push ( " " );
}
aHtml.push ( "</td>" );
//文本列
aHtml.push ( "<td nowrap unselectable='on'>" );
aHtml.push ( aItemData.text );
aHtml.push ( "</td>" );
//右边(如果有子菜单应显示箭头)
aHtml.push ( "<td nowrap width=10 unselectable='on'>" );
if( blnHasChildren ) {
aHtml.push ( "<font style='font-family:Webdings;font-size:7pt;height:10;padding-right:5px;padding-left:3px;'>4</font>" );
} else {
aHtml.push ( " " );
}
aHtml.push ( "</td>" );
aHtml.push ( "</tr>" );
return aHtml.join("");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// ------------------------------ end 将菜单数据转换为html代码的函数 -------------------------------------//
// ------------------------------------- 显示子菜单的处理 ---------------------------------------//
//////////////////////////////////////////////////////////////////////////////////////////////////
//显示主菜单下的一级子菜单
function showItemsOfMain ( id ) {
var hasSub = hasChildren( id );
//判断事件
var eventType = window.event.type.toLowerCase();
if( eventType == "mouseover" && !getPopup(0).isOpen ) {
return;
}
if( eventType == "click" ) {
execute( id );
}
//alert("OK");
///////////////////////////////////////////////////
//如果没有子菜单,则隐藏第一级popup窗口即可,因为其它子窗口会一并隐藏
if( !hasSub ) {
//getPopup(0).hide();
return;
}
var objMain = document.getElementById( id );
var pop = getPopup(0);
pop.document.body.innerHTML = getSubItemsHtml(id);
//设置id属性,以便辨别打开的窗口属于该菜单项
pop.document.body.setAttribute("id", id);
pop.show(0,0,1,1,objMain);
var intWidth = pop.document.body.scrollWidth;
var intHeight = pop.document.body.scrollHeight;
pop.hide();
pop.show(10,objMain.offsetHeight-2,intWidth,intHeight,objMain);
}
//显示菜单项下属的子菜单
//@param objItem 菜单项对象
//@param id 菜单项id(添加数据时的id)
function showItems( objItem, id ) {
//如果没有子菜单,则隐藏窗口打开的子窗口
if( !hasChildren(id) ) {
hideAllParentPopup( id );
return;
}
//得到显示的Popup窗口
var degree = getMenuDegree(id);
var pop = getPopup( degree );
pop.document.body.innerHTML = getSubItemsHtml(id);
//设置id属性,以便辨别打开的窗口属于该菜单项
pop.document.body.setAttribute("id", id);
pop.show(0,0,1,1,objItem);
var intWidth = pop.document.body.scrollWidth;
var intHeight = pop.document.body.scrollHeight;
var intLeft = objItem.offsetWidth - 2;
/*
var screenWidth = screen.width;
document.all.txtWidth.value = (intLeft + intWidth + 5) + " left=" + objItem.scrollLeft;
if( (intLeft + intWidth + 5) > screenWidth ) {
intLeft = intLeft - 2 * intWidth;
}*/
pop.hide();
pop.show(intLeft, -2, intWidth,intHeight, objItem);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// ------------------------------------- end 显示子菜单的处理 ---------------------------------------//
//判断一个菜单项下属的子菜单是否打开
function isSubItemsOpen( id ) {
if( !hasChildren( id ) ) {
return false;
}
var degree = getMenuDegree(id);
if( !aPopupWindows[degree] || !aPopupWindows[degree].isOpen ) {
return false;
}
if( aPopupWindows[degree].document.body.getAttribute("id") != id ) {
return false;
}
return true;
}
var prevMainMenuItemObj = null;
// --------------- 重置菜单得时间器处理 ------------------//
//这种方式对于子菜单不适应
var menuPopTimer = null;
function menuPopOut() {
//clearMenuPopTimer();
menuPopTimer = window.setTimeout("resetMenu()",700);
}
function clearMenuPopTimer() {
if( menuPopTimer != null ) {
window.clearTimeout(menuPopTimer);
}
}
////////////////////////////////////////////////////////////
document.onclick = clickEvent
top.document.onclick = clickEvent
// ------------------------------ 改变菜单样式得相关处理 -----------------------------------//
/////////////////////////////////////////////////////////////////////////////////////////////
//将菜单置为初始状态
function resetMenu() {
//clickEvent()
if( prevMainMenuItemObj != null ) {
chgMainMenuStyle(prevMainMenuItemObj, false);
prevMainMenuItemObj = null;
}
getPopup(0).hide();
}
//鼠标单击时响应的事件
function clickEvent() {
if( prevMainMenuItemObj != null && !getPopup(0).isOpen ) {
chgMainMenuStyle(prevMainMenuItemObj, false);
prevMainMenuItemObj = null;
}
}
//鼠标移上主菜单时样式的改变
function mainMenuOverStyle(id, obj) {
//clearMenuPopTimer();//清除重置菜单得时间器
chgMainMenuStyle(obj, true);
mapIdVSItemInfos[id].obj = obj;
if( prevMainMenuItemObj == obj ) {
return;
}
if( prevMainMenuItemObj != null ) {
chgMainMenuStyle(prevMainMenuItemObj, false);
}
prevMainMenuItemObj = obj;
}
//鼠标移上主菜单上样式的改变
//@param id 菜单项对应的id
//@param obj 被恢复样式的菜单对象
function mainMenuOutStyle(id, obj) {
//menuPopOut();//打开重置菜单得时间器
//如果有子菜单打开,则不恢复
if( isSubItemsOpen(id) ) {
return;
}
chgMainMenuStyle(obj, false);
}
//鼠标移上子菜单项上时样式的改变
//除了改变当前菜单项的样式之外,
//还要恢复同窗口中上次被改变的菜单样式
function subMenuOverStyle(id, obj) {
//clearMenuPopTimer();//清除重置菜单得时间器
mapIdVSItemInfos[id].obj = obj;
var parentId = mapIdVSItemInfos[id].parentId;
var preObj = mapIdVSItemInfos[parentId].preObj;
chgSubMenuStyle(obj, true);
if( preObj == obj ) {
return;
}
if( preObj ) {
chgSubMenuStyle(preObj, false);
}
mapIdVSItemInfos[parentId].preObj = obj;
}
//鼠标移开子菜单上样式的改变
//@param id 菜单项对应的id
//@param obj 被恢复样式的菜单对象
function subMenuOutStyle(id, obj) {
//menuPopOut();//打开重置菜单得时间器
//如果有子菜单打开,则不恢复
if( isSubItemsOpen(id) ) {
return;
}
chgSubMenuStyle(obj, false);
}
/////////////////////////////////////////////////////////////////////////////////////////////
// ------------------------------ end 改变菜单样式得相关处理 -----------------------------------//
//显示主窗口需弹出的popup窗口
function showMainPopup( pop, objMain ) {
var objLink = pop.document.getElementsByTagName("LINK")[0];
if( objLink.readyState == "complete" ) {
}
}
//判断一个菜单项是否有子菜单
function hasChildren( id ) {
if( !menuItemVSSubItems[id] ) {
return false;
}
if( menuItemVSSubItems[id].length == 0 ) {
return false;
}
return true;
}
/// ------------------------------------ 执行菜单相应事件的操作 ------------------------------------------------//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//执行菜单的响应事件
function execute( id ) {
var action = mapIdVSItemInfos[id].action;
var target = mapIdVSItemInfos[id].target;
var aFromIds = getMenuFromIds(id);//进入该菜单所经历的菜单项
//获取位置信息
var position = "";
for( var i = aFromIds.length - 1;i >=0;i -- ) {
position += mapIdVSItemInfos[aFromIds[i]].text + " ";
}
position += mapIdVSItemInfos[id].text;
//end 获取位置信息
//alert(position);
if( action == "" || action == "#" ) {
return;
}
resetMenu();//重置菜单
if( target.toLowerCase() == "js" || target.toLowerCase() == "javascript" ) {
eval( action );
return;
}
if( shouldAddContextPathBefore( action ) ) {
action = contextPath + action;
}
//alert( action );
window.open(action, target);
}
//判断是否应在某个链接前加上contextPath
function shouldAddContextPathBefore( action ) {
if( !contextPath || contextPath == "" ) {
return false;
}
if( action.toLowerCase().substring(0,4) == "http" ) {
return false;
}
//如果url指定的不是决定路径,则不用加
if( action.substring(0,1) != "/" ) {
return false;
}
//如果已经是contextptah开头,则不用加
var len = contextPath.length;
if( action.length > len && action.substring(0,len) == contextPath ) {
return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ------------------------------------ end 执行菜单相应事件的操作 ------------------------------------------------//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -