3 exports.__esModule = true;
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; }; /**
12 // Include the built-in techs
15 var _window = require('global/window');
17 var _window2 = _interopRequireDefault(_window);
19 var _document = require('global/document');
21 var _document2 = _interopRequireDefault(_document);
23 var _setup = require('./setup');
25 var setup = _interopRequireWildcard(_setup);
27 var _stylesheet = require('./utils/stylesheet.js');
29 var stylesheet = _interopRequireWildcard(_stylesheet);
31 var _component = require('./component');
33 var _component2 = _interopRequireDefault(_component);
35 var _eventTarget = require('./event-target');
37 var _eventTarget2 = _interopRequireDefault(_eventTarget);
39 var _events = require('./utils/events.js');
41 var Events = _interopRequireWildcard(_events);
43 var _player = require('./player');
45 var _player2 = _interopRequireDefault(_player);
47 var _plugins = require('./plugins.js');
49 var _plugins2 = _interopRequireDefault(_plugins);
51 var _mergeOptions2 = require('./utils/merge-options.js');
53 var _mergeOptions3 = _interopRequireDefault(_mergeOptions2);
55 var _fn = require('./utils/fn.js');
57 var Fn = _interopRequireWildcard(_fn);
59 var _textTrack = require('./tracks/text-track.js');
61 var _textTrack2 = _interopRequireDefault(_textTrack);
63 var _audioTrack = require('./tracks/audio-track.js');
65 var _audioTrack2 = _interopRequireDefault(_audioTrack);
67 var _videoTrack = require('./tracks/video-track.js');
69 var _videoTrack2 = _interopRequireDefault(_videoTrack);
71 var _timeRanges = require('./utils/time-ranges.js');
73 var _formatTime = require('./utils/format-time.js');
75 var _formatTime2 = _interopRequireDefault(_formatTime);
77 var _log = require('./utils/log.js');
79 var _log2 = _interopRequireDefault(_log);
81 var _dom = require('./utils/dom.js');
83 var Dom = _interopRequireWildcard(_dom);
85 var _browser = require('./utils/browser.js');
87 var browser = _interopRequireWildcard(_browser);
89 var _url = require('./utils/url.js');
91 var Url = _interopRequireWildcard(_url);
93 var _obj = require('./utils/obj');
95 var _computedStyle = require('./utils/computed-style.js');
97 var _computedStyle2 = _interopRequireDefault(_computedStyle);
99 var _extend = require('./extend.js');
101 var _extend2 = _interopRequireDefault(_extend);
103 var _xhr = require('xhr');
105 var _xhr2 = _interopRequireDefault(_xhr);
107 var _tech = require('./tech/tech.js');
109 var _tech2 = _interopRequireDefault(_tech);
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; } }
113 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
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');
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.
127 * @param {string|Element} id
128 * Video element or video element ID
130 * @param {Object} [options]
131 * Optional options object for config/settings
133 * @param {Component~ReadyCallback} [ready]
134 * Optional ready callback
141 function videojs(id, options, ready) {
144 // Allow for element or ID to be passed in
146 if (typeof id === 'string') {
148 // Adjust for jQuery ID syntax
149 if (id.indexOf('#') === 0) {
153 // If a player instance has already been created for this ID return it.
154 if (videojs.getPlayers()[id]) {
156 // If options or ready funtion are passed, warn
158 _log2['default'].warn('Player "' + id + '" is already initialised. Options will not be applied.');
162 videojs.getPlayers()[id].ready(ready);
165 return videojs.getPlayers()[id];
168 // Otherwise get element for ID
171 // ID is a media element
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)');
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];
188 options = options || {};
190 videojs.hooks('beforesetup').forEach(function (hookFunction) {
191 var opts = hookFunction(tag, (0, _mergeOptions3['default'])(options));
193 if (!(0, _obj.isObject)(opts) || Array.isArray(opts)) {
194 _log2['default'].error('please return an object in beforesetup hooks');
198 options = (0, _mergeOptions3['default'])(options, opts);
201 var PlayerComponent = _component2['default'].getComponent('Player');
202 // If not, set up a new player
203 var player = new PlayerComponent(tag, options, ready);
205 videojs.hooks('setup').forEach(function (hookFunction) {
206 return hookFunction(player);
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
219 * Get a list of hooks for a specific lifecycle
221 * @param {string} type
222 * the lifecyle to get hooks from
224 * @param {Function} [fn]
225 * Optionally add a hook to the lifecycle that your are getting.
228 * an array of hooks, or an empty array if there are none.
230 videojs.hooks = function (type, fn) {
231 videojs.hooks_[type] = videojs.hooks_[type] || [];
233 videojs.hooks_[type] = videojs.hooks_[type].concat(fn);
235 return videojs.hooks_[type];
239 * Add a function hook to a specific videojs lifecycle.
241 * @param {string} type
242 * the lifecycle to hook the function to.
244 * @param {Function|Function[]}
245 * The function or array of functions to attach.
247 videojs.hook = function (type, fn) {
248 videojs.hooks(type, fn);
252 * Remove a hook from a specific videojs lifecycle.
254 * @param {string} type
255 * the lifecycle that the function hooked to
257 * @param {Function} fn
258 * The hooked function to remove
261 * The function that was removed or undef
263 videojs.removeHook = function (type, fn) {
264 var index = videojs.hooks(type).indexOf(fn);
270 videojs.hooks_[type] = videojs.hooks_[type].slice();
271 videojs.hooks_[type].splice(index, 1);
276 // Add default styles
277 if (_window2['default'].VIDEOJS_NO_DYNAMIC_STYLE !== true && Dom.isReal()) {
278 var style = Dom.$('.vjs-styles-defaults');
281 style = stylesheet.createStyleElement('vjs-styles-defaults');
282 var head = Dom.$('head');
285 head.insertBefore(style, head.firstChild);
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 ');
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);
297 * Current software version. Follows semver.
301 videojs.VERSION = '5.19.2';
304 * The global options object. These are the settings that take effect
305 * if no overrides are specified when the player is created.
309 videojs.options = _player2['default'].prototype.options_;
312 * Get an object with the currently created players, keyed by player ID
315 * The created players
317 videojs.getPlayers = function () {
318 return _player2['default'].players;
322 * Expose players object.
325 * @property {Object} players
327 videojs.players = _player2['default'].players;
330 * Get a component class object by name
332 * @borrows Component.getComponent as videojs.getComponent
334 videojs.getComponent = _component2['default'].getComponent;
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'] }`.
341 * > NOTE: You could also just initialize the component before adding.
342 * `component.addChild(new MyComponent());`
344 * @param {string} name
345 * The class name of the component
347 * @param {Component} comp
348 * The component class
350 * @return {Component}
351 * The newly registered component
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)');
358 _component2['default'].registerComponent.call(_component2['default'], name, comp);
362 * Get a Tech class object by name
364 * @borrows Tech.getTech as videojs.getTech
366 videojs.getTech = _tech2['default'].getTech;
369 * Register a Tech so it can referred to by name.
370 * This is used in the tech order for the player.
372 * @borrows Tech.registerTech as videojs.registerTech
374 videojs.registerTech = _tech2['default'].registerTech;
377 * A suite of browser and device tests from {@link browser}.
382 videojs.browser = browser;
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.
389 * @deprecated since version 5.0
392 videojs.TOUCH_ENABLED = browser.TOUCH_ENABLED;
395 * Subclass an existing class
396 * Mimics ES6 subclassing with the `extend` keyword
398 * @borrows extend:extendFn as videojs.extend
400 videojs.extend = _extend2['default'];
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.
408 * @borrows merge-options:mergeOptions as videojs.mergeOptions
410 videojs.mergeOptions = _mergeOptions3['default'];
413 * Change the context (this) of a function
415 * > NOTE: as of v5.0 we require an ES5 shim, so you should use the native
416 * `function() {}.bind(newContext);` instead of this.
418 * @borrows fn:bind as videojs.bind
420 videojs.bind = Fn.bind;
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
428 * @borrows plugin:plugin as videojs.plugin
430 videojs.plugin = _plugins2['default'];
433 * Adding languages so that they're available to all players.
434 * Example: `videojs.addLanguage('es', { 'Hello': 'Hola' });`
436 * @param {string} code
437 * The language code or dictionary property
439 * @param {Object} data
440 * The data values to be translated
443 * The resulting language dictionary object
445 videojs.addLanguage = function (code, data) {
448 code = ('' + code).toLowerCase();
450 videojs.options.languages = (0, _mergeOptions3['default'])(videojs.options.languages, (_mergeOptions = {}, _mergeOptions[code] = data, _mergeOptions));
452 return videojs.options.languages[code];
458 * @borrows log:log as videojs.log
460 videojs.log = _log2['default'];
463 * Creates an emulated TimeRange object.
465 * @borrows time-ranges:createTimeRanges as videojs.createTimeRange
468 * @borrows time-ranges:createTimeRanges as videojs.createTimeRanges
470 videojs.createTimeRange = videojs.createTimeRanges = _timeRanges.createTimeRanges;
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
477 * @borrows format-time:formatTime as videojs.formatTime
479 videojs.formatTime = _formatTime2['default'];
482 * Resolve and parse the elements of a URL
484 * @borrows url:parseUrl as videojs.parseUrl
486 videojs.parseUrl = Url.parseUrl;
489 * Returns whether the url passed is a cross domain request or not.
491 * @borrows url:isCrossOrigin as videojs.isCrossOrigin
493 videojs.isCrossOrigin = Url.isCrossOrigin;
496 * Event target class.
498 * @borrows EventTarget as videojs.EventTarget
500 videojs.EventTarget = _eventTarget2['default'];
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.
508 * @borrows events:on as videojs.on
510 videojs.on = Events.on;
513 * Trigger a listener only once for an event
515 * @borrows events:one as videojs.one
517 videojs.one = Events.one;
520 * Removes event listeners from an element
522 * @borrows events:off as videojs.off
524 videojs.off = Events.off;
527 * Trigger an event for an element
529 * @borrows events:trigger as videojs.trigger
531 videojs.trigger = Events.trigger;
534 * A cross-browser XMLHttpRequest wrapper. Here's a simple example:
536 * @param {Object} options
537 * settings for the request.
539 * @return {XMLHttpRequest|XDomainRequest}
540 * The request object.
542 * @see https://github.com/Raynos/xhr
544 videojs.xhr = _xhr2['default'];
549 * @borrows TextTrack as videojs.TextTrack
551 videojs.TextTrack = _textTrack2['default'];
554 * export the AudioTrack class so that source handlers can create
555 * AudioTracks and then add them to the players AudioTrackList
557 * @borrows AudioTrack as videojs.AudioTrack
559 videojs.AudioTrack = _audioTrack2['default'];
562 * export the VideoTrack class so that source handlers can create
563 * VideoTracks and then add them to the players VideoTrackList
565 * @borrows VideoTrack as videojs.VideoTrack
567 videojs.VideoTrack = _videoTrack2['default'];
570 * Determines, via duck typing, whether or not a value is a DOM element.
572 * @borrows dom:isEl as videojs.isEl
574 videojs.isEl = Dom.isEl;
577 * Determines, via duck typing, whether or not a value is a text node.
579 * @borrows dom:isTextNode as videojs.isTextNode
581 videojs.isTextNode = Dom.isTextNode;
584 * Creates an element and applies properties.
586 * @borrows dom:createEl as videojs.createEl
588 videojs.createEl = Dom.createEl;
591 * Check if an element has a CSS class
593 * @borrows dom:hasElClass as videojs.hasClass
595 videojs.hasClass = Dom.hasElClass;
598 * Add a CSS class name to an element
600 * @borrows dom:addElClass as videojs.addClass
602 videojs.addClass = Dom.addElClass;
605 * Remove a CSS class name from an element
607 * @borrows dom:removeElClass as videojs.removeClass
609 videojs.removeClass = Dom.removeElClass;
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.
615 * @borrows dom:toggleElClass as videojs.toggleClass
617 videojs.toggleClass = Dom.toggleElClass;
620 * Apply attributes to an HTML element.
622 * @borrows dom:setElAttributes as videojs.setAttribute
624 videojs.setAttributes = Dom.setElAttributes;
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.
632 * @borrows dom:getElAttributes as videojs.getAttributes
634 videojs.getAttributes = Dom.getElAttributes;
637 * Empties the contents of an element.
639 * @borrows dom:emptyEl as videojs.emptyEl
641 videojs.emptyEl = Dom.emptyEl;
644 * Normalizes and appends content to an element.
646 * The content for an element can be passed in multiple types and
647 * combinations, whose behavior is as follows:
650 * Normalized into a text node.
652 * - Element, TextNode
656 * A one-dimensional array of strings, elements, nodes, or functions (which
657 * return single strings, elements, or nodes).
660 * If the sole argument, is expected to produce a string, element,
663 * @borrows dom:appendContents as videojs.appendContet
665 videojs.appendContent = Dom.appendContent;
668 * Normalizes and inserts content into an element; this is identical to
669 * `appendContent()`, except it empties the element first.
671 * The content for an element can be passed in multiple types and
672 * combinations, whose behavior is as follows:
675 * Normalized into a text node.
677 * - Element, TextNode
681 * A one-dimensional array of strings, elements, nodes, or functions (which
682 * return single strings, elements, or nodes).
685 * If the sole argument, is expected to produce a string, element,
688 * @borrows dom:insertContent as videojs.insertContent
690 videojs.insertContent = Dom.insertContent;
693 * A safe getComputedStyle with an IE8 fallback.
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.
700 * @borrows computed-style:computedStyle as videojs.computedStyle
702 videojs.computedStyle = _computedStyle2['default'];
705 * Custom Universal Module Definition (UMD)
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.
711 if (typeof define === 'function' && define.amd) {
712 define('videojs', [], function () {
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;
721 exports['default'] = videojs;