Added missing modules, including some as submodules.
[yaffs-website] / node_modules / videojs-vtt.js / lib / vttcue-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 VTTCue so we can extend it, otherwise assume
18 // VTTCue is on the global.
19 if (typeof module !== "undefined" && module.exports) {
20   this.VTTCue = this.VTTCue || require("./vttcue").VTTCue;
21 }
22
23 // Extend VTTCue with methods to convert to JSON, from JSON, and construct a
24 // VTTCue from an options object. The primary purpose of this is for use in the
25 // vtt.js test suite (for testing only properties that we care about). It's also
26 // useful if you need to work with VTTCues in JSON format.
27 (function(root) {
28
29   root.VTTCue.prototype.toJSON = function() {
30     var cue = {},
31         self = this;
32     // Filter out getCueAsHTML as it's a function and hasBeenReset and displayState as
33     // they're only used when running the processing model algorithm.
34     Object.keys(this).forEach(function(key) {
35       if (key !== "getCueAsHTML" && key !== "hasBeenReset" && key !== "displayState") {
36         cue[key] = self[key];
37       }
38     });
39     return cue;
40   };
41
42   root.VTTCue.create = function(options) {
43     if (!options.hasOwnProperty("startTime") || !options.hasOwnProperty("endTime") ||
44         !options.hasOwnProperty("text")) {
45       throw new Error("You must at least have start time, end time, and text.");
46     }
47     var cue = new root.VTTCue(options.startTime, options.endTime, options.text);
48     for (var key in options) {
49       if (cue.hasOwnProperty(key)) {
50         cue[key] = options[key];
51       }
52     }
53     return cue;
54   };
55
56   root.VTTCue.fromJSON = function(json) {
57     return this.create(JSON.parse(json));
58   };
59
60 }(this));