Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to localize the aria labels #886

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,18 @@ var flky = new Flickity( '.gallery', {
// watches the content of :after of the element
// activates if #element:after { content: 'flickity' }

wrapAround: false
wrapAround: false,
// at end of cells, wraps-around to first for infinite scrolling

pageDotAriaLabel: 'Page dot %n'
// Aria label for the page dots. `%n` gets replaced with the slide number

previousAriaLabel: 'Previous',
// Aria label for the previous button

nextAriaLabel: 'Next'
// Aria label for the next button

});
```

Expand Down
5 changes: 4 additions & 1 deletion js/page-dots.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ PageDots.prototype.addDots = function( count ) {
var newDots = [];
var length = this.dots.length;
var max = length + count;
var ariaLabel = this.parent.options.pageDotAriaLabel;

for ( var i = length; i < max; i++ ) {
var dot = document.createElement('li');
var label = ariaLabel.replace( '%n', i + 1 );
dot.className = 'dot';
dot.setAttribute( 'aria-label', 'Page dot ' + ( i + 1 ) );
dot.setAttribute( 'aria-label', label );
fragment.appendChild( dot );
newDots.push( dot );
}
Expand Down Expand Up @@ -143,6 +145,7 @@ Flickity.PageDots = PageDots;

utils.extend( Flickity.defaults, {
pageDots: true,
pageDotAriaLabel: 'Page dot %n'
} );

Flickity.createMethods.push('_createPageDots');
Expand Down
6 changes: 5 additions & 1 deletion js/prev-next-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ PrevNextButton.prototype._create = function() {
// init as disabled
this.disable();

element.setAttribute( 'aria-label', this.isPrevious ? 'Previous' : 'Next' );
var optionName = this.isPrevious ? 'previous' : 'next';
var label = this.parent.options[ optionName + 'AriaLabel' ];
element.setAttribute('aria-label', label);

// create arrow
var svg = this.createSVG();
Expand Down Expand Up @@ -167,6 +169,8 @@ PrevNextButton.prototype.destroy = function() {

utils.extend( Flickity.defaults, {
prevNextButtons: true,
previousAriaLabel: 'Previous',
nextAriaLabel: 'Next',
arrowShape: {
x0: 10,
x1: 60, y1: 50,
Expand Down