2 * o------------------------------------------------------------------------------o
3 * | This file is part of the RGraph package - you can learn more at: |
5 * | http://www.rgraph.net |
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: |
11 * | http://www.rgraph.net/LICENSE.txt |
12 * o------------------------------------------------------------------------------o
16 ModalDialog.dialog = null;
17 ModalDialog.background = null;
18 ModalDialog.offset = 50;
19 ModalDialog.events = [];
22 * Shows the dialog with the supplied DIV acting as the contents
24 * @param string id The ID of the DIV to use as the dialogs contents
25 * @param int width The width of the dialog
27 ModalDialog.Show = function (id, width)
30 ModalDialog.width = width;
32 ModalDialog.ShowBackground();
33 ModalDialog.ShowDialog();
35 // Install the event handlers
36 window.onresize = ModalDialog.Resize;
39 // Call them initially
42 ModalDialog.FireCustomEvent('onmodaldialog');
47 * Shows the background semi-transparent darkened DIV
49 ModalDialog.ShowBackground = function ()
51 // Create the background if neccessary
52 ModalDialog.background = document.createElement('DIV');
53 ModalDialog.background.className = 'ModalDialog_background';
54 ModalDialog.background.style.position = 'fixed';
55 ModalDialog.background.style.top = 0;
56 ModalDialog.background.style.left = 0;
57 ModalDialog.background.style.width = (screen.width + 100) + 'px';
58 ModalDialog.background.style.height = (screen.height + 100) + 'px';
59 ModalDialog.background.style.backgroundColor = 'rgb(204,204,204)';
60 ModalDialog.background.style.opacity = 0;
61 ModalDialog.background.style.zIndex = 3276;
62 ModalDialog.background.style.filter = "Alpha(opacity=50)";
64 document.body.appendChild(ModalDialog.background);
66 ModalDialog.background.style.visibility = 'visible';
71 * Shows the dialog itself
73 ModalDialog.ShowDialog = function ()
75 // Create the DIV if necessary
76 if (!ModalDialog.dialog) {
77 ModalDialog.dialog = document.createElement('DIV');
79 ModalDialog.dialog.id = 'ModalDialog_dialog';
80 ModalDialog.dialog.className = 'ModalDialog_dialog';
82 var borderRadius = '15px';
84 ModalDialog.dialog.style.borderRadius = borderRadius;
85 ModalDialog.dialog.style.MozBorderRadius = borderRadius;
86 ModalDialog.dialog.style.WebkitBorderRadius = borderRadius;
88 ModalDialog.dialog.style.boxShadow = '3px 3px 3px rgba(96,96,96,0.5)';
89 ModalDialog.dialog.style.MozBoxShadow = '3px 3px 3px rgba(96,96,96,0.5)';
90 ModalDialog.dialog.style.WebkitBoxShadow = 'rgba(96,96,96,0.5) 3px 3px 3px';
92 ModalDialog.dialog.style.position = 'fixed';
93 ModalDialog.dialog.style.backgroundColor = 'white';
94 ModalDialog.dialog.style.width = parseInt(ModalDialog.width) + 'px';
95 ModalDialog.dialog.style.border = '2px solid #999';
96 ModalDialog.dialog.style.zIndex = 32767;
97 ModalDialog.dialog.style.padding = '5px';
98 ModalDialog.dialog.style.paddingTop = '25px';
99 ModalDialog.dialog.style.opacity = 0;
102 ModalDialog.dialog.style.zIndex = 32767;
107 // Accomodate various browsers
108 if (navigator.userAgent.indexOf('Opera') != -1) {
109 ModalDialog.dialog.style.paddingTop = '25px';
111 } else if (navigator.userAgent.indexOf('MSIE') != -1) {
112 ModalDialog.dialog.style.paddingTop = '25px';
114 } else if (navigator.userAgent.indexOf('Safari') != -1) {
115 ModalDialog.dialog.style.paddingTop = '25px';
118 document.body.appendChild(ModalDialog.dialog);
121 // Now create the grey bar at the top of the dialog
122 var bar = document.createElement('DIV');
123 bar.className = 'ModalDialog_topbar';
126 bar.style.width = '100%';//(ModalDialog.dialog.offsetWidth - 4) + 'px';
127 bar.style.height = '20px';
128 bar.style.backgroundColor = '#bbb';
129 bar.style.borderBottom = '2px solid #999';
130 //bar.style.zIndex = 50000;
131 bar.style.position = 'absolute';
132 var borderRadius = '11px';
133 bar.style.WebkitBorderTopLeftRadius = borderRadius;
134 bar.style.WebkitBorderTopRightRadius = borderRadius;
135 bar.style.MozBorderRadiusTopleft = borderRadius;
136 bar.style.MozBorderRadiusTopright = borderRadius;
137 bar.style.borderTopRightRadius = borderRadius;
138 bar.style.borderTopLeftRadius = borderRadius;
139 ModalDialog.dialog.appendChild(bar);
141 // Add the content div
142 var content = document.createElement('DIV');
143 //content.style.paddingTop = '20px';
144 content.style.width = '100%';
145 content.style.height = '100%';
146 ModalDialog.dialog.appendChild(content);
148 content.innerHTML = document.getElementById(ModalDialog.id).innerHTML;
150 // Now reposition the dialog in the center
151 ModalDialog.dialog.style.left = (document.body.offsetWidth / 2) - (ModalDialog.dialog.offsetWidth / 2) + 'px';
152 ModalDialog.dialog.style.top = '30%';
156 ModalDialog.dialog.style.visibility = 'visible';
158 // A simple fade-in effect
159 setTimeout('ModalDialog.dialog.style.opacity = 0.2', 50);
160 setTimeout('ModalDialog.dialog.style.opacity = 0.4', 100);
161 setTimeout('ModalDialog.dialog.style.opacity = 0.6', 150);
162 setTimeout('ModalDialog.dialog.style.opacity = 0.8', 200);
163 setTimeout('ModalDialog.dialog.style.opacity = 1', 250);
165 setTimeout('ModalDialog.background.style.opacity = 0.1', 50);
166 setTimeout('ModalDialog.background.style.opacity = 0.2', 100);
167 setTimeout('ModalDialog.background.style.opacity = 0.3', 150);
168 setTimeout('ModalDialog.background.style.opacity = 0.4', 200);
169 setTimeout('ModalDialog.background.style.opacity = 0.5', 250);
176 ModalDialog.Close = function ()
178 if (ModalDialog.dialog) {
179 ModalDialog.dialog.style.visibility = 'hidden';
180 ModalDialog.dialog.style.opacity = 0;
183 if (ModalDialog.background) {
184 ModalDialog.background.style.visibility = 'hidden';
185 ModalDialog.background.style.opacity = 0;
190 ModalDialog.Hide = ModalDialog.Close
194 * Accommodate the window being resized
196 ModalDialog.Resize = function ()
198 if (ModalDialog.dialog) {
199 ModalDialog.dialog.style.left = (document.body.offsetWidth / 2) - (ModalDialog.dialog.offsetWidth / 2) + 'px';
202 ModalDialog.background.style.width = '2500px';
203 ModalDialog.background.style.height = '2500px';
208 * Returns the page height
210 * @return int The page height
212 ModalDialog.AddCustomEventListener = function (name, func)
214 if (typeof(ModalDialog.events) == 'undefined') {
215 ModalDialog.events = [];
218 ModalDialog.events.push([name, func]);
223 * Used to fire the ModalDialog custom event
225 * @param object obj The graph object that fires the event
226 * @param string event The name of the event to fire
228 ModalDialog.FireCustomEvent = function (name)
230 for (var i=0; i<ModalDialog.events.length; ++i) {
231 if (typeof(ModalDialog.events[i][0]) == 'string' && ModalDialog.events[i][0] == name && typeof(ModalDialog.events[i][1]) == 'function') {
232 ModalDialog.events[i][1]();
239 * Returns true if the browser is IE8
241 ModalDialog.isIE8 = function ()
243 return document.all && (navigatot.userAgent.indexOf('MSIE 8') > 0);