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

Feature/accessibility support #411

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
39 changes: 30 additions & 9 deletions src/galleria.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,19 @@ var doc = window.document,
return protoArray.slice.call(obj, 0);
},

create : function( className, nodeName ) {
create : function( className, nodeName, attributes ) {
nodeName = nodeName || 'div';
var elem = doc.createElement( nodeName );
elem.className = className;

// attributes f.ex "role" for accessibility support
if (attributes) {
for (var attrName in attributes) {
if (attributes.hasOwnProperty(attrName)) {
elem.setAttribute(attrName, attributes[attrName]);
}
}
}
return elem;
},

Expand Down Expand Up @@ -1202,11 +1211,13 @@ Galleria = function() {
this._id = parseInt(M.random()*10000, 10);

// add some elements
var divs = 'container stage images image-nav image-nav-left image-nav-right ' +
var divs = 'container stage images image-nav ' +
'info info-text info-title info-description ' +
'thumbnails thumbnails-list thumbnails-container thumb-nav-left thumb-nav-right ' +
'thumbnails thumbnails-list thumbnails-container ' +
'loader counter tooltip',
spans = 'current total';
spans = 'current total',
buttons = 'image-nav-left image-nav-right ' +
'thumb-nav-left thumb-nav-right ';

$.each( divs.split(' '), function( i, elemId ) {
self._dom[ elemId ] = Utils.create( 'galleria-' + elemId );
Expand All @@ -1216,6 +1227,12 @@ Galleria = function() {
self._dom[ elemId ] = Utils.create( 'galleria-' + elemId, 'span' );
});

$.each( buttons.split(' '), function( i, elemId ) {
self._dom[ elemId ] = Utils.create( 'galleria-' + elemId, 'button', {
role: 'button'
});
});

// the internal keyboard object
// keeps reference of the keybinds and provides helper methods for binding keys
var keyboard = this._keyboard = {
Expand Down Expand Up @@ -2870,7 +2887,7 @@ Galleria.prototype = {
'info' :
['info-text'],
'image-nav' :
['image-nav-right', 'image-nav-left'],
['image-nav-left', 'image-nav-right'],
'stage' :
['images', 'loader', 'counter', 'image-nav'],
'thumbnails-list' :
Expand Down Expand Up @@ -3427,7 +3444,7 @@ Galleria.prototype = {
if ( ( o.thumbnails === true || optval == 'lazy' ) && ( data.thumb || data.image ) ) {

// add a new Picture instance
thumb = new Galleria.Picture(i);
thumb = new Galleria.Picture(i, true);

// save the index
thumb.index = i;
Expand Down Expand Up @@ -3488,7 +3505,7 @@ Galleria.prototype = {
// create empty spans if thumbnails is set to 'empty'
} else if ( ( data.iframe && optval !== null ) || optval === 'empty' || optval === 'numbers' ) {
thumb = {
container: Utils.create( 'galleria-image' ),
container: Utils.create( 'galleria-image', 'button', { role: 'button' }),
image: Utils.create( 'img', 'span' ),
ready: true,
data: {
Expand Down Expand Up @@ -6097,7 +6114,7 @@ Galleria.requires = function( version, msg ) {
@param {number} [id] Optional id to keep track of instances
*/

Galleria.Picture = function( id ) {
Galleria.Picture = function( id, asButton ) {

// save the id
this.id = id || null;
Expand All @@ -6106,7 +6123,11 @@ Galleria.Picture = function( id ) {
this.image = null;

// Create a new container
this.container = Utils.create('galleria-image');
if (asButton) {
this.container = Utils.create('galleria-image', 'button', { role: 'button' });
} else {
this.container = Utils.create('galleria-image');
}

// add container styles
$( this.container ).css({
Expand Down
4 changes: 4 additions & 0 deletions src/themes/classic/galleria.classic.css
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@
left: 10px;
z-index: 2;
background-position: 0 46px;
background-color: transparent;
border: 0;
}
.galleria-theme-classic .galleria-image-nav-right {
left: auto;
Expand Down Expand Up @@ -180,6 +182,8 @@
z-index: 3;
opacity: .8;
filter: alpha(opacity=80);
background-color: transparent;
border: 0;
}
.galleria-theme-classic .galleria-thumb-nav-right {
background-position: -578px 5px;
Expand Down