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

Make image hotspot more accessible #2

Open
wants to merge 1 commit 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
11 changes: 9 additions & 2 deletions scripts/hotspot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@
* @param {boolean} isSmallDeviceCB
* @param {H5P.ImageHotspots} parent
*/
ImageHotspots.Hotspot = function (config, color, id, isSmallDeviceCB, parent) {
ImageHotspots.Hotspot = function (config, color, id, isSmallDeviceCB, parent, index) {
var self = this;
this.config = config;
this.visible = false;
this.id = id;
this.isSmallDeviceCB = isSmallDeviceCB;
this.tabIndex = index;

if (!this.config.content.length) {
throw new Error('Missing mandatory library for hotspot');
}

this.$element = $('<div/>', {
'id': 'hotspot-' + this.tabIndex,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be multiple imagehotspots in the same dom, this would result in non unique IDs :/

'class': 'h5p-image-hotspot',
'title': 'Clickable hotspot number: '+ this.tabIndex,
'tabindex': this.tabIndex,
click: function(){
if(self.visible) {
self.hidePopup();
Expand Down Expand Up @@ -76,7 +80,10 @@
var self = this;

// Create popup content:
var $popupBody = $('<div/>', {'class': 'h5p-image-hotspot-popup-body'});
var $popupBody = $('<div/>', {
'class': 'h5p-image-hotspot-popup-body',
'title': 'The hotspot name is: ' + self.config.header
});

this.actionInstances = [];
var waitForLoaded = [];
Expand Down
3 changes: 2 additions & 1 deletion scripts/image-hotspots.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ H5P.ImageHotspots = (function ($, EventDispatcher) {
if (this.options.image && this.options.image.path) {
this.$image = $('<img/>', {
'class': 'h5p-image-hotspots-background',
'alt': this.options.alt,
src: H5P.getPath(this.options.image.path, this.id)
}).appendTo(this.$hotspotContainer);
}
Expand All @@ -79,7 +80,7 @@ H5P.ImageHotspots = (function ($, EventDispatcher) {
var numHotspots = this.options.hotspots.length;
for(var i=0; i<numHotspots; i++) {
try {
new ImageHotspots.Hotspot(this.options.hotspots[i], this.options.color, this.id, isSmallDevice, self).appendTo(this.$hotspotContainer);
new ImageHotspots.Hotspot(this.options.hotspots[i], this.options.color, this.id, isSmallDevice, self, i + 1).appendTo(this.$hotspotContainer);
}
catch (e) {
H5P.error(e);
Expand Down
6 changes: 6 additions & 0 deletions semantics.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
"showInput": true
}
},
{
"label": "Alternate text for the image",
"name": "alt",
"type": "text",
"description": "Put the alternate text here to make the image accessible!"
},
{
"name": "hotspots",
"type": "list",
Expand Down