RGraph.modaldialog.js 11 KB

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