]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js
use just one close handler for menu.js; small tweak to support that, and some debug...
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / OpenILS / global_util.js
1     function $(id) { return document.getElementById(id); }
2
3     function oils_unsaved_data_V() {
4         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
5         data.stash_retrieve();
6         if (typeof data.unsaved_data == 'undefined') { data.unsaved_data = 0; }
7         data.unsaved_data++;
8         window.oils_lock++;
9         data.stash('unsaved_data');
10         dump('incrementing window.oils_lock\n');
11         dump(location.href + ' window.oils_lock == ' + window.oils_lock + '\n');
12         dump('incrementing data.unsaved_data\n');
13         dump('data.unsaved_data == ' + data.unsaved_data + '\n');
14     }
15
16     function oils_unsaved_data_P(count) {
17         if (!count) { count = 1; }
18         dump('decrementing window.oils_lock by ' + count + '\n');
19         window.oils_lock -= count;
20         if (window.oils_lock < 0) { window.oils_lock = 0; }
21         dump(location.href + ' window.oils_lock == ' + window.oils_lock + '\n');
22         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
23         data.stash_retrieve();
24         if (typeof data.unsaved_data == 'undefined') { data.unsaved_data = 0; }
25         dump('decrementing data.unsaved_data by ' + count + '\n');
26         data.unsaved_data -= count;
27         if (data.unsaved_data < 0) { data.unsaved_data = 0; }
28         data.stash('unsaved_data');
29         dump('data.unsaved_data == ' + data.unsaved_data + '\n');
30     }
31
32     function oils_lock_page(params) {
33         dump('oils_lock_page\n');
34         if (!params) { params = {}; }
35         if (window.oils_lock > 0) {
36             if (!params.allow_multiple_locks) {
37                 return window.oils_lock;
38             }
39         }
40         if (typeof xulG != 'undefined') {
41             if (typeof xulG.unlock_tab == 'function') {
42                 dump('\twith xulG.lock_tab\n');
43                 xulG.lock_tab();
44             } else {
45                 dump('\twithout xulG.lock_tab\n');
46                 oils_unsaved_data_V();
47             }
48         } else {
49             dump('\twithout xulG.lock_tab\n');
50             oils_unsaved_data_V();
51         }
52         return window.oils_lock;
53     }
54
55     function oils_unlock_page(params) {
56         dump('oils_unlock_page\n');
57         if (typeof xulG != 'undefined') {
58             if (typeof xulG.unlock_tab == 'function') {
59                 dump('\twith xulG.unlock_tab\n');
60                 xulG.unlock_tab();
61             } else {
62                 dump('\twithout xulG.unlock_tab\n');
63                 oils_unsaved_data_P();
64             }
65         } else {
66             dump('\twithout xulG.unlock_tab\n');
67             oils_unsaved_data_P();
68         }
69         return window.oils_lock;
70     }
71
72     window.oils_lock = 0;
73     dump(location.href + ' init window.oils_lock == ' + window.oils_lock + '\n');
74     window.addEventListener(
75         'close',
76         function(ev) {
77             try {
78                 dump('oils_lock_page/oils_unlock_page onclose handler\n');
79                 if (window.oils_lock > 0) {
80                     var confirmation = window.confirm($('offlineStrings').getString('menu.close_window.unsaved_data_warning'));
81                     if (!confirmation) {
82                         ev.preventDefault();
83                         return false;
84                     }
85                 }
86
87                 if (typeof xulG != 'undefined') {
88                     if (typeof xulG.unlock_tab == 'function') {
89                         xulG.unlock_tab();
90                     } else {
91                         oils_unsaved_data_P( window.oils_lock );
92                     }
93                 } else {
94                     oils_unsaved_data_P( window.oils_lock );
95                 }
96                 window.oils_lock = 0;
97                 dump(location.href + ' forcing window.oils_lock == ' + window.oils_lock + '\n');
98
99                 // Dispatching the window close event doesn't always close the window, even though the event does happen
100                 setTimeout(
101                     function() {
102                         try {
103                             window.close();
104                         } catch(E) {
105                             dump('Error inside global_util.js, onclose handler, setTimeout window.close KLUDGE: ' + E + '\n');
106                         }
107                     }, 0
108                 );
109
110                 return true;
111             } catch(E) {
112                 dump('Error inside global_util.js, onclose handler: ' + E + '\n');
113                 return true;
114             }
115         },
116         false
117     );
118
119     function ses(a,params) {
120         try {
121             if (!params) params = {};
122             var data;
123             if (params.data) {
124                 data = params.data; data.stash_retrieve();
125             } else {
126                 // This has been breaking in certain contexts, with an internal instantiation of util.error failing because of util.error being an object instead of the constructor function it should be
127                 JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.stash_retrieve();
128             }
129
130             switch(a) {
131                 case 'staff' : return data.list.au[0]; break;
132                 case 'staff_id' : return data.list.au[0].id(); break;
133                 case 'staff_usrname' : return data.list.au[0].usrname(); break;
134                 case 'ws_ou' :
135                     return data.list.au[0].ws_ou();
136                 break;
137                 case 'ws_ou_shortname' :
138                     return data.hash.aou[ data.list.au[0].ws_ou() ].shortname();
139                 break;
140                 case 'authtime' :
141                     return data.session.authtime;
142                 break;
143                 case 'key':
144                 default:
145                     return data.session.key;
146                 break;
147             }
148         } catch(E) {
149             alert(location.href + '\nError in global_utils.js, ses(): ' + E);
150             throw(E);
151         }
152     }
153
154     function font_helper() {
155         try {
156             JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
157             removeCSSClass(document.documentElement,'ALL_FONTS_LARGER');
158             removeCSSClass(document.documentElement,'ALL_FONTS_SMALLER');
159             removeCSSClass(document.documentElement,'ALL_FONTS_XX_SMALL');
160             removeCSSClass(document.documentElement,'ALL_FONTS_X_SMALL');
161             removeCSSClass(document.documentElement,'ALL_FONTS_SMALL');
162             removeCSSClass(document.documentElement,'ALL_FONTS_MEDIUM');
163             removeCSSClass(document.documentElement,'ALL_FONTS_LARGE');
164             removeCSSClass(document.documentElement,'ALL_FONTS_X_LARGE');
165             removeCSSClass(document.documentElement,'ALL_FONTS_XX_LARGE');
166             addCSSClass(document.documentElement,data.global_font_adjust);
167         } catch(E) {
168             var Strings = $('offlineStrings') || $('commonStrings');
169             alert(Strings.getFormattedString('openils.global_util.font_size.error', [E]));
170         }
171     }
172
173     function oils_persist(e,cancelable) {
174         try {
175             if (!e) { return; }
176             if (typeof cancelable == 'undefined') { cancelable = false; } 
177             var evt = document.createEvent("Events");
178             evt.initEvent( 'oils_persist', false, cancelable ); // event name, bubbles, cancelable
179             e.dispatchEvent(evt);
180         } catch(E) {
181             alert('Error with oils_persist():' + E);
182         }
183     }
184
185     function persist_helper(base_key_suffix) {
186         try {
187             if (base_key_suffix) {
188                 base_key_suffix = base_key_suffix.replace(/[^A-Za-z]/g,'_') + '_';
189             } else {
190                 base_key_suffix = '';
191             }
192
193             function gen_event_handler(etype,node) {
194                 return function(ev) {
195                     try {
196                         oils_persist(ev.target);
197                     } catch(E) {
198                         alert('Error in persist_helper, firing virtual event oils_persist after ' + etype + ' event on ' + node.nodeName + '.id = ' + node.id + ': ' + E);
199                     }
200                 };
201             };
202
203             function gen_oils_persist_handler(bk,node) {
204                 return function(ev) {
205                     try {
206                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
207                         var target;
208                         if (ev.target.nodeName == 'command') {
209                             target = node;
210                             if (ev.explicitOriginalTarget != node) return;
211                         } else {
212                             target = ev.target;
213                             if (target == window) {
214                                 target = window.document.documentElement;
215                             }
216                         }
217                         var filename = location.pathname.split('/')[ location.pathname.split('/').length - 1 ];
218                         var base_key = 'oils_persist_' + String(location.hostname + '_' + filename + '_' + target.getAttribute('id')).replace('/','_','g') + '_' + base_key_suffix;
219                         var attribute_list = target.getAttribute('oils_persist').split(' ');
220                         dump('on_oils_persist: <<< ' + target.nodeName + '.id = ' + target.id + '\t' + bk + '\n');
221                         for (var j = 0; j < attribute_list.length; j++) {
222                             var key = base_key + attribute_list[j];
223                             var value = target.getAttribute( attribute_list[j] );
224                             if ( attribute_list[j] == 'checked' && ['checkbox','toolbarbutton'].indexOf( target.nodeName ) > -1 ) {
225                                 value = target.checked;
226                                 dump('\t' + value + ' <== .' + attribute_list[j] + '\n');
227                             } else if ( attribute_list[j] == 'value' && ['textbox'].indexOf( target.nodeName ) > -1 ) {
228                                 value = target.value;
229                                 dump('\t' + value + ' <== .' + attribute_list[j] + '\n');
230                             } else if ( attribute_list[j] == 'sizemode' && ['window'].indexOf( target.nodeName ) > -1 ) {
231                                 value = window.windowState;
232                                 dump('\t' + value + ' <== window.windowState, @' + attribute_list[j] + '\n');
233                             } else if ( attribute_list[j] == 'height' && ['window'].indexOf( target.nodeName ) > -1 ) {
234                                 value = window.outerHeight;
235                                 dump('\t' + value + ' <== window.outerHeight, @' + attribute_list[j] + '\n');
236                             } else if ( attribute_list[j] == 'width' && ['window'].indexOf( target.nodeName ) > -1 ) {
237                                 value = window.outerWidth;
238                                 dump('\t' + value + ' <== window.outerWidth, @' + attribute_list[j] + '\n');
239                             } else {
240                                 dump('\t' + value + ' <== @' + attribute_list[j] + '\n');
241                             }
242                             prefs.setCharPref( key, value );
243                             // TODO: Need to add logic for splitter repositioning, grippy state, etc.
244                             // NOTE: oils_persist_peers and oils_persist="width" on those peers can help with the elements adjacent to a splitter
245                         }
246                         if (target.hasAttribute('oils_persist_peers') && ! ev.cancelable) { // We abuse the .cancelable field on the oils_persist event to prevent looping
247                             var peer_list = target.getAttribute('oils_persist_peers').split(' ');
248                             for (var j = 0; j < peer_list.length; j++) {
249                                 dump('on_oils_persist: dispatching oils_persist to peer ' + peer_list[j] + '\n');
250                                 oils_persist( document.getElementById( peer_list[j] ), true );
251                             } 
252                         }
253                     } catch(E) {
254                         alert('Error in persist_helper() event listener for ' + bk + ': ' + E);
255                     }
256                 };
257             }
258
259             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
260             var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
261             var nodes = document.getElementsByAttribute('oils_persist','*');
262             for (var i = 0; i < nodes.length; i++) {
263                 var filename = location.pathname.split('/')[ location.pathname.split('/').length - 1 ];
264                 var base_key = 'oils_persist_' + String(location.hostname + '_' + filename + '_' + nodes[i].getAttribute('id')).replace('/','_','g') + '_' + base_key_suffix;
265                 var attribute_list = nodes[i].getAttribute('oils_persist').split(' ');
266                 dump('persist_helper: >>> ' + nodes[i].nodeName + '.id = ' + nodes[i].id + '\t' + base_key + '\n');
267                 for (var j = 0; j < attribute_list.length; j++) {
268                     var key = base_key + attribute_list[j];
269                     var has_key = prefs.prefHasUserValue(key);
270                     var value = has_key ? prefs.getCharPref(key) : null;
271                     if (value == 'true') { value = true; }
272                     if (value == 'false') { value = false; }
273                     if (has_key) {
274                         if ( attribute_list[j] == 'checked' && ['checkbox','toolbarbutton'].indexOf( nodes[i].nodeName ) > -1 ) {
275                             nodes[i].checked = value; 
276                             dump('\t' + value + ' ==> .' + attribute_list[j] + '\n');
277                             if (!value) {
278                                 nodes[i].removeAttribute('checked');
279                                 dump('\tremoving @checked\n');
280                             }
281                         } else if ( attribute_list[j] == 'value' && ['textbox'].indexOf( nodes[i].nodeName ) > -1 ) {
282                             nodes[i].value = value;
283                             dump('\t' + value + ' ==> .' + attribute_list[j] + '\n');
284                         } else if ( attribute_list[j] == 'sizemode' && ['window'].indexOf( nodes[i].nodeName ) > -1 ) {
285                             switch(value) {
286                                 case window.STATE_MAXIMIZED:
287                                     window.maximize();
288                                     break;
289                                 case window.STATE_MINIMIZED:
290                                     window.minimize();
291                                     break;
292                             };
293                             dump('\t' + value + ' ==> window.windowState, @' + attribute_list[j] + '\n');
294                         } else if ( attribute_list[j] == 'height' && ['window'].indexOf( nodes[i].nodeName ) > -1 ) {
295                             window.outerHeight = value;
296                             dump('\t' + value + ' ==> window.outerHeight, @' + attribute_list[j] + '\n');
297                         } else if ( attribute_list[j] == 'width' && ['window'].indexOf( nodes[i].nodeName ) > -1 ) {
298                             window.outerWidth = value;
299                             dump('\t' + value + ' ==> window.outerWidth, @' + attribute_list[j] + '\n');
300                         } else {
301                             nodes[i].setAttribute( attribute_list[j], value);
302                             dump('\t' + value + ' ==> @' + attribute_list[j] + '\n');
303                         }
304                     }
305                 }
306                 var cmd = nodes[i].getAttribute('command');
307                 var cmd_el = document.getElementById(cmd);
308                 if (nodes[i].disabled == false && nodes[i].hidden == false) {
309                     var no_poke = nodes[i].getAttribute('oils_persist_no_poke');
310                     if (no_poke && no_poke == 'true') {
311                         // Timing issue for some checkboxes; don't poke them with an event
312                         dump('\tnot poking\n');
313                     } else {
314                         if (cmd_el) {
315                             dump('\tpoking @command\n');
316                             var evt = document.createEvent("Events");
317                             evt.initEvent( 'command', true, true );
318                             cmd_el.dispatchEvent(evt);
319                         } else {
320                             dump('\tpoking\n');
321                             var evt = document.createEvent("Events");
322                             evt.initEvent( 'command', true, true );
323                             nodes[i].dispatchEvent(evt);
324                         }
325                     }
326                 }
327                 if (cmd_el) {
328                     cmd_el.addEventListener(
329                         'command',
330                         gen_event_handler('command',cmd_el),
331                         false
332                     );
333                     cmd_el.addEventListener(
334                         'oils_persist',
335                         gen_oils_persist_handler( base_key, nodes[i] ),
336                         false
337                     );
338                 } else {
339                     var node = nodes[i];
340                     var event_types = [];
341                     if (node.hasAttribute('oils_persist_events')) {
342                         var event_type_list = node.getAttribute('oils_persist_events').split(' ');
343                         for (var j = 0; j < event_type_list.length; j++) {
344                             event_types.push( event_type_list[j] );
345                         }
346                     } else {
347                         if (node.nodeName == 'textbox') { 
348                             event_types.push('change'); 
349                         } else if (node.nodeName == 'window') {
350                             event_types.push('resize'); 
351                             node = window; // xul window is an element of window.document
352                         } else {
353                             event_types.push('command'); 
354                         }
355                     }
356                     for (var j = 0; j < event_types.length; j++) {
357                         node.addEventListener(
358                             event_types[j],
359                             gen_event_handler(event_types[j],node),
360                             false
361                         );
362                     }
363                     node.addEventListener(
364                         'oils_persist',
365                         gen_oils_persist_handler( base_key, node ),
366                         false
367                     );
368                 }
369             }
370         } catch(E) {
371             alert('Error in persist_helper(): ' + E);
372         }
373     }
374
375     function getKeys(o) {
376         var keys = [];
377         for (var k in o) keys.push(k);
378         return keys;
379     }
380
381     function get_contentWindow(frame) {
382         try {
383             netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
384             if (frame && frame.contentWindow) {
385                 try {
386                     if (typeof frame.contentWindow.wrappedJSObject != 'undefined') {
387                                      return frame.contentWindow.wrappedJSObject;
388                           }
389                 } catch(E) {
390                     var Strings = $('offlineStrings') || $('commonStrings');
391                     alert(Strings.getFormattedString('openils.global_util.content_window_jsobject.error', [frame, E]));
392                 }
393                 return frame.contentWindow;
394             } else {
395                 return null;
396             }
397         } catch(E) {
398             var Strings = $('offlineStrings') || $('commonStrings');
399             alert(Strings.getFormattedString('openils.global_util.content_window.error', [frame, E]));
400         }
401     }
402
403     function update_modal_xulG(v) {
404         try {
405             JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
406             var key = location.pathname + location.search + location.hash;
407             if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
408                 data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ] = v;
409                 data.stash('modal_xulG_stack');
410             }
411         } catch(E) {
412             alert('FIXME: update_modal_xulG => ' + E);
413         }
414     }
415
416     function xul_param(param_name,_params) {
417         /* By default, this function looks for a CGI-style query param identified by param_name.  If one isn't found, it then looks in xulG.  If one still isn't found, and _params.stash_name is true, it looks in the global xpcom stash for the field identified by stash_name.  If _params.concat is true, then it looks in all these places and concatenates the results.  There are also options for converting JSON to javascript objects, and clearing the xpcom stash_name field after retrieval.  Also added, ability to search a specific spot in the xpcom stash that implements a stack to hold xulG's for modal windows */
418         try {
419             //dump('xul_param('+param_name+','+js2JSON(_params)+')\n');
420             var value = undefined; if (!_params) _params = {};
421             if (typeof _params.no_cgi == 'undefined') {
422                 var cgi = new CGI();
423                 if (cgi.param(param_name)) {
424                     var x = cgi.param(param_name);
425                     //dump('\tfound via location.href = ' + x + '\n');
426                     if (typeof _params.JSON2js_if_cgi != 'undefined') {
427                         x = JSON2js( x );
428                         //dump('\tJSON2js = ' + x + '\n');
429                     }
430                     if (typeof _params.concat == 'undefined') {
431                         //alert(param_name + ' x = ' + x);
432                         return x; // value
433                     } else {
434                         if (value) {
435                             if (value.constructor != Array) value = [ value ];
436                             value = value.concat(x);
437                         } else {
438                             value = x;
439                         }
440                     }
441                 }
442             }
443             if (typeof _params.no_xulG == 'undefined') {
444                 if (typeof _params.modal_xulG != 'undefined') {
445                     JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
446                     var key = location.pathname + location.search + location.hash;
447                     //dump('xul_param, considering modal key = ' + key + '\n');
448                     if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') {
449                         xulG = data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ];
450                     }
451                 }
452                 if (typeof xulG == 'object' && typeof xulG[ param_name ] != 'undefined') {
453                     var x = xulG[ param_name ];
454                     //dump('\tfound via xulG = ' + x + '\n');
455                     if (typeof _params.JSON2js_if_xulG != 'undefined') {
456                         x = JSON2js( x );
457                         //dump('\tJSON2js = ' + x + '\n');
458                     }
459                     if (typeof _params.concat == 'undefined') {
460                         //alert(param_name + ' x = ' + x);
461                         return x; // value
462                     } else {
463                         if (value) {
464                             if (value.constructor != Array) value = [ value ];
465                             value = value.concat(x);
466                         } else {
467                             value = x;
468                         }
469                     }
470                 }
471             }
472             if (typeof _params.no_xpcom == 'undefined') {
473                 /* the field names used for temp variables in the global stash tend to be more unique than xuLG or CGI param names, to avoid collisions */
474                 if (typeof _params.stash_name != 'undefined') { 
475                     JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
476                     if (typeof data[ _params.stash_name ] != 'undefined') {
477                         var x = data[ _params.stash_name ];
478                         //dump('\tfound via xpcom = ' + x + '\n');
479                         if (typeof _params.JSON2js_if_xpcom != 'undefined') {
480                             x = JSON2js( x );
481                             //dump('\tJSON2js = ' + x + '\n');
482                         }
483                         if (_params.clear_xpcom) { 
484                             data[ _params.stash_name ] = undefined; data.stash( _params.stash_name ); 
485                         }
486                         if (typeof _params.concat == 'undefined') {
487                             //alert(param_name + ' x = ' + x);
488                             return x; // value
489                         } else {
490                             if (value) {
491                                 if (value.constructor != Array) value = [ value ];
492                                 value = value.concat(x);
493                             } else {
494                                 value = x;
495                             }
496                         }
497                     }
498                 }
499             }
500             //alert(param_name + ' value = ' + value);
501             return value;
502         } catch(E) {
503             dump('xul_param error: ' + E + '\n');
504         }
505     }
506
507     function get_bool(a) {
508         // Normal javascript interpretation except 'f' == false, per postgres, and 'F' == false, and '0' == false (newer JSON is returning '0' instead of 0 in cases)
509         // So false includes 'f', '', '0', 0, null, and undefined
510         if (a == 'f') return false;
511         if (a == 'F') return false;
512         if (a == '0') return false;
513         if (a) return true; else return false;
514     }
515
516     function get_localized_bool(a) {
517         var Strings = $('offlineStrings') || $('commonStrings');
518         return get_bool(a) ? Strings.getString('common.yes') : Strings.getString('common.no');
519     }
520
521     function get_db_true() {
522         return 't';
523     }
524
525     function get_db_false() {
526         return 'f';
527     }
528
529     function copy_to_clipboard(ev) {
530         try {
531             netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
532             var text;
533             if (typeof ev == 'object') {
534                 if (typeof ev.target != 'undefined') {
535                     if (typeof ev.target.textContent != 'undefined') if (ev.target.textContent) text = ev.target.textContent;
536                     if (typeof ev.target.value != 'undefined') if (ev.target.value) text = ev.target.value;
537                 }
538             } else if (typeof ev == 'string') {
539                 text = ev;
540             }
541             const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
542                 .getService(Components.interfaces.nsIClipboardHelper);
543             gClipboardHelper.copyString(text);
544             var Strings = $('offlineStrings') || $('commonStrings');
545             alert(Strings.getFormattedString('openils.global_util.clipboard', [text]));
546         } catch(E) {
547             var Strings = $('offlineStrings') || $('commonStrings');
548             alert(Strings.getFormattedString('openils.global_util.clipboard.error', [E]));    
549         }
550     }
551
552     function clear_the_cache() {
553         try {
554             netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
555             var cacheClass         = Components.classes["@mozilla.org/network/cache-service;1"];
556             var cacheService    = cacheClass.getService(Components.interfaces.nsICacheService);
557             cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
558             cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
559         } catch(E) {
560             var Strings = $('offlineStrings') || $('commonStrings');
561             alert(Strings.getFormattedString('openils.global_util.clear_cache.error', [E]));
562         }
563     }
564
565     function toOpenWindowByType(inType, uri) {
566         var winopts = "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar";
567         window.open(uri, "_blank", winopts);
568     }
569
570     function url_prefix(url) {
571         if (url.match(/^\//)) url = urls.remote + url;
572         if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
573         dump('url_prefix = ' + url + '\n');
574         return url;
575     }
576