scratch – Blame information for rev 117
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
117 | office | 1 | // Accessibility tools |
2 | s.a11y = { |
||
3 | makeFocusable: function ($el) { |
||
4 | $el.attr('tabIndex', '0'); |
||
5 | return $el; |
||
6 | }, |
||
7 | addRole: function ($el, role) { |
||
8 | $el.attr('role', role); |
||
9 | return $el; |
||
10 | }, |
||
11 | |||
12 | addLabel: function ($el, label) { |
||
13 | $el.attr('aria-label', label); |
||
14 | return $el; |
||
15 | }, |
||
16 | |||
17 | disable: function ($el) { |
||
18 | $el.attr('aria-disabled', true); |
||
19 | return $el; |
||
20 | }, |
||
21 | |||
22 | enable: function ($el) { |
||
23 | $el.attr('aria-disabled', false); |
||
24 | return $el; |
||
25 | }, |
||
26 | |||
27 | onEnterKey: function (event) { |
||
28 | if (event.keyCode !== 13) return; |
||
29 | if ($(event.target).is(s.params.nextButton)) { |
||
30 | s.onClickNext(event); |
||
31 | if (s.isEnd) { |
||
32 | s.a11y.notify(s.params.lastSlideMessage); |
||
33 | } |
||
34 | else { |
||
35 | s.a11y.notify(s.params.nextSlideMessage); |
||
36 | } |
||
37 | } |
||
38 | else if ($(event.target).is(s.params.prevButton)) { |
||
39 | s.onClickPrev(event); |
||
40 | if (s.isBeginning) { |
||
41 | s.a11y.notify(s.params.firstSlideMessage); |
||
42 | } |
||
43 | else { |
||
44 | s.a11y.notify(s.params.prevSlideMessage); |
||
45 | } |
||
46 | } |
||
47 | if ($(event.target).is('.' + s.params.bulletClass)) { |
||
48 | $(event.target)[0].click(); |
||
49 | } |
||
50 | }, |
||
51 | |||
52 | liveRegion: $('<span class="' + s.params.notificationClass + '" aria-live="assertive" aria-atomic="true"></span>'), |
||
53 | |||
54 | notify: function (message) { |
||
55 | var notification = s.a11y.liveRegion; |
||
56 | if (notification.length === 0) return; |
||
57 | notification.html(''); |
||
58 | notification.html(message); |
||
59 | }, |
||
60 | init: function () { |
||
61 | // Setup accessibility |
||
62 | if (s.params.nextButton && s.nextButton && s.nextButton.length > 0) { |
||
63 | s.a11y.makeFocusable(s.nextButton); |
||
64 | s.a11y.addRole(s.nextButton, 'button'); |
||
65 | s.a11y.addLabel(s.nextButton, s.params.nextSlideMessage); |
||
66 | } |
||
67 | if (s.params.prevButton && s.prevButton && s.prevButton.length > 0) { |
||
68 | s.a11y.makeFocusable(s.prevButton); |
||
69 | s.a11y.addRole(s.prevButton, 'button'); |
||
70 | s.a11y.addLabel(s.prevButton, s.params.prevSlideMessage); |
||
71 | } |
||
72 | |||
73 | $(s.container).append(s.a11y.liveRegion); |
||
74 | }, |
||
75 | initPagination: function () { |
||
76 | if (s.params.pagination && s.params.paginationClickable && s.bullets && s.bullets.length) { |
||
77 | s.bullets.each(function () { |
||
78 | var bullet = $(this); |
||
79 | s.a11y.makeFocusable(bullet); |
||
80 | s.a11y.addRole(bullet, 'button'); |
||
81 | s.a11y.addLabel(bullet, s.params.paginationBulletMessage.replace(/{{index}}/, bullet.index() + 1)); |
||
82 | }); |
||
83 | } |
||
84 | }, |
||
85 | destroy: function () { |
||
86 | if (s.a11y.liveRegion && s.a11y.liveRegion.length > 0) s.a11y.liveRegion.remove(); |
||
87 | } |
||
88 | }; |