国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.6KB

  1. /**
  2. *
  3. * @version $Id: context_menu.js 1 22:28 2010年7月20日Z tianya $
  4. * @package DedeBIZ.Administrator
  5. * @copyright Copyright (c) 2022, DedeBIZ.COM
  6. * @license https://www.dedebiz.com/license
  7. * @link https://www.dedebiz.com
  8. */
  9. var MenuWidth = 120;
  10. var ItemHeight = 16;
  11. var ItemNumber = 0;
  12. function curNav() {
  13. if (window.navigator.userAgent.indexOf("MSIE") >= 1) return 'IE';
  14. else if (window.navigator.userAgent.indexOf("Firefox") >= 1) return 'FF';
  15. else return 'OT';
  16. }
  17. function insertHtm(op, code, isStart) {
  18. if (curNav() == 'IE') {
  19. op.insertAdjacentHTML(isStart ? "beforeEnd" : "afterEnd", code);
  20. } else {
  21. var range = op.ownerDocument.createRange();
  22. range.setStartBefore(op);
  23. var fragment = range.createContextualFragment(code);
  24. if (isStart) op.insertBefore(fragment, op.firstChild);
  25. else op.appendChild(fragment);
  26. }
  27. }
  28. ContextMenu.WebFX_PopUp = null;
  29. ContextMenu.WbFX_PopUpcss = null;
  30. ContextMenu.intializeContextMenu = function () {
  31. insertHtm(document.body, '<iframe src="#" scrolling="no" class="WebFX-ContextMenu" marginwidth="0" marginheight="0" frameborder="0" style="position:absolute;display:none;z-index:50000000;" id="WebFX_PopUp"></iframe>', true);
  32. if (curNav() == 'IE') WebFX_PopUp = document.frames['WebFX_PopUp'];
  33. else WebFX_PopUp = document.getElementById('WebFX_PopUp');
  34. WebFX_PopUpcss = document.getElementById('WebFX_PopUp');
  35. WebFX_PopUpcss.onfocus = function () { WebFX_PopUpcss.style.display = "inline" };
  36. WebFX_PopUpcss.onblur = function () { WebFX_PopUpcss.style.display = "none" };
  37. if (curNav() == 'IE') document.body.attachEvent("onmousedown", function () { WebFX_PopUpcss.style.display = "none" });
  38. else document.addEventListener("onblur", function () { WebFX_PopUpcss.style.display = "none" }, false);
  39. if (curNav() == 'IE') document.attachEvent("onblur", function () { WebFX_PopUpcss.style.display = "none" });
  40. else document.addEventListener("onblur", function () { WebFX_PopUpcss.style.display = "none" }, false);
  41. }
  42. function ContextSeperator() { }
  43. function ContextMenu() { }
  44. ContextMenu.showPopup = function (x, y) {
  45. WebFX_PopUpcss.style.display = "block"
  46. }
  47. ContextMenu.display = function (evt, popupoptions) {
  48. var eobj, x, y;
  49. eobj = evt ? evt : (window.event ? window.event : null);
  50. if (curNav() == 'IE') {
  51. x = eobj.x; y = eobj.y
  52. } else {
  53. x = eobj.pageX; y = eobj.pageY;
  54. }
  55. ContextMenu.populatePopup(popupoptions, window)
  56. ContextMenu.showPopup(x, y);
  57. ContextMenu.fixSize();
  58. ContextMenu.fixPos(x, y);
  59. eobj.cancelBubble = true;
  60. eobj.returnValue = false;
  61. }
  62. //TODO
  63. ContextMenu.getScrollTop = function () {
  64. return document.body.scrollTop;
  65. }
  66. ContextMenu.getScrollLeft = function () {
  67. return document.body.scrollLeft;
  68. }
  69. ContextMenu.fixPos = function (x, y) {
  70. WebFX_PopUpcss.style.top = y + "px";
  71. WebFX_PopUpcss.style.left = x + "px";
  72. }
  73. ContextMenu.fixSize = function () {
  74. WebFX_PopUpcss.style.height = (ItemHeight * ItemNember + 20) + "px";
  75. WebFX_PopUpcss.style.width = MenuWidth + "px";
  76. ItemNember = 0;
  77. }
  78. ContextMenu.populatePopup = function (arr, win) {
  79. var alen, i, tmpobj, doc, height, htmstr;
  80. alen = arr.length;
  81. ItemNember = alen;
  82. if (curNav() == 'IE') doc = WebFX_PopUp.document;
  83. else doc = WebFX_PopUp.contentWindow.document;
  84. doc.body.innerHTML = '';
  85. doc.open();
  86. doc.write('<html><head><link rel="StyleSheet" href="js/contextmenu.css"></head><body></body></html>');
  87. doc.close();
  88. for (i = 0; i < alen; i++) {
  89. if (arr[i].constructor == ContextItem) {
  90. tmpobj = doc.createElement("DIV");
  91. tmpobj.noWrap = true;
  92. tmpobj.className = "WebFX-ContextMenu-Item";
  93. if (arr[i].disabled) {
  94. htmstr = '<span class="WebFX-ContextMenu-DisabledContainer">'
  95. htmstr += arr[i].text + '</span>'
  96. tmpobj.innerHTML = htmstr
  97. tmpobj.className = "WebFX-ContextMenu-Disabled";
  98. tmpobj.onmouseover = function () { this.className = "WebFX-ContextMenu-Disabled-Over" }
  99. tmpobj.onmouseout = function () { this.className = "WebFX-ContextMenu-Disabled" }
  100. } else {
  101. tmpobj.innerHTML = arr[i].text;
  102. tmpobj.onclick = (function (f) {
  103. return function () {
  104. win.WebFX_PopUpcss.style.display = 'none'
  105. if (typeof (f) == "function") { f(); }
  106. };
  107. })(arr[i].action);
  108. tmpobj.onmouseover = function () { this.className = "WebFX-ContextMenu-Over" }
  109. tmpobj.onmouseout = function () { this.className = "WebFX-ContextMenu-Item" }
  110. }
  111. doc.body.appendChild(tmpobj);
  112. } else {
  113. doc.body.appendChild(doc.createElement("DIV")).className = "WebFX-ContextMenu-Separator";
  114. }
  115. }
  116. doc.body.className = "WebFX-ContextMenu-Body";
  117. doc.body.onselectstart = function () { return false; }
  118. }
  119. function ContextItem(str, fnc, disabled) {
  120. this.text = str;
  121. this.action = fnc;
  122. this.disabled = disabled || false;
  123. }