Pull merge.
[yaffs-website] / node_modules / video.js / es5 / video.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /**
6                                                                                                                                                                                                                                                                                * @file video.js
7                                                                                                                                                                                                                                                                                * @module videojs
8                                                                                                                                                                                                                                                                                */
9
10 /* global define */
11
12 // Include the built-in techs
13
14
15 var _window = require('global/window');
16
17 var _window2 = _interopRequireDefault(_window);
18
19 var _document = require('global/document');
20
21 var _document2 = _interopRequireDefault(_document);
22
23 var _setup = require('./setup');
24
25 var setup = _interopRequireWildcard(_setup);
26
27 var _stylesheet = require('./utils/stylesheet.js');
28
29 var stylesheet = _interopRequireWildcard(_stylesheet);
30
31 var _component = require('./component');
32
33 var _component2 = _interopRequireDefault(_component);
34
35 var _eventTarget = require('./event-target');
36
37 var _eventTarget2 = _interopRequireDefault(_eventTarget);
38
39 var _events = require('./utils/events.js');
40
41 var Events = _interopRequireWildcard(_events);
42
43 var _player = require('./player');
44
45 var _player2 = _interopRequireDefault(_player);
46
47 var _plugins = require('./plugins.js');
48
49 var _plugins2 = _interopRequireDefault(_plugins);
50
51 var _mergeOptions2 = require('./utils/merge-options.js');
52
53 var _mergeOptions3 = _interopRequireDefault(_mergeOptions2);
54
55 var _fn = require('./utils/fn.js');
56
57 var Fn = _interopRequireWildcard(_fn);
58
59 var _textTrack = require('./tracks/text-track.js');
60
61 var _textTrack2 = _interopRequireDefault(_textTrack);
62
63 var _audioTrack = require('./tracks/audio-track.js');
64
65 var _audioTrack2 = _interopRequireDefault(_audioTrack);
66
67 var _videoTrack = require('./tracks/video-track.js');
68
69 var _videoTrack2 = _interopRequireDefault(_videoTrack);
70
71 var _timeRanges = require('./utils/time-ranges.js');
72
73 var _formatTime = require('./utils/format-time.js');
74
75 var _formatTime2 = _interopRequireDefault(_formatTime);
76
77 var _log = require('./utils/log.js');
78
79 var _log2 = _interopRequireDefault(_log);
80
81 var _dom = require('./utils/dom.js');
82
83 var Dom = _interopRequireWildcard(_dom);
84
85 var _browser = require('./utils/browser.js');
86
87 var browser = _interopRequireWildcard(_browser);
88
89 var _url = require('./utils/url.js');
90
91 var Url = _interopRequireWildcard(_url);
92
93 var _obj = require('./utils/obj');
94
95 var _computedStyle = require('./utils/computed-style.js');
96
97 var _computedStyle2 = _interopRequireDefault(_computedStyle);
98
99 var _extend = require('./extend.js');
100
101 var _extend2 = _interopRequireDefault(_extend);
102
103 var _xhr = require('xhr');
104
105 var _xhr2 = _interopRequireDefault(_xhr);
106
107 var _tech = require('./tech/tech.js');
108
109 var _tech2 = _interopRequireDefault(_tech);
110
111 function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
112
113 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
114
115 // HTML5 Element Shim for IE8
116 if (typeof HTMLVideoElement === 'undefined' && Dom.isReal()) {
117   _document2['default'].createElement('video');
118   _document2['default'].createElement('audio');
119   _document2['default'].createElement('track');
120 }
121
122 /**
123  * Doubles as the main function for users to create a player instance and also
124  * the main library object.
125  * The `videojs` function can be used to initialize or retrieve a player.
126   *
127  * @param {string|Element} id
128  *        Video element or video element ID
129  *
130  * @param {Object} [options]
131  *        Optional options object for config/settings
132  *
133  * @param {Component~ReadyCallback} [ready]
134  *        Optional ready callback
135  *
136  * @return {Player}
137  *         A player instance
138  *
139  * @mixes videojs
140  */
141 function videojs(id, options, ready) {
142   var tag = void 0;
143
144   // Allow for element or ID to be passed in
145   // String ID
146   if (typeof id === 'string') {
147
148     // Adjust for jQuery ID syntax
149     if (id.indexOf('#') === 0) {
150       id = id.slice(1);
151     }
152
153     // If a player instance has already been created for this ID return it.
154     if (videojs.getPlayers()[id]) {
155
156       // If options or ready funtion are passed, warn
157       if (options) {
158         _log2['default'].warn('Player "' + id + '" is already initialised. Options will not be applied.');
159       }
160
161       if (ready) {
162         videojs.getPlayers()[id].ready(ready);
163       }
164
165       return videojs.getPlayers()[id];
166     }
167
168     // Otherwise get element for ID
169     tag = Dom.getEl(id);
170
171     // ID is a media element
172   } else {
173     tag = id;
174   }
175
176   // Check for a useable element
177   // re: nodeName, could be a box div also
178   if (!tag || !tag.nodeName) {
179     throw new TypeError('The element or ID supplied is not valid. (videojs)');
180   }
181
182   // Element may have a player attr referring to an already created player instance.
183   // If so return that otherwise set up a new player below
184   if (tag.player || _player2['default'].players[tag.playerId]) {
185     return tag.player || _player2['default'].players[tag.playerId];
186   }
187
188   options = options || {};
189
190   videojs.hooks('beforesetup').forEach(function (hookFunction) {
191     var opts = hookFunction(tag, (0, _mergeOptions3['default'])(options));
192
193     if (!(0, _obj.isObject)(opts) || Array.isArray(opts)) {
194       _log2['default'].error('please return an object in beforesetup hooks');
195       return;
196     }
197
198     options = (0, _mergeOptions3['default'])(options, opts);
199   });
200
201   var PlayerComponent = _component2['default'].getComponent('Player');
202   // If not, set up a new player
203   var player = new PlayerComponent(tag, options, ready);
204
205   videojs.hooks('setup').forEach(function (hookFunction) {
206     return hookFunction(player);
207   });
208
209   return player;
210 }
211
212 /**
213  * An Object that contains lifecycle hooks as keys which point to an array
214  * of functions that are run when a lifecycle is triggered
215  */
216 videojs.hooks_ = {};
217
218 /**
219  * Get a list of hooks for a specific lifecycle
220  *
221  * @param {string} type
222  *        the lifecyle to get hooks from
223  *
224  * @param {Function} [fn]
225  *        Optionally add a hook to the lifecycle that your are getting.
226  *
227  * @return {Array}
228  *         an array of hooks, or an empty array if there are none.
229  */
230 videojs.hooks = function (type, fn) {
231   videojs.hooks_[type] = videojs.hooks_[type] || [];
232   if (fn) {
233     videojs.hooks_[type] = videojs.hooks_[type].concat(fn);
234   }
235   return videojs.hooks_[type];
236 };
237
238 /**
239  * Add a function hook to a specific videojs lifecycle.
240  *
241  * @param {string} type
242  *        the lifecycle to hook the function to.
243  *
244  * @param {Function|Function[]}
245  *        The function or array of functions to attach.
246  */
247 videojs.hook = function (type, fn) {
248   videojs.hooks(type, fn);
249 };
250
251 /**
252  * Remove a hook from a specific videojs lifecycle.
253  *
254  * @param {string} type
255  *        the lifecycle that the function hooked to
256  *
257  * @param {Function} fn
258  *        The hooked function to remove
259  *
260  * @return {boolean}
261  *         The function that was removed or undef
262  */
263 videojs.removeHook = function (type, fn) {
264   var index = videojs.hooks(type).indexOf(fn);
265
266   if (index <= -1) {
267     return false;
268   }
269
270   videojs.hooks_[type] = videojs.hooks_[type].slice();
271   videojs.hooks_[type].splice(index, 1);
272
273   return true;
274 };
275
276 // Add default styles
277 if (_window2['default'].VIDEOJS_NO_DYNAMIC_STYLE !== true && Dom.isReal()) {
278   var style = Dom.$('.vjs-styles-defaults');
279
280   if (!style) {
281     style = stylesheet.createStyleElement('vjs-styles-defaults');
282     var head = Dom.$('head');
283
284     if (head) {
285       head.insertBefore(style, head.firstChild);
286     }
287     stylesheet.setTextContent(style, '\n      .video-js {\n        width: 300px;\n        height: 150px;\n      }\n\n      .vjs-fluid {\n        padding-top: 56.25%\n      }\n    ');
288   }
289 }
290
291 // Run Auto-load players
292 // You have to wait at least once in case this script is loaded after your
293 // video in the DOM (weird behavior only with minified version)
294 setup.autoSetupTimeout(1, videojs);
295
296 /**
297  * Current software version. Follows semver.
298  *
299  * @type {string}
300  */
301 videojs.VERSION = '5.19.2';
302
303 /**
304  * The global options object. These are the settings that take effect
305  * if no overrides are specified when the player is created.
306  *
307  * @type {Object}
308  */
309 videojs.options = _player2['default'].prototype.options_;
310
311 /**
312  * Get an object with the currently created players, keyed by player ID
313  *
314  * @return {Object}
315  *         The created players
316  */
317 videojs.getPlayers = function () {
318   return _player2['default'].players;
319 };
320
321 /**
322  * Expose players object.
323  *
324  * @memberOf videojs
325  * @property {Object} players
326  */
327 videojs.players = _player2['default'].players;
328
329 /**
330  * Get a component class object by name
331  *
332  * @borrows Component.getComponent as videojs.getComponent
333  */
334 videojs.getComponent = _component2['default'].getComponent;
335
336 /**
337  * Register a component so it can referred to by name. Used when adding to other
338  * components, either through addChild `component.addChild('myComponent')` or through
339  * default children options  `{ children: ['myComponent'] }`.
340  *
341  * > NOTE: You could also just initialize the component before adding.
342  * `component.addChild(new MyComponent());`
343  *
344  * @param {string} name
345  *        The class name of the component
346  *
347  * @param {Component} comp
348  *        The component class
349  *
350  * @return {Component}
351  *         The newly registered component
352  */
353 videojs.registerComponent = function (name, comp) {
354   if (_tech2['default'].isTech(comp)) {
355     _log2['default'].warn('The ' + name + ' tech was registered as a component. It should instead be registered using videojs.registerTech(name, tech)');
356   }
357
358   _component2['default'].registerComponent.call(_component2['default'], name, comp);
359 };
360
361 /**
362  * Get a Tech class object by name
363  *
364  * @borrows Tech.getTech as videojs.getTech
365  */
366 videojs.getTech = _tech2['default'].getTech;
367
368 /**
369  * Register a Tech so it can referred to by name.
370  * This is used in the tech order for the player.
371  *
372  * @borrows Tech.registerTech as videojs.registerTech
373  */
374 videojs.registerTech = _tech2['default'].registerTech;
375
376 /**
377  * A suite of browser and device tests from {@link browser}.
378  *
379  * @type {Object}
380  * @private
381  */
382 videojs.browser = browser;
383
384 /**
385  * Whether or not the browser supports touch events. Included for backward
386  * compatibility with 4.x, but deprecated. Use `videojs.browser.TOUCH_ENABLED`
387  * instead going forward.
388  *
389  * @deprecated since version 5.0
390  * @type {boolean}
391  */
392 videojs.TOUCH_ENABLED = browser.TOUCH_ENABLED;
393
394 /**
395  * Subclass an existing class
396  * Mimics ES6 subclassing with the `extend` keyword
397  *
398  * @borrows extend:extendFn as videojs.extend
399  */
400 videojs.extend = _extend2['default'];
401
402 /**
403  * Merge two options objects recursively
404  * Performs a deep merge like lodash.merge but **only merges plain objects**
405  * (not arrays, elements, anything else)
406  * Other values will be copied directly from the second object.
407  *
408  * @borrows merge-options:mergeOptions as videojs.mergeOptions
409  */
410 videojs.mergeOptions = _mergeOptions3['default'];
411
412 /**
413  * Change the context (this) of a function
414  *
415  * > NOTE: as of v5.0 we require an ES5 shim, so you should use the native
416  * `function() {}.bind(newContext);` instead of this.
417  *
418  * @borrows fn:bind as videojs.bind
419  */
420 videojs.bind = Fn.bind;
421
422 /**
423  * Create a Video.js player plugin.
424  * Plugins are only initialized when options for the plugin are included
425  * in the player options, or the plugin function on the player instance is
426  * called.
427  *
428  * @borrows plugin:plugin as videojs.plugin
429  */
430 videojs.plugin = _plugins2['default'];
431
432 /**
433  * Adding languages so that they're available to all players.
434  * Example: `videojs.addLanguage('es', { 'Hello': 'Hola' });`
435  *
436  * @param {string} code
437  *        The language code or dictionary property
438  *
439  * @param {Object} data
440  *        The data values to be translated
441  *
442  * @return {Object}
443  *         The resulting language dictionary object
444  */
445 videojs.addLanguage = function (code, data) {
446   var _mergeOptions;
447
448   code = ('' + code).toLowerCase();
449
450   videojs.options.languages = (0, _mergeOptions3['default'])(videojs.options.languages, (_mergeOptions = {}, _mergeOptions[code] = data, _mergeOptions));
451
452   return videojs.options.languages[code];
453 };
454
455 /**
456  * Log messages
457  *
458  * @borrows log:log as videojs.log
459  */
460 videojs.log = _log2['default'];
461
462 /**
463  * Creates an emulated TimeRange object.
464  *
465  * @borrows time-ranges:createTimeRanges as videojs.createTimeRange
466  */
467 /**
468  * @borrows time-ranges:createTimeRanges as videojs.createTimeRanges
469  */
470 videojs.createTimeRange = videojs.createTimeRanges = _timeRanges.createTimeRanges;
471
472 /**
473  * Format seconds as a time string, H:MM:SS or M:SS
474  * Supplying a guide (in seconds) will force a number of leading zeros
475  * to cover the length of the guide
476  *
477  * @borrows format-time:formatTime as videojs.formatTime
478  */
479 videojs.formatTime = _formatTime2['default'];
480
481 /**
482  * Resolve and parse the elements of a URL
483  *
484  * @borrows url:parseUrl as videojs.parseUrl
485  */
486 videojs.parseUrl = Url.parseUrl;
487
488 /**
489  * Returns whether the url passed is a cross domain request or not.
490  *
491  * @borrows url:isCrossOrigin as videojs.isCrossOrigin
492  */
493 videojs.isCrossOrigin = Url.isCrossOrigin;
494
495 /**
496  * Event target class.
497  *
498  * @borrows EventTarget as videojs.EventTarget
499  */
500 videojs.EventTarget = _eventTarget2['default'];
501
502 /**
503  * Add an event listener to element
504  * It stores the handler function in a separate cache object
505  * and adds a generic handler to the element's event,
506  * along with a unique id (guid) to the element.
507  *
508  * @borrows events:on as videojs.on
509  */
510 videojs.on = Events.on;
511
512 /**
513  * Trigger a listener only once for an event
514  *
515  * @borrows events:one as videojs.one
516  */
517 videojs.one = Events.one;
518
519 /**
520  * Removes event listeners from an element
521  *
522  * @borrows events:off as videojs.off
523  */
524 videojs.off = Events.off;
525
526 /**
527  * Trigger an event for an element
528  *
529  * @borrows events:trigger as videojs.trigger
530  */
531 videojs.trigger = Events.trigger;
532
533 /**
534  * A cross-browser XMLHttpRequest wrapper. Here's a simple example:
535  *
536  * @param {Object} options
537  *        settings for the request.
538  *
539  * @return {XMLHttpRequest|XDomainRequest}
540  *         The request object.
541  *
542  * @see https://github.com/Raynos/xhr
543  */
544 videojs.xhr = _xhr2['default'];
545
546 /**
547  * TextTrack class
548  *
549  * @borrows TextTrack as videojs.TextTrack
550  */
551 videojs.TextTrack = _textTrack2['default'];
552
553 /**
554  * export the AudioTrack class so that source handlers can create
555  * AudioTracks and then add them to the players AudioTrackList
556  *
557  * @borrows AudioTrack as videojs.AudioTrack
558  */
559 videojs.AudioTrack = _audioTrack2['default'];
560
561 /**
562  * export the VideoTrack class so that source handlers can create
563  * VideoTracks and then add them to the players VideoTrackList
564  *
565  * @borrows VideoTrack as videojs.VideoTrack
566  */
567 videojs.VideoTrack = _videoTrack2['default'];
568
569 /**
570  * Determines, via duck typing, whether or not a value is a DOM element.
571  *
572  * @borrows dom:isEl as videojs.isEl
573  */
574 videojs.isEl = Dom.isEl;
575
576 /**
577  * Determines, via duck typing, whether or not a value is a text node.
578  *
579  * @borrows dom:isTextNode as videojs.isTextNode
580  */
581 videojs.isTextNode = Dom.isTextNode;
582
583 /**
584  * Creates an element and applies properties.
585  *
586  * @borrows dom:createEl as videojs.createEl
587  */
588 videojs.createEl = Dom.createEl;
589
590 /**
591  * Check if an element has a CSS class
592  *
593  * @borrows dom:hasElClass as videojs.hasClass
594  */
595 videojs.hasClass = Dom.hasElClass;
596
597 /**
598  * Add a CSS class name to an element
599  *
600  * @borrows dom:addElClass as videojs.addClass
601  */
602 videojs.addClass = Dom.addElClass;
603
604 /**
605  * Remove a CSS class name from an element
606  *
607  * @borrows dom:removeElClass as videojs.removeClass
608  */
609 videojs.removeClass = Dom.removeElClass;
610
611 /**
612  * Adds or removes a CSS class name on an element depending on an optional
613  * condition or the presence/absence of the class name.
614  *
615  * @borrows dom:toggleElClass as videojs.toggleClass
616  */
617 videojs.toggleClass = Dom.toggleElClass;
618
619 /**
620  * Apply attributes to an HTML element.
621  *
622  * @borrows dom:setElAttributes as videojs.setAttribute
623  */
624 videojs.setAttributes = Dom.setElAttributes;
625
626 /**
627  * Get an element's attribute values, as defined on the HTML tag
628  * Attributes are not the same as properties. They're defined on the tag
629  * or with setAttribute (which shouldn't be used with HTML)
630  * This will return true or false for boolean attributes.
631  *
632  * @borrows dom:getElAttributes as videojs.getAttributes
633  */
634 videojs.getAttributes = Dom.getElAttributes;
635
636 /**
637  * Empties the contents of an element.
638  *
639  * @borrows dom:emptyEl as videojs.emptyEl
640  */
641 videojs.emptyEl = Dom.emptyEl;
642
643 /**
644  * Normalizes and appends content to an element.
645  *
646  * The content for an element can be passed in multiple types and
647  * combinations, whose behavior is as follows:
648  *
649  * - String
650  *   Normalized into a text node.
651  *
652  * - Element, TextNode
653  *   Passed through.
654  *
655  * - Array
656  *   A one-dimensional array of strings, elements, nodes, or functions (which
657  *   return single strings, elements, or nodes).
658  *
659  * - Function
660  *   If the sole argument, is expected to produce a string, element,
661  *   node, or array.
662  *
663  * @borrows dom:appendContents as videojs.appendContet
664  */
665 videojs.appendContent = Dom.appendContent;
666
667 /**
668  * Normalizes and inserts content into an element; this is identical to
669  * `appendContent()`, except it empties the element first.
670  *
671  * The content for an element can be passed in multiple types and
672  * combinations, whose behavior is as follows:
673  *
674  * - String
675  *   Normalized into a text node.
676  *
677  * - Element, TextNode
678  *   Passed through.
679  *
680  * - Array
681  *   A one-dimensional array of strings, elements, nodes, or functions (which
682  *   return single strings, elements, or nodes).
683  *
684  * - Function
685  *   If the sole argument, is expected to produce a string, element,
686  *   node, or array.
687  *
688  * @borrows dom:insertContent as videojs.insertContent
689  */
690 videojs.insertContent = Dom.insertContent;
691
692 /**
693  * A safe getComputedStyle with an IE8 fallback.
694  *
695  * This is because in Firefox, if the player is loaded in an iframe with `display:none`,
696  * then `getComputedStyle` returns `null`, so, we do a null-check to make sure
697  * that the player doesn't break in these cases.
698  * See https://bugzilla.mozilla.org/show_bug.cgi?id=548397 for more details.
699  *
700  * @borrows computed-style:computedStyle as videojs.computedStyle
701  */
702 videojs.computedStyle = _computedStyle2['default'];
703
704 /*
705  * Custom Universal Module Definition (UMD)
706  *
707  * Video.js will never be a non-browser lib so we can simplify UMD a bunch and
708  * still support requirejs and browserify. This also needs to be closure
709  * compiler compatible, so string keys are used.
710  */
711 if (typeof define === 'function' && define.amd) {
712   define('videojs', [], function () {
713     return videojs;
714   });
715
716   // checking that module is an object too because of umdjs/umd#35
717 } else if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object' && (typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object') {
718   module.exports = videojs;
719 }
720
721 exports['default'] = videojs;