CModal.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2011
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. /**
  13. Class: CModal
  14. Description:
  15. @param title String to show in the header. [Mandatory]
  16. @param sCloseToolTip String to use as tooltip for close button. [Madatory]
  17. @param parent The container of this dialog. [Optional]
  18. @param t Top coordinate. [Optional] By Default the dialog is centered.
  19. @param l Left coordinate. [Optional] By Default the dialog is centered.
  20. @param h Height of the dialog. [Optional] By Default the dialog is centered.
  21. @param w Width of the dialog. [Optional] By Default the dialog is centered.
  22. */
  23. function CModal(title, sCloseToolTip, parent, t, l, h, w)
  24. {
  25. this.m_title = title;
  26. this.m_sCloseToolTip = sCloseToolTip;
  27. if (parent) {
  28. this.m_parent = parent;
  29. }
  30. else {
  31. this.m_parent = (document.all ? document.body : document.documentElement);
  32. }
  33. var oBL = document.getElementById(CMODAL_BACKGROUND_LAYER_ID);
  34. if (!oBL) {
  35. oBL = document.createElement('div');
  36. oBL.id = CMODAL_BACKGROUND_LAYER_ID;
  37. oBL.style.display = 'none';
  38. oBL.style.position = 'absolute';
  39. oBL.style.top = '0px';
  40. oBL.style.left = '0px';
  41. oBL.style.zIndex = (CMODAL_ZINDEX - 2);
  42. oBL.style.width = '100%';
  43. oBL.style.height = '100%';
  44. oBL.innerHTML = '<table width="100%" height="100%"><tr><td onmousemove="CModalEvent_mousemoving(event)" onmouseup="CModalEvent_disableDrag(event)"></td></tr></table>';
  45. this.m_parent.appendChild(oBL);
  46. }
  47. this.m_backLayer = oBL;
  48. this.m_top = (t == null ? 0 : t);
  49. this.m_left = (l == null ? 0 : l);
  50. this.m_height = (h == null ? 0 : h);
  51. this.m_width = (w == null ? 0 : w);
  52. var f = document.getElementById(CMODAL_ID);
  53. if (!f) {
  54. f = document.createElement('span');
  55. f.id = CMODAL_ID;
  56. f.CModal = this;
  57. f.className = 'CModal_frame';
  58. f.style.zIndex = CMODAL_ZINDEX;
  59. this.m_parent.appendChild(f);
  60. }
  61. this.m_back_iframe = document.getElementById(CMODAL_BACK_IFRAME_ID);
  62. if (!this.m_back_iframe) {
  63. this.m_back_iframe = document.createElement('iframe');
  64. this.m_back_iframe.id = CMODAL_BACK_IFRAME_ID;
  65. this.m_back_iframe.frameBorder = 0;
  66. this.m_back_iframe.src = "../common/blank.html";
  67. this.m_back_iframe.style.position = 'absolute';
  68. this.m_back_iframe.style.zIndex = CMODAL_ZINDEX - 1;
  69. this.m_parent.appendChild(this.m_back_iframe);
  70. }
  71. // render framework of the modal dialog
  72. f.innerHTML = this.renderDialogFrame();
  73. this.m_frame = f;
  74. }
  75. function CModal_hide() {
  76. this.m_top = parseInt(this.m_frame.offsetTop,10);
  77. this.m_left = parseInt(this.m_frame.offsetLeft,10);
  78. this.m_height = parseInt(this.m_frame.offsetHeight,10);
  79. this.m_width = parseInt(this.m_frame.offsetWidth,10);
  80. this.m_backLayer.style.display = 'none';
  81. this.m_frame.style.display = 'none';
  82. if (this.m_back_iframe) {
  83. this.m_back_iframe.style.display = 'none';
  84. }
  85. }
  86. function CModal_reCenter() {
  87. this.m_left = (this.m_backLayer.offsetWidth - this.m_width)/2;
  88. this.m_top = (this.m_backLayer.offsetHeight - this.m_height)/2;
  89. }
  90. function CModal_renderDialogFrame() {
  91. var sTableAttrs = 'summary="" cellpadding="0" cellspacing="0" border="0"';
  92. var out =
  93. '<table width="100%" height="100%" ' + sTableAttrs + ' onmouseup="CModalEvent_disableDrag(event)" onmousemove="CModalEvent_mousemoving(event)"><tr>' +
  94. '<td onmousedown="CModalEvent_enableDrag(event);">' +
  95. '<table class="dialogHeader" width="100%" ' + sTableAttrs + '><tr>' +
  96. '<td id="' + CMODAL_HEADER + '" valign="top" class="dialogHeaderTitle" width="100%" nowrap="nowrap">' +
  97. getConfigFrame().htmlencode(this.m_title) +
  98. '</td><td align="right" valign="middle">' +
  99. '<a onclick="hideCModal()" style="cursor:pointer;">' +
  100. '<img height="16" width="16" vspace="2" border="0" class="dialogClose" onmouseover="this.className = \'dialogCloseOver\'" onmouseout="this.className = \'dialogClose\'" onmouseup="this.className = \'dialogClose\'" src="' + p_sSkinFolder + '/portal/images/close.gif" title="' + getConfigFrame().htmlencode(this.m_sCloseToolTip) + '">' +
  101. '</a>' +
  102. '</td></tr></table>' +
  103. '</td></tr><tr><td width="100%" height="100%" class="body_dialog_modal" style="border-left:1px solid #CECFCE;border-right:1px solid #CECFCE;" onmousemove="CModalEvent_mousemoving(event)" onmouseup="CModalEvent_disableDrag(event)">' +
  104. '<iframe id="' + CMODAL_CONTENT_ID + '" name="' + CMODAL_CONTENT_ID + '" class="body_dialog_modal" src="../' + qs_dir + '/blankNewWin.html" style="padding:0px;margin:0px;width:100%;height:100%;" frameborder="0">no iframe support?</iframe>' +
  105. '</td></tr><tr><td>' +
  106. '<table ' + sTableAttrs + ' class="dialogButtonBar" style="padding:0px">' +
  107. '<tr>' +
  108. '<td width="2" valign="middle"><img width="2" alt="" src="../ps/images/space.gif"></td>' +
  109. '<td valign="middle"><table border="0" cellpadding="1" cellspacing="0">' +
  110. '<tr>' +
  111. '<td><img height="1" width="8" alt="" src="../ps/images/space.gif"></td>' +
  112. '<td>' + CModal_renderButton(msgQS['OK'], 'okCModal()') + '</td>' +
  113. '<td><img height="1" width="8" alt="" src="../ps/images/space.gif"></td>' +
  114. '<td>' + CModal_renderButton(msgQS['CANCEL'], 'cancelCModal()') + '</td>' +
  115. '<td><img height="1" width="8" alt="" src="../ps/images/space.gif"></td>' +
  116. '</tr></table>' +
  117. '</td><td width="100%">&nbsp;</td>' +
  118. '<td style="padding:3px;" valign="bottom" class="CModal_sideSE" onmousedown="CModalEvent_enableResize(event)">' +
  119. '<img class="CModal_sideSE" style="cursor:se-resize;" alt="" height="12" width="12" border="0" src="../common/images/dialog_resize.gif" onmousedown="CModalEvent_enableResize(event);return false;" onmouseup="CModalEvent_disableDrag(event);return false;" onmousemove="CModalEvent_mousemoving(event);return false;">' +
  120. '</td>' +
  121. '</tr></table></td></tr></table>';
  122. return out;
  123. }
  124. function CModal_renderButton(label, jsFct) {
  125. var out = '<table cellpadding="0" cellspacing="0" style="padding: 2px 10px 3px;" class="commandButton" onmouseover="this.className=\'commandButtonOver\'"' +
  126. ' onmouseout="this.className = \'commandButton\'" onmousedown="this.className=\'commandButtonDown\'">' +
  127. '<tr>' +
  128. '<td style="cursor:pointer;" valign="middle" align="center" nowrap id="btnAnchor"><img height="1" width="60" alt="" src="../ps/images/space.gif"><br>' +
  129. '<a onclick="' + jsFct + '" onmouseover="window.status=\'\';return true;" onmouseout="window.status=\'\';return true;">' + label + '</a></td></tr></table>';
  130. return out;
  131. }
  132. function CModal_show() {
  133. this.m_backLayer.style.display = 'block';
  134. this.reCenter();
  135. this.m_frame.style.top = this.m_top;
  136. this.m_frame.style.left = this.m_left;
  137. this.m_frame.style.height = this.m_height;
  138. this.m_frame.style.width = this.m_width;
  139. this.m_frame.style.display = 'inline';
  140. if (this.m_back_iframe) {
  141. this.m_back_iframe.style.top = this.m_frame.offsetTop;
  142. this.m_back_iframe.style.left = this.m_frame.offsetLeft;
  143. this.m_back_iframe.style.height = this.m_frame.offsetHeight;
  144. this.m_back_iframe.style.width = this.m_frame.offsetWidth;
  145. this.m_back_iframe.style.display = "block";
  146. }
  147. }
  148. CModal.prototype.hide = CModal_hide;
  149. CModal.prototype.reCenter = CModal_reCenter;
  150. CModal.prototype.renderDialogFrame = CModal_renderDialogFrame;
  151. CModal.prototype.show = CModal_show;
  152. /* Constants */
  153. var CMODAL_ID = 'CMODAL_FRAME';
  154. var CMODAL_CONTENT_ID = 'CMODAL_CONTENT';
  155. var CMODAL_HEADER = 'CMODAL_HEADER';
  156. var CMODAL_BACKGROUND_LAYER_ID = 'CMODAL_BK';
  157. var CMODAL_BACK_IFRAME_ID = 'CMODAL_BK_IFRAME';
  158. var CMODAL_ZINDEX = 111;
  159. /* Global variables */
  160. var CMODAL_dragEnabled = false;
  161. var CMODAL_resizeDirection = null;
  162. var CMODAL_startLeft = null;
  163. var CMODAL_startTop = null;
  164. var CMODAL_startWidth = null;
  165. var CMODAL_startHeight = null;
  166. var CMODAL_deltaX = null;
  167. var CMODAL_deltaY = null;
  168. /* Event handlers for CModal (global functions) */
  169. function hideCModal() {
  170. var cdlg = document.getElementById(CMODAL_ID);
  171. if (cdlg && cdlg.CModal) {
  172. cdlg.CModal.hide();
  173. }
  174. }
  175. function cancelCModal() {
  176. var iframe = document.getElementById(CMODAL_CONTENT_ID);
  177. if (iframe && iframe.contentWindow && typeof iframe.contentWindow.cancelDialog == 'function') {
  178. iframe.contentWindow.cancelDialog();
  179. }
  180. else {
  181. hideCModal();
  182. }
  183. }
  184. function okCModal() {
  185. var iframe = document.getElementById(CMODAL_CONTENT_ID);
  186. if (iframe && iframe.contentWindow && typeof iframe.contentWindow.execute == 'function') {
  187. iframe.contentWindow.execute();
  188. }
  189. else {
  190. hideCModal();
  191. }
  192. }
  193. function CModalEvent_mousemoving(e) {
  194. var oDlg = null;
  195. var oIFrame = null;
  196. if (CMODAL_dragEnabled) {
  197. if (e == null && (typeof event == 'object') && event.clientX != null) {
  198. e = event;
  199. }
  200. oDlg = document.getElementById(CMODAL_ID);
  201. if (CMODAL_startLeft == null) {
  202. CMODAL_startLeft = parseInt(oDlg.style.left,10) - e.clientX;
  203. CMODAL_startTop = parseInt(oDlg.style.top,10) - e.clientY;
  204. }
  205. oDlg.style.left = CMODAL_startLeft + e.clientX;
  206. oDlg.style.top = CMODAL_startTop + e.clientY;
  207. oIFrame = document.getElementById(CMODAL_BACK_IFRAME_ID);
  208. if (oIFrame) {
  209. oIFrame.style.left = oDlg.style.left;
  210. oIFrame.style.top = oDlg.style.top;
  211. }
  212. }
  213. if (CMODAL_resizeDirection) {
  214. if (e == null && (typeof event == 'object') && event.clientX != null) {
  215. e = event;
  216. }
  217. oDlg = document.getElementById(CMODAL_ID);
  218. if (CMODAL_startLeft == null) {
  219. CMODAL_startLeft = parseInt(oDlg.style.left,10);
  220. CMODAL_startTop = parseInt(oDlg.style.top,10);
  221. CMODAL_startHeight = parseInt(oDlg.style.height,10);
  222. CMODAL_startWidth = parseInt(oDlg.style.width,10);
  223. }
  224. var h = 0, w = 0;
  225. switch (CMODAL_resizeDirection) {
  226. case 'NE':
  227. case 'E':
  228. case 'SE':
  229. w = (e.clientX - CMODAL_startLeft + CMODAL_deltaX);
  230. if (w < 100) {
  231. w = 100;
  232. }
  233. oDlg.style.width = w + "px";
  234. }
  235. switch (CMODAL_resizeDirection) {
  236. case 'SW':
  237. case 'S':
  238. case 'SE':
  239. h = (e.clientY - CMODAL_startTop + CMODAL_deltaY);
  240. if (h < 100) {
  241. h = 100;
  242. }
  243. oDlg.style.height = h + "px";
  244. }
  245. switch (CMODAL_resizeDirection) {
  246. case 'NW':
  247. case 'N':
  248. case 'NE':
  249. oDlg.style.top = e.clientY;
  250. h = (CMODAL_startHeight + (CMODAL_startTop - e.clientY) + CMODAL_deltaY);
  251. if (h < 100) {
  252. h = 100;
  253. }
  254. oDlg.style.height = h + "px";
  255. }
  256. switch (CMODAL_resizeDirection) {
  257. case 'NW':
  258. case 'W':
  259. case 'SW':
  260. oDlg.style.left = e.clientX;
  261. w = (CMODAL_startWidth + (CMODAL_startLeft - e.clientX) + CMODAL_deltaX);
  262. if (w < 100) {
  263. w = 100;
  264. }
  265. oDlg.style.width = w + "px";
  266. }
  267. oIFrame = document.getElementById(CMODAL_BACK_IFRAME_ID);
  268. if (oIFrame) {
  269. oIFrame.style.left = oDlg.offsetLeft;
  270. oIFrame.style.top = oDlg.offsetTop;
  271. oIFrame.style.height = oDlg.offsetHeight;
  272. oIFrame.style.width = oDlg.offsetWidth;
  273. }
  274. }
  275. if (e.returnValue) { e.returnValue = false; }
  276. else if (e.preventDefault) { e.preventDefault(); }
  277. else { return false; }
  278. }
  279. function CModalEvent_disableDrag(e) {
  280. CMODAL_dragEnabled = false;
  281. CMODAL_resizeDirection = null;
  282. CMODAL_startLeft = null;
  283. CMODAL_startTop = null;
  284. CMODAL_deltaX = 0;
  285. CMODAL_deltaY = 0;
  286. // remove dragging style
  287. var cn = document.getElementById(CMODAL_ID).className;
  288. document.getElementById(CMODAL_HEADER).style.cursor = 'default';
  289. document.getElementById(CMODAL_ID).className = cn.replace(/\s*\bCModal_dragging\b/g, '');
  290. // show content frame
  291. document.getElementById(CMODAL_CONTENT_ID).style.visibility = "visible";
  292. if (typeof document.getElementById(CMODAL_CONTENT_ID).contentWindow.refreshContent == "function") {
  293. document.getElementById(CMODAL_CONTENT_ID).contentWindow.refreshContent();
  294. }
  295. if (e.returnValue) { e.returnValue = false; }
  296. else if (e.preventDefault) { e.preventDefault(); }
  297. else { return false; }
  298. }
  299. function CModalEvent_enableDrag(e) {
  300. CMODAL_dragEnabled = true;
  301. CMODAL_startLeft = null;
  302. CMODAL_startTop = null;
  303. if (e == null && (typeof event == 'object') && event.clientX != null) {
  304. e = event;
  305. }
  306. // apply dragging style to frame
  307. document.getElementById(CMODAL_ID).className += " CModal_dragging";
  308. document.getElementById(CMODAL_HEADER).style.cursor = 'move';
  309. // hide content frame
  310. document.getElementById(CMODAL_CONTENT_ID).style.visibility = "hidden";
  311. if (e.returnValue) { e.returnValue = false; }
  312. else if (e.preventDefault) { e.preventDefault(); }
  313. else { return false; }
  314. }
  315. function CModalEvent_enableResize(e) {
  316. CMODAL_startLeft = null;
  317. CMODAL_startTop = null;
  318. CMODAL_startWidth = null;
  319. CMODAL_startHeight = null;
  320. CMODAL_deltaX = 0;
  321. CMODAL_deltaY = 0;
  322. if (e == null && (typeof event == 'object') && event.clientX != null) {
  323. e = event;
  324. }
  325. var oDlg = document.getElementById(CMODAL_ID);
  326. CMODAL_startLeft = parseInt(oDlg.style.left,10);
  327. CMODAL_startTop = parseInt(oDlg.style.top,10);
  328. CMODAL_startHeight = parseInt(oDlg.style.height,10);
  329. CMODAL_startWidth = parseInt(oDlg.style.width,10);
  330. CMODAL_deltaX = (CMODAL_startLeft + CMODAL_startWidth - e.clientX);
  331. CMODAL_deltaY = (CMODAL_startTop + CMODAL_startHeight - e.clientY);
  332. var src = (e.srcElement ? e.srcElement : e.target);
  333. if ( (/\bCModal_side(\w+)\b/).test(src.className) ) {
  334. // set resize direction using className
  335. CMODAL_resizeDirection = RegExp.$1;
  336. // apply dragging style to frame
  337. document.getElementById(CMODAL_ID).className += " CModal_dragging";
  338. // hide content frame
  339. document.getElementById(CMODAL_CONTENT_ID).style.visibility = "hidden";
  340. }
  341. if (e.returnValue) { e.returnValue = false; }
  342. else if (e.preventDefault) { e.preventDefault(); }
  343. else { return false; }
  344. }