Skip to content

Commit 1ed3a19

Browse files
authored
fix: position, lineAlign, positionAlign (#36)
Also, increase backwards compatibility and compatibility with native vttcue implementations.
1 parent f580f83 commit 1ed3a19

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

lib/vtt.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ function parseCue(input, cue, regionList) {
213213
// Apply default values for any missing fields.
214214
cue.region = settings.get("region", null);
215215
cue.vertical = settings.get("vertical", "");
216-
cue.line = settings.get("line", "auto");
216+
try {
217+
cue.line = settings.get("line", "auto");
218+
} catch (e) {}
217219
cue.lineAlign = settings.get("lineAlign", "start");
218220
cue.snapToLines = settings.get("snapToLines", true);
219221
cue.size = settings.get("size", 100);
@@ -223,14 +225,20 @@ function parseCue(input, cue, regionList) {
223225
} catch (e) {
224226
cue.align = settings.get("align", "middle");
225227
}
226-
cue.position = settings.get("position", {
227-
start: 0,
228-
left: 0,
229-
center: 50,
230-
middle: 50,
231-
end: 100,
232-
right: 100
233-
}, cue.align);
228+
try {
229+
cue.position = settings.get("position", "auto");
230+
} catch (e) {
231+
cue.position = settings.get("position", {
232+
start: 0,
233+
left: 0,
234+
center: 50,
235+
middle: 50,
236+
end: 100,
237+
right: 100
238+
}, cue.align);
239+
}
240+
241+
234242
cue.positionAlign = settings.get("positionAlign", {
235243
start: "start",
236244
left: "start",

lib/vttcue.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ var alignSetting = {
2525
"center": 1,
2626
"end": 1,
2727
"left": 1,
28-
"right": 1
28+
"right": 1,
29+
"auto": 1,
30+
"line-left": 1,
31+
"line-right": 1
2932
};
3033

3134
function findDirectionSetting(value) {
@@ -70,9 +73,9 @@ function VTTCue(startTime, endTime, text) {
7073
var _snapToLines = true;
7174
var _line = "auto";
7275
var _lineAlign = "start";
73-
var _position = 50;
74-
var _positionAlign = "center";
75-
var _size = 50;
76+
var _position = "auto";
77+
var _positionAlign = "auto";
78+
var _size = 100;
7679
var _align = "center";
7780

7881
Object.defineProperties(this, {
@@ -195,10 +198,11 @@ function VTTCue(startTime, endTime, text) {
195198
set: function(value) {
196199
var setting = findAlignSetting(value);
197200
if (!setting) {
198-
throw new SyntaxError("lineAlign: an invalid or illegal alignment string was specified.");
201+
console.warn("lineAlign: an invalid or illegal string was specified.");
202+
} else {
203+
_lineAlign = setting;
204+
this.hasBeenReset = true;
199205
}
200-
_lineAlign = setting;
201-
this.hasBeenReset = true;
202206
}
203207
},
204208

@@ -224,10 +228,11 @@ function VTTCue(startTime, endTime, text) {
224228
set: function(value) {
225229
var setting = findAlignSetting(value);
226230
if (!setting) {
227-
throw new SyntaxError("positionAlign: An invalid or illegal alignment string was specified.");
231+
console.warn("positionAlign: an invalid or illegal string was specified.");
232+
} else {
233+
_positionAlign = setting;
234+
this.hasBeenReset = true;
228235
}
229-
_positionAlign = setting;
230-
this.hasBeenReset = true;
231236
}
232237
},
233238

@@ -253,7 +258,7 @@ function VTTCue(startTime, endTime, text) {
253258
set: function(value) {
254259
var setting = findAlignSetting(value);
255260
if (!setting) {
256-
throw new SyntaxError("align: An invalid or illegal alignment string was specified.");
261+
throw new SyntaxError("align: an invalid or illegal alignment string was specified.");
257262
}
258263
_align = setting;
259264
this.hasBeenReset = true;

0 commit comments

Comments
 (0)