国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

context_menu.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. *
  3. * @version $Id: context_menu.js 1 22:28 2010年7月20日Z tianya $
  4. * @package DedeCMS.Administrator
  5. * @copyright Copyright (c) 2007 - 2020, DesDev, Inc.
  6. * @license http://help.dedecms.com/usersguide/license.html
  7. * @link http://www.dedecms.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.clientX; y = eobj.clientY;
  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. {
  121. return function () {
  122. win.WebFX_PopUpcss.style.display='none'
  123. if (typeof(f)=="function"){ f(); }
  124. };
  125. })(arr[i].action);
  126. tmpobj.onmouseover = function(){this.className="WebFX-ContextMenu-Over"}
  127. tmpobj.onmouseout = function(){this.className="WebFX-ContextMenu-Item"}
  128. }
  129. doc.body.appendChild(tmpobj);
  130. }else{
  131. doc.body.appendChild(doc.createElement("DIV")).className = "WebFX-ContextMenu-Separator";
  132. }
  133. }
  134. doc.body.className = "WebFX-ContextMenu-Body" ;
  135. doc.body.onselectstart = function(){return false;}
  136. }
  137. function ContextItem(str,fnc,disabled){
  138. this.text = str;
  139. this.action = fnc;
  140. this.disabled = disabled || false;
  141. }