forked from pauljadam/bookmarklets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
landmark-heading-nav.js
74 lines (73 loc) · 3.42 KB
/
landmark-heading-nav.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
javascript: (function() {
function callback() {
function l() {
var landmarks = $('[role=main], [role=search], [role=contentinfo], [role=banner], [role=navigation], [role=complementary], [role=application]');
var sections = $('main, banner, footer, header, aside, nav');
$('#success').remove();
$(landmarks).each(function() {
$(this).attr('tabindex','0');
});
$(landmarks).focus(function() {
$(this).attr('style','outline:3px solid orange;');
$(this).blur(function() {
$(this).removeAttr('style');
});
});
$(sections).each(function() {
$(this).attr('tabindex','0');
});
$(sections).focus(function() {
$(this).attr('style','outline:3px solid orange;');
$(this).blur(function() {
$(this).removeAttr('style');
});
});
$(':header').each(function() {
$(this).attr('tabindex','0');
});
$(':header').focus(function() {
$(this).attr('style','outline:3px solid orange;');
$(this).blur(function() {
$(this).removeAttr('style');
});
});
$(document).keypress(function(e) {
switch(e.which)
{
/* user presses the "m" */
case 109: console.log('m key pressed'); if ($('main').length) {$('main:first').focus();} if ($('[role=main]').length) {$('[role=main]:first').focus();} break;
/* user presses the "b" */
case 98: console.log('b key pressed'); if ($('header').length) {$('header:first').focus();} if ($('[role=banner]').length) {$('[role=banner]:first').focus();} break;
/* user presses the "n" */
case 110: console.log('n key pressed'); if ($('nav').length) {$('nav:first').focus();} if ($('[role=navigation]').length) {$('[role=navigation]:first').focus();} break;
/* user presses the "f" */
case 102: console.log('f key pressed'); if ($('footer').length) {$('footer:first').focus();} if ($('[role=contentinfo]').length) {$('[role=contentinfo]:first').focus();} break;
/* user presses the "s" */
case 115: console.log('s key pressed'); if ($('search').length) {$('search:first').focus();} if ($('[role=search]').length) {$('[role=search]:first').focus();} break;
/* user presses the "1" */
case 49: $('h1').focus(); break;
/* user presses the "2" */
case 50: $('h2').focus(); break;
/* user presses the "3" */
case 51: $('h3').focus(); break;
/* user presses the "4" */
case 52: $('h4').focus(); break;
/* user presses the "5" */
case 53: $('h5').focus(); break;
/* user presses the "6" */
case 54: $('h6').focus(); break;
}
});
if (!$(landmarks).length && !$(':header').length && !$(sections).length){
alert('No Landmarks or Headings Found!');
} else {
$('body').append('<div id="success" role="alert" style="position:absolute; width:0; height:0; clip: rect(0,0,0,0);"></div>');
$('#success').html('Success! Landmarks or Headings Found on Page: ' + document.title);
setTimeout(function(){ $('#success').remove(); s.remove(); }, 3000);
}
}
l()
}
var s = document.createElement("script");
s.addEventListener ? s.addEventListener("load", callback, !1) : s.readyState && (s.onreadystatechange = callback), s.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js", document.body.appendChild(s);
})()