A Qcodo based CMS/ecommerce framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
6.6 KiB

12 years ago
  1. /////////////////////////////////////////////
  2. // Control: Dialog Box functionality
  3. /////////////////////////////////////////////
  4. qcodo.registerDialogBox = function(mixControl, strMatteColor, intMatteOpacity, blnMatteClickable, blnAnyKeyCloses) {
  5. // Initialize the Event Handler
  6. qcodo.handleEvent();
  7. // Get Control/Wrapper
  8. var objControl; if (!(objControl = qcodo.getControl(mixControl))) return;
  9. var objWrapper = objControl.wrapper;
  10. // DialogBox MUST be at the "top level" in the DOM, a direct child of the FORM
  11. document.getElementById(document.getElementById("Qform__FormId").value).appendChild(objWrapper);
  12. // Setup the DialogBoxBackground (DbBg) if applicable
  13. objWrapper.dbBg = document.getElementById(objWrapper.id + "dbbg");
  14. var objDbBg = objWrapper.dbBg;
  15. if (!objDbBg) {
  16. var objDbBg = document.createElement("div");
  17. objDbBg.id = objWrapper.id + "dbbg";
  18. document.getElementById(document.getElementById("Qform__FormId").value).appendChild(objDbBg);
  19. // Setup the Object Links
  20. objWrapper.dbBg = objDbBg;
  21. objDbBg.wrapper = objWrapper;
  22. if (qcodo.isBrowser(qcodo.IE)) {
  23. var objIframe = document.createElement("iframe");
  24. objIframe.id = objWrapper.id + "dbbgframe";
  25. objIframe.style.left = "0px";
  26. objIframe.style.top = "0px";
  27. objIframe.style.position = "absolute";
  28. objIframe.style.filter = "alpha(opacity=0)";
  29. objIframe.src = "javascript: false;";
  30. objIframe.frameBorder = 0;
  31. objIframe.scrolling = "no";
  32. objIframe.style.zIndex = 990;
  33. objIframe.display = "none";
  34. document.getElementById(document.getElementById("Qform__FormId").value).appendChild(objIframe);
  35. objWrapper.dbBgFrame = objIframe;
  36. };
  37. };
  38. objWrapper.handleResize = function(objEvent) {
  39. objEvent = qcodo.handleEvent(objEvent);
  40. if (objEvent.target) {
  41. if ((objEvent.target.nodeName.toLowerCase() == 'div') || (objEvent.target.nodeName.toLowerCase() == 'span'))
  42. return;
  43. };
  44. // Restore from Link
  45. var objWrapper = qcodo.activeDialogBox;
  46. var objDbBg = objWrapper.dbBg;
  47. var objDbBgFrame = objWrapper.dbBgFrame;
  48. // Hide Everything
  49. objWrapper.style.display = "none";
  50. objDbBg.style.display = "none";
  51. if (objDbBgFrame) objDbBgFrame.style.display = "none";
  52. // Setup Events
  53. qcodo.handleEvent(objEvent);
  54. // Show Everything
  55. objWrapper.style.display = "inline";
  56. objDbBg.style.display = "block";
  57. if (objDbBgFrame) objDbBgFrame.style.display = "block";
  58. // DbBg Re-Setup
  59. objDbBg.style.width = Math.max(qcodo.page.width, qcodo.client.width) + "px";
  60. objDbBg.style.height = Math.max(qcodo.page.height, qcodo.client.height) + "px";
  61. if (objDbBgFrame) {
  62. objDbBgFrame.style.width = Math.max(qcodo.page.width, qcodo.client.width) + "px";
  63. objDbBgFrame.style.height = Math.max(qcodo.page.height, qcodo.client.height) + "px";
  64. };
  65. // Wrapper Re-Setup
  66. var intWidth = objWrapper.offsetWidth;
  67. var intHeight = objWrapper.offsetHeight;
  68. var intTop = Math.round((qcodo.client.height - intHeight) / 2) + qcodo.scroll.y;
  69. var intLeft = Math.round((qcodo.client.width - intWidth) / 2) + qcodo.scroll.x;
  70. objWrapper.setAbsolutePosition(intLeft, intTop);
  71. return true;
  72. };
  73. objWrapper.handleKeyPress = function(objEvent) {
  74. objEvent = qcodo.handleEvent(objEvent);
  75. qcodo.terminateEvent(objEvent);
  76. var objWrapper = qcodo.activeDialogBox;
  77. objWrapper.hideDialogBox();
  78. return false;
  79. };
  80. objWrapper.showDialogBox = function() {
  81. // Restore from Object Link
  82. var objDbBg = this.dbBg;
  83. var objDbBgFrame = this.dbBgFrame;
  84. // Hide Everything
  85. objWrapper.style.display = "none";
  86. objDbBg.style.display = "none";
  87. if (objDbBgFrame) objDbBgFrame.style.display = "none";
  88. // Setup Events
  89. qcodo.handleEvent();
  90. // Show Everything
  91. objDbBg.style.display = "block";
  92. if (objDbBgFrame) objDbBgFrame.style.display = "block";
  93. this.toggleDisplay("show");
  94. // DbBg Re-Setup
  95. objDbBg.style.width = Math.max(qcodo.page.width, qcodo.client.width) + "px";
  96. objDbBg.style.height = Math.max(qcodo.page.height, qcodo.client.height) + "px";
  97. if (objDbBgFrame) {
  98. objDbBgFrame.style.width = Math.max(qcodo.page.width, qcodo.client.width) + "px";
  99. objDbBgFrame.style.height = Math.max(qcodo.page.height, qcodo.client.height) + "px";
  100. };
  101. // Wrapper Re-Setup
  102. var intWidth = objWrapper.offsetWidth;
  103. var intHeight = objWrapper.offsetHeight;
  104. var intTop = Math.round((qcodo.client.height - intHeight) / 2) + qcodo.scroll.y;
  105. var intLeft = Math.round((qcodo.client.width - intWidth) / 2) + qcodo.scroll.x;
  106. objWrapper.setAbsolutePosition(intLeft, intTop);
  107. // Set Window OnResize Handling
  108. window.onresize = this.handleResize;
  109. window.onscroll = this.handleResize;
  110. qcodo.activeDialogBox = this;
  111. // If we have blnMatteClickable and blnAnyKeyCloses
  112. if (objWrapper.anyKeyCloses) {
  113. document.body.onkeypress = this.handleKeyPress;
  114. objWrapper.control.focus();
  115. };
  116. };
  117. objWrapper.hideDialogBox = function() {
  118. var objWrapper = this;
  119. if (this.id.indexOf("_ctldbbg") > 0)
  120. objWrapper = this.wrapper;
  121. objWrapper.dbBg.style.display = "none";
  122. if (objWrapper.dbBgFrame) objWrapper.dbBgFrame.style.display = "none";
  123. objWrapper.toggleDisplay("hide");
  124. // Unsetup OnResize Handling
  125. window.onresize = null;
  126. window.onscroll = null;
  127. // Unsetup KeyPress Closing
  128. document.body.onkeypress = null;
  129. // Unsetup ActiveDialogBox
  130. qcodo.activeDialogBox = null;
  131. };
  132. // Initial Wrapper Setup
  133. objWrapper.style.zIndex = 999;
  134. objWrapper.position = "absolute";
  135. objWrapper.anyKeyCloses = blnAnyKeyCloses;
  136. // Initial DbBg Setup
  137. objDbBg.style.position = "absolute";
  138. objDbBg.style.zIndex = 998;
  139. objDbBg.style.top = "0px";
  140. objDbBg.style.left = "0px";
  141. if (qcodo.isBrowser(qcodo.IE))
  142. objDbBg.style.overflow = "auto";
  143. else
  144. objDbBg.style.overflow = "hide";
  145. if (blnMatteClickable) {
  146. objDbBg.style.cursor = "pointer";
  147. objDbBg.onclick = objWrapper.hideDialogBox;
  148. } else {
  149. objDbBg.style.cursor = "url(" + qc.imageAssets + "/_core/move_nodrop.cur), auto";
  150. objDbBg.onclick = null;
  151. };
  152. // Background Color and Opacity
  153. objDbBg.style.backgroundColor = strMatteColor;
  154. if (qcodo.isBrowser(qcodo.IE))
  155. objDbBg.style.filter = "alpha(opacity=" + intMatteOpacity + ")";
  156. else
  157. objDbBg.style.opacity = intMatteOpacity / 100.0;
  158. // Other Random Stuff
  159. objDbBg.style.fontSize = "1px";
  160. objDbBg.innerHTML = " ";
  161. // Perform a Show or Hide (depending on state)
  162. if (objWrapper.style.display == 'none')
  163. objWrapper.hideDialogBox();
  164. else
  165. objWrapper.showDialogBox();
  166. };
  167. //////////////////
  168. // Qcodo Shortcuts
  169. //////////////////
  170. qc.regDB = qcodo.registerDialogBox;