popup.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. function popup_on_click()
  17. {
  18. contextMenu.hide();
  19. return this.doAction ? this.doAction() : null;
  20. }
  21. function popup_on_mouse_over()
  22. {
  23. this.style.backgroundColor='highlight';
  24. var button=this.firstChild;
  25. if(button.noaction)
  26. {
  27. button.disabled=false;
  28. button.style.color='graytext';
  29. }
  30. else
  31. {
  32. button.style.color='highlighttext';
  33. }
  34. }
  35. function popup_on_mouse_out()
  36. {
  37. this.style.backgroundColor='';
  38. var button=this.firstChild;
  39. if(button.noaction)
  40. button.disabled=true;
  41. button.style.color='menutext';
  42. };
  43. function popup_popup()
  44. {
  45. return false;
  46. }
  47. function showPopup(menu,posx,posy)
  48. {
  49. if(!window.createPopup)
  50. return false;
  51. contextMenu=window.createPopup();
  52. var popupDoc=contextMenu.document;
  53. var popupBody=popupDoc.body;
  54. popupBody.style.backgroundColor = "menu";
  55. popupBody.style.border = "outset white 2px";
  56. var tab=popupDoc.createElement('TABLE');
  57. tab.style.font='menu';
  58. tab.id='tab';
  59. tab.width=10;
  60. tab.oncontextmenu=popup_popup;
  61. tab.onselectstart=popup_popup;
  62. tab.cellSpacing=0;
  63. var tbody = popupDoc.createElement('TBODY');
  64. var lasttd=null;
  65. for(var item in menu)
  66. {
  67. if(menu[item] && menu[item].length>=2)
  68. {
  69. var tr=popupDoc.createElement('TR');
  70. tr.doAction=menu[item][1];
  71. tr.onclick=popup_on_click;
  72. var td=popupDoc.createElement('TD');
  73. td.style.padding='3px 20px 3px 20px';
  74. td.style.whiteSpace='nowrap';
  75. td.onmouseover=popup_on_mouse_over;
  76. td.onmouseout=popup_on_mouse_out;
  77. if(lasttd && lasttd.groupend)
  78. {
  79. td.style.borderTop='2px outset #fff';
  80. td.style.paddingTop='4px';
  81. }
  82. var span=popupDoc.createElement('SPAN');
  83. span.name='button';
  84. span.disabled=span.noaction=(!menu[item][1]);
  85. span.style.backgroundColor='transparent';
  86. span.style.cursor='default';
  87. span.appendChild(popupDoc.createTextNode(menu[item][0]));
  88. td.appendChild(span);
  89. if(menu[item][2]=='checked')
  90. {
  91. var check=popupDoc.createElement('SPAN');
  92. check.innerHTML='√';
  93. check.style.position='absolute';
  94. check.style.left='5px';
  95. check.style.fontWeight='bolder';
  96. td.appendChild(check);
  97. }
  98. tr.appendChild(td);
  99. tbody.appendChild(tr);
  100. lasttd=td;
  101. }
  102. else
  103. {
  104. if(lasttd)
  105. {
  106. lasttd.style.borderBottom='1px outset #fff';
  107. lasttd.style.paddingBottom='5px';
  108. lasttd.groupend=true;
  109. }
  110. }
  111. }
  112. tab.appendChild(tbody);
  113. popupBody.appendChild(tab);
  114. contextMenu.show(posx, posy, 300, 300, null);
  115. var w=popupBody.all.tab.clientWidth+5,
  116. h=popupBody.all.tab.clientHeight+5;
  117. contextMenu.show(posx, posy, w, h, null);
  118. return true;
  119. }
  120. function showColumnPopup(tableId, colIndex, toggleMultiSelect)
  121. {
  122. function setColumn()
  123. {
  124. toggleMultiSelect( tableId, colIndex, true);
  125. }
  126. function alignColumn(alignment)
  127. {
  128. var table = document.getElementById( tableId );
  129. if (table) {
  130. var rows = table.rows;
  131. var nrows= rows.length;
  132. var i = document.getElementById('H.' + tableId) ? 0 : 1;
  133. for (; i<nrows; i++) {
  134. var row = rows[i];
  135. if (row.id.indexOf('.toggle') == -1)
  136. rows[i].cells[colIndex].style.textAlign = alignment;
  137. }
  138. }
  139. }
  140. function alignColumnLeft()
  141. {
  142. alignColumn('left');
  143. }
  144. function alignColumnCenter()
  145. {
  146. alignColumn('center');
  147. }
  148. function alignColumnRight()
  149. {
  150. alignColumn('right');
  151. }
  152. function changeColumnWidth(htable, table, points)
  153. {
  154. if (table) {
  155. var rows = table.rows;
  156. var nrows= rows.length;
  157. var htableRow = htable ? htable.rows[0] : null;
  158. var hw=0;
  159. for (var i=0; i<nrows; i++) {
  160. var row = rows[i];
  161. if (row.id.indexOf('.toggle') == -1)
  162. {
  163. cell = row.cells[colIndex];
  164. var w = cell.offsetWidth * (1 + points)
  165. cell.style.width = w;
  166. if (hw==0)
  167. hw = w;
  168. }
  169. }
  170. if (htableRow)
  171. htableRow.cells[colIndex].style.width = hw;
  172. }
  173. }
  174. function increaseWidth()
  175. {
  176. var table = document.getElementById( tableId );
  177. var htable = document.getElementById('H.' + tableId);
  178. changeColumnWidth(htable, table, 0.2)
  179. }
  180. function decreaseWidth()
  181. {
  182. var table = document.getElementById( tableId );
  183. var htable = document.getElementById('H.' + tableId);
  184. changeColumnWidth(htable, table, -0.2)
  185. }
  186. var menu=[];
  187. if (toggleMultiSelect) {
  188. menu.push( ["Set Column...", setColumn] );
  189. menu.push( null );
  190. }
  191. menu.push( ["Align Left", alignColumnLeft] );
  192. menu.push( ["Align Center", alignColumnCenter] );
  193. menu.push( ["Align Right", alignColumnRight] );
  194. menu.push( ["Increase Width", increaseWidth]);
  195. menu.push( ["Decrease Width", decreaseWidth]);
  196. var x, y;
  197. if (window.event)
  198. {
  199. x = window.event.screenX;
  200. y = window.event.screenY;
  201. window.event.cancelBubble = true;
  202. }
  203. else
  204. x = y = 0;
  205. showPopup(menu, x, y);
  206. return false;//suppress default browser popup
  207. }