Adding proper event handling

This commit is contained in:
Lindsay Evans 2012-04-24 12:01:31 +10:00
parent 70386fb139
commit aef04f1c75

View File

@ -2,17 +2,26 @@
// based on http://www.paciellogroup.com/blog/2012/04/how-to-remove-css-outlines-in-an-accessible-manner/
(function(d){
var style_element = d.createElement('STYLE');
var style_element = d.createElement('STYLE'),
dom_events = 'addEventListener' in d,
add_event_listener = function(type, callback){
if(dom_events){
d.addEventListener(type, callback);
}else{
d.attachEvent('on' + type, callback);
}
}
;
d.getElementsByTagName('HEAD')[0].appendChild(style_element);
// Using mousedown instead of mouseover, so that previously focused elements don't lose focus ring on mouse move
d.onmousedown = function(){
add_event_listener('mousedown', function(){
style_element.innerHTML = 'a{outline:none}';
};
});
d.onkeydown = function(){
add_event_listener('keydown', function(){
style_element.innerHTML = '';
};
});
})(document);