contextMenu.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. function contextMenu() {
  2. this.items = new Array();
  3. this.addItem = function(item) {
  4. this.items[this.items.length] = item;
  5. }
  6. this.show = function(oDoc) {
  7. var strShow = "";
  8. var i;
  9. strShow = "<div id=\"rightmenu\" style=\"BACKGROUND-COLOR: #ffffff; BORDER: #000000 1px solid; LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: hidden; Z-INDEX: 10\">";
  10. strShow += "<table border=\"0\" height=\"";
  11. strShow += this.items.length * 20;
  12. strShow += "\" cellpadding=\"0\" cellspacing=\"0\">";
  13. strShow += "<tr height=\"3\"><td bgcolor=\"#d0d0ce\" width=\"2\"></td><td>";
  14. strShow += "<table border=\"0\" width=\"100%\" height=\"100%\" cellpadding=0 cellspacing=0 bgcolor=\"#ffffff\">";
  15. strShow += "<tr><td bgcolor=\"#d0d0ce\" width=\"23\"></td><td><img src=\" \" height=\"1\" border=\"0\"></td></tr></table>";
  16. strShow += "</td><td width=\"2\"></td></tr>";
  17. strShow += "<tr><td bgcolor=\"#d0d0ce\"></td><td nowrap>";
  18. strShow += "<table border=\"0\" width=\"100%\" class=tablemenu height=\"100%\" cellpadding=3 cellspacing=0 bgcolor=\"#ffffff\">";
  19. oDoc.write(strShow);
  20. for (i = 0; i < this.items.length; i++) {
  21. this.items[i].show(oDoc);
  22. }
  23. strShow = "</table></td><td></td></tr>";
  24. strShow += "<tr height=\"3\"><td bgcolor=\"#d0d0ce\"></td><td>";
  25. strShow += "<table border=\"0\" width=\"100%\" height=\"100%\" cellpadding=0 cellspacing=0 bgcolor=\"#ffffff\">";
  26. strShow += "<tr><td bgcolor=\"#d0d0ce\" width=\"23\"></td><td><img src=\" \" height=\"1\" border=\"0\"></td></tr></table>";
  27. strShow += "</td><td></td></tr>";
  28. strShow += "</table></div>\n";
  29. oDoc.write(strShow);
  30. }
  31. }
  32. // menu Item object
  33. /*
  34. * text ���˵��������� icon ���˵�ǰ���ͼƬ cmd �����õ�JS���� type ��menu �˵�
  35. * separator �ָ���
  36. */
  37. function contextItem(text, icon, cmd, type) {
  38. this.text = text ? text : "";
  39. this.icon = icon ? icon : "";
  40. this.cmd = cmd ? cmd : "";
  41. this.type = type ? type : "menu";
  42. this.show = function(oDoc) {
  43. var strShow = "";
  44. if (this.type == "menu") {
  45. strShow += "<tr ";
  46. strShow += "onmouseover=\"changeStyle(this, 'on');\" ";
  47. strShow += "onmouseout=\"changeStyle(this, 'out');\" ";
  48. strShow += "onclick=\"";
  49. strShow += this.cmd;
  50. strShow += "\">";
  51. strShow += "<td class=\"ltdexitmenu\" width=\"16\">";
  52. if (this.icon == "")
  53. strShow += "&nbsp;";
  54. else {
  55. strShow += "<img border=\"0\" src=\"";
  56. strShow += this.icon;
  57. strShow += "\" width=\"16\" height=\"16\" style=\"POSITION: relative\"></img>";
  58. }
  59. strShow += "</td><td class=\"mtdexitmenu\" nowrap> ";
  60. strShow += this.text;
  61. strShow += "</td><td class=\"rtdexitmenu\" width=\"5\">&nbsp;</td></tr>";
  62. } else if (this.type == "separator") {
  63. strShow += "<tr><td class=\"ltdexitmenu\">&nbsp;</td>";
  64. strShow += "<td class=\"mtdexitmenu\" colspan=\"2\"><hr color=\"#000000\" size=\"1\"></td></tr>";
  65. }
  66. oDoc.write(strShow);
  67. }
  68. }
  69. function changeStyle(obj, cmd) {
  70. if (obj)
  71. try {
  72. var imgObj = obj.children(0).children(0);
  73. if (cmd == 'on') {
  74. obj.children(0).className = "ltdfocusmenu";
  75. obj.children(1).className = "mtdfocusmenu";
  76. obj.children(2).className = "rtdfocusmenu";
  77. if (imgObj) {
  78. if (imgObj.tagName.toUpperCase() == "IMG") {
  79. imgObj.style.left = "-1px";
  80. imgObj.style.top = "-1px";
  81. }
  82. }
  83. } else if (cmd == 'out') {
  84. obj.children(0).className = "ltdexitmenu";
  85. obj.children(1).className = "mtdexitmenu";
  86. obj.children(2).className = "rtdexitmenu";
  87. if (imgObj) {
  88. if (imgObj.tagName.toUpperCase() == "IMG") {
  89. imgObj.style.left = "0px";
  90. imgObj.style.top = "0px";
  91. }
  92. }
  93. }
  94. } catch (e) {
  95. }
  96. }
  97. function rightUp(obj) {
  98. selectTdObj = obj;
  99. var x, y, w, h, ox, oy;
  100. x = event.clientX;
  101. y = event.clientY;
  102. var obj = document.getElementById("rightmenu");
  103. if (obj == null)
  104. return true;
  105. ox = document.body.clientWidth;
  106. oy = document.body.clientHeight;
  107. if (x > ox || y > oy)
  108. return false;
  109. w = obj.offsetWidth;
  110. h = obj.offsetHeight;
  111. if ((x + w) > ox)
  112. x = x - w;
  113. if ((y + h) > oy)
  114. y = y - h;
  115. obj.style.posLeft = x + document.body.scrollLeft;
  116. obj.style.posTop = y + document.body.scrollTop;
  117. obj.style.visibility = "visible";
  118. return false;
  119. }
  120. function hideMenu() {
  121. if (event.button == 0) {
  122. var obj = document.getElementById("rightmenu");
  123. if (obj == null)
  124. return true;
  125. obj.style.visibility = "hidden";
  126. obj.style.posLeft = 0;
  127. obj.style.posTop = 0;
  128. }
  129. }
  130. function toggleMenu(isEnable) {
  131. if (isEnable)
  132. document.oncontextmenu = showMenu;
  133. else
  134. document.oncontextmenu = new function() {
  135. return true;
  136. };
  137. }
  138. function tdchangeStyle(obj, cmd) {
  139. if (obj)
  140. try {
  141. if (cmd == 'on') {
  142. obj.className = "tdfocus";
  143. } else if (cmd == 'out') {
  144. obj.className = "";
  145. }
  146. } catch (e) {
  147. }
  148. }
  149. function inputbtchangeStyle(obj, cmd) {
  150. if (obj)
  151. try {
  152. if (cmd == 'on') {
  153. obj.className = "tdfocus";
  154. } else if (cmd == 'out') {
  155. obj.className = "button";
  156. }
  157. } catch (e) {
  158. }
  159. }
  160. function imgbtchangeStyle(obj, cmd) {
  161. if (obj)
  162. try {
  163. if (cmd == 'on') {
  164. obj.className = "tdfocus";
  165. } else if (cmd == 'out') {
  166. obj.className = "";
  167. }
  168. } catch (e) {
  169. }
  170. }