8a379e62c54c408673a685917c061841279fb161
[yaffs-website] / node_modules / videojs-vtt.js / lib / vttregion-extended.js
1 /**
2  * Copyright 2013 vtt.js Contributors
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 // If we're in Node.js then require VTTRegion so we can extend it, otherwise assume
18 // VTTRegion is on the global.
19 if (typeof module !== "undefined" && module.exports) {
20   this.VTTRegion = require("./vttregion").VTTRegion;
21 }
22
23 // Extend VTTRegion with methods to convert to JSON, from JSON, and construct a
24 // VTTRegion from an options object. The primary purpose of this is for use in the
25 // vtt.js test suite. It's also useful if you need to work with VTTRegions in
26 // JSON format.
27 (function(root) {
28
29   root.VTTRegion.create = function(options) {
30     var region = new root.VTTRegion();
31     for (var key in options) {
32       if (region.hasOwnProperty(key)) {
33         region[key] = options[key];
34       }
35     }
36     return region;
37   };
38
39   root.VTTRegion.fromJSON = function(json) {
40     return this.create(JSON.parse(json));
41   };
42
43 }(this));