home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / controls / htmlarea / dialog.js < prev    next >
Text File  |  2004-03-08  |  2KB  |  74 lines

  1. // htmlArea v3.0 - Copyright (c) 2003-2004 interactivetools.com, inc.
  2. // This copyright notice MUST stay intact for use (see license.txt).
  3. //
  4. // Portions (c) dynarch.com, 2003-2004
  5. //
  6. // A free WYSIWYG editor replacement for <textarea> fields.
  7. // For full source code and docs, visit http://www.interactivetools.com/
  8. //
  9. // Version 3.0 developed by Mihai Bazon.
  10. //   http://dynarch.com/mishoo
  11. //
  12. // $Id: dialog.js,v 1.5 2004/03/03 11:22:40 mschering Exp $
  13.  
  14. // Though "Dialog" looks like an object, it isn't really an object.  Instead
  15. // it's just namespace for protecting global symbols.
  16.  
  17. function Dialog(url, action, init) {
  18.     if (typeof init == "undefined") {
  19.         init = window;    // pass this window object by default
  20.     }
  21.     Dialog._geckoOpenModal(url, action, init);
  22. };
  23.  
  24. Dialog._parentEvent = function(ev) {
  25.     setTimeout( function() { if (Dialog._modal && !Dialog._modal.closed) { Dialog._modal.focus() } }, 50);
  26.     if (Dialog._modal && !Dialog._modal.closed) {
  27.         HTMLArea._stopEvent(ev);
  28.     }
  29. };
  30.  
  31.  
  32. // should be a function, the return handler of the currently opened dialog.
  33. Dialog._return = null;
  34.  
  35. // constant, the currently opened dialog
  36. Dialog._modal = null;
  37.  
  38. // the dialog will read it's args from this variable
  39. Dialog._arguments = null;
  40.  
  41. Dialog._geckoOpenModal = function(url, action, init) {
  42.     var dlg = window.open(url, "hadialog",
  43.                   "toolbar=no,menubar=no,personalbar=no,width=10,height=10," +
  44.                   "scrollbars=no,resizable=yes");
  45.     Dialog._modal = dlg;
  46.     Dialog._arguments = init;
  47.  
  48.     // capture some window's events
  49.     function capwin(w) {
  50.         HTMLArea._addEvent(w, "click", Dialog._parentEvent);
  51.         HTMLArea._addEvent(w, "mousedown", Dialog._parentEvent);
  52.         HTMLArea._addEvent(w, "focus", Dialog._parentEvent);
  53.     };
  54.     // release the captured events
  55.     function relwin(w) {
  56.         HTMLArea._removeEvent(w, "click", Dialog._parentEvent);
  57.         HTMLArea._removeEvent(w, "mousedown", Dialog._parentEvent);
  58.         HTMLArea._removeEvent(w, "focus", Dialog._parentEvent);
  59.     };
  60.     capwin(window);
  61.     // capture other frames
  62.     for (var i = 0; i < window.frames.length; capwin(window.frames[i++]));
  63.     // make up a function to be called when the Dialog ends.
  64.     Dialog._return = function (val) {
  65.         if (val && action) {
  66.             action(val);
  67.         }
  68.         relwin(window);
  69.         // capture other frames
  70.         for (var i = 0; i < window.frames.length; relwin(window.frames[i++]));
  71.         Dialog._modal = null;
  72.     };
  73. };
  74.