076a1bd387e46bcd2f2ae359b22913239aab2dff.svn-base 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright DHTMLX LTD. http://www.dhtmlx.com You allowed to use this component
  3. * or parts of it under GPL terms To use it on other terms or get Professional
  4. * edition of the component please contact us at sales@dhtmlx.com
  5. */
  6. function dhtmlXContextMenuObject(width, height, gfxPath, httpsdummy) {
  7. this.menu = new dhtmlXMenuBarObject(document.body, width, height, "", 1,
  8. gfxPath, httpsdummy);
  9. this.menu.setMenuMode("popup");
  10. this.menu.hideBar();
  11. this.menu.contextMenu = this;
  12. this.menu.enableWindowOpenMode(false);
  13. this.menu.setOnClickHandler(this._innerOnClick);
  14. this.aframes = new Array();
  15. this.registerFrame(window);
  16. return this
  17. };
  18. dhtmlXContextMenuObject.prototype.registerFrame = function(awin) {
  19. this.aframes[this.aframes.length] = awin
  20. };
  21. dhtmlXContextMenuObject.prototype.setContextMenuHandler = function(func) {
  22. if (typeof(func) == "function")
  23. this.onClickHandler = func;
  24. else
  25. this.onClickHandler = eval(func)
  26. };
  27. dhtmlXContextMenuObject.prototype.openAt = function(x, y, id, smartPosition) {
  28. this.espc = convertStringToBoolean(smartPosition);
  29. var f = new Object;
  30. f.button = 2;
  31. f.clientX = x;
  32. f.clientY = y;
  33. var start = new Object;
  34. start.contextMenuId = id;
  35. start.contextMenu = this;
  36. start.a = this._contextStart;
  37. start.a(document.body, f);
  38. this.espc = null
  39. };
  40. dhtmlXContextMenuObject.prototype.disableMenu = function(mode) {
  41. this._dsbd = convertStringToBoolean(mode)
  42. };
  43. dhtmlXContextMenuObject.prototype.setOnShowMenuHandler = function(func) {
  44. if (typeof(func) == "function")
  45. this.onShowHandler = func;
  46. else
  47. this.onShowHandler = eval(func)
  48. };
  49. dhtmlXContextMenuObject.prototype.setContextMenuPosition = function(left, top) {
  50. this._msTop = parseInt(top);
  51. this._msLeft = parseInt(left)
  52. };
  53. dhtmlXContextMenuObject.prototype._innerOnClick = function(id) {
  54. var that = document.body.contextMenu;
  55. if (that.contextZone.ownerDocument) {
  56. if (that.contextZone.ownerDocument.body.onclick)
  57. that.contextZone.ownerDocument.body.onclick()
  58. } else if (document.body.onclick)
  59. document.body.onclick();
  60. if (that.onClickHandler)
  61. return that.onClickHandler(id, that.zoneId, that.contextZone);
  62. return true
  63. };
  64. dhtmlXContextMenuObject.prototype.setContextZone = function(htmlObject, zoneId) {
  65. if (typeof(htmlObject) != "object")
  66. htmlObject = document.getElementById(htmlObject);
  67. if (!htmlObject.contextMenu)
  68. htmlObject.contextOnclick = htmlObject.onmouseup;
  69. htmlObject.selfobj = this;
  70. htmlObject[_isMacOS ? "oncontextmenu" : "onmouseup"] = function(e) {
  71. this.selfobj._contextStart(this, e)
  72. };
  73. htmlObject.contextMenu = this;
  74. htmlObject.contextMenuId = zoneId
  75. };
  76. dhtmlXContextMenuObject.prototype._contextStart = function(obj, e) {
  77. if ((_isIE) && (window.event))
  78. event.srcElement.oncontextmenu = function() {
  79. event.cancelBubble = true;
  80. return false
  81. };
  82. if (e && e.preventDefault)
  83. e.preventDefault();
  84. if (!this.contextMenu)
  85. this.contextMenu = this;
  86. var win = obj.ownerDocument ? obj.ownerDocument.parentWindow : window;
  87. if (!win) {
  88. win = obj.ownerDocument.defaultView
  89. };
  90. var a = this.contextMenu.menu.topNod;
  91. a.style.position = "absolute";
  92. if (!e) {
  93. e = win.event
  94. };
  95. if (document.body.onclick)
  96. document.body.onclick();
  97. if ((!_isMacOS) && ((!e) || (e.button != 2))) {
  98. if (obj.contextOnclick)
  99. obj.contextOnclick();
  100. return true
  101. } else {
  102. if (this.contextMenu._dsbd)
  103. return true;
  104. if (this.contextMenu.onShowHandler) {
  105. var z = this.contextMenu.onShowHandler(obj.contextMenuId);
  106. if ((typeof(z) == "boolean") && (!z))
  107. return
  108. };
  109. this.contextMenu.menu.showBar()
  110. };
  111. var winScreenTop = window.screenTop;
  112. if ((!winScreenTop) && (winScreenTop != 0)) {
  113. winScreenTop = window.screenY + window.outerHeight - window.innerHeight
  114. };
  115. var winScreenLeft = window.screenLeft;
  116. if ((!winScreenLeft) && (winScreenLeft != 0)) {
  117. winScreenLeft = window.screenX + window.outerWidth - window.innerWidth
  118. - 4
  119. };
  120. var dEl0 = window.document.documentElement;
  121. var dEl1 = window.document.body;
  122. if (e.screenY - winScreenTop + a.offsetHeight
  123. - (dEl0.scrollTop || dEl1.scrollTop) > (dEl0.clientHeight || dEl1.clientHeight)) {
  124. var verCor = a.offsetHeight
  125. } else
  126. var verCor = ((this.contextMenu._msTop * (-1)) || 0);
  127. var corrector = new Array((dEl0.scrollLeft || dEl1.scrollLeft)
  128. + (this.contextMenu._msLeft || 0), verCor
  129. - (dEl0.scrollTop || dEl1.scrollTop));
  130. if ((!e.screenY) && (e.clientX)) {
  131. a.style.top = e.clientY + "px";
  132. a.style.left = e.clientX + "px"
  133. } else {
  134. a.style.top = e.screenY - winScreenTop - corrector[1] + "px";
  135. a.style.left = e.screenX - winScreenLeft + corrector[0] + "px"
  136. };
  137. if (!_isIE) {
  138. a.style.top = e.clientY - corrector[1] + "px";
  139. a.style.left = e.clientX + corrector[0] + "px"
  140. };
  141. this.contextMenu.correctMenuPosition(a);
  142. if (a.ieFix) {
  143. a.ieFix.style.top = a.style.top;
  144. a.ieFix.style.left = a.style.left
  145. };
  146. win.document.body.oncontextmenu = new Function("document.body.oncontextmenu=new Function('if (document.body.onclick)document.body.onclick();return false;');return false;");
  147. for (var i = 0; i < this.contextMenu.aframes.length; i++) {
  148. if (this.contextMenu.aframes[i].document)
  149. this.contextMenu.aframes[i].document.body.selfobj = this;
  150. this.contextMenu.aframes[i].document.body.onclick = function(e) {
  151. this.selfobj.contextMenu._contextEnd(e)
  152. }
  153. };
  154. document.body.contextMenu = this.contextMenu;
  155. this.contextMenu.contextZone = obj;
  156. this.contextMenu.zoneId = obj.contextMenuId;
  157. return false
  158. };
  159. dhtmlXContextMenuObject.prototype.correctMenuPosition = function(panel, mode) {
  160. var xs = document.body.offsetWidth + document.body.scrollLeft;
  161. var ys = document.body.offsetHeight - 15 + document.body.scrollTop;
  162. if ((panel.offsetWidth + parseInt(panel.style.left)) > xs) {
  163. var z = parseInt(panel.style.left) - panel.offsetWidth;
  164. if ((z < 0) || (this.espc))
  165. z = xs - panel.offsetWidth;
  166. if (z < 0)
  167. z = 0;
  168. panel.style.left = z + "px";
  169. if (panel.ieFix)
  170. panel.ieFix.style.left = z + "px"
  171. };
  172. if ((panel.offsetHeight + parseInt(panel.style.top)) > ys) {
  173. var z = parseInt(panel.style.top) - panel.offsetHeight;
  174. if ((z < 0) || (this.espc))
  175. z = ys - panel.offsetHeight;
  176. if (z < 0)
  177. z = 0;
  178. panel.style.top = z + "px";
  179. if (panel.ieFix)
  180. panel.ieFix.style.top = z + "px"
  181. };
  182. if (!mode)
  183. this.correctMenuPosition(panel, 1)
  184. };
  185. dhtmlXMenuBarObject.prototype.correctMenuPosition = dhtmlXContextMenuObject.prototype.correctMenuPosition;
  186. dhtmlXContextMenuObject.prototype._contextEnd = function(e) {
  187. var menu = this.menu;
  188. menu._closePanel(menu);
  189. menu.lastOpenedPanel = "";
  190. menu.lastSelectedItem = 0;
  191. menu.hideBar();
  192. for (var i = 0; i < this.aframes.length; i++)
  193. if (this.aframes[i].document) {
  194. this.aframes[i].document.body.onclick = null;
  195. this.aframes[i].document.body.oncontextmenu = null
  196. };
  197. return false
  198. };
  199. /*
  200. * Copyright DHTMLX LTD. http://www.dhtmlx.com You allowed to use this component
  201. * or parts of it under GPL terms To use it on other terms or get Professional
  202. * edition of the component please contact us at sales@dhtmlx.com
  203. */