OfficeXP menu(过程版)

发表于:2007-07-14来源:作者:点击数: 标签:
? php /** * 仿Office XP 风格的左边版面列表 * -------------------------------------------------------------------------------- * blood 于 2/19/2002 4:47:11 PM 加贴在 Visual Basic * * 徐祖宁(唠叨) 移植于 2/28/2002 * 更正部分错误 * */ if($key
<?php
/**
* 仿OfficeXP风格的左边版面列表    
* --------------------------------------------------------------------------------
* blood 于 2/19/2002 4:47:11 PM 加贴在 Visual Basic
*
* 徐祖宁(唠叨) 移植于 2/28/2002
* 更正部分错误
*
*/

if($key == ""):
echo <<<EOD
<HTML>
<HEAD>
<TITLE>Menu Sample</TITLE>
<SCRIPT LANGUAGE="JavaScript">
if (window != top) top.location.href = location.href;
</SCRIPT>
</HEAD>
  <FRAMESET cols="161,*">        
    <FRAME MARGINWIDTH="0" SRC="$PHP_SELF?key=menu" NAME="menu" SCROLLING=no NORESIZE>
    <FRAME  MARGINWIDTH="0" SRC="$PHP_SELF?key=about" NAME="main" scrolling=auto NORESIZE>
  </FRAMESET>
</HTML>
EOD;
endif;

if($key == "menu"):
/**
*
* $MenuOn                      定义分类菜单数目
* $MenuBackColor               定义分类菜单背景颜色
* $MenuFontSize                定义分类菜单字体
* $MenuBarHeight               定义分类菜单高度
* $ItemTextColor               定义分类菜单项目文字颜色
* $ItemBackColor               定义分类菜单项目背景颜色
* $TopMenuHeight               定义分类菜单与顶部的间距
* $SelectedItemDarkBorder      定义分类菜单项目在鼠标移动到上面时的暗边框颜色
* $SelectedItemLightBorder     定义分类菜单项目在鼠标移动到上面时的亮边框颜色
* $SelectedItemBackgroundColor 定义分类菜单项目在鼠标移动到上面时的背景颜色
* $menuSubSectionBackColor     定义二级菜单背景颜色
* $menuSubSectionFontColor     定义二级菜单菜单字体颜色
* $defTarget                   定义菜单项目超连接默认目标框架
*/
$TopMenuHeight = 0;           //设置分类菜单与顶部的间距
$MenuBarHeight = 20;          //设置分类菜单高度
$MenuFontSize = "9pt";            //设置菜单字体大小

//我们使用仿Office XP风格的外观,也可以使用普通外观。
$menu_mode = false;

if($menu_mode) {
  //普通菜单外观
  $MenuBackColor = "lightgrey";             //设置背景颜色
  $ItemBackColor = "#7f7f7f";               //设置菜单项目背景色
  $ItemTextColor = "#ffffff";               //设置菜单项目文字颜色
  $SelectedItemDarkBorder = "#ffffff";      //设置菜单项目在鼠标移动到上面时的暗边框颜色
  $SelectedItemLightBorder = "#000000";     //设置菜单项目在鼠标移动到上面时的亮边框颜色
  $SelectedItemBackgroundColor = "";        //设置菜单项目在鼠标移动到上面时的背景颜色
  $menuSubSectionBackColor = "lightgrey";   //设置二级菜单背景颜色
  $menuSubSectionFontColor="black";          //设置二级菜单字体颜色
}else {
  //仿Office XP风格外观
  $MenuBackColor = "lightgrey";             //设置背景颜色
  $ItemBackColor = "lightgrey";             //设置菜单项目背景色
  $ItemTextColor = "#000000";               //设置菜单项目文字颜色
  $SelectedItemDarkBorder = "#08246B";      //设置菜单项目在鼠标移动到上面时的暗边框颜色
  $SelectedItemLightBorder = "#08246B";     //设置菜单项目在鼠标移动到上面时的亮边框颜色
  $SelectedItemBackgroundColor = "#B5BED6"; //设置菜单项目在鼠标移动到上面时的背景颜色
  $menuSubSectionBackColor = "darkgray";    //设置二级菜单背景颜色
  $menuSubSectionFontColor = "black";       //设置二级菜单字体颜色
}
$defTarget = "main";    //设置菜单项目超连接默认目标框架

echo <<<EOD
<style>
td { font-size: $MenuFontSize; font-family:"Verdana", "Arial", "宋体"; }
</style>
<body leftmargin=0 topmargin=0 rightmargin=0 bgcolor="$MenuBackColor">
EOD;

$menuOn = 0;             //对菜单数目初始化

/**
* 绘制菜单方法:
* menuStartSection($Seq, $Label)
*   制作分类菜单
*   $Seq = 分类菜单序列号,使用菜单序列号控制启动是显示顺序
*   $Label = 分类菜单标题
* menuAddItem($Label, $Description, $URL, $Target="")
*   制作菜单项目
*   $Label = 项目标题
*   $Description = 项目简介
*   $URL = 超连接地址
*   $Target = 超连接目标框架,默认为$defTarget
* menuAddSubSection($Label)
*   制作二级分类菜单。
*   $Label = 二级分类菜单标题
* menuAddSubSectionLine()
*   制作项目分割线,使用高度为2的图片
* menuEndSection()
*   分类菜单结束
* menuSectionAsItem($Label, $Description, $URL, $Target="")
*   制作带超连接的分类菜单,类似菜单项目,可以直接使用
*   $Label = 分类菜单标题
*   $Description = 分类菜单简介
*   $URL = 超连接地址
*   $Target = 超连接目标框架,默认为$defTarget
*/

/**
* 函数定义
*/
function menuAddItem($itemLabel, $StatusText, $URL, $target="") {
  global $defTarget,
         $SelectedItemDarkBorder,
         $SelectedItemLightBorder,
         $ItemTextColor,
         $SelectedItemBackgroundColor,
         $MenuFontSize ;
  if($target == "") $target = $defTarget;
  $URL = rawurldecode($URL);
  echo <<<EOD

<tr><td width="100%" align=left style="cursor:hand;" title="$StatusText" onmouseover="this.borderColorDark='$SelectedItemDarkBorder';
this.borderColorLight='$SelectedItemLightBorder';this.style.backgroundColor='$SelectedItemBackgroundColor';
this.style.color='black';status='$StatusText';" onmouseout="this.borderColorDark='';this.borderColorLight='';
this.style.backgroundColor='';status='';" onclick="window.open('$URL','$target');">
<font color="$ItemTextColor">$itemLabel</font></td></tr>
EOD;
}

function menuAddSubSection($ItemLabel) {
  global $menuSubSectionBackColor,
         $MenuFontSize,
         $menuSubSectionFontColor;
  echo <<<EOD

<tr bgcolor="$menuSubSectionBackColor"><td align=center width="100%"><font color="$menuSubSectionFontColor">
$ItemLabel</font></td></tr>
EOD;
}

function menuAddSubSectionLine() {
  echo <<<EOD

<tr vAlign="center">
  <td align=center width="100%" height="2" bgcolor="white">
    <table border=0 cellspacing=0 cellpadding=0 width="100%" height="1">
     <tr vAlign="center" height="2">
       <td bgcolor="white"></td>
     </tr>
    </table>
  </td>
</tr>
EOD;
}

function menuSectionAsItem($SectionSeq, $SectionName, $SectionDesc, $URL, $target="") {
  global $defTarget,
         $menuBackColor,
         $MenuBarHeight,
         $MenuFontSize;
  if($target == "") $target = $defTarget;
  $URL = rawurldecode($URL);
  $mh = $MenuBarHeight-2;
  echo <<<EOD

<table border=0 cellspacing=0 cellpadding=0 width="100%" height="1">
<tr vAlign="center" height="1">
  <td bgcolor="white"></td>
</tr>
</table>
<table bgcolor="$menuBackColor" border=1 cellspacing=0 cellpadding=0 bordercolor="$menuBackColor" width="100%" height="Smh">
<tr height="100%" vAlign="center">
  <td border=3 vAlign="middle" width="100%" height="100%" bordercolordark=lightgrey bordercolorlight=lightgrey align=center style="cursor:hand;" title="$SectionDesc" onmouseover="status='$SectionDesc';" onmouseout="status='';" onclick="window.open('$URL','$target');"><font color="#000000">$SectionName</font></td>
</tr>
</table>
<table border=0 cellspacing=0 cellpadding=0 width="100%" height="1">
<tr height="1">
  <td bgcolor="Black"></td>
</tr>
</table>
EOD;
}

function menuStartSection($SectionSeq, $SectionName) {
  global $menuBackColor,
         $MenuBarHeight,
         $MenuFontSize,
         $menuSection,
         $ItemBackColor;
  $mh = $MenuBarHeight-2;
  echo <<<EOD

<table bgcolor="$menuBackColo" border=0 cellspacing=0 cellpadding=0 width="100%" height="1">
<tr height="1">
  <td bgcolor="white"></td>
</tr>
</table>
<table bgcolor="$menuBackColor" border=1 cellspacing=0 cellpadding=0 bordercolor="$menuBackColor" width="100%" height="$mh">
<tr vAlign="center" height="100%">
  <td nowrap border=3 width="100%" height="100%" bordercolordark=lightgrey bordercolorlight=lightgrey align=center style="cursor:hand;" title="$SectionName" onmouseover="status='$SectionName';" onmouseout="status='';" onclick="StartSection(menuSection$SectionSeq);">$SectionName</td>
</tr>
</table>
<table border=0 cellspacing=0 cellpadding=0 width="100%" height="1">
<tr height="1">
  <td bgcolor="Black"></td>
</tr>
</table>
<div name=menuSection$SectionSeq id=menuSection$SectionSeq style="display:'none';overflow:hidden; height:1px;marginRight:0px;">
<table bgcolor=$ItemBackColor style="marginRight=0px;" border=1 cellspacing=0 cellpadding=0 bordercolor="$ItemBackColor" width="100%">
EOD;
}

function menuEndSection() {
  echo <<<EOD

</table>
</div>
EOD;
}

/**
* 创建菜单
*/
  menuStartSection(2, "代码世界");
  menuAddItem("Joy ASP", "欢迎访问Joy ASP", "$PHP_SELF?key=page&id=Joy ASP");
  menuAddItem("Java 世界", "欢迎访问Java 世界", "$PHP_SELF?key=page&id=Java 世界");
  menuAddItem("DotNet 时代", "欢迎访问DotNet 时代", "$PHP_SELF?key=page&id=DotNet 时代");
  menuAddItem("Visual Basic", "欢迎访问Visual Basic", "$PHP_SELF?key=page&id=Visual Basic");
  menuAddItem("Delphi", "欢迎访问Delphi", "$PHP_SELF?key=page&id=Delphi");
  menuEndSection();

  menuStartSection(3, "开心一刻");
  menuAddItem("传统笑话", "传统笑话", "$PHP_SELF?key=page&id=传统笑话");
  menuAddItem("近代笑话", "近代笑话", "$PHP_SELF?key=page&id=近代笑话");
  menuAddSubSection("儿童类");
  menuAddItem("校园笑话", "校园笑话", "$PHP_SELF?key=page&id=校园笑话");
  menuAddItem("幼儿笑话", "幼儿笑话", "$PHP_SELF?key=page&id=幼儿笑话");
  menuAddItem("少年笑话", "少年笑话", "$PHP_SELF?key=page&id=少年笑话");
  menuAddSubSectionLine();
  menuAddItem("中学时代笑话", "中学时代笑话", "$PHP_SELF?key=page&id=中学时代笑话");
  menuAddSubSection("成人笑话");
  menuAddItem("带颜色的笑话", "带颜色的笑话", "$PHP_SELF?key=page&id=带颜色的笑话");
  menuAddItem("笑话林", "笑话林", "$PHP_SELF?key=page&id=笑话林");
  menuEndSection();

  menuSectionAsItem(3, "菜单简介", "菜单简介", "$PHP_SELF?key=about");

  menuStartSection(1, "个人收藏夹");
  menuAddItem("DotNet 时代", "欢迎访问DotNet 时代", "$PHP_SELF?key=page&id=DotNet 时代");
  menuEndSection();

  // 将个人收藏夹定为启动菜单
  $menuOn = 4;

/**
* 输出javascript脚本
*/
echo <<<EOD

<script language=javascript>
var AvailHeight       // 定义可利用的高度
var LastSection       // 定义将要打开的菜单关闭
var ThisSection       // 定义当前需要打开的菜单
var timerDelay=15     // 定义并设置延时
var menuActive=false  // 测定当前活动的菜单
var VisibleHeight     // 定义显示高度,确定是否显示滚动条
var AniRatio          // 定义菜单显示滑动的速度

function getSizing() {
  // 菜单打开时得到的可利用的高度
  AvailHeight=document.body.clientHeight-$TopMenuHeight-($MenuBarHeight*$menuOn)
  if(AvailHeight<=0) {
    LastSection.style.display='none';
  }else {
    // 改变菜单显示滑动速度的比率
    AniRatio=0.75;                          // 设定速度
    if(AvailHeight>200) {AniRatio=0.667;}  
    if(AvailHeight>500) {AniRatio=0.5;}    // 根据可利用高度调整速度
    LastSection.style.height=AvailHeight;
    LastSection.style.overflow='visible';
    LastSection.style.display='';
    VisibleHeight=parseInt(LastSection.clientHeight);
    if(VisibleHeight>AvailHeight) {LastSection.style.overflow='auto';}else{LastSection.style.overflow='hidden';};
  }
}

function slideMenu() {
  // 菜单滑动函数
  if(parseInt(LastSection.style.height)>1) {
    LastSection.style.height=parseInt(parseInt(LastSection.style.height)*AniRatio);
    ThisSection.style.height=AvailHeight-parseInt(LastSection.style.height);
    var movetimer=setTimeout("slideMenu()",timerDelay)  ;
  }else {
    // 完成菜单滑动,显示新打开的菜单,隐藏前面以打开的菜单
    LastSection.style.display='none';
    ThisSection.style.height=AvailHeight;
    menuActive=false;
    if (VisibleHeight>AvailHeight) {ThisSection.style.overflow='auto';};
    ThisSection.style.marginRight=0;
    LastSection=ThisSection;
    clearTimeout(movetimer);
  }
}

function StartSection(theSection) {
  // 开始滑动菜单,检测是否对菜单进行单击
  if(menuActive==false) {
    if(LastSection!=theSection) {
      menuActive=true;
      ThisSection=theSection;
      LastSection.style.overflow='hidden';
      ThisSection.style.overflow='visible';
      ThisSection.style.display='';
      VisibleHeight=parseInt(ThisSection.clientHeight);
      ThisSection.style.overflow='hidden';
      ThisSection.style.display='none';
      ThisSection.style.height=1;
      LastSection.style.height=AvailHeight-1;
      LastSection.style.display='';
      ThisSection.style.display='';
      slideMenu()
    }
  }
}

window.onresize=getSizing
// 启动时打开默认的序号为第一个的菜单
LastSection=document.all.menuSection1;
LastSection.style.display='';
getSizing();
</script>
</body>
EOD;

endif;


if($key == "page"):
echo <<<EOD
<style>
body { font-size: 9pt; font-family:"Verdana", "Arial", "宋体"; }
</style>
<body>
<center>
<br>
<br>
欢迎访问 $id
</center>
</body>
EOD;
endif;

if($key == "about"):
echo <<<EOD
<style>
body { font-size: 9pt; font-family:"Verdana", "Arial", "宋体"; }
</style>
<body>
<center>
<br>
<br>
关于此菜单
<br>
<br>
说明,此菜单程序只能使用在IE 5以上的版本使用,NetSpace下不能使用,推荐使用IE 6正式中文版
</center>
</body>
EOD;
endif;
?>

原文转自:http://www.ltesting.net