From 60aaebe86f380250c76554c04d5e60371dbe677e Mon Sep 17 00:00:00 2001 From: Czirkos Zoltan Date: Sun, 18 Feb 2018 16:44:46 +0100 Subject: [PATCH] Added options (previousButtonLabel, nextButtonLabel, closeButtonLabel) to enable customization of ARIA labels --- README.md | 1 + src/baguetteBox.js | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 401b2747..dc0c372e 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ The following options are available: | --- | --- | --- | --- | | `captions` | `Boolean` \| `function(element)` | `true` | Display image captions. Passing a function will use a string returned by this callback. The only argument is `a` element containing the image. Invoked in the context of the current gallery array | | `buttons` | `Boolean` \| `'auto'` | `'auto'` | Display buttons. `'auto'` hides buttons on touch-enabled devices or when only one image is available | +| `previousButtonLabel`, `nextButtonLabel`, `closeButtonLabel` | `String` | `'Previous'`, `'Next'`, `'Close'` | ARIA label of buttons | | `fullScreen` | `Boolean` | `false` | Enable full screen mode | | `noScrollbars` | `Boolean` | `false` | Hide scrollbars when gallery is displayed | | `bodyClass` | `String` | `'baguetteBox-open'` | Class name that will be appended to the `body` when lightbox is visible (works in IE 10+) | diff --git a/src/baguetteBox.js b/src/baguetteBox.js index 8fa2af04..e99d79b2 100644 --- a/src/baguetteBox.js +++ b/src/baguetteBox.js @@ -38,6 +38,9 @@ defaults = { captions: true, buttons: 'auto', + previousButtonLabel: 'Previous', + nextButtonLabel: 'Next', + closeButtonLabel: 'Close', fullScreen: false, noScrollbars: false, bodyClass: 'baguetteBox-open', @@ -273,21 +276,18 @@ previousButton = create('button'); previousButton.setAttribute('type', 'button'); previousButton.id = 'previous-button'; - previousButton.setAttribute('aria-label', 'Previous'); previousButton.innerHTML = supports.svg ? leftArrow : '<'; overlay.appendChild(previousButton); nextButton = create('button'); nextButton.setAttribute('type', 'button'); nextButton.id = 'next-button'; - nextButton.setAttribute('aria-label', 'Next'); nextButton.innerHTML = supports.svg ? rightArrow : '>'; overlay.appendChild(nextButton); closeButton = create('button'); closeButton.setAttribute('type', 'button'); closeButton.id = 'close-button'; - closeButton.setAttribute('aria-label', 'Close'); closeButton.innerHTML = supports.svg ? closeX : '×'; overlay.appendChild(closeButton); @@ -388,6 +388,10 @@ } // Set buttons style to hide or display them previousButton.style.display = nextButton.style.display = (options.buttons ? '' : 'none'); + // Set buttons' aria-labels + previousButton.setAttribute('aria-label', options.previousButtonLabel); + nextButton.setAttribute('aria-label', options.nextButtonLabel); + closeButton.setAttribute('aria-label', options.closeButtonLabel); // Set overlay color try { overlay.style.backgroundColor = options.overlayBackgroundColor;