Skip to content

Commit

Permalink
✨ Improve DOM accessible elements
Browse files Browse the repository at this point in the history
  • Loading branch information
frncesc committed May 26, 2020
1 parent c94e3d7 commit db9da3a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### v1.1.15 (Not yet released)
### v1.1.15 (2020-05-26)
#### Bug fixes
- Unset `box-shadow` and `text-shadow` attributes in custom buttons
- Fallback accessible components for `canvas` regions should always be created since `[HitRegions](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/addHitRegion)` have been deprecated. Also, `[CanvasRenderingContext2D.drawFocusIfNeeded](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawFocusIfNeeded)` should be called on each call to `ActiveBox.updateContent`, not just at creation time.
- Accessible components for `canvas` regions should always be created since [`HitRegions`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/addHitRegion) have been deprecated. Also, [`CanvasRenderingContext2D.drawFocusIfNeeded`](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawFocusIfNeeded) should be called on each call to `updateContent` on ActiveBox objects, not just at creation time.

#### Improvements
- Map JDK logical fonts ("Dialog", "Serif", etc.) to [HTML5 generic font family names](https://developer.mozilla.org/en-US/docs/Web/CSS/font-family)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jclic",
"title": "JClic.js",
"description": "HTML5 player for JClic activities",
"version": "1.1.15-beta-2",
"version": "1.1.15",
"main": "src/JClic.js",
"jsdelivr": "dist/jclic.min.js",
"homepage": "http://projectestac.github.io/jclic.js",
Expand Down
1 change: 0 additions & 1 deletion src/JClic.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ define([
*/
loadProject: function (div, projectName, options) {

//options = Utils.init(Object.assign({}, JClicObject.options, options))
options = Utils.init($.extend(Object.create(JClicObject.options), options || {}))
let player = null

Expand Down
5 changes: 3 additions & 2 deletions src/activities/panels/Explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ define([
if (this.act.useOrder)
this.currentItem = this.bgA.getNextItem(this.currentItem)
this.ps.reportNewAction(this.act, 'SELECT', bx1.getDescription(), bx2.getDescription(), true, 0)
if (bx2.$accessibleElement)
bx2.$accessibleElement.focus()
// Modified May 2020: Focusing `accessibleElement` will always draw a border on bx2
// if (bx2.$accessibleElement)
// bx2.$accessibleElement.focus()
} else {
bx2.clear()
bx2.setInactive(false)
Expand Down
15 changes: 15 additions & 0 deletions src/activities/text/WrittenAnswer.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,21 @@ define([
}
}

/**
* Builds the accessible components needed for this ActivityPanel
* This method is called when all main elements are placed and visible, when the activity is ready
* to start or when resized.
* @override
*/
buildAccessibleComponents() {
if (this.$canvas && this.accessibleCanvas) {
super.buildAccessibleComponents()
if (this.bgA)
this.bgA.buildAccessibleElements(this.$canvas, this.$div, 'click')
// bgB has a regular input element, so it's already accessible
}
}

/**
* Checks if all inverse associations are done
* @returns {boolean}
Expand Down
27 changes: 20 additions & 7 deletions src/boxes/ActiveBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ define([
box.setContent(abc)
box.setBounds(rect)
$dom.append($canvas)
// Create accessible, focusable elements only for cells with media content
// TODO: remove focus mark on blur in cells placed on fillInBlanks activities
if (abc.mediaContent)
box.buildAccessibleElement($canvas, $dom)
box.update($canvas.get(-1).getContext('2d'), rect)
return box
}
Expand Down Expand Up @@ -409,8 +413,10 @@ define([
abc = this.getCurrentContent(),
bb = this.getBoxBaseResolve()

if (this.isInactive() || !abc || this.dim.width < 2 || this.dim.height < 2)
if (this.isInactive() || !abc || this.dim.width < 2 || this.dim.height < 2) {
this._focusAccessibleElement(ctx)
return true
}

if (dirtyRegion && !this.intersects(dirtyRegion))
return false
Expand Down Expand Up @@ -576,13 +582,20 @@ define([
}
}

this._focusAccessibleElement(ctx)

return true
}

/**
* Draw focus on accessible element if needed
* @param {external:CanvasRenderingContext2D} ctx - The canvas rendering context
*/
_focusAccessibleElement(ctx) {
if (Utils.settings.CANVAS_DRAW_FOCUS && this.$accessibleElement) {
const elem = this.$accessibleElement.get(-1);
this.shape.preparePath(ctx);
ctx.drawFocusIfNeeded(elem);
ctx.drawFocusIfNeeded(this.$accessibleElement.get(-1));
}

return true
}

/**
Expand Down Expand Up @@ -737,10 +750,10 @@ define([
if (Utils.settings.CANVAS_DRAW_FOCUS) {
this.$accessibleElement.on('focus blur', ev => {
Utils.log('debug', `${ev.type} event on accessible element: ${this.toString()}`)
this.invalidate();
if (this.container)
this.container.update();
else
this.updateContent(canvas.getContext(), null);
this.updateContent(canvas.getContext('2d'), null);
})
}
}
Expand Down

0 comments on commit db9da3a

Please sign in to comment.