CAlignmentPicker.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| BI and PM: prmt
  5. *| (C) Copyright IBM Corp. 2002, 2016
  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. CAlignmentPicker.js
  14. This script provides interactivity for the alignment prompt control.
  15. */
  16. // Constructor to create a new Alignment Picker prompt
  17. // sPromptId: The id of the prompt control (String)
  18. // sRef: the name of this object
  19. // sCallBackFunction: function to call with the new alignment value as a parameter
  20. // sTooltip: string to used as a tooltip for the color picker button
  21. // bToolbar: (Optional, Default: true). Is this button in a toolbar?
  22. function CAlignmentPicker(sPromptId, sRef, sCallBackFunction, sToolTip, bToolbar)
  23. {
  24. // set up control
  25. this.m_sSkin = (typeof getPromptSkin != "undefined" ? getPromptSkin() : "../skins/corporate");
  26. this.m_sImgPath = this.m_sSkin + "/prompting/images/";
  27. this.m_parentId = "selectAlignment" + sPromptId;
  28. this.m_oParent = document.getElementById(this.m_parentId);
  29. this.m_sRef = sRef;
  30. this.m_sDialogId = "alignmentDialog" + sPromptId;
  31. this.m_sToolTip = (typeof sToolTip == "undefined") ? null : sToolTip;
  32. this.m_bToolbar = (bToolbar != false);
  33. //create any needed objects
  34. this.init();
  35. // update the UI
  36. this.draw();
  37. this.m_oDialog = document.getElementById(this.m_sDialogId);
  38. this.m_sAlignment = null;
  39. this.m_sActiveButtonId = this.m_sRef+'_DF';
  40. this.m_sCallBackFunction = sCallBackFunction;
  41. }
  42. function CAlignmentPicker_init()
  43. {
  44. }
  45. //draw the UI for the picker
  46. function CAlignmentPicker_draw()
  47. {
  48. var HTMLOut = (this.m_bToolbar ? '<button' : '<span' );
  49. if (this.m_sToolTip != null && this.m_sToolTip != "") {
  50. HTMLOut += ' title="'+this.m_sToolTip+'"';
  51. }
  52. if (this.m_bToolbar) {
  53. HTMLOut += ' class="clsCPButton" onmouseover="this.className=\'clsCPButtonOver\'" onmouseout="this.className=\'clsCPButton\'" type="button"';
  54. }
  55. HTMLOut += ' onclick="'+this.m_sRef+'.togglePicker();CAlignmentPicker_preventBubbling(event);" ><img src="'+ this.m_sImgPath +'align.gif">';
  56. HTMLOut += (this.m_bToolbar ? '</button>' : '</span>' );
  57. HTMLOut += '<br/><div id="'+this.m_sDialogId+'" class="clsAPContainer" style="display:none;position:absolute;margin-top:1px;">';
  58. HTMLOut += '<table cellpadding="0" cellspacing="3" border="0">';
  59. HTMLOut += '<tr><td title="'+PMT_AP_ALIGN_TOP_LEFT+'" id="'+this.m_sRef+'_TL" onclick="'+this.m_sRef+'.setAlignment(\'TL\')" class="clsAPButtonNormal" onmouseover="'+this.m_sRef+'.buttonMouseHandler(this,\'over\');" onmouseout="'+this.m_sRef+'.buttonMouseHandler(this,\'out\');" onMouseDown="'+this.m_sRef+'.buttonMouseHandler(this,\'down\');"><img src="'+ this.m_sImgPath +'align_top_left.gif"></td>';
  60. HTMLOut += '<td title="'+PMT_AP_ALIGN_TOP_CENTER+'" id="'+this.m_sRef+'_TC" onclick="'+this.m_sRef+'.setAlignment(\'TC\')" class="clsAPButtonNormal" onmouseover="'+this.m_sRef+'.buttonMouseHandler(this,\'over\');" onmouseout="'+this.m_sRef+'.buttonMouseHandler(this,\'out\');" onmousedown="'+this.m_sRef+'.buttonMouseHandler(this,\'down\');"><img src="'+ this.m_sImgPath +'align_top_center.gif"></td>';
  61. HTMLOut += '<td title="'+PMT_AP_ALIGN_TOP_RIGHT+'" id="'+this.m_sRef+'_TR" onclick="'+this.m_sRef+'.setAlignment(\'TR\')" class="clsAPButtonNormal" onmouseover="'+this.m_sRef+'.buttonMouseHandler(this,\'over\');" onmouseout="'+this.m_sRef+'.buttonMouseHandler(this,\'out\');" onmousedown="'+this.m_sRef+'.buttonMouseHandler(this,\'down\');"><img src="'+ this.m_sImgPath +'align_top_right.gif"></td></tr>';
  62. HTMLOut += '<tr><td title="'+PMT_AP_ALIGN_MIDDLE_LEFT+'" id="'+this.m_sRef+'_ML" onclick="'+this.m_sRef+'.setAlignment(\'ML\')" class="clsAPButtonNormal" onmouseover="'+this.m_sRef+'.buttonMouseHandler(this,\'over\');" onmouseout="'+this.m_sRef+'.buttonMouseHandler(this,\'out\');" onmousedown="'+this.m_sRef+'.buttonMouseHandler(this,\'down\');"><img src="'+ this.m_sImgPath +'align_middle_left.gif"></td>';
  63. HTMLOut += '<td title="'+PMT_AP_ALIGN_MIDDLE_CENTER+'" id="'+this.m_sRef+'_MC" onclick="'+this.m_sRef+'.setAlignment(\'MC\')" class="clsAPButtonNormal" onmouseover="'+this.m_sRef+'.buttonMouseHandler(this,\'over\');" onmouseout="'+this.m_sRef+'.buttonMouseHandler(this,\'out\');" onmousedown="'+this.m_sRef+'.buttonMouseHandler(this,\'down\');"><img src="'+ this.m_sImgPath +'align_middle_center.gif"></td>';
  64. HTMLOut += '<td title="'+PMT_AP_ALIGN_MIDDLE_RIGHT+'" id="'+this.m_sRef+'_MR" onclick="'+this.m_sRef+'.setAlignment(\'MR\')" class="clsAPButtonNormal" onmouseover="'+this.m_sRef+'.buttonMouseHandler(this,\'over\');" onmouseout="'+this.m_sRef+'.buttonMouseHandler(this,\'out\');" onmousedown="'+this.m_sRef+'.buttonMouseHandler(this,\'down\');"><img src="'+ this.m_sImgPath +'align_middle_right.gif"></td></tr>';
  65. HTMLOut += '<tr><td title="'+PMT_AP_ALIGN_BOTTOM_LEFT+'" id="'+this.m_sRef+'_BL" onclick="'+this.m_sRef+'.setAlignment(\'BL\')" class="clsAPButtonNormal" onmouseover="'+this.m_sRef+'.buttonMouseHandler(this,\'over\');" onmouseout="'+this.m_sRef+'.buttonMouseHandler(this,\'out\');" onmousedown="'+this.m_sRef+'.buttonMouseHandler(this,\'down\');"><img src="'+ this.m_sImgPath +'align_bottom_left.gif"></td>';
  66. HTMLOut += '<td title="'+PMT_AP_ALIGN_BOTTOM_CENTER+'" id="'+this.m_sRef+'_BC" onclick="'+this.m_sRef+'.setAlignment(\'BC\')" class="clsAPButtonNormal" onmouseover="'+this.m_sRef+'.buttonMouseHandler(this,\'over\');" onmouseout="'+this.m_sRef+'.buttonMouseHandler(this,\'out\');" onmousedown="'+this.m_sRef+'.buttonMouseHandler(this,\'down\');"><img src="'+ this.m_sImgPath +'align_bottom_center.gif"></td>';
  67. HTMLOut += '<td title="'+PMT_AP_ALIGN_BOTTOM_RIGHT+'" id="'+this.m_sRef+'_BR" onclick="'+this.m_sRef+'.setAlignment(\'BR\')" class="clsAPButtonNormal" onmouseover="'+this.m_sRef+'.buttonMouseHandler(this,\'over\');" onmouseout="'+this.m_sRef+'.buttonMouseHandler(this,\'out\');" onmousedown="'+this.m_sRef+'.buttonMouseHandler(this,\'down\');"><img src="'+ this.m_sImgPath +'align_bottom_right.gif"></td></tr>';
  68. HTMLOut += '<tr><td title="'+PMT_AP_ALIGN_DEFAULT+'" id="'+this.m_sRef+'_DF" style="text-align: center;" onclick="'+this.m_sRef+'.setAlignment(\'\')" class="clsAPButtonNormal" onmouseover="'+this.m_sRef+'.buttonMouseHandler(this,\'over\');" onmouseout="'+this.m_sRef+'.buttonMouseHandler(this,\'out\');" onmousedown="'+this.m_sRef+'.buttonMouseHandler(this,\'down\');"><img src="'+ this.m_sImgPath +'default_color.gif"></td>';
  69. HTMLOut += '<td colspan="2"><img src="'+ this.m_sImgPath +'spacer.gif" width="1" height="1"></td></tr>';
  70. HTMLOut += '</table>';
  71. HTMLOut += '</div>';
  72. this.m_oParent.innerHTML = HTMLOut;
  73. }
  74. //switch that will hide and show the picker dialog
  75. function CAlignmentPicker_togglePicker(e)
  76. {
  77. if (this.m_oDialog.style.display == "inline")
  78. {
  79. this.hide();
  80. }
  81. else
  82. {
  83. this.show();
  84. }
  85. this.preventBubbling(e);
  86. }
  87. //show the picker dialog
  88. function CAlignmentPicker_show()
  89. {
  90. //hide any other pickers that might be visible
  91. if (hidePickers)
  92. {
  93. hidePickers();
  94. }
  95. var activeButton = document.getElementById(this.m_sActiveButtonId);
  96. activeButton.className = 'clsAPButtonPressed';
  97. this.m_oDialog.style.display = 'inline';
  98. this.m_oDialog.style.zIndex = '2';
  99. }
  100. //hide the picker dialog
  101. function CAlignmentPicker_hide()
  102. {
  103. //clear all classes back to normal
  104. for (var i=0; i < apCodes.length; i++)
  105. {
  106. document.getElementById(this.m_sRef+'_'+apCodes[i]).className = 'clsAPButtonNormal';
  107. }
  108. this.m_oDialog.style.display = 'none';
  109. this.m_oDialog.style.zIndex = '1';
  110. }
  111. function CAlignmentPicker_preventBubbling(e)
  112. {
  113. if (typeof e == "object")
  114. {
  115. if (window.ie)
  116. {
  117. e.returnValue = false;
  118. e.cancelBubble = true;
  119. }
  120. else
  121. {
  122. e.preventDefault();
  123. e.stopPropagation();
  124. }
  125. }
  126. }
  127. function CAlignmentPicker_buttonMouseHandler(button, action)
  128. {
  129. if (button.id == this.m_sActiveButtonId)
  130. {
  131. if (action == "over") {
  132. button.className = 'clsAPButtonOverPressed';
  133. }
  134. else if (action == "out") {
  135. button.className = 'clsAPButtonPressed';
  136. }
  137. else if (action == "down") {
  138. button.className= 'clsAPButtonPressed';
  139. }
  140. }
  141. else
  142. {
  143. if (action == "over") {
  144. button.className = 'clsAPButtonOver';
  145. }
  146. else if (action == "out") {
  147. button.className = 'clsAPButtonNormal';
  148. }
  149. else if (action == "down") {
  150. button.className= 'clsAPButtonPressed';
  151. }
  152. }
  153. }
  154. //change the button with the pressed look
  155. function CAlignmentPicker_setActiveAlignment(sAlignment)
  156. {
  157. this.m_sAlignment = sAlignment;
  158. this.m_sActiveButtonId = this.m_sRef+'_'+(this.m_sAlignment == "" ? "DF" : this.m_sAlignment);
  159. }
  160. //change the alignment and apply it
  161. function CAlignmentPicker_setAlignment(sAlignment)
  162. {
  163. if (this.m_sAlignment != sAlignment) {
  164. this.m_sAlignment = sAlignment;
  165. if (typeof this.m_sCallBackFunction == 'string' && this.m_sCallBackFunction !== null && this.m_sCallBackFunction !== "")
  166. {
  167. var theCommand = this.m_sCallBackFunction + '("' + this.m_sAlignment + '")';
  168. eval (theCommand);
  169. }
  170. }
  171. //hide the picker
  172. this.hide();
  173. }
  174. //get the current alignment
  175. function CAlignmentPicker_getAlignment()
  176. {
  177. return this.m_sAlignment;
  178. }
  179. var apCodes = ['TL','TC','TR',
  180. 'ML','MC','MR',
  181. 'BL','BC','BR',
  182. 'DF'];
  183. CAlignmentPicker.prototype.init = CAlignmentPicker_init;
  184. CAlignmentPicker.prototype.draw = CAlignmentPicker_draw;
  185. CAlignmentPicker.prototype.togglePicker = CAlignmentPicker_togglePicker;
  186. CAlignmentPicker.prototype.show = CAlignmentPicker_show;
  187. CAlignmentPicker.prototype.hide = CAlignmentPicker_hide;
  188. CAlignmentPicker.prototype.setActiveAlignment = CAlignmentPicker_setActiveAlignment;
  189. CAlignmentPicker.prototype.setAlignment = CAlignmentPicker_setAlignment;
  190. CAlignmentPicker.prototype.getAlignment = CAlignmentPicker_getAlignment;
  191. CAlignmentPicker.prototype.preventBubbling = CAlignmentPicker_preventBubbling;
  192. CAlignmentPicker.prototype.buttonMouseHandler = CAlignmentPicker_buttonMouseHandler;