mirror of
https://github.com/lindsayevans/outline.js.git
synced 2024-10-26 21:43:38 +03:00
Adding proper event handling
This commit is contained in:
parent
70386fb139
commit
aef04f1c75
21
outline.js
21
outline.js
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user