📄 icopopmenu_newstructure.htc
字号:
var vMenuOffsetLeft,vMenuOffsetTop,vMenuLeft,vMenuTop,vMenuWidth,vMenuHeight;
var objMenuItem,objMenuPanel,objMenu;
var vShadowFix = 0; //用于出现菜单滚动条时阴影的补偿高度,因为在出现滚动条后菜单的高度-(2 * vScrollHeight)了,而shadow是根据这个高度确定的
var vShadowSize = 5; //阴影露出菜单的大小(这里不是实际的值,实际值由css(top、left)控制,且要减去菜单边框大小)
objMenuItem = arrMenuItem[argDepth];
objMenu = arrMenu[argDepth];
objMenuPanel = objMenu.parentElement;
if (argDepth == 0){
vMenuTop = y;
vMenuLeft = x;
}
else{
objTemp = objMenuItem.parentElement;
if(objTemp){
vMenuTop = objMenuItem.offsetTop + objTemp.offsetTop - objTemp.scrollTop;//MenuItem距其menu当前顶部的距离
}else{
vMenuTop = 0;
}
vMenuLeft = objMenuItem.offsetLeft + objMenuItem.offsetWidth;
}
vMenuOffsetTop = vMenuTop;
vMenuOffsetLeft = vMenuLeft;
//计算菜单的相对页面位置
objTemp = objMenuPanel.offsetParent;
while(objTemp){
vMenuOffsetTop += objTemp.offsetTop;//取得相对页面的绝对距离
vMenuOffsetLeft += objTemp.offsetLeft;
objTemp = objTemp.offsetParent;
}
vMenuWidth = objMenu.scrollWidth + 4;
vMenuHeight = objMenu.scrollHeight + 2;//取得内部高度
//测试菜单的left
vTemp = vMenuWidth + vMenuOffsetLeft + vShadowSize - (element.document.body.clientWidth + element.document.body.scrollLeft);//菜单超过右边界的值,vShadowSize代表的是阴影的宽度
if(argDepth == 0 && vTemp > 0){ //一级子菜单
vMenuOffsetLeft -= vTemp;
vMenuLeft -= vTemp;
}
if(argDepth != 0 && vTemp > 0){ //其他级子菜单(自身超右界或父菜单超右界都向左偏)(vTemp > 0 || objTemp.offsetLeft < 0)
objTemp = objMenuPanel.parentElement;
vMenuLeft -= vMenuWidth + objTemp.offsetWidth - 6;
vMenuOffsetLeft -= vMenuWidth + objTemp.offsetWidth - 6;
}
if(vMenuOffsetLeft < element.document.body.scrollLeft){ //以左端为界修正
vMenuLeft += (element.document.body.scrollLeft - vMenuOffsetLeft); //也就是加上超过的距离
}
//测试菜单的top,在需要的情况下添加上下滚动条
vTemp = vMenuHeight + vMenuOffsetTop + vShadowSize - (element.document.body.clientHeight + element.document.body.scrollTop); //菜单超过下边界的值,vShadowSize代表的是阴影的高度
if(vTemp > 0) {
vMenuTop -= vTemp;
vMenuOffsetTop -= vTemp;
if(vMenuOffsetTop < element.document.body.scrollTop){ //如果冒出了当前页面可视范围则加滚动
vShadowFix = 2 * vScrollHeight;
vMenuHeight = element.document.body.clientHeight - (2 * vScrollHeight) - vShadowSize;
vMenuTop = (argDepth == 0)?element.document.body.scrollTop:0;
objMenu.style.top = vScrollHeight;
addScrollBar(objMenuPanel,vMenuWidth,vMenuHeight);
}
}
with(objMenu.style){ //内框
pixelWidth = vMenuWidth;
pixelHeight = vMenuHeight;
}
/*
with(objLeftIcoContainsDiv.style){ //ico容器
pixelHeight = vMenuHeight;
}
*/
with(objShadow.style){ //阴影
pixelWidth = vMenuWidth - 3;
pixelHeight = vMenuHeight - 3 + vShadowFix;
}
with(objMenuPanel.style){ //外面板
top = vMenuTop;
left = vMenuLeft;
}
}
function addScrollBar(argMenuPanel,argWidth,argHeight){ //添加滚动块,滚动块在argMenuPanel中,宽度是argWidth,下滑块的top是argHeight + 10
var objScrollBar1,objScrollBar2;
objScrollBar1= element.document.createElement("<div class='phms_ipm_scrollbar'></div>");
objScrollBar1= argMenuPanel.appendChild(objScrollBar1);
with(objScrollBar1){ //下滚动条
style.background = "#eeeeee";
innerHTML = "<v:polyline style='position:absolute;top:3;' points='0,0 4,4 8,0 0,0' fillcolor='#000000'/>";
onmouseover = scrollMenu;
onmouseout = stopScroll;
}
objScrollBar2 = element.document.createElement("<div class='phms_ipm_scrollbar'></div>");
objScrollBar2 = argMenuPanel.appendChild(objScrollBar2);
with(objScrollBar2){ //上滚动条
style.background = "#eeeeee";
innerHTML = "<v:polyline style='position:absolute;top:0;' points='0,8 4,4 8,8 0,8' fillcolor='#000000'/>";
onmouseover = scrollMenu;
onmouseout = stopScroll;
}
with(objScrollBar1.style){
pixelWidth = argWidth;
pixelHeight = vScrollHeight;
top = argHeight + vScrollHeight - 1;
left = 0;
}
with(objScrollBar2.style){
pixelWidth = argWidth;
pixelHeight = vScrollHeight;
top = 1;
left = 0;
}
}
function scrollMenu(){ //滚动超长菜单
var vTemp;
objScrollMenu = this.parentElement.firstChild; //滚动的menu,被滚动的是menu的内容
window.clearTimeout(vOpenTimer);
closeMenu(parseInt(objScrollMenu.depth)); //清除所有子菜单后再滚动
if(this.offsetTop < 10) vScrollTimer = window.setInterval(scrollDownMenu,100);
else vScrollTimer = window.setInterval(scrollUpMenu,100);
}
function scrollDownMenu(){ //连续上滚,按照菜单运动的方向
if(objScrollMenu.scrollTop > 0) objScrollMenu.scrollTop -= 10;
if(objLeftIcoContainsDiv.scrollTop > 0) objLeftIcoContainsDiv.scrollTop -=10;
else window.clearInterval(vScrollTimer);
}
function scrollUpMenu(){
var vMaxScrollTop = objScrollMenu.scrollHeight - objScrollMenu.offsetHeight;
if(objScrollMenu.scrollTop < vMaxScrollTop) objScrollMenu.scrollTop += 10;
if(objLeftIcoContainsDiv.scrollTop < vMaxScrollTop) objLeftIcoContainsDiv.scrollTop += 10;
else{
objScrollMenu.scrollTop = vMaxScrollTop;
objLeftIcoContainsDiv.scrollTop = vMaxScrollTop;
window.clearInterval(vScrollTimer);
}
}
function stopScroll(){ //停止滚动
window.clearTimeout(vScrollTimer);
}
function closeMenu(argDepth){ //关闭某级菜单项的子菜单
var objMenu;
var vDepth;
var i;
vDepth = argDepth;
objMenu = arrMenu[vDepth];
if (!objMenu) return;
if(objMenu.parentElement){
objMenu.parentElement.removeNode(true); //remove the menu Panel
}
unselectMenuItem(arrMenuItem[vDepth]);
for(i = vDepth; i < arrMenu.length; i++){ //所有下级菜单记录清空
arrMenu[i] = null;
delete arrMenu[i];
arrMenuItem[i] = null;
delete arrMenuItem[i];
}
}
function checkMenuItem(argObject,argMenu){ //核对参数对象是否是菜单项
var objTemp;
objTemp = argObject;
while(objTemp != argMenu){
if(objTemp && objTemp.__mid) return objTemp; //具有mid属性即为菜单项
objTemp = objTemp.parentElement;
}
return null;
}
function selectMenuItem(argMenuItem){
var objArrow;
var intSumLeft = 0;
var intSumTop = 0;
if(!argMenuItem) return;
if(argMenuItem.parentElement && argMenuItem.parentElement.depth){
for(var i = 0; i < parseInt(argMenuItem.parentElement.depth); i++){
intSumLeft = intSumLeft + arrMenu[i].parentElement.style.pixelLeft;
intSumTop = intSumTop + arrMenu[i].parentElement.style.pixelTop;
}
}
/*
if(objSelectBgDiv){
with(objSelectBgDiv.style){
pixelLeft = intSumLeft + 2;
pixelTop = intSumTop + argMenuItem.offsetTop + 2;
if(argMenuItem.parentElement){
pixelWidth = argMenuItem.parentElement.offsetWidth - 4;
}
pixelHeight = 20;
zIndex = 20;
visibility = "visible";
}
}
*/
with(argMenuItem.runtimeStyle){
//backgroundColor = "#BBC2D2";
backgroundColor = "#dddddd";
color = "#000000";
}
objArrow = argMenuItem.all.tags("POLYLINE")(0);
if(objArrow){
objArrow.fillcolor = "#000000";
objArrow.strokecolor.value = "#000000";
}
}
function unselectMenuItem(argMenuItem){
var objArrow;
if(!argMenuItem) return;
/*
with(objSelectBgDiv.style){
visibility = "hidden";
}
*/
//objSelectBgDiv.parentElement.removeChild(objSelectBgDiv);
//objSelectBgDiv = null;
//arrSelectBgDiv.length = arrSelectBgDiv.length - 1;
with(argMenuItem.runtimeStyle){
backgroundColor = "";
color = "";
}
objArrow = argMenuItem.all.tags("POLYLINE")(0);
if(objArrow){
objArrow.fillcolor = "#000000";
objArrow.strokecolor.value = "#000000";
}
}
function createSelectBgDiv(argDepth){
var oTempDiv;
var isExist = false;
var tmpStr;
for(var i=0;i<element.document.all.tags("DIV").length;i++){
oTempDiv = element.document.all.tags("DIV")[i];
if(oTempDiv.depth && oTempDiv.depth == argDepth){
isExist = true;
break;
}
}
/*
if(!isExist){//如果不存在则创建
oSelectBgDiv = element.document.createElement("<div class='phms_ipm_selectBgDiv'/>");
oSelectBgDiv = element.appendChild(oSelectBgDiv);
oSelectBgDiv.depth = argDepth;//绑定depth属性
arrSelectBgDiv[arrSelectBgDiv.length] = oSelectBgDiv; //创建该级菜单上的选择前景
objSelectBgDiv = oSelectBgDiv;
}
*/
for(var i=0;i<element.document.all.tags("DIV").length;i++){
if(element.document.all.tags("DIV")[i].depth){
tmpStr += element.document.all.tags("DIV")[i].depth + "|";
}
}
}
function noResponse() {
window.event.cancelBubble = true;
window.event.returnValue = false;
}
function formatXMLSource(argXMLNode,argCaptionPropName){ //将argXMLNode节点下的子元素格式化为menu htc能接受的xml样式
var vXSL;
var vPropName;
if(vCaptionPropName == null || !argXMLNode) return null;
if(!argCaptionPropName) vPropName = vCaptionPropName;
else if(argCaptionPropName.search("@") == -1) vPropName = linkPropName(argCaptionPropName);
else vPropName = argCaptionPropName;
if(!vPropName) return null;
vXSL = '<?xml version="1.0" encoding="gb2312"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" version="1.0" omit-xml-declaration="yes" encoding="gb2312" indent="no"/><xsl:template match="*"><xsl:for-each select="./*"><xsl:call-template name="menu"/></xsl:for-each></xsl:template><xsl:template name="menu"><xsl:copy><xsl:copy-of select="@*"/><xsl:attribute name="__mid"><xsl:value-of select="generate-id()"/></xsl:attribute><xsl:attribute name="__caption"><xsl:value-of select="' + vPropName + '"/></xsl:attribute><xsl:if test="count(./*) != 0"><xsl:attribute name="__hasSubMenu">true</xsl:attribute></xsl:if><xsl:for-each select="./*"><xsl:call-template name="menu"/></xsl:for-each></xsl:copy></xsl:template></xsl:stylesheet>'; //concat(\'L\',count(ancestor::*),\'F\',count(following::*),\'P\',count(preceding::*))
return argXMLNode.transformNode(inputXML(vXSL).childNodes(0));
}
function linkPropName(argPropNames){ //连接组合PropName XPath表达式
var vPropNames;
if(!argPropNames) return null;
vPropNames = argPropNames.replace(/^,|,$/,"");
if(vPropNames.search(/\,/g) == -1) vPropNames = "@" + vPropNames;
else vPropNames = "concat(@" + vPropNames.replace(",",",@") + ")";
return vPropNames;
}
function inputXML(argSource){
return(window.__objGlobalCommonInst.inputXML(argSource));
}
function popUp(argX,argY){ //弹出菜单,参数见外部文档
if(!objXMLDoc || !vXSLT) return; //必须数据和格式化均正确才能执行弹出
if(x == null) x = (typeof(argX) == "undefined")?(window.event.clientX + element.document.body.scrollLeft):argX;
if(y == null) y = (typeof(argY) == "undefined")?(window.event.clientY + element.document.body.scrollTop - 2):argY;
//element.style.zIndex = 99999;
element.innerHTML = ""; //防止鼠标点击太快导致重复出现菜单
addSubMenu(element);
x = null;
y = null; //不影响下一次弹出
downElement();
}
function initialize(){
//vXSLT = '<?xml version="1.0" encoding="gb2312"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:v="schemas-microsoft-com:vml"><xsl:output method="xml"/><xsl:template match="*"><xsl:for-each select="./*"><xsl:if test="not(@enable=\'false\')"><div class="phms_ipm_submenuitem" nowrap="true"><xsl:copy-of select="@*[name() != \'__caption\']"/><xsl:if test="@ico"><img src="{@ico}" width="' + vIcoWidth + '" height="' + vIcoHeight + '" align="absmiddle"/></xsl:if><xsl:if test="not(@ico)"><img src="images/ico/dot.gif" width="' + vIcoWidth + '" height="' + vIcoHeight + '" align="absmiddle"/></xsl:if> <xsl:value-of select="@__caption"/>   <xsl:if test="@__hasSubMenu or @dynchild"><v:polyline points="0,3 0,9 3,6 0,3" filled="true" fillcolor="#000000" class="phms_ipm_arrow"/></xsl:if></div></xsl:if><xsl:if test="@enable=\'false\'"><div class="phms_ipm_submenuitem" nowrap="true" onclick="return false;" style="color:#eeeeee" disabled="false"><xsl:copy-of select="@*[name() != \'__caption\']"/><xsl:if test="@ico"><img src="{@ico}" width="' + vIcoWidth + '" height="' + vIcoHeight + '" align="absmiddle"/></xsl:if><xsl:if test="not(@ico)"><img src="images/ico/dot.gif" width="' + vIcoWidth + '" height="' + vIcoHeight + '" align="absmiddle"/></xsl:if> <xsl:value-of select="@__caption"/>   <xsl:if test="@__hasSubMenu or @dynchild"><v:polyline points="0,3 0,9 3,6 0,3" filled="true" fillcolor="#000000" class="phms_ipm_arrow"/></xsl:if></div></xsl:if></xsl:for-each></xsl:template></xsl:stylesheet>';
vXSLT = '<?xml version="1.0" encoding="gb2312"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:v="schemas-microsoft-com:vml"><xsl:output method="xml"/><xsl:template match="*"><xsl:for-each select="./*"><xsl:if test="not(@enable=\'false\')"><div class="phms_ipm_submenuitem" nowrap="true"><xsl:copy-of select="@*[name() != \'__caption\']"/>     <xsl:value-of select="@__caption"/>   <xsl:if test="@__hasSubMenu or @dynchild"><v:polyline points="0,3 0,9 3,6 0,3" filled="true" fillcolor="#000000" class="phms_ipm_arrow"/></xsl:if></div></xsl:if><xsl:if test="@enable=\'false\'"><div class="phms_ipm_submenuitem" nowrap="true" disabled="true"><xsl:copy-of select="@*[name() != \'__caption\']"/>     <xsl:value-of select="@__caption"/>   <xsl:if test="@__hasSubMenu or @dynchild"><v:polyline points="0,3 0,9 3,6 0,3" filled="true" fillcolor="#000000" class="phms_ipm_arrow"/></xsl:if></div></xsl:if></xsl:for-each></xsl:template></xsl:stylesheet>';
vIcoXSLT = '<?xml version="1.0" encoding="gb2312"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:v="schemas-microsoft-com:vml"><xsl:output method="xml"/><xsl:template match="*"><xsl:for-each select="./*"><xsl:if test="not(@enable=\'false\')"><div class="phms_ipm_icoItemDiv" nowrap="true"><xsl:if test="@ico"><img src="{@ico}" width="18" height="18" align="absmiddle"/></xsl:if><xsl:if test="not(@ico)"><img src="../images/ico/dot.gif" width="18" height="18" align="absmiddle"/></xsl:if></div></xsl:if><xsl:if test="@enable=\'false\'"><div class="phms_ipm_icoItemDiv" nowrap="true" disabled="true"><xsl:if test="@ico"><img src="{@ico}" width="18" height="18" align="absmiddle"/></xsl:if><xsl:if test="not(@ico)"><img src="../images/ico/dot.gif" width="18" height="18" align="absmiddle"/></xsl:if></div></xsl:if></xsl:for-each></xsl:template></xsl:stylesheet>';
objDynMenuXML = inputXML("<?xml version='1.0' encoding='gb2312'?><root/>");
//debugger;
/*
objSelectBgDiv.style.visibility = "hidden";
*/
}
//-->
</script>
</public:component>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -