ContextMenu.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: pps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2017
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. var jtree = false;
  9. var toolbarPopup = false;
  10. var bannerPopDown = false;
  11. var forContextMenu = false;
  12. var ownerFrame = null;
  13. var theDoc = null;
  14. var theWindow = null;
  15. var PP_ContextPopUpcss = null;
  16. var PP_ContextPopUpDoc = null;
  17. var BODY_BORDER_AND_SHADING = 4;
  18. var BANNER_BODY_BORDER_AND_SHADING = 6;
  19. var BANNER_MENU_MIN_WIDTH = 80;
  20. var NETSCAPE_SCROLL_WIDTH = 15;
  21. ContextMenu.initialize = function(skipXtabFrame, skipCreate) {
  22. var id = "PP_ContextPopUp";
  23. if (skipXtabFrame) {
  24. theDoc = document;
  25. theWindow = window;
  26. }
  27. else {
  28. ownerFrame = topparent.frames[window.name];
  29. if (!ownerFrame)
  30. {
  31. if (window.name == "Crosstab")
  32. ownerFrame = topparent.getXtabFrame();
  33. else if (window.name == "Chart")
  34. ownerFrame = topparent.getChartFrame();
  35. }
  36. if (toolbarPopup == true)
  37. {
  38. var actPaneHeight = topparent.document.getElementById("rightFrameset").rows;
  39. actPaneHeight = actPaneHeight.substring(actPaneHeight.indexOf(",") + 1,actPaneHeight.lastIndexOf(","));
  40. ownerFrame = topparent.getXtabFrame();
  41. if(parseInt(actPaneHeight) > 0)
  42. ownerFrame = topparent.getActionFrame();
  43. } else if (bannerPopDown == true) {
  44. ownerFrame = topparent.getXtabFrame();
  45. if (ownerFrame.isSplitDisplay())
  46. ownerFrame = topparent.getChartFrame();
  47. }
  48. if(ownerFrame.window.frames[id] == null)
  49. skipCreate = false;
  50. theDoc = ownerFrame.document;
  51. theWindow = ownerFrame.window;
  52. }
  53. if ( theDoc.getElementById(id).contentWindow )
  54. PP_ContextPopUpDoc = theDoc.getElementById(id).contentWindow.document; // IE, NS
  55. else
  56. PP_ContextPopUpDoc = theDoc.getElementById(id).contentDocument; // W3C, i.e., Safari, NS
  57. PP_ContextPopUpcss = theDoc.getElementById(id);
  58. if (!skipCreate) {
  59. if (!theDoc.body.onmousedown) {
  60. theDoc.body.onmousedown = function(){PP_ContextPopUpcss.style.visibility = "hidden"};
  61. }
  62. if (!theWindow.onmousedown)
  63. theWindow.onmousedown = function(){PP_ContextPopUpcss.style.visibility = "hidden"};
  64. }
  65. ContextMenu.initializeDoc();
  66. }
  67. function ContextMenu(){}
  68. ContextMenu.display=function(event, popupoptions, contextMenu)
  69. {
  70. var eventM = new eventManager(event);
  71. if (!jtree)
  72. ContextMenu.initialize(false,true);
  73. var x,y;
  74. if (eventM.theEvent == null)
  75. return;
  76. if (toolbarPopup) {
  77. var button = eventM.getSrc();
  78. if (button.id.indexOf("menu_") == 0)
  79. x = button.previousSibling.offsetLeft;
  80. else
  81. x = button.offsetLeft;
  82. } else if (bannerPopDown) {
  83. var button = eventM.getSrc();
  84. while (button.tagName != "TD")
  85. button = button.parentNode;
  86. if (button.getAttribute("menubutton") == "true") {
  87. button = button.previousSibling;
  88. }
  89. x = getPageOffsetLeft(button) - topparent.getXtabFrameOffsetLeft();
  90. } else
  91. x = eventM.theEvent.clientX;
  92. if (bannerPopDown)
  93. y = 0;
  94. else if (contextMenu) {
  95. y = eventM.theEvent.clientY;
  96. forContextMenu = true;
  97. }else
  98. y = 1000;
  99. ContextMenu.populatePopup(popupoptions,theWindow);
  100. //Create a wide short context menu first, so we can render and size properly
  101. PP_ContextPopUpcss.style.overflow = "auto";
  102. PP_ContextPopUpcss.style.width = "100%";
  103. PP_ContextPopUpcss.style.height = "0px";
  104. var menuDiv = PP_ContextPopUpDoc.body.firstChild;
  105. menuDiv.style.width = "0px";
  106. menuDiv.style.height = "0px";
  107. menuDiv.style.overflow = "hidden";
  108. //Wait 100 milliseconds to allow the browser to update its presentational information.
  109. setTimeout("ContextMenu.fixSizeAndPosition(" + x + "," + y + ");", 100);
  110. topparent.executeCrossFrameFunction( "hidePopupMenu", theWindow.name, true);
  111. eventM.cancelBubble();
  112. }
  113. ContextMenu.fixSizeAndPosition=function(x,y)
  114. {
  115. if (!isLoadingImages()) {
  116. ContextMenu.fixSize();
  117. //If the action pane is not large enough to hold the flyout, temporarily resize it
  118. if (toolbarPopup)
  119. ContextMenu.resizeActionPane();
  120. ContextMenu.fixPos(x,y);
  121. PP_ContextPopUpcss.style.visibility = 'visible';
  122. } else {
  123. setTimeout("ContextMenu.fixSizeAndPosition(" + x + "," + y + ");", 100);
  124. }
  125. }
  126. ContextMenu.setActionPaneSize=function(x) {
  127. var actPaneHeight = topparent.document.getElementById("rightFrameset").rows;
  128. var rows = actPaneHeight.substring(0,actPaneHeight.indexOf(",") + 1);
  129. rows += x;
  130. rows += actPaneHeight.substring(actPaneHeight.lastIndexOf(","));
  131. topparent.document.getElementById("rightFrameset").rows = rows;
  132. }
  133. ContextMenu.setSplitViewXtabFrameSize=function(x) {
  134. //We can't use a * for the chart size because the browser will sometimes simply
  135. //Set the chart frame to size 0 and hide ths chart alltoghether. So we will attempt to
  136. //Extrapolate a reasonable percentage value.
  137. var splitViewFrameset = topparent.Data.document.getElementById("dataArea");
  138. if (splitViewFrameset && splitViewFrameset.childNodes.length > 1) {
  139. var xtabFrameSize = splitViewFrameset.lastChild.offsetHeight;
  140. var chartFrameSize = splitViewFrameset.firstChild.offsetHeight;
  141. var newChartFrameSize = chartFrameSize - (x - xtabFrameSize); //Adjust the chart framesize.
  142. var newXtabFrameSize = x;
  143. if (newChartFrameSize <= 0) {
  144. newXtabFrameSize -= ((0 - newChartFrameSize) + 10)
  145. newChartFrameSize = 10;
  146. }
  147. topparent.Data.document.getElementById("dataArea").rows = newChartFrameSize + "," + newXtabFrameSize;
  148. }
  149. }
  150. ContextMenu.resizeActionPane=function()
  151. {
  152. var actPaneHeight = topparent.document.getElementById("rightFrameset").rows;
  153. var actionPaneSize = actPaneHeight.substring(actPaneHeight.indexOf(",") + 1,actPaneHeight.lastIndexOf(","));
  154. if (actionPaneSize > 0 && actionPaneSize < PP_ContextPopUpcss.offsetHeight) {
  155. var height = PP_ContextPopUpcss.offsetHeight + 20; //Add 20px for scrollbars
  156. ContextMenu.setActionPaneSize(height);
  157. if (!PP_ContextPopUpDoc.body.getAttribute("APprefferedSize") || !parseInt(PP_ContextPopUpDoc.body.getAttribute("APprefferedSize")))
  158. PP_ContextPopUpDoc.body.setAttribute("APprefferedSize",actionPaneSize);
  159. }
  160. //We may also have to resize the crosstab portion of the split view
  161. var splitViewFrameset = topparent.Data.document.getElementById("dataArea");
  162. if (splitViewFrameset && splitViewFrameset.childNodes.length > 1) {
  163. var xtabFrameSize = splitViewFrameset.lastChild.offsetHeight;
  164. if (xtabFrameSize > 0 && xtabFrameSize < PP_ContextPopUpcss.offsetHeight) {
  165. var height = PP_ContextPopUpcss.offsetHeight + 20; //Add 20px for scrollbars
  166. ContextMenu.setSplitViewXtabFrameSize(height);
  167. }
  168. }
  169. }
  170. //TODO
  171. ContextMenu.getScrollTop=function()
  172. {
  173. return theDoc.body.scrollTop;
  174. //window.pageXOffset and window.pageYOffset for moz
  175. }
  176. ContextMenu.getScrollLeft=function()
  177. {
  178. return theDoc.body.scrollLeft;
  179. }
  180. ContextMenu.fixPos=function(x,y)
  181. {
  182. var docheight,docwidth,dh,dw;
  183. if (theWindow.innerHeight) {
  184. docheight = theWindow.innerHeight;
  185. docwidth = theWindow.innerWidth;
  186. } else {
  187. docheight = theDoc.body.offsetHeight;
  188. docwidth = theDoc.body.offsetWidth;
  189. }
  190. dh = (PP_ContextPopUpcss.offsetHeight+y) - docheight;
  191. dw = (PP_ContextPopUpcss.offsetWidth+x) - docwidth;
  192. if(dw>0) {
  193. PP_ContextPopUpcss.style.left = (x - dw) + ContextMenu.getScrollLeft() + "px";
  194. }
  195. else {
  196. PP_ContextPopUpcss.style.left = x + ContextMenu.getScrollLeft();
  197. }
  198. if(dh>0) {
  199. if (!topparent.getGlobal("nn7")) {
  200. if (forContextMenu) {
  201. PP_ContextPopUpcss.style.top = y + ContextMenu.getScrollTop() - PP_ContextPopUpcss.offsetHeight;;
  202. PP_ContextPopUpcss.style.bottom = "";
  203. forContextMenu = false;
  204. } else {
  205. //Set the bottom instead of the top.
  206. PP_ContextPopUpcss.style.top = "";
  207. PP_ContextPopUpcss.style.bottom = "0px";
  208. }
  209. } else {
  210. PP_ContextPopUpcss.style.top = theWindow.scrollY + docheight - PP_ContextPopUpcss.offsetHeight;
  211. }
  212. }
  213. else {
  214. PP_ContextPopUpcss.style.bottom = "";
  215. PP_ContextPopUpcss.style.top = y + ContextMenu.getScrollTop();
  216. }
  217. }
  218. ContextMenu.fixSize=function()
  219. {
  220. var menuDiv = PP_ContextPopUpDoc.body.firstChild;
  221. if (bannerPopDown) {
  222. if (menuDiv.scrollWidth < BANNER_MENU_MIN_WIDTH)
  223. menuDiv.style.width = BANNER_MENU_MIN_WIDTH;
  224. else
  225. menuDiv.style.width = menuDiv.scrollWidth;
  226. menuDiv.style.height = menuDiv.scrollHeight;
  227. PP_ContextPopUpcss.style.height = menuDiv.scrollHeight + BANNER_BODY_BORDER_AND_SHADING;
  228. PP_ContextPopUpcss.style.width = menuDiv.scrollWidth + BANNER_BODY_BORDER_AND_SHADING;
  229. } else {
  230. if (topparent.getGlobal("nn7") && menuDiv.getAttribute("horizontal") != "true")
  231. menuDiv.style.width = menuDiv.scrollWidth + NETSCAPE_SCROLL_WIDTH;
  232. else
  233. menuDiv.style.width = menuDiv.scrollWidth;
  234. menuDiv.style.height = menuDiv.scrollHeight;
  235. PP_ContextPopUpcss.style.height = menuDiv.scrollHeight + BODY_BORDER_AND_SHADING;
  236. PP_ContextPopUpcss.style.width = menuDiv.scrollWidth + BODY_BORDER_AND_SHADING;
  237. }
  238. }
  239. ContextMenu.initializeDoc=function()
  240. {
  241. if ( typeof PP_ContextPopUpDoc == "undefined" )
  242. {
  243. doc.clear();
  244. doc.open();
  245. doc.write('<html><head></head><body></body></html>');
  246. doc.close();
  247. }
  248. else
  249. doc = PP_ContextPopUpDoc;
  250. var headtag = doc.getElementsByTagName('head')[0];
  251. if (!headtag)
  252. headtag = doc.firstChild;
  253. var link = doc.createElement('link');
  254. link.rel = "StyleSheet";
  255. link.type = "text/css";
  256. link.href = topparent.getGlobal("virtualDirRoot") + '/../skins/' + topparent.getGlobal("ppSkin") + '/ppwb/styles.css';
  257. headtag.appendChild(link);
  258. //Remove any extra tags that were automatically inserted into the body tag.
  259. while(doc.body.childNodes.length)
  260. doc.body.removeChild(doc.body.childNodes[0]);
  261. }
  262. ContextMenu.clearPopup=function() {
  263. if (PP_ContextPopUpDoc) {
  264. var menuDiv = PP_ContextPopUpDoc.body.firstChild;
  265. if (menuDiv) {
  266. //Clean up dangling functions
  267. while (menuDiv.childNodes.length ) {
  268. menuDiv.childNodes[0].onmouseover = null;
  269. menuDiv.childNodes[0].onmouseout = null;
  270. menuDiv.childNodes[0].onclick = null;
  271. menuDiv.removeChild(menuDiv.childNodes[0]);
  272. }
  273. }
  274. }
  275. ContextMenu.restoreActionPaneSize();
  276. }
  277. ContextMenu.restoreActionPaneSize = function()
  278. {
  279. if (PP_ContextPopUpDoc && PP_ContextPopUpDoc.body) {
  280. var actionPaneSize = PP_ContextPopUpDoc.body.getAttribute("APprefferedSize");
  281. if (actionPaneSize) {
  282. ContextMenu.setActionPaneSize(parseInt(actionPaneSize));
  283. PP_ContextPopUpDoc.body.setAttribute("APprefferedSize",0);
  284. }
  285. }
  286. }
  287. ContextMenu.populatePopup=function(arr,win)
  288. {
  289. var alen,tmpobj,doc,height,htmstr,span_outer,imgobj;
  290. alen = arr.length;
  291. this.alen = alen;
  292. if (arr[0].toolbarPopup)
  293. this.toolbarPopup = true;
  294. else
  295. this.toolbarPopup = false;
  296. if (arr[0].bannerPopDown)
  297. this.bannerPopDown = true;
  298. else
  299. this.bannerPopDown = false;
  300. doc = PP_ContextPopUpDoc;
  301. var menuDiv = doc.body.firstChild;
  302. var horizontal = false;
  303. if (!menuDiv) {
  304. menuDiv = doc.createElement("DIV");
  305. doc.body.appendChild(menuDiv);
  306. }
  307. for( var i=0;i<alen;i++)
  308. {
  309. if(arr[i].type == "ContextItem")
  310. {
  311. tmpobj=doc.createElement("DIV");
  312. tmpobj.style.whitespace = "nowrap";
  313. tmpobj.className = "PP-ContextMenu-Item";
  314. var el;
  315. span_outer = doc.createElement("SPAN");
  316. el = doc.createElement("NOBR");
  317. if (this.toolbarPopup) {
  318. if (arr[i].disabled)
  319. span_outer.className = "PP-ContextMenu-DisabledContainer";
  320. insertIMGNode(el, arr[i].image, "ContextMenu-Image", [], doc);
  321. }
  322. el.appendChild(doc.createTextNode(" " + arr[i].text));
  323. span_outer.appendChild(el);
  324. tmpobj.appendChild(span_outer);
  325. if (!arr[i].disabled) {
  326. tmpobj.onclick = (function (f)
  327. {
  328. return function () {
  329. theDoc.getElementById("PP_ContextPopUp").style.visibility = "hidden";
  330. ContextMenu.restoreActionPaneSize();
  331. if (typeof(f)=="function"){ f(); }
  332. };
  333. })(arr[i].action);
  334. tmpobj.onmouseover = function(){this.className="PP-ContextMenu-Over"}
  335. tmpobj.onmouseout = function(){this.className="PP-ContextMenu-Item"}
  336. } else {
  337. tmpobj.className = "PP-ContextMenu-Disabled-item";
  338. tmpobj.onmouseover = function(){this.className="PP-ContextMenu-Disabled-Over"}
  339. tmpobj.onmouseout = function(){this.className="PP-ContextMenu-Disabled-item"}
  340. }
  341. menuDiv.appendChild(tmpobj);
  342. }
  343. else if (arr[i].type == "BannerMenuItem")
  344. {
  345. tmpobj=doc.createElement("DIV");
  346. tmpobj.className = "BannermenuItemNormal";
  347. var el = doc.createElement("NOBR");
  348. if (arr[i].image != '') {
  349. insertIMGNode(el, arr[i].image, "BannermenuItemIcon", [], doc);
  350. } else {
  351. insertIMGNode(el, topparent.getGlobal("imgPath") + "blank.gif", "BannermenuItemSpacer", [], doc);
  352. }
  353. el.appendChild(doc.createTextNode(arr[i].text));
  354. insertIMGNode(el, topparent.getGlobal("imgPath") + "blank.gif", "BannermenuItemSpacer", [], doc);
  355. tmpobj.appendChild(el);
  356. tmpobj.onclick = (function (f)
  357. {
  358. return function () {
  359. theDoc.getElementById("PP_ContextPopUp").style.visibility = "hidden";
  360. if (typeof(f)=="function"){ f(); }
  361. };
  362. })(arr[i].action);
  363. tmpobj.onmouseover = function(){this.className="BannermenuItemOver"}
  364. tmpobj.onmouseout = function(){this.className="BannermenuItemNormal"}
  365. menuDiv.appendChild(tmpobj);
  366. }
  367. else if (arr[i].type == "ContextSeparator")
  368. {
  369. menuDiv.appendChild(doc.createElement("DIV")).className = "PP-ContextMenu-Separator";
  370. }
  371. else if (arr[i].type == "BannerMenuDivider")
  372. {
  373. menuDiv.appendChild(doc.createElement("DIV")).className = "BannerflyOutMenuSeparator";
  374. }
  375. else if (arr[i].type == "ContextImageItem")
  376. {
  377. if (!horizontal) {
  378. horizontal = true;
  379. menuDiv.appendChild(doc.createElement("NOBR"));
  380. }
  381. var img = insertIMGNode(menuDiv.firstChild, arr[i].image, "ContextMenu-ImageItem", [new attrib("title",arr[i].tooltip)], doc);
  382. if (!arr[i].disabled) {
  383. img.onmouseover = new Function("this.className = 'ContextMenu-ImageItemRollover';");
  384. img.onmouseout = new Function("this.className = 'ContextMenu-ImageItem';");
  385. img.onclick = (function (f)
  386. {
  387. return function () {
  388. theDoc.getElementById("PP_ContextPopUp").style.visibility = "hidden";
  389. if (typeof(f)=="function"){ f(); }
  390. };
  391. })(arr[i].action);
  392. }
  393. }
  394. }
  395. if (bannerPopDown)
  396. doc.body.className = "BannerflyOutMenu";
  397. else if (!horizontal)
  398. doc.body.className = "PP-ContextMenu-Body";
  399. else
  400. doc.body.className = "PP-ContextMenu-Body-horizontal";
  401. menuDiv.setAttribute("horizontal",(horizontal)?"true":"false");
  402. doc.body.onselectstart = function(){return false;}
  403. }
  404. function ContextItem(image,str,fnc,disabled)
  405. {
  406. if (image == '') {
  407. this.toolbarPopup = false;
  408. }
  409. else {
  410. this.toolbarPopup = true;
  411. if (!image) {
  412. image = "empty.gif";
  413. alert(image);
  414. }
  415. this.image = topparent.getGlobal("toolbarMenuIconPath") + image;
  416. }
  417. this.text = str;
  418. this.action = fnc;
  419. this.disabled = disabled || false;
  420. }
  421. ContextItem.prototype.type = "ContextItem";
  422. function ContextSeparator()
  423. {
  424. this.toolbarPopup = false;
  425. }
  426. ContextSeparator.prototype.type = "ContextSeparator";
  427. function ContextImageItem(image,fnc,tooltip,disabled)
  428. {
  429. this.image = image;
  430. this.action = fnc;
  431. this.disabled = disabled || false;
  432. this.tooltip = tooltip;
  433. }
  434. ContextImageItem.prototype.type = "ContextImageItem";
  435. function BannerMenuItem(image,str,func) {
  436. this.image = image;
  437. this.text = str;
  438. this.action = func;
  439. this.bannerPopDown = true;
  440. }
  441. BannerMenuItem.prototype.type = "BannerMenuItem";
  442. function BannerMenuDivider() {}
  443. BannerMenuDivider.prototype.type = "BannerMenuDivider";
  444. function hidePopupMenu(targetDoc) {
  445. var doc;
  446. if (!targetDoc)
  447. doc = theDoc;
  448. else
  449. doc = targetDoc;
  450. var popUp = doc.getElementById("PP_ContextPopUp");
  451. if (popUp) {
  452. ContextMenu.clearPopup();
  453. popUp.style.visibility = "hidden";
  454. }
  455. }