RGraph.modaldialog.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /**
  2. * o------------------------------------------------------------------------------o
  3. * | This file is part of the RGraph package - you can learn more at: |
  4. * | |
  5. * | http://www.rgraph.net |
  6. * | |
  7. * | This package is licensed under the RGraph license. For all kinds of business |
  8. * | purposes there is a small one-time licensing fee to pay and for non |
  9. * | commercial purposes it is free to use. You can read the full license here: |
  10. * | |
  11. * | http://www.rgraph.net/license |
  12. * o------------------------------------------------------------------------------o
  13. */
  14. ModalDialog = {}
  15. ModalDialog.dialog = null;
  16. ModalDialog.background = null;
  17. ModalDialog.offset = 50;
  18. ModalDialog.events = [];
  19. /**
  20. * Shows the dialog with the supplied DIV acting as the contents
  21. *
  22. * @param string id The ID of the DIV to use as the dialogs contents
  23. * @param int width The width of the dialog
  24. */
  25. ModalDialog.Show = function (id, width)
  26. {
  27. ModalDialog.id = id;
  28. ModalDialog.width = width;
  29. ModalDialog.ShowBackground();
  30. ModalDialog.ShowDialog();
  31. // Install the event handlers
  32. window.onresize = ModalDialog.Resize;
  33. // Call them initially
  34. ModalDialog.Resize();
  35. if (typeof(ModalDialog.onmodaldialog) == 'function') {
  36. ModalDialog.onmodaldialog();
  37. }
  38. ModalDialog.FireCustomEvent('onmodaldialog');
  39. }
  40. /**
  41. * Shows the background semi-transparent darkened DIV
  42. */
  43. ModalDialog.ShowBackground = function ()
  44. {
  45. // Create the background if neccessary
  46. ModalDialog.background = document.createElement('DIV');
  47. ModalDialog.background.className = 'ModalDialog_background';
  48. ModalDialog.background.style.position = 'fixed';
  49. ModalDialog.background.style.top = 0;
  50. ModalDialog.background.style.left = 0;
  51. ModalDialog.background.style.width = (screen.width + 100) + 'px';
  52. ModalDialog.background.style.height = (screen.height + 100) + 'px';
  53. ModalDialog.background.style.backgroundColor = 'rgb(204,204,204)';
  54. ModalDialog.background.style.opacity = 0;
  55. ModalDialog.background.style.zIndex = 3276;
  56. ModalDialog.background.style.filter = "Alpha(opacity=50)";
  57. document.body.appendChild(ModalDialog.background);
  58. ModalDialog.background.style.visibility = 'visible';
  59. }
  60. /**
  61. * Shows the dialog itself
  62. */
  63. ModalDialog.ShowDialog = function ()
  64. {
  65. // Create the DIV if necessary
  66. // Jan 2012- Changed so that the dialog is ALWAYS (re)created
  67. if (!ModalDialog.dialog || true) {
  68. ModalDialog.dialog = document.createElement('DIV');
  69. ModalDialog.dialog.id = 'ModalDialog_dialog';
  70. ModalDialog.dialog.className = 'ModalDialog_dialog';
  71. var borderRadius = '15px';
  72. ModalDialog.dialog.style.borderRadius = borderRadius;
  73. ModalDialog.dialog.style.MozBorderRadius = borderRadius;
  74. ModalDialog.dialog.style.WebkitBorderRadius = borderRadius;
  75. ModalDialog.dialog.style.boxShadow = '3px 3px 3px rgba(96,96,96,0.5)';
  76. ModalDialog.dialog.style.MozBoxShadow = '3px 3px 3px rgba(96,96,96,0.5)';
  77. ModalDialog.dialog.style.WebkitBoxShadow = 'rgba(96,96,96,0.5) 3px 3px 3px';
  78. ModalDialog.dialog.style.position = 'fixed';
  79. ModalDialog.dialog.style.backgroundColor = 'white';
  80. ModalDialog.dialog.style.width = parseInt(ModalDialog.width) + 'px';
  81. ModalDialog.dialog.style.border = '2px solid #999';
  82. ModalDialog.dialog.style.zIndex = 32767;
  83. ModalDialog.dialog.style.padding = '5px';
  84. ModalDialog.dialog.style.paddingTop = '25px';
  85. ModalDialog.dialog.style.opacity = 0;
  86. if (document.all) {
  87. ModalDialog.dialog.style.zIndex = 32767;
  88. }
  89. // Accomodate various browsers
  90. if (navigator.userAgent.indexOf('Opera') != -1) {
  91. ModalDialog.dialog.style.paddingTop = '25px';
  92. } else if (navigator.userAgent.indexOf('MSIE') != -1) {
  93. ModalDialog.dialog.style.paddingTop = '25px';
  94. } else if (navigator.userAgent.indexOf('Safari') != -1) {
  95. ModalDialog.dialog.style.paddingTop = '25px';
  96. }
  97. document.body.appendChild(ModalDialog.dialog);
  98. // Now create the grey bar at the top of the dialog
  99. var bar = document.createElement('DIV');
  100. bar.className = 'ModalDialog_topbar';
  101. bar.style.top = 0;
  102. bar.style.left = 0;
  103. bar.style.width = '100%';//(ModalDialog.dialog.offsetWidth - 4) + 'px';
  104. bar.style.height = '20px';
  105. bar.style.backgroundColor = '#bbb';
  106. bar.style.borderBottom = '2px solid #999';
  107. //bar.style.zIndex = 50000;
  108. bar.style.position = 'absolute';
  109. var borderRadius = '11px';
  110. bar.style.WebkitBorderTopLeftRadius = borderRadius;
  111. bar.style.WebkitBorderTopRightRadius = borderRadius;
  112. bar.style.MozBorderRadiusTopleft = borderRadius;
  113. bar.style.MozBorderRadiusTopright = borderRadius;
  114. bar.style.borderTopRightRadius = borderRadius;
  115. bar.style.borderTopLeftRadius = borderRadius;
  116. ModalDialog.dialog.appendChild(bar);
  117. // Add the content div
  118. var content = document.createElement('DIV');
  119. //content.style.paddingTop = '20px';
  120. content.style.width = '100%';
  121. content.style.height = '100%';
  122. ModalDialog.dialog.appendChild(content);
  123. if (ModalDialog.id.toLowerCase().substring(0, 7) == 'string:') {
  124. content.innerHTML = ModalDialog.id.substring(7);
  125. } else {
  126. content.innerHTML = document.getElementById(ModalDialog.id).innerHTML;
  127. }
  128. // Now reposition the dialog in the center
  129. ModalDialog.dialog.style.left = (document.body.offsetWidth / 2) - (ModalDialog.dialog.offsetWidth / 2) + 'px';
  130. ModalDialog.dialog.style.top = '30%';
  131. }
  132. // Show the dialog
  133. ModalDialog.dialog.style.visibility = 'visible';
  134. // A simple fade-in effect
  135. setTimeout('ModalDialog.dialog.style.opacity = 0.2', 50);
  136. setTimeout('ModalDialog.dialog.style.opacity = 0.4', 100);
  137. setTimeout('ModalDialog.dialog.style.opacity = 0.6', 150);
  138. setTimeout('ModalDialog.dialog.style.opacity = 0.8', 200);
  139. setTimeout('ModalDialog.dialog.style.opacity = 1', 250);
  140. setTimeout('ModalDialog.background.style.opacity = 0.1', 50);
  141. setTimeout('ModalDialog.background.style.opacity = 0.2', 100);
  142. setTimeout('ModalDialog.background.style.opacity = 0.3', 150);
  143. setTimeout('ModalDialog.background.style.opacity = 0.4', 200);
  144. setTimeout('ModalDialog.background.style.opacity = 0.5', 250);
  145. }
  146. /**
  147. * Hides everything
  148. */
  149. ModalDialog.Close = function ()
  150. {
  151. if (ModalDialog.dialog) {
  152. // February 2012 - now remove the dialog node from the DOM
  153. if (document.getElementById(ModalDialog.dialog.id)) {
  154. document.body.removeChild(ModalDialog.dialog);
  155. }
  156. ModalDialog.dialog.style.visibility = 'hidden';
  157. ModalDialog.dialog.style.opacity = 0;
  158. }
  159. if (ModalDialog.background) {
  160. ModalDialog.background.style.visibility = 'hidden';
  161. ModalDialog.background.style.opacity = 0;
  162. // February 2012 - now remove the dialog node from the DOM
  163. if (document.getElementById(ModalDialog.background.id)) {
  164. document.body.removeChild(ModalDialog.background);
  165. }
  166. }
  167. }
  168. // An alias
  169. ModalDialog.Hide = ModalDialog.Close
  170. /**
  171. * Accommodate the window being resized
  172. */
  173. ModalDialog.Resize = function ()
  174. {
  175. if (ModalDialog.dialog) {
  176. ModalDialog.dialog.style.left = (document.body.offsetWidth / 2) - (ModalDialog.dialog.offsetWidth / 2) + 'px';
  177. }
  178. ModalDialog.background.style.width = '2500px';
  179. ModalDialog.background.style.height = '2500px';
  180. }
  181. /**
  182. * Returns the page height
  183. *
  184. * @return int The page height
  185. */
  186. ModalDialog.AddCustomEventListener = function (name, func)
  187. {
  188. if (typeof(ModalDialog.events) == 'undefined') {
  189. ModalDialog.events = [];
  190. }
  191. ModalDialog.events.push([name, func]);
  192. }
  193. /**
  194. * Used to fire the ModalDialog custom event
  195. *
  196. * @param object obj The graph object that fires the event
  197. * @param string event The name of the event to fire
  198. */
  199. ModalDialog.FireCustomEvent = function (name)
  200. {
  201. for (var i=0; i<ModalDialog.events.length; ++i) {
  202. if (typeof(ModalDialog.events[i][0]) == 'string' && ModalDialog.events[i][0] == name && typeof(ModalDialog.events[i][1]) == 'function') {
  203. ModalDialog.events[i][1]();
  204. }
  205. }
  206. }
  207. /**
  208. * Returns true if the browser is IE8
  209. */
  210. ModalDialog.isIE8 = function ()
  211. {
  212. return document.all && (navigator.userAgent.indexOf('MSIE 8') > 0);
  213. }