]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/util/window.js
internal: an alternative to default_focus
[working/Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / util / window.js
1 dump('entering util/window.js\n');
2
3 if (typeof util == 'undefined') util = {};
4 util.window = function () {
5     JSAN.use('util.error'); this.error = new util.error(); this.win = window;
6     return this;
7 };
8
9 util.window.prototype = {
10     
11     // list of open window references, used for debugging in shell
12     'win_list' : [],    
13
14     // list of Top Level menu interface window references
15     'appshell_list' : [],    
16
17     // list of documents for debugging.  BROKEN
18     'doc_list' : [],    
19
20     // This number gets put into the title bar for Top Level menu interface windows
21     'appshell_name_increment' : function() {
22         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
23         if (typeof data.appshell_name_increment == 'undefined') {
24             data.appshell_name_increment = 1;
25         } else {
26             data.appshell_name_increment++;
27         }
28         data.stash('appshell_name_increment');
29         return data.appshell_name_increment;
30     },
31
32     // From: Bryan White on netscape.public.mozilla.xpfe, Oct 13, 2004
33     // Message-ID: <ckjh7a$18q1@ripley.netscape.com>
34     // Modified by Jason for Evergreen
35     'SafeWindowOpenDialog' : function (url,title,features) {
36         var w;
37
38         const CI = Components.interfaces;
39         const PB = Components.classes["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefBranch);
40
41         var blocked = false;
42         try {
43             // pref 'dom.disable_open_during_load' is the main popup blocker preference
44             blocked = PB.getBoolPref("dom.disable_open_during_load");
45             if(blocked) PB.setBoolPref("dom.disable_open_during_load",false);
46             w = this.win.openDialog.apply(this.win,arguments);
47         } catch(E) {
48             this.error.sdump('D_ERROR','window.SafeWindowOpenDialog: ' + E + '\n');
49             throw(E);
50         }
51         if(blocked) PB.setBoolPref("dom.disable_open_during_load",true);
52
53         return w;
54     },
55
56     // This has basically become a compatibility wrapper for openDialog.
57     'open' : function(url,title,features,my_xulG) {
58         var key;
59         if (!features) features = 'chrome,dialog=no';
60         if (!features.match(/dialog/)) features = 'dialog=no,' + features; // window.open doesn't do dialog by default
61         if (!features.match(/chrome/)) features = 'chrome=no,' + features; // And window.open doesn't assume chrome by default
62         var outArgs = Array.prototype.slice.call(arguments);
63         outArgs[1] = title;
64         outArgs[2] = features;
65         return this.openDialog.apply(this, outArgs); // Pass to openDialog
66     },
67
68     'openDialog' : function(url,title,features,my_xulG) {
69         var key;
70         if (!title) title = '_blank';
71         if (!features) features = 'chrome'; // Note that this is a default for openDialog anyway
72         var outArgs = Array.prototype.slice.call(arguments);
73         outArgs[1] = title;
74         outArgs[2] = features;
75         this.error.sdump('D_WIN', 'opening ' + url + ', ' + title + ', ' + features + ' from ' + this.win + '\n');
76         var data;
77         var w = this.SafeWindowOpenDialog.apply(this, outArgs);
78         if (features.match(/modal/) && my_xulG) { 
79             return my_xulG;
80         } else {
81             if (my_xulG) {
82                 if (get_contentWindow(w)) {
83                     get_contentWindow(w).xulG = my_xulG;
84                 } else {
85                     w.xulG = my_xulG;
86                 }
87             }
88         }
89         /*
90         setTimeout( 
91             function() { 
92                 try { w.title = title; } catch(E) { dump('**'+E+'\n'); }
93                 try { w.document.title = title; } catch(E) { dump('**'+E+'\n'); }
94             }, 0 
95         );
96         */
97         return w;
98     }
99 }
100
101 dump('exiting util/window.js\n');