Focus fix for gecko based browser dialogs

This commit is contained in:
julmis 2004-03-01 23:59:11 +00:00
parent f77b6706ac
commit e418c553a6

View File

@ -1,72 +1,72 @@
// Though "Dialog" looks like an object, it isn't really an object. Instead // Though "Dialog" looks like an object, it isn't really an object. Instead
// it's just namespace for protecting global symbols. // it's just namespace for protecting global symbols.
function Dialog(url, action, init) { function Dialog(url, action, init) {
if (typeof init == "undefined") { if (typeof init == "undefined") {
init = window; // pass this window object by default init = window; // pass this window object by default
} }
if (document.all) { // here we hope that Mozilla will never support document.all if (document.all) { // here we hope that Mozilla will never support document.all
var value = var value =
showModalDialog(url, init, showModalDialog(url, init,
//window.open(url, '_blank', //window.open(url, '_blank',
"resizable: no; help: no; status: no; scroll: no"); "resizable: no; help: no; status: no; scroll: no");
if (action) { if (action) {
action(value); action(value);
} }
} else { } else {
return Dialog._geckoOpenModal(url, action, init); return Dialog._geckoOpenModal(url, action, init);
} }
}; };
Dialog._parentEvent = function(ev) { Dialog._parentEvent = function(ev) {
if (Dialog._modal && !Dialog._modal.closed) { if (Dialog._modal && !Dialog._modal.closed) {
Dialog._modal.focus(); setTimeout(function(){Dialog._modal.focus();}, 1);
// we get here in Mozilla only, anyway, so we can safely use // we get here in Mozilla only, anyway, so we can safely use
// the DOM version. // the DOM version.
ev.preventDefault(); ev.preventDefault();
ev.stopPropagation(); ev.stopPropagation();
} }
}; };
// should be a function, the return handler of the currently opened dialog. // should be a function, the return handler of the currently opened dialog.
Dialog._return = null; Dialog._return = null;
// constant, the currently opened dialog // constant, the currently opened dialog
Dialog._modal = null; Dialog._modal = null;
// the dialog will read it's args from this variable // the dialog will read it's args from this variable
Dialog._arguments = null; Dialog._arguments = null;
Dialog._geckoOpenModal = function(url, action, init) { Dialog._geckoOpenModal = function(url, action, init) {
var dlg = window.open(url, "ha_dialog", var dlg = window.open(url, "ha_dialog",
"toolbar=no,menubar=no,personalbar=no,width=10,height=10," + "toolbar=no,menubar=no,personalbar=no,width=10,height=10," +
"scrollbars=no,resizable=no"); "scrollbars=no,resizable=no");
Dialog._modal = dlg; Dialog._modal = dlg;
Dialog._arguments = init; Dialog._arguments = init;
// capture some window's events // capture some window's events
function capwin(w) { function capwin(w) {
w.addEventListener("click", Dialog._parentEvent, true); w.addEventListener("click", Dialog._parentEvent, true);
w.addEventListener("mousedown", Dialog._parentEvent, true); w.addEventListener("mousedown", Dialog._parentEvent, true);
w.addEventListener("focus", Dialog._parentEvent, true); w.addEventListener("focus", Dialog._parentEvent, true);
}; };
// release the captured events // release the captured events
function relwin(w) { function relwin(w) {
w.removeEventListener("focus", Dialog._parentEvent, true); w.removeEventListener("focus", Dialog._parentEvent, true);
w.removeEventListener("mousedown", Dialog._parentEvent, true); w.removeEventListener("mousedown", Dialog._parentEvent, true);
w.removeEventListener("click", Dialog._parentEvent, true); w.removeEventListener("click", Dialog._parentEvent, true);
}; };
capwin(window); capwin(window);
// capture other frames // capture other frames
//for (var i = 0; i < window.frames.length; capwin(window.frames[i++])); for (var i = 0; i < window.frames.length; capwin(window.frames[i++]));
// make up a function to be called when the Dialog ends. // make up a function to be called when the Dialog ends.
Dialog._return = function (val) { Dialog._return = function (val) {
if (val && action) { if (val && action) {
action(val); action(val);
} }
relwin(window); relwin(window);
// capture other frames // capture other frames
//for (var i = 0; i < window.frames.length; relwin(window.frames[i++])); for (var i = 0; i < window.frames.length; relwin(window.frames[i++]));
Dialog._modal = null; Dialog._modal = null;
}; };
}; };