Skip to content

Commit dff35ad

Browse files
committed
Override most defaults with data-* attribs
1 parent 62d87d3 commit dff35ad

4 files changed

Lines changed: 141 additions & 47 deletions

File tree

build/ableplayer.js

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
// HTML5 Media API:
55
// http://www.w3.org/TR/html5/embedded-content-0.html#htmlmediaelement
6+
// http://dev.w3.org/html5/spec-author-view/video.html
67
78
// W3C API Test Page:
89
// http://www.w3.org/2010/05/video/mediaevents.html
@@ -26,18 +27,7 @@
2627
$(document).ready(function () {
2728
$('video, audio').each(function (index, element) {
2829
if ($(element).data('able-player') !== undefined) {
29-
var includeTranscript = $(element).data('include-transcript');
30-
if (includeTranscript === undefined || includeTranscript === "") {
31-
// If there are caption tracks and no default provided, include transcript.
32-
if ($(element).find('track[kind="captions"], track[kind="subtitles"]').length > 0) {
33-
includeTranscript = true;
34-
}
35-
}
36-
new AblePlayer($(this),
37-
$(element).data('start-time') || 0,
38-
includeTranscript,
39-
$(element).data('transcript-div'),
40-
$(element).data('youtube-id'));
30+
new AblePlayer($(this),$(element));
4131
}
4232
});
4333
});
@@ -60,8 +50,7 @@
6050
// Construct an AblePlayer object
6151
// Parameters are:
6252
// media - jQuery selector or element identifying the media.
63-
// startTime - the time at which to begin playing the media
64-
window.AblePlayer = function(media, startTime, includeTranscript, transcriptDiv, youtubeId) {
53+
window.AblePlayer = function(media) {
6554
// Keep track of the last player created for use with global events.
6655
AblePlayer.lastCreated = this;
6756

@@ -73,29 +62,86 @@
7362
return;
7463
}
7564

76-
if (transcriptDiv) {
77-
this.transcriptDivLocation = transcriptDiv;
65+
// override defaults with values of data-* attributes
66+
67+
var includeTranscript = media.data('include-transcript');
68+
if (includeTranscript === undefined || includeTranscript === "") {
69+
// If there are caption tracks and no default provided, include transcript.
70+
if (media.find('track[kind="captions"], track[kind="subtitles"]').length > 0) {
71+
includeTranscript = true;
72+
}
7873
}
79-
8074
if (includeTranscript) {
8175
this.includeTranscript = true;
8276
}
8377
else {
8478
this.includeTranscript = false;
8579
}
86-
87-
if (startTime) {
88-
this.startTime = startTime;
80+
81+
if ($(media).data('start-time') !== undefined && $(media).data('start-time') !== "") {
82+
this.startTime = $(media).data('start-time');
8983
}
9084
else {
9185
this.startTime = 0;
9286
}
9387

88+
if ($(media).data('transcript-div') !== undefined && $(media).data('transcript-div') !== "") {
89+
this.transcriptDivLocation = $(media).data('transcript-div');
90+
}
91+
92+
if ($(media).data('youtube-id') !== undefined && $(media).data('youtube-id') !== "") {
93+
this.youtubeId = $(media).data('youtube-id');
94+
}
95+
96+
if ($(media).data('debug') !== undefined && $(media).data('debug') !== "false") {
97+
this.debug = true;
98+
}
99+
100+
if ($(media).data('youtube-id') !== undefined && $(media).data('youtube-id') !== "") {
101+
// add validation
102+
this.youtubeId = $(media).data('youtube-id');
103+
}
104+
105+
if ($(media).data('volume') !== undefined && $(media).data('volume') !== "") {
106+
// add validation
107+
this.defaultVolume = $(media).data('volume');
108+
}
109+
110+
if ($(media).data('icon-type') !== undefined && $(media).data('icon-type') !== "") {
111+
// add validation
112+
this.iconType = $(media).data('icon-type');
113+
}
114+
115+
if ($(media).data('seek-interval') !== undefined && $(media).data('seek-interval') !== "") {
116+
// add validation
117+
this.seekInterval = $(media).data('seek-interval');
118+
}
119+
console.log('seekInterval is ' + this.seekInterval);
120+
121+
if ($(media).data('show-now-playing') !== undefined && $(media).data('show-now-playing') !== "false") {
122+
this.showNowPlaying = true;
123+
}
124+
125+
if ($(media).data('fallback') !== undefined && $(media).data('fallback') !== "") {
126+
// add validation
127+
this.fallback = $(media).data('fallback');
128+
}
129+
130+
if ($(media).data('test-fallback') !== undefined && $(media).data('test-fallback') !== "false") {
131+
this.testFallback = true;
132+
}
133+
134+
if ($(media).data('lang') !== undefined && $(media).data('lang') !== "") {
135+
this.lang = $(media).data('lang');
136+
}
137+
138+
if ($(media).data('lang-override') !== undefined && $(media).data('lang-override') !== "false") {
139+
this.langOverride = true;
140+
}
141+
94142
this.ableIndex = AblePlayer.nextIndex;
95143
AblePlayer.nextIndex += 1;
96144

97-
this.youtubeId = youtubeId;
98-
99145
this.title = $(media).attr('title');
100146

101147
// populate translation object with localized versions of all labels and prompts
@@ -190,6 +236,7 @@
190236
(function () {
191237
// Set default variable values.
192238
AblePlayer.prototype.setDefaults = function () {
239+
193240
// Debug - set to true to write messages to console; otherwise false
194241
this.debug = false;
195242

@@ -256,7 +303,7 @@
256303
this.langOverride = true;
257304

258305
// translationDir - specify path to translation files
259-
this.translationDir = '/translations/';
306+
this.translationDir = '../translations/';
260307

261308
this.setButtonImages();
262309
};

scripts/ableplayer-base.js

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
// HTML5 Media API:
55
// http://www.w3.org/TR/html5/embedded-content-0.html#htmlmediaelement
6+
// http://dev.w3.org/html5/spec-author-view/video.html
67
78
// W3C API Test Page:
89
// http://www.w3.org/2010/05/video/mediaevents.html
@@ -26,18 +27,7 @@
2627
$(document).ready(function () {
2728
$('video, audio').each(function (index, element) {
2829
if ($(element).data('able-player') !== undefined) {
29-
var includeTranscript = $(element).data('include-transcript');
30-
if (includeTranscript === undefined || includeTranscript === "") {
31-
// If there are caption tracks and no default provided, include transcript.
32-
if ($(element).find('track[kind="captions"], track[kind="subtitles"]').length > 0) {
33-
includeTranscript = true;
34-
}
35-
}
36-
new AblePlayer($(this),
37-
$(element).data('start-time') || 0,
38-
includeTranscript,
39-
$(element).data('transcript-div'),
40-
$(element).data('youtube-id'));
30+
new AblePlayer($(this),$(element));
4131
}
4232
});
4333
});
@@ -60,8 +50,7 @@
6050
// Construct an AblePlayer object
6151
// Parameters are:
6252
// media - jQuery selector or element identifying the media.
63-
// startTime - the time at which to begin playing the media
64-
window.AblePlayer = function(media, startTime, includeTranscript, transcriptDiv, youtubeId) {
53+
window.AblePlayer = function(media) {
6554
// Keep track of the last player created for use with global events.
6655
AblePlayer.lastCreated = this;
6756

@@ -73,29 +62,86 @@
7362
return;
7463
}
7564

76-
if (transcriptDiv) {
77-
this.transcriptDivLocation = transcriptDiv;
65+
// override defaults with values of data-* attributes
66+
67+
var includeTranscript = media.data('include-transcript');
68+
if (includeTranscript === undefined || includeTranscript === "") {
69+
// If there are caption tracks and no default provided, include transcript.
70+
if (media.find('track[kind="captions"], track[kind="subtitles"]').length > 0) {
71+
includeTranscript = true;
72+
}
7873
}
79-
8074
if (includeTranscript) {
8175
this.includeTranscript = true;
8276
}
8377
else {
8478
this.includeTranscript = false;
8579
}
86-
87-
if (startTime) {
88-
this.startTime = startTime;
80+
81+
if ($(media).data('start-time') !== undefined && $(media).data('start-time') !== "") {
82+
this.startTime = $(media).data('start-time');
8983
}
9084
else {
9185
this.startTime = 0;
9286
}
9387

88+
if ($(media).data('transcript-div') !== undefined && $(media).data('transcript-div') !== "") {
89+
this.transcriptDivLocation = $(media).data('transcript-div');
90+
}
91+
92+
if ($(media).data('youtube-id') !== undefined && $(media).data('youtube-id') !== "") {
93+
this.youtubeId = $(media).data('youtube-id');
94+
}
95+
96+
if ($(media).data('debug') !== undefined && $(media).data('debug') !== "false") {
97+
this.debug = true;
98+
}
99+
100+
if ($(media).data('youtube-id') !== undefined && $(media).data('youtube-id') !== "") {
101+
// add validation
102+
this.youtubeId = $(media).data('youtube-id');
103+
}
104+
105+
if ($(media).data('volume') !== undefined && $(media).data('volume') !== "") {
106+
// add validation
107+
this.defaultVolume = $(media).data('volume');
108+
}
109+
110+
if ($(media).data('icon-type') !== undefined && $(media).data('icon-type') !== "") {
111+
// add validation
112+
this.iconType = $(media).data('icon-type');
113+
}
114+
115+
if ($(media).data('seek-interval') !== undefined && $(media).data('seek-interval') !== "") {
116+
// add validation
117+
this.seekInterval = $(media).data('seek-interval');
118+
}
119+
console.log('seekInterval is ' + this.seekInterval);
120+
121+
if ($(media).data('show-now-playing') !== undefined && $(media).data('show-now-playing') !== "false") {
122+
this.showNowPlaying = true;
123+
}
124+
125+
if ($(media).data('fallback') !== undefined && $(media).data('fallback') !== "") {
126+
// add validation
127+
this.fallback = $(media).data('fallback');
128+
}
129+
130+
if ($(media).data('test-fallback') !== undefined && $(media).data('test-fallback') !== "false") {
131+
this.testFallback = true;
132+
}
133+
134+
if ($(media).data('lang') !== undefined && $(media).data('lang') !== "") {
135+
this.lang = $(media).data('lang');
136+
}
137+
138+
if ($(media).data('lang-override') !== undefined && $(media).data('lang-override') !== "false") {
139+
this.langOverride = true;
140+
}
141+
94142
this.ableIndex = AblePlayer.nextIndex;
95143
AblePlayer.nextIndex += 1;
96144

97-
this.youtubeId = youtubeId;
98-
99145
this.title = $(media).attr('title');
100146

101147
// populate translation object with localized versions of all labels and prompts

scripts/initialize.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(function () {
22
// Set default variable values.
33
AblePlayer.prototype.setDefaults = function () {
4+
45
// Debug - set to true to write messages to console; otherwise false
56
this.debug = false;
67

@@ -67,7 +68,7 @@
6768
this.langOverride = true;
6869

6970
// translationDir - specify path to translation files
70-
this.translationDir = '/translations/';
71+
this.translationDir = '../translations/';
7172

7273
this.setButtonImages();
7374
};

tests/test7b.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h1>Able Player Test #7b:<br/>Video player with interactive transcript in an ext
2929

3030
<!-- to write transcript to an external div, pass id of an empty div via data-transcript-div -->
3131

32-
<video id="video1" preload="auto" width="480" height="360" poster="../media/wwa.jpg" data-able-player data-transcript-div="transcript">
32+
<video id="video1" preload="auto" width="480" height="360" poster="../media/wwa.jpg" data-able-player data-transcript-div="transcript" data-seek-interval="5">
3333
<source type="video/webm" src="../media/wwa.webm" data-desc-src="../media/wwa_described.webm"/>
3434
<source type="video/mp4" src="../media/wwa.mp4" data-desc-src="../media/wwa_described.mp4"/>
3535
<track kind="captions" src="../media/wwa_captions_en.vtt" srclang="en" label="English"/>

0 commit comments

Comments
 (0)