chinese_menu.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. // Javascript Menu Copyright (C) 2001, 2002 Min Qiang Zhao (Kent)
  2. var agt=navigator.userAgent.toLowerCase();
  3. var is_major = parseInt(navigator.appVersion);
  4. var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
  5. && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
  6. && (agt.indexOf('webtv')==-1));
  7. var is_ie = (agt.indexOf("msie") != -1);
  8. var is_nav5up = (is_nav && (is_major >= 5));
  9. function createCSS(){
  10. var h=0, w=0, counter =0, layerid, top = 1, left = 1, color, topAbsolute, leftAbsolute;
  11. document.write("<style>");
  12. document.write("#background {position: absolute; top: 120px; left: 0px; width: 600px; height: 500px; clip: rect(0px 1000px 500px 0px);}");
  13. h = calHeight(root);
  14. w = rootW + 2;
  15. writeCSS("rootB", menuTop, menuLeft, w, h, menuBodercolor, 0);
  16. w = w -2;
  17. for (x=0; x<root.length; x+=7){
  18. eval("layerid = 'rootI" + counter + "';");
  19. if (root[x+2]==0)
  20. h = menuHeight;
  21. else
  22. h = root[x+2];
  23. if (root[x+3]==0)
  24. color = menuBGcolor;
  25. else
  26. color = root[x+3];
  27. writeCSS(layerid, top, left, w, h, color, 0);
  28. if (root[x+5] == 1){
  29. topAbsolute = menuTop + top - 1;
  30. leftAbsolute = menuLeft + rootW + menuIndent;
  31. createSubCSS(eval("'roots" + counter + "'"), topAbsolute, leftAbsolute);
  32. }
  33. top += h + 1;
  34. counter++;
  35. }
  36. document.write(".text {font-size:11px; font-family:Verdona, Arial; text-decoration:none; color:navy; layer-background-color:transparent; background-color:transparent;}");
  37. document.write("</style>");
  38. }
  39. function createSubCSS(name, t, l){
  40. var h=0, w=0, counter =0, layerid, top = 1, left = 1, color, topAbsolute, leftAbsolute, arrayLength;
  41. var menuName = eval(name);
  42. w = eval(name + "W") + 2;
  43. h = calHeight(menuName);
  44. writeCSS((name + "B"), t, l, w, h, menuBodercolor, 2);
  45. w = w -2;
  46. eval("arrayLength = " + name + ".length;");
  47. var x1 = 0;
  48. for (x1=0; x1<arrayLength; x1+=7){
  49. eval("layerid = '" + name + "I" + counter + "';");
  50. if (menuName[x1+2]==0)
  51. h = menuHeight;
  52. else
  53. h = menuName[x1+2];
  54. if (menuName[x1+3]==0)
  55. color = menuBGcolor;
  56. else
  57. color = menuName[x1+3];
  58. writeCSS(layerid, top, left, w, h, color, 1);
  59. if (menuName[x1+5] == 1){
  60. topAbsolute = t + top -1;
  61. leftAbsolute = l + w + menuIndent;
  62. createSubCSS(eval("'" + name + "s" + counter + "';"), topAbsolute, leftAbsolute);
  63. }
  64. top += h +1;
  65. counter++;
  66. }
  67. return;
  68. }
  69. function calHeight(menuName){
  70. var total = 0;
  71. for (x2=0; x2<menuName.length; x2+=7){
  72. if (menuName[x2+2] == 0)
  73. total += menuHeight;
  74. else
  75. total += menuName[x2+2];
  76. }
  77. total += menuName.length/7 + 1;
  78. return total;
  79. }
  80. var V = new Array("visible", "inherit", "hidden");
  81. function writeCSS(layerid, top, left, width, height, color, index){
  82. document.write("#" + layerid + " {position: absolute; top:"+ top+ "px; left: "+ left + "px; width:" + width + "px; height:" + height + "px; clip:rect(0px " + width + "px " + height + "px 0px); layer-background-color:" + color + "; background-color: " + color + "; visibility: " + V[index]+ ";}\n");
  83. }
  84. function writeDiv(){
  85. var layerN, link, counter=0, childrenID;
  86. document.write("<div id='background'>&nbsp;</div>");
  87. var Main = new CreateLayer("background", "");
  88. Main.layer.onmouseover = HideAll;
  89. for (x=0; x<rootDiv.length; x++){
  90. document.write("<div id='" + rootDiv[x] + "B'>\n");
  91. makeLayerID(eval("'" + rootDiv[x]+ "B'"), "", "", "", -1);
  92. counter = 0;
  93. var menuName = eval(rootDiv[x]);
  94. for (y=0; y<menuName.length; y+=7){
  95. layerN = rootDiv[x] + "I" + eval("'" + counter + "'");
  96. if (menuName[y+1] != "")
  97. link = "href='" + menuName[y+1] + "'";
  98. document.write("<div id='" + layerN + "'><a "+ link +"class='text'>&nbsp;&nbsp;" + menuName[y] + "</a></div>\n");
  99. makeLayerID(layerN, eval("'" + rootDiv[x] + "B'"), menuName, y, 0);
  100. counter++;
  101. link = "";
  102. }
  103. document.write("</div>\n\n");
  104. }
  105. createLayerInfoID();
  106. }
  107. var layerID;
  108. function makeLayerID(id, rootid, menuName, index, isNotBGlayer) { // -1: no subroot (hasSubroot)
  109. layerID = "L" + id;
  110. eval(layerID + "= new CreateLayer('" + id + "','" + rootid + "');");
  111. if (isNotBGlayer != -1){
  112. var LID = eval(layerID);
  113. LID.id = "L" + id;
  114. LID.layerInfo = menuName[index+6];
  115. if (menuName[index+3] != 0)
  116. LID.BGcolor = menuName[index+3];
  117. else
  118. LID.BGcolor = menuBGcolor;
  119. if (menuName[index+4] != 0)
  120. LID.OBGcolor = menuName[index+4];
  121. else
  122. LID.OBGcolor = menuOBGcolor;
  123. if (menuName[index+5] == 1)
  124. LID.children = "L" + rootid.split("B")[0] + "s" + eval("'"+(index/7)+"'") + "B";
  125. else
  126. LID.children = 0;
  127. var level = LID.id.split("s");
  128. LID.level = level.length - 1;
  129. // 0 => onmouseout 1 => onmouseover
  130. LID.layer.onmouseover = new Function("ChangeColor('" + LID.id + "', 1)");
  131. LID.layer.onmouseout = new Function("ChangeColor('" + LID.id + "', 0)");
  132. }
  133. }
  134. var bgC = ".backgroundColor";
  135. if (is_nav && !is_nav5up)
  136. bgC = ".document.bgColor";
  137. function ChangeColor(id, type){
  138. var layerID = eval(id);
  139. if (type == 1){
  140. eval("layerID.css" + bgC + "='" + layerID.OBGcolor + "';");
  141. HideShowLayer(layerID, 1);
  142. }
  143. else{
  144. eval("layerID.css" + bgC + "='" + layerID.BGcolor + "';");
  145. HideShowLayer(layerID, 0);
  146. }
  147. }
  148. var track = new Array();
  149. for (x= 0; x<menuLevel-1; x++){
  150. track[x] = "";
  151. }
  152. var layerInfo = "";
  153. function HideShowLayer(layerID, l){
  154. hideCondition = false;
  155. if (l == 1)
  156. hidePower = false;
  157. else
  158. hidePower = true;
  159. for (x=menuLevel-2; x>=layerID.level; x--){
  160. if (track[x] != "")
  161. eval(track[x] + ".css.visibility = 'hidden'");
  162. }
  163. if (layerID.children != 0){
  164. eval(layerID.children + ".css.visibility = 'visible'");
  165. track[layerID.level] = layerID.children;
  166. }
  167. if (layerID.layerInfo != 0 && l == 1 && layerID.layerInfo != layerInfo){
  168. if (layerInfo != "")
  169. eval("L" + layerInfo + ".css.visibility = 'hidden'");
  170. eval("L" + layerID.layerInfo + ".css.visibility = 'visible'");
  171. layerInfo = layerID.layerInfo;
  172. }
  173. }
  174. var hideCondition = false;
  175. var hidePower = true;
  176. var IDset = false;
  177. function HideAll(){
  178. if (hidePower == true){
  179. if (hideCondition == true){
  180. for (x=menuLevel-2; x>=0; x--){
  181. if (track[x] != "")
  182. eval(track[x] + ".css.visibility = 'hidden'");
  183. }
  184. if (IDset == true){
  185. clearInterval(hideID);
  186. IDset = false;
  187. }
  188. hideCondition = false;
  189. }
  190. else{
  191. hideCondition = true;
  192. if (IDset == false){
  193. hideID = setInterval("HideAll()", menuHideSpeed);
  194. IDset = true;
  195. }
  196. }
  197. }
  198. }
  199. function CreateLayer(id, rootid) {
  200. if (is_nav5up) {
  201. this.layer = document.getElementById(id);
  202. this.css = this.layer.style;
  203. }
  204. if (is_nav && !is_nav5up){
  205. if (rootid != "")
  206. this.layer = document.layers[rootid].document.layers[id];
  207. else
  208. this.layer = document.layers[id];
  209. this.css = this.layer;
  210. }
  211. if (is_ie) {
  212. this.layer = document.all[id];
  213. this.css = document.all[id].style;
  214. }
  215. }
  216. function writeCSSLayerInfo(name){
  217. document.write("#" + name + "{position: absolute; top:" + LayerInfoTop + "; left:" + LayerInfoLeft + "; visibility: hidden;}");
  218. }
  219. function createLayerInfoID(){
  220. if (LayerInfoDiv[0] != ""){
  221. for (x=0; x<LayerInfoDiv.length; x++)
  222. eval("L" + LayerInfoDiv[x] + "= new CreateLayer('" + LayerInfoDiv[x] + "', '');");
  223. }
  224. }