1 dump('entering util/window.js\n');
3 if (typeof util == 'undefined') util = {};
4 util.window = function () {
5 JSAN.use('util.error'); this.error = new util.error(); this.win = window;
9 util.window.prototype = {
11 // list of open window references, used for debugging in shell
14 // list of Top Level menu interface window references
17 // list of documents for debugging. BROKEN
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;
26 data.appshell_name_increment++;
28 data.stash('appshell_name_increment');
29 return data.appshell_name_increment;
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 'SafeWindowOpen' : function (url,title,features) {
38 const CI = Components.interfaces;
39 const PB = Components.classes["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefBranch);
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.open(url,title,features);
48 this.error.sdump('D_ERROR','window.SafeWindowOpen: ' + E + '\n');
51 if(blocked) PB.setBoolPref("dom.disable_open_during_load",true);
56 'SafeWindowOpenDialog' : function (url,title,features) {
59 const CI = Components.interfaces;
60 const PB = Components.classes["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefBranch);
64 // pref 'dom.disable_open_during_load' is the main popup blocker preference
65 blocked = PB.getBoolPref("dom.disable_open_during_load");
66 if(blocked) PB.setBoolPref("dom.disable_open_during_load",false);
67 w = this.win.openDialog.apply(this.win,arguments);
69 this.error.sdump('D_ERROR','window.SafeWindowOpen: ' + E + '\n');
72 if(blocked) PB.setBoolPref("dom.disable_open_during_load",true);
77 'open' : function(url,title,features,my_xulG) {
79 if (!title) title = '_blank';
80 if (!features) features = 'chrome';
81 this.error.sdump('D_WIN', 'opening ' + url + ', ' + title + ', ' + features + ' from ' + this.win + '\n');
83 if (features.match(/modal/) && my_xulG) {
84 JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.init({'via':'stash'});
85 if (typeof data.modal_xulG_stack == 'undefined') data.modal_xulG_stack = {};
86 /* FIXME - not a perfect key.. could imagine two top-level windows both opening modal windows */
88 if (typeof xulG == 'object') {
89 if (typeof xulG.url_prefix == 'function') {
90 key = key.replace( xulG.url_prefix('/'), '/' );
92 } else if (typeof url_prefix == 'function') {
93 key = key.replace( url_prefix('/'), '/' );
95 // oils://remote/ looks like http://server/ to files loaded off of it. That is, location.pathname ignores it.
96 // So remove it here, like we remove url_prefix.
97 key = key.replace('oils://remote/', '/');
98 if (typeof data.modal_xulG_stack[key] == 'undefined') data.modal_xulG_stack[key] = [];
99 data.modal_xulG_stack[key].push( my_xulG );
100 data.stash('modal_xulG_stack');
101 this.error.sdump('D_WIN','modal key = ' + key);
103 var w = this.SafeWindowOpen(url,title,features);
104 if (features.match(/modal/) && my_xulG) {
105 data.init({'via':'stash'});
106 var x = data.modal_xulG_stack[key].pop();
107 data.stash('modal_xulG_stack');
112 if (get_contentWindow(w)) {
113 get_contentWindow(w).xulG = my_xulG;
122 try { w.title = title; } catch(E) { dump('**'+E+'\n'); }
123 try { w.document.title = title; } catch(E) { dump('**'+E+'\n'); }
130 'openDialog' : function(url,title,features,my_xulG) {
132 if (!title) title = '_blank';
133 if (!features) features = 'chrome'; // Note that this is a default for openDialog anyway
134 var outArgs = Array.prototype.slice.call(arguments);
135 outArgs.splice(3,1); // Remove my_xulG
136 this.error.sdump('D_WIN', 'opening ' + url + ', ' + title + ', ' + features + ' from ' + this.win + '\n');
138 if (features.match(/modal/) && my_xulG) {
139 JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.init({'via':'stash'});
140 if (typeof data.modal_xulG_stack == 'undefined') data.modal_xulG_stack = {};
141 /* FIXME - not a perfect key.. could imagine two top-level windows both opening modal windows */
143 if (typeof xulG == 'object') {
144 if (typeof xulG.url_prefix == 'function') {
145 key = key.replace( xulG.url_prefix('/'), '/' );
147 } else if (typeof url_prefix == 'function') {
148 key = key.replace( url_prefix('/'), '/' );
150 // oils://remote/ looks like http://server/ to files loaded off of it. That is, location.pathname ignores it.
151 // So remove it here, like we remove url_prefix.
152 key = key.replace('oils://remote/', '/');
153 if (typeof data.modal_xulG_stack[key] == 'undefined') data.modal_xulG_stack[key] = [];
154 data.modal_xulG_stack[key].push( my_xulG );
155 data.stash('modal_xulG_stack');
156 this.error.sdump('D_WIN','modal key = ' + key);
158 var w = this.SafeWindowOpenDialog.apply(this, outArgs);
159 if (features.match(/modal/) && my_xulG) {
160 data.init({'via':'stash'});
161 var x = data.modal_xulG_stack[key].pop();
162 data.stash('modal_xulG_stack');
167 if (get_contentWindow(w)) {
168 get_contentWindow(w).xulG = my_xulG;
177 try { w.title = title; } catch(E) { dump('**'+E+'\n'); }
178 try { w.document.title = title; } catch(E) { dump('**'+E+'\n'); }
186 dump('exiting util/window.js\n');