Skip to content

Commit 6a60c6c

Browse files
authored
Fix accessibility issue affecting carousel homepage (#347)
1 parent d2faccf commit 6a60c6c

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

_includes/head.html

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,6 @@
3030
</script>
3131
3232
-->
33-
<script>
34-
$(function(){
35-
$('#myCarousel.slide').carousel({
36-
interval: 5000,
37-
pause: "hover"
38-
});
39-
$('input').focus(function(){
40-
$("#myCarousel").carousel('pause');
41-
}).blur(function() {
42-
$("#myCarousel").carousel('cycle');
43-
});
44-
});
45-
</script>
4633

4734
<link rel="stylesheet" href="https://www.odata.org/public/css/bootstrap.min.css"/>
4835
<link rel="stylesheet" href="{{'/public/css/site.css' | prepend: site.baseurl | prepend: site.url}}">

index.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,37 @@ <h4><a href="{{'/odata-services/' | prepend: site.baseurl | prepend: site.url}}"
189189
</div>
190190
</div>
191191
</div>
192+
193+
<script>
194+
$(function(){
195+
var myCarousel = $("#myCarousel");
196+
197+
$('#myCarousel.slide').carousel({
198+
interval: 5000,
199+
pause: "hover"
200+
});
201+
202+
$('input').focus(function(){
203+
myCarousel.carousel('pause');
204+
}).blur(function() {
205+
myCarousel.carousel('cycle');
206+
});
207+
208+
var carousel = document.getElementById('myCarousel');
209+
210+
var liveRegion = document.createElement('span');
211+
liveRegion.setAttribute('aria-live', 'polite');
212+
liveRegion.setAttribute('aria-atomic', 'true');
213+
liveRegion.setAttribute('class', 'live-region sr-only');
214+
carousel.appendChild(liveRegion);
215+
216+
var headers = $(myCarousel).find('div.carousel-inner > div > div > h1');
217+
218+
myCarousel.on('slid.bs.carousel', function () {
219+
var activeSlide = $('#myCarousel > div.carousel-inner > div.active > div > h1');
220+
var captionText = activeSlide.text();
221+
var position = headers.index(activeSlide) + 1
222+
liveRegion.textContent = 'Slide ' + position + ' of ' + headers.length + ' - ' + captionText;
223+
});
224+
});
225+
</script>

0 commit comments

Comments
 (0)