国内流行的内容管理系统(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.

169 lines
5.5KB

  1. /**
  2. *
  3. * @version $Id: context_menu.js 1 22:28 2010年7月20日Z tianya $
  4. * @package DedeBIZ.Administrator
  5. * @copyright Copyright (c) 2020, 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. //window.pageXOffset and window.pageYOffset for moz
  66. }
  67. ContextMenu.getScrollLeft = function () {
  68. return document.body.scrollLeft;
  69. }
  70. ContextMenu.fixPos = function (x, y) {
  71. /*var docheight,docwidth,dh,dw;
  72. if(!x) { x=0; y=0; }
  73. docheight = document.body.clientHeight;
  74. docwidth = document.body.clientWidth;
  75. dh = (WebFX_PopUpcss.offsetHeight+y) - docheight;
  76. dw = (WebFX_PopUpcss.offsetWidth+x) - docwidth;
  77. if(dw>0){
  78. WebFX_PopUpcss.style.left = (x - dw) + ContextMenu.getScrollLeft() + "px";
  79. }else {
  80. WebFX_PopUpcss.style.left = x + ContextMenu.getScrollLeft();
  81. } if(dh>0) {
  82. WebFX_PopUpcss.style.top = (y - dh) + ContextMenu.getScrollTop() + "px"
  83. }else{
  84. WebFX_PopUpcss.style.top = y + ContextMenu.getScrollTop(); }*/
  85. WebFX_PopUpcss.style.top = y + "px";
  86. WebFX_PopUpcss.style.left = x + "px";
  87. }
  88. ContextMenu.fixSize = function () {
  89. WebFX_PopUpcss.style.height = (ItemHeight * ItemNember + 20) + "px";
  90. WebFX_PopUpcss.style.width = MenuWidth + "px";
  91. ItemNember = 0;
  92. }
  93. ContextMenu.populatePopup = function (arr, win) {
  94. var alen, i, tmpobj, doc, height, htmstr;
  95. alen = arr.length;
  96. ItemNember = alen;
  97. if (curNav() == 'IE') doc = WebFX_PopUp.document;
  98. else doc = WebFX_PopUp.contentWindow.document;
  99. doc.body.innerHTML = '';
  100. //if (doc.getElementsByTagName("LINK").length == 0){
  101. doc.open();
  102. doc.write('<html><head><link rel="StyleSheet" type="text/css" href="js/contextmenu.css"></head><body></body></html>');
  103. doc.close();
  104. //}
  105. for (i = 0; i < alen; i++) {
  106. if (arr[i].constructor == ContextItem) {
  107. tmpobj = doc.createElement("DIV");
  108. tmpobj.noWrap = true;
  109. tmpobj.className = "WebFX-ContextMenu-Item";
  110. if (arr[i].disabled) {
  111. htmstr = '<span class="WebFX-ContextMenu-DisabledContainer">'
  112. htmstr += arr[i].text + '</span>'
  113. tmpobj.innerHTML = htmstr
  114. tmpobj.className = "WebFX-ContextMenu-Disabled";
  115. tmpobj.onmouseover = function () { this.className = "WebFX-ContextMenu-Disabled-Over" }
  116. tmpobj.onmouseout = function () { this.className = "WebFX-ContextMenu-Disabled" }
  117. } else {
  118. tmpobj.innerHTML = arr[i].text;
  119. tmpobj.onclick = (function (f) {
  120. return function () {
  121. win.WebFX_PopUpcss.style.display = 'none'
  122. if (typeof (f) == "function") { f(); }
  123. };
  124. })(arr[i].action);
  125. tmpobj.onmouseover = function () { this.className = "WebFX-ContextMenu-Over" }
  126. tmpobj.onmouseout = function () { this.className = "WebFX-ContextMenu-Item" }
  127. }
  128. doc.body.appendChild(tmpobj);
  129. } else {
  130. doc.body.appendChild(doc.createElement("DIV")).className = "WebFX-ContextMenu-Separator";
  131. }
  132. }
  133. doc.body.className = "WebFX-ContextMenu-Body";
  134. doc.body.onselectstart = function () { return false; }
  135. }
  136. function ContextItem(str, fnc, disabled) {
  137. this.text = str;
  138. this.action = fnc;
  139. this.disabled = disabled || false;
  140. }