initial support for multiple browser windows
[openemr.git] / library / dialog.js
blob65822556c72ff8dc032c81583e1e00ece65c2e56
1 // Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 // open a new cascaded window
9 function cascwin(url, winname, width, height, options) {
10  var mywin = window.parent ? window.parent : window;
11  var newx = 25, newy = 25;
12  if (!isNaN(mywin.screenX)) {
13   newx += mywin.screenX;
14   newy += mywin.screenY;
15  } else if (!isNaN(mywin.screenLeft)) {
16   newx += mywin.screenLeft;
17   newy += mywin.screenTop;
18  }
19  if ((newx + width) > screen.width || (newy + height) > screen.height) {
20   newx = 0;
21   newy = 0;
22  }
23  top.restoreSession();
24  return window.open(url, winname, options +
25   ",width="   + width + ",height="  + height +
26   ",left="    + newx  + ",top="     + newy   +
27   ",screenX=" + newx  + ",screenY=" + newy);
30 // recursive window focus-event grabber
31 function grabfocus(w) {
32  for (var i = 0; i < w.frames.length; ++i) grabfocus(w.frames[i]);
33  w.onfocus = top.imfocused;
35  // the following was tried and discarded because it's too invasive and
36  // does not help anyway, but i left it here for the curious.
37  //
38  // for (var i = 0; i < w.document.forms.length; ++i) {
39  //  var e = w.document.forms[i].elements;
40  //  for (var j = 0; j < e.length; ++j) {
41  //   e[j].onfocus = top.imfocused;
42  //  }
43  // }
46 // call this when a "modal" dialog is desired
47 function dlgopen(url, winname, width, height) {
48  if (top.modaldialog && ! top.modaldialog.closed) {
49   if (window.focus) top.modaldialog.focus();
50   if (top.modaldialog.confirm("OK to close this other popup window?")) {
51    top.modaldialog.close();
52    top.modaldialog = null;
53   } else {
54    return false;
55   }
56  }
57  top.modaldialog = cascwin(url, winname, width, height,
58   "resizable=1,scrollbars=1");
59  grabfocus(top);
60  return false;