Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding proper event handling
  • Loading branch information
lindsayevans committed Apr 24, 2012
1 parent 70386fb commit aef04f1
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions outline.js
Expand Up @@ -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);

0 comments on commit aef04f1

Please sign in to comment.