vttregion-extended.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. // If we're in Node.js then require VTTRegion so we can extend it, otherwise assume
  17. // VTTRegion is on the global.
  18. if (typeof module !== "undefined" && module.exports) {
  19. this.VTTRegion = require("./vttregion").VTTRegion;
  20. }
  21. // Extend VTTRegion with methods to convert to JSON, from JSON, and construct a
  22. // VTTRegion from an options object. The primary purpose of this is for use in the
  23. // vtt.js test suite. It's also useful if you need to work with VTTRegions in
  24. // JSON format.
  25. (function(root) {
  26. root.VTTRegion.create = function(options) {
  27. var region = new root.VTTRegion();
  28. for (var key in options) {
  29. if (region.hasOwnProperty(key)) {
  30. region[key] = options[key];
  31. }
  32. }
  33. return region;
  34. };
  35. root.VTTRegion.fromJSON = function(json) {
  36. return this.create(JSON.parse(json));
  37. };
  38. }(this));