Skip to content

Commit 013f5ec

Browse files
committed
Add support for data-state-captions and data-state-descriptions
1 parent b54f420 commit 013f5ec

8 files changed

Lines changed: 125 additions & 37 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ The following attributes are supported on both the `<audio>` and `<video>` eleme
242242
#### Captions
243243

244244
- **data-captions-position** - optional; specify default position of captions relative to the video (either "below" or "overlay"; "below" is the default if not specified). Users can override this setting in Captions Preferences.
245+
- **data-state-captions** - optional; "on" or "off". Captions are on by default if they're available, but this allows website owners to override that setting. If users enable captions, their preference will be saved in a cookie, and that will override the default setting on future visits.
245246

246247
#### Transcript
247248

@@ -383,7 +384,7 @@ available, add a **data-desc-src** attribute to the `<source>` element for
383384
that video. The value of this attribute is a path pointing to the
384385
described version of the video. With this method, the described version
385386
of the video can be played instead of the non-described version, and the
386-
two versions can be swapped with clicking the "D" button on the
387+
two versions can be swapped with clicking the "Descriptions" button on the
387388
controller.
388389

389390
If descriptions are available using either of the above methods, a
@@ -406,6 +407,9 @@ by screen readers or browsers (for example, if the sole video source is a descr
406407
In such cases, use **data-descriptions-audible="false"** to prevent browsers and screen readers
407408
from announcing the description text.
408409

410+
If description is available through either of the above methods, it is off by default and users must enable it using the "Descriptions" button on the player control. Website owners can override
411+
this setting and change the default state to "on" using **data-state-descriptions="on"**. If users have turned descriptions off on the same website, their preference will be saved in a cookie, and that will override the default setting on future visits.
412+
409413
#### Sign language
410414

411415
Sign language translation is supported in a separate video player,

build/ableplayer.dist.js

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,7 @@ var AblePlayerInstances = [];
166166
else {
167167
this.useChaptersButton = true;
168168
}
169-
170-
if ($(media).data('use-descriptions-button') !== undefined && $(media).data('use-descriptions-button') === false) {
171-
this.useDescriptionsButton = false;
172-
}
173-
else {
174-
this.useDescriptionsButton = true;
175-
}
176-
169+
177170
// Control whether text descriptions are read aloud
178171
// set to "false" if the sole purpose of the WebVTT descriptions file
179172
// is to integrate text description into the transcript
@@ -204,6 +197,22 @@ var AblePlayerInstances = [];
204197
this.descReader = 'browser';
205198
}
206199

200+
// Default state of captions and descriptions
201+
// This setting is overridden by user preferences, if they exist
202+
// values for data-state-captions and data-state-descriptions are 'on' or 'off'
203+
if ($(media).data('state-captions') == 'off') {
204+
this.defaultStateCaptions = 'off';
205+
}
206+
else {
207+
this.defaultStateCaptions = 'on'; // on by default
208+
}
209+
if ($(media).data('state-descriptions') == 'on') {
210+
this.defaultStateDescriptions = 'on';
211+
}
212+
else {
213+
this.defaultStateDescriptions = 'off'; // off by default
214+
}
215+
207216
// Headings
208217
// By default, an off-screen heading is automatically added to the top of the media player
209218
// It is intelligently assigned a heading level based on context, via misc.js > getNextHeadingLevel()
@@ -5497,9 +5506,18 @@ var AblePlayerInstances = [];
54975506
if (this.prefCaptions === 1) {
54985507
this.captionsOn = true;
54995508
}
5500-
else {
5509+
else if (this.prefCaptions === 0) {
55015510
this.captionsOn = false;
55025511
}
5512+
else {
5513+
// user has no prefs. Use default state.
5514+
if (this.defaultStateCaptions === 'on') {
5515+
this.captionsOn = true;
5516+
}
5517+
else {
5518+
this.captionsOn = false;
5519+
}
5520+
}
55035521
}
55045522
else {
55055523
this.hasCaptions = false;
@@ -7202,6 +7220,7 @@ if (thisObj.useTtml && (trackSrc.endsWith('.xml') || trackText.startsWith('<?xml
72027220
// In the latter two scendarios, this.refreshingDesc == true via control.js > handleDescriptionToggle()
72037221

72047222
// The following variables are applicable to delivery of description:
7223+
// defaultStateDescriptions == 'on' or 'off', defined by website owner (overridden by prefDesc)
72057224
// prefDesc == 1 if user wants description (i.e., Description button is on); else 0
72067225
// prefDescPause == 1 to pause video when description starts; else 0
72077226
// prefDescVisible == 1 to visibly show text-based description area; else 0
@@ -7259,12 +7278,21 @@ if (thisObj.useTtml && (trackSrc.endsWith('.xml') || trackText.startsWith('<?xml
72597278

72607279
// Set the default state of descriptions
72617280
if (this.descMethod) {
7262-
if (this.prefDesc) {
7281+
if (this.prefDesc === 1) {
72637282
this.descOn = true;
72647283
}
7265-
else {
7284+
else if (this.prefDesc === 0) {
72667285
this.descOn = false;
72677286
}
7287+
else {
7288+
// user has no prefs. Use default state.
7289+
if (this.defaultStateDescriptions === 'on') {
7290+
this.descOn = true;
7291+
}
7292+
else {
7293+
this.descOn = false;
7294+
}
7295+
}
72687296
}
72697297
else {
72707298
this.descOn = false;

build/ableplayer.js

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,7 @@ var AblePlayerInstances = [];
166166
else {
167167
this.useChaptersButton = true;
168168
}
169-
170-
if ($(media).data('use-descriptions-button') !== undefined && $(media).data('use-descriptions-button') === false) {
171-
this.useDescriptionsButton = false;
172-
}
173-
else {
174-
this.useDescriptionsButton = true;
175-
}
176-
169+
177170
// Control whether text descriptions are read aloud
178171
// set to "false" if the sole purpose of the WebVTT descriptions file
179172
// is to integrate text description into the transcript
@@ -204,6 +197,22 @@ var AblePlayerInstances = [];
204197
this.descReader = 'browser';
205198
}
206199

200+
// Default state of captions and descriptions
201+
// This setting is overridden by user preferences, if they exist
202+
// values for data-state-captions and data-state-descriptions are 'on' or 'off'
203+
if ($(media).data('state-captions') == 'off') {
204+
this.defaultStateCaptions = 'off';
205+
}
206+
else {
207+
this.defaultStateCaptions = 'on'; // on by default
208+
}
209+
if ($(media).data('state-descriptions') == 'on') {
210+
this.defaultStateDescriptions = 'on';
211+
}
212+
else {
213+
this.defaultStateDescriptions = 'off'; // off by default
214+
}
215+
207216
// Headings
208217
// By default, an off-screen heading is automatically added to the top of the media player
209218
// It is intelligently assigned a heading level based on context, via misc.js > getNextHeadingLevel()
@@ -5497,9 +5506,18 @@ var AblePlayerInstances = [];
54975506
if (this.prefCaptions === 1) {
54985507
this.captionsOn = true;
54995508
}
5500-
else {
5509+
else if (this.prefCaptions === 0) {
55015510
this.captionsOn = false;
55025511
}
5512+
else {
5513+
// user has no prefs. Use default state.
5514+
if (this.defaultStateCaptions === 'on') {
5515+
this.captionsOn = true;
5516+
}
5517+
else {
5518+
this.captionsOn = false;
5519+
}
5520+
}
55035521
}
55045522
else {
55055523
this.hasCaptions = false;
@@ -7202,6 +7220,7 @@ if (thisObj.useTtml && (trackSrc.endsWith('.xml') || trackText.startsWith('<?xml
72027220
// In the latter two scendarios, this.refreshingDesc == true via control.js > handleDescriptionToggle()
72037221

72047222
// The following variables are applicable to delivery of description:
7223+
// defaultStateDescriptions == 'on' or 'off', defined by website owner (overridden by prefDesc)
72057224
// prefDesc == 1 if user wants description (i.e., Description button is on); else 0
72067225
// prefDescPause == 1 to pause video when description starts; else 0
72077226
// prefDescVisible == 1 to visibly show text-based description area; else 0
@@ -7259,12 +7278,21 @@ if (thisObj.useTtml && (trackSrc.endsWith('.xml') || trackText.startsWith('<?xml
72597278

72607279
// Set the default state of descriptions
72617280
if (this.descMethod) {
7262-
if (this.prefDesc) {
7281+
if (this.prefDesc === 1) {
72637282
this.descOn = true;
72647283
}
7265-
else {
7284+
else if (this.prefDesc === 0) {
72667285
this.descOn = false;
72677286
}
7287+
else {
7288+
// user has no prefs. Use default state.
7289+
if (this.defaultStateDescriptions === 'on') {
7290+
this.descOn = true;
7291+
}
7292+
else {
7293+
this.descOn = false;
7294+
}
7295+
}
72687296
}
72697297
else {
72707298
this.descOn = false;

build/ableplayer.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ableplayer",
3-
"version": "4.4.16",
3+
"version": "4.4.17",
44
"description": "fully accessible HTML5 media player",
55
"homepage": "http://ableplayer.github.io/ableplayer",
66
"bugs": "https://github.com/ableplayer/ableplayer/issues",

scripts/ableplayer-base.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,7 @@ var AblePlayerInstances = [];
166166
else {
167167
this.useChaptersButton = true;
168168
}
169-
170-
if ($(media).data('use-descriptions-button') !== undefined && $(media).data('use-descriptions-button') === false) {
171-
this.useDescriptionsButton = false;
172-
}
173-
else {
174-
this.useDescriptionsButton = true;
175-
}
176-
169+
177170
// Control whether text descriptions are read aloud
178171
// set to "false" if the sole purpose of the WebVTT descriptions file
179172
// is to integrate text description into the transcript
@@ -204,6 +197,22 @@ var AblePlayerInstances = [];
204197
this.descReader = 'browser';
205198
}
206199

200+
// Default state of captions and descriptions
201+
// This setting is overridden by user preferences, if they exist
202+
// values for data-state-captions and data-state-descriptions are 'on' or 'off'
203+
if ($(media).data('state-captions') == 'off') {
204+
this.defaultStateCaptions = 'off';
205+
}
206+
else {
207+
this.defaultStateCaptions = 'on'; // on by default
208+
}
209+
if ($(media).data('state-descriptions') == 'on') {
210+
this.defaultStateDescriptions = 'on';
211+
}
212+
else {
213+
this.defaultStateDescriptions = 'off'; // off by default
214+
}
215+
207216
// Headings
208217
// By default, an off-screen heading is automatically added to the top of the media player
209218
// It is intelligently assigned a heading level based on context, via misc.js > getNextHeadingLevel()

scripts/description.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// In the latter two scendarios, this.refreshingDesc == true via control.js > handleDescriptionToggle()
1010

1111
// The following variables are applicable to delivery of description:
12+
// defaultStateDescriptions == 'on' or 'off', defined by website owner (overridden by prefDesc)
1213
// prefDesc == 1 if user wants description (i.e., Description button is on); else 0
1314
// prefDescPause == 1 to pause video when description starts; else 0
1415
// prefDescVisible == 1 to visibly show text-based description area; else 0
@@ -66,12 +67,21 @@
6667

6768
// Set the default state of descriptions
6869
if (this.descMethod) {
69-
if (this.prefDesc) {
70+
if (this.prefDesc === 1) {
7071
this.descOn = true;
7172
}
72-
else {
73+
else if (this.prefDesc === 0) {
7374
this.descOn = false;
7475
}
76+
else {
77+
// user has no prefs. Use default state.
78+
if (this.defaultStateDescriptions === 'on') {
79+
this.descOn = true;
80+
}
81+
else {
82+
this.descOn = false;
83+
}
84+
}
7585
}
7686
else {
7787
this.descOn = false;

scripts/track.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,18 @@
263263
if (this.prefCaptions === 1) {
264264
this.captionsOn = true;
265265
}
266-
else {
266+
else if (this.prefCaptions === 0) {
267267
this.captionsOn = false;
268268
}
269+
else {
270+
// user has no prefs. Use default state.
271+
if (this.defaultStateCaptions === 'on') {
272+
this.captionsOn = true;
273+
}
274+
else {
275+
this.captionsOn = false;
276+
}
277+
}
269278
}
270279
else {
271280
this.hasCaptions = false;

0 commit comments

Comments
 (0)