2 * Copyright 2013 vtt.js Contributors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 (function(root, vttjs) {
24 function findScrollSetting(value) {
25 if (typeof value !== "string") {
28 var scroll = scrollSetting[value.toLowerCase()];
29 return scroll ? value.toLowerCase() : false;
32 function isValidPercentValue(value) {
33 return typeof value === "number" && (value >= 0 && value <= 100);
36 // VTTRegion shim http://dev.w3.org/html5/webvtt/#vttregion-interface
37 function VTTRegion() {
40 var _regionAnchorX = 0;
41 var _regionAnchorY = 100;
42 var _viewportAnchorX = 0;
43 var _viewportAnchorY = 100;
46 Object.defineProperties(this, {
52 set: function(value) {
53 if (!isValidPercentValue(value)) {
54 throw new Error("Width must be between 0 and 100.");
64 set: function(value) {
65 if (typeof value !== "number") {
66 throw new TypeError("Lines must be set to a number.");
74 return _regionAnchorY;
76 set: function(value) {
77 if (!isValidPercentValue(value)) {
78 throw new Error("RegionAnchorX must be between 0 and 100.");
80 _regionAnchorY = value;
86 return _regionAnchorX;
88 set: function(value) {
89 if(!isValidPercentValue(value)) {
90 throw new Error("RegionAnchorY must be between 0 and 100.");
92 _regionAnchorX = value;
98 return _viewportAnchorY;
100 set: function(value) {
101 if (!isValidPercentValue(value)) {
102 throw new Error("ViewportAnchorY must be between 0 and 100.");
104 _viewportAnchorY = value;
110 return _viewportAnchorX;
112 set: function(value) {
113 if (!isValidPercentValue(value)) {
114 throw new Error("ViewportAnchorX must be between 0 and 100.");
116 _viewportAnchorX = value;
124 set: function(value) {
125 var setting = findScrollSetting(value);
126 // Have to check for false as an empty string is a legal value.
127 if (setting === false) {
128 throw new SyntaxError("An invalid or illegal string was specified.");
136 root.VTTRegion = root.VTTRegion || VTTRegion;
137 vttjs.VTTRegion = VTTRegion;
138 }(this, (this.vttjs || {})));