var AutoFocus = {
'cssText_on' : 'background-color: #fee; border: 2px #866 solid;',
'cssText_off' : '',
'Handlers': {
'blur' : function (evt) {
var e = evt. target ;
if ( /INPUT|TEXTAREA/.test(e.nodeName) ) {
e.style.cssText = AutoFocus.cssText_off;
}
},
'focus' : function (evt) {
var e = evt. target ;
if ( /INPUT|TEXTAREA/.test(e.nodeName) ) {
e.style.cssText = AutoFocus.cssText_on;
}
},
'unload': function (evt) {
AutoFocus.Detach (document, 'blur' , AutoFocus.Listener, true);
AutoFocus.Detach (document, 'focus' , AutoFocus.Listener, true);
}
},
'Listener':
function (evt) {
AutoFocus.Handlers[ evt.type ].apply (this, arguments);
},
'Attach':
function (target, type, listener, useCapture) {
return target. addEventListener( type, listener, useCapture);
},
'Detach':
function (target, type, listener, useCapture) {
return target. removeEventListener( type, listener, useCapture);
},
'Initialize':
function () {
this.Attach (document, 'blur' , this.Listener, true);
this.Attach (document, 'focus' , this.Listener, true);
this.Attach (window, 'unload', this.Listener, true);
}
};
AutoFocus.Initialize();