logo

drewdevault.com

[mirror] blog and personal website of Drew DeVault git clone https://hacktivis.me/git/mirror/drewdevault.com.git

video.js (702904B)


  1. /**
  2. * @license
  3. * Video.js 5.8.8 <http://videojs.com/>
  4. * Copyright Brightcove, Inc. <https://www.brightcove.com/>
  5. * Available under Apache License Version 2.0
  6. * <https://github.com/videojs/video.js/blob/master/LICENSE>
  7. *
  8. * Includes vtt.js <https://github.com/mozilla/vtt.js>
  9. * Available under Apache License Version 2.0
  10. * <https://github.com/mozilla/vtt.js/blob/master/LICENSE>
  11. */
  12. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.videojs = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  13. (function (global){
  14. var topLevel = typeof global !== 'undefined' ? global :
  15. typeof window !== 'undefined' ? window : {}
  16. var minDoc = _dereq_('min-document');
  17. if (typeof document !== 'undefined') {
  18. module.exports = document;
  19. } else {
  20. var doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'];
  21. if (!doccy) {
  22. doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'] = minDoc;
  23. }
  24. module.exports = doccy;
  25. }
  26. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  27. //# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9nbG9iYWwvZG9jdW1lbnQuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBIiwiZmlsZSI6ImdlbmVyYXRlZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyJ2YXIgdG9wTGV2ZWwgPSB0eXBlb2YgZ2xvYmFsICE9PSAndW5kZWZpbmVkJyA/IGdsb2JhbCA6XG4gICAgdHlwZW9mIHdpbmRvdyAhPT0gJ3VuZGVmaW5lZCcgPyB3aW5kb3cgOiB7fVxudmFyIG1pbkRvYyA9IHJlcXVpcmUoJ21pbi1kb2N1bWVudCcpO1xuXG5pZiAodHlwZW9mIGRvY3VtZW50ICE9PSAndW5kZWZpbmVkJykge1xuICAgIG1vZHVsZS5leHBvcnRzID0gZG9jdW1lbnQ7XG59IGVsc2Uge1xuICAgIHZhciBkb2NjeSA9IHRvcExldmVsWydfX0dMT0JBTF9ET0NVTUVOVF9DQUNIRUA0J107XG5cbiAgICBpZiAoIWRvY2N5KSB7XG4gICAgICAgIGRvY2N5ID0gdG9wTGV2ZWxbJ19fR0xPQkFMX0RPQ1VNRU5UX0NBQ0hFQDQnXSA9IG1pbkRvYztcbiAgICB9XG5cbiAgICBtb2R1bGUuZXhwb3J0cyA9IGRvY2N5O1xufVxuIl19
  28. },{"min-document":3}],2:[function(_dereq_,module,exports){
  29. (function (global){
  30. if (typeof window !== "undefined") {
  31. module.exports = window;
  32. } else if (typeof global !== "undefined") {
  33. module.exports = global;
  34. } else if (typeof self !== "undefined"){
  35. module.exports = self;
  36. } else {
  37. module.exports = {};
  38. }
  39. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  40. //# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9nbG9iYWwvd2luZG93LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQSIsImZpbGUiOiJnZW5lcmF0ZWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlc0NvbnRlbnQiOlsiaWYgKHR5cGVvZiB3aW5kb3cgIT09IFwidW5kZWZpbmVkXCIpIHtcbiAgICBtb2R1bGUuZXhwb3J0cyA9IHdpbmRvdztcbn0gZWxzZSBpZiAodHlwZW9mIGdsb2JhbCAhPT0gXCJ1bmRlZmluZWRcIikge1xuICAgIG1vZHVsZS5leHBvcnRzID0gZ2xvYmFsO1xufSBlbHNlIGlmICh0eXBlb2Ygc2VsZiAhPT0gXCJ1bmRlZmluZWRcIil7XG4gICAgbW9kdWxlLmV4cG9ydHMgPSBzZWxmO1xufSBlbHNlIHtcbiAgICBtb2R1bGUuZXhwb3J0cyA9IHt9O1xufVxuIl19
  41. },{}],3:[function(_dereq_,module,exports){
  42. },{}],4:[function(_dereq_,module,exports){
  43. var getNative = _dereq_('../internal/getNative');
  44. /* Native method references for those with the same name as other `lodash` methods. */
  45. var nativeNow = getNative(Date, 'now');
  46. /**
  47. * Gets the number of milliseconds that have elapsed since the Unix epoch
  48. * (1 January 1970 00:00:00 UTC).
  49. *
  50. * @static
  51. * @memberOf _
  52. * @category Date
  53. * @example
  54. *
  55. * _.defer(function(stamp) {
  56. * console.log(_.now() - stamp);
  57. * }, _.now());
  58. * // => logs the number of milliseconds it took for the deferred function to be invoked
  59. */
  60. var now = nativeNow || function() {
  61. return new Date().getTime();
  62. };
  63. module.exports = now;
  64. },{"../internal/getNative":20}],5:[function(_dereq_,module,exports){
  65. var isObject = _dereq_('../lang/isObject'),
  66. now = _dereq_('../date/now');
  67. /** Used as the `TypeError` message for "Functions" methods. */
  68. var FUNC_ERROR_TEXT = 'Expected a function';
  69. /* Native method references for those with the same name as other `lodash` methods. */
  70. var nativeMax = Math.max;
  71. /**
  72. * Creates a debounced function that delays invoking `func` until after `wait`
  73. * milliseconds have elapsed since the last time the debounced function was
  74. * invoked. The debounced function comes with a `cancel` method to cancel
  75. * delayed invocations. Provide an options object to indicate that `func`
  76. * should be invoked on the leading and/or trailing edge of the `wait` timeout.
  77. * Subsequent calls to the debounced function return the result of the last
  78. * `func` invocation.
  79. *
  80. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  81. * on the trailing edge of the timeout only if the the debounced function is
  82. * invoked more than once during the `wait` timeout.
  83. *
  84. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  85. * for details over the differences between `_.debounce` and `_.throttle`.
  86. *
  87. * @static
  88. * @memberOf _
  89. * @category Function
  90. * @param {Function} func The function to debounce.
  91. * @param {number} [wait=0] The number of milliseconds to delay.
  92. * @param {Object} [options] The options object.
  93. * @param {boolean} [options.leading=false] Specify invoking on the leading
  94. * edge of the timeout.
  95. * @param {number} [options.maxWait] The maximum time `func` is allowed to be
  96. * delayed before it's invoked.
  97. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  98. * edge of the timeout.
  99. * @returns {Function} Returns the new debounced function.
  100. * @example
  101. *
  102. * // avoid costly calculations while the window size is in flux
  103. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  104. *
  105. * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
  106. * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
  107. * 'leading': true,
  108. * 'trailing': false
  109. * }));
  110. *
  111. * // ensure `batchLog` is invoked once after 1 second of debounced calls
  112. * var source = new EventSource('/stream');
  113. * jQuery(source).on('message', _.debounce(batchLog, 250, {
  114. * 'maxWait': 1000
  115. * }));
  116. *
  117. * // cancel a debounced call
  118. * var todoChanges = _.debounce(batchLog, 1000);
  119. * Object.observe(models.todo, todoChanges);
  120. *
  121. * Object.observe(models, function(changes) {
  122. * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
  123. * todoChanges.cancel();
  124. * }
  125. * }, ['delete']);
  126. *
  127. * // ...at some point `models.todo` is changed
  128. * models.todo.completed = true;
  129. *
  130. * // ...before 1 second has passed `models.todo` is deleted
  131. * // which cancels the debounced `todoChanges` call
  132. * delete models.todo;
  133. */
  134. function debounce(func, wait, options) {
  135. var args,
  136. maxTimeoutId,
  137. result,
  138. stamp,
  139. thisArg,
  140. timeoutId,
  141. trailingCall,
  142. lastCalled = 0,
  143. maxWait = false,
  144. trailing = true;
  145. if (typeof func != 'function') {
  146. throw new TypeError(FUNC_ERROR_TEXT);
  147. }
  148. wait = wait < 0 ? 0 : (+wait || 0);
  149. if (options === true) {
  150. var leading = true;
  151. trailing = false;
  152. } else if (isObject(options)) {
  153. leading = !!options.leading;
  154. maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
  155. trailing = 'trailing' in options ? !!options.trailing : trailing;
  156. }
  157. function cancel() {
  158. if (timeoutId) {
  159. clearTimeout(timeoutId);
  160. }
  161. if (maxTimeoutId) {
  162. clearTimeout(maxTimeoutId);
  163. }
  164. lastCalled = 0;
  165. maxTimeoutId = timeoutId = trailingCall = undefined;
  166. }
  167. function complete(isCalled, id) {
  168. if (id) {
  169. clearTimeout(id);
  170. }
  171. maxTimeoutId = timeoutId = trailingCall = undefined;
  172. if (isCalled) {
  173. lastCalled = now();
  174. result = func.apply(thisArg, args);
  175. if (!timeoutId && !maxTimeoutId) {
  176. args = thisArg = undefined;
  177. }
  178. }
  179. }
  180. function delayed() {
  181. var remaining = wait - (now() - stamp);
  182. if (remaining <= 0 || remaining > wait) {
  183. complete(trailingCall, maxTimeoutId);
  184. } else {
  185. timeoutId = setTimeout(delayed, remaining);
  186. }
  187. }
  188. function maxDelayed() {
  189. complete(trailing, timeoutId);
  190. }
  191. function debounced() {
  192. args = arguments;
  193. stamp = now();
  194. thisArg = this;
  195. trailingCall = trailing && (timeoutId || !leading);
  196. if (maxWait === false) {
  197. var leadingCall = leading && !timeoutId;
  198. } else {
  199. if (!maxTimeoutId && !leading) {
  200. lastCalled = stamp;
  201. }
  202. var remaining = maxWait - (stamp - lastCalled),
  203. isCalled = remaining <= 0 || remaining > maxWait;
  204. if (isCalled) {
  205. if (maxTimeoutId) {
  206. maxTimeoutId = clearTimeout(maxTimeoutId);
  207. }
  208. lastCalled = stamp;
  209. result = func.apply(thisArg, args);
  210. }
  211. else if (!maxTimeoutId) {
  212. maxTimeoutId = setTimeout(maxDelayed, remaining);
  213. }
  214. }
  215. if (isCalled && timeoutId) {
  216. timeoutId = clearTimeout(timeoutId);
  217. }
  218. else if (!timeoutId && wait !== maxWait) {
  219. timeoutId = setTimeout(delayed, wait);
  220. }
  221. if (leadingCall) {
  222. isCalled = true;
  223. result = func.apply(thisArg, args);
  224. }
  225. if (isCalled && !timeoutId && !maxTimeoutId) {
  226. args = thisArg = undefined;
  227. }
  228. return result;
  229. }
  230. debounced.cancel = cancel;
  231. return debounced;
  232. }
  233. module.exports = debounce;
  234. },{"../date/now":4,"../lang/isObject":33}],6:[function(_dereq_,module,exports){
  235. /** Used as the `TypeError` message for "Functions" methods. */
  236. var FUNC_ERROR_TEXT = 'Expected a function';
  237. /* Native method references for those with the same name as other `lodash` methods. */
  238. var nativeMax = Math.max;
  239. /**
  240. * Creates a function that invokes `func` with the `this` binding of the
  241. * created function and arguments from `start` and beyond provided as an array.
  242. *
  243. * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/Web/JavaScript/Reference/Functions/rest_parameters).
  244. *
  245. * @static
  246. * @memberOf _
  247. * @category Function
  248. * @param {Function} func The function to apply a rest parameter to.
  249. * @param {number} [start=func.length-1] The start position of the rest parameter.
  250. * @returns {Function} Returns the new function.
  251. * @example
  252. *
  253. * var say = _.restParam(function(what, names) {
  254. * return what + ' ' + _.initial(names).join(', ') +
  255. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  256. * });
  257. *
  258. * say('hello', 'fred', 'barney', 'pebbles');
  259. * // => 'hello fred, barney, & pebbles'
  260. */
  261. function restParam(func, start) {
  262. if (typeof func != 'function') {
  263. throw new TypeError(FUNC_ERROR_TEXT);
  264. }
  265. start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
  266. return function() {
  267. var args = arguments,
  268. index = -1,
  269. length = nativeMax(args.length - start, 0),
  270. rest = Array(length);
  271. while (++index < length) {
  272. rest[index] = args[start + index];
  273. }
  274. switch (start) {
  275. case 0: return func.call(this, rest);
  276. case 1: return func.call(this, args[0], rest);
  277. case 2: return func.call(this, args[0], args[1], rest);
  278. }
  279. var otherArgs = Array(start + 1);
  280. index = -1;
  281. while (++index < start) {
  282. otherArgs[index] = args[index];
  283. }
  284. otherArgs[start] = rest;
  285. return func.apply(this, otherArgs);
  286. };
  287. }
  288. module.exports = restParam;
  289. },{}],7:[function(_dereq_,module,exports){
  290. var debounce = _dereq_('./debounce'),
  291. isObject = _dereq_('../lang/isObject');
  292. /** Used as the `TypeError` message for "Functions" methods. */
  293. var FUNC_ERROR_TEXT = 'Expected a function';
  294. /**
  295. * Creates a throttled function that only invokes `func` at most once per
  296. * every `wait` milliseconds. The throttled function comes with a `cancel`
  297. * method to cancel delayed invocations. Provide an options object to indicate
  298. * that `func` should be invoked on the leading and/or trailing edge of the
  299. * `wait` timeout. Subsequent calls to the throttled function return the
  300. * result of the last `func` call.
  301. *
  302. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  303. * on the trailing edge of the timeout only if the the throttled function is
  304. * invoked more than once during the `wait` timeout.
  305. *
  306. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  307. * for details over the differences between `_.throttle` and `_.debounce`.
  308. *
  309. * @static
  310. * @memberOf _
  311. * @category Function
  312. * @param {Function} func The function to throttle.
  313. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  314. * @param {Object} [options] The options object.
  315. * @param {boolean} [options.leading=true] Specify invoking on the leading
  316. * edge of the timeout.
  317. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  318. * edge of the timeout.
  319. * @returns {Function} Returns the new throttled function.
  320. * @example
  321. *
  322. * // avoid excessively updating the position while scrolling
  323. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  324. *
  325. * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
  326. * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
  327. * 'trailing': false
  328. * }));
  329. *
  330. * // cancel a trailing throttled call
  331. * jQuery(window).on('popstate', throttled.cancel);
  332. */
  333. function throttle(func, wait, options) {
  334. var leading = true,
  335. trailing = true;
  336. if (typeof func != 'function') {
  337. throw new TypeError(FUNC_ERROR_TEXT);
  338. }
  339. if (options === false) {
  340. leading = false;
  341. } else if (isObject(options)) {
  342. leading = 'leading' in options ? !!options.leading : leading;
  343. trailing = 'trailing' in options ? !!options.trailing : trailing;
  344. }
  345. return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
  346. }
  347. module.exports = throttle;
  348. },{"../lang/isObject":33,"./debounce":5}],8:[function(_dereq_,module,exports){
  349. /**
  350. * Copies the values of `source` to `array`.
  351. *
  352. * @private
  353. * @param {Array} source The array to copy values from.
  354. * @param {Array} [array=[]] The array to copy values to.
  355. * @returns {Array} Returns `array`.
  356. */
  357. function arrayCopy(source, array) {
  358. var index = -1,
  359. length = source.length;
  360. array || (array = Array(length));
  361. while (++index < length) {
  362. array[index] = source[index];
  363. }
  364. return array;
  365. }
  366. module.exports = arrayCopy;
  367. },{}],9:[function(_dereq_,module,exports){
  368. /**
  369. * A specialized version of `_.forEach` for arrays without support for callback
  370. * shorthands and `this` binding.
  371. *
  372. * @private
  373. * @param {Array} array The array to iterate over.
  374. * @param {Function} iteratee The function invoked per iteration.
  375. * @returns {Array} Returns `array`.
  376. */
  377. function arrayEach(array, iteratee) {
  378. var index = -1,
  379. length = array.length;
  380. while (++index < length) {
  381. if (iteratee(array[index], index, array) === false) {
  382. break;
  383. }
  384. }
  385. return array;
  386. }
  387. module.exports = arrayEach;
  388. },{}],10:[function(_dereq_,module,exports){
  389. /**
  390. * Copies properties of `source` to `object`.
  391. *
  392. * @private
  393. * @param {Object} source The object to copy properties from.
  394. * @param {Array} props The property names to copy.
  395. * @param {Object} [object={}] The object to copy properties to.
  396. * @returns {Object} Returns `object`.
  397. */
  398. function baseCopy(source, props, object) {
  399. object || (object = {});
  400. var index = -1,
  401. length = props.length;
  402. while (++index < length) {
  403. var key = props[index];
  404. object[key] = source[key];
  405. }
  406. return object;
  407. }
  408. module.exports = baseCopy;
  409. },{}],11:[function(_dereq_,module,exports){
  410. var createBaseFor = _dereq_('./createBaseFor');
  411. /**
  412. * The base implementation of `baseForIn` and `baseForOwn` which iterates
  413. * over `object` properties returned by `keysFunc` invoking `iteratee` for
  414. * each property. Iteratee functions may exit iteration early by explicitly
  415. * returning `false`.
  416. *
  417. * @private
  418. * @param {Object} object The object to iterate over.
  419. * @param {Function} iteratee The function invoked per iteration.
  420. * @param {Function} keysFunc The function to get the keys of `object`.
  421. * @returns {Object} Returns `object`.
  422. */
  423. var baseFor = createBaseFor();
  424. module.exports = baseFor;
  425. },{"./createBaseFor":18}],12:[function(_dereq_,module,exports){
  426. var baseFor = _dereq_('./baseFor'),
  427. keysIn = _dereq_('../object/keysIn');
  428. /**
  429. * The base implementation of `_.forIn` without support for callback
  430. * shorthands and `this` binding.
  431. *
  432. * @private
  433. * @param {Object} object The object to iterate over.
  434. * @param {Function} iteratee The function invoked per iteration.
  435. * @returns {Object} Returns `object`.
  436. */
  437. function baseForIn(object, iteratee) {
  438. return baseFor(object, iteratee, keysIn);
  439. }
  440. module.exports = baseForIn;
  441. },{"../object/keysIn":39,"./baseFor":11}],13:[function(_dereq_,module,exports){
  442. var arrayEach = _dereq_('./arrayEach'),
  443. baseMergeDeep = _dereq_('./baseMergeDeep'),
  444. isArray = _dereq_('../lang/isArray'),
  445. isArrayLike = _dereq_('./isArrayLike'),
  446. isObject = _dereq_('../lang/isObject'),
  447. isObjectLike = _dereq_('./isObjectLike'),
  448. isTypedArray = _dereq_('../lang/isTypedArray'),
  449. keys = _dereq_('../object/keys');
  450. /**
  451. * The base implementation of `_.merge` without support for argument juggling,
  452. * multiple sources, and `this` binding `customizer` functions.
  453. *
  454. * @private
  455. * @param {Object} object The destination object.
  456. * @param {Object} source The source object.
  457. * @param {Function} [customizer] The function to customize merged values.
  458. * @param {Array} [stackA=[]] Tracks traversed source objects.
  459. * @param {Array} [stackB=[]] Associates values with source counterparts.
  460. * @returns {Object} Returns `object`.
  461. */
  462. function baseMerge(object, source, customizer, stackA, stackB) {
  463. if (!isObject(object)) {
  464. return object;
  465. }
  466. var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
  467. props = isSrcArr ? undefined : keys(source);
  468. arrayEach(props || source, function(srcValue, key) {
  469. if (props) {
  470. key = srcValue;
  471. srcValue = source[key];
  472. }
  473. if (isObjectLike(srcValue)) {
  474. stackA || (stackA = []);
  475. stackB || (stackB = []);
  476. baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
  477. }
  478. else {
  479. var value = object[key],
  480. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  481. isCommon = result === undefined;
  482. if (isCommon) {
  483. result = srcValue;
  484. }
  485. if ((result !== undefined || (isSrcArr && !(key in object))) &&
  486. (isCommon || (result === result ? (result !== value) : (value === value)))) {
  487. object[key] = result;
  488. }
  489. }
  490. });
  491. return object;
  492. }
  493. module.exports = baseMerge;
  494. },{"../lang/isArray":30,"../lang/isObject":33,"../lang/isTypedArray":36,"../object/keys":38,"./arrayEach":9,"./baseMergeDeep":14,"./isArrayLike":21,"./isObjectLike":26}],14:[function(_dereq_,module,exports){
  495. var arrayCopy = _dereq_('./arrayCopy'),
  496. isArguments = _dereq_('../lang/isArguments'),
  497. isArray = _dereq_('../lang/isArray'),
  498. isArrayLike = _dereq_('./isArrayLike'),
  499. isPlainObject = _dereq_('../lang/isPlainObject'),
  500. isTypedArray = _dereq_('../lang/isTypedArray'),
  501. toPlainObject = _dereq_('../lang/toPlainObject');
  502. /**
  503. * A specialized version of `baseMerge` for arrays and objects which performs
  504. * deep merges and tracks traversed objects enabling objects with circular
  505. * references to be merged.
  506. *
  507. * @private
  508. * @param {Object} object The destination object.
  509. * @param {Object} source The source object.
  510. * @param {string} key The key of the value to merge.
  511. * @param {Function} mergeFunc The function to merge values.
  512. * @param {Function} [customizer] The function to customize merged values.
  513. * @param {Array} [stackA=[]] Tracks traversed source objects.
  514. * @param {Array} [stackB=[]] Associates values with source counterparts.
  515. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  516. */
  517. function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
  518. var length = stackA.length,
  519. srcValue = source[key];
  520. while (length--) {
  521. if (stackA[length] == srcValue) {
  522. object[key] = stackB[length];
  523. return;
  524. }
  525. }
  526. var value = object[key],
  527. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  528. isCommon = result === undefined;
  529. if (isCommon) {
  530. result = srcValue;
  531. if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
  532. result = isArray(value)
  533. ? value
  534. : (isArrayLike(value) ? arrayCopy(value) : []);
  535. }
  536. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  537. result = isArguments(value)
  538. ? toPlainObject(value)
  539. : (isPlainObject(value) ? value : {});
  540. }
  541. else {
  542. isCommon = false;
  543. }
  544. }
  545. // Add the source value to the stack of traversed objects and associate
  546. // it with its merged value.
  547. stackA.push(srcValue);
  548. stackB.push(result);
  549. if (isCommon) {
  550. // Recursively merge objects and arrays (susceptible to call stack limits).
  551. object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
  552. } else if (result === result ? (result !== value) : (value === value)) {
  553. object[key] = result;
  554. }
  555. }
  556. module.exports = baseMergeDeep;
  557. },{"../lang/isArguments":29,"../lang/isArray":30,"../lang/isPlainObject":34,"../lang/isTypedArray":36,"../lang/toPlainObject":37,"./arrayCopy":8,"./isArrayLike":21}],15:[function(_dereq_,module,exports){
  558. var toObject = _dereq_('./toObject');
  559. /**
  560. * The base implementation of `_.property` without support for deep paths.
  561. *
  562. * @private
  563. * @param {string} key The key of the property to get.
  564. * @returns {Function} Returns the new function.
  565. */
  566. function baseProperty(key) {
  567. return function(object) {
  568. return object == null ? undefined : toObject(object)[key];
  569. };
  570. }
  571. module.exports = baseProperty;
  572. },{"./toObject":28}],16:[function(_dereq_,module,exports){
  573. var identity = _dereq_('../utility/identity');
  574. /**
  575. * A specialized version of `baseCallback` which only supports `this` binding
  576. * and specifying the number of arguments to provide to `func`.
  577. *
  578. * @private
  579. * @param {Function} func The function to bind.
  580. * @param {*} thisArg The `this` binding of `func`.
  581. * @param {number} [argCount] The number of arguments to provide to `func`.
  582. * @returns {Function} Returns the callback.
  583. */
  584. function bindCallback(func, thisArg, argCount) {
  585. if (typeof func != 'function') {
  586. return identity;
  587. }
  588. if (thisArg === undefined) {
  589. return func;
  590. }
  591. switch (argCount) {
  592. case 1: return function(value) {
  593. return func.call(thisArg, value);
  594. };
  595. case 3: return function(value, index, collection) {
  596. return func.call(thisArg, value, index, collection);
  597. };
  598. case 4: return function(accumulator, value, index, collection) {
  599. return func.call(thisArg, accumulator, value, index, collection);
  600. };
  601. case 5: return function(value, other, key, object, source) {
  602. return func.call(thisArg, value, other, key, object, source);
  603. };
  604. }
  605. return function() {
  606. return func.apply(thisArg, arguments);
  607. };
  608. }
  609. module.exports = bindCallback;
  610. },{"../utility/identity":42}],17:[function(_dereq_,module,exports){
  611. var bindCallback = _dereq_('./bindCallback'),
  612. isIterateeCall = _dereq_('./isIterateeCall'),
  613. restParam = _dereq_('../function/restParam');
  614. /**
  615. * Creates a `_.assign`, `_.defaults`, or `_.merge` function.
  616. *
  617. * @private
  618. * @param {Function} assigner The function to assign values.
  619. * @returns {Function} Returns the new assigner function.
  620. */
  621. function createAssigner(assigner) {
  622. return restParam(function(object, sources) {
  623. var index = -1,
  624. length = object == null ? 0 : sources.length,
  625. customizer = length > 2 ? sources[length - 2] : undefined,
  626. guard = length > 2 ? sources[2] : undefined,
  627. thisArg = length > 1 ? sources[length - 1] : undefined;
  628. if (typeof customizer == 'function') {
  629. customizer = bindCallback(customizer, thisArg, 5);
  630. length -= 2;
  631. } else {
  632. customizer = typeof thisArg == 'function' ? thisArg : undefined;
  633. length -= (customizer ? 1 : 0);
  634. }
  635. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  636. customizer = length < 3 ? undefined : customizer;
  637. length = 1;
  638. }
  639. while (++index < length) {
  640. var source = sources[index];
  641. if (source) {
  642. assigner(object, source, customizer);
  643. }
  644. }
  645. return object;
  646. });
  647. }
  648. module.exports = createAssigner;
  649. },{"../function/restParam":6,"./bindCallback":16,"./isIterateeCall":24}],18:[function(_dereq_,module,exports){
  650. var toObject = _dereq_('./toObject');
  651. /**
  652. * Creates a base function for `_.forIn` or `_.forInRight`.
  653. *
  654. * @private
  655. * @param {boolean} [fromRight] Specify iterating from right to left.
  656. * @returns {Function} Returns the new base function.
  657. */
  658. function createBaseFor(fromRight) {
  659. return function(object, iteratee, keysFunc) {
  660. var iterable = toObject(object),
  661. props = keysFunc(object),
  662. length = props.length,
  663. index = fromRight ? length : -1;
  664. while ((fromRight ? index-- : ++index < length)) {
  665. var key = props[index];
  666. if (iteratee(iterable[key], key, iterable) === false) {
  667. break;
  668. }
  669. }
  670. return object;
  671. };
  672. }
  673. module.exports = createBaseFor;
  674. },{"./toObject":28}],19:[function(_dereq_,module,exports){
  675. var baseProperty = _dereq_('./baseProperty');
  676. /**
  677. * Gets the "length" property value of `object`.
  678. *
  679. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  680. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  681. *
  682. * @private
  683. * @param {Object} object The object to query.
  684. * @returns {*} Returns the "length" value.
  685. */
  686. var getLength = baseProperty('length');
  687. module.exports = getLength;
  688. },{"./baseProperty":15}],20:[function(_dereq_,module,exports){
  689. var isNative = _dereq_('../lang/isNative');
  690. /**
  691. * Gets the native function at `key` of `object`.
  692. *
  693. * @private
  694. * @param {Object} object The object to query.
  695. * @param {string} key The key of the method to get.
  696. * @returns {*} Returns the function if it's native, else `undefined`.
  697. */
  698. function getNative(object, key) {
  699. var value = object == null ? undefined : object[key];
  700. return isNative(value) ? value : undefined;
  701. }
  702. module.exports = getNative;
  703. },{"../lang/isNative":32}],21:[function(_dereq_,module,exports){
  704. var getLength = _dereq_('./getLength'),
  705. isLength = _dereq_('./isLength');
  706. /**
  707. * Checks if `value` is array-like.
  708. *
  709. * @private
  710. * @param {*} value The value to check.
  711. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  712. */
  713. function isArrayLike(value) {
  714. return value != null && isLength(getLength(value));
  715. }
  716. module.exports = isArrayLike;
  717. },{"./getLength":19,"./isLength":25}],22:[function(_dereq_,module,exports){
  718. /**
  719. * Checks if `value` is a host object in IE < 9.
  720. *
  721. * @private
  722. * @param {*} value The value to check.
  723. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  724. */
  725. var isHostObject = (function() {
  726. try {
  727. Object({ 'toString': 0 } + '');
  728. } catch(e) {
  729. return function() { return false; };
  730. }
  731. return function(value) {
  732. // IE < 9 presents many host objects as `Object` objects that can coerce
  733. // to strings despite having improperly defined `toString` methods.
  734. return typeof value.toString != 'function' && typeof (value + '') == 'string';
  735. };
  736. }());
  737. module.exports = isHostObject;
  738. },{}],23:[function(_dereq_,module,exports){
  739. /** Used to detect unsigned integer values. */
  740. var reIsUint = /^\d+$/;
  741. /**
  742. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  743. * of an array-like value.
  744. */
  745. var MAX_SAFE_INTEGER = 9007199254740991;
  746. /**
  747. * Checks if `value` is a valid array-like index.
  748. *
  749. * @private
  750. * @param {*} value The value to check.
  751. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  752. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  753. */
  754. function isIndex(value, length) {
  755. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  756. length = length == null ? MAX_SAFE_INTEGER : length;
  757. return value > -1 && value % 1 == 0 && value < length;
  758. }
  759. module.exports = isIndex;
  760. },{}],24:[function(_dereq_,module,exports){
  761. var isArrayLike = _dereq_('./isArrayLike'),
  762. isIndex = _dereq_('./isIndex'),
  763. isObject = _dereq_('../lang/isObject');
  764. /**
  765. * Checks if the provided arguments are from an iteratee call.
  766. *
  767. * @private
  768. * @param {*} value The potential iteratee value argument.
  769. * @param {*} index The potential iteratee index or key argument.
  770. * @param {*} object The potential iteratee object argument.
  771. * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
  772. */
  773. function isIterateeCall(value, index, object) {
  774. if (!isObject(object)) {
  775. return false;
  776. }
  777. var type = typeof index;
  778. if (type == 'number'
  779. ? (isArrayLike(object) && isIndex(index, object.length))
  780. : (type == 'string' && index in object)) {
  781. var other = object[index];
  782. return value === value ? (value === other) : (other !== other);
  783. }
  784. return false;
  785. }
  786. module.exports = isIterateeCall;
  787. },{"../lang/isObject":33,"./isArrayLike":21,"./isIndex":23}],25:[function(_dereq_,module,exports){
  788. /**
  789. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  790. * of an array-like value.
  791. */
  792. var MAX_SAFE_INTEGER = 9007199254740991;
  793. /**
  794. * Checks if `value` is a valid array-like length.
  795. *
  796. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  797. *
  798. * @private
  799. * @param {*} value The value to check.
  800. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  801. */
  802. function isLength(value) {
  803. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  804. }
  805. module.exports = isLength;
  806. },{}],26:[function(_dereq_,module,exports){
  807. /**
  808. * Checks if `value` is object-like.
  809. *
  810. * @private
  811. * @param {*} value The value to check.
  812. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  813. */
  814. function isObjectLike(value) {
  815. return !!value && typeof value == 'object';
  816. }
  817. module.exports = isObjectLike;
  818. },{}],27:[function(_dereq_,module,exports){
  819. var isArguments = _dereq_('../lang/isArguments'),
  820. isArray = _dereq_('../lang/isArray'),
  821. isIndex = _dereq_('./isIndex'),
  822. isLength = _dereq_('./isLength'),
  823. isString = _dereq_('../lang/isString'),
  824. keysIn = _dereq_('../object/keysIn');
  825. /** Used for native method references. */
  826. var objectProto = Object.prototype;
  827. /** Used to check objects for own properties. */
  828. var hasOwnProperty = objectProto.hasOwnProperty;
  829. /**
  830. * A fallback implementation of `Object.keys` which creates an array of the
  831. * own enumerable property names of `object`.
  832. *
  833. * @private
  834. * @param {Object} object The object to query.
  835. * @returns {Array} Returns the array of property names.
  836. */
  837. function shimKeys(object) {
  838. var props = keysIn(object),
  839. propsLength = props.length,
  840. length = propsLength && object.length;
  841. var allowIndexes = !!length && isLength(length) &&
  842. (isArray(object) || isArguments(object) || isString(object));
  843. var index = -1,
  844. result = [];
  845. while (++index < propsLength) {
  846. var key = props[index];
  847. if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
  848. result.push(key);
  849. }
  850. }
  851. return result;
  852. }
  853. module.exports = shimKeys;
  854. },{"../lang/isArguments":29,"../lang/isArray":30,"../lang/isString":35,"../object/keysIn":39,"./isIndex":23,"./isLength":25}],28:[function(_dereq_,module,exports){
  855. var isObject = _dereq_('../lang/isObject'),
  856. isString = _dereq_('../lang/isString'),
  857. support = _dereq_('../support');
  858. /**
  859. * Converts `value` to an object if it's not one.
  860. *
  861. * @private
  862. * @param {*} value The value to process.
  863. * @returns {Object} Returns the object.
  864. */
  865. function toObject(value) {
  866. if (support.unindexedChars && isString(value)) {
  867. var index = -1,
  868. length = value.length,
  869. result = Object(value);
  870. while (++index < length) {
  871. result[index] = value.charAt(index);
  872. }
  873. return result;
  874. }
  875. return isObject(value) ? value : Object(value);
  876. }
  877. module.exports = toObject;
  878. },{"../lang/isObject":33,"../lang/isString":35,"../support":41}],29:[function(_dereq_,module,exports){
  879. var isArrayLike = _dereq_('../internal/isArrayLike'),
  880. isObjectLike = _dereq_('../internal/isObjectLike');
  881. /** Used for native method references. */
  882. var objectProto = Object.prototype;
  883. /** Used to check objects for own properties. */
  884. var hasOwnProperty = objectProto.hasOwnProperty;
  885. /** Native method references. */
  886. var propertyIsEnumerable = objectProto.propertyIsEnumerable;
  887. /**
  888. * Checks if `value` is classified as an `arguments` object.
  889. *
  890. * @static
  891. * @memberOf _
  892. * @category Lang
  893. * @param {*} value The value to check.
  894. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  895. * @example
  896. *
  897. * _.isArguments(function() { return arguments; }());
  898. * // => true
  899. *
  900. * _.isArguments([1, 2, 3]);
  901. * // => false
  902. */
  903. function isArguments(value) {
  904. return isObjectLike(value) && isArrayLike(value) &&
  905. hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
  906. }
  907. module.exports = isArguments;
  908. },{"../internal/isArrayLike":21,"../internal/isObjectLike":26}],30:[function(_dereq_,module,exports){
  909. var getNative = _dereq_('../internal/getNative'),
  910. isLength = _dereq_('../internal/isLength'),
  911. isObjectLike = _dereq_('../internal/isObjectLike');
  912. /** `Object#toString` result references. */
  913. var arrayTag = '[object Array]';
  914. /** Used for native method references. */
  915. var objectProto = Object.prototype;
  916. /**
  917. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  918. * of values.
  919. */
  920. var objToString = objectProto.toString;
  921. /* Native method references for those with the same name as other `lodash` methods. */
  922. var nativeIsArray = getNative(Array, 'isArray');
  923. /**
  924. * Checks if `value` is classified as an `Array` object.
  925. *
  926. * @static
  927. * @memberOf _
  928. * @category Lang
  929. * @param {*} value The value to check.
  930. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  931. * @example
  932. *
  933. * _.isArray([1, 2, 3]);
  934. * // => true
  935. *
  936. * _.isArray(function() { return arguments; }());
  937. * // => false
  938. */
  939. var isArray = nativeIsArray || function(value) {
  940. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  941. };
  942. module.exports = isArray;
  943. },{"../internal/getNative":20,"../internal/isLength":25,"../internal/isObjectLike":26}],31:[function(_dereq_,module,exports){
  944. var isObject = _dereq_('./isObject');
  945. /** `Object#toString` result references. */
  946. var funcTag = '[object Function]';
  947. /** Used for native method references. */
  948. var objectProto = Object.prototype;
  949. /**
  950. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  951. * of values.
  952. */
  953. var objToString = objectProto.toString;
  954. /**
  955. * Checks if `value` is classified as a `Function` object.
  956. *
  957. * @static
  958. * @memberOf _
  959. * @category Lang
  960. * @param {*} value The value to check.
  961. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  962. * @example
  963. *
  964. * _.isFunction(_);
  965. * // => true
  966. *
  967. * _.isFunction(/abc/);
  968. * // => false
  969. */
  970. function isFunction(value) {
  971. // The use of `Object#toString` avoids issues with the `typeof` operator
  972. // in older versions of Chrome and Safari which return 'function' for regexes
  973. // and Safari 8 which returns 'object' for typed array constructors.
  974. return isObject(value) && objToString.call(value) == funcTag;
  975. }
  976. module.exports = isFunction;
  977. },{"./isObject":33}],32:[function(_dereq_,module,exports){
  978. var isFunction = _dereq_('./isFunction'),
  979. isHostObject = _dereq_('../internal/isHostObject'),
  980. isObjectLike = _dereq_('../internal/isObjectLike');
  981. /** Used to detect host constructors (Safari > 5). */
  982. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  983. /** Used for native method references. */
  984. var objectProto = Object.prototype;
  985. /** Used to resolve the decompiled source of functions. */
  986. var fnToString = Function.prototype.toString;
  987. /** Used to check objects for own properties. */
  988. var hasOwnProperty = objectProto.hasOwnProperty;
  989. /** Used to detect if a method is native. */
  990. var reIsNative = RegExp('^' +
  991. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  992. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  993. );
  994. /**
  995. * Checks if `value` is a native function.
  996. *
  997. * @static
  998. * @memberOf _
  999. * @category Lang
  1000. * @param {*} value The value to check.
  1001. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  1002. * @example
  1003. *
  1004. * _.isNative(Array.prototype.push);
  1005. * // => true
  1006. *
  1007. * _.isNative(_);
  1008. * // => false
  1009. */
  1010. function isNative(value) {
  1011. if (value == null) {
  1012. return false;
  1013. }
  1014. if (isFunction(value)) {
  1015. return reIsNative.test(fnToString.call(value));
  1016. }
  1017. return isObjectLike(value) && (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
  1018. }
  1019. module.exports = isNative;
  1020. },{"../internal/isHostObject":22,"../internal/isObjectLike":26,"./isFunction":31}],33:[function(_dereq_,module,exports){
  1021. /**
  1022. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  1023. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  1024. *
  1025. * @static
  1026. * @memberOf _
  1027. * @category Lang
  1028. * @param {*} value The value to check.
  1029. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  1030. * @example
  1031. *
  1032. * _.isObject({});
  1033. * // => true
  1034. *
  1035. * _.isObject([1, 2, 3]);
  1036. * // => true
  1037. *
  1038. * _.isObject(1);
  1039. * // => false
  1040. */
  1041. function isObject(value) {
  1042. // Avoid a V8 JIT bug in Chrome 19-20.
  1043. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  1044. var type = typeof value;
  1045. return !!value && (type == 'object' || type == 'function');
  1046. }
  1047. module.exports = isObject;
  1048. },{}],34:[function(_dereq_,module,exports){
  1049. var baseForIn = _dereq_('../internal/baseForIn'),
  1050. isArguments = _dereq_('./isArguments'),
  1051. isHostObject = _dereq_('../internal/isHostObject'),
  1052. isObjectLike = _dereq_('../internal/isObjectLike'),
  1053. support = _dereq_('../support');
  1054. /** `Object#toString` result references. */
  1055. var objectTag = '[object Object]';
  1056. /** Used for native method references. */
  1057. var objectProto = Object.prototype;
  1058. /** Used to check objects for own properties. */
  1059. var hasOwnProperty = objectProto.hasOwnProperty;
  1060. /**
  1061. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  1062. * of values.
  1063. */
  1064. var objToString = objectProto.toString;
  1065. /**
  1066. * Checks if `value` is a plain object, that is, an object created by the
  1067. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  1068. *
  1069. * **Note:** This method assumes objects created by the `Object` constructor
  1070. * have no inherited enumerable properties.
  1071. *
  1072. * @static
  1073. * @memberOf _
  1074. * @category Lang
  1075. * @param {*} value The value to check.
  1076. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  1077. * @example
  1078. *
  1079. * function Foo() {
  1080. * this.a = 1;
  1081. * }
  1082. *
  1083. * _.isPlainObject(new Foo);
  1084. * // => false
  1085. *
  1086. * _.isPlainObject([1, 2, 3]);
  1087. * // => false
  1088. *
  1089. * _.isPlainObject({ 'x': 0, 'y': 0 });
  1090. * // => true
  1091. *
  1092. * _.isPlainObject(Object.create(null));
  1093. * // => true
  1094. */
  1095. function isPlainObject(value) {
  1096. var Ctor;
  1097. // Exit early for non `Object` objects.
  1098. if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isHostObject(value) && !isArguments(value)) ||
  1099. (!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
  1100. return false;
  1101. }
  1102. // IE < 9 iterates inherited properties before own properties. If the first
  1103. // iterated property is an object's own property then there are no inherited
  1104. // enumerable properties.
  1105. var result;
  1106. if (support.ownLast) {
  1107. baseForIn(value, function(subValue, key, object) {
  1108. result = hasOwnProperty.call(object, key);
  1109. return false;
  1110. });
  1111. return result !== false;
  1112. }
  1113. // In most environments an object's own properties are iterated before
  1114. // its inherited properties. If the last iterated property is an object's
  1115. // own property then there are no inherited enumerable properties.
  1116. baseForIn(value, function(subValue, key) {
  1117. result = key;
  1118. });
  1119. return result === undefined || hasOwnProperty.call(value, result);
  1120. }
  1121. module.exports = isPlainObject;
  1122. },{"../internal/baseForIn":12,"../internal/isHostObject":22,"../internal/isObjectLike":26,"../support":41,"./isArguments":29}],35:[function(_dereq_,module,exports){
  1123. var isObjectLike = _dereq_('../internal/isObjectLike');
  1124. /** `Object#toString` result references. */
  1125. var stringTag = '[object String]';
  1126. /** Used for native method references. */
  1127. var objectProto = Object.prototype;
  1128. /**
  1129. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  1130. * of values.
  1131. */
  1132. var objToString = objectProto.toString;
  1133. /**
  1134. * Checks if `value` is classified as a `String` primitive or object.
  1135. *
  1136. * @static
  1137. * @memberOf _
  1138. * @category Lang
  1139. * @param {*} value The value to check.
  1140. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  1141. * @example
  1142. *
  1143. * _.isString('abc');
  1144. * // => true
  1145. *
  1146. * _.isString(1);
  1147. * // => false
  1148. */
  1149. function isString(value) {
  1150. return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
  1151. }
  1152. module.exports = isString;
  1153. },{"../internal/isObjectLike":26}],36:[function(_dereq_,module,exports){
  1154. var isLength = _dereq_('../internal/isLength'),
  1155. isObjectLike = _dereq_('../internal/isObjectLike');
  1156. /** `Object#toString` result references. */
  1157. var argsTag = '[object Arguments]',
  1158. arrayTag = '[object Array]',
  1159. boolTag = '[object Boolean]',
  1160. dateTag = '[object Date]',
  1161. errorTag = '[object Error]',
  1162. funcTag = '[object Function]',
  1163. mapTag = '[object Map]',
  1164. numberTag = '[object Number]',
  1165. objectTag = '[object Object]',
  1166. regexpTag = '[object RegExp]',
  1167. setTag = '[object Set]',
  1168. stringTag = '[object String]',
  1169. weakMapTag = '[object WeakMap]';
  1170. var arrayBufferTag = '[object ArrayBuffer]',
  1171. float32Tag = '[object Float32Array]',
  1172. float64Tag = '[object Float64Array]',
  1173. int8Tag = '[object Int8Array]',
  1174. int16Tag = '[object Int16Array]',
  1175. int32Tag = '[object Int32Array]',
  1176. uint8Tag = '[object Uint8Array]',
  1177. uint8ClampedTag = '[object Uint8ClampedArray]',
  1178. uint16Tag = '[object Uint16Array]',
  1179. uint32Tag = '[object Uint32Array]';
  1180. /** Used to identify `toStringTag` values of typed arrays. */
  1181. var typedArrayTags = {};
  1182. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  1183. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  1184. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  1185. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  1186. typedArrayTags[uint32Tag] = true;
  1187. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  1188. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  1189. typedArrayTags[dateTag] = typedArrayTags[errorTag] =
  1190. typedArrayTags[funcTag] = typedArrayTags[mapTag] =
  1191. typedArrayTags[numberTag] = typedArrayTags[objectTag] =
  1192. typedArrayTags[regexpTag] = typedArrayTags[setTag] =
  1193. typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  1194. /** Used for native method references. */
  1195. var objectProto = Object.prototype;
  1196. /**
  1197. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  1198. * of values.
  1199. */
  1200. var objToString = objectProto.toString;
  1201. /**
  1202. * Checks if `value` is classified as a typed array.
  1203. *
  1204. * @static
  1205. * @memberOf _
  1206. * @category Lang
  1207. * @param {*} value The value to check.
  1208. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  1209. * @example
  1210. *
  1211. * _.isTypedArray(new Uint8Array);
  1212. * // => true
  1213. *
  1214. * _.isTypedArray([]);
  1215. * // => false
  1216. */
  1217. function isTypedArray(value) {
  1218. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
  1219. }
  1220. module.exports = isTypedArray;
  1221. },{"../internal/isLength":25,"../internal/isObjectLike":26}],37:[function(_dereq_,module,exports){
  1222. var baseCopy = _dereq_('../internal/baseCopy'),
  1223. keysIn = _dereq_('../object/keysIn');
  1224. /**
  1225. * Converts `value` to a plain object flattening inherited enumerable
  1226. * properties of `value` to own properties of the plain object.
  1227. *
  1228. * @static
  1229. * @memberOf _
  1230. * @category Lang
  1231. * @param {*} value The value to convert.
  1232. * @returns {Object} Returns the converted plain object.
  1233. * @example
  1234. *
  1235. * function Foo() {
  1236. * this.b = 2;
  1237. * }
  1238. *
  1239. * Foo.prototype.c = 3;
  1240. *
  1241. * _.assign({ 'a': 1 }, new Foo);
  1242. * // => { 'a': 1, 'b': 2 }
  1243. *
  1244. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  1245. * // => { 'a': 1, 'b': 2, 'c': 3 }
  1246. */
  1247. function toPlainObject(value) {
  1248. return baseCopy(value, keysIn(value));
  1249. }
  1250. module.exports = toPlainObject;
  1251. },{"../internal/baseCopy":10,"../object/keysIn":39}],38:[function(_dereq_,module,exports){
  1252. var getNative = _dereq_('../internal/getNative'),
  1253. isArrayLike = _dereq_('../internal/isArrayLike'),
  1254. isObject = _dereq_('../lang/isObject'),
  1255. shimKeys = _dereq_('../internal/shimKeys'),
  1256. support = _dereq_('../support');
  1257. /* Native method references for those with the same name as other `lodash` methods. */
  1258. var nativeKeys = getNative(Object, 'keys');
  1259. /**
  1260. * Creates an array of the own enumerable property names of `object`.
  1261. *
  1262. * **Note:** Non-object values are coerced to objects. See the
  1263. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  1264. * for more details.
  1265. *
  1266. * @static
  1267. * @memberOf _
  1268. * @category Object
  1269. * @param {Object} object The object to query.
  1270. * @returns {Array} Returns the array of property names.
  1271. * @example
  1272. *
  1273. * function Foo() {
  1274. * this.a = 1;
  1275. * this.b = 2;
  1276. * }
  1277. *
  1278. * Foo.prototype.c = 3;
  1279. *
  1280. * _.keys(new Foo);
  1281. * // => ['a', 'b'] (iteration order is not guaranteed)
  1282. *
  1283. * _.keys('hi');
  1284. * // => ['0', '1']
  1285. */
  1286. var keys = !nativeKeys ? shimKeys : function(object) {
  1287. var Ctor = object == null ? undefined : object.constructor;
  1288. if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
  1289. (typeof object == 'function' ? support.enumPrototypes : isArrayLike(object))) {
  1290. return shimKeys(object);
  1291. }
  1292. return isObject(object) ? nativeKeys(object) : [];
  1293. };
  1294. module.exports = keys;
  1295. },{"../internal/getNative":20,"../internal/isArrayLike":21,"../internal/shimKeys":27,"../lang/isObject":33,"../support":41}],39:[function(_dereq_,module,exports){
  1296. var arrayEach = _dereq_('../internal/arrayEach'),
  1297. isArguments = _dereq_('../lang/isArguments'),
  1298. isArray = _dereq_('../lang/isArray'),
  1299. isFunction = _dereq_('../lang/isFunction'),
  1300. isIndex = _dereq_('../internal/isIndex'),
  1301. isLength = _dereq_('../internal/isLength'),
  1302. isObject = _dereq_('../lang/isObject'),
  1303. isString = _dereq_('../lang/isString'),
  1304. support = _dereq_('../support');
  1305. /** `Object#toString` result references. */
  1306. var arrayTag = '[object Array]',
  1307. boolTag = '[object Boolean]',
  1308. dateTag = '[object Date]',
  1309. errorTag = '[object Error]',
  1310. funcTag = '[object Function]',
  1311. numberTag = '[object Number]',
  1312. objectTag = '[object Object]',
  1313. regexpTag = '[object RegExp]',
  1314. stringTag = '[object String]';
  1315. /** Used to fix the JScript `[[DontEnum]]` bug. */
  1316. var shadowProps = [
  1317. 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
  1318. 'toLocaleString', 'toString', 'valueOf'
  1319. ];
  1320. /** Used for native method references. */
  1321. var errorProto = Error.prototype,
  1322. objectProto = Object.prototype,
  1323. stringProto = String.prototype;
  1324. /** Used to check objects for own properties. */
  1325. var hasOwnProperty = objectProto.hasOwnProperty;
  1326. /**
  1327. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  1328. * of values.
  1329. */
  1330. var objToString = objectProto.toString;
  1331. /** Used to avoid iterating over non-enumerable properties in IE < 9. */
  1332. var nonEnumProps = {};
  1333. nonEnumProps[arrayTag] = nonEnumProps[dateTag] = nonEnumProps[numberTag] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
  1334. nonEnumProps[boolTag] = nonEnumProps[stringTag] = { 'constructor': true, 'toString': true, 'valueOf': true };
  1335. nonEnumProps[errorTag] = nonEnumProps[funcTag] = nonEnumProps[regexpTag] = { 'constructor': true, 'toString': true };
  1336. nonEnumProps[objectTag] = { 'constructor': true };
  1337. arrayEach(shadowProps, function(key) {
  1338. for (var tag in nonEnumProps) {
  1339. if (hasOwnProperty.call(nonEnumProps, tag)) {
  1340. var props = nonEnumProps[tag];
  1341. props[key] = hasOwnProperty.call(props, key);
  1342. }
  1343. }
  1344. });
  1345. /**
  1346. * Creates an array of the own and inherited enumerable property names of `object`.
  1347. *
  1348. * **Note:** Non-object values are coerced to objects.
  1349. *
  1350. * @static
  1351. * @memberOf _
  1352. * @category Object
  1353. * @param {Object} object The object to query.
  1354. * @returns {Array} Returns the array of property names.
  1355. * @example
  1356. *
  1357. * function Foo() {
  1358. * this.a = 1;
  1359. * this.b = 2;
  1360. * }
  1361. *
  1362. * Foo.prototype.c = 3;
  1363. *
  1364. * _.keysIn(new Foo);
  1365. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  1366. */
  1367. function keysIn(object) {
  1368. if (object == null) {
  1369. return [];
  1370. }
  1371. if (!isObject(object)) {
  1372. object = Object(object);
  1373. }
  1374. var length = object.length;
  1375. length = (length && isLength(length) &&
  1376. (isArray(object) || isArguments(object) || isString(object)) && length) || 0;
  1377. var Ctor = object.constructor,
  1378. index = -1,
  1379. proto = (isFunction(Ctor) && Ctor.prototype) || objectProto,
  1380. isProto = proto === object,
  1381. result = Array(length),
  1382. skipIndexes = length > 0,
  1383. skipErrorProps = support.enumErrorProps && (object === errorProto || object instanceof Error),
  1384. skipProto = support.enumPrototypes && isFunction(object);
  1385. while (++index < length) {
  1386. result[index] = (index + '');
  1387. }
  1388. // lodash skips the `constructor` property when it infers it's iterating
  1389. // over a `prototype` object because IE < 9 can't set the `[[Enumerable]]`
  1390. // attribute of an existing property and the `constructor` property of a
  1391. // prototype defaults to non-enumerable.
  1392. for (var key in object) {
  1393. if (!(skipProto && key == 'prototype') &&
  1394. !(skipErrorProps && (key == 'message' || key == 'name')) &&
  1395. !(skipIndexes && isIndex(key, length)) &&
  1396. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  1397. result.push(key);
  1398. }
  1399. }
  1400. if (support.nonEnumShadows && object !== objectProto) {
  1401. var tag = object === stringProto ? stringTag : (object === errorProto ? errorTag : objToString.call(object)),
  1402. nonEnums = nonEnumProps[tag] || nonEnumProps[objectTag];
  1403. if (tag == objectTag) {
  1404. proto = objectProto;
  1405. }
  1406. length = shadowProps.length;
  1407. while (length--) {
  1408. key = shadowProps[length];
  1409. var nonEnum = nonEnums[key];
  1410. if (!(isProto && nonEnum) &&
  1411. (nonEnum ? hasOwnProperty.call(object, key) : object[key] !== proto[key])) {
  1412. result.push(key);
  1413. }
  1414. }
  1415. }
  1416. return result;
  1417. }
  1418. module.exports = keysIn;
  1419. },{"../internal/arrayEach":9,"../internal/isIndex":23,"../internal/isLength":25,"../lang/isArguments":29,"../lang/isArray":30,"../lang/isFunction":31,"../lang/isObject":33,"../lang/isString":35,"../support":41}],40:[function(_dereq_,module,exports){
  1420. var baseMerge = _dereq_('../internal/baseMerge'),
  1421. createAssigner = _dereq_('../internal/createAssigner');
  1422. /**
  1423. * Recursively merges own enumerable properties of the source object(s), that
  1424. * don't resolve to `undefined` into the destination object. Subsequent sources
  1425. * overwrite property assignments of previous sources. If `customizer` is
  1426. * provided it's invoked to produce the merged values of the destination and
  1427. * source properties. If `customizer` returns `undefined` merging is handled
  1428. * by the method instead. The `customizer` is bound to `thisArg` and invoked
  1429. * with five arguments: (objectValue, sourceValue, key, object, source).
  1430. *
  1431. * @static
  1432. * @memberOf _
  1433. * @category Object
  1434. * @param {Object} object The destination object.
  1435. * @param {...Object} [sources] The source objects.
  1436. * @param {Function} [customizer] The function to customize assigned values.
  1437. * @param {*} [thisArg] The `this` binding of `customizer`.
  1438. * @returns {Object} Returns `object`.
  1439. * @example
  1440. *
  1441. * var users = {
  1442. * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
  1443. * };
  1444. *
  1445. * var ages = {
  1446. * 'data': [{ 'age': 36 }, { 'age': 40 }]
  1447. * };
  1448. *
  1449. * _.merge(users, ages);
  1450. * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
  1451. *
  1452. * // using a customizer callback
  1453. * var object = {
  1454. * 'fruits': ['apple'],
  1455. * 'vegetables': ['beet']
  1456. * };
  1457. *
  1458. * var other = {
  1459. * 'fruits': ['banana'],
  1460. * 'vegetables': ['carrot']
  1461. * };
  1462. *
  1463. * _.merge(object, other, function(a, b) {
  1464. * if (_.isArray(a)) {
  1465. * return a.concat(b);
  1466. * }
  1467. * });
  1468. * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
  1469. */
  1470. var merge = createAssigner(baseMerge);
  1471. module.exports = merge;
  1472. },{"../internal/baseMerge":13,"../internal/createAssigner":17}],41:[function(_dereq_,module,exports){
  1473. /** Used for native method references. */
  1474. var arrayProto = Array.prototype,
  1475. errorProto = Error.prototype,
  1476. objectProto = Object.prototype;
  1477. /** Native method references. */
  1478. var propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1479. splice = arrayProto.splice;
  1480. /**
  1481. * An object environment feature flags.
  1482. *
  1483. * @static
  1484. * @memberOf _
  1485. * @type Object
  1486. */
  1487. var support = {};
  1488. (function(x) {
  1489. var Ctor = function() { this.x = x; },
  1490. object = { '0': x, 'length': x },
  1491. props = [];
  1492. Ctor.prototype = { 'valueOf': x, 'y': x };
  1493. for (var key in new Ctor) { props.push(key); }
  1494. /**
  1495. * Detect if `name` or `message` properties of `Error.prototype` are
  1496. * enumerable by default (IE < 9, Safari < 5.1).
  1497. *
  1498. * @memberOf _.support
  1499. * @type boolean
  1500. */
  1501. support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') ||
  1502. propertyIsEnumerable.call(errorProto, 'name');
  1503. /**
  1504. * Detect if `prototype` properties are enumerable by default.
  1505. *
  1506. * Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
  1507. * (if the prototype or a property on the prototype has been set)
  1508. * incorrectly set the `[[Enumerable]]` value of a function's `prototype`
  1509. * property to `true`.
  1510. *
  1511. * @memberOf _.support
  1512. * @type boolean
  1513. */
  1514. support.enumPrototypes = propertyIsEnumerable.call(Ctor, 'prototype');
  1515. /**
  1516. * Detect if properties shadowing those on `Object.prototype` are non-enumerable.
  1517. *
  1518. * In IE < 9 an object's own properties, shadowing non-enumerable ones,
  1519. * are made non-enumerable as well (a.k.a the JScript `[[DontEnum]]` bug).
  1520. *
  1521. * @memberOf _.support
  1522. * @type boolean
  1523. */
  1524. support.nonEnumShadows = !/valueOf/.test(props);
  1525. /**
  1526. * Detect if own properties are iterated after inherited properties (IE < 9).
  1527. *
  1528. * @memberOf _.support
  1529. * @type boolean
  1530. */
  1531. support.ownLast = props[0] != 'x';
  1532. /**
  1533. * Detect if `Array#shift` and `Array#splice` augment array-like objects
  1534. * correctly.
  1535. *
  1536. * Firefox < 10, compatibility modes of IE 8, and IE < 9 have buggy Array
  1537. * `shift()` and `splice()` functions that fail to remove the last element,
  1538. * `value[0]`, of array-like objects even though the "length" property is
  1539. * set to `0`. The `shift()` method is buggy in compatibility modes of IE 8,
  1540. * while `splice()` is buggy regardless of mode in IE < 9.
  1541. *
  1542. * @memberOf _.support
  1543. * @type boolean
  1544. */
  1545. support.spliceObjects = (splice.call(object, 0, 1), !object[0]);
  1546. /**
  1547. * Detect lack of support for accessing string characters by index.
  1548. *
  1549. * IE < 8 can't access characters by index. IE 8 can only access characters
  1550. * by index on string literals, not string objects.
  1551. *
  1552. * @memberOf _.support
  1553. * @type boolean
  1554. */
  1555. support.unindexedChars = ('x'[0] + Object('x')[0]) != 'xx';
  1556. }(1, 0));
  1557. module.exports = support;
  1558. },{}],42:[function(_dereq_,module,exports){
  1559. /**
  1560. * This method returns the first argument provided to it.
  1561. *
  1562. * @static
  1563. * @memberOf _
  1564. * @category Utility
  1565. * @param {*} value Any value.
  1566. * @returns {*} Returns `value`.
  1567. * @example
  1568. *
  1569. * var object = { 'user': 'fred' };
  1570. *
  1571. * _.identity(object) === object;
  1572. * // => true
  1573. */
  1574. function identity(value) {
  1575. return value;
  1576. }
  1577. module.exports = identity;
  1578. },{}],43:[function(_dereq_,module,exports){
  1579. 'use strict';
  1580. var keys = _dereq_('object-keys');
  1581. module.exports = function hasSymbols() {
  1582. if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }
  1583. if (typeof Symbol.iterator === 'symbol') { return true; }
  1584. var obj = {};
  1585. var sym = Symbol('test');
  1586. if (typeof sym === 'string') { return false; }
  1587. // temp disabled per https://github.com/ljharb/object.assign/issues/17
  1588. // if (sym instanceof Symbol) { return false; }
  1589. // temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4
  1590. // if (!(Object(sym) instanceof Symbol)) { return false; }
  1591. var symVal = 42;
  1592. obj[sym] = symVal;
  1593. for (sym in obj) { return false; }
  1594. if (keys(obj).length !== 0) { return false; }
  1595. if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }
  1596. if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }
  1597. var syms = Object.getOwnPropertySymbols(obj);
  1598. if (syms.length !== 1 || syms[0] !== sym) { return false; }
  1599. if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }
  1600. if (typeof Object.getOwnPropertyDescriptor === 'function') {
  1601. var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
  1602. if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }
  1603. }
  1604. return true;
  1605. };
  1606. },{"object-keys":50}],44:[function(_dereq_,module,exports){
  1607. 'use strict';
  1608. // modified from https://github.com/es-shims/es6-shim
  1609. var keys = _dereq_('object-keys');
  1610. var bind = _dereq_('function-bind');
  1611. var canBeObject = function (obj) {
  1612. return typeof obj !== 'undefined' && obj !== null;
  1613. };
  1614. var hasSymbols = _dereq_('./hasSymbols')();
  1615. var toObject = Object;
  1616. var push = bind.call(Function.call, Array.prototype.push);
  1617. var propIsEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable);
  1618. module.exports = function assign(target, source1) {
  1619. if (!canBeObject(target)) { throw new TypeError('target must be an object'); }
  1620. var objTarget = toObject(target);
  1621. var s, source, i, props, syms, value, key;
  1622. for (s = 1; s < arguments.length; ++s) {
  1623. source = toObject(arguments[s]);
  1624. props = keys(source);
  1625. if (hasSymbols && Object.getOwnPropertySymbols) {
  1626. syms = Object.getOwnPropertySymbols(source);
  1627. for (i = 0; i < syms.length; ++i) {
  1628. key = syms[i];
  1629. if (propIsEnumerable(source, key)) {
  1630. push(props, key);
  1631. }
  1632. }
  1633. }
  1634. for (i = 0; i < props.length; ++i) {
  1635. key = props[i];
  1636. value = source[key];
  1637. if (propIsEnumerable(source, key)) {
  1638. objTarget[key] = value;
  1639. }
  1640. }
  1641. }
  1642. return objTarget;
  1643. };
  1644. },{"./hasSymbols":43,"function-bind":49,"object-keys":50}],45:[function(_dereq_,module,exports){
  1645. 'use strict';
  1646. var defineProperties = _dereq_('define-properties');
  1647. var implementation = _dereq_('./implementation');
  1648. var getPolyfill = _dereq_('./polyfill');
  1649. var shim = _dereq_('./shim');
  1650. defineProperties(implementation, {
  1651. implementation: implementation,
  1652. getPolyfill: getPolyfill,
  1653. shim: shim
  1654. });
  1655. module.exports = implementation;
  1656. },{"./implementation":44,"./polyfill":52,"./shim":53,"define-properties":46}],46:[function(_dereq_,module,exports){
  1657. 'use strict';
  1658. var keys = _dereq_('object-keys');
  1659. var foreach = _dereq_('foreach');
  1660. var hasSymbols = typeof Symbol === 'function' && typeof Symbol() === 'symbol';
  1661. var toStr = Object.prototype.toString;
  1662. var isFunction = function (fn) {
  1663. return typeof fn === 'function' && toStr.call(fn) === '[object Function]';
  1664. };
  1665. var arePropertyDescriptorsSupported = function () {
  1666. var obj = {};
  1667. try {
  1668. Object.defineProperty(obj, 'x', { enumerable: false, value: obj });
  1669. /* eslint-disable no-unused-vars, no-restricted-syntax */
  1670. for (var _ in obj) { return false; }
  1671. /* eslint-enable no-unused-vars, no-restricted-syntax */
  1672. return obj.x === obj;
  1673. } catch (e) { /* this is IE 8. */
  1674. return false;
  1675. }
  1676. };
  1677. var supportsDescriptors = Object.defineProperty && arePropertyDescriptorsSupported();
  1678. var defineProperty = function (object, name, value, predicate) {
  1679. if (name in object && (!isFunction(predicate) || !predicate())) {
  1680. return;
  1681. }
  1682. if (supportsDescriptors) {
  1683. Object.defineProperty(object, name, {
  1684. configurable: true,
  1685. enumerable: false,
  1686. value: value,
  1687. writable: true
  1688. });
  1689. } else {
  1690. object[name] = value;
  1691. }
  1692. };
  1693. var defineProperties = function (object, map) {
  1694. var predicates = arguments.length > 2 ? arguments[2] : {};
  1695. var props = keys(map);
  1696. if (hasSymbols) {
  1697. props = props.concat(Object.getOwnPropertySymbols(map));
  1698. }
  1699. foreach(props, function (name) {
  1700. defineProperty(object, name, map[name], predicates[name]);
  1701. });
  1702. };
  1703. defineProperties.supportsDescriptors = !!supportsDescriptors;
  1704. module.exports = defineProperties;
  1705. },{"foreach":47,"object-keys":50}],47:[function(_dereq_,module,exports){
  1706. var hasOwn = Object.prototype.hasOwnProperty;
  1707. var toString = Object.prototype.toString;
  1708. module.exports = function forEach (obj, fn, ctx) {
  1709. if (toString.call(fn) !== '[object Function]') {
  1710. throw new TypeError('iterator must be a function');
  1711. }
  1712. var l = obj.length;
  1713. if (l === +l) {
  1714. for (var i = 0; i < l; i++) {
  1715. fn.call(ctx, obj[i], i, obj);
  1716. }
  1717. } else {
  1718. for (var k in obj) {
  1719. if (hasOwn.call(obj, k)) {
  1720. fn.call(ctx, obj[k], k, obj);
  1721. }
  1722. }
  1723. }
  1724. };
  1725. },{}],48:[function(_dereq_,module,exports){
  1726. var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
  1727. var slice = Array.prototype.slice;
  1728. var toStr = Object.prototype.toString;
  1729. var funcType = '[object Function]';
  1730. module.exports = function bind(that) {
  1731. var target = this;
  1732. if (typeof target !== 'function' || toStr.call(target) !== funcType) {
  1733. throw new TypeError(ERROR_MESSAGE + target);
  1734. }
  1735. var args = slice.call(arguments, 1);
  1736. var bound;
  1737. var binder = function () {
  1738. if (this instanceof bound) {
  1739. var result = target.apply(
  1740. this,
  1741. args.concat(slice.call(arguments))
  1742. );
  1743. if (Object(result) === result) {
  1744. return result;
  1745. }
  1746. return this;
  1747. } else {
  1748. return target.apply(
  1749. that,
  1750. args.concat(slice.call(arguments))
  1751. );
  1752. }
  1753. };
  1754. var boundLength = Math.max(0, target.length - args.length);
  1755. var boundArgs = [];
  1756. for (var i = 0; i < boundLength; i++) {
  1757. boundArgs.push('$' + i);
  1758. }
  1759. bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
  1760. if (target.prototype) {
  1761. var Empty = function Empty() {};
  1762. Empty.prototype = target.prototype;
  1763. bound.prototype = new Empty();
  1764. Empty.prototype = null;
  1765. }
  1766. return bound;
  1767. };
  1768. },{}],49:[function(_dereq_,module,exports){
  1769. var implementation = _dereq_('./implementation');
  1770. module.exports = Function.prototype.bind || implementation;
  1771. },{"./implementation":48}],50:[function(_dereq_,module,exports){
  1772. 'use strict';
  1773. // modified from https://github.com/es-shims/es5-shim
  1774. var has = Object.prototype.hasOwnProperty;
  1775. var toStr = Object.prototype.toString;
  1776. var slice = Array.prototype.slice;
  1777. var isArgs = _dereq_('./isArguments');
  1778. var hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString');
  1779. var hasProtoEnumBug = function () {}.propertyIsEnumerable('prototype');
  1780. var dontEnums = [
  1781. 'toString',
  1782. 'toLocaleString',
  1783. 'valueOf',
  1784. 'hasOwnProperty',
  1785. 'isPrototypeOf',
  1786. 'propertyIsEnumerable',
  1787. 'constructor'
  1788. ];
  1789. var equalsConstructorPrototype = function (o) {
  1790. var ctor = o.constructor;
  1791. return ctor && ctor.prototype === o;
  1792. };
  1793. var blacklistedKeys = {
  1794. $console: true,
  1795. $frame: true,
  1796. $frameElement: true,
  1797. $frames: true,
  1798. $parent: true,
  1799. $self: true,
  1800. $webkitIndexedDB: true,
  1801. $webkitStorageInfo: true,
  1802. $window: true
  1803. };
  1804. var hasAutomationEqualityBug = (function () {
  1805. /* global window */
  1806. if (typeof window === 'undefined') { return false; }
  1807. for (var k in window) {
  1808. try {
  1809. if (!blacklistedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
  1810. try {
  1811. equalsConstructorPrototype(window[k]);
  1812. } catch (e) {
  1813. return true;
  1814. }
  1815. }
  1816. } catch (e) {
  1817. return true;
  1818. }
  1819. }
  1820. return false;
  1821. }());
  1822. var equalsConstructorPrototypeIfNotBuggy = function (o) {
  1823. /* global window */
  1824. if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
  1825. return equalsConstructorPrototype(o);
  1826. }
  1827. try {
  1828. return equalsConstructorPrototype(o);
  1829. } catch (e) {
  1830. return false;
  1831. }
  1832. };
  1833. var keysShim = function keys(object) {
  1834. var isObject = object !== null && typeof object === 'object';
  1835. var isFunction = toStr.call(object) === '[object Function]';
  1836. var isArguments = isArgs(object);
  1837. var isString = isObject && toStr.call(object) === '[object String]';
  1838. var theKeys = [];
  1839. if (!isObject && !isFunction && !isArguments) {
  1840. throw new TypeError('Object.keys called on a non-object');
  1841. }
  1842. var skipProto = hasProtoEnumBug && isFunction;
  1843. if (isString && object.length > 0 && !has.call(object, 0)) {
  1844. for (var i = 0; i < object.length; ++i) {
  1845. theKeys.push(String(i));
  1846. }
  1847. }
  1848. if (isArguments && object.length > 0) {
  1849. for (var j = 0; j < object.length; ++j) {
  1850. theKeys.push(String(j));
  1851. }
  1852. } else {
  1853. for (var name in object) {
  1854. if (!(skipProto && name === 'prototype') && has.call(object, name)) {
  1855. theKeys.push(String(name));
  1856. }
  1857. }
  1858. }
  1859. if (hasDontEnumBug) {
  1860. var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
  1861. for (var k = 0; k < dontEnums.length; ++k) {
  1862. if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
  1863. theKeys.push(dontEnums[k]);
  1864. }
  1865. }
  1866. }
  1867. return theKeys;
  1868. };
  1869. keysShim.shim = function shimObjectKeys() {
  1870. if (Object.keys) {
  1871. var keysWorksWithArguments = (function () {
  1872. // Safari 5.0 bug
  1873. return (Object.keys(arguments) || '').length === 2;
  1874. }(1, 2));
  1875. if (!keysWorksWithArguments) {
  1876. var originalKeys = Object.keys;
  1877. Object.keys = function keys(object) {
  1878. if (isArgs(object)) {
  1879. return originalKeys(slice.call(object));
  1880. } else {
  1881. return originalKeys(object);
  1882. }
  1883. };
  1884. }
  1885. } else {
  1886. Object.keys = keysShim;
  1887. }
  1888. return Object.keys || keysShim;
  1889. };
  1890. module.exports = keysShim;
  1891. },{"./isArguments":51}],51:[function(_dereq_,module,exports){
  1892. 'use strict';
  1893. var toStr = Object.prototype.toString;
  1894. module.exports = function isArguments(value) {
  1895. var str = toStr.call(value);
  1896. var isArgs = str === '[object Arguments]';
  1897. if (!isArgs) {
  1898. isArgs = str !== '[object Array]' &&
  1899. value !== null &&
  1900. typeof value === 'object' &&
  1901. typeof value.length === 'number' &&
  1902. value.length >= 0 &&
  1903. toStr.call(value.callee) === '[object Function]';
  1904. }
  1905. return isArgs;
  1906. };
  1907. },{}],52:[function(_dereq_,module,exports){
  1908. 'use strict';
  1909. var implementation = _dereq_('./implementation');
  1910. var lacksProperEnumerationOrder = function () {
  1911. if (!Object.assign) {
  1912. return false;
  1913. }
  1914. // v8, specifically in node 4.x, has a bug with incorrect property enumeration order
  1915. // note: this does not detect the bug unless there's 20 characters
  1916. var str = 'abcdefghijklmnopqrst';
  1917. var letters = str.split('');
  1918. var map = {};
  1919. for (var i = 0; i < letters.length; ++i) {
  1920. map[letters[i]] = letters[i];
  1921. }
  1922. var obj = Object.assign({}, map);
  1923. var actual = '';
  1924. for (var k in obj) {
  1925. actual += k;
  1926. }
  1927. return str !== actual;
  1928. };
  1929. var assignHasPendingExceptions = function () {
  1930. if (!Object.assign || !Object.preventExtensions) {
  1931. return false;
  1932. }
  1933. // Firefox 37 still has "pending exception" logic in its Object.assign implementation,
  1934. // which is 72% slower than our shim, and Firefox 40's native implementation.
  1935. var thrower = Object.preventExtensions({ 1: 2 });
  1936. try {
  1937. Object.assign(thrower, 'xy');
  1938. } catch (e) {
  1939. return thrower[1] === 'y';
  1940. }
  1941. };
  1942. module.exports = function getPolyfill() {
  1943. if (!Object.assign) {
  1944. return implementation;
  1945. }
  1946. if (lacksProperEnumerationOrder()) {
  1947. return implementation;
  1948. }
  1949. if (assignHasPendingExceptions()) {
  1950. return implementation;
  1951. }
  1952. return Object.assign;
  1953. };
  1954. },{"./implementation":44}],53:[function(_dereq_,module,exports){
  1955. 'use strict';
  1956. var define = _dereq_('define-properties');
  1957. var getPolyfill = _dereq_('./polyfill');
  1958. module.exports = function shimAssign() {
  1959. var polyfill = getPolyfill();
  1960. define(
  1961. Object,
  1962. { assign: polyfill },
  1963. { assign: function () { return Object.assign !== polyfill; } }
  1964. );
  1965. return polyfill;
  1966. };
  1967. },{"./polyfill":52,"define-properties":46}],54:[function(_dereq_,module,exports){
  1968. module.exports = SafeParseTuple
  1969. function SafeParseTuple(obj, reviver) {
  1970. var json
  1971. var error = null
  1972. try {
  1973. json = JSON.parse(obj, reviver)
  1974. } catch (err) {
  1975. error = err
  1976. }
  1977. return [error, json]
  1978. }
  1979. },{}],55:[function(_dereq_,module,exports){
  1980. function clean (s) {
  1981. return s.replace(/\n\r?\s*/g, '')
  1982. }
  1983. module.exports = function tsml (sa) {
  1984. var s = ''
  1985. , i = 0
  1986. for (; i < arguments.length; i++)
  1987. s += clean(sa[i]) + (arguments[i + 1] || '')
  1988. return s
  1989. }
  1990. },{}],56:[function(_dereq_,module,exports){
  1991. "use strict";
  1992. var window = _dereq_("global/window")
  1993. var once = _dereq_("once")
  1994. var isFunction = _dereq_("is-function")
  1995. var parseHeaders = _dereq_("parse-headers")
  1996. var xtend = _dereq_("xtend")
  1997. module.exports = createXHR
  1998. createXHR.XMLHttpRequest = window.XMLHttpRequest || noop
  1999. createXHR.XDomainRequest = "withCredentials" in (new createXHR.XMLHttpRequest()) ? createXHR.XMLHttpRequest : window.XDomainRequest
  2000. forEachArray(["get", "put", "post", "patch", "head", "delete"], function(method) {
  2001. createXHR[method === "delete" ? "del" : method] = function(uri, options, callback) {
  2002. options = initParams(uri, options, callback)
  2003. options.method = method.toUpperCase()
  2004. return _createXHR(options)
  2005. }
  2006. })
  2007. function forEachArray(array, iterator) {
  2008. for (var i = 0; i < array.length; i++) {
  2009. iterator(array[i])
  2010. }
  2011. }
  2012. function isEmpty(obj){
  2013. for(var i in obj){
  2014. if(obj.hasOwnProperty(i)) return false
  2015. }
  2016. return true
  2017. }
  2018. function initParams(uri, options, callback) {
  2019. var params = uri
  2020. if (isFunction(options)) {
  2021. callback = options
  2022. if (typeof uri === "string") {
  2023. params = {uri:uri}
  2024. }
  2025. } else {
  2026. params = xtend(options, {uri: uri})
  2027. }
  2028. params.callback = callback
  2029. return params
  2030. }
  2031. function createXHR(uri, options, callback) {
  2032. options = initParams(uri, options, callback)
  2033. return _createXHR(options)
  2034. }
  2035. function _createXHR(options) {
  2036. var callback = options.callback
  2037. if(typeof callback === "undefined"){
  2038. throw new Error("callback argument missing")
  2039. }
  2040. callback = once(callback)
  2041. function readystatechange() {
  2042. if (xhr.readyState === 4) {
  2043. loadFunc()
  2044. }
  2045. }
  2046. function getBody() {
  2047. // Chrome with requestType=blob throws errors arround when even testing access to responseText
  2048. var body = undefined
  2049. if (xhr.response) {
  2050. body = xhr.response
  2051. } else if (xhr.responseType === "text" || !xhr.responseType) {
  2052. body = xhr.responseText || xhr.responseXML
  2053. }
  2054. if (isJson) {
  2055. try {
  2056. body = JSON.parse(body)
  2057. } catch (e) {}
  2058. }
  2059. return body
  2060. }
  2061. var failureResponse = {
  2062. body: undefined,
  2063. headers: {},
  2064. statusCode: 0,
  2065. method: method,
  2066. url: uri,
  2067. rawRequest: xhr
  2068. }
  2069. function errorFunc(evt) {
  2070. clearTimeout(timeoutTimer)
  2071. if(!(evt instanceof Error)){
  2072. evt = new Error("" + (evt || "Unknown XMLHttpRequest Error") )
  2073. }
  2074. evt.statusCode = 0
  2075. callback(evt, failureResponse)
  2076. }
  2077. // will load the data & process the response in a special response object
  2078. function loadFunc() {
  2079. if (aborted) return
  2080. var status
  2081. clearTimeout(timeoutTimer)
  2082. if(options.useXDR && xhr.status===undefined) {
  2083. //IE8 CORS GET successful response doesn't have a status field, but body is fine
  2084. status = 200
  2085. } else {
  2086. status = (xhr.status === 1223 ? 204 : xhr.status)
  2087. }
  2088. var response = failureResponse
  2089. var err = null
  2090. if (status !== 0){
  2091. response = {
  2092. body: getBody(),
  2093. statusCode: status,
  2094. method: method,
  2095. headers: {},
  2096. url: uri,
  2097. rawRequest: xhr
  2098. }
  2099. if(xhr.getAllResponseHeaders){ //remember xhr can in fact be XDR for CORS in IE
  2100. response.headers = parseHeaders(xhr.getAllResponseHeaders())
  2101. }
  2102. } else {
  2103. err = new Error("Internal XMLHttpRequest Error")
  2104. }
  2105. callback(err, response, response.body)
  2106. }
  2107. var xhr = options.xhr || null
  2108. if (!xhr) {
  2109. if (options.cors || options.useXDR) {
  2110. xhr = new createXHR.XDomainRequest()
  2111. }else{
  2112. xhr = new createXHR.XMLHttpRequest()
  2113. }
  2114. }
  2115. var key
  2116. var aborted
  2117. var uri = xhr.url = options.uri || options.url
  2118. var method = xhr.method = options.method || "GET"
  2119. var body = options.body || options.data || null
  2120. var headers = xhr.headers = options.headers || {}
  2121. var sync = !!options.sync
  2122. var isJson = false
  2123. var timeoutTimer
  2124. if ("json" in options) {
  2125. isJson = true
  2126. headers["accept"] || headers["Accept"] || (headers["Accept"] = "application/json") //Don't override existing accept header declared by user
  2127. if (method !== "GET" && method !== "HEAD") {
  2128. headers["content-type"] || headers["Content-Type"] || (headers["Content-Type"] = "application/json") //Don't override existing accept header declared by user
  2129. body = JSON.stringify(options.json)
  2130. }
  2131. }
  2132. xhr.onreadystatechange = readystatechange
  2133. xhr.onload = loadFunc
  2134. xhr.onerror = errorFunc
  2135. // IE9 must have onprogress be set to a unique function.
  2136. xhr.onprogress = function () {
  2137. // IE must die
  2138. }
  2139. xhr.ontimeout = errorFunc
  2140. xhr.open(method, uri, !sync, options.username, options.password)
  2141. //has to be after open
  2142. if(!sync) {
  2143. xhr.withCredentials = !!options.withCredentials
  2144. }
  2145. // Cannot set timeout with sync request
  2146. // not setting timeout on the xhr object, because of old webkits etc. not handling that correctly
  2147. // both npm's request and jquery 1.x use this kind of timeout, so this is being consistent
  2148. if (!sync && options.timeout > 0 ) {
  2149. timeoutTimer = setTimeout(function(){
  2150. aborted=true//IE9 may still call readystatechange
  2151. xhr.abort("timeout")
  2152. var e = new Error("XMLHttpRequest timeout")
  2153. e.code = "ETIMEDOUT"
  2154. errorFunc(e)
  2155. }, options.timeout )
  2156. }
  2157. if (xhr.setRequestHeader) {
  2158. for(key in headers){
  2159. if(headers.hasOwnProperty(key)){
  2160. xhr.setRequestHeader(key, headers[key])
  2161. }
  2162. }
  2163. } else if (options.headers && !isEmpty(options.headers)) {
  2164. throw new Error("Headers cannot be set on an XDomainRequest object")
  2165. }
  2166. if ("responseType" in options) {
  2167. xhr.responseType = options.responseType
  2168. }
  2169. if ("beforeSend" in options &&
  2170. typeof options.beforeSend === "function"
  2171. ) {
  2172. options.beforeSend(xhr)
  2173. }
  2174. xhr.send(body)
  2175. return xhr
  2176. }
  2177. function noop() {}
  2178. },{"global/window":2,"is-function":57,"once":58,"parse-headers":61,"xtend":62}],57:[function(_dereq_,module,exports){
  2179. module.exports = isFunction
  2180. var toString = Object.prototype.toString
  2181. function isFunction (fn) {
  2182. var string = toString.call(fn)
  2183. return string === '[object Function]' ||
  2184. (typeof fn === 'function' && string !== '[object RegExp]') ||
  2185. (typeof window !== 'undefined' &&
  2186. // IE8 and below
  2187. (fn === window.setTimeout ||
  2188. fn === window.alert ||
  2189. fn === window.confirm ||
  2190. fn === window.prompt))
  2191. };
  2192. },{}],58:[function(_dereq_,module,exports){
  2193. module.exports = once
  2194. once.proto = once(function () {
  2195. Object.defineProperty(Function.prototype, 'once', {
  2196. value: function () {
  2197. return once(this)
  2198. },
  2199. configurable: true
  2200. })
  2201. })
  2202. function once (fn) {
  2203. var called = false
  2204. return function () {
  2205. if (called) return
  2206. called = true
  2207. return fn.apply(this, arguments)
  2208. }
  2209. }
  2210. },{}],59:[function(_dereq_,module,exports){
  2211. var isFunction = _dereq_('is-function')
  2212. module.exports = forEach
  2213. var toString = Object.prototype.toString
  2214. var hasOwnProperty = Object.prototype.hasOwnProperty
  2215. function forEach(list, iterator, context) {
  2216. if (!isFunction(iterator)) {
  2217. throw new TypeError('iterator must be a function')
  2218. }
  2219. if (arguments.length < 3) {
  2220. context = this
  2221. }
  2222. if (toString.call(list) === '[object Array]')
  2223. forEachArray(list, iterator, context)
  2224. else if (typeof list === 'string')
  2225. forEachString(list, iterator, context)
  2226. else
  2227. forEachObject(list, iterator, context)
  2228. }
  2229. function forEachArray(array, iterator, context) {
  2230. for (var i = 0, len = array.length; i < len; i++) {
  2231. if (hasOwnProperty.call(array, i)) {
  2232. iterator.call(context, array[i], i, array)
  2233. }
  2234. }
  2235. }
  2236. function forEachString(string, iterator, context) {
  2237. for (var i = 0, len = string.length; i < len; i++) {
  2238. // no such thing as a sparse string.
  2239. iterator.call(context, string.charAt(i), i, string)
  2240. }
  2241. }
  2242. function forEachObject(object, iterator, context) {
  2243. for (var k in object) {
  2244. if (hasOwnProperty.call(object, k)) {
  2245. iterator.call(context, object[k], k, object)
  2246. }
  2247. }
  2248. }
  2249. },{"is-function":57}],60:[function(_dereq_,module,exports){
  2250. exports = module.exports = trim;
  2251. function trim(str){
  2252. return str.replace(/^\s*|\s*$/g, '');
  2253. }
  2254. exports.left = function(str){
  2255. return str.replace(/^\s*/, '');
  2256. };
  2257. exports.right = function(str){
  2258. return str.replace(/\s*$/, '');
  2259. };
  2260. },{}],61:[function(_dereq_,module,exports){
  2261. var trim = _dereq_('trim')
  2262. , forEach = _dereq_('for-each')
  2263. , isArray = function(arg) {
  2264. return Object.prototype.toString.call(arg) === '[object Array]';
  2265. }
  2266. module.exports = function (headers) {
  2267. if (!headers)
  2268. return {}
  2269. var result = {}
  2270. forEach(
  2271. trim(headers).split('\n')
  2272. , function (row) {
  2273. var index = row.indexOf(':')
  2274. , key = trim(row.slice(0, index)).toLowerCase()
  2275. , value = trim(row.slice(index + 1))
  2276. if (typeof(result[key]) === 'undefined') {
  2277. result[key] = value
  2278. } else if (isArray(result[key])) {
  2279. result[key].push(value)
  2280. } else {
  2281. result[key] = [ result[key], value ]
  2282. }
  2283. }
  2284. )
  2285. return result
  2286. }
  2287. },{"for-each":59,"trim":60}],62:[function(_dereq_,module,exports){
  2288. module.exports = extend
  2289. var hasOwnProperty = Object.prototype.hasOwnProperty;
  2290. function extend() {
  2291. var target = {}
  2292. for (var i = 0; i < arguments.length; i++) {
  2293. var source = arguments[i]
  2294. for (var key in source) {
  2295. if (hasOwnProperty.call(source, key)) {
  2296. target[key] = source[key]
  2297. }
  2298. }
  2299. }
  2300. return target
  2301. }
  2302. },{}],63:[function(_dereq_,module,exports){
  2303. /**
  2304. * @file big-play-button.js
  2305. */
  2306. 'use strict';
  2307. exports.__esModule = true;
  2308. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  2309. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  2310. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  2311. var _buttonJs = _dereq_('./button.js');
  2312. var _buttonJs2 = _interopRequireDefault(_buttonJs);
  2313. var _componentJs = _dereq_('./component.js');
  2314. var _componentJs2 = _interopRequireDefault(_componentJs);
  2315. /**
  2316. * Initial play button. Shows before the video has played. The hiding of the
  2317. * big play button is done via CSS and player states.
  2318. *
  2319. * @param {Object} player Main Player
  2320. * @param {Object=} options Object of option names and values
  2321. * @extends Button
  2322. * @class BigPlayButton
  2323. */
  2324. var BigPlayButton = (function (_Button) {
  2325. _inherits(BigPlayButton, _Button);
  2326. function BigPlayButton(player, options) {
  2327. _classCallCheck(this, BigPlayButton);
  2328. _Button.call(this, player, options);
  2329. }
  2330. /**
  2331. * Allow sub components to stack CSS class names
  2332. *
  2333. * @return {String} The constructed class name
  2334. * @method buildCSSClass
  2335. */
  2336. BigPlayButton.prototype.buildCSSClass = function buildCSSClass() {
  2337. return 'vjs-big-play-button';
  2338. };
  2339. /**
  2340. * Handles click for play
  2341. *
  2342. * @method handleClick
  2343. */
  2344. BigPlayButton.prototype.handleClick = function handleClick() {
  2345. this.player_.play();
  2346. };
  2347. return BigPlayButton;
  2348. })(_buttonJs2['default']);
  2349. BigPlayButton.prototype.controlText_ = 'Play Video';
  2350. _componentJs2['default'].registerComponent('BigPlayButton', BigPlayButton);
  2351. exports['default'] = BigPlayButton;
  2352. module.exports = exports['default'];
  2353. },{"./button.js":64,"./component.js":67}],64:[function(_dereq_,module,exports){
  2354. /**
  2355. * @file button.js
  2356. */
  2357. 'use strict';
  2358. exports.__esModule = true;
  2359. 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; } }
  2360. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  2361. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  2362. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  2363. var _clickableComponentJs = _dereq_('./clickable-component.js');
  2364. var _clickableComponentJs2 = _interopRequireDefault(_clickableComponentJs);
  2365. var _component = _dereq_('./component');
  2366. var _component2 = _interopRequireDefault(_component);
  2367. var _utilsEventsJs = _dereq_('./utils/events.js');
  2368. var Events = _interopRequireWildcard(_utilsEventsJs);
  2369. var _utilsFnJs = _dereq_('./utils/fn.js');
  2370. var Fn = _interopRequireWildcard(_utilsFnJs);
  2371. var _utilsLogJs = _dereq_('./utils/log.js');
  2372. var _utilsLogJs2 = _interopRequireDefault(_utilsLogJs);
  2373. var _globalDocument = _dereq_('global/document');
  2374. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  2375. var _objectAssign = _dereq_('object.assign');
  2376. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  2377. /**
  2378. * Base class for all buttons
  2379. *
  2380. * @param {Object} player Main Player
  2381. * @param {Object=} options Object of option names and values
  2382. * @extends ClickableComponent
  2383. * @class Button
  2384. */
  2385. var Button = (function (_ClickableComponent) {
  2386. _inherits(Button, _ClickableComponent);
  2387. function Button(player, options) {
  2388. _classCallCheck(this, Button);
  2389. _ClickableComponent.call(this, player, options);
  2390. }
  2391. /**
  2392. * Create the component's DOM element
  2393. *
  2394. * @param {String=} type Element's node type. e.g. 'div'
  2395. * @param {Object=} props An object of properties that should be set on the element
  2396. * @param {Object=} attributes An object of attributes that should be set on the element
  2397. * @return {Element}
  2398. * @method createEl
  2399. */
  2400. Button.prototype.createEl = function createEl() {
  2401. var tag = arguments.length <= 0 || arguments[0] === undefined ? 'button' : arguments[0];
  2402. var props = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  2403. var attributes = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  2404. props = _objectAssign2['default']({
  2405. className: this.buildCSSClass()
  2406. }, props);
  2407. if (tag !== 'button') {
  2408. _utilsLogJs2['default'].warn('Creating a Button with an HTML element of ' + tag + ' is deprecated; use ClickableComponent instead.');
  2409. }
  2410. // Add attributes for button element
  2411. attributes = _objectAssign2['default']({
  2412. type: 'button', // Necessary since the default button type is "submit"
  2413. 'aria-live': 'polite' // let the screen reader user know that the text of the button may change
  2414. }, attributes);
  2415. var el = _component2['default'].prototype.createEl.call(this, tag, props, attributes);
  2416. this.createControlTextEl(el);
  2417. return el;
  2418. };
  2419. /**
  2420. * Adds a child component inside this button
  2421. *
  2422. * @param {String|Component} child The class name or instance of a child to add
  2423. * @param {Object=} options Options, including options to be passed to children of the child.
  2424. * @return {Component} The child component (created by this process if a string was used)
  2425. * @deprecated
  2426. * @method addChild
  2427. */
  2428. Button.prototype.addChild = function addChild(child) {
  2429. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  2430. var className = this.constructor.name;
  2431. _utilsLogJs2['default'].warn('Adding an actionable (user controllable) child to a Button (' + className + ') is not supported; use a ClickableComponent instead.');
  2432. // Avoid the error message generated by ClickableComponent's addChild method
  2433. return _component2['default'].prototype.addChild.call(this, child, options);
  2434. };
  2435. /**
  2436. * Handle KeyPress (document level) - Extend with specific functionality for button
  2437. *
  2438. * @method handleKeyPress
  2439. */
  2440. Button.prototype.handleKeyPress = function handleKeyPress(event) {
  2441. // Ignore Space (32) or Enter (13) key operation, which is handled by the browser for a button.
  2442. if (event.which === 32 || event.which === 13) {} else {
  2443. _ClickableComponent.prototype.handleKeyPress.call(this, event); // Pass keypress handling up for unsupported keys
  2444. }
  2445. };
  2446. return Button;
  2447. })(_clickableComponentJs2['default']);
  2448. _component2['default'].registerComponent('Button', Button);
  2449. exports['default'] = Button;
  2450. module.exports = exports['default'];
  2451. },{"./clickable-component.js":65,"./component":67,"./utils/events.js":133,"./utils/fn.js":134,"./utils/log.js":137,"global/document":1,"object.assign":45}],65:[function(_dereq_,module,exports){
  2452. /**
  2453. * @file button.js
  2454. */
  2455. 'use strict';
  2456. exports.__esModule = true;
  2457. 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; } }
  2458. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  2459. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  2460. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  2461. var _component = _dereq_('./component');
  2462. var _component2 = _interopRequireDefault(_component);
  2463. var _utilsDomJs = _dereq_('./utils/dom.js');
  2464. var Dom = _interopRequireWildcard(_utilsDomJs);
  2465. var _utilsEventsJs = _dereq_('./utils/events.js');
  2466. var Events = _interopRequireWildcard(_utilsEventsJs);
  2467. var _utilsFnJs = _dereq_('./utils/fn.js');
  2468. var Fn = _interopRequireWildcard(_utilsFnJs);
  2469. var _utilsLogJs = _dereq_('./utils/log.js');
  2470. var _utilsLogJs2 = _interopRequireDefault(_utilsLogJs);
  2471. var _globalDocument = _dereq_('global/document');
  2472. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  2473. var _objectAssign = _dereq_('object.assign');
  2474. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  2475. /**
  2476. * Clickable Component which is clickable or keyboard actionable, but is not a native HTML button
  2477. *
  2478. * @param {Object} player Main Player
  2479. * @param {Object=} options Object of option names and values
  2480. * @extends Component
  2481. * @class ClickableComponent
  2482. */
  2483. var ClickableComponent = (function (_Component) {
  2484. _inherits(ClickableComponent, _Component);
  2485. function ClickableComponent(player, options) {
  2486. _classCallCheck(this, ClickableComponent);
  2487. _Component.call(this, player, options);
  2488. this.emitTapEvents();
  2489. this.on('tap', this.handleClick);
  2490. this.on('click', this.handleClick);
  2491. this.on('focus', this.handleFocus);
  2492. this.on('blur', this.handleBlur);
  2493. }
  2494. /**
  2495. * Create the component's DOM element
  2496. *
  2497. * @param {String=} type Element's node type. e.g. 'div'
  2498. * @param {Object=} props An object of properties that should be set on the element
  2499. * @param {Object=} attributes An object of attributes that should be set on the element
  2500. * @return {Element}
  2501. * @method createEl
  2502. */
  2503. ClickableComponent.prototype.createEl = function createEl() {
  2504. var tag = arguments.length <= 0 || arguments[0] === undefined ? 'div' : arguments[0];
  2505. var props = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  2506. var attributes = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  2507. props = _objectAssign2['default']({
  2508. className: this.buildCSSClass(),
  2509. tabIndex: 0
  2510. }, props);
  2511. if (tag === 'button') {
  2512. _utilsLogJs2['default'].error('Creating a ClickableComponent with an HTML element of ' + tag + ' is not supported; use a Button instead.');
  2513. }
  2514. // Add ARIA attributes for clickable element which is not a native HTML button
  2515. attributes = _objectAssign2['default']({
  2516. role: 'button',
  2517. 'aria-live': 'polite' // let the screen reader user know that the text of the element may change
  2518. }, attributes);
  2519. var el = _Component.prototype.createEl.call(this, tag, props, attributes);
  2520. this.createControlTextEl(el);
  2521. return el;
  2522. };
  2523. /**
  2524. * create control text
  2525. *
  2526. * @param {Element} el Parent element for the control text
  2527. * @return {Element}
  2528. * @method controlText
  2529. */
  2530. ClickableComponent.prototype.createControlTextEl = function createControlTextEl(el) {
  2531. this.controlTextEl_ = Dom.createEl('span', {
  2532. className: 'vjs-control-text'
  2533. });
  2534. if (el) {
  2535. el.appendChild(this.controlTextEl_);
  2536. }
  2537. this.controlText(this.controlText_);
  2538. return this.controlTextEl_;
  2539. };
  2540. /**
  2541. * Controls text - both request and localize
  2542. *
  2543. * @param {String} text Text for element
  2544. * @return {String}
  2545. * @method controlText
  2546. */
  2547. ClickableComponent.prototype.controlText = function controlText(text) {
  2548. if (!text) return this.controlText_ || 'Need Text';
  2549. this.controlText_ = text;
  2550. this.controlTextEl_.innerHTML = this.localize(this.controlText_);
  2551. return this;
  2552. };
  2553. /**
  2554. * Allows sub components to stack CSS class names
  2555. *
  2556. * @return {String}
  2557. * @method buildCSSClass
  2558. */
  2559. ClickableComponent.prototype.buildCSSClass = function buildCSSClass() {
  2560. return 'vjs-control vjs-button ' + _Component.prototype.buildCSSClass.call(this);
  2561. };
  2562. /**
  2563. * Adds a child component inside this clickable-component
  2564. *
  2565. * @param {String|Component} child The class name or instance of a child to add
  2566. * @param {Object=} options Options, including options to be passed to children of the child.
  2567. * @return {Component} The child component (created by this process if a string was used)
  2568. * @method addChild
  2569. */
  2570. ClickableComponent.prototype.addChild = function addChild(child) {
  2571. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  2572. // TODO: Fix adding an actionable child to a ClickableComponent; currently
  2573. // it will cause issues with assistive technology (e.g. screen readers)
  2574. // which support ARIA, since an element with role="button" cannot have
  2575. // actionable child elements.
  2576. //let className = this.constructor.name;
  2577. //log.warn(`Adding a child to a ClickableComponent (${className}) can cause issues with assistive technology which supports ARIA, since an element with role="button" cannot have actionable child elements.`);
  2578. return _Component.prototype.addChild.call(this, child, options);
  2579. };
  2580. /**
  2581. * Handle Click - Override with specific functionality for component
  2582. *
  2583. * @method handleClick
  2584. */
  2585. ClickableComponent.prototype.handleClick = function handleClick() {};
  2586. /**
  2587. * Handle Focus - Add keyboard functionality to element
  2588. *
  2589. * @method handleFocus
  2590. */
  2591. ClickableComponent.prototype.handleFocus = function handleFocus() {
  2592. Events.on(_globalDocument2['default'], 'keydown', Fn.bind(this, this.handleKeyPress));
  2593. };
  2594. /**
  2595. * Handle KeyPress (document level) - Trigger click when Space or Enter key is pressed
  2596. *
  2597. * @method handleKeyPress
  2598. */
  2599. ClickableComponent.prototype.handleKeyPress = function handleKeyPress(event) {
  2600. // Support Space (32) or Enter (13) key operation to fire a click event
  2601. if (event.which === 32 || event.which === 13) {
  2602. event.preventDefault();
  2603. this.handleClick(event);
  2604. } else if (_Component.prototype.handleKeyPress) {
  2605. _Component.prototype.handleKeyPress.call(this, event); // Pass keypress handling up for unsupported keys
  2606. }
  2607. };
  2608. /**
  2609. * Handle Blur - Remove keyboard triggers
  2610. *
  2611. * @method handleBlur
  2612. */
  2613. ClickableComponent.prototype.handleBlur = function handleBlur() {
  2614. Events.off(_globalDocument2['default'], 'keydown', Fn.bind(this, this.handleKeyPress));
  2615. };
  2616. return ClickableComponent;
  2617. })(_component2['default']);
  2618. _component2['default'].registerComponent('ClickableComponent', ClickableComponent);
  2619. exports['default'] = ClickableComponent;
  2620. module.exports = exports['default'];
  2621. },{"./component":67,"./utils/dom.js":132,"./utils/events.js":133,"./utils/fn.js":134,"./utils/log.js":137,"global/document":1,"object.assign":45}],66:[function(_dereq_,module,exports){
  2622. 'use strict';
  2623. exports.__esModule = true;
  2624. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  2625. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  2626. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  2627. var _button = _dereq_('./button');
  2628. var _button2 = _interopRequireDefault(_button);
  2629. var _component = _dereq_('./component');
  2630. var _component2 = _interopRequireDefault(_component);
  2631. /**
  2632. * The `CloseButton` component is a button which fires a "close" event
  2633. * when it is activated.
  2634. *
  2635. * @extends Button
  2636. * @class CloseButton
  2637. */
  2638. var CloseButton = (function (_Button) {
  2639. _inherits(CloseButton, _Button);
  2640. function CloseButton(player, options) {
  2641. _classCallCheck(this, CloseButton);
  2642. _Button.call(this, player, options);
  2643. this.controlText(options && options.controlText || this.localize('Close'));
  2644. }
  2645. CloseButton.prototype.buildCSSClass = function buildCSSClass() {
  2646. return 'vjs-close-button ' + _Button.prototype.buildCSSClass.call(this);
  2647. };
  2648. CloseButton.prototype.handleClick = function handleClick() {
  2649. this.trigger({ type: 'close', bubbles: false });
  2650. };
  2651. return CloseButton;
  2652. })(_button2['default']);
  2653. _component2['default'].registerComponent('CloseButton', CloseButton);
  2654. exports['default'] = CloseButton;
  2655. module.exports = exports['default'];
  2656. },{"./button":64,"./component":67}],67:[function(_dereq_,module,exports){
  2657. /**
  2658. * @file component.js
  2659. *
  2660. * Player Component - Base class for all UI objects
  2661. */
  2662. 'use strict';
  2663. exports.__esModule = true;
  2664. 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; } }
  2665. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  2666. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  2667. var _globalWindow = _dereq_('global/window');
  2668. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  2669. var _utilsDomJs = _dereq_('./utils/dom.js');
  2670. var Dom = _interopRequireWildcard(_utilsDomJs);
  2671. var _utilsFnJs = _dereq_('./utils/fn.js');
  2672. var Fn = _interopRequireWildcard(_utilsFnJs);
  2673. var _utilsGuidJs = _dereq_('./utils/guid.js');
  2674. var Guid = _interopRequireWildcard(_utilsGuidJs);
  2675. var _utilsEventsJs = _dereq_('./utils/events.js');
  2676. var Events = _interopRequireWildcard(_utilsEventsJs);
  2677. var _utilsLogJs = _dereq_('./utils/log.js');
  2678. var _utilsLogJs2 = _interopRequireDefault(_utilsLogJs);
  2679. var _utilsToTitleCaseJs = _dereq_('./utils/to-title-case.js');
  2680. var _utilsToTitleCaseJs2 = _interopRequireDefault(_utilsToTitleCaseJs);
  2681. var _objectAssign = _dereq_('object.assign');
  2682. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  2683. var _utilsMergeOptionsJs = _dereq_('./utils/merge-options.js');
  2684. var _utilsMergeOptionsJs2 = _interopRequireDefault(_utilsMergeOptionsJs);
  2685. /**
  2686. * Base UI Component class
  2687. * Components are embeddable UI objects that are represented by both a
  2688. * javascript object and an element in the DOM. They can be children of other
  2689. * components, and can have many children themselves.
  2690. * ```js
  2691. * // adding a button to the player
  2692. * var button = player.addChild('button');
  2693. * button.el(); // -> button element
  2694. * ```
  2695. * ```html
  2696. * <div class="video-js">
  2697. * <div class="vjs-button">Button</div>
  2698. * </div>
  2699. * ```
  2700. * Components are also event targets.
  2701. * ```js
  2702. * button.on('click', function(){
  2703. * console.log('Button Clicked!');
  2704. * });
  2705. * button.trigger('customevent');
  2706. * ```
  2707. *
  2708. * @param {Object} player Main Player
  2709. * @param {Object=} options Object of option names and values
  2710. * @param {Function=} ready Ready callback function
  2711. * @class Component
  2712. */
  2713. var Component = (function () {
  2714. function Component(player, options, ready) {
  2715. _classCallCheck(this, Component);
  2716. // The component might be the player itself and we can't pass `this` to super
  2717. if (!player && this.play) {
  2718. this.player_ = player = this; // eslint-disable-line
  2719. } else {
  2720. this.player_ = player;
  2721. }
  2722. // Make a copy of prototype.options_ to protect against overriding defaults
  2723. this.options_ = _utilsMergeOptionsJs2['default']({}, this.options_);
  2724. // Updated options with supplied options
  2725. options = this.options_ = _utilsMergeOptionsJs2['default'](this.options_, options);
  2726. // Get ID from options or options element if one is supplied
  2727. this.id_ = options.id || options.el && options.el.id;
  2728. // If there was no ID from the options, generate one
  2729. if (!this.id_) {
  2730. // Don't require the player ID function in the case of mock players
  2731. var id = player && player.id && player.id() || 'no_player';
  2732. this.id_ = id + '_component_' + Guid.newGUID();
  2733. }
  2734. this.name_ = options.name || null;
  2735. // Create element if one wasn't provided in options
  2736. if (options.el) {
  2737. this.el_ = options.el;
  2738. } else if (options.createEl !== false) {
  2739. this.el_ = this.createEl();
  2740. }
  2741. this.children_ = [];
  2742. this.childIndex_ = {};
  2743. this.childNameIndex_ = {};
  2744. // Add any child components in options
  2745. if (options.initChildren !== false) {
  2746. this.initChildren();
  2747. }
  2748. this.ready(ready);
  2749. // Don't want to trigger ready here or it will before init is actually
  2750. // finished for all children that run this constructor
  2751. if (options.reportTouchActivity !== false) {
  2752. this.enableTouchActivity();
  2753. }
  2754. }
  2755. /**
  2756. * Dispose of the component and all child components
  2757. *
  2758. * @method dispose
  2759. */
  2760. Component.prototype.dispose = function dispose() {
  2761. this.trigger({ type: 'dispose', bubbles: false });
  2762. // Dispose all children.
  2763. if (this.children_) {
  2764. for (var i = this.children_.length - 1; i >= 0; i--) {
  2765. if (this.children_[i].dispose) {
  2766. this.children_[i].dispose();
  2767. }
  2768. }
  2769. }
  2770. // Delete child references
  2771. this.children_ = null;
  2772. this.childIndex_ = null;
  2773. this.childNameIndex_ = null;
  2774. // Remove all event listeners.
  2775. this.off();
  2776. // Remove element from DOM
  2777. if (this.el_.parentNode) {
  2778. this.el_.parentNode.removeChild(this.el_);
  2779. }
  2780. Dom.removeElData(this.el_);
  2781. this.el_ = null;
  2782. };
  2783. /**
  2784. * Return the component's player
  2785. *
  2786. * @return {Player}
  2787. * @method player
  2788. */
  2789. Component.prototype.player = function player() {
  2790. return this.player_;
  2791. };
  2792. /**
  2793. * Deep merge of options objects
  2794. * Whenever a property is an object on both options objects
  2795. * the two properties will be merged using mergeOptions.
  2796. *
  2797. * ```js
  2798. * Parent.prototype.options_ = {
  2799. * optionSet: {
  2800. * 'childOne': { 'foo': 'bar', 'asdf': 'fdsa' },
  2801. * 'childTwo': {},
  2802. * 'childThree': {}
  2803. * }
  2804. * }
  2805. * newOptions = {
  2806. * optionSet: {
  2807. * 'childOne': { 'foo': 'baz', 'abc': '123' }
  2808. * 'childTwo': null,
  2809. * 'childFour': {}
  2810. * }
  2811. * }
  2812. *
  2813. * this.options(newOptions);
  2814. * ```
  2815. * RESULT
  2816. * ```js
  2817. * {
  2818. * optionSet: {
  2819. * 'childOne': { 'foo': 'baz', 'asdf': 'fdsa', 'abc': '123' },
  2820. * 'childTwo': null, // Disabled. Won't be initialized.
  2821. * 'childThree': {},
  2822. * 'childFour': {}
  2823. * }
  2824. * }
  2825. * ```
  2826. *
  2827. * @param {Object} obj Object of new option values
  2828. * @return {Object} A NEW object of this.options_ and obj merged
  2829. * @method options
  2830. */
  2831. Component.prototype.options = function options(obj) {
  2832. _utilsLogJs2['default'].warn('this.options() has been deprecated and will be moved to the constructor in 6.0');
  2833. if (!obj) {
  2834. return this.options_;
  2835. }
  2836. this.options_ = _utilsMergeOptionsJs2['default'](this.options_, obj);
  2837. return this.options_;
  2838. };
  2839. /**
  2840. * Get the component's DOM element
  2841. * ```js
  2842. * var domEl = myComponent.el();
  2843. * ```
  2844. *
  2845. * @return {Element}
  2846. * @method el
  2847. */
  2848. Component.prototype.el = function el() {
  2849. return this.el_;
  2850. };
  2851. /**
  2852. * Create the component's DOM element
  2853. *
  2854. * @param {String=} tagName Element's node type. e.g. 'div'
  2855. * @param {Object=} properties An object of properties that should be set
  2856. * @param {Object=} attributes An object of attributes that should be set
  2857. * @return {Element}
  2858. * @method createEl
  2859. */
  2860. Component.prototype.createEl = function createEl(tagName, properties, attributes) {
  2861. return Dom.createEl(tagName, properties, attributes);
  2862. };
  2863. Component.prototype.localize = function localize(string) {
  2864. var code = this.player_.language && this.player_.language();
  2865. var languages = this.player_.languages && this.player_.languages();
  2866. if (!code || !languages) {
  2867. return string;
  2868. }
  2869. var language = languages[code];
  2870. if (language && language[string]) {
  2871. return language[string];
  2872. }
  2873. var primaryCode = code.split('-')[0];
  2874. var primaryLang = languages[primaryCode];
  2875. if (primaryLang && primaryLang[string]) {
  2876. return primaryLang[string];
  2877. }
  2878. return string;
  2879. };
  2880. /**
  2881. * Return the component's DOM element where children are inserted.
  2882. * Will either be the same as el() or a new element defined in createEl().
  2883. *
  2884. * @return {Element}
  2885. * @method contentEl
  2886. */
  2887. Component.prototype.contentEl = function contentEl() {
  2888. return this.contentEl_ || this.el_;
  2889. };
  2890. /**
  2891. * Get the component's ID
  2892. * ```js
  2893. * var id = myComponent.id();
  2894. * ```
  2895. *
  2896. * @return {String}
  2897. * @method id
  2898. */
  2899. Component.prototype.id = function id() {
  2900. return this.id_;
  2901. };
  2902. /**
  2903. * Get the component's name. The name is often used to reference the component.
  2904. * ```js
  2905. * var name = myComponent.name();
  2906. * ```
  2907. *
  2908. * @return {String}
  2909. * @method name
  2910. */
  2911. Component.prototype.name = function name() {
  2912. return this.name_;
  2913. };
  2914. /**
  2915. * Get an array of all child components
  2916. * ```js
  2917. * var kids = myComponent.children();
  2918. * ```
  2919. *
  2920. * @return {Array} The children
  2921. * @method children
  2922. */
  2923. Component.prototype.children = function children() {
  2924. return this.children_;
  2925. };
  2926. /**
  2927. * Returns a child component with the provided ID
  2928. *
  2929. * @return {Component}
  2930. * @method getChildById
  2931. */
  2932. Component.prototype.getChildById = function getChildById(id) {
  2933. return this.childIndex_[id];
  2934. };
  2935. /**
  2936. * Returns a child component with the provided name
  2937. *
  2938. * @return {Component}
  2939. * @method getChild
  2940. */
  2941. Component.prototype.getChild = function getChild(name) {
  2942. return this.childNameIndex_[name];
  2943. };
  2944. /**
  2945. * Adds a child component inside this component
  2946. * ```js
  2947. * myComponent.el();
  2948. * // -> <div class='my-component'></div>
  2949. * myComponent.children();
  2950. * // [empty array]
  2951. *
  2952. * var myButton = myComponent.addChild('MyButton');
  2953. * // -> <div class='my-component'><div class="my-button">myButton<div></div>
  2954. * // -> myButton === myComponent.children()[0];
  2955. * ```
  2956. * Pass in options for child constructors and options for children of the child
  2957. * ```js
  2958. * var myButton = myComponent.addChild('MyButton', {
  2959. * text: 'Press Me',
  2960. * buttonChildExample: {
  2961. * buttonChildOption: true
  2962. * }
  2963. * });
  2964. * ```
  2965. *
  2966. * @param {String|Component} child The class name or instance of a child to add
  2967. * @param {Object=} options Options, including options to be passed to children of the child.
  2968. * @param {Number} index into our children array to attempt to add the child
  2969. * @return {Component} The child component (created by this process if a string was used)
  2970. * @method addChild
  2971. */
  2972. Component.prototype.addChild = function addChild(child) {
  2973. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  2974. var index = arguments.length <= 2 || arguments[2] === undefined ? this.children_.length : arguments[2];
  2975. var component = undefined;
  2976. var componentName = undefined;
  2977. // If child is a string, create nt with options
  2978. if (typeof child === 'string') {
  2979. componentName = child;
  2980. // Options can also be specified as a boolean, so convert to an empty object if false.
  2981. if (!options) {
  2982. options = {};
  2983. }
  2984. // Same as above, but true is deprecated so show a warning.
  2985. if (options === true) {
  2986. _utilsLogJs2['default'].warn('Initializing a child component with `true` is deprecated. Children should be defined in an array when possible, but if necessary use an object instead of `true`.');
  2987. options = {};
  2988. }
  2989. // If no componentClass in options, assume componentClass is the name lowercased
  2990. // (e.g. playButton)
  2991. var componentClassName = options.componentClass || _utilsToTitleCaseJs2['default'](componentName);
  2992. // Set name through options
  2993. options.name = componentName;
  2994. // Create a new object & element for this controls set
  2995. // If there's no .player_, this is a player
  2996. var ComponentClass = Component.getComponent(componentClassName);
  2997. if (!ComponentClass) {
  2998. throw new Error('Component ' + componentClassName + ' does not exist');
  2999. }
  3000. // data stored directly on the videojs object may be
  3001. // misidentified as a component to retain
  3002. // backwards-compatibility with 4.x. check to make sure the
  3003. // component class can be instantiated.
  3004. if (typeof ComponentClass !== 'function') {
  3005. return null;
  3006. }
  3007. component = new ComponentClass(this.player_ || this, options);
  3008. // child is a component instance
  3009. } else {
  3010. component = child;
  3011. }
  3012. this.children_.splice(index, 0, component);
  3013. if (typeof component.id === 'function') {
  3014. this.childIndex_[component.id()] = component;
  3015. }
  3016. // If a name wasn't used to create the component, check if we can use the
  3017. // name function of the component
  3018. componentName = componentName || component.name && component.name();
  3019. if (componentName) {
  3020. this.childNameIndex_[componentName] = component;
  3021. }
  3022. // Add the UI object's element to the container div (box)
  3023. // Having an element is not required
  3024. if (typeof component.el === 'function' && component.el()) {
  3025. var childNodes = this.contentEl().children;
  3026. var refNode = childNodes[index] || null;
  3027. this.contentEl().insertBefore(component.el(), refNode);
  3028. }
  3029. // Return so it can stored on parent object if desired.
  3030. return component;
  3031. };
  3032. /**
  3033. * Remove a child component from this component's list of children, and the
  3034. * child component's element from this component's element
  3035. *
  3036. * @param {Component} component Component to remove
  3037. * @method removeChild
  3038. */
  3039. Component.prototype.removeChild = function removeChild(component) {
  3040. if (typeof component === 'string') {
  3041. component = this.getChild(component);
  3042. }
  3043. if (!component || !this.children_) {
  3044. return;
  3045. }
  3046. var childFound = false;
  3047. for (var i = this.children_.length - 1; i >= 0; i--) {
  3048. if (this.children_[i] === component) {
  3049. childFound = true;
  3050. this.children_.splice(i, 1);
  3051. break;
  3052. }
  3053. }
  3054. if (!childFound) {
  3055. return;
  3056. }
  3057. this.childIndex_[component.id()] = null;
  3058. this.childNameIndex_[component.name()] = null;
  3059. var compEl = component.el();
  3060. if (compEl && compEl.parentNode === this.contentEl()) {
  3061. this.contentEl().removeChild(component.el());
  3062. }
  3063. };
  3064. /**
  3065. * Add and initialize default child components from options
  3066. * ```js
  3067. * // when an instance of MyComponent is created, all children in options
  3068. * // will be added to the instance by their name strings and options
  3069. * MyComponent.prototype.options_ = {
  3070. * children: [
  3071. * 'myChildComponent'
  3072. * ],
  3073. * myChildComponent: {
  3074. * myChildOption: true
  3075. * }
  3076. * };
  3077. *
  3078. * // Or when creating the component
  3079. * var myComp = new MyComponent(player, {
  3080. * children: [
  3081. * 'myChildComponent'
  3082. * ],
  3083. * myChildComponent: {
  3084. * myChildOption: true
  3085. * }
  3086. * });
  3087. * ```
  3088. * The children option can also be an array of
  3089. * child options objects (that also include a 'name' key).
  3090. * This can be used if you have two child components of the
  3091. * same type that need different options.
  3092. * ```js
  3093. * var myComp = new MyComponent(player, {
  3094. * children: [
  3095. * 'button',
  3096. * {
  3097. * name: 'button',
  3098. * someOtherOption: true
  3099. * },
  3100. * {
  3101. * name: 'button',
  3102. * someOtherOption: false
  3103. * }
  3104. * ]
  3105. * });
  3106. * ```
  3107. *
  3108. * @method initChildren
  3109. */
  3110. Component.prototype.initChildren = function initChildren() {
  3111. var _this = this;
  3112. var children = this.options_.children;
  3113. if (children) {
  3114. (function () {
  3115. // `this` is `parent`
  3116. var parentOptions = _this.options_;
  3117. var handleAdd = function handleAdd(child) {
  3118. var name = child.name;
  3119. var opts = child.opts;
  3120. // Allow options for children to be set at the parent options
  3121. // e.g. videojs(id, { controlBar: false });
  3122. // instead of videojs(id, { children: { controlBar: false });
  3123. if (parentOptions[name] !== undefined) {
  3124. opts = parentOptions[name];
  3125. }
  3126. // Allow for disabling default components
  3127. // e.g. options['children']['posterImage'] = false
  3128. if (opts === false) {
  3129. return;
  3130. }
  3131. // Allow options to be passed as a simple boolean if no configuration
  3132. // is necessary.
  3133. if (opts === true) {
  3134. opts = {};
  3135. }
  3136. // We also want to pass the original player options to each component as well so they don't need to
  3137. // reach back into the player for options later.
  3138. opts.playerOptions = _this.options_.playerOptions;
  3139. // Create and add the child component.
  3140. // Add a direct reference to the child by name on the parent instance.
  3141. // If two of the same component are used, different names should be supplied
  3142. // for each
  3143. var newChild = _this.addChild(name, opts);
  3144. if (newChild) {
  3145. _this[name] = newChild;
  3146. }
  3147. };
  3148. // Allow for an array of children details to passed in the options
  3149. var workingChildren = undefined;
  3150. var Tech = Component.getComponent('Tech');
  3151. if (Array.isArray(children)) {
  3152. workingChildren = children;
  3153. } else {
  3154. workingChildren = Object.keys(children);
  3155. }
  3156. workingChildren
  3157. // children that are in this.options_ but also in workingChildren would
  3158. // give us extra children we do not want. So, we want to filter them out.
  3159. .concat(Object.keys(_this.options_).filter(function (child) {
  3160. return !workingChildren.some(function (wchild) {
  3161. if (typeof wchild === 'string') {
  3162. return child === wchild;
  3163. } else {
  3164. return child === wchild.name;
  3165. }
  3166. });
  3167. })).map(function (child) {
  3168. var name = undefined,
  3169. opts = undefined;
  3170. if (typeof child === 'string') {
  3171. name = child;
  3172. opts = children[name] || _this.options_[name] || {};
  3173. } else {
  3174. name = child.name;
  3175. opts = child;
  3176. }
  3177. return { name: name, opts: opts };
  3178. }).filter(function (child) {
  3179. // we have to make sure that child.name isn't in the techOrder since
  3180. // techs are registerd as Components but can't aren't compatible
  3181. // See https://github.com/videojs/video.js/issues/2772
  3182. var c = Component.getComponent(child.opts.componentClass || _utilsToTitleCaseJs2['default'](child.name));
  3183. return c && !Tech.isTech(c);
  3184. }).forEach(handleAdd);
  3185. })();
  3186. }
  3187. };
  3188. /**
  3189. * Allows sub components to stack CSS class names
  3190. *
  3191. * @return {String} The constructed class name
  3192. * @method buildCSSClass
  3193. */
  3194. Component.prototype.buildCSSClass = function buildCSSClass() {
  3195. // Child classes can include a function that does:
  3196. // return 'CLASS NAME' + this._super();
  3197. return '';
  3198. };
  3199. /**
  3200. * Add an event listener to this component's element
  3201. * ```js
  3202. * var myFunc = function(){
  3203. * var myComponent = this;
  3204. * // Do something when the event is fired
  3205. * };
  3206. *
  3207. * myComponent.on('eventType', myFunc);
  3208. * ```
  3209. * The context of myFunc will be myComponent unless previously bound.
  3210. * Alternatively, you can add a listener to another element or component.
  3211. * ```js
  3212. * myComponent.on(otherElement, 'eventName', myFunc);
  3213. * myComponent.on(otherComponent, 'eventName', myFunc);
  3214. * ```
  3215. * The benefit of using this over `VjsEvents.on(otherElement, 'eventName', myFunc)`
  3216. * and `otherComponent.on('eventName', myFunc)` is that this way the listeners
  3217. * will be automatically cleaned up when either component is disposed.
  3218. * It will also bind myComponent as the context of myFunc.
  3219. * **NOTE**: When using this on elements in the page other than window
  3220. * and document (both permanent), if you remove the element from the DOM
  3221. * you need to call `myComponent.trigger(el, 'dispose')` on it to clean up
  3222. * references to it and allow the browser to garbage collect it.
  3223. *
  3224. * @param {String|Component} first The event type or other component
  3225. * @param {Function|String} second The event handler or event type
  3226. * @param {Function} third The event handler
  3227. * @return {Component}
  3228. * @method on
  3229. */
  3230. Component.prototype.on = function on(first, second, third) {
  3231. var _this2 = this;
  3232. if (typeof first === 'string' || Array.isArray(first)) {
  3233. Events.on(this.el_, first, Fn.bind(this, second));
  3234. // Targeting another component or element
  3235. } else {
  3236. (function () {
  3237. var target = first;
  3238. var type = second;
  3239. var fn = Fn.bind(_this2, third);
  3240. // When this component is disposed, remove the listener from the other component
  3241. var removeOnDispose = function removeOnDispose() {
  3242. return _this2.off(target, type, fn);
  3243. };
  3244. // Use the same function ID so we can remove it later it using the ID
  3245. // of the original listener
  3246. removeOnDispose.guid = fn.guid;
  3247. _this2.on('dispose', removeOnDispose);
  3248. // If the other component is disposed first we need to clean the reference
  3249. // to the other component in this component's removeOnDispose listener
  3250. // Otherwise we create a memory leak.
  3251. var cleanRemover = function cleanRemover() {
  3252. return _this2.off('dispose', removeOnDispose);
  3253. };
  3254. // Add the same function ID so we can easily remove it later
  3255. cleanRemover.guid = fn.guid;
  3256. // Check if this is a DOM node
  3257. if (first.nodeName) {
  3258. // Add the listener to the other element
  3259. Events.on(target, type, fn);
  3260. Events.on(target, 'dispose', cleanRemover);
  3261. // Should be a component
  3262. // Not using `instanceof Component` because it makes mock players difficult
  3263. } else if (typeof first.on === 'function') {
  3264. // Add the listener to the other component
  3265. target.on(type, fn);
  3266. target.on('dispose', cleanRemover);
  3267. }
  3268. })();
  3269. }
  3270. return this;
  3271. };
  3272. /**
  3273. * Remove an event listener from this component's element
  3274. * ```js
  3275. * myComponent.off('eventType', myFunc);
  3276. * ```
  3277. * If myFunc is excluded, ALL listeners for the event type will be removed.
  3278. * If eventType is excluded, ALL listeners will be removed from the component.
  3279. * Alternatively you can use `off` to remove listeners that were added to other
  3280. * elements or components using `myComponent.on(otherComponent...`.
  3281. * In this case both the event type and listener function are REQUIRED.
  3282. * ```js
  3283. * myComponent.off(otherElement, 'eventType', myFunc);
  3284. * myComponent.off(otherComponent, 'eventType', myFunc);
  3285. * ```
  3286. *
  3287. * @param {String=|Component} first The event type or other component
  3288. * @param {Function=|String} second The listener function or event type
  3289. * @param {Function=} third The listener for other component
  3290. * @return {Component}
  3291. * @method off
  3292. */
  3293. Component.prototype.off = function off(first, second, third) {
  3294. if (!first || typeof first === 'string' || Array.isArray(first)) {
  3295. Events.off(this.el_, first, second);
  3296. } else {
  3297. var target = first;
  3298. var type = second;
  3299. // Ensure there's at least a guid, even if the function hasn't been used
  3300. var fn = Fn.bind(this, third);
  3301. // Remove the dispose listener on this component,
  3302. // which was given the same guid as the event listener
  3303. this.off('dispose', fn);
  3304. if (first.nodeName) {
  3305. // Remove the listener
  3306. Events.off(target, type, fn);
  3307. // Remove the listener for cleaning the dispose listener
  3308. Events.off(target, 'dispose', fn);
  3309. } else {
  3310. target.off(type, fn);
  3311. target.off('dispose', fn);
  3312. }
  3313. }
  3314. return this;
  3315. };
  3316. /**
  3317. * Add an event listener to be triggered only once and then removed
  3318. * ```js
  3319. * myComponent.one('eventName', myFunc);
  3320. * ```
  3321. * Alternatively you can add a listener to another element or component
  3322. * that will be triggered only once.
  3323. * ```js
  3324. * myComponent.one(otherElement, 'eventName', myFunc);
  3325. * myComponent.one(otherComponent, 'eventName', myFunc);
  3326. * ```
  3327. *
  3328. * @param {String|Component} first The event type or other component
  3329. * @param {Function|String} second The listener function or event type
  3330. * @param {Function=} third The listener function for other component
  3331. * @return {Component}
  3332. * @method one
  3333. */
  3334. Component.prototype.one = function one(first, second, third) {
  3335. var _this3 = this,
  3336. _arguments = arguments;
  3337. if (typeof first === 'string' || Array.isArray(first)) {
  3338. Events.one(this.el_, first, Fn.bind(this, second));
  3339. } else {
  3340. (function () {
  3341. var target = first;
  3342. var type = second;
  3343. var fn = Fn.bind(_this3, third);
  3344. var newFunc = function newFunc() {
  3345. _this3.off(target, type, newFunc);
  3346. fn.apply(null, _arguments);
  3347. };
  3348. // Keep the same function ID so we can remove it later
  3349. newFunc.guid = fn.guid;
  3350. _this3.on(target, type, newFunc);
  3351. })();
  3352. }
  3353. return this;
  3354. };
  3355. /**
  3356. * Trigger an event on an element
  3357. * ```js
  3358. * myComponent.trigger('eventName');
  3359. * myComponent.trigger({'type':'eventName'});
  3360. * myComponent.trigger('eventName', {data: 'some data'});
  3361. * myComponent.trigger({'type':'eventName'}, {data: 'some data'});
  3362. * ```
  3363. *
  3364. * @param {Event|Object|String} event A string (the type) or an event object with a type attribute
  3365. * @param {Object} [hash] data hash to pass along with the event
  3366. * @return {Component} self
  3367. * @method trigger
  3368. */
  3369. Component.prototype.trigger = function trigger(event, hash) {
  3370. Events.trigger(this.el_, event, hash);
  3371. return this;
  3372. };
  3373. /**
  3374. * Bind a listener to the component's ready state.
  3375. * Different from event listeners in that if the ready event has already happened
  3376. * it will trigger the function immediately.
  3377. *
  3378. * @param {Function} fn Ready listener
  3379. * @param {Boolean} sync Exec the listener synchronously if component is ready
  3380. * @return {Component}
  3381. * @method ready
  3382. */
  3383. Component.prototype.ready = function ready(fn) {
  3384. var sync = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
  3385. if (fn) {
  3386. if (this.isReady_) {
  3387. if (sync) {
  3388. fn.call(this);
  3389. } else {
  3390. // Call the function asynchronously by default for consistency
  3391. this.setTimeout(fn, 1);
  3392. }
  3393. } else {
  3394. this.readyQueue_ = this.readyQueue_ || [];
  3395. this.readyQueue_.push(fn);
  3396. }
  3397. }
  3398. return this;
  3399. };
  3400. /**
  3401. * Trigger the ready listeners
  3402. *
  3403. * @return {Component}
  3404. * @method triggerReady
  3405. */
  3406. Component.prototype.triggerReady = function triggerReady() {
  3407. this.isReady_ = true;
  3408. // Ensure ready is triggerd asynchronously
  3409. this.setTimeout(function () {
  3410. var readyQueue = this.readyQueue_;
  3411. // Reset Ready Queue
  3412. this.readyQueue_ = [];
  3413. if (readyQueue && readyQueue.length > 0) {
  3414. readyQueue.forEach(function (fn) {
  3415. fn.call(this);
  3416. }, this);
  3417. }
  3418. // Allow for using event listeners also
  3419. this.trigger('ready');
  3420. }, 1);
  3421. };
  3422. /**
  3423. * Finds a single DOM element matching `selector` within the component's
  3424. * `contentEl` or another custom context.
  3425. *
  3426. * @method $
  3427. * @param {String} selector
  3428. * A valid CSS selector, which will be passed to `querySelector`.
  3429. *
  3430. * @param {Element|String} [context=document]
  3431. * A DOM element within which to query. Can also be a selector
  3432. * string in which case the first matching element will be used
  3433. * as context. If missing (or no element matches selector), falls
  3434. * back to `document`.
  3435. *
  3436. * @return {Element|null}
  3437. */
  3438. Component.prototype.$ = function $(selector, context) {
  3439. return Dom.$(selector, context || this.contentEl());
  3440. };
  3441. /**
  3442. * Finds a all DOM elements matching `selector` within the component's
  3443. * `contentEl` or another custom context.
  3444. *
  3445. * @method $$
  3446. * @param {String} selector
  3447. * A valid CSS selector, which will be passed to `querySelectorAll`.
  3448. *
  3449. * @param {Element|String} [context=document]
  3450. * A DOM element within which to query. Can also be a selector
  3451. * string in which case the first matching element will be used
  3452. * as context. If missing (or no element matches selector), falls
  3453. * back to `document`.
  3454. *
  3455. * @return {NodeList}
  3456. */
  3457. Component.prototype.$$ = function $$(selector, context) {
  3458. return Dom.$$(selector, context || this.contentEl());
  3459. };
  3460. /**
  3461. * Check if a component's element has a CSS class name
  3462. *
  3463. * @param {String} classToCheck Classname to check
  3464. * @return {Component}
  3465. * @method hasClass
  3466. */
  3467. Component.prototype.hasClass = function hasClass(classToCheck) {
  3468. return Dom.hasElClass(this.el_, classToCheck);
  3469. };
  3470. /**
  3471. * Add a CSS class name to the component's element
  3472. *
  3473. * @param {String} classToAdd Classname to add
  3474. * @return {Component}
  3475. * @method addClass
  3476. */
  3477. Component.prototype.addClass = function addClass(classToAdd) {
  3478. Dom.addElClass(this.el_, classToAdd);
  3479. return this;
  3480. };
  3481. /**
  3482. * Remove a CSS class name from the component's element
  3483. *
  3484. * @param {String} classToRemove Classname to remove
  3485. * @return {Component}
  3486. * @method removeClass
  3487. */
  3488. Component.prototype.removeClass = function removeClass(classToRemove) {
  3489. Dom.removeElClass(this.el_, classToRemove);
  3490. return this;
  3491. };
  3492. /**
  3493. * Add or remove a CSS class name from the component's element
  3494. *
  3495. * @param {String} classToToggle
  3496. * @param {Boolean|Function} [predicate]
  3497. * Can be a function that returns a Boolean. If `true`, the class
  3498. * will be added; if `false`, the class will be removed. If not
  3499. * given, the class will be added if not present and vice versa.
  3500. *
  3501. * @return {Component}
  3502. * @method toggleClass
  3503. */
  3504. Component.prototype.toggleClass = function toggleClass(classToToggle, predicate) {
  3505. Dom.toggleElClass(this.el_, classToToggle, predicate);
  3506. return this;
  3507. };
  3508. /**
  3509. * Show the component element if hidden
  3510. *
  3511. * @return {Component}
  3512. * @method show
  3513. */
  3514. Component.prototype.show = function show() {
  3515. this.removeClass('vjs-hidden');
  3516. return this;
  3517. };
  3518. /**
  3519. * Hide the component element if currently showing
  3520. *
  3521. * @return {Component}
  3522. * @method hide
  3523. */
  3524. Component.prototype.hide = function hide() {
  3525. this.addClass('vjs-hidden');
  3526. return this;
  3527. };
  3528. /**
  3529. * Lock an item in its visible state
  3530. * To be used with fadeIn/fadeOut.
  3531. *
  3532. * @return {Component}
  3533. * @private
  3534. * @method lockShowing
  3535. */
  3536. Component.prototype.lockShowing = function lockShowing() {
  3537. this.addClass('vjs-lock-showing');
  3538. return this;
  3539. };
  3540. /**
  3541. * Unlock an item to be hidden
  3542. * To be used with fadeIn/fadeOut.
  3543. *
  3544. * @return {Component}
  3545. * @private
  3546. * @method unlockShowing
  3547. */
  3548. Component.prototype.unlockShowing = function unlockShowing() {
  3549. this.removeClass('vjs-lock-showing');
  3550. return this;
  3551. };
  3552. /**
  3553. * Set or get the width of the component (CSS values)
  3554. * Setting the video tag dimension values only works with values in pixels.
  3555. * Percent values will not work.
  3556. * Some percents can be used, but width()/height() will return the number + %,
  3557. * not the actual computed width/height.
  3558. *
  3559. * @param {Number|String=} num Optional width number
  3560. * @param {Boolean} skipListeners Skip the 'resize' event trigger
  3561. * @return {Component} This component, when setting the width
  3562. * @return {Number|String} The width, when getting
  3563. * @method width
  3564. */
  3565. Component.prototype.width = function width(num, skipListeners) {
  3566. return this.dimension('width', num, skipListeners);
  3567. };
  3568. /**
  3569. * Get or set the height of the component (CSS values)
  3570. * Setting the video tag dimension values only works with values in pixels.
  3571. * Percent values will not work.
  3572. * Some percents can be used, but width()/height() will return the number + %,
  3573. * not the actual computed width/height.
  3574. *
  3575. * @param {Number|String=} num New component height
  3576. * @param {Boolean=} skipListeners Skip the resize event trigger
  3577. * @return {Component} This component, when setting the height
  3578. * @return {Number|String} The height, when getting
  3579. * @method height
  3580. */
  3581. Component.prototype.height = function height(num, skipListeners) {
  3582. return this.dimension('height', num, skipListeners);
  3583. };
  3584. /**
  3585. * Set both width and height at the same time
  3586. *
  3587. * @param {Number|String} width Width of player
  3588. * @param {Number|String} height Height of player
  3589. * @return {Component} The component
  3590. * @method dimensions
  3591. */
  3592. Component.prototype.dimensions = function dimensions(width, height) {
  3593. // Skip resize listeners on width for optimization
  3594. return this.width(width, true).height(height);
  3595. };
  3596. /**
  3597. * Get or set width or height
  3598. * This is the shared code for the width() and height() methods.
  3599. * All for an integer, integer + 'px' or integer + '%';
  3600. * Known issue: Hidden elements officially have a width of 0. We're defaulting
  3601. * to the style.width value and falling back to computedStyle which has the
  3602. * hidden element issue. Info, but probably not an efficient fix:
  3603. * http://www.foliotek.com/devblog/getting-the-width-of-a-hidden-element-with-jquery-using-width/
  3604. *
  3605. * @param {String} widthOrHeight 'width' or 'height'
  3606. * @param {Number|String=} num New dimension
  3607. * @param {Boolean=} skipListeners Skip resize event trigger
  3608. * @return {Component} The component if a dimension was set
  3609. * @return {Number|String} The dimension if nothing was set
  3610. * @private
  3611. * @method dimension
  3612. */
  3613. Component.prototype.dimension = function dimension(widthOrHeight, num, skipListeners) {
  3614. if (num !== undefined) {
  3615. // Set to zero if null or literally NaN (NaN !== NaN)
  3616. if (num === null || num !== num) {
  3617. num = 0;
  3618. }
  3619. // Check if using css width/height (% or px) and adjust
  3620. if (('' + num).indexOf('%') !== -1 || ('' + num).indexOf('px') !== -1) {
  3621. this.el_.style[widthOrHeight] = num;
  3622. } else if (num === 'auto') {
  3623. this.el_.style[widthOrHeight] = '';
  3624. } else {
  3625. this.el_.style[widthOrHeight] = num + 'px';
  3626. }
  3627. // skipListeners allows us to avoid triggering the resize event when setting both width and height
  3628. if (!skipListeners) {
  3629. this.trigger('resize');
  3630. }
  3631. // Return component
  3632. return this;
  3633. }
  3634. // Not setting a value, so getting it
  3635. // Make sure element exists
  3636. if (!this.el_) {
  3637. return 0;
  3638. }
  3639. // Get dimension value from style
  3640. var val = this.el_.style[widthOrHeight];
  3641. var pxIndex = val.indexOf('px');
  3642. if (pxIndex !== -1) {
  3643. // Return the pixel value with no 'px'
  3644. return parseInt(val.slice(0, pxIndex), 10);
  3645. }
  3646. // No px so using % or no style was set, so falling back to offsetWidth/height
  3647. // If component has display:none, offset will return 0
  3648. // TODO: handle display:none and no dimension style using px
  3649. return parseInt(this.el_['offset' + _utilsToTitleCaseJs2['default'](widthOrHeight)], 10);
  3650. };
  3651. /**
  3652. * Emit 'tap' events when touch events are supported
  3653. * This is used to support toggling the controls through a tap on the video.
  3654. * We're requiring them to be enabled because otherwise every component would
  3655. * have this extra overhead unnecessarily, on mobile devices where extra
  3656. * overhead is especially bad.
  3657. *
  3658. * @private
  3659. * @method emitTapEvents
  3660. */
  3661. Component.prototype.emitTapEvents = function emitTapEvents() {
  3662. // Track the start time so we can determine how long the touch lasted
  3663. var touchStart = 0;
  3664. var firstTouch = null;
  3665. // Maximum movement allowed during a touch event to still be considered a tap
  3666. // Other popular libs use anywhere from 2 (hammer.js) to 15, so 10 seems like a nice, round number.
  3667. var tapMovementThreshold = 10;
  3668. // The maximum length a touch can be while still being considered a tap
  3669. var touchTimeThreshold = 200;
  3670. var couldBeTap = undefined;
  3671. this.on('touchstart', function (event) {
  3672. // If more than one finger, don't consider treating this as a click
  3673. if (event.touches.length === 1) {
  3674. // Copy the touches object to prevent modifying the original
  3675. firstTouch = _objectAssign2['default']({}, event.touches[0]);
  3676. // Record start time so we can detect a tap vs. "touch and hold"
  3677. touchStart = new Date().getTime();
  3678. // Reset couldBeTap tracking
  3679. couldBeTap = true;
  3680. }
  3681. });
  3682. this.on('touchmove', function (event) {
  3683. // If more than one finger, don't consider treating this as a click
  3684. if (event.touches.length > 1) {
  3685. couldBeTap = false;
  3686. } else if (firstTouch) {
  3687. // Some devices will throw touchmoves for all but the slightest of taps.
  3688. // So, if we moved only a small distance, this could still be a tap
  3689. var xdiff = event.touches[0].pageX - firstTouch.pageX;
  3690. var ydiff = event.touches[0].pageY - firstTouch.pageY;
  3691. var touchDistance = Math.sqrt(xdiff * xdiff + ydiff * ydiff);
  3692. if (touchDistance > tapMovementThreshold) {
  3693. couldBeTap = false;
  3694. }
  3695. }
  3696. });
  3697. var noTap = function noTap() {
  3698. couldBeTap = false;
  3699. };
  3700. // TODO: Listen to the original target. http://youtu.be/DujfpXOKUp8?t=13m8s
  3701. this.on('touchleave', noTap);
  3702. this.on('touchcancel', noTap);
  3703. // When the touch ends, measure how long it took and trigger the appropriate
  3704. // event
  3705. this.on('touchend', function (event) {
  3706. firstTouch = null;
  3707. // Proceed only if the touchmove/leave/cancel event didn't happen
  3708. if (couldBeTap === true) {
  3709. // Measure how long the touch lasted
  3710. var touchTime = new Date().getTime() - touchStart;
  3711. // Make sure the touch was less than the threshold to be considered a tap
  3712. if (touchTime < touchTimeThreshold) {
  3713. // Don't let browser turn this into a click
  3714. event.preventDefault();
  3715. this.trigger('tap');
  3716. // It may be good to copy the touchend event object and change the
  3717. // type to tap, if the other event properties aren't exact after
  3718. // Events.fixEvent runs (e.g. event.target)
  3719. }
  3720. }
  3721. });
  3722. };
  3723. /**
  3724. * Report user touch activity when touch events occur
  3725. * User activity is used to determine when controls should show/hide. It's
  3726. * relatively simple when it comes to mouse events, because any mouse event
  3727. * should show the controls. So we capture mouse events that bubble up to the
  3728. * player and report activity when that happens.
  3729. * With touch events it isn't as easy. We can't rely on touch events at the
  3730. * player level, because a tap (touchstart + touchend) on the video itself on
  3731. * mobile devices is meant to turn controls off (and on). User activity is
  3732. * checked asynchronously, so what could happen is a tap event on the video
  3733. * turns the controls off, then the touchend event bubbles up to the player,
  3734. * which if it reported user activity, would turn the controls right back on.
  3735. * (We also don't want to completely block touch events from bubbling up)
  3736. * Also a touchmove, touch+hold, and anything other than a tap is not supposed
  3737. * to turn the controls back on on a mobile device.
  3738. * Here we're setting the default component behavior to report user activity
  3739. * whenever touch events happen, and this can be turned off by components that
  3740. * want touch events to act differently.
  3741. *
  3742. * @method enableTouchActivity
  3743. */
  3744. Component.prototype.enableTouchActivity = function enableTouchActivity() {
  3745. // Don't continue if the root player doesn't support reporting user activity
  3746. if (!this.player() || !this.player().reportUserActivity) {
  3747. return;
  3748. }
  3749. // listener for reporting that the user is active
  3750. var report = Fn.bind(this.player(), this.player().reportUserActivity);
  3751. var touchHolding = undefined;
  3752. this.on('touchstart', function () {
  3753. report();
  3754. // For as long as the they are touching the device or have their mouse down,
  3755. // we consider them active even if they're not moving their finger or mouse.
  3756. // So we want to continue to update that they are active
  3757. this.clearInterval(touchHolding);
  3758. // report at the same interval as activityCheck
  3759. touchHolding = this.setInterval(report, 250);
  3760. });
  3761. var touchEnd = function touchEnd(event) {
  3762. report();
  3763. // stop the interval that maintains activity if the touch is holding
  3764. this.clearInterval(touchHolding);
  3765. };
  3766. this.on('touchmove', report);
  3767. this.on('touchend', touchEnd);
  3768. this.on('touchcancel', touchEnd);
  3769. };
  3770. /**
  3771. * Creates timeout and sets up disposal automatically.
  3772. *
  3773. * @param {Function} fn The function to run after the timeout.
  3774. * @param {Number} timeout Number of ms to delay before executing specified function.
  3775. * @return {Number} Returns the timeout ID
  3776. * @method setTimeout
  3777. */
  3778. Component.prototype.setTimeout = function setTimeout(fn, timeout) {
  3779. fn = Fn.bind(this, fn);
  3780. // window.setTimeout would be preferable here, but due to some bizarre issue with Sinon and/or Phantomjs, we can't.
  3781. var timeoutId = _globalWindow2['default'].setTimeout(fn, timeout);
  3782. var disposeFn = function disposeFn() {
  3783. this.clearTimeout(timeoutId);
  3784. };
  3785. disposeFn.guid = 'vjs-timeout-' + timeoutId;
  3786. this.on('dispose', disposeFn);
  3787. return timeoutId;
  3788. };
  3789. /**
  3790. * Clears a timeout and removes the associated dispose listener
  3791. *
  3792. * @param {Number} timeoutId The id of the timeout to clear
  3793. * @return {Number} Returns the timeout ID
  3794. * @method clearTimeout
  3795. */
  3796. Component.prototype.clearTimeout = function clearTimeout(timeoutId) {
  3797. _globalWindow2['default'].clearTimeout(timeoutId);
  3798. var disposeFn = function disposeFn() {};
  3799. disposeFn.guid = 'vjs-timeout-' + timeoutId;
  3800. this.off('dispose', disposeFn);
  3801. return timeoutId;
  3802. };
  3803. /**
  3804. * Creates an interval and sets up disposal automatically.
  3805. *
  3806. * @param {Function} fn The function to run every N seconds.
  3807. * @param {Number} interval Number of ms to delay before executing specified function.
  3808. * @return {Number} Returns the interval ID
  3809. * @method setInterval
  3810. */
  3811. Component.prototype.setInterval = function setInterval(fn, interval) {
  3812. fn = Fn.bind(this, fn);
  3813. var intervalId = _globalWindow2['default'].setInterval(fn, interval);
  3814. var disposeFn = function disposeFn() {
  3815. this.clearInterval(intervalId);
  3816. };
  3817. disposeFn.guid = 'vjs-interval-' + intervalId;
  3818. this.on('dispose', disposeFn);
  3819. return intervalId;
  3820. };
  3821. /**
  3822. * Clears an interval and removes the associated dispose listener
  3823. *
  3824. * @param {Number} intervalId The id of the interval to clear
  3825. * @return {Number} Returns the interval ID
  3826. * @method clearInterval
  3827. */
  3828. Component.prototype.clearInterval = function clearInterval(intervalId) {
  3829. _globalWindow2['default'].clearInterval(intervalId);
  3830. var disposeFn = function disposeFn() {};
  3831. disposeFn.guid = 'vjs-interval-' + intervalId;
  3832. this.off('dispose', disposeFn);
  3833. return intervalId;
  3834. };
  3835. /**
  3836. * Registers a component
  3837. *
  3838. * @param {String} name Name of the component to register
  3839. * @param {Object} comp The component to register
  3840. * @static
  3841. * @method registerComponent
  3842. */
  3843. Component.registerComponent = function registerComponent(name, comp) {
  3844. if (!Component.components_) {
  3845. Component.components_ = {};
  3846. }
  3847. Component.components_[name] = comp;
  3848. return comp;
  3849. };
  3850. /**
  3851. * Gets a component by name
  3852. *
  3853. * @param {String} name Name of the component to get
  3854. * @return {Component}
  3855. * @static
  3856. * @method getComponent
  3857. */
  3858. Component.getComponent = function getComponent(name) {
  3859. if (Component.components_ && Component.components_[name]) {
  3860. return Component.components_[name];
  3861. }
  3862. if (_globalWindow2['default'] && _globalWindow2['default'].videojs && _globalWindow2['default'].videojs[name]) {
  3863. _utilsLogJs2['default'].warn('The ' + name + ' component was added to the videojs object when it should be registered using videojs.registerComponent(name, component)');
  3864. return _globalWindow2['default'].videojs[name];
  3865. }
  3866. };
  3867. /**
  3868. * Sets up the constructor using the supplied init method
  3869. * or uses the init of the parent object
  3870. *
  3871. * @param {Object} props An object of properties
  3872. * @static
  3873. * @deprecated
  3874. * @method extend
  3875. */
  3876. Component.extend = function extend(props) {
  3877. props = props || {};
  3878. _utilsLogJs2['default'].warn('Component.extend({}) has been deprecated, use videojs.extend(Component, {}) instead');
  3879. // Set up the constructor using the supplied init method
  3880. // or using the init of the parent object
  3881. // Make sure to check the unobfuscated version for external libs
  3882. var init = props.init || props.init || this.prototype.init || this.prototype.init || function () {};
  3883. // In Resig's simple class inheritance (previously used) the constructor
  3884. // is a function that calls `this.init.apply(arguments)`
  3885. // However that would prevent us from using `ParentObject.call(this);`
  3886. // in a Child constructor because the `this` in `this.init`
  3887. // would still refer to the Child and cause an infinite loop.
  3888. // We would instead have to do
  3889. // `ParentObject.prototype.init.apply(this, arguments);`
  3890. // Bleh. We're not creating a _super() function, so it's good to keep
  3891. // the parent constructor reference simple.
  3892. var subObj = function subObj() {
  3893. init.apply(this, arguments);
  3894. };
  3895. // Inherit from this object's prototype
  3896. subObj.prototype = Object.create(this.prototype);
  3897. // Reset the constructor property for subObj otherwise
  3898. // instances of subObj would have the constructor of the parent Object
  3899. subObj.prototype.constructor = subObj;
  3900. // Make the class extendable
  3901. subObj.extend = Component.extend;
  3902. // Extend subObj's prototype with functions and other properties from props
  3903. for (var _name in props) {
  3904. if (props.hasOwnProperty(_name)) {
  3905. subObj.prototype[_name] = props[_name];
  3906. }
  3907. }
  3908. return subObj;
  3909. };
  3910. return Component;
  3911. })();
  3912. Component.registerComponent('Component', Component);
  3913. exports['default'] = Component;
  3914. module.exports = exports['default'];
  3915. },{"./utils/dom.js":132,"./utils/events.js":133,"./utils/fn.js":134,"./utils/guid.js":136,"./utils/log.js":137,"./utils/merge-options.js":138,"./utils/to-title-case.js":141,"global/window":2,"object.assign":45}],68:[function(_dereq_,module,exports){
  3916. /**
  3917. * @file control-bar.js
  3918. */
  3919. 'use strict';
  3920. exports.__esModule = true;
  3921. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  3922. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  3923. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  3924. var _componentJs = _dereq_('../component.js');
  3925. var _componentJs2 = _interopRequireDefault(_componentJs);
  3926. // Required children
  3927. var _playToggleJs = _dereq_('./play-toggle.js');
  3928. var _playToggleJs2 = _interopRequireDefault(_playToggleJs);
  3929. var _timeControlsCurrentTimeDisplayJs = _dereq_('./time-controls/current-time-display.js');
  3930. var _timeControlsCurrentTimeDisplayJs2 = _interopRequireDefault(_timeControlsCurrentTimeDisplayJs);
  3931. var _timeControlsDurationDisplayJs = _dereq_('./time-controls/duration-display.js');
  3932. var _timeControlsDurationDisplayJs2 = _interopRequireDefault(_timeControlsDurationDisplayJs);
  3933. var _timeControlsTimeDividerJs = _dereq_('./time-controls/time-divider.js');
  3934. var _timeControlsTimeDividerJs2 = _interopRequireDefault(_timeControlsTimeDividerJs);
  3935. var _timeControlsRemainingTimeDisplayJs = _dereq_('./time-controls/remaining-time-display.js');
  3936. var _timeControlsRemainingTimeDisplayJs2 = _interopRequireDefault(_timeControlsRemainingTimeDisplayJs);
  3937. var _liveDisplayJs = _dereq_('./live-display.js');
  3938. var _liveDisplayJs2 = _interopRequireDefault(_liveDisplayJs);
  3939. var _progressControlProgressControlJs = _dereq_('./progress-control/progress-control.js');
  3940. var _progressControlProgressControlJs2 = _interopRequireDefault(_progressControlProgressControlJs);
  3941. var _fullscreenToggleJs = _dereq_('./fullscreen-toggle.js');
  3942. var _fullscreenToggleJs2 = _interopRequireDefault(_fullscreenToggleJs);
  3943. var _volumeControlVolumeControlJs = _dereq_('./volume-control/volume-control.js');
  3944. var _volumeControlVolumeControlJs2 = _interopRequireDefault(_volumeControlVolumeControlJs);
  3945. var _volumeMenuButtonJs = _dereq_('./volume-menu-button.js');
  3946. var _volumeMenuButtonJs2 = _interopRequireDefault(_volumeMenuButtonJs);
  3947. var _muteToggleJs = _dereq_('./mute-toggle.js');
  3948. var _muteToggleJs2 = _interopRequireDefault(_muteToggleJs);
  3949. var _textTrackControlsChaptersButtonJs = _dereq_('./text-track-controls/chapters-button.js');
  3950. var _textTrackControlsChaptersButtonJs2 = _interopRequireDefault(_textTrackControlsChaptersButtonJs);
  3951. var _textTrackControlsSubtitlesButtonJs = _dereq_('./text-track-controls/subtitles-button.js');
  3952. var _textTrackControlsSubtitlesButtonJs2 = _interopRequireDefault(_textTrackControlsSubtitlesButtonJs);
  3953. var _textTrackControlsCaptionsButtonJs = _dereq_('./text-track-controls/captions-button.js');
  3954. var _textTrackControlsCaptionsButtonJs2 = _interopRequireDefault(_textTrackControlsCaptionsButtonJs);
  3955. var _playbackRateMenuPlaybackRateMenuButtonJs = _dereq_('./playback-rate-menu/playback-rate-menu-button.js');
  3956. var _playbackRateMenuPlaybackRateMenuButtonJs2 = _interopRequireDefault(_playbackRateMenuPlaybackRateMenuButtonJs);
  3957. var _spacerControlsCustomControlSpacerJs = _dereq_('./spacer-controls/custom-control-spacer.js');
  3958. var _spacerControlsCustomControlSpacerJs2 = _interopRequireDefault(_spacerControlsCustomControlSpacerJs);
  3959. /**
  3960. * Container of main controls
  3961. *
  3962. * @extends Component
  3963. * @class ControlBar
  3964. */
  3965. var ControlBar = (function (_Component) {
  3966. _inherits(ControlBar, _Component);
  3967. function ControlBar() {
  3968. _classCallCheck(this, ControlBar);
  3969. _Component.apply(this, arguments);
  3970. }
  3971. /**
  3972. * Create the component's DOM element
  3973. *
  3974. * @return {Element}
  3975. * @method createEl
  3976. */
  3977. ControlBar.prototype.createEl = function createEl() {
  3978. return _Component.prototype.createEl.call(this, 'div', {
  3979. className: 'vjs-control-bar',
  3980. dir: 'ltr'
  3981. }, {
  3982. 'role': 'group' // The control bar is a group, so it can contain menuitems
  3983. });
  3984. };
  3985. return ControlBar;
  3986. })(_componentJs2['default']);
  3987. ControlBar.prototype.options_ = {
  3988. loadEvent: 'play',
  3989. children: ['playToggle', 'volumeMenuButton', 'currentTimeDisplay', 'timeDivider', 'durationDisplay', 'progressControl', 'liveDisplay', 'remainingTimeDisplay', 'customControlSpacer', 'playbackRateMenuButton', 'chaptersButton', 'subtitlesButton', 'captionsButton', 'fullscreenToggle']
  3990. };
  3991. _componentJs2['default'].registerComponent('ControlBar', ControlBar);
  3992. exports['default'] = ControlBar;
  3993. module.exports = exports['default'];
  3994. },{"../component.js":67,"./fullscreen-toggle.js":69,"./live-display.js":70,"./mute-toggle.js":71,"./play-toggle.js":72,"./playback-rate-menu/playback-rate-menu-button.js":73,"./progress-control/progress-control.js":78,"./spacer-controls/custom-control-spacer.js":80,"./text-track-controls/captions-button.js":83,"./text-track-controls/chapters-button.js":84,"./text-track-controls/subtitles-button.js":87,"./time-controls/current-time-display.js":90,"./time-controls/duration-display.js":91,"./time-controls/remaining-time-display.js":92,"./time-controls/time-divider.js":93,"./volume-control/volume-control.js":95,"./volume-menu-button.js":97}],69:[function(_dereq_,module,exports){
  3995. /**
  3996. * @file fullscreen-toggle.js
  3997. */
  3998. 'use strict';
  3999. exports.__esModule = true;
  4000. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4001. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4002. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4003. var _buttonJs = _dereq_('../button.js');
  4004. var _buttonJs2 = _interopRequireDefault(_buttonJs);
  4005. var _componentJs = _dereq_('../component.js');
  4006. var _componentJs2 = _interopRequireDefault(_componentJs);
  4007. /**
  4008. * Toggle fullscreen video
  4009. *
  4010. * @extends Button
  4011. * @class FullscreenToggle
  4012. */
  4013. var FullscreenToggle = (function (_Button) {
  4014. _inherits(FullscreenToggle, _Button);
  4015. function FullscreenToggle() {
  4016. _classCallCheck(this, FullscreenToggle);
  4017. _Button.apply(this, arguments);
  4018. }
  4019. /**
  4020. * Allow sub components to stack CSS class names
  4021. *
  4022. * @return {String} The constructed class name
  4023. * @method buildCSSClass
  4024. */
  4025. FullscreenToggle.prototype.buildCSSClass = function buildCSSClass() {
  4026. return 'vjs-fullscreen-control ' + _Button.prototype.buildCSSClass.call(this);
  4027. };
  4028. /**
  4029. * Handles click for full screen
  4030. *
  4031. * @method handleClick
  4032. */
  4033. FullscreenToggle.prototype.handleClick = function handleClick() {
  4034. if (!this.player_.isFullscreen()) {
  4035. this.player_.requestFullscreen();
  4036. this.controlText('Non-Fullscreen');
  4037. } else {
  4038. this.player_.exitFullscreen();
  4039. this.controlText('Fullscreen');
  4040. }
  4041. };
  4042. return FullscreenToggle;
  4043. })(_buttonJs2['default']);
  4044. FullscreenToggle.prototype.controlText_ = 'Fullscreen';
  4045. _componentJs2['default'].registerComponent('FullscreenToggle', FullscreenToggle);
  4046. exports['default'] = FullscreenToggle;
  4047. module.exports = exports['default'];
  4048. },{"../button.js":64,"../component.js":67}],70:[function(_dereq_,module,exports){
  4049. /**
  4050. * @file live-display.js
  4051. */
  4052. 'use strict';
  4053. exports.__esModule = true;
  4054. 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; } }
  4055. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4056. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4057. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4058. var _component = _dereq_('../component');
  4059. var _component2 = _interopRequireDefault(_component);
  4060. var _utilsDomJs = _dereq_('../utils/dom.js');
  4061. var Dom = _interopRequireWildcard(_utilsDomJs);
  4062. /**
  4063. * Displays the live indicator
  4064. * TODO - Future make it click to snap to live
  4065. *
  4066. * @extends Component
  4067. * @class LiveDisplay
  4068. */
  4069. var LiveDisplay = (function (_Component) {
  4070. _inherits(LiveDisplay, _Component);
  4071. function LiveDisplay(player, options) {
  4072. _classCallCheck(this, LiveDisplay);
  4073. _Component.call(this, player, options);
  4074. this.updateShowing();
  4075. this.on(this.player(), 'durationchange', this.updateShowing);
  4076. }
  4077. /**
  4078. * Create the component's DOM element
  4079. *
  4080. * @return {Element}
  4081. * @method createEl
  4082. */
  4083. LiveDisplay.prototype.createEl = function createEl() {
  4084. var el = _Component.prototype.createEl.call(this, 'div', {
  4085. className: 'vjs-live-control vjs-control'
  4086. });
  4087. this.contentEl_ = Dom.createEl('div', {
  4088. className: 'vjs-live-display',
  4089. innerHTML: '<span class="vjs-control-text">' + this.localize('Stream Type') + '</span>' + this.localize('LIVE')
  4090. }, {
  4091. 'aria-live': 'off'
  4092. });
  4093. el.appendChild(this.contentEl_);
  4094. return el;
  4095. };
  4096. LiveDisplay.prototype.updateShowing = function updateShowing() {
  4097. if (this.player().duration() === Infinity) {
  4098. this.show();
  4099. } else {
  4100. this.hide();
  4101. }
  4102. };
  4103. return LiveDisplay;
  4104. })(_component2['default']);
  4105. _component2['default'].registerComponent('LiveDisplay', LiveDisplay);
  4106. exports['default'] = LiveDisplay;
  4107. module.exports = exports['default'];
  4108. },{"../component":67,"../utils/dom.js":132}],71:[function(_dereq_,module,exports){
  4109. /**
  4110. * @file mute-toggle.js
  4111. */
  4112. 'use strict';
  4113. exports.__esModule = true;
  4114. 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; } }
  4115. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4116. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4117. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4118. var _button = _dereq_('../button');
  4119. var _button2 = _interopRequireDefault(_button);
  4120. var _component = _dereq_('../component');
  4121. var _component2 = _interopRequireDefault(_component);
  4122. var _utilsDomJs = _dereq_('../utils/dom.js');
  4123. var Dom = _interopRequireWildcard(_utilsDomJs);
  4124. /**
  4125. * A button component for muting the audio
  4126. *
  4127. * @param {Player|Object} player
  4128. * @param {Object=} options
  4129. * @extends Button
  4130. * @class MuteToggle
  4131. */
  4132. var MuteToggle = (function (_Button) {
  4133. _inherits(MuteToggle, _Button);
  4134. function MuteToggle(player, options) {
  4135. _classCallCheck(this, MuteToggle);
  4136. _Button.call(this, player, options);
  4137. this.on(player, 'volumechange', this.update);
  4138. // hide mute toggle if the current tech doesn't support volume control
  4139. if (player.tech_ && player.tech_['featuresVolumeControl'] === false) {
  4140. this.addClass('vjs-hidden');
  4141. }
  4142. this.on(player, 'loadstart', function () {
  4143. this.update(); // We need to update the button to account for a default muted state.
  4144. if (player.tech_['featuresVolumeControl'] === false) {
  4145. this.addClass('vjs-hidden');
  4146. } else {
  4147. this.removeClass('vjs-hidden');
  4148. }
  4149. });
  4150. }
  4151. /**
  4152. * Allow sub components to stack CSS class names
  4153. *
  4154. * @return {String} The constructed class name
  4155. * @method buildCSSClass
  4156. */
  4157. MuteToggle.prototype.buildCSSClass = function buildCSSClass() {
  4158. return 'vjs-mute-control ' + _Button.prototype.buildCSSClass.call(this);
  4159. };
  4160. /**
  4161. * Handle click on mute
  4162. *
  4163. * @method handleClick
  4164. */
  4165. MuteToggle.prototype.handleClick = function handleClick() {
  4166. this.player_.muted(this.player_.muted() ? false : true);
  4167. };
  4168. /**
  4169. * Update volume
  4170. *
  4171. * @method update
  4172. */
  4173. MuteToggle.prototype.update = function update() {
  4174. var vol = this.player_.volume(),
  4175. level = 3;
  4176. if (vol === 0 || this.player_.muted()) {
  4177. level = 0;
  4178. } else if (vol < 0.33) {
  4179. level = 1;
  4180. } else if (vol < 0.67) {
  4181. level = 2;
  4182. }
  4183. // Don't rewrite the button text if the actual text doesn't change.
  4184. // This causes unnecessary and confusing information for screen reader users.
  4185. // This check is needed because this function gets called every time the volume level is changed.
  4186. var toMute = this.player_.muted() ? 'Unmute' : 'Mute';
  4187. if (this.controlText() !== toMute) {
  4188. this.controlText(toMute);
  4189. }
  4190. /* TODO improve muted icon classes */
  4191. for (var i = 0; i < 4; i++) {
  4192. Dom.removeElClass(this.el_, 'vjs-vol-' + i);
  4193. }
  4194. Dom.addElClass(this.el_, 'vjs-vol-' + level);
  4195. };
  4196. return MuteToggle;
  4197. })(_button2['default']);
  4198. MuteToggle.prototype.controlText_ = 'Mute';
  4199. _component2['default'].registerComponent('MuteToggle', MuteToggle);
  4200. exports['default'] = MuteToggle;
  4201. module.exports = exports['default'];
  4202. },{"../button":64,"../component":67,"../utils/dom.js":132}],72:[function(_dereq_,module,exports){
  4203. /**
  4204. * @file play-toggle.js
  4205. */
  4206. 'use strict';
  4207. exports.__esModule = true;
  4208. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4209. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4210. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4211. var _buttonJs = _dereq_('../button.js');
  4212. var _buttonJs2 = _interopRequireDefault(_buttonJs);
  4213. var _componentJs = _dereq_('../component.js');
  4214. var _componentJs2 = _interopRequireDefault(_componentJs);
  4215. /**
  4216. * Button to toggle between play and pause
  4217. *
  4218. * @param {Player|Object} player
  4219. * @param {Object=} options
  4220. * @extends Button
  4221. * @class PlayToggle
  4222. */
  4223. var PlayToggle = (function (_Button) {
  4224. _inherits(PlayToggle, _Button);
  4225. function PlayToggle(player, options) {
  4226. _classCallCheck(this, PlayToggle);
  4227. _Button.call(this, player, options);
  4228. this.on(player, 'play', this.handlePlay);
  4229. this.on(player, 'pause', this.handlePause);
  4230. }
  4231. /**
  4232. * Allow sub components to stack CSS class names
  4233. *
  4234. * @return {String} The constructed class name
  4235. * @method buildCSSClass
  4236. */
  4237. PlayToggle.prototype.buildCSSClass = function buildCSSClass() {
  4238. return 'vjs-play-control ' + _Button.prototype.buildCSSClass.call(this);
  4239. };
  4240. /**
  4241. * Handle click to toggle between play and pause
  4242. *
  4243. * @method handleClick
  4244. */
  4245. PlayToggle.prototype.handleClick = function handleClick() {
  4246. if (this.player_.paused()) {
  4247. this.player_.play();
  4248. } else {
  4249. this.player_.pause();
  4250. }
  4251. };
  4252. /**
  4253. * Add the vjs-playing class to the element so it can change appearance
  4254. *
  4255. * @method handlePlay
  4256. */
  4257. PlayToggle.prototype.handlePlay = function handlePlay() {
  4258. this.removeClass('vjs-paused');
  4259. this.addClass('vjs-playing');
  4260. this.controlText('Pause'); // change the button text to "Pause"
  4261. };
  4262. /**
  4263. * Add the vjs-paused class to the element so it can change appearance
  4264. *
  4265. * @method handlePause
  4266. */
  4267. PlayToggle.prototype.handlePause = function handlePause() {
  4268. this.removeClass('vjs-playing');
  4269. this.addClass('vjs-paused');
  4270. this.controlText('Play'); // change the button text to "Play"
  4271. };
  4272. return PlayToggle;
  4273. })(_buttonJs2['default']);
  4274. PlayToggle.prototype.controlText_ = 'Play';
  4275. _componentJs2['default'].registerComponent('PlayToggle', PlayToggle);
  4276. exports['default'] = PlayToggle;
  4277. module.exports = exports['default'];
  4278. },{"../button.js":64,"../component.js":67}],73:[function(_dereq_,module,exports){
  4279. /**
  4280. * @file playback-rate-menu-button.js
  4281. */
  4282. 'use strict';
  4283. exports.__esModule = true;
  4284. 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; } }
  4285. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4286. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4287. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4288. var _menuMenuButtonJs = _dereq_('../../menu/menu-button.js');
  4289. var _menuMenuButtonJs2 = _interopRequireDefault(_menuMenuButtonJs);
  4290. var _menuMenuJs = _dereq_('../../menu/menu.js');
  4291. var _menuMenuJs2 = _interopRequireDefault(_menuMenuJs);
  4292. var _playbackRateMenuItemJs = _dereq_('./playback-rate-menu-item.js');
  4293. var _playbackRateMenuItemJs2 = _interopRequireDefault(_playbackRateMenuItemJs);
  4294. var _componentJs = _dereq_('../../component.js');
  4295. var _componentJs2 = _interopRequireDefault(_componentJs);
  4296. var _utilsDomJs = _dereq_('../../utils/dom.js');
  4297. var Dom = _interopRequireWildcard(_utilsDomJs);
  4298. /**
  4299. * The component for controlling the playback rate
  4300. *
  4301. * @param {Player|Object} player
  4302. * @param {Object=} options
  4303. * @extends MenuButton
  4304. * @class PlaybackRateMenuButton
  4305. */
  4306. var PlaybackRateMenuButton = (function (_MenuButton) {
  4307. _inherits(PlaybackRateMenuButton, _MenuButton);
  4308. function PlaybackRateMenuButton(player, options) {
  4309. _classCallCheck(this, PlaybackRateMenuButton);
  4310. _MenuButton.call(this, player, options);
  4311. this.updateVisibility();
  4312. this.updateLabel();
  4313. this.on(player, 'loadstart', this.updateVisibility);
  4314. this.on(player, 'ratechange', this.updateLabel);
  4315. }
  4316. /**
  4317. * Create the component's DOM element
  4318. *
  4319. * @return {Element}
  4320. * @method createEl
  4321. */
  4322. PlaybackRateMenuButton.prototype.createEl = function createEl() {
  4323. var el = _MenuButton.prototype.createEl.call(this);
  4324. this.labelEl_ = Dom.createEl('div', {
  4325. className: 'vjs-playback-rate-value',
  4326. innerHTML: 1.0
  4327. });
  4328. el.appendChild(this.labelEl_);
  4329. return el;
  4330. };
  4331. /**
  4332. * Allow sub components to stack CSS class names
  4333. *
  4334. * @return {String} The constructed class name
  4335. * @method buildCSSClass
  4336. */
  4337. PlaybackRateMenuButton.prototype.buildCSSClass = function buildCSSClass() {
  4338. return 'vjs-playback-rate ' + _MenuButton.prototype.buildCSSClass.call(this);
  4339. };
  4340. /**
  4341. * Create the playback rate menu
  4342. *
  4343. * @return {Menu} Menu object populated with items
  4344. * @method createMenu
  4345. */
  4346. PlaybackRateMenuButton.prototype.createMenu = function createMenu() {
  4347. var menu = new _menuMenuJs2['default'](this.player());
  4348. var rates = this.playbackRates();
  4349. if (rates) {
  4350. for (var i = rates.length - 1; i >= 0; i--) {
  4351. menu.addChild(new _playbackRateMenuItemJs2['default'](this.player(), { 'rate': rates[i] + 'x' }));
  4352. }
  4353. }
  4354. return menu;
  4355. };
  4356. /**
  4357. * Updates ARIA accessibility attributes
  4358. *
  4359. * @method updateARIAAttributes
  4360. */
  4361. PlaybackRateMenuButton.prototype.updateARIAAttributes = function updateARIAAttributes() {
  4362. // Current playback rate
  4363. this.el().setAttribute('aria-valuenow', this.player().playbackRate());
  4364. };
  4365. /**
  4366. * Handle menu item click
  4367. *
  4368. * @method handleClick
  4369. */
  4370. PlaybackRateMenuButton.prototype.handleClick = function handleClick() {
  4371. // select next rate option
  4372. var currentRate = this.player().playbackRate();
  4373. var rates = this.playbackRates();
  4374. // this will select first one if the last one currently selected
  4375. var newRate = rates[0];
  4376. for (var i = 0; i < rates.length; i++) {
  4377. if (rates[i] > currentRate) {
  4378. newRate = rates[i];
  4379. break;
  4380. }
  4381. }
  4382. this.player().playbackRate(newRate);
  4383. };
  4384. /**
  4385. * Get possible playback rates
  4386. *
  4387. * @return {Array} Possible playback rates
  4388. * @method playbackRates
  4389. */
  4390. PlaybackRateMenuButton.prototype.playbackRates = function playbackRates() {
  4391. return this.options_['playbackRates'] || this.options_.playerOptions && this.options_.playerOptions['playbackRates'];
  4392. };
  4393. /**
  4394. * Get supported playback rates
  4395. *
  4396. * @return {Array} Supported playback rates
  4397. * @method playbackRateSupported
  4398. */
  4399. PlaybackRateMenuButton.prototype.playbackRateSupported = function playbackRateSupported() {
  4400. return this.player().tech_ && this.player().tech_['featuresPlaybackRate'] && this.playbackRates() && this.playbackRates().length > 0;
  4401. };
  4402. /**
  4403. * Hide playback rate controls when they're no playback rate options to select
  4404. *
  4405. * @method updateVisibility
  4406. */
  4407. PlaybackRateMenuButton.prototype.updateVisibility = function updateVisibility() {
  4408. if (this.playbackRateSupported()) {
  4409. this.removeClass('vjs-hidden');
  4410. } else {
  4411. this.addClass('vjs-hidden');
  4412. }
  4413. };
  4414. /**
  4415. * Update button label when rate changed
  4416. *
  4417. * @method updateLabel
  4418. */
  4419. PlaybackRateMenuButton.prototype.updateLabel = function updateLabel() {
  4420. if (this.playbackRateSupported()) {
  4421. this.labelEl_.innerHTML = this.player().playbackRate() + 'x';
  4422. }
  4423. };
  4424. return PlaybackRateMenuButton;
  4425. })(_menuMenuButtonJs2['default']);
  4426. PlaybackRateMenuButton.prototype.controlText_ = 'Playback Rate';
  4427. _componentJs2['default'].registerComponent('PlaybackRateMenuButton', PlaybackRateMenuButton);
  4428. exports['default'] = PlaybackRateMenuButton;
  4429. module.exports = exports['default'];
  4430. },{"../../component.js":67,"../../menu/menu-button.js":104,"../../menu/menu.js":106,"../../utils/dom.js":132,"./playback-rate-menu-item.js":74}],74:[function(_dereq_,module,exports){
  4431. /**
  4432. * @file playback-rate-menu-item.js
  4433. */
  4434. 'use strict';
  4435. exports.__esModule = true;
  4436. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4437. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4438. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4439. var _menuMenuItemJs = _dereq_('../../menu/menu-item.js');
  4440. var _menuMenuItemJs2 = _interopRequireDefault(_menuMenuItemJs);
  4441. var _componentJs = _dereq_('../../component.js');
  4442. var _componentJs2 = _interopRequireDefault(_componentJs);
  4443. /**
  4444. * The specific menu item type for selecting a playback rate
  4445. *
  4446. * @param {Player|Object} player
  4447. * @param {Object=} options
  4448. * @extends MenuItem
  4449. * @class PlaybackRateMenuItem
  4450. */
  4451. var PlaybackRateMenuItem = (function (_MenuItem) {
  4452. _inherits(PlaybackRateMenuItem, _MenuItem);
  4453. function PlaybackRateMenuItem(player, options) {
  4454. _classCallCheck(this, PlaybackRateMenuItem);
  4455. var label = options['rate'];
  4456. var rate = parseFloat(label, 10);
  4457. // Modify options for parent MenuItem class's init.
  4458. options['label'] = label;
  4459. options['selected'] = rate === 1;
  4460. _MenuItem.call(this, player, options);
  4461. this.label = label;
  4462. this.rate = rate;
  4463. this.on(player, 'ratechange', this.update);
  4464. }
  4465. /**
  4466. * Handle click on menu item
  4467. *
  4468. * @method handleClick
  4469. */
  4470. PlaybackRateMenuItem.prototype.handleClick = function handleClick() {
  4471. _MenuItem.prototype.handleClick.call(this);
  4472. this.player().playbackRate(this.rate);
  4473. };
  4474. /**
  4475. * Update playback rate with selected rate
  4476. *
  4477. * @method update
  4478. */
  4479. PlaybackRateMenuItem.prototype.update = function update() {
  4480. this.selected(this.player().playbackRate() === this.rate);
  4481. };
  4482. return PlaybackRateMenuItem;
  4483. })(_menuMenuItemJs2['default']);
  4484. PlaybackRateMenuItem.prototype.contentElType = 'button';
  4485. _componentJs2['default'].registerComponent('PlaybackRateMenuItem', PlaybackRateMenuItem);
  4486. exports['default'] = PlaybackRateMenuItem;
  4487. module.exports = exports['default'];
  4488. },{"../../component.js":67,"../../menu/menu-item.js":105}],75:[function(_dereq_,module,exports){
  4489. /**
  4490. * @file load-progress-bar.js
  4491. */
  4492. 'use strict';
  4493. exports.__esModule = true;
  4494. 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; } }
  4495. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4496. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4497. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4498. var _componentJs = _dereq_('../../component.js');
  4499. var _componentJs2 = _interopRequireDefault(_componentJs);
  4500. var _utilsDomJs = _dereq_('../../utils/dom.js');
  4501. var Dom = _interopRequireWildcard(_utilsDomJs);
  4502. /**
  4503. * Shows load progress
  4504. *
  4505. * @param {Player|Object} player
  4506. * @param {Object=} options
  4507. * @extends Component
  4508. * @class LoadProgressBar
  4509. */
  4510. var LoadProgressBar = (function (_Component) {
  4511. _inherits(LoadProgressBar, _Component);
  4512. function LoadProgressBar(player, options) {
  4513. _classCallCheck(this, LoadProgressBar);
  4514. _Component.call(this, player, options);
  4515. this.on(player, 'progress', this.update);
  4516. }
  4517. /**
  4518. * Create the component's DOM element
  4519. *
  4520. * @return {Element}
  4521. * @method createEl
  4522. */
  4523. LoadProgressBar.prototype.createEl = function createEl() {
  4524. return _Component.prototype.createEl.call(this, 'div', {
  4525. className: 'vjs-load-progress',
  4526. innerHTML: '<span class="vjs-control-text"><span>' + this.localize('Loaded') + '</span>: 0%</span>'
  4527. });
  4528. };
  4529. /**
  4530. * Update progress bar
  4531. *
  4532. * @method update
  4533. */
  4534. LoadProgressBar.prototype.update = function update() {
  4535. var buffered = this.player_.buffered();
  4536. var duration = this.player_.duration();
  4537. var bufferedEnd = this.player_.bufferedEnd();
  4538. var children = this.el_.children;
  4539. // get the percent width of a time compared to the total end
  4540. var percentify = function percentify(time, end) {
  4541. var percent = time / end || 0; // no NaN
  4542. return (percent >= 1 ? 1 : percent) * 100 + '%';
  4543. };
  4544. // update the width of the progress bar
  4545. this.el_.style.width = percentify(bufferedEnd, duration);
  4546. // add child elements to represent the individual buffered time ranges
  4547. for (var i = 0; i < buffered.length; i++) {
  4548. var start = buffered.start(i);
  4549. var end = buffered.end(i);
  4550. var part = children[i];
  4551. if (!part) {
  4552. part = this.el_.appendChild(Dom.createEl());
  4553. }
  4554. // set the percent based on the width of the progress bar (bufferedEnd)
  4555. part.style.left = percentify(start, bufferedEnd);
  4556. part.style.width = percentify(end - start, bufferedEnd);
  4557. }
  4558. // remove unused buffered range elements
  4559. for (var i = children.length; i > buffered.length; i--) {
  4560. this.el_.removeChild(children[i - 1]);
  4561. }
  4562. };
  4563. return LoadProgressBar;
  4564. })(_componentJs2['default']);
  4565. _componentJs2['default'].registerComponent('LoadProgressBar', LoadProgressBar);
  4566. exports['default'] = LoadProgressBar;
  4567. module.exports = exports['default'];
  4568. },{"../../component.js":67,"../../utils/dom.js":132}],76:[function(_dereq_,module,exports){
  4569. /**
  4570. * @file mouse-time-display.js
  4571. */
  4572. 'use strict';
  4573. exports.__esModule = true;
  4574. 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; } }
  4575. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4576. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4577. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4578. var _componentJs = _dereq_('../../component.js');
  4579. var _componentJs2 = _interopRequireDefault(_componentJs);
  4580. var _utilsDomJs = _dereq_('../../utils/dom.js');
  4581. var Dom = _interopRequireWildcard(_utilsDomJs);
  4582. var _utilsFnJs = _dereq_('../../utils/fn.js');
  4583. var Fn = _interopRequireWildcard(_utilsFnJs);
  4584. var _utilsFormatTimeJs = _dereq_('../../utils/format-time.js');
  4585. var _utilsFormatTimeJs2 = _interopRequireDefault(_utilsFormatTimeJs);
  4586. var _lodashCompatFunctionThrottle = _dereq_('lodash-compat/function/throttle');
  4587. var _lodashCompatFunctionThrottle2 = _interopRequireDefault(_lodashCompatFunctionThrottle);
  4588. /**
  4589. * The Mouse Time Display component shows the time you will seek to
  4590. * when hovering over the progress bar
  4591. *
  4592. * @param {Player|Object} player
  4593. * @param {Object=} options
  4594. * @extends Component
  4595. * @class MouseTimeDisplay
  4596. */
  4597. var MouseTimeDisplay = (function (_Component) {
  4598. _inherits(MouseTimeDisplay, _Component);
  4599. function MouseTimeDisplay(player, options) {
  4600. var _this = this;
  4601. _classCallCheck(this, MouseTimeDisplay);
  4602. _Component.call(this, player, options);
  4603. this.update(0, 0);
  4604. player.on('ready', function () {
  4605. _this.on(player.controlBar.progressControl.el(), 'mousemove', _lodashCompatFunctionThrottle2['default'](Fn.bind(_this, _this.handleMouseMove), 25));
  4606. });
  4607. }
  4608. /**
  4609. * Create the component's DOM element
  4610. *
  4611. * @return {Element}
  4612. * @method createEl
  4613. */
  4614. MouseTimeDisplay.prototype.createEl = function createEl() {
  4615. return _Component.prototype.createEl.call(this, 'div', {
  4616. className: 'vjs-mouse-display'
  4617. });
  4618. };
  4619. MouseTimeDisplay.prototype.handleMouseMove = function handleMouseMove(event) {
  4620. var duration = this.player_.duration();
  4621. var newTime = this.calculateDistance(event) * duration;
  4622. var position = event.pageX - Dom.findElPosition(this.el().parentNode).left;
  4623. this.update(newTime, position);
  4624. };
  4625. MouseTimeDisplay.prototype.update = function update(newTime, position) {
  4626. var time = _utilsFormatTimeJs2['default'](newTime, this.player_.duration());
  4627. this.el().style.left = position + 'px';
  4628. this.el().setAttribute('data-current-time', time);
  4629. };
  4630. MouseTimeDisplay.prototype.calculateDistance = function calculateDistance(event) {
  4631. return Dom.getPointerPosition(this.el().parentNode, event).x;
  4632. };
  4633. return MouseTimeDisplay;
  4634. })(_componentJs2['default']);
  4635. _componentJs2['default'].registerComponent('MouseTimeDisplay', MouseTimeDisplay);
  4636. exports['default'] = MouseTimeDisplay;
  4637. module.exports = exports['default'];
  4638. },{"../../component.js":67,"../../utils/dom.js":132,"../../utils/fn.js":134,"../../utils/format-time.js":135,"lodash-compat/function/throttle":7}],77:[function(_dereq_,module,exports){
  4639. /**
  4640. * @file play-progress-bar.js
  4641. */
  4642. 'use strict';
  4643. exports.__esModule = true;
  4644. 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; } }
  4645. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4646. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4647. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4648. var _componentJs = _dereq_('../../component.js');
  4649. var _componentJs2 = _interopRequireDefault(_componentJs);
  4650. var _utilsFnJs = _dereq_('../../utils/fn.js');
  4651. var Fn = _interopRequireWildcard(_utilsFnJs);
  4652. var _utilsFormatTimeJs = _dereq_('../../utils/format-time.js');
  4653. var _utilsFormatTimeJs2 = _interopRequireDefault(_utilsFormatTimeJs);
  4654. /**
  4655. * Shows play progress
  4656. *
  4657. * @param {Player|Object} player
  4658. * @param {Object=} options
  4659. * @extends Component
  4660. * @class PlayProgressBar
  4661. */
  4662. var PlayProgressBar = (function (_Component) {
  4663. _inherits(PlayProgressBar, _Component);
  4664. function PlayProgressBar(player, options) {
  4665. _classCallCheck(this, PlayProgressBar);
  4666. _Component.call(this, player, options);
  4667. this.updateDataAttr();
  4668. this.on(player, 'timeupdate', this.updateDataAttr);
  4669. player.ready(Fn.bind(this, this.updateDataAttr));
  4670. }
  4671. /**
  4672. * Create the component's DOM element
  4673. *
  4674. * @return {Element}
  4675. * @method createEl
  4676. */
  4677. PlayProgressBar.prototype.createEl = function createEl() {
  4678. return _Component.prototype.createEl.call(this, 'div', {
  4679. className: 'vjs-play-progress vjs-slider-bar',
  4680. innerHTML: '<span class="vjs-control-text"><span>' + this.localize('Progress') + '</span>: 0%</span>'
  4681. });
  4682. };
  4683. PlayProgressBar.prototype.updateDataAttr = function updateDataAttr() {
  4684. var time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  4685. this.el_.setAttribute('data-current-time', _utilsFormatTimeJs2['default'](time, this.player_.duration()));
  4686. };
  4687. return PlayProgressBar;
  4688. })(_componentJs2['default']);
  4689. _componentJs2['default'].registerComponent('PlayProgressBar', PlayProgressBar);
  4690. exports['default'] = PlayProgressBar;
  4691. module.exports = exports['default'];
  4692. },{"../../component.js":67,"../../utils/fn.js":134,"../../utils/format-time.js":135}],78:[function(_dereq_,module,exports){
  4693. /**
  4694. * @file progress-control.js
  4695. */
  4696. 'use strict';
  4697. exports.__esModule = true;
  4698. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4699. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4700. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4701. var _componentJs = _dereq_('../../component.js');
  4702. var _componentJs2 = _interopRequireDefault(_componentJs);
  4703. var _seekBarJs = _dereq_('./seek-bar.js');
  4704. var _seekBarJs2 = _interopRequireDefault(_seekBarJs);
  4705. var _mouseTimeDisplayJs = _dereq_('./mouse-time-display.js');
  4706. var _mouseTimeDisplayJs2 = _interopRequireDefault(_mouseTimeDisplayJs);
  4707. /**
  4708. * The Progress Control component contains the seek bar, load progress,
  4709. * and play progress
  4710. *
  4711. * @param {Player|Object} player
  4712. * @param {Object=} options
  4713. * @extends Component
  4714. * @class ProgressControl
  4715. */
  4716. var ProgressControl = (function (_Component) {
  4717. _inherits(ProgressControl, _Component);
  4718. function ProgressControl() {
  4719. _classCallCheck(this, ProgressControl);
  4720. _Component.apply(this, arguments);
  4721. }
  4722. /**
  4723. * Create the component's DOM element
  4724. *
  4725. * @return {Element}
  4726. * @method createEl
  4727. */
  4728. ProgressControl.prototype.createEl = function createEl() {
  4729. return _Component.prototype.createEl.call(this, 'div', {
  4730. className: 'vjs-progress-control vjs-control'
  4731. });
  4732. };
  4733. return ProgressControl;
  4734. })(_componentJs2['default']);
  4735. ProgressControl.prototype.options_ = {
  4736. children: ['seekBar']
  4737. };
  4738. _componentJs2['default'].registerComponent('ProgressControl', ProgressControl);
  4739. exports['default'] = ProgressControl;
  4740. module.exports = exports['default'];
  4741. },{"../../component.js":67,"./mouse-time-display.js":76,"./seek-bar.js":79}],79:[function(_dereq_,module,exports){
  4742. /**
  4743. * @file seek-bar.js
  4744. */
  4745. 'use strict';
  4746. exports.__esModule = true;
  4747. 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; } }
  4748. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4749. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4750. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4751. var _sliderSliderJs = _dereq_('../../slider/slider.js');
  4752. var _sliderSliderJs2 = _interopRequireDefault(_sliderSliderJs);
  4753. var _componentJs = _dereq_('../../component.js');
  4754. var _componentJs2 = _interopRequireDefault(_componentJs);
  4755. var _loadProgressBarJs = _dereq_('./load-progress-bar.js');
  4756. var _loadProgressBarJs2 = _interopRequireDefault(_loadProgressBarJs);
  4757. var _playProgressBarJs = _dereq_('./play-progress-bar.js');
  4758. var _playProgressBarJs2 = _interopRequireDefault(_playProgressBarJs);
  4759. var _utilsFnJs = _dereq_('../../utils/fn.js');
  4760. var Fn = _interopRequireWildcard(_utilsFnJs);
  4761. var _utilsFormatTimeJs = _dereq_('../../utils/format-time.js');
  4762. var _utilsFormatTimeJs2 = _interopRequireDefault(_utilsFormatTimeJs);
  4763. var _objectAssign = _dereq_('object.assign');
  4764. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  4765. /**
  4766. * Seek Bar and holder for the progress bars
  4767. *
  4768. * @param {Player|Object} player
  4769. * @param {Object=} options
  4770. * @extends Slider
  4771. * @class SeekBar
  4772. */
  4773. var SeekBar = (function (_Slider) {
  4774. _inherits(SeekBar, _Slider);
  4775. function SeekBar(player, options) {
  4776. _classCallCheck(this, SeekBar);
  4777. _Slider.call(this, player, options);
  4778. this.on(player, 'timeupdate', this.updateARIAAttributes);
  4779. player.ready(Fn.bind(this, this.updateARIAAttributes));
  4780. }
  4781. /**
  4782. * Create the component's DOM element
  4783. *
  4784. * @return {Element}
  4785. * @method createEl
  4786. */
  4787. SeekBar.prototype.createEl = function createEl() {
  4788. return _Slider.prototype.createEl.call(this, 'div', {
  4789. className: 'vjs-progress-holder'
  4790. }, {
  4791. 'aria-label': 'video progress bar'
  4792. });
  4793. };
  4794. /**
  4795. * Update ARIA accessibility attributes
  4796. *
  4797. * @method updateARIAAttributes
  4798. */
  4799. SeekBar.prototype.updateARIAAttributes = function updateARIAAttributes() {
  4800. // Allows for smooth scrubbing, when player can't keep up.
  4801. var time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  4802. this.el_.setAttribute('aria-valuenow', (this.getPercent() * 100).toFixed(2)); // machine readable value of progress bar (percentage complete)
  4803. this.el_.setAttribute('aria-valuetext', _utilsFormatTimeJs2['default'](time, this.player_.duration())); // human readable value of progress bar (time complete)
  4804. };
  4805. /**
  4806. * Get percentage of video played
  4807. *
  4808. * @return {Number} Percentage played
  4809. * @method getPercent
  4810. */
  4811. SeekBar.prototype.getPercent = function getPercent() {
  4812. var percent = this.player_.currentTime() / this.player_.duration();
  4813. return percent >= 1 ? 1 : percent;
  4814. };
  4815. /**
  4816. * Handle mouse down on seek bar
  4817. *
  4818. * @method handleMouseDown
  4819. */
  4820. SeekBar.prototype.handleMouseDown = function handleMouseDown(event) {
  4821. _Slider.prototype.handleMouseDown.call(this, event);
  4822. this.player_.scrubbing(true);
  4823. this.videoWasPlaying = !this.player_.paused();
  4824. this.player_.pause();
  4825. };
  4826. /**
  4827. * Handle mouse move on seek bar
  4828. *
  4829. * @method handleMouseMove
  4830. */
  4831. SeekBar.prototype.handleMouseMove = function handleMouseMove(event) {
  4832. var newTime = this.calculateDistance(event) * this.player_.duration();
  4833. // Don't let video end while scrubbing.
  4834. if (newTime === this.player_.duration()) {
  4835. newTime = newTime - 0.1;
  4836. }
  4837. // Set new time (tell player to seek to new time)
  4838. this.player_.currentTime(newTime);
  4839. };
  4840. /**
  4841. * Handle mouse up on seek bar
  4842. *
  4843. * @method handleMouseUp
  4844. */
  4845. SeekBar.prototype.handleMouseUp = function handleMouseUp(event) {
  4846. _Slider.prototype.handleMouseUp.call(this, event);
  4847. this.player_.scrubbing(false);
  4848. if (this.videoWasPlaying) {
  4849. this.player_.play();
  4850. }
  4851. };
  4852. /**
  4853. * Move more quickly fast forward for keyboard-only users
  4854. *
  4855. * @method stepForward
  4856. */
  4857. SeekBar.prototype.stepForward = function stepForward() {
  4858. this.player_.currentTime(this.player_.currentTime() + 5); // more quickly fast forward for keyboard-only users
  4859. };
  4860. /**
  4861. * Move more quickly rewind for keyboard-only users
  4862. *
  4863. * @method stepBack
  4864. */
  4865. SeekBar.prototype.stepBack = function stepBack() {
  4866. this.player_.currentTime(this.player_.currentTime() - 5); // more quickly rewind for keyboard-only users
  4867. };
  4868. return SeekBar;
  4869. })(_sliderSliderJs2['default']);
  4870. SeekBar.prototype.options_ = {
  4871. children: ['loadProgressBar', 'mouseTimeDisplay', 'playProgressBar'],
  4872. 'barName': 'playProgressBar'
  4873. };
  4874. SeekBar.prototype.playerEvent = 'timeupdate';
  4875. _componentJs2['default'].registerComponent('SeekBar', SeekBar);
  4876. exports['default'] = SeekBar;
  4877. module.exports = exports['default'];
  4878. },{"../../component.js":67,"../../slider/slider.js":114,"../../utils/fn.js":134,"../../utils/format-time.js":135,"./load-progress-bar.js":75,"./play-progress-bar.js":77,"object.assign":45}],80:[function(_dereq_,module,exports){
  4879. /**
  4880. * @file custom-control-spacer.js
  4881. */
  4882. 'use strict';
  4883. exports.__esModule = true;
  4884. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4885. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4886. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4887. var _spacerJs = _dereq_('./spacer.js');
  4888. var _spacerJs2 = _interopRequireDefault(_spacerJs);
  4889. var _componentJs = _dereq_('../../component.js');
  4890. var _componentJs2 = _interopRequireDefault(_componentJs);
  4891. /**
  4892. * Spacer specifically meant to be used as an insertion point for new plugins, etc.
  4893. *
  4894. * @extends Spacer
  4895. * @class CustomControlSpacer
  4896. */
  4897. var CustomControlSpacer = (function (_Spacer) {
  4898. _inherits(CustomControlSpacer, _Spacer);
  4899. function CustomControlSpacer() {
  4900. _classCallCheck(this, CustomControlSpacer);
  4901. _Spacer.apply(this, arguments);
  4902. }
  4903. /**
  4904. * Allow sub components to stack CSS class names
  4905. *
  4906. * @return {String} The constructed class name
  4907. * @method buildCSSClass
  4908. */
  4909. CustomControlSpacer.prototype.buildCSSClass = function buildCSSClass() {
  4910. return 'vjs-custom-control-spacer ' + _Spacer.prototype.buildCSSClass.call(this);
  4911. };
  4912. /**
  4913. * Create the component's DOM element
  4914. *
  4915. * @return {Element}
  4916. * @method createEl
  4917. */
  4918. CustomControlSpacer.prototype.createEl = function createEl() {
  4919. var el = _Spacer.prototype.createEl.call(this, {
  4920. className: this.buildCSSClass()
  4921. });
  4922. // No-flex/table-cell mode requires there be some content
  4923. // in the cell to fill the remaining space of the table.
  4924. el.innerHTML = '&nbsp;';
  4925. return el;
  4926. };
  4927. return CustomControlSpacer;
  4928. })(_spacerJs2['default']);
  4929. _componentJs2['default'].registerComponent('CustomControlSpacer', CustomControlSpacer);
  4930. exports['default'] = CustomControlSpacer;
  4931. module.exports = exports['default'];
  4932. },{"../../component.js":67,"./spacer.js":81}],81:[function(_dereq_,module,exports){
  4933. /**
  4934. * @file spacer.js
  4935. */
  4936. 'use strict';
  4937. exports.__esModule = true;
  4938. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4939. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4940. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4941. var _componentJs = _dereq_('../../component.js');
  4942. var _componentJs2 = _interopRequireDefault(_componentJs);
  4943. /**
  4944. * Just an empty spacer element that can be used as an append point for plugins, etc.
  4945. * Also can be used to create space between elements when necessary.
  4946. *
  4947. * @extends Component
  4948. * @class Spacer
  4949. */
  4950. var Spacer = (function (_Component) {
  4951. _inherits(Spacer, _Component);
  4952. function Spacer() {
  4953. _classCallCheck(this, Spacer);
  4954. _Component.apply(this, arguments);
  4955. }
  4956. /**
  4957. * Allow sub components to stack CSS class names
  4958. *
  4959. * @return {String} The constructed class name
  4960. * @method buildCSSClass
  4961. */
  4962. Spacer.prototype.buildCSSClass = function buildCSSClass() {
  4963. return 'vjs-spacer ' + _Component.prototype.buildCSSClass.call(this);
  4964. };
  4965. /**
  4966. * Create the component's DOM element
  4967. *
  4968. * @return {Element}
  4969. * @method createEl
  4970. */
  4971. Spacer.prototype.createEl = function createEl() {
  4972. return _Component.prototype.createEl.call(this, 'div', {
  4973. className: this.buildCSSClass()
  4974. });
  4975. };
  4976. return Spacer;
  4977. })(_componentJs2['default']);
  4978. _componentJs2['default'].registerComponent('Spacer', Spacer);
  4979. exports['default'] = Spacer;
  4980. module.exports = exports['default'];
  4981. },{"../../component.js":67}],82:[function(_dereq_,module,exports){
  4982. /**
  4983. * @file caption-settings-menu-item.js
  4984. */
  4985. 'use strict';
  4986. exports.__esModule = true;
  4987. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  4988. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4989. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  4990. var _textTrackMenuItemJs = _dereq_('./text-track-menu-item.js');
  4991. var _textTrackMenuItemJs2 = _interopRequireDefault(_textTrackMenuItemJs);
  4992. var _componentJs = _dereq_('../../component.js');
  4993. var _componentJs2 = _interopRequireDefault(_componentJs);
  4994. /**
  4995. * The menu item for caption track settings menu
  4996. *
  4997. * @param {Player|Object} player
  4998. * @param {Object=} options
  4999. * @extends TextTrackMenuItem
  5000. * @class CaptionSettingsMenuItem
  5001. */
  5002. var CaptionSettingsMenuItem = (function (_TextTrackMenuItem) {
  5003. _inherits(CaptionSettingsMenuItem, _TextTrackMenuItem);
  5004. function CaptionSettingsMenuItem(player, options) {
  5005. _classCallCheck(this, CaptionSettingsMenuItem);
  5006. options['track'] = {
  5007. 'kind': options['kind'],
  5008. 'player': player,
  5009. 'label': options['kind'] + ' settings',
  5010. 'selectable': false,
  5011. 'default': false,
  5012. mode: 'disabled'
  5013. };
  5014. // CaptionSettingsMenuItem has no concept of 'selected'
  5015. options['selectable'] = false;
  5016. _TextTrackMenuItem.call(this, player, options);
  5017. this.addClass('vjs-texttrack-settings');
  5018. this.controlText(', opens ' + options['kind'] + ' settings dialog');
  5019. }
  5020. /**
  5021. * Handle click on menu item
  5022. *
  5023. * @method handleClick
  5024. */
  5025. CaptionSettingsMenuItem.prototype.handleClick = function handleClick() {
  5026. this.player().getChild('textTrackSettings').show();
  5027. this.player().getChild('textTrackSettings').el_.focus();
  5028. };
  5029. return CaptionSettingsMenuItem;
  5030. })(_textTrackMenuItemJs2['default']);
  5031. _componentJs2['default'].registerComponent('CaptionSettingsMenuItem', CaptionSettingsMenuItem);
  5032. exports['default'] = CaptionSettingsMenuItem;
  5033. module.exports = exports['default'];
  5034. },{"../../component.js":67,"./text-track-menu-item.js":89}],83:[function(_dereq_,module,exports){
  5035. /**
  5036. * @file captions-button.js
  5037. */
  5038. 'use strict';
  5039. exports.__esModule = true;
  5040. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5041. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5042. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5043. var _textTrackButtonJs = _dereq_('./text-track-button.js');
  5044. var _textTrackButtonJs2 = _interopRequireDefault(_textTrackButtonJs);
  5045. var _componentJs = _dereq_('../../component.js');
  5046. var _componentJs2 = _interopRequireDefault(_componentJs);
  5047. var _captionSettingsMenuItemJs = _dereq_('./caption-settings-menu-item.js');
  5048. var _captionSettingsMenuItemJs2 = _interopRequireDefault(_captionSettingsMenuItemJs);
  5049. /**
  5050. * The button component for toggling and selecting captions
  5051. *
  5052. * @param {Object} player Player object
  5053. * @param {Object=} options Object of option names and values
  5054. * @param {Function=} ready Ready callback function
  5055. * @extends TextTrackButton
  5056. * @class CaptionsButton
  5057. */
  5058. var CaptionsButton = (function (_TextTrackButton) {
  5059. _inherits(CaptionsButton, _TextTrackButton);
  5060. function CaptionsButton(player, options, ready) {
  5061. _classCallCheck(this, CaptionsButton);
  5062. _TextTrackButton.call(this, player, options, ready);
  5063. this.el_.setAttribute('aria-label', 'Captions Menu');
  5064. }
  5065. /**
  5066. * Allow sub components to stack CSS class names
  5067. *
  5068. * @return {String} The constructed class name
  5069. * @method buildCSSClass
  5070. */
  5071. CaptionsButton.prototype.buildCSSClass = function buildCSSClass() {
  5072. return 'vjs-captions-button ' + _TextTrackButton.prototype.buildCSSClass.call(this);
  5073. };
  5074. /**
  5075. * Update caption menu items
  5076. *
  5077. * @method update
  5078. */
  5079. CaptionsButton.prototype.update = function update() {
  5080. var threshold = 2;
  5081. _TextTrackButton.prototype.update.call(this);
  5082. // if native, then threshold is 1 because no settings button
  5083. if (this.player().tech_ && this.player().tech_['featuresNativeTextTracks']) {
  5084. threshold = 1;
  5085. }
  5086. if (this.items && this.items.length > threshold) {
  5087. this.show();
  5088. } else {
  5089. this.hide();
  5090. }
  5091. };
  5092. /**
  5093. * Create caption menu items
  5094. *
  5095. * @return {Array} Array of menu items
  5096. * @method createItems
  5097. */
  5098. CaptionsButton.prototype.createItems = function createItems() {
  5099. var items = [];
  5100. if (!(this.player().tech_ && this.player().tech_['featuresNativeTextTracks'])) {
  5101. items.push(new _captionSettingsMenuItemJs2['default'](this.player_, { 'kind': this.kind_ }));
  5102. }
  5103. return _TextTrackButton.prototype.createItems.call(this, items);
  5104. };
  5105. return CaptionsButton;
  5106. })(_textTrackButtonJs2['default']);
  5107. CaptionsButton.prototype.kind_ = 'captions';
  5108. CaptionsButton.prototype.controlText_ = 'Captions';
  5109. _componentJs2['default'].registerComponent('CaptionsButton', CaptionsButton);
  5110. exports['default'] = CaptionsButton;
  5111. module.exports = exports['default'];
  5112. },{"../../component.js":67,"./caption-settings-menu-item.js":82,"./text-track-button.js":88}],84:[function(_dereq_,module,exports){
  5113. /**
  5114. * @file chapters-button.js
  5115. */
  5116. 'use strict';
  5117. exports.__esModule = true;
  5118. 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; } }
  5119. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5120. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5121. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5122. var _textTrackButtonJs = _dereq_('./text-track-button.js');
  5123. var _textTrackButtonJs2 = _interopRequireDefault(_textTrackButtonJs);
  5124. var _componentJs = _dereq_('../../component.js');
  5125. var _componentJs2 = _interopRequireDefault(_componentJs);
  5126. var _textTrackMenuItemJs = _dereq_('./text-track-menu-item.js');
  5127. var _textTrackMenuItemJs2 = _interopRequireDefault(_textTrackMenuItemJs);
  5128. var _chaptersTrackMenuItemJs = _dereq_('./chapters-track-menu-item.js');
  5129. var _chaptersTrackMenuItemJs2 = _interopRequireDefault(_chaptersTrackMenuItemJs);
  5130. var _menuMenuJs = _dereq_('../../menu/menu.js');
  5131. var _menuMenuJs2 = _interopRequireDefault(_menuMenuJs);
  5132. var _utilsDomJs = _dereq_('../../utils/dom.js');
  5133. var Dom = _interopRequireWildcard(_utilsDomJs);
  5134. var _utilsFnJs = _dereq_('../../utils/fn.js');
  5135. var Fn = _interopRequireWildcard(_utilsFnJs);
  5136. var _utilsToTitleCaseJs = _dereq_('../../utils/to-title-case.js');
  5137. var _utilsToTitleCaseJs2 = _interopRequireDefault(_utilsToTitleCaseJs);
  5138. var _globalWindow = _dereq_('global/window');
  5139. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  5140. /**
  5141. * The button component for toggling and selecting chapters
  5142. * Chapters act much differently than other text tracks
  5143. * Cues are navigation vs. other tracks of alternative languages
  5144. *
  5145. * @param {Object} player Player object
  5146. * @param {Object=} options Object of option names and values
  5147. * @param {Function=} ready Ready callback function
  5148. * @extends TextTrackButton
  5149. * @class ChaptersButton
  5150. */
  5151. var ChaptersButton = (function (_TextTrackButton) {
  5152. _inherits(ChaptersButton, _TextTrackButton);
  5153. function ChaptersButton(player, options, ready) {
  5154. _classCallCheck(this, ChaptersButton);
  5155. _TextTrackButton.call(this, player, options, ready);
  5156. this.el_.setAttribute('aria-label', 'Chapters Menu');
  5157. }
  5158. /**
  5159. * Allow sub components to stack CSS class names
  5160. *
  5161. * @return {String} The constructed class name
  5162. * @method buildCSSClass
  5163. */
  5164. ChaptersButton.prototype.buildCSSClass = function buildCSSClass() {
  5165. return 'vjs-chapters-button ' + _TextTrackButton.prototype.buildCSSClass.call(this);
  5166. };
  5167. /**
  5168. * Create a menu item for each text track
  5169. *
  5170. * @return {Array} Array of menu items
  5171. * @method createItems
  5172. */
  5173. ChaptersButton.prototype.createItems = function createItems() {
  5174. var items = [];
  5175. var tracks = this.player_.textTracks();
  5176. if (!tracks) {
  5177. return items;
  5178. }
  5179. for (var i = 0; i < tracks.length; i++) {
  5180. var track = tracks[i];
  5181. if (track['kind'] === this.kind_) {
  5182. items.push(new _textTrackMenuItemJs2['default'](this.player_, {
  5183. 'track': track
  5184. }));
  5185. }
  5186. }
  5187. return items;
  5188. };
  5189. /**
  5190. * Create menu from chapter buttons
  5191. *
  5192. * @return {Menu} Menu of chapter buttons
  5193. * @method createMenu
  5194. */
  5195. ChaptersButton.prototype.createMenu = function createMenu() {
  5196. var _this = this;
  5197. var tracks = this.player_.textTracks() || [];
  5198. var chaptersTrack = undefined;
  5199. var items = this.items = [];
  5200. for (var i = 0, _length = tracks.length; i < _length; i++) {
  5201. var track = tracks[i];
  5202. if (track['kind'] === this.kind_) {
  5203. chaptersTrack = track;
  5204. break;
  5205. }
  5206. }
  5207. var menu = this.menu;
  5208. if (menu === undefined) {
  5209. menu = new _menuMenuJs2['default'](this.player_);
  5210. var title = Dom.createEl('li', {
  5211. className: 'vjs-menu-title',
  5212. innerHTML: _utilsToTitleCaseJs2['default'](this.kind_),
  5213. tabIndex: -1
  5214. });
  5215. menu.children_.unshift(title);
  5216. Dom.insertElFirst(title, menu.contentEl());
  5217. }
  5218. if (chaptersTrack && chaptersTrack.cues == null) {
  5219. chaptersTrack['mode'] = 'hidden';
  5220. var remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(chaptersTrack);
  5221. if (remoteTextTrackEl) {
  5222. remoteTextTrackEl.addEventListener('load', function (event) {
  5223. return _this.update();
  5224. });
  5225. }
  5226. }
  5227. if (chaptersTrack && chaptersTrack.cues && chaptersTrack.cues.length > 0) {
  5228. var cues = chaptersTrack['cues'],
  5229. cue = undefined;
  5230. for (var i = 0, l = cues.length; i < l; i++) {
  5231. cue = cues[i];
  5232. var mi = new _chaptersTrackMenuItemJs2['default'](this.player_, {
  5233. 'track': chaptersTrack,
  5234. 'cue': cue
  5235. });
  5236. items.push(mi);
  5237. menu.addChild(mi);
  5238. }
  5239. this.addChild(menu);
  5240. }
  5241. if (this.items.length > 0) {
  5242. this.show();
  5243. }
  5244. return menu;
  5245. };
  5246. return ChaptersButton;
  5247. })(_textTrackButtonJs2['default']);
  5248. ChaptersButton.prototype.kind_ = 'chapters';
  5249. ChaptersButton.prototype.controlText_ = 'Chapters';
  5250. _componentJs2['default'].registerComponent('ChaptersButton', ChaptersButton);
  5251. exports['default'] = ChaptersButton;
  5252. module.exports = exports['default'];
  5253. },{"../../component.js":67,"../../menu/menu.js":106,"../../utils/dom.js":132,"../../utils/fn.js":134,"../../utils/to-title-case.js":141,"./chapters-track-menu-item.js":85,"./text-track-button.js":88,"./text-track-menu-item.js":89,"global/window":2}],85:[function(_dereq_,module,exports){
  5254. /**
  5255. * @file chapters-track-menu-item.js
  5256. */
  5257. 'use strict';
  5258. exports.__esModule = true;
  5259. 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; } }
  5260. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5261. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5262. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5263. var _menuMenuItemJs = _dereq_('../../menu/menu-item.js');
  5264. var _menuMenuItemJs2 = _interopRequireDefault(_menuMenuItemJs);
  5265. var _componentJs = _dereq_('../../component.js');
  5266. var _componentJs2 = _interopRequireDefault(_componentJs);
  5267. var _utilsFnJs = _dereq_('../../utils/fn.js');
  5268. var Fn = _interopRequireWildcard(_utilsFnJs);
  5269. /**
  5270. * The chapter track menu item
  5271. *
  5272. * @param {Player|Object} player
  5273. * @param {Object=} options
  5274. * @extends MenuItem
  5275. * @class ChaptersTrackMenuItem
  5276. */
  5277. var ChaptersTrackMenuItem = (function (_MenuItem) {
  5278. _inherits(ChaptersTrackMenuItem, _MenuItem);
  5279. function ChaptersTrackMenuItem(player, options) {
  5280. _classCallCheck(this, ChaptersTrackMenuItem);
  5281. var track = options['track'];
  5282. var cue = options['cue'];
  5283. var currentTime = player.currentTime();
  5284. // Modify options for parent MenuItem class's init.
  5285. options['label'] = cue.text;
  5286. options['selected'] = cue['startTime'] <= currentTime && currentTime < cue['endTime'];
  5287. _MenuItem.call(this, player, options);
  5288. this.track = track;
  5289. this.cue = cue;
  5290. track.addEventListener('cuechange', Fn.bind(this, this.update));
  5291. }
  5292. /**
  5293. * Handle click on menu item
  5294. *
  5295. * @method handleClick
  5296. */
  5297. ChaptersTrackMenuItem.prototype.handleClick = function handleClick() {
  5298. _MenuItem.prototype.handleClick.call(this);
  5299. this.player_.currentTime(this.cue.startTime);
  5300. this.update(this.cue.startTime);
  5301. };
  5302. /**
  5303. * Update chapter menu item
  5304. *
  5305. * @method update
  5306. */
  5307. ChaptersTrackMenuItem.prototype.update = function update() {
  5308. var cue = this.cue;
  5309. var currentTime = this.player_.currentTime();
  5310. // vjs.log(currentTime, cue.startTime);
  5311. this.selected(cue['startTime'] <= currentTime && currentTime < cue['endTime']);
  5312. };
  5313. return ChaptersTrackMenuItem;
  5314. })(_menuMenuItemJs2['default']);
  5315. _componentJs2['default'].registerComponent('ChaptersTrackMenuItem', ChaptersTrackMenuItem);
  5316. exports['default'] = ChaptersTrackMenuItem;
  5317. module.exports = exports['default'];
  5318. },{"../../component.js":67,"../../menu/menu-item.js":105,"../../utils/fn.js":134}],86:[function(_dereq_,module,exports){
  5319. /**
  5320. * @file off-text-track-menu-item.js
  5321. */
  5322. 'use strict';
  5323. exports.__esModule = true;
  5324. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5325. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5326. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5327. var _textTrackMenuItemJs = _dereq_('./text-track-menu-item.js');
  5328. var _textTrackMenuItemJs2 = _interopRequireDefault(_textTrackMenuItemJs);
  5329. var _componentJs = _dereq_('../../component.js');
  5330. var _componentJs2 = _interopRequireDefault(_componentJs);
  5331. /**
  5332. * A special menu item for turning of a specific type of text track
  5333. *
  5334. * @param {Player|Object} player
  5335. * @param {Object=} options
  5336. * @extends TextTrackMenuItem
  5337. * @class OffTextTrackMenuItem
  5338. */
  5339. var OffTextTrackMenuItem = (function (_TextTrackMenuItem) {
  5340. _inherits(OffTextTrackMenuItem, _TextTrackMenuItem);
  5341. function OffTextTrackMenuItem(player, options) {
  5342. _classCallCheck(this, OffTextTrackMenuItem);
  5343. // Create pseudo track info
  5344. // Requires options['kind']
  5345. options['track'] = {
  5346. 'kind': options['kind'],
  5347. 'player': player,
  5348. 'label': options['kind'] + ' off',
  5349. 'default': false,
  5350. 'mode': 'disabled'
  5351. };
  5352. // MenuItem is selectable
  5353. options['selectable'] = true;
  5354. _TextTrackMenuItem.call(this, player, options);
  5355. this.selected(true);
  5356. }
  5357. /**
  5358. * Handle text track change
  5359. *
  5360. * @param {Object} event Event object
  5361. * @method handleTracksChange
  5362. */
  5363. OffTextTrackMenuItem.prototype.handleTracksChange = function handleTracksChange(event) {
  5364. var tracks = this.player().textTracks();
  5365. var selected = true;
  5366. for (var i = 0, l = tracks.length; i < l; i++) {
  5367. var track = tracks[i];
  5368. if (track['kind'] === this.track['kind'] && track['mode'] === 'showing') {
  5369. selected = false;
  5370. break;
  5371. }
  5372. }
  5373. this.selected(selected);
  5374. };
  5375. return OffTextTrackMenuItem;
  5376. })(_textTrackMenuItemJs2['default']);
  5377. _componentJs2['default'].registerComponent('OffTextTrackMenuItem', OffTextTrackMenuItem);
  5378. exports['default'] = OffTextTrackMenuItem;
  5379. module.exports = exports['default'];
  5380. },{"../../component.js":67,"./text-track-menu-item.js":89}],87:[function(_dereq_,module,exports){
  5381. /**
  5382. * @file subtitles-button.js
  5383. */
  5384. 'use strict';
  5385. exports.__esModule = true;
  5386. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5387. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5388. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5389. var _textTrackButtonJs = _dereq_('./text-track-button.js');
  5390. var _textTrackButtonJs2 = _interopRequireDefault(_textTrackButtonJs);
  5391. var _componentJs = _dereq_('../../component.js');
  5392. var _componentJs2 = _interopRequireDefault(_componentJs);
  5393. /**
  5394. * The button component for toggling and selecting subtitles
  5395. *
  5396. * @param {Object} player Player object
  5397. * @param {Object=} options Object of option names and values
  5398. * @param {Function=} ready Ready callback function
  5399. * @extends TextTrackButton
  5400. * @class SubtitlesButton
  5401. */
  5402. var SubtitlesButton = (function (_TextTrackButton) {
  5403. _inherits(SubtitlesButton, _TextTrackButton);
  5404. function SubtitlesButton(player, options, ready) {
  5405. _classCallCheck(this, SubtitlesButton);
  5406. _TextTrackButton.call(this, player, options, ready);
  5407. this.el_.setAttribute('aria-label', 'Subtitles Menu');
  5408. }
  5409. /**
  5410. * Allow sub components to stack CSS class names
  5411. *
  5412. * @return {String} The constructed class name
  5413. * @method buildCSSClass
  5414. */
  5415. SubtitlesButton.prototype.buildCSSClass = function buildCSSClass() {
  5416. return 'vjs-subtitles-button ' + _TextTrackButton.prototype.buildCSSClass.call(this);
  5417. };
  5418. return SubtitlesButton;
  5419. })(_textTrackButtonJs2['default']);
  5420. SubtitlesButton.prototype.kind_ = 'subtitles';
  5421. SubtitlesButton.prototype.controlText_ = 'Subtitles';
  5422. _componentJs2['default'].registerComponent('SubtitlesButton', SubtitlesButton);
  5423. exports['default'] = SubtitlesButton;
  5424. module.exports = exports['default'];
  5425. },{"../../component.js":67,"./text-track-button.js":88}],88:[function(_dereq_,module,exports){
  5426. /**
  5427. * @file text-track-button.js
  5428. */
  5429. 'use strict';
  5430. exports.__esModule = true;
  5431. 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; } }
  5432. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5433. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5434. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5435. var _menuMenuButtonJs = _dereq_('../../menu/menu-button.js');
  5436. var _menuMenuButtonJs2 = _interopRequireDefault(_menuMenuButtonJs);
  5437. var _componentJs = _dereq_('../../component.js');
  5438. var _componentJs2 = _interopRequireDefault(_componentJs);
  5439. var _utilsFnJs = _dereq_('../../utils/fn.js');
  5440. var Fn = _interopRequireWildcard(_utilsFnJs);
  5441. var _textTrackMenuItemJs = _dereq_('./text-track-menu-item.js');
  5442. var _textTrackMenuItemJs2 = _interopRequireDefault(_textTrackMenuItemJs);
  5443. var _offTextTrackMenuItemJs = _dereq_('./off-text-track-menu-item.js');
  5444. var _offTextTrackMenuItemJs2 = _interopRequireDefault(_offTextTrackMenuItemJs);
  5445. /**
  5446. * The base class for buttons that toggle specific text track types (e.g. subtitles)
  5447. *
  5448. * @param {Player|Object} player
  5449. * @param {Object=} options
  5450. * @extends MenuButton
  5451. * @class TextTrackButton
  5452. */
  5453. var TextTrackButton = (function (_MenuButton) {
  5454. _inherits(TextTrackButton, _MenuButton);
  5455. function TextTrackButton(player, options) {
  5456. _classCallCheck(this, TextTrackButton);
  5457. _MenuButton.call(this, player, options);
  5458. var tracks = this.player_.textTracks();
  5459. if (this.items.length <= 1) {
  5460. this.hide();
  5461. }
  5462. if (!tracks) {
  5463. return;
  5464. }
  5465. var updateHandler = Fn.bind(this, this.update);
  5466. tracks.addEventListener('removetrack', updateHandler);
  5467. tracks.addEventListener('addtrack', updateHandler);
  5468. this.player_.on('dispose', function () {
  5469. tracks.removeEventListener('removetrack', updateHandler);
  5470. tracks.removeEventListener('addtrack', updateHandler);
  5471. });
  5472. }
  5473. // Create a menu item for each text track
  5474. TextTrackButton.prototype.createItems = function createItems() {
  5475. var items = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
  5476. // Add an OFF menu item to turn all tracks off
  5477. items.push(new _offTextTrackMenuItemJs2['default'](this.player_, { 'kind': this.kind_ }));
  5478. var tracks = this.player_.textTracks();
  5479. if (!tracks) {
  5480. return items;
  5481. }
  5482. for (var i = 0; i < tracks.length; i++) {
  5483. var track = tracks[i];
  5484. // only add tracks that are of the appropriate kind and have a label
  5485. if (track['kind'] === this.kind_) {
  5486. items.push(new _textTrackMenuItemJs2['default'](this.player_, {
  5487. // MenuItem is selectable
  5488. 'selectable': true,
  5489. 'track': track
  5490. }));
  5491. }
  5492. }
  5493. return items;
  5494. };
  5495. return TextTrackButton;
  5496. })(_menuMenuButtonJs2['default']);
  5497. _componentJs2['default'].registerComponent('TextTrackButton', TextTrackButton);
  5498. exports['default'] = TextTrackButton;
  5499. module.exports = exports['default'];
  5500. },{"../../component.js":67,"../../menu/menu-button.js":104,"../../utils/fn.js":134,"./off-text-track-menu-item.js":86,"./text-track-menu-item.js":89}],89:[function(_dereq_,module,exports){
  5501. /**
  5502. * @file text-track-menu-item.js
  5503. */
  5504. 'use strict';
  5505. exports.__esModule = true;
  5506. 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; } }
  5507. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5508. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5509. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5510. var _menuMenuItemJs = _dereq_('../../menu/menu-item.js');
  5511. var _menuMenuItemJs2 = _interopRequireDefault(_menuMenuItemJs);
  5512. var _componentJs = _dereq_('../../component.js');
  5513. var _componentJs2 = _interopRequireDefault(_componentJs);
  5514. var _utilsFnJs = _dereq_('../../utils/fn.js');
  5515. var Fn = _interopRequireWildcard(_utilsFnJs);
  5516. var _globalWindow = _dereq_('global/window');
  5517. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  5518. var _globalDocument = _dereq_('global/document');
  5519. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  5520. /**
  5521. * The specific menu item type for selecting a language within a text track kind
  5522. *
  5523. * @param {Player|Object} player
  5524. * @param {Object=} options
  5525. * @extends MenuItem
  5526. * @class TextTrackMenuItem
  5527. */
  5528. var TextTrackMenuItem = (function (_MenuItem) {
  5529. _inherits(TextTrackMenuItem, _MenuItem);
  5530. function TextTrackMenuItem(player, options) {
  5531. var _this = this;
  5532. _classCallCheck(this, TextTrackMenuItem);
  5533. var track = options['track'];
  5534. var tracks = player.textTracks();
  5535. // Modify options for parent MenuItem class's init.
  5536. options['label'] = track['label'] || track['language'] || 'Unknown';
  5537. options['selected'] = track['default'] || track['mode'] === 'showing';
  5538. _MenuItem.call(this, player, options);
  5539. this.track = track;
  5540. if (tracks) {
  5541. (function () {
  5542. var changeHandler = Fn.bind(_this, _this.handleTracksChange);
  5543. tracks.addEventListener('change', changeHandler);
  5544. _this.on('dispose', function () {
  5545. tracks.removeEventListener('change', changeHandler);
  5546. });
  5547. })();
  5548. }
  5549. // iOS7 doesn't dispatch change events to TextTrackLists when an
  5550. // associated track's mode changes. Without something like
  5551. // Object.observe() (also not present on iOS7), it's not
  5552. // possible to detect changes to the mode attribute and polyfill
  5553. // the change event. As a poor substitute, we manually dispatch
  5554. // change events whenever the controls modify the mode.
  5555. if (tracks && tracks.onchange === undefined) {
  5556. (function () {
  5557. var event = undefined;
  5558. _this.on(['tap', 'click'], function () {
  5559. if (typeof _globalWindow2['default'].Event !== 'object') {
  5560. // Android 2.3 throws an Illegal Constructor error for window.Event
  5561. try {
  5562. event = new _globalWindow2['default'].Event('change');
  5563. } catch (err) {}
  5564. }
  5565. if (!event) {
  5566. event = _globalDocument2['default'].createEvent('Event');
  5567. event.initEvent('change', true, true);
  5568. }
  5569. tracks.dispatchEvent(event);
  5570. });
  5571. })();
  5572. }
  5573. }
  5574. /**
  5575. * Handle click on text track
  5576. *
  5577. * @method handleClick
  5578. */
  5579. TextTrackMenuItem.prototype.handleClick = function handleClick(event) {
  5580. var kind = this.track['kind'];
  5581. var tracks = this.player_.textTracks();
  5582. _MenuItem.prototype.handleClick.call(this, event);
  5583. if (!tracks) return;
  5584. for (var i = 0; i < tracks.length; i++) {
  5585. var track = tracks[i];
  5586. if (track['kind'] !== kind) {
  5587. continue;
  5588. }
  5589. if (track === this.track) {
  5590. track['mode'] = 'showing';
  5591. } else {
  5592. track['mode'] = 'disabled';
  5593. }
  5594. }
  5595. };
  5596. /**
  5597. * Handle text track change
  5598. *
  5599. * @method handleTracksChange
  5600. */
  5601. TextTrackMenuItem.prototype.handleTracksChange = function handleTracksChange(event) {
  5602. this.selected(this.track['mode'] === 'showing');
  5603. };
  5604. return TextTrackMenuItem;
  5605. })(_menuMenuItemJs2['default']);
  5606. _componentJs2['default'].registerComponent('TextTrackMenuItem', TextTrackMenuItem);
  5607. exports['default'] = TextTrackMenuItem;
  5608. module.exports = exports['default'];
  5609. },{"../../component.js":67,"../../menu/menu-item.js":105,"../../utils/fn.js":134,"global/document":1,"global/window":2}],90:[function(_dereq_,module,exports){
  5610. /**
  5611. * @file current-time-display.js
  5612. */
  5613. 'use strict';
  5614. exports.__esModule = true;
  5615. 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; } }
  5616. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5617. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5618. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5619. var _componentJs = _dereq_('../../component.js');
  5620. var _componentJs2 = _interopRequireDefault(_componentJs);
  5621. var _utilsDomJs = _dereq_('../../utils/dom.js');
  5622. var Dom = _interopRequireWildcard(_utilsDomJs);
  5623. var _utilsFormatTimeJs = _dereq_('../../utils/format-time.js');
  5624. var _utilsFormatTimeJs2 = _interopRequireDefault(_utilsFormatTimeJs);
  5625. /**
  5626. * Displays the current time
  5627. *
  5628. * @param {Player|Object} player
  5629. * @param {Object=} options
  5630. * @extends Component
  5631. * @class CurrentTimeDisplay
  5632. */
  5633. var CurrentTimeDisplay = (function (_Component) {
  5634. _inherits(CurrentTimeDisplay, _Component);
  5635. function CurrentTimeDisplay(player, options) {
  5636. _classCallCheck(this, CurrentTimeDisplay);
  5637. _Component.call(this, player, options);
  5638. this.on(player, 'timeupdate', this.updateContent);
  5639. }
  5640. /**
  5641. * Create the component's DOM element
  5642. *
  5643. * @return {Element}
  5644. * @method createEl
  5645. */
  5646. CurrentTimeDisplay.prototype.createEl = function createEl() {
  5647. var el = _Component.prototype.createEl.call(this, 'div', {
  5648. className: 'vjs-current-time vjs-time-control vjs-control'
  5649. });
  5650. this.contentEl_ = Dom.createEl('div', {
  5651. className: 'vjs-current-time-display',
  5652. // label the current time for screen reader users
  5653. innerHTML: '<span class="vjs-control-text">Current Time </span>' + '0:00'
  5654. }, {
  5655. // tell screen readers not to automatically read the time as it changes
  5656. 'aria-live': 'off'
  5657. });
  5658. el.appendChild(this.contentEl_);
  5659. return el;
  5660. };
  5661. /**
  5662. * Update current time display
  5663. *
  5664. * @method updateContent
  5665. */
  5666. CurrentTimeDisplay.prototype.updateContent = function updateContent() {
  5667. // Allows for smooth scrubbing, when player can't keep up.
  5668. var time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
  5669. var localizedText = this.localize('Current Time');
  5670. var formattedTime = _utilsFormatTimeJs2['default'](time, this.player_.duration());
  5671. if (formattedTime !== this.formattedTime_) {
  5672. this.formattedTime_ = formattedTime;
  5673. this.contentEl_.innerHTML = '<span class="vjs-control-text">' + localizedText + '</span> ' + formattedTime;
  5674. }
  5675. };
  5676. return CurrentTimeDisplay;
  5677. })(_componentJs2['default']);
  5678. _componentJs2['default'].registerComponent('CurrentTimeDisplay', CurrentTimeDisplay);
  5679. exports['default'] = CurrentTimeDisplay;
  5680. module.exports = exports['default'];
  5681. },{"../../component.js":67,"../../utils/dom.js":132,"../../utils/format-time.js":135}],91:[function(_dereq_,module,exports){
  5682. /**
  5683. * @file duration-display.js
  5684. */
  5685. 'use strict';
  5686. exports.__esModule = true;
  5687. 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; } }
  5688. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5689. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5690. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5691. var _componentJs = _dereq_('../../component.js');
  5692. var _componentJs2 = _interopRequireDefault(_componentJs);
  5693. var _utilsDomJs = _dereq_('../../utils/dom.js');
  5694. var Dom = _interopRequireWildcard(_utilsDomJs);
  5695. var _utilsFormatTimeJs = _dereq_('../../utils/format-time.js');
  5696. var _utilsFormatTimeJs2 = _interopRequireDefault(_utilsFormatTimeJs);
  5697. /**
  5698. * Displays the duration
  5699. *
  5700. * @param {Player|Object} player
  5701. * @param {Object=} options
  5702. * @extends Component
  5703. * @class DurationDisplay
  5704. */
  5705. var DurationDisplay = (function (_Component) {
  5706. _inherits(DurationDisplay, _Component);
  5707. function DurationDisplay(player, options) {
  5708. _classCallCheck(this, DurationDisplay);
  5709. _Component.call(this, player, options);
  5710. // this might need to be changed to 'durationchange' instead of 'timeupdate' eventually,
  5711. // however the durationchange event fires before this.player_.duration() is set,
  5712. // so the value cannot be written out using this method.
  5713. // Once the order of durationchange and this.player_.duration() being set is figured out,
  5714. // this can be updated.
  5715. this.on(player, 'timeupdate', this.updateContent);
  5716. this.on(player, 'loadedmetadata', this.updateContent);
  5717. }
  5718. /**
  5719. * Create the component's DOM element
  5720. *
  5721. * @return {Element}
  5722. * @method createEl
  5723. */
  5724. DurationDisplay.prototype.createEl = function createEl() {
  5725. var el = _Component.prototype.createEl.call(this, 'div', {
  5726. className: 'vjs-duration vjs-time-control vjs-control'
  5727. });
  5728. this.contentEl_ = Dom.createEl('div', {
  5729. className: 'vjs-duration-display',
  5730. // label the duration time for screen reader users
  5731. innerHTML: '<span class="vjs-control-text">' + this.localize('Duration Time') + '</span> 0:00'
  5732. }, {
  5733. // tell screen readers not to automatically read the time as it changes
  5734. 'aria-live': 'off'
  5735. });
  5736. el.appendChild(this.contentEl_);
  5737. return el;
  5738. };
  5739. /**
  5740. * Update duration time display
  5741. *
  5742. * @method updateContent
  5743. */
  5744. DurationDisplay.prototype.updateContent = function updateContent() {
  5745. var duration = this.player_.duration();
  5746. if (duration && this.duration_ !== duration) {
  5747. this.duration_ = duration;
  5748. var localizedText = this.localize('Duration Time');
  5749. var formattedTime = _utilsFormatTimeJs2['default'](duration);
  5750. this.contentEl_.innerHTML = '<span class="vjs-control-text">' + localizedText + '</span> ' + formattedTime; // label the duration time for screen reader users
  5751. }
  5752. };
  5753. return DurationDisplay;
  5754. })(_componentJs2['default']);
  5755. _componentJs2['default'].registerComponent('DurationDisplay', DurationDisplay);
  5756. exports['default'] = DurationDisplay;
  5757. module.exports = exports['default'];
  5758. },{"../../component.js":67,"../../utils/dom.js":132,"../../utils/format-time.js":135}],92:[function(_dereq_,module,exports){
  5759. /**
  5760. * @file remaining-time-display.js
  5761. */
  5762. 'use strict';
  5763. exports.__esModule = true;
  5764. 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; } }
  5765. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5766. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5767. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5768. var _componentJs = _dereq_('../../component.js');
  5769. var _componentJs2 = _interopRequireDefault(_componentJs);
  5770. var _utilsDomJs = _dereq_('../../utils/dom.js');
  5771. var Dom = _interopRequireWildcard(_utilsDomJs);
  5772. var _utilsFormatTimeJs = _dereq_('../../utils/format-time.js');
  5773. var _utilsFormatTimeJs2 = _interopRequireDefault(_utilsFormatTimeJs);
  5774. /**
  5775. * Displays the time left in the video
  5776. *
  5777. * @param {Player|Object} player
  5778. * @param {Object=} options
  5779. * @extends Component
  5780. * @class RemainingTimeDisplay
  5781. */
  5782. var RemainingTimeDisplay = (function (_Component) {
  5783. _inherits(RemainingTimeDisplay, _Component);
  5784. function RemainingTimeDisplay(player, options) {
  5785. _classCallCheck(this, RemainingTimeDisplay);
  5786. _Component.call(this, player, options);
  5787. this.on(player, 'timeupdate', this.updateContent);
  5788. }
  5789. /**
  5790. * Create the component's DOM element
  5791. *
  5792. * @return {Element}
  5793. * @method createEl
  5794. */
  5795. RemainingTimeDisplay.prototype.createEl = function createEl() {
  5796. var el = _Component.prototype.createEl.call(this, 'div', {
  5797. className: 'vjs-remaining-time vjs-time-control vjs-control'
  5798. });
  5799. this.contentEl_ = Dom.createEl('div', {
  5800. className: 'vjs-remaining-time-display',
  5801. // label the remaining time for screen reader users
  5802. innerHTML: '<span class="vjs-control-text">' + this.localize('Remaining Time') + '</span> -0:00'
  5803. }, {
  5804. // tell screen readers not to automatically read the time as it changes
  5805. 'aria-live': 'off'
  5806. });
  5807. el.appendChild(this.contentEl_);
  5808. return el;
  5809. };
  5810. /**
  5811. * Update remaining time display
  5812. *
  5813. * @method updateContent
  5814. */
  5815. RemainingTimeDisplay.prototype.updateContent = function updateContent() {
  5816. if (this.player_.duration()) {
  5817. var localizedText = this.localize('Remaining Time');
  5818. var formattedTime = _utilsFormatTimeJs2['default'](this.player_.remainingTime());
  5819. if (formattedTime !== this.formattedTime_) {
  5820. this.formattedTime_ = formattedTime;
  5821. this.contentEl_.innerHTML = '<span class="vjs-control-text">' + localizedText + '</span> -' + formattedTime;
  5822. }
  5823. }
  5824. // Allows for smooth scrubbing, when player can't keep up.
  5825. // var time = (this.player_.scrubbing()) ? this.player_.getCache().currentTime : this.player_.currentTime();
  5826. // this.contentEl_.innerHTML = vjs.formatTime(time, this.player_.duration());
  5827. };
  5828. return RemainingTimeDisplay;
  5829. })(_componentJs2['default']);
  5830. _componentJs2['default'].registerComponent('RemainingTimeDisplay', RemainingTimeDisplay);
  5831. exports['default'] = RemainingTimeDisplay;
  5832. module.exports = exports['default'];
  5833. },{"../../component.js":67,"../../utils/dom.js":132,"../../utils/format-time.js":135}],93:[function(_dereq_,module,exports){
  5834. /**
  5835. * @file time-divider.js
  5836. */
  5837. 'use strict';
  5838. exports.__esModule = true;
  5839. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5840. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5841. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5842. var _componentJs = _dereq_('../../component.js');
  5843. var _componentJs2 = _interopRequireDefault(_componentJs);
  5844. /**
  5845. * The separator between the current time and duration.
  5846. * Can be hidden if it's not needed in the design.
  5847. *
  5848. * @param {Player|Object} player
  5849. * @param {Object=} options
  5850. * @extends Component
  5851. * @class TimeDivider
  5852. */
  5853. var TimeDivider = (function (_Component) {
  5854. _inherits(TimeDivider, _Component);
  5855. function TimeDivider() {
  5856. _classCallCheck(this, TimeDivider);
  5857. _Component.apply(this, arguments);
  5858. }
  5859. /**
  5860. * Create the component's DOM element
  5861. *
  5862. * @return {Element}
  5863. * @method createEl
  5864. */
  5865. TimeDivider.prototype.createEl = function createEl() {
  5866. return _Component.prototype.createEl.call(this, 'div', {
  5867. className: 'vjs-time-control vjs-time-divider',
  5868. innerHTML: '<div><span>/</span></div>'
  5869. });
  5870. };
  5871. return TimeDivider;
  5872. })(_componentJs2['default']);
  5873. _componentJs2['default'].registerComponent('TimeDivider', TimeDivider);
  5874. exports['default'] = TimeDivider;
  5875. module.exports = exports['default'];
  5876. },{"../../component.js":67}],94:[function(_dereq_,module,exports){
  5877. /**
  5878. * @file volume-bar.js
  5879. */
  5880. 'use strict';
  5881. exports.__esModule = true;
  5882. 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; } }
  5883. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5884. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5885. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5886. var _sliderSliderJs = _dereq_('../../slider/slider.js');
  5887. var _sliderSliderJs2 = _interopRequireDefault(_sliderSliderJs);
  5888. var _componentJs = _dereq_('../../component.js');
  5889. var _componentJs2 = _interopRequireDefault(_componentJs);
  5890. var _utilsFnJs = _dereq_('../../utils/fn.js');
  5891. var Fn = _interopRequireWildcard(_utilsFnJs);
  5892. // Required children
  5893. var _volumeLevelJs = _dereq_('./volume-level.js');
  5894. var _volumeLevelJs2 = _interopRequireDefault(_volumeLevelJs);
  5895. /**
  5896. * The bar that contains the volume level and can be clicked on to adjust the level
  5897. *
  5898. * @param {Player|Object} player
  5899. * @param {Object=} options
  5900. * @extends Slider
  5901. * @class VolumeBar
  5902. */
  5903. var VolumeBar = (function (_Slider) {
  5904. _inherits(VolumeBar, _Slider);
  5905. function VolumeBar(player, options) {
  5906. _classCallCheck(this, VolumeBar);
  5907. _Slider.call(this, player, options);
  5908. this.on(player, 'volumechange', this.updateARIAAttributes);
  5909. player.ready(Fn.bind(this, this.updateARIAAttributes));
  5910. }
  5911. /**
  5912. * Create the component's DOM element
  5913. *
  5914. * @return {Element}
  5915. * @method createEl
  5916. */
  5917. VolumeBar.prototype.createEl = function createEl() {
  5918. return _Slider.prototype.createEl.call(this, 'div', {
  5919. className: 'vjs-volume-bar vjs-slider-bar'
  5920. }, {
  5921. 'aria-label': 'volume level'
  5922. });
  5923. };
  5924. /**
  5925. * Handle mouse move on volume bar
  5926. *
  5927. * @method handleMouseMove
  5928. */
  5929. VolumeBar.prototype.handleMouseMove = function handleMouseMove(event) {
  5930. this.checkMuted();
  5931. this.player_.volume(this.calculateDistance(event));
  5932. };
  5933. VolumeBar.prototype.checkMuted = function checkMuted() {
  5934. if (this.player_.muted()) {
  5935. this.player_.muted(false);
  5936. }
  5937. };
  5938. /**
  5939. * Get percent of volume level
  5940. *
  5941. * @retun {Number} Volume level percent
  5942. * @method getPercent
  5943. */
  5944. VolumeBar.prototype.getPercent = function getPercent() {
  5945. if (this.player_.muted()) {
  5946. return 0;
  5947. } else {
  5948. return this.player_.volume();
  5949. }
  5950. };
  5951. /**
  5952. * Increase volume level for keyboard users
  5953. *
  5954. * @method stepForward
  5955. */
  5956. VolumeBar.prototype.stepForward = function stepForward() {
  5957. this.checkMuted();
  5958. this.player_.volume(this.player_.volume() + 0.1);
  5959. };
  5960. /**
  5961. * Decrease volume level for keyboard users
  5962. *
  5963. * @method stepBack
  5964. */
  5965. VolumeBar.prototype.stepBack = function stepBack() {
  5966. this.checkMuted();
  5967. this.player_.volume(this.player_.volume() - 0.1);
  5968. };
  5969. /**
  5970. * Update ARIA accessibility attributes
  5971. *
  5972. * @method updateARIAAttributes
  5973. */
  5974. VolumeBar.prototype.updateARIAAttributes = function updateARIAAttributes() {
  5975. // Current value of volume bar as a percentage
  5976. var volume = (this.player_.volume() * 100).toFixed(2);
  5977. this.el_.setAttribute('aria-valuenow', volume);
  5978. this.el_.setAttribute('aria-valuetext', volume + '%');
  5979. };
  5980. return VolumeBar;
  5981. })(_sliderSliderJs2['default']);
  5982. VolumeBar.prototype.options_ = {
  5983. children: ['volumeLevel'],
  5984. 'barName': 'volumeLevel'
  5985. };
  5986. VolumeBar.prototype.playerEvent = 'volumechange';
  5987. _componentJs2['default'].registerComponent('VolumeBar', VolumeBar);
  5988. exports['default'] = VolumeBar;
  5989. module.exports = exports['default'];
  5990. },{"../../component.js":67,"../../slider/slider.js":114,"../../utils/fn.js":134,"./volume-level.js":96}],95:[function(_dereq_,module,exports){
  5991. /**
  5992. * @file volume-control.js
  5993. */
  5994. 'use strict';
  5995. exports.__esModule = true;
  5996. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  5997. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  5998. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5999. var _componentJs = _dereq_('../../component.js');
  6000. var _componentJs2 = _interopRequireDefault(_componentJs);
  6001. // Required children
  6002. var _volumeBarJs = _dereq_('./volume-bar.js');
  6003. var _volumeBarJs2 = _interopRequireDefault(_volumeBarJs);
  6004. /**
  6005. * The component for controlling the volume level
  6006. *
  6007. * @param {Player|Object} player
  6008. * @param {Object=} options
  6009. * @extends Component
  6010. * @class VolumeControl
  6011. */
  6012. var VolumeControl = (function (_Component) {
  6013. _inherits(VolumeControl, _Component);
  6014. function VolumeControl(player, options) {
  6015. _classCallCheck(this, VolumeControl);
  6016. _Component.call(this, player, options);
  6017. // hide volume controls when they're not supported by the current tech
  6018. if (player.tech_ && player.tech_['featuresVolumeControl'] === false) {
  6019. this.addClass('vjs-hidden');
  6020. }
  6021. this.on(player, 'loadstart', function () {
  6022. if (player.tech_['featuresVolumeControl'] === false) {
  6023. this.addClass('vjs-hidden');
  6024. } else {
  6025. this.removeClass('vjs-hidden');
  6026. }
  6027. });
  6028. }
  6029. /**
  6030. * Create the component's DOM element
  6031. *
  6032. * @return {Element}
  6033. * @method createEl
  6034. */
  6035. VolumeControl.prototype.createEl = function createEl() {
  6036. return _Component.prototype.createEl.call(this, 'div', {
  6037. className: 'vjs-volume-control vjs-control'
  6038. });
  6039. };
  6040. return VolumeControl;
  6041. })(_componentJs2['default']);
  6042. VolumeControl.prototype.options_ = {
  6043. children: ['volumeBar']
  6044. };
  6045. _componentJs2['default'].registerComponent('VolumeControl', VolumeControl);
  6046. exports['default'] = VolumeControl;
  6047. module.exports = exports['default'];
  6048. },{"../../component.js":67,"./volume-bar.js":94}],96:[function(_dereq_,module,exports){
  6049. /**
  6050. * @file volume-level.js
  6051. */
  6052. 'use strict';
  6053. exports.__esModule = true;
  6054. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  6055. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  6056. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6057. var _componentJs = _dereq_('../../component.js');
  6058. var _componentJs2 = _interopRequireDefault(_componentJs);
  6059. /**
  6060. * Shows volume level
  6061. *
  6062. * @param {Player|Object} player
  6063. * @param {Object=} options
  6064. * @extends Component
  6065. * @class VolumeLevel
  6066. */
  6067. var VolumeLevel = (function (_Component) {
  6068. _inherits(VolumeLevel, _Component);
  6069. function VolumeLevel() {
  6070. _classCallCheck(this, VolumeLevel);
  6071. _Component.apply(this, arguments);
  6072. }
  6073. /**
  6074. * Create the component's DOM element
  6075. *
  6076. * @return {Element}
  6077. * @method createEl
  6078. */
  6079. VolumeLevel.prototype.createEl = function createEl() {
  6080. return _Component.prototype.createEl.call(this, 'div', {
  6081. className: 'vjs-volume-level',
  6082. innerHTML: '<span class="vjs-control-text"></span>'
  6083. });
  6084. };
  6085. return VolumeLevel;
  6086. })(_componentJs2['default']);
  6087. _componentJs2['default'].registerComponent('VolumeLevel', VolumeLevel);
  6088. exports['default'] = VolumeLevel;
  6089. module.exports = exports['default'];
  6090. },{"../../component.js":67}],97:[function(_dereq_,module,exports){
  6091. /**
  6092. * @file volume-menu-button.js
  6093. */
  6094. 'use strict';
  6095. exports.__esModule = true;
  6096. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  6097. 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; } }
  6098. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  6099. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6100. var _utilsFnJs = _dereq_('../utils/fn.js');
  6101. var Fn = _interopRequireWildcard(_utilsFnJs);
  6102. var _componentJs = _dereq_('../component.js');
  6103. var _componentJs2 = _interopRequireDefault(_componentJs);
  6104. var _popupPopupJs = _dereq_('../popup/popup.js');
  6105. var _popupPopupJs2 = _interopRequireDefault(_popupPopupJs);
  6106. var _popupPopupButtonJs = _dereq_('../popup/popup-button.js');
  6107. var _popupPopupButtonJs2 = _interopRequireDefault(_popupPopupButtonJs);
  6108. var _muteToggleJs = _dereq_('./mute-toggle.js');
  6109. var _muteToggleJs2 = _interopRequireDefault(_muteToggleJs);
  6110. var _volumeControlVolumeBarJs = _dereq_('./volume-control/volume-bar.js');
  6111. var _volumeControlVolumeBarJs2 = _interopRequireDefault(_volumeControlVolumeBarJs);
  6112. var _globalDocument = _dereq_('global/document');
  6113. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  6114. /**
  6115. * Button for volume popup
  6116. *
  6117. * @param {Player|Object} player
  6118. * @param {Object=} options
  6119. * @extends PopupButton
  6120. * @class VolumeMenuButton
  6121. */
  6122. var VolumeMenuButton = (function (_PopupButton) {
  6123. _inherits(VolumeMenuButton, _PopupButton);
  6124. function VolumeMenuButton(player) {
  6125. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  6126. _classCallCheck(this, VolumeMenuButton);
  6127. // Default to inline
  6128. if (options.inline === undefined) {
  6129. options.inline = true;
  6130. }
  6131. // If the vertical option isn't passed at all, default to true.
  6132. if (options.vertical === undefined) {
  6133. // If an inline volumeMenuButton is used, we should default to using
  6134. // a horizontal slider for obvious reasons.
  6135. if (options.inline) {
  6136. options.vertical = false;
  6137. } else {
  6138. options.vertical = true;
  6139. }
  6140. }
  6141. // The vertical option needs to be set on the volumeBar as well,
  6142. // since that will need to be passed along to the VolumeBar constructor
  6143. options.volumeBar = options.volumeBar || {};
  6144. options.volumeBar.vertical = !!options.vertical;
  6145. _PopupButton.call(this, player, options);
  6146. // Same listeners as MuteToggle
  6147. this.on(player, 'volumechange', this.volumeUpdate);
  6148. this.on(player, 'loadstart', this.volumeUpdate);
  6149. // hide mute toggle if the current tech doesn't support volume control
  6150. function updateVisibility() {
  6151. if (player.tech_ && player.tech_['featuresVolumeControl'] === false) {
  6152. this.addClass('vjs-hidden');
  6153. } else {
  6154. this.removeClass('vjs-hidden');
  6155. }
  6156. }
  6157. updateVisibility.call(this);
  6158. this.on(player, 'loadstart', updateVisibility);
  6159. this.on(this.volumeBar, ['slideractive', 'focus'], function () {
  6160. this.addClass('vjs-slider-active');
  6161. });
  6162. this.on(this.volumeBar, ['sliderinactive', 'blur'], function () {
  6163. this.removeClass('vjs-slider-active');
  6164. });
  6165. this.on(this.volumeBar, ['focus'], function () {
  6166. this.addClass('vjs-lock-showing');
  6167. });
  6168. this.on(this.volumeBar, ['blur'], function () {
  6169. this.removeClass('vjs-lock-showing');
  6170. });
  6171. }
  6172. /**
  6173. * Allow sub components to stack CSS class names
  6174. *
  6175. * @return {String} The constructed class name
  6176. * @method buildCSSClass
  6177. */
  6178. VolumeMenuButton.prototype.buildCSSClass = function buildCSSClass() {
  6179. var orientationClass = '';
  6180. if (!!this.options_.vertical) {
  6181. orientationClass = 'vjs-volume-menu-button-vertical';
  6182. } else {
  6183. orientationClass = 'vjs-volume-menu-button-horizontal';
  6184. }
  6185. return 'vjs-volume-menu-button ' + _PopupButton.prototype.buildCSSClass.call(this) + ' ' + orientationClass;
  6186. };
  6187. /**
  6188. * Allow sub components to stack CSS class names
  6189. *
  6190. * @return {Popup} The volume popup button
  6191. * @method createPopup
  6192. */
  6193. VolumeMenuButton.prototype.createPopup = function createPopup() {
  6194. var popup = new _popupPopupJs2['default'](this.player_, {
  6195. contentElType: 'div'
  6196. });
  6197. var vb = new _volumeControlVolumeBarJs2['default'](this.player_, this.options_.volumeBar);
  6198. popup.addChild(vb);
  6199. this.menuContent = popup;
  6200. this.volumeBar = vb;
  6201. this.attachVolumeBarEvents();
  6202. return popup;
  6203. };
  6204. /**
  6205. * Handle click on volume popup and calls super
  6206. *
  6207. * @method handleClick
  6208. */
  6209. VolumeMenuButton.prototype.handleClick = function handleClick() {
  6210. _muteToggleJs2['default'].prototype.handleClick.call(this);
  6211. _PopupButton.prototype.handleClick.call(this);
  6212. };
  6213. VolumeMenuButton.prototype.attachVolumeBarEvents = function attachVolumeBarEvents() {
  6214. this.menuContent.on(['mousedown', 'touchdown'], Fn.bind(this, this.handleMouseDown));
  6215. };
  6216. VolumeMenuButton.prototype.handleMouseDown = function handleMouseDown(event) {
  6217. this.on(['mousemove', 'touchmove'], Fn.bind(this.volumeBar, this.volumeBar.handleMouseMove));
  6218. this.on(_globalDocument2['default'], ['mouseup', 'touchend'], this.handleMouseUp);
  6219. };
  6220. VolumeMenuButton.prototype.handleMouseUp = function handleMouseUp(event) {
  6221. this.off(['mousemove', 'touchmove'], Fn.bind(this.volumeBar, this.volumeBar.handleMouseMove));
  6222. };
  6223. return VolumeMenuButton;
  6224. })(_popupPopupButtonJs2['default']);
  6225. VolumeMenuButton.prototype.volumeUpdate = _muteToggleJs2['default'].prototype.update;
  6226. VolumeMenuButton.prototype.controlText_ = 'Mute';
  6227. _componentJs2['default'].registerComponent('VolumeMenuButton', VolumeMenuButton);
  6228. exports['default'] = VolumeMenuButton;
  6229. module.exports = exports['default'];
  6230. },{"../component.js":67,"../popup/popup-button.js":110,"../popup/popup.js":111,"../utils/fn.js":134,"./mute-toggle.js":71,"./volume-control/volume-bar.js":94,"global/document":1}],98:[function(_dereq_,module,exports){
  6231. /**
  6232. * @file error-display.js
  6233. */
  6234. 'use strict';
  6235. exports.__esModule = true;
  6236. 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; } }
  6237. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  6238. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  6239. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6240. var _component = _dereq_('./component');
  6241. var _component2 = _interopRequireDefault(_component);
  6242. var _modalDialog = _dereq_('./modal-dialog');
  6243. var _modalDialog2 = _interopRequireDefault(_modalDialog);
  6244. var _utilsDom = _dereq_('./utils/dom');
  6245. var Dom = _interopRequireWildcard(_utilsDom);
  6246. var _utilsMergeOptions = _dereq_('./utils/merge-options');
  6247. var _utilsMergeOptions2 = _interopRequireDefault(_utilsMergeOptions);
  6248. /**
  6249. * Display that an error has occurred making the video unplayable.
  6250. *
  6251. * @extends ModalDialog
  6252. * @class ErrorDisplay
  6253. */
  6254. var ErrorDisplay = (function (_ModalDialog) {
  6255. _inherits(ErrorDisplay, _ModalDialog);
  6256. /**
  6257. * Constructor for error display modal.
  6258. *
  6259. * @param {Player} player
  6260. * @param {Object} [options]
  6261. */
  6262. function ErrorDisplay(player, options) {
  6263. _classCallCheck(this, ErrorDisplay);
  6264. _ModalDialog.call(this, player, options);
  6265. this.on(player, 'error', this.open);
  6266. }
  6267. /**
  6268. * Include the old class for backward-compatibility.
  6269. *
  6270. * This can be removed in 6.0.
  6271. *
  6272. * @method buildCSSClass
  6273. * @deprecated
  6274. * @return {String}
  6275. */
  6276. ErrorDisplay.prototype.buildCSSClass = function buildCSSClass() {
  6277. return 'vjs-error-display ' + _ModalDialog.prototype.buildCSSClass.call(this);
  6278. };
  6279. /**
  6280. * Generates the modal content based on the player error.
  6281. *
  6282. * @return {String|Null}
  6283. */
  6284. ErrorDisplay.prototype.content = function content() {
  6285. var error = this.player().error();
  6286. return error ? this.localize(error.message) : '';
  6287. };
  6288. return ErrorDisplay;
  6289. })(_modalDialog2['default']);
  6290. ErrorDisplay.prototype.options_ = _utilsMergeOptions2['default'](_modalDialog2['default'].prototype.options_, {
  6291. fillAlways: true,
  6292. temporary: false,
  6293. uncloseable: true
  6294. });
  6295. _component2['default'].registerComponent('ErrorDisplay', ErrorDisplay);
  6296. exports['default'] = ErrorDisplay;
  6297. module.exports = exports['default'];
  6298. },{"./component":67,"./modal-dialog":107,"./utils/dom":132,"./utils/merge-options":138}],99:[function(_dereq_,module,exports){
  6299. /**
  6300. * @file event-target.js
  6301. */
  6302. 'use strict';
  6303. exports.__esModule = true;
  6304. 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; } }
  6305. var _utilsEventsJs = _dereq_('./utils/events.js');
  6306. var Events = _interopRequireWildcard(_utilsEventsJs);
  6307. var EventTarget = function EventTarget() {};
  6308. EventTarget.prototype.allowedEvents_ = {};
  6309. EventTarget.prototype.on = function (type, fn) {
  6310. // Remove the addEventListener alias before calling Events.on
  6311. // so we don't get into an infinite type loop
  6312. var ael = this.addEventListener;
  6313. this.addEventListener = Function.prototype;
  6314. Events.on(this, type, fn);
  6315. this.addEventListener = ael;
  6316. };
  6317. EventTarget.prototype.addEventListener = EventTarget.prototype.on;
  6318. EventTarget.prototype.off = function (type, fn) {
  6319. Events.off(this, type, fn);
  6320. };
  6321. EventTarget.prototype.removeEventListener = EventTarget.prototype.off;
  6322. EventTarget.prototype.one = function (type, fn) {
  6323. Events.one(this, type, fn);
  6324. };
  6325. EventTarget.prototype.trigger = function (event) {
  6326. var type = event.type || event;
  6327. if (typeof event === 'string') {
  6328. event = {
  6329. type: type
  6330. };
  6331. }
  6332. event = Events.fixEvent(event);
  6333. if (this.allowedEvents_[type] && this['on' + type]) {
  6334. this['on' + type](event);
  6335. }
  6336. Events.trigger(this, event);
  6337. };
  6338. // The standard DOM EventTarget.dispatchEvent() is aliased to trigger()
  6339. EventTarget.prototype.dispatchEvent = EventTarget.prototype.trigger;
  6340. exports['default'] = EventTarget;
  6341. module.exports = exports['default'];
  6342. },{"./utils/events.js":133}],100:[function(_dereq_,module,exports){
  6343. 'use strict';
  6344. exports.__esModule = true;
  6345. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  6346. var _utilsLog = _dereq_('./utils/log');
  6347. var _utilsLog2 = _interopRequireDefault(_utilsLog);
  6348. /*
  6349. * @file extend.js
  6350. *
  6351. * A combination of node inherits and babel's inherits (after transpile).
  6352. * Both work the same but node adds `super_` to the subClass
  6353. * and Bable adds the superClass as __proto__. Both seem useful.
  6354. */
  6355. var _inherits = function _inherits(subClass, superClass) {
  6356. if (typeof superClass !== 'function' && superClass !== null) {
  6357. throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);
  6358. }
  6359. subClass.prototype = Object.create(superClass && superClass.prototype, {
  6360. constructor: {
  6361. value: subClass,
  6362. enumerable: false,
  6363. writable: true,
  6364. configurable: true
  6365. }
  6366. });
  6367. if (superClass) {
  6368. // node
  6369. subClass.super_ = superClass;
  6370. }
  6371. };
  6372. /*
  6373. * Function for subclassing using the same inheritance that
  6374. * videojs uses internally
  6375. * ```js
  6376. * var Button = videojs.getComponent('Button');
  6377. * ```
  6378. * ```js
  6379. * var MyButton = videojs.extend(Button, {
  6380. * constructor: function(player, options) {
  6381. * Button.call(this, player, options);
  6382. * },
  6383. * onClick: function() {
  6384. * // doSomething
  6385. * }
  6386. * });
  6387. * ```
  6388. */
  6389. var extendFn = function extendFn(superClass) {
  6390. var subClassMethods = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  6391. var subClass = function subClass() {
  6392. superClass.apply(this, arguments);
  6393. };
  6394. var methods = {};
  6395. if (typeof subClassMethods === 'object') {
  6396. if (typeof subClassMethods.init === 'function') {
  6397. _utilsLog2['default'].warn('Constructor logic via init() is deprecated; please use constructor() instead.');
  6398. subClassMethods.constructor = subClassMethods.init;
  6399. }
  6400. if (subClassMethods.constructor !== Object.prototype.constructor) {
  6401. subClass = subClassMethods.constructor;
  6402. }
  6403. methods = subClassMethods;
  6404. } else if (typeof subClassMethods === 'function') {
  6405. subClass = subClassMethods;
  6406. }
  6407. _inherits(subClass, superClass);
  6408. // Extend subObj's prototype with functions and other properties from props
  6409. for (var name in methods) {
  6410. if (methods.hasOwnProperty(name)) {
  6411. subClass.prototype[name] = methods[name];
  6412. }
  6413. }
  6414. return subClass;
  6415. };
  6416. exports['default'] = extendFn;
  6417. module.exports = exports['default'];
  6418. },{"./utils/log":137}],101:[function(_dereq_,module,exports){
  6419. /**
  6420. * @file fullscreen-api.js
  6421. */
  6422. 'use strict';
  6423. exports.__esModule = true;
  6424. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  6425. var _globalDocument = _dereq_('global/document');
  6426. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  6427. /*
  6428. * Store the browser-specific methods for the fullscreen API
  6429. * @type {Object|undefined}
  6430. * @private
  6431. */
  6432. var FullscreenApi = {};
  6433. // browser API methods
  6434. // map approach from Screenful.js - https://github.com/sindresorhus/screenfull.js
  6435. var apiMap = [
  6436. // Spec: https://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html
  6437. ['requestFullscreen', 'exitFullscreen', 'fullscreenElement', 'fullscreenEnabled', 'fullscreenchange', 'fullscreenerror'],
  6438. // WebKit
  6439. ['webkitRequestFullscreen', 'webkitExitFullscreen', 'webkitFullscreenElement', 'webkitFullscreenEnabled', 'webkitfullscreenchange', 'webkitfullscreenerror'],
  6440. // Old WebKit (Safari 5.1)
  6441. ['webkitRequestFullScreen', 'webkitCancelFullScreen', 'webkitCurrentFullScreenElement', 'webkitCancelFullScreen', 'webkitfullscreenchange', 'webkitfullscreenerror'],
  6442. // Mozilla
  6443. ['mozRequestFullScreen', 'mozCancelFullScreen', 'mozFullScreenElement', 'mozFullScreenEnabled', 'mozfullscreenchange', 'mozfullscreenerror'],
  6444. // Microsoft
  6445. ['msRequestFullscreen', 'msExitFullscreen', 'msFullscreenElement', 'msFullscreenEnabled', 'MSFullscreenChange', 'MSFullscreenError']];
  6446. var specApi = apiMap[0];
  6447. var browserApi = undefined;
  6448. // determine the supported set of functions
  6449. for (var i = 0; i < apiMap.length; i++) {
  6450. // check for exitFullscreen function
  6451. if (apiMap[i][1] in _globalDocument2['default']) {
  6452. browserApi = apiMap[i];
  6453. break;
  6454. }
  6455. }
  6456. // map the browser API names to the spec API names
  6457. if (browserApi) {
  6458. for (var i = 0; i < browserApi.length; i++) {
  6459. FullscreenApi[specApi[i]] = browserApi[i];
  6460. }
  6461. }
  6462. exports['default'] = FullscreenApi;
  6463. module.exports = exports['default'];
  6464. },{"global/document":1}],102:[function(_dereq_,module,exports){
  6465. /**
  6466. * @file loading-spinner.js
  6467. */
  6468. 'use strict';
  6469. exports.__esModule = true;
  6470. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  6471. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  6472. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6473. var _component = _dereq_('./component');
  6474. var _component2 = _interopRequireDefault(_component);
  6475. /* Loading Spinner
  6476. ================================================================================ */
  6477. /**
  6478. * Loading spinner for waiting events
  6479. *
  6480. * @extends Component
  6481. * @class LoadingSpinner
  6482. */
  6483. var LoadingSpinner = (function (_Component) {
  6484. _inherits(LoadingSpinner, _Component);
  6485. function LoadingSpinner() {
  6486. _classCallCheck(this, LoadingSpinner);
  6487. _Component.apply(this, arguments);
  6488. }
  6489. /**
  6490. * Create the component's DOM element
  6491. *
  6492. * @method createEl
  6493. */
  6494. LoadingSpinner.prototype.createEl = function createEl() {
  6495. return _Component.prototype.createEl.call(this, 'div', {
  6496. className: 'vjs-loading-spinner',
  6497. dir: 'ltr'
  6498. });
  6499. };
  6500. return LoadingSpinner;
  6501. })(_component2['default']);
  6502. _component2['default'].registerComponent('LoadingSpinner', LoadingSpinner);
  6503. exports['default'] = LoadingSpinner;
  6504. module.exports = exports['default'];
  6505. },{"./component":67}],103:[function(_dereq_,module,exports){
  6506. /**
  6507. * @file media-error.js
  6508. */
  6509. 'use strict';
  6510. exports.__esModule = true;
  6511. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  6512. var _objectAssign = _dereq_('object.assign');
  6513. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  6514. /*
  6515. * Custom MediaError to mimic the HTML5 MediaError
  6516. *
  6517. * @param {Number} code The media error code
  6518. */
  6519. var MediaError = function MediaError(code) {
  6520. if (typeof code === 'number') {
  6521. this.code = code;
  6522. } else if (typeof code === 'string') {
  6523. // default code is zero, so this is a custom error
  6524. this.message = code;
  6525. } else if (typeof code === 'object') {
  6526. // object
  6527. _objectAssign2['default'](this, code);
  6528. }
  6529. if (!this.message) {
  6530. this.message = MediaError.defaultMessages[this.code] || '';
  6531. }
  6532. };
  6533. /*
  6534. * The error code that refers two one of the defined
  6535. * MediaError types
  6536. *
  6537. * @type {Number}
  6538. */
  6539. MediaError.prototype.code = 0;
  6540. /*
  6541. * An optional message to be shown with the error.
  6542. * Message is not part of the HTML5 video spec
  6543. * but allows for more informative custom errors.
  6544. *
  6545. * @type {String}
  6546. */
  6547. MediaError.prototype.message = '';
  6548. /*
  6549. * An optional status code that can be set by plugins
  6550. * to allow even more detail about the error.
  6551. * For example the HLS plugin might provide the specific
  6552. * HTTP status code that was returned when the error
  6553. * occurred, then allowing a custom error overlay
  6554. * to display more information.
  6555. *
  6556. * @type {Array}
  6557. */
  6558. MediaError.prototype.status = null;
  6559. MediaError.errorTypes = ['MEDIA_ERR_CUSTOM', // = 0
  6560. 'MEDIA_ERR_ABORTED', // = 1
  6561. 'MEDIA_ERR_NETWORK', // = 2
  6562. 'MEDIA_ERR_DECODE', // = 3
  6563. 'MEDIA_ERR_SRC_NOT_SUPPORTED', // = 4
  6564. 'MEDIA_ERR_ENCRYPTED' // = 5
  6565. ];
  6566. MediaError.defaultMessages = {
  6567. 1: 'You aborted the media playback',
  6568. 2: 'A network error caused the media download to fail part-way.',
  6569. 3: 'The media playback was aborted due to a corruption problem or because the media used features your browser did not support.',
  6570. 4: 'The media could not be loaded, either because the server or network failed or because the format is not supported.',
  6571. 5: 'The media is encrypted and we do not have the keys to decrypt it.'
  6572. };
  6573. // Add types as properties on MediaError
  6574. // e.g. MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
  6575. for (var errNum = 0; errNum < MediaError.errorTypes.length; errNum++) {
  6576. MediaError[MediaError.errorTypes[errNum]] = errNum;
  6577. // values should be accessible on both the class and instance
  6578. MediaError.prototype[MediaError.errorTypes[errNum]] = errNum;
  6579. }
  6580. exports['default'] = MediaError;
  6581. module.exports = exports['default'];
  6582. },{"object.assign":45}],104:[function(_dereq_,module,exports){
  6583. /**
  6584. * @file menu-button.js
  6585. */
  6586. 'use strict';
  6587. exports.__esModule = true;
  6588. 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; } }
  6589. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  6590. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  6591. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6592. var _clickableComponentJs = _dereq_('../clickable-component.js');
  6593. var _clickableComponentJs2 = _interopRequireDefault(_clickableComponentJs);
  6594. var _componentJs = _dereq_('../component.js');
  6595. var _componentJs2 = _interopRequireDefault(_componentJs);
  6596. var _menuJs = _dereq_('./menu.js');
  6597. var _menuJs2 = _interopRequireDefault(_menuJs);
  6598. var _utilsDomJs = _dereq_('../utils/dom.js');
  6599. var Dom = _interopRequireWildcard(_utilsDomJs);
  6600. var _utilsFnJs = _dereq_('../utils/fn.js');
  6601. var Fn = _interopRequireWildcard(_utilsFnJs);
  6602. var _utilsToTitleCaseJs = _dereq_('../utils/to-title-case.js');
  6603. var _utilsToTitleCaseJs2 = _interopRequireDefault(_utilsToTitleCaseJs);
  6604. /**
  6605. * A button class with a popup menu
  6606. *
  6607. * @param {Player|Object} player
  6608. * @param {Object=} options
  6609. * @extends Button
  6610. * @class MenuButton
  6611. */
  6612. var MenuButton = (function (_ClickableComponent) {
  6613. _inherits(MenuButton, _ClickableComponent);
  6614. function MenuButton(player) {
  6615. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  6616. _classCallCheck(this, MenuButton);
  6617. _ClickableComponent.call(this, player, options);
  6618. this.update();
  6619. this.el_.setAttribute('aria-haspopup', true);
  6620. this.el_.setAttribute('role', 'menuitem');
  6621. this.on('keydown', this.handleSubmenuKeyPress);
  6622. }
  6623. /**
  6624. * Update menu
  6625. *
  6626. * @method update
  6627. */
  6628. MenuButton.prototype.update = function update() {
  6629. var menu = this.createMenu();
  6630. if (this.menu) {
  6631. this.removeChild(this.menu);
  6632. }
  6633. this.menu = menu;
  6634. this.addChild(menu);
  6635. /**
  6636. * Track the state of the menu button
  6637. *
  6638. * @type {Boolean}
  6639. * @private
  6640. */
  6641. this.buttonPressed_ = false;
  6642. this.el_.setAttribute('aria-expanded', false);
  6643. if (this.items && this.items.length === 0) {
  6644. this.hide();
  6645. } else if (this.items && this.items.length > 1) {
  6646. this.show();
  6647. }
  6648. };
  6649. /**
  6650. * Create menu
  6651. *
  6652. * @return {Menu} The constructed menu
  6653. * @method createMenu
  6654. */
  6655. MenuButton.prototype.createMenu = function createMenu() {
  6656. var menu = new _menuJs2['default'](this.player_);
  6657. // Add a title list item to the top
  6658. if (this.options_.title) {
  6659. var title = Dom.createEl('li', {
  6660. className: 'vjs-menu-title',
  6661. innerHTML: _utilsToTitleCaseJs2['default'](this.options_.title),
  6662. tabIndex: -1
  6663. });
  6664. menu.children_.unshift(title);
  6665. Dom.insertElFirst(title, menu.contentEl());
  6666. }
  6667. this.items = this['createItems']();
  6668. if (this.items) {
  6669. // Add menu items to the menu
  6670. for (var i = 0; i < this.items.length; i++) {
  6671. menu.addItem(this.items[i]);
  6672. }
  6673. }
  6674. return menu;
  6675. };
  6676. /**
  6677. * Create the list of menu items. Specific to each subclass.
  6678. *
  6679. * @method createItems
  6680. */
  6681. MenuButton.prototype.createItems = function createItems() {};
  6682. /**
  6683. * Create the component's DOM element
  6684. *
  6685. * @return {Element}
  6686. * @method createEl
  6687. */
  6688. MenuButton.prototype.createEl = function createEl() {
  6689. return _ClickableComponent.prototype.createEl.call(this, 'div', {
  6690. className: this.buildCSSClass()
  6691. });
  6692. };
  6693. /**
  6694. * Allow sub components to stack CSS class names
  6695. *
  6696. * @return {String} The constructed class name
  6697. * @method buildCSSClass
  6698. */
  6699. MenuButton.prototype.buildCSSClass = function buildCSSClass() {
  6700. var menuButtonClass = 'vjs-menu-button';
  6701. // If the inline option is passed, we want to use different styles altogether.
  6702. if (this.options_.inline === true) {
  6703. menuButtonClass += '-inline';
  6704. } else {
  6705. menuButtonClass += '-popup';
  6706. }
  6707. return 'vjs-menu-button ' + menuButtonClass + ' ' + _ClickableComponent.prototype.buildCSSClass.call(this);
  6708. };
  6709. /**
  6710. * When you click the button it adds focus, which
  6711. * will show the menu indefinitely.
  6712. * So we'll remove focus when the mouse leaves the button.
  6713. * Focus is needed for tab navigation.
  6714. * Allow sub components to stack CSS class names
  6715. *
  6716. * @method handleClick
  6717. */
  6718. MenuButton.prototype.handleClick = function handleClick() {
  6719. this.one('mouseout', Fn.bind(this, function () {
  6720. this.menu.unlockShowing();
  6721. this.el_.blur();
  6722. }));
  6723. if (this.buttonPressed_) {
  6724. this.unpressButton();
  6725. } else {
  6726. this.pressButton();
  6727. }
  6728. };
  6729. /**
  6730. * Handle key press on menu
  6731. *
  6732. * @param {Object} event Key press event
  6733. * @method handleKeyPress
  6734. */
  6735. MenuButton.prototype.handleKeyPress = function handleKeyPress(event) {
  6736. // Escape (27) key or Tab (9) key unpress the 'button'
  6737. if (event.which === 27 || event.which === 9) {
  6738. if (this.buttonPressed_) {
  6739. this.unpressButton();
  6740. }
  6741. // Don't preventDefault for Tab key - we still want to lose focus
  6742. if (event.which !== 9) {
  6743. event.preventDefault();
  6744. }
  6745. // Up (38) key or Down (40) key press the 'button'
  6746. } else if (event.which === 38 || event.which === 40) {
  6747. if (!this.buttonPressed_) {
  6748. this.pressButton();
  6749. event.preventDefault();
  6750. }
  6751. } else {
  6752. _ClickableComponent.prototype.handleKeyPress.call(this, event);
  6753. }
  6754. };
  6755. /**
  6756. * Handle key press on submenu
  6757. *
  6758. * @param {Object} event Key press event
  6759. * @method handleSubmenuKeyPress
  6760. */
  6761. MenuButton.prototype.handleSubmenuKeyPress = function handleSubmenuKeyPress(event) {
  6762. // Escape (27) key or Tab (9) key unpress the 'button'
  6763. if (event.which === 27 || event.which === 9) {
  6764. if (this.buttonPressed_) {
  6765. this.unpressButton();
  6766. }
  6767. // Don't preventDefault for Tab key - we still want to lose focus
  6768. if (event.which !== 9) {
  6769. event.preventDefault();
  6770. }
  6771. }
  6772. };
  6773. /**
  6774. * Makes changes based on button pressed
  6775. *
  6776. * @method pressButton
  6777. */
  6778. MenuButton.prototype.pressButton = function pressButton() {
  6779. this.buttonPressed_ = true;
  6780. this.menu.lockShowing();
  6781. this.el_.setAttribute('aria-expanded', true);
  6782. this.menu.focus(); // set the focus into the submenu
  6783. };
  6784. /**
  6785. * Makes changes based on button unpressed
  6786. *
  6787. * @method unpressButton
  6788. */
  6789. MenuButton.prototype.unpressButton = function unpressButton() {
  6790. this.buttonPressed_ = false;
  6791. this.menu.unlockShowing();
  6792. this.el_.setAttribute('aria-expanded', false);
  6793. this.el_.focus(); // Set focus back to this menu button
  6794. };
  6795. return MenuButton;
  6796. })(_clickableComponentJs2['default']);
  6797. _componentJs2['default'].registerComponent('MenuButton', MenuButton);
  6798. exports['default'] = MenuButton;
  6799. module.exports = exports['default'];
  6800. },{"../clickable-component.js":65,"../component.js":67,"../utils/dom.js":132,"../utils/fn.js":134,"../utils/to-title-case.js":141,"./menu.js":106}],105:[function(_dereq_,module,exports){
  6801. /**
  6802. * @file menu-item.js
  6803. */
  6804. 'use strict';
  6805. exports.__esModule = true;
  6806. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  6807. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  6808. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6809. var _clickableComponentJs = _dereq_('../clickable-component.js');
  6810. var _clickableComponentJs2 = _interopRequireDefault(_clickableComponentJs);
  6811. var _componentJs = _dereq_('../component.js');
  6812. var _componentJs2 = _interopRequireDefault(_componentJs);
  6813. var _objectAssign = _dereq_('object.assign');
  6814. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  6815. /**
  6816. * The component for a menu item. `<li>`
  6817. *
  6818. * @param {Player|Object} player
  6819. * @param {Object=} options
  6820. * @extends Button
  6821. * @class MenuItem
  6822. */
  6823. var MenuItem = (function (_ClickableComponent) {
  6824. _inherits(MenuItem, _ClickableComponent);
  6825. function MenuItem(player, options) {
  6826. _classCallCheck(this, MenuItem);
  6827. _ClickableComponent.call(this, player, options);
  6828. this.selectable = options['selectable'];
  6829. this.selected(options['selected']);
  6830. if (this.selectable) {
  6831. // TODO: May need to be either menuitemcheckbox or menuitemradio,
  6832. // and may need logical grouping of menu items.
  6833. this.el_.setAttribute('role', 'menuitemcheckbox');
  6834. } else {
  6835. this.el_.setAttribute('role', 'menuitem');
  6836. }
  6837. }
  6838. /**
  6839. * Create the component's DOM element
  6840. *
  6841. * @param {String=} type Desc
  6842. * @param {Object=} props Desc
  6843. * @return {Element}
  6844. * @method createEl
  6845. */
  6846. MenuItem.prototype.createEl = function createEl(type, props, attrs) {
  6847. return _ClickableComponent.prototype.createEl.call(this, 'li', _objectAssign2['default']({
  6848. className: 'vjs-menu-item',
  6849. innerHTML: this.localize(this.options_['label']),
  6850. tabIndex: -1
  6851. }, props), attrs);
  6852. };
  6853. /**
  6854. * Handle a click on the menu item, and set it to selected
  6855. *
  6856. * @method handleClick
  6857. */
  6858. MenuItem.prototype.handleClick = function handleClick() {
  6859. this.selected(true);
  6860. };
  6861. /**
  6862. * Set this menu item as selected or not
  6863. *
  6864. * @param {Boolean} selected
  6865. * @method selected
  6866. */
  6867. MenuItem.prototype.selected = function selected(_selected) {
  6868. if (this.selectable) {
  6869. if (_selected) {
  6870. this.addClass('vjs-selected');
  6871. this.el_.setAttribute('aria-checked', true);
  6872. // aria-checked isn't fully supported by browsers/screen readers,
  6873. // so indicate selected state to screen reader in the control text.
  6874. this.controlText(', selected');
  6875. } else {
  6876. this.removeClass('vjs-selected');
  6877. this.el_.setAttribute('aria-checked', false);
  6878. // Indicate un-selected state to screen reader
  6879. // Note that a space clears out the selected state text
  6880. this.controlText(' ');
  6881. }
  6882. }
  6883. };
  6884. return MenuItem;
  6885. })(_clickableComponentJs2['default']);
  6886. _componentJs2['default'].registerComponent('MenuItem', MenuItem);
  6887. exports['default'] = MenuItem;
  6888. module.exports = exports['default'];
  6889. },{"../clickable-component.js":65,"../component.js":67,"object.assign":45}],106:[function(_dereq_,module,exports){
  6890. /**
  6891. * @file menu.js
  6892. */
  6893. 'use strict';
  6894. exports.__esModule = true;
  6895. 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; } }
  6896. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  6897. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  6898. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  6899. var _componentJs = _dereq_('../component.js');
  6900. var _componentJs2 = _interopRequireDefault(_componentJs);
  6901. var _utilsDomJs = _dereq_('../utils/dom.js');
  6902. var Dom = _interopRequireWildcard(_utilsDomJs);
  6903. var _utilsFnJs = _dereq_('../utils/fn.js');
  6904. var Fn = _interopRequireWildcard(_utilsFnJs);
  6905. var _utilsEventsJs = _dereq_('../utils/events.js');
  6906. var Events = _interopRequireWildcard(_utilsEventsJs);
  6907. /**
  6908. * The Menu component is used to build pop up menus, including subtitle and
  6909. * captions selection menus.
  6910. *
  6911. * @extends Component
  6912. * @class Menu
  6913. */
  6914. var Menu = (function (_Component) {
  6915. _inherits(Menu, _Component);
  6916. function Menu(player, options) {
  6917. _classCallCheck(this, Menu);
  6918. _Component.call(this, player, options);
  6919. this.focusedChild_ = -1;
  6920. this.on('keydown', this.handleKeyPress);
  6921. }
  6922. /**
  6923. * Add a menu item to the menu
  6924. *
  6925. * @param {Object|String} component Component or component type to add
  6926. * @method addItem
  6927. */
  6928. Menu.prototype.addItem = function addItem(component) {
  6929. this.addChild(component);
  6930. component.on('click', Fn.bind(this, function () {
  6931. this.unlockShowing();
  6932. //TODO: Need to set keyboard focus back to the menuButton
  6933. }));
  6934. };
  6935. /**
  6936. * Create the component's DOM element
  6937. *
  6938. * @return {Element}
  6939. * @method createEl
  6940. */
  6941. Menu.prototype.createEl = function createEl() {
  6942. var contentElType = this.options_.contentElType || 'ul';
  6943. this.contentEl_ = Dom.createEl(contentElType, {
  6944. className: 'vjs-menu-content'
  6945. });
  6946. this.contentEl_.setAttribute('role', 'menu');
  6947. var el = _Component.prototype.createEl.call(this, 'div', {
  6948. append: this.contentEl_,
  6949. className: 'vjs-menu'
  6950. });
  6951. el.setAttribute('role', 'presentation');
  6952. el.appendChild(this.contentEl_);
  6953. // Prevent clicks from bubbling up. Needed for Menu Buttons,
  6954. // where a click on the parent is significant
  6955. Events.on(el, 'click', function (event) {
  6956. event.preventDefault();
  6957. event.stopImmediatePropagation();
  6958. });
  6959. return el;
  6960. };
  6961. /**
  6962. * Handle key press for menu
  6963. *
  6964. * @param {Object} event Event object
  6965. * @method handleKeyPress
  6966. */
  6967. Menu.prototype.handleKeyPress = function handleKeyPress(event) {
  6968. if (event.which === 37 || event.which === 40) {
  6969. // Left and Down Arrows
  6970. event.preventDefault();
  6971. this.stepForward();
  6972. } else if (event.which === 38 || event.which === 39) {
  6973. // Up and Right Arrows
  6974. event.preventDefault();
  6975. this.stepBack();
  6976. }
  6977. };
  6978. /**
  6979. * Move to next (lower) menu item for keyboard users
  6980. *
  6981. * @method stepForward
  6982. */
  6983. Menu.prototype.stepForward = function stepForward() {
  6984. var stepChild = 0;
  6985. if (this.focusedChild_ !== undefined) {
  6986. stepChild = this.focusedChild_ + 1;
  6987. }
  6988. this.focus(stepChild);
  6989. };
  6990. /**
  6991. * Move to previous (higher) menu item for keyboard users
  6992. *
  6993. * @method stepBack
  6994. */
  6995. Menu.prototype.stepBack = function stepBack() {
  6996. var stepChild = 0;
  6997. if (this.focusedChild_ !== undefined) {
  6998. stepChild = this.focusedChild_ - 1;
  6999. }
  7000. this.focus(stepChild);
  7001. };
  7002. /**
  7003. * Set focus on a menu item in the menu
  7004. *
  7005. * @param {Object|String} item Index of child item set focus on
  7006. * @method focus
  7007. */
  7008. Menu.prototype.focus = function focus() {
  7009. var item = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
  7010. var children = this.children().slice();
  7011. var haveTitle = children.length && children[0].className && /vjs-menu-title/.test(children[0].className);
  7012. if (haveTitle) {
  7013. children.shift();
  7014. }
  7015. if (children.length > 0) {
  7016. if (item < 0) {
  7017. item = 0;
  7018. } else if (item >= children.length) {
  7019. item = children.length - 1;
  7020. }
  7021. this.focusedChild_ = item;
  7022. children[item].el_.focus();
  7023. }
  7024. };
  7025. return Menu;
  7026. })(_componentJs2['default']);
  7027. _componentJs2['default'].registerComponent('Menu', Menu);
  7028. exports['default'] = Menu;
  7029. module.exports = exports['default'];
  7030. },{"../component.js":67,"../utils/dom.js":132,"../utils/events.js":133,"../utils/fn.js":134}],107:[function(_dereq_,module,exports){
  7031. /**
  7032. * @file modal-dialog.js
  7033. */
  7034. 'use strict';
  7035. exports.__esModule = true;
  7036. 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; } }
  7037. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  7038. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  7039. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7040. var _globalDocument = _dereq_('global/document');
  7041. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  7042. var _utilsDom = _dereq_('./utils/dom');
  7043. var Dom = _interopRequireWildcard(_utilsDom);
  7044. var _utilsFn = _dereq_('./utils/fn');
  7045. var Fn = _interopRequireWildcard(_utilsFn);
  7046. var _utilsLog = _dereq_('./utils/log');
  7047. var _utilsLog2 = _interopRequireDefault(_utilsLog);
  7048. var _component = _dereq_('./component');
  7049. var _component2 = _interopRequireDefault(_component);
  7050. var _closeButton = _dereq_('./close-button');
  7051. var _closeButton2 = _interopRequireDefault(_closeButton);
  7052. var MODAL_CLASS_NAME = 'vjs-modal-dialog';
  7053. var ESC = 27;
  7054. /**
  7055. * The `ModalDialog` displays over the video and its controls, which blocks
  7056. * interaction with the player until it is closed.
  7057. *
  7058. * Modal dialogs include a "Close" button and will close when that button
  7059. * is activated - or when ESC is pressed anywhere.
  7060. *
  7061. * @extends Component
  7062. * @class ModalDialog
  7063. */
  7064. var ModalDialog = (function (_Component) {
  7065. _inherits(ModalDialog, _Component);
  7066. /**
  7067. * Constructor for modals.
  7068. *
  7069. * @param {Player} player
  7070. * @param {Object} [options]
  7071. * @param {Mixed} [options.content=undefined]
  7072. * Provide customized content for this modal.
  7073. *
  7074. * @param {String} [options.description]
  7075. * A text description for the modal, primarily for accessibility.
  7076. *
  7077. * @param {Boolean} [options.fillAlways=false]
  7078. * Normally, modals are automatically filled only the first time
  7079. * they open. This tells the modal to refresh its content
  7080. * every time it opens.
  7081. *
  7082. * @param {String} [options.label]
  7083. * A text label for the modal, primarily for accessibility.
  7084. *
  7085. * @param {Boolean} [options.temporary=true]
  7086. * If `true`, the modal can only be opened once; it will be
  7087. * disposed as soon as it's closed.
  7088. *
  7089. * @param {Boolean} [options.uncloseable=false]
  7090. * If `true`, the user will not be able to close the modal
  7091. * through the UI in the normal ways. Programmatic closing is
  7092. * still possible.
  7093. *
  7094. */
  7095. function ModalDialog(player, options) {
  7096. _classCallCheck(this, ModalDialog);
  7097. _Component.call(this, player, options);
  7098. this.opened_ = this.hasBeenOpened_ = this.hasBeenFilled_ = false;
  7099. this.closeable(!this.options_.uncloseable);
  7100. this.content(this.options_.content);
  7101. // Make sure the contentEl is defined AFTER any children are initialized
  7102. // because we only want the contents of the modal in the contentEl
  7103. // (not the UI elements like the close button).
  7104. this.contentEl_ = Dom.createEl('div', {
  7105. className: MODAL_CLASS_NAME + '-content'
  7106. }, {
  7107. role: 'document'
  7108. });
  7109. this.descEl_ = Dom.createEl('p', {
  7110. className: MODAL_CLASS_NAME + '-description vjs-offscreen',
  7111. id: this.el().getAttribute('aria-describedby')
  7112. });
  7113. Dom.textContent(this.descEl_, this.description());
  7114. this.el_.appendChild(this.descEl_);
  7115. this.el_.appendChild(this.contentEl_);
  7116. }
  7117. /*
  7118. * Modal dialog default options.
  7119. *
  7120. * @type {Object}
  7121. * @private
  7122. */
  7123. /**
  7124. * Create the modal's DOM element
  7125. *
  7126. * @method createEl
  7127. * @return {Element}
  7128. */
  7129. ModalDialog.prototype.createEl = function createEl() {
  7130. return _Component.prototype.createEl.call(this, 'div', {
  7131. className: this.buildCSSClass(),
  7132. tabIndex: -1
  7133. }, {
  7134. 'aria-describedby': this.id() + '_description',
  7135. 'aria-hidden': 'true',
  7136. 'aria-label': this.label(),
  7137. role: 'dialog'
  7138. });
  7139. };
  7140. /**
  7141. * Build the modal's CSS class.
  7142. *
  7143. * @method buildCSSClass
  7144. * @return {String}
  7145. */
  7146. ModalDialog.prototype.buildCSSClass = function buildCSSClass() {
  7147. return MODAL_CLASS_NAME + ' vjs-hidden ' + _Component.prototype.buildCSSClass.call(this);
  7148. };
  7149. /**
  7150. * Handles key presses on the document, looking for ESC, which closes
  7151. * the modal.
  7152. *
  7153. * @method handleKeyPress
  7154. * @param {Event} e
  7155. */
  7156. ModalDialog.prototype.handleKeyPress = function handleKeyPress(e) {
  7157. if (e.which === ESC && this.closeable()) {
  7158. this.close();
  7159. }
  7160. };
  7161. /**
  7162. * Returns the label string for this modal. Primarily used for accessibility.
  7163. *
  7164. * @return {String}
  7165. */
  7166. ModalDialog.prototype.label = function label() {
  7167. return this.options_.label || this.localize('Modal Window');
  7168. };
  7169. /**
  7170. * Returns the description string for this modal. Primarily used for
  7171. * accessibility.
  7172. *
  7173. * @return {String}
  7174. */
  7175. ModalDialog.prototype.description = function description() {
  7176. var desc = this.options_.description || this.localize('This is a modal window.');
  7177. // Append a universal closeability message if the modal is closeable.
  7178. if (this.closeable()) {
  7179. desc += ' ' + this.localize('This modal can be closed by pressing the Escape key or activating the close button.');
  7180. }
  7181. return desc;
  7182. };
  7183. /**
  7184. * Opens the modal.
  7185. *
  7186. * @method open
  7187. * @return {ModalDialog}
  7188. */
  7189. ModalDialog.prototype.open = function open() {
  7190. if (!this.opened_) {
  7191. var player = this.player();
  7192. this.trigger('beforemodalopen');
  7193. this.opened_ = true;
  7194. // Fill content if the modal has never opened before and
  7195. // never been filled.
  7196. if (this.options_.fillAlways || !this.hasBeenOpened_ && !this.hasBeenFilled_) {
  7197. this.fill();
  7198. }
  7199. // If the player was playing, pause it and take note of its previously
  7200. // playing state.
  7201. this.wasPlaying_ = !player.paused();
  7202. if (this.wasPlaying_) {
  7203. player.pause();
  7204. }
  7205. if (this.closeable()) {
  7206. this.on(_globalDocument2['default'], 'keydown', Fn.bind(this, this.handleKeyPress));
  7207. }
  7208. player.controls(false);
  7209. this.show();
  7210. this.el().setAttribute('aria-hidden', 'false');
  7211. this.trigger('modalopen');
  7212. this.hasBeenOpened_ = true;
  7213. }
  7214. return this;
  7215. };
  7216. /**
  7217. * Whether or not the modal is opened currently.
  7218. *
  7219. * @method opened
  7220. * @param {Boolean} [value]
  7221. * If given, it will open (`true`) or close (`false`) the modal.
  7222. *
  7223. * @return {Boolean}
  7224. */
  7225. ModalDialog.prototype.opened = function opened(value) {
  7226. if (typeof value === 'boolean') {
  7227. this[value ? 'open' : 'close']();
  7228. }
  7229. return this.opened_;
  7230. };
  7231. /**
  7232. * Closes the modal.
  7233. *
  7234. * @method close
  7235. * @return {ModalDialog}
  7236. */
  7237. ModalDialog.prototype.close = function close() {
  7238. if (this.opened_) {
  7239. var player = this.player();
  7240. this.trigger('beforemodalclose');
  7241. this.opened_ = false;
  7242. if (this.wasPlaying_) {
  7243. player.play();
  7244. }
  7245. if (this.closeable()) {
  7246. this.off(_globalDocument2['default'], 'keydown', Fn.bind(this, this.handleKeyPress));
  7247. }
  7248. player.controls(true);
  7249. this.hide();
  7250. this.el().setAttribute('aria-hidden', 'true');
  7251. this.trigger('modalclose');
  7252. if (this.options_.temporary) {
  7253. this.dispose();
  7254. }
  7255. }
  7256. return this;
  7257. };
  7258. /**
  7259. * Whether or not the modal is closeable via the UI.
  7260. *
  7261. * @method closeable
  7262. * @param {Boolean} [value]
  7263. * If given as a Boolean, it will set the `closeable` option.
  7264. *
  7265. * @return {Boolean}
  7266. */
  7267. ModalDialog.prototype.closeable = function closeable(value) {
  7268. if (typeof value === 'boolean') {
  7269. var closeable = this.closeable_ = !!value;
  7270. var _close = this.getChild('closeButton');
  7271. // If this is being made closeable and has no close button, add one.
  7272. if (closeable && !_close) {
  7273. // The close button should be a child of the modal - not its
  7274. // content element, so temporarily change the content element.
  7275. var temp = this.contentEl_;
  7276. this.contentEl_ = this.el_;
  7277. _close = this.addChild('closeButton');
  7278. this.contentEl_ = temp;
  7279. this.on(_close, 'close', this.close);
  7280. }
  7281. // If this is being made uncloseable and has a close button, remove it.
  7282. if (!closeable && _close) {
  7283. this.off(_close, 'close', this.close);
  7284. this.removeChild(_close);
  7285. _close.dispose();
  7286. }
  7287. }
  7288. return this.closeable_;
  7289. };
  7290. /**
  7291. * Fill the modal's content element with the modal's "content" option.
  7292. *
  7293. * The content element will be emptied before this change takes place.
  7294. *
  7295. * @method fill
  7296. * @return {ModalDialog}
  7297. */
  7298. ModalDialog.prototype.fill = function fill() {
  7299. return this.fillWith(this.content());
  7300. };
  7301. /**
  7302. * Fill the modal's content element with arbitrary content.
  7303. *
  7304. * The content element will be emptied before this change takes place.
  7305. *
  7306. * @method fillWith
  7307. * @param {Mixed} [content]
  7308. * The same rules apply to this as apply to the `content` option.
  7309. *
  7310. * @return {ModalDialog}
  7311. */
  7312. ModalDialog.prototype.fillWith = function fillWith(content) {
  7313. var contentEl = this.contentEl();
  7314. var parentEl = contentEl.parentNode;
  7315. var nextSiblingEl = contentEl.nextSibling;
  7316. this.trigger('beforemodalfill');
  7317. this.hasBeenFilled_ = true;
  7318. // Detach the content element from the DOM before performing
  7319. // manipulation to avoid modifying the live DOM multiple times.
  7320. parentEl.removeChild(contentEl);
  7321. this.empty();
  7322. Dom.insertContent(contentEl, content);
  7323. this.trigger('modalfill');
  7324. // Re-inject the re-filled content element.
  7325. if (nextSiblingEl) {
  7326. parentEl.insertBefore(contentEl, nextSiblingEl);
  7327. } else {
  7328. parentEl.appendChild(contentEl);
  7329. }
  7330. return this;
  7331. };
  7332. /**
  7333. * Empties the content element.
  7334. *
  7335. * This happens automatically anytime the modal is filled.
  7336. *
  7337. * @method empty
  7338. * @return {ModalDialog}
  7339. */
  7340. ModalDialog.prototype.empty = function empty() {
  7341. this.trigger('beforemodalempty');
  7342. Dom.emptyEl(this.contentEl());
  7343. this.trigger('modalempty');
  7344. return this;
  7345. };
  7346. /**
  7347. * Gets or sets the modal content, which gets normalized before being
  7348. * rendered into the DOM.
  7349. *
  7350. * This does not update the DOM or fill the modal, but it is called during
  7351. * that process.
  7352. *
  7353. * @method content
  7354. * @param {Mixed} [value]
  7355. * If defined, sets the internal content value to be used on the
  7356. * next call(s) to `fill`. This value is normalized before being
  7357. * inserted. To "clear" the internal content value, pass `null`.
  7358. *
  7359. * @return {Mixed}
  7360. */
  7361. ModalDialog.prototype.content = function content(value) {
  7362. if (typeof value !== 'undefined') {
  7363. this.content_ = value;
  7364. }
  7365. return this.content_;
  7366. };
  7367. return ModalDialog;
  7368. })(_component2['default']);
  7369. ModalDialog.prototype.options_ = {
  7370. temporary: true
  7371. };
  7372. _component2['default'].registerComponent('ModalDialog', ModalDialog);
  7373. exports['default'] = ModalDialog;
  7374. module.exports = exports['default'];
  7375. },{"./close-button":66,"./component":67,"./utils/dom":132,"./utils/fn":134,"./utils/log":137,"global/document":1}],108:[function(_dereq_,module,exports){
  7376. /**
  7377. * @file player.js
  7378. */
  7379. // Subclasses Component
  7380. 'use strict';
  7381. exports.__esModule = true;
  7382. 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; } }
  7383. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  7384. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  7385. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  7386. var _componentJs = _dereq_('./component.js');
  7387. var _componentJs2 = _interopRequireDefault(_componentJs);
  7388. var _globalDocument = _dereq_('global/document');
  7389. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  7390. var _globalWindow = _dereq_('global/window');
  7391. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  7392. var _utilsEventsJs = _dereq_('./utils/events.js');
  7393. var Events = _interopRequireWildcard(_utilsEventsJs);
  7394. var _utilsDomJs = _dereq_('./utils/dom.js');
  7395. var Dom = _interopRequireWildcard(_utilsDomJs);
  7396. var _utilsFnJs = _dereq_('./utils/fn.js');
  7397. var Fn = _interopRequireWildcard(_utilsFnJs);
  7398. var _utilsGuidJs = _dereq_('./utils/guid.js');
  7399. var Guid = _interopRequireWildcard(_utilsGuidJs);
  7400. var _utilsBrowserJs = _dereq_('./utils/browser.js');
  7401. var browser = _interopRequireWildcard(_utilsBrowserJs);
  7402. var _utilsLogJs = _dereq_('./utils/log.js');
  7403. var _utilsLogJs2 = _interopRequireDefault(_utilsLogJs);
  7404. var _utilsToTitleCaseJs = _dereq_('./utils/to-title-case.js');
  7405. var _utilsToTitleCaseJs2 = _interopRequireDefault(_utilsToTitleCaseJs);
  7406. var _utilsTimeRangesJs = _dereq_('./utils/time-ranges.js');
  7407. var _utilsBufferJs = _dereq_('./utils/buffer.js');
  7408. var _utilsStylesheetJs = _dereq_('./utils/stylesheet.js');
  7409. var stylesheet = _interopRequireWildcard(_utilsStylesheetJs);
  7410. var _fullscreenApiJs = _dereq_('./fullscreen-api.js');
  7411. var _fullscreenApiJs2 = _interopRequireDefault(_fullscreenApiJs);
  7412. var _mediaErrorJs = _dereq_('./media-error.js');
  7413. var _mediaErrorJs2 = _interopRequireDefault(_mediaErrorJs);
  7414. var _safeJsonParseTuple = _dereq_('safe-json-parse/tuple');
  7415. var _safeJsonParseTuple2 = _interopRequireDefault(_safeJsonParseTuple);
  7416. var _objectAssign = _dereq_('object.assign');
  7417. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  7418. var _utilsMergeOptionsJs = _dereq_('./utils/merge-options.js');
  7419. var _utilsMergeOptionsJs2 = _interopRequireDefault(_utilsMergeOptionsJs);
  7420. var _tracksTextTrackListConverterJs = _dereq_('./tracks/text-track-list-converter.js');
  7421. var _tracksTextTrackListConverterJs2 = _interopRequireDefault(_tracksTextTrackListConverterJs);
  7422. // Include required child components (importing also registers them)
  7423. var _techLoaderJs = _dereq_('./tech/loader.js');
  7424. var _techLoaderJs2 = _interopRequireDefault(_techLoaderJs);
  7425. var _posterImageJs = _dereq_('./poster-image.js');
  7426. var _posterImageJs2 = _interopRequireDefault(_posterImageJs);
  7427. var _tracksTextTrackDisplayJs = _dereq_('./tracks/text-track-display.js');
  7428. var _tracksTextTrackDisplayJs2 = _interopRequireDefault(_tracksTextTrackDisplayJs);
  7429. var _loadingSpinnerJs = _dereq_('./loading-spinner.js');
  7430. var _loadingSpinnerJs2 = _interopRequireDefault(_loadingSpinnerJs);
  7431. var _bigPlayButtonJs = _dereq_('./big-play-button.js');
  7432. var _bigPlayButtonJs2 = _interopRequireDefault(_bigPlayButtonJs);
  7433. var _controlBarControlBarJs = _dereq_('./control-bar/control-bar.js');
  7434. var _controlBarControlBarJs2 = _interopRequireDefault(_controlBarControlBarJs);
  7435. var _errorDisplayJs = _dereq_('./error-display.js');
  7436. var _errorDisplayJs2 = _interopRequireDefault(_errorDisplayJs);
  7437. var _tracksTextTrackSettingsJs = _dereq_('./tracks/text-track-settings.js');
  7438. var _tracksTextTrackSettingsJs2 = _interopRequireDefault(_tracksTextTrackSettingsJs);
  7439. var _modalDialog = _dereq_('./modal-dialog');
  7440. var _modalDialog2 = _interopRequireDefault(_modalDialog);
  7441. // Require html5 tech, at least for disposing the original video tag
  7442. var _techTechJs = _dereq_('./tech/tech.js');
  7443. var _techTechJs2 = _interopRequireDefault(_techTechJs);
  7444. var _techHtml5Js = _dereq_('./tech/html5.js');
  7445. var _techHtml5Js2 = _interopRequireDefault(_techHtml5Js);
  7446. /**
  7447. * An instance of the `Player` class is created when any of the Video.js setup methods are used to initialize a video.
  7448. * ```js
  7449. * var myPlayer = videojs('example_video_1');
  7450. * ```
  7451. * In the following example, the `data-setup` attribute tells the Video.js library to create a player instance when the library is ready.
  7452. * ```html
  7453. * <video id="example_video_1" data-setup='{}' controls>
  7454. * <source src="my-source.mp4" type="video/mp4">
  7455. * </video>
  7456. * ```
  7457. * After an instance has been created it can be accessed globally using `Video('example_video_1')`.
  7458. *
  7459. * @param {Element} tag The original video tag used for configuring options
  7460. * @param {Object=} options Object of option names and values
  7461. * @param {Function=} ready Ready callback function
  7462. * @extends Component
  7463. * @class Player
  7464. */
  7465. var Player = (function (_Component) {
  7466. _inherits(Player, _Component);
  7467. /**
  7468. * player's constructor function
  7469. *
  7470. * @constructs
  7471. * @method init
  7472. * @param {Element} tag The original video tag used for configuring options
  7473. * @param {Object=} options Player options
  7474. * @param {Function=} ready Ready callback function
  7475. */
  7476. function Player(tag, options, ready) {
  7477. var _this = this;
  7478. _classCallCheck(this, Player);
  7479. // Make sure tag ID exists
  7480. tag.id = tag.id || 'vjs_video_' + Guid.newGUID();
  7481. // Set Options
  7482. // The options argument overrides options set in the video tag
  7483. // which overrides globally set options.
  7484. // This latter part coincides with the load order
  7485. // (tag must exist before Player)
  7486. options = _objectAssign2['default'](Player.getTagSettings(tag), options);
  7487. // Delay the initialization of children because we need to set up
  7488. // player properties first, and can't use `this` before `super()`
  7489. options.initChildren = false;
  7490. // Same with creating the element
  7491. options.createEl = false;
  7492. // we don't want the player to report touch activity on itself
  7493. // see enableTouchActivity in Component
  7494. options.reportTouchActivity = false;
  7495. // Run base component initializing with new options
  7496. _Component.call(this, null, options, ready);
  7497. // if the global option object was accidentally blown away by
  7498. // someone, bail early with an informative error
  7499. if (!this.options_ || !this.options_.techOrder || !this.options_.techOrder.length) {
  7500. throw new Error('No techOrder specified. Did you overwrite ' + 'videojs.options instead of just changing the ' + 'properties you want to override?');
  7501. }
  7502. this.tag = tag; // Store the original tag used to set options
  7503. // Store the tag attributes used to restore html5 element
  7504. this.tagAttributes = tag && Dom.getElAttributes(tag);
  7505. // Update current language
  7506. this.language(this.options_.language);
  7507. // Update Supported Languages
  7508. if (options.languages) {
  7509. (function () {
  7510. // Normalise player option languages to lowercase
  7511. var languagesToLower = {};
  7512. Object.getOwnPropertyNames(options.languages).forEach(function (name) {
  7513. languagesToLower[name.toLowerCase()] = options.languages[name];
  7514. });
  7515. _this.languages_ = languagesToLower;
  7516. })();
  7517. } else {
  7518. this.languages_ = Player.prototype.options_.languages;
  7519. }
  7520. // Cache for video property values.
  7521. this.cache_ = {};
  7522. // Set poster
  7523. this.poster_ = options.poster || '';
  7524. // Set controls
  7525. this.controls_ = !!options.controls;
  7526. // Original tag settings stored in options
  7527. // now remove immediately so native controls don't flash.
  7528. // May be turned back on by HTML5 tech if nativeControlsForTouch is true
  7529. tag.controls = false;
  7530. /*
  7531. * Store the internal state of scrubbing
  7532. *
  7533. * @private
  7534. * @return {Boolean} True if the user is scrubbing
  7535. */
  7536. this.scrubbing_ = false;
  7537. this.el_ = this.createEl();
  7538. // We also want to pass the original player options to each component and plugin
  7539. // as well so they don't need to reach back into the player for options later.
  7540. // We also need to do another copy of this.options_ so we don't end up with
  7541. // an infinite loop.
  7542. var playerOptionsCopy = _utilsMergeOptionsJs2['default'](this.options_);
  7543. // Load plugins
  7544. if (options.plugins) {
  7545. (function () {
  7546. var plugins = options.plugins;
  7547. Object.getOwnPropertyNames(plugins).forEach(function (name) {
  7548. if (typeof this[name] === 'function') {
  7549. this[name](plugins[name]);
  7550. } else {
  7551. _utilsLogJs2['default'].error('Unable to find plugin:', name);
  7552. }
  7553. }, _this);
  7554. })();
  7555. }
  7556. this.options_.playerOptions = playerOptionsCopy;
  7557. this.initChildren();
  7558. // Set isAudio based on whether or not an audio tag was used
  7559. this.isAudio(tag.nodeName.toLowerCase() === 'audio');
  7560. // Update controls className. Can't do this when the controls are initially
  7561. // set because the element doesn't exist yet.
  7562. if (this.controls()) {
  7563. this.addClass('vjs-controls-enabled');
  7564. } else {
  7565. this.addClass('vjs-controls-disabled');
  7566. }
  7567. if (this.isAudio()) {
  7568. this.addClass('vjs-audio');
  7569. }
  7570. if (this.flexNotSupported_()) {
  7571. this.addClass('vjs-no-flex');
  7572. }
  7573. // TODO: Make this smarter. Toggle user state between touching/mousing
  7574. // using events, since devices can have both touch and mouse events.
  7575. // if (browser.TOUCH_ENABLED) {
  7576. // this.addClass('vjs-touch-enabled');
  7577. // }
  7578. // iOS Safari has broken hover handling
  7579. if (!browser.IS_IOS) {
  7580. this.addClass('vjs-workinghover');
  7581. }
  7582. // Make player easily findable by ID
  7583. Player.players[this.id_] = this;
  7584. // When the player is first initialized, trigger activity so components
  7585. // like the control bar show themselves if needed
  7586. this.userActive(true);
  7587. this.reportUserActivity();
  7588. this.listenForUserActivity_();
  7589. this.on('fullscreenchange', this.handleFullscreenChange_);
  7590. this.on('stageclick', this.handleStageClick_);
  7591. }
  7592. /*
  7593. * Global player list
  7594. *
  7595. * @type {Object}
  7596. */
  7597. /**
  7598. * Destroys the video player and does any necessary cleanup
  7599. * ```js
  7600. * myPlayer.dispose();
  7601. * ```
  7602. * This is especially helpful if you are dynamically adding and removing videos
  7603. * to/from the DOM.
  7604. *
  7605. * @method dispose
  7606. */
  7607. Player.prototype.dispose = function dispose() {
  7608. this.trigger('dispose');
  7609. // prevent dispose from being called twice
  7610. this.off('dispose');
  7611. if (this.styleEl_ && this.styleEl_.parentNode) {
  7612. this.styleEl_.parentNode.removeChild(this.styleEl_);
  7613. }
  7614. // Kill reference to this player
  7615. Player.players[this.id_] = null;
  7616. if (this.tag && this.tag.player) {
  7617. this.tag.player = null;
  7618. }
  7619. if (this.el_ && this.el_.player) {
  7620. this.el_.player = null;
  7621. }
  7622. if (this.tech_) {
  7623. this.tech_.dispose();
  7624. }
  7625. _Component.prototype.dispose.call(this);
  7626. };
  7627. /**
  7628. * Create the component's DOM element
  7629. *
  7630. * @return {Element}
  7631. * @method createEl
  7632. */
  7633. Player.prototype.createEl = function createEl() {
  7634. var el = this.el_ = _Component.prototype.createEl.call(this, 'div');
  7635. var tag = this.tag;
  7636. // Remove width/height attrs from tag so CSS can make it 100% width/height
  7637. tag.removeAttribute('width');
  7638. tag.removeAttribute('height');
  7639. // Copy over all the attributes from the tag, including ID and class
  7640. // ID will now reference player box, not the video tag
  7641. var attrs = Dom.getElAttributes(tag);
  7642. Object.getOwnPropertyNames(attrs).forEach(function (attr) {
  7643. // workaround so we don't totally break IE7
  7644. // http://stackoverflow.com/questions/3653444/css-styles-not-applied-on-dynamic-elements-in-internet-explorer-7
  7645. if (attr === 'class') {
  7646. el.className = attrs[attr];
  7647. } else {
  7648. el.setAttribute(attr, attrs[attr]);
  7649. }
  7650. });
  7651. // Update tag id/class for use as HTML5 playback tech
  7652. // Might think we should do this after embedding in container so .vjs-tech class
  7653. // doesn't flash 100% width/height, but class only applies with .video-js parent
  7654. tag.playerId = tag.id;
  7655. tag.id += '_html5_api';
  7656. tag.className = 'vjs-tech';
  7657. // Make player findable on elements
  7658. tag.player = el.player = this;
  7659. // Default state of video is paused
  7660. this.addClass('vjs-paused');
  7661. // Add a style element in the player that we'll use to set the width/height
  7662. // of the player in a way that's still overrideable by CSS, just like the
  7663. // video element
  7664. this.styleEl_ = stylesheet.createStyleElement('vjs-styles-dimensions');
  7665. var defaultsStyleEl = Dom.$('.vjs-styles-defaults');
  7666. var head = Dom.$('head');
  7667. head.insertBefore(this.styleEl_, defaultsStyleEl ? defaultsStyleEl.nextSibling : head.firstChild);
  7668. // Pass in the width/height/aspectRatio options which will update the style el
  7669. this.width(this.options_.width);
  7670. this.height(this.options_.height);
  7671. this.fluid(this.options_.fluid);
  7672. this.aspectRatio(this.options_.aspectRatio);
  7673. // insertElFirst seems to cause the networkState to flicker from 3 to 2, so
  7674. // keep track of the original for later so we can know if the source originally failed
  7675. tag.initNetworkState_ = tag.networkState;
  7676. // Wrap video tag in div (el/box) container
  7677. if (tag.parentNode) {
  7678. tag.parentNode.insertBefore(el, tag);
  7679. }
  7680. // insert the tag as the first child of the player element
  7681. // then manually add it to the children array so that this.addChild
  7682. // will work properly for other components
  7683. Dom.insertElFirst(tag, el); // Breaks iPhone, fixed in HTML5 setup.
  7684. this.children_.unshift(tag);
  7685. this.el_ = el;
  7686. return el;
  7687. };
  7688. /**
  7689. * Get/set player width
  7690. *
  7691. * @param {Number=} value Value for width
  7692. * @return {Number} Width when getting
  7693. * @method width
  7694. */
  7695. Player.prototype.width = function width(value) {
  7696. return this.dimension('width', value);
  7697. };
  7698. /**
  7699. * Get/set player height
  7700. *
  7701. * @param {Number=} value Value for height
  7702. * @return {Number} Height when getting
  7703. * @method height
  7704. */
  7705. Player.prototype.height = function height(value) {
  7706. return this.dimension('height', value);
  7707. };
  7708. /**
  7709. * Get/set dimension for player
  7710. *
  7711. * @param {String} dimension Either width or height
  7712. * @param {Number=} value Value for dimension
  7713. * @return {Component}
  7714. * @method dimension
  7715. */
  7716. Player.prototype.dimension = function dimension(_dimension, value) {
  7717. var privDimension = _dimension + '_';
  7718. if (value === undefined) {
  7719. return this[privDimension] || 0;
  7720. }
  7721. if (value === '') {
  7722. // If an empty string is given, reset the dimension to be automatic
  7723. this[privDimension] = undefined;
  7724. } else {
  7725. var parsedVal = parseFloat(value);
  7726. if (isNaN(parsedVal)) {
  7727. _utilsLogJs2['default'].error('Improper value "' + value + '" supplied for for ' + _dimension);
  7728. return this;
  7729. }
  7730. this[privDimension] = parsedVal;
  7731. }
  7732. this.updateStyleEl_();
  7733. return this;
  7734. };
  7735. /**
  7736. * Add/remove the vjs-fluid class
  7737. *
  7738. * @param {Boolean} bool Value of true adds the class, value of false removes the class
  7739. * @method fluid
  7740. */
  7741. Player.prototype.fluid = function fluid(bool) {
  7742. if (bool === undefined) {
  7743. return !!this.fluid_;
  7744. }
  7745. this.fluid_ = !!bool;
  7746. if (bool) {
  7747. this.addClass('vjs-fluid');
  7748. } else {
  7749. this.removeClass('vjs-fluid');
  7750. }
  7751. };
  7752. /**
  7753. * Get/Set the aspect ratio
  7754. *
  7755. * @param {String=} ratio Aspect ratio for player
  7756. * @return aspectRatio
  7757. * @method aspectRatio
  7758. */
  7759. Player.prototype.aspectRatio = function aspectRatio(ratio) {
  7760. if (ratio === undefined) {
  7761. return this.aspectRatio_;
  7762. }
  7763. // Check for width:height format
  7764. if (!/^\d+\:\d+$/.test(ratio)) {
  7765. throw new Error('Improper value supplied for aspect ratio. The format should be width:height, for example 16:9.');
  7766. }
  7767. this.aspectRatio_ = ratio;
  7768. // We're assuming if you set an aspect ratio you want fluid mode,
  7769. // because in fixed mode you could calculate width and height yourself.
  7770. this.fluid(true);
  7771. this.updateStyleEl_();
  7772. };
  7773. /**
  7774. * Update styles of the player element (height, width and aspect ratio)
  7775. *
  7776. * @method updateStyleEl_
  7777. */
  7778. Player.prototype.updateStyleEl_ = function updateStyleEl_() {
  7779. var width = undefined;
  7780. var height = undefined;
  7781. var aspectRatio = undefined;
  7782. var idClass = undefined;
  7783. // The aspect ratio is either used directly or to calculate width and height.
  7784. if (this.aspectRatio_ !== undefined && this.aspectRatio_ !== 'auto') {
  7785. // Use any aspectRatio that's been specifically set
  7786. aspectRatio = this.aspectRatio_;
  7787. } else if (this.videoWidth()) {
  7788. // Otherwise try to get the aspect ratio from the video metadata
  7789. aspectRatio = this.videoWidth() + ':' + this.videoHeight();
  7790. } else {
  7791. // Or use a default. The video element's is 2:1, but 16:9 is more common.
  7792. aspectRatio = '16:9';
  7793. }
  7794. // Get the ratio as a decimal we can use to calculate dimensions
  7795. var ratioParts = aspectRatio.split(':');
  7796. var ratioMultiplier = ratioParts[1] / ratioParts[0];
  7797. if (this.width_ !== undefined) {
  7798. // Use any width that's been specifically set
  7799. width = this.width_;
  7800. } else if (this.height_ !== undefined) {
  7801. // Or calulate the width from the aspect ratio if a height has been set
  7802. width = this.height_ / ratioMultiplier;
  7803. } else {
  7804. // Or use the video's metadata, or use the video el's default of 300
  7805. width = this.videoWidth() || 300;
  7806. }
  7807. if (this.height_ !== undefined) {
  7808. // Use any height that's been specifically set
  7809. height = this.height_;
  7810. } else {
  7811. // Otherwise calculate the height from the ratio and the width
  7812. height = width * ratioMultiplier;
  7813. }
  7814. // Ensure the CSS class is valid by starting with an alpha character
  7815. if (/^[^a-zA-Z]/.test(this.id())) {
  7816. idClass = 'dimensions-' + this.id();
  7817. } else {
  7818. idClass = this.id() + '-dimensions';
  7819. }
  7820. // Ensure the right class is still on the player for the style element
  7821. this.addClass(idClass);
  7822. stylesheet.setTextContent(this.styleEl_, '\n .' + idClass + ' {\n width: ' + width + 'px;\n height: ' + height + 'px;\n }\n\n .' + idClass + '.vjs-fluid {\n padding-top: ' + ratioMultiplier * 100 + '%;\n }\n ');
  7823. };
  7824. /**
  7825. * Load the Media Playback Technology (tech)
  7826. * Load/Create an instance of playback technology including element and API methods
  7827. * And append playback element in player div.
  7828. *
  7829. * @param {String} techName Name of the playback technology
  7830. * @param {String} source Video source
  7831. * @method loadTech_
  7832. * @private
  7833. */
  7834. Player.prototype.loadTech_ = function loadTech_(techName, source) {
  7835. // Pause and remove current playback technology
  7836. if (this.tech_) {
  7837. this.unloadTech_();
  7838. }
  7839. // get rid of the HTML5 video tag as soon as we are using another tech
  7840. if (techName !== 'Html5' && this.tag) {
  7841. _techTechJs2['default'].getTech('Html5').disposeMediaElement(this.tag);
  7842. this.tag.player = null;
  7843. this.tag = null;
  7844. }
  7845. this.techName_ = techName;
  7846. // Turn off API access because we're loading a new tech that might load asynchronously
  7847. this.isReady_ = false;
  7848. // Grab tech-specific options from player options and add source and parent element to use.
  7849. var techOptions = _objectAssign2['default']({
  7850. 'nativeControlsForTouch': this.options_.nativeControlsForTouch,
  7851. 'source': source,
  7852. 'playerId': this.id(),
  7853. 'techId': this.id() + '_' + techName + '_api',
  7854. 'textTracks': this.textTracks_,
  7855. 'autoplay': this.options_.autoplay,
  7856. 'preload': this.options_.preload,
  7857. 'loop': this.options_.loop,
  7858. 'muted': this.options_.muted,
  7859. 'poster': this.poster(),
  7860. 'language': this.language(),
  7861. 'vtt.js': this.options_['vtt.js']
  7862. }, this.options_[techName.toLowerCase()]);
  7863. if (this.tag) {
  7864. techOptions.tag = this.tag;
  7865. }
  7866. if (source) {
  7867. this.currentType_ = source.type;
  7868. if (source.src === this.cache_.src && this.cache_.currentTime > 0) {
  7869. techOptions.startTime = this.cache_.currentTime;
  7870. }
  7871. this.cache_.src = source.src;
  7872. }
  7873. // Initialize tech instance
  7874. var techComponent = _techTechJs2['default'].getTech(techName);
  7875. // Support old behavior of techs being registered as components.
  7876. // Remove once that deprecated behavior is removed.
  7877. if (!techComponent) {
  7878. techComponent = _componentJs2['default'].getComponent(techName);
  7879. }
  7880. this.tech_ = new techComponent(techOptions);
  7881. // player.triggerReady is always async, so don't need this to be async
  7882. this.tech_.ready(Fn.bind(this, this.handleTechReady_), true);
  7883. _tracksTextTrackListConverterJs2['default'].jsonToTextTracks(this.textTracksJson_ || [], this.tech_);
  7884. // Listen to all HTML5-defined events and trigger them on the player
  7885. this.on(this.tech_, 'loadstart', this.handleTechLoadStart_);
  7886. this.on(this.tech_, 'waiting', this.handleTechWaiting_);
  7887. this.on(this.tech_, 'canplay', this.handleTechCanPlay_);
  7888. this.on(this.tech_, 'canplaythrough', this.handleTechCanPlayThrough_);
  7889. this.on(this.tech_, 'playing', this.handleTechPlaying_);
  7890. this.on(this.tech_, 'ended', this.handleTechEnded_);
  7891. this.on(this.tech_, 'seeking', this.handleTechSeeking_);
  7892. this.on(this.tech_, 'seeked', this.handleTechSeeked_);
  7893. this.on(this.tech_, 'play', this.handleTechPlay_);
  7894. this.on(this.tech_, 'firstplay', this.handleTechFirstPlay_);
  7895. this.on(this.tech_, 'pause', this.handleTechPause_);
  7896. this.on(this.tech_, 'progress', this.handleTechProgress_);
  7897. this.on(this.tech_, 'durationchange', this.handleTechDurationChange_);
  7898. this.on(this.tech_, 'fullscreenchange', this.handleTechFullscreenChange_);
  7899. this.on(this.tech_, 'error', this.handleTechError_);
  7900. this.on(this.tech_, 'suspend', this.handleTechSuspend_);
  7901. this.on(this.tech_, 'abort', this.handleTechAbort_);
  7902. this.on(this.tech_, 'emptied', this.handleTechEmptied_);
  7903. this.on(this.tech_, 'stalled', this.handleTechStalled_);
  7904. this.on(this.tech_, 'loadedmetadata', this.handleTechLoadedMetaData_);
  7905. this.on(this.tech_, 'loadeddata', this.handleTechLoadedData_);
  7906. this.on(this.tech_, 'timeupdate', this.handleTechTimeUpdate_);
  7907. this.on(this.tech_, 'ratechange', this.handleTechRateChange_);
  7908. this.on(this.tech_, 'volumechange', this.handleTechVolumeChange_);
  7909. this.on(this.tech_, 'texttrackchange', this.handleTechTextTrackChange_);
  7910. this.on(this.tech_, 'loadedmetadata', this.updateStyleEl_);
  7911. this.on(this.tech_, 'posterchange', this.handleTechPosterChange_);
  7912. this.usingNativeControls(this.techGet_('controls'));
  7913. if (this.controls() && !this.usingNativeControls()) {
  7914. this.addTechControlsListeners_();
  7915. }
  7916. // Add the tech element in the DOM if it was not already there
  7917. // Make sure to not insert the original video element if using Html5
  7918. if (this.tech_.el().parentNode !== this.el() && (techName !== 'Html5' || !this.tag)) {
  7919. Dom.insertElFirst(this.tech_.el(), this.el());
  7920. }
  7921. // Get rid of the original video tag reference after the first tech is loaded
  7922. if (this.tag) {
  7923. this.tag.player = null;
  7924. this.tag = null;
  7925. }
  7926. };
  7927. /**
  7928. * Unload playback technology
  7929. *
  7930. * @method unloadTech_
  7931. * @private
  7932. */
  7933. Player.prototype.unloadTech_ = function unloadTech_() {
  7934. // Save the current text tracks so that we can reuse the same text tracks with the next tech
  7935. this.textTracks_ = this.textTracks();
  7936. this.textTracksJson_ = _tracksTextTrackListConverterJs2['default'].textTracksToJson(this.tech_);
  7937. this.isReady_ = false;
  7938. this.tech_.dispose();
  7939. this.tech_ = false;
  7940. };
  7941. /**
  7942. * Return a reference to the current tech.
  7943. * It will only return a reference to the tech if given an object with the
  7944. * `IWillNotUseThisInPlugins` property on it. This is try and prevent misuse
  7945. * of techs by plugins.
  7946. *
  7947. * @param {Object}
  7948. * @return {Object} The Tech
  7949. * @method tech
  7950. */
  7951. Player.prototype.tech = function tech(safety) {
  7952. if (safety && safety.IWillNotUseThisInPlugins) {
  7953. return this.tech_;
  7954. }
  7955. var errorText = '\n Please make sure that you are not using this inside of a plugin.\n To disable this alert and error, please pass in an object with\n `IWillNotUseThisInPlugins` to the `tech` method. See\n https://github.com/videojs/video.js/issues/2617 for more info.\n ';
  7956. _globalWindow2['default'].alert(errorText);
  7957. throw new Error(errorText);
  7958. };
  7959. /**
  7960. * Set up click and touch listeners for the playback element
  7961. *
  7962. * On desktops, a click on the video itself will toggle playback,
  7963. * on a mobile device a click on the video toggles controls.
  7964. * (toggling controls is done by toggling the user state between active and
  7965. * inactive)
  7966. * A tap can signal that a user has become active, or has become inactive
  7967. * e.g. a quick tap on an iPhone movie should reveal the controls. Another
  7968. * quick tap should hide them again (signaling the user is in an inactive
  7969. * viewing state)
  7970. * In addition to this, we still want the user to be considered inactive after
  7971. * a few seconds of inactivity.
  7972. * Note: the only part of iOS interaction we can't mimic with this setup
  7973. * is a touch and hold on the video element counting as activity in order to
  7974. * keep the controls showing, but that shouldn't be an issue. A touch and hold
  7975. * on any controls will still keep the user active
  7976. *
  7977. * @private
  7978. * @method addTechControlsListeners_
  7979. */
  7980. Player.prototype.addTechControlsListeners_ = function addTechControlsListeners_() {
  7981. // Make sure to remove all the previous listeners in case we are called multiple times.
  7982. this.removeTechControlsListeners_();
  7983. // Some browsers (Chrome & IE) don't trigger a click on a flash swf, but do
  7984. // trigger mousedown/up.
  7985. // http://stackoverflow.com/questions/1444562/javascript-onclick-event-over-flash-object
  7986. // Any touch events are set to block the mousedown event from happening
  7987. this.on(this.tech_, 'mousedown', this.handleTechClick_);
  7988. // If the controls were hidden we don't want that to change without a tap event
  7989. // so we'll check if the controls were already showing before reporting user
  7990. // activity
  7991. this.on(this.tech_, 'touchstart', this.handleTechTouchStart_);
  7992. this.on(this.tech_, 'touchmove', this.handleTechTouchMove_);
  7993. this.on(this.tech_, 'touchend', this.handleTechTouchEnd_);
  7994. // The tap listener needs to come after the touchend listener because the tap
  7995. // listener cancels out any reportedUserActivity when setting userActive(false)
  7996. this.on(this.tech_, 'tap', this.handleTechTap_);
  7997. };
  7998. /**
  7999. * Remove the listeners used for click and tap controls. This is needed for
  8000. * toggling to controls disabled, where a tap/touch should do nothing.
  8001. *
  8002. * @method removeTechControlsListeners_
  8003. * @private
  8004. */
  8005. Player.prototype.removeTechControlsListeners_ = function removeTechControlsListeners_() {
  8006. // We don't want to just use `this.off()` because there might be other needed
  8007. // listeners added by techs that extend this.
  8008. this.off(this.tech_, 'tap', this.handleTechTap_);
  8009. this.off(this.tech_, 'touchstart', this.handleTechTouchStart_);
  8010. this.off(this.tech_, 'touchmove', this.handleTechTouchMove_);
  8011. this.off(this.tech_, 'touchend', this.handleTechTouchEnd_);
  8012. this.off(this.tech_, 'mousedown', this.handleTechClick_);
  8013. };
  8014. /**
  8015. * Player waits for the tech to be ready
  8016. *
  8017. * @method handleTechReady_
  8018. * @private
  8019. */
  8020. Player.prototype.handleTechReady_ = function handleTechReady_() {
  8021. this.triggerReady();
  8022. // Keep the same volume as before
  8023. if (this.cache_.volume) {
  8024. this.techCall_('setVolume', this.cache_.volume);
  8025. }
  8026. // Look if the tech found a higher resolution poster while loading
  8027. this.handleTechPosterChange_();
  8028. // Update the duration if available
  8029. this.handleTechDurationChange_();
  8030. // Chrome and Safari both have issues with autoplay.
  8031. // In Safari (5.1.1), when we move the video element into the container div, autoplay doesn't work.
  8032. // In Chrome (15), if you have autoplay + a poster + no controls, the video gets hidden (but audio plays)
  8033. // This fixes both issues. Need to wait for API, so it updates displays correctly
  8034. if (this.src() && this.tag && this.options_.autoplay && this.paused()) {
  8035. delete this.tag.poster; // Chrome Fix. Fixed in Chrome v16.
  8036. this.play();
  8037. }
  8038. };
  8039. /**
  8040. * Fired when the user agent begins looking for media data
  8041. *
  8042. * @private
  8043. * @method handleTechLoadStart_
  8044. */
  8045. Player.prototype.handleTechLoadStart_ = function handleTechLoadStart_() {
  8046. // TODO: Update to use `emptied` event instead. See #1277.
  8047. this.removeClass('vjs-ended');
  8048. // reset the error state
  8049. this.error(null);
  8050. // If it's already playing we want to trigger a firstplay event now.
  8051. // The firstplay event relies on both the play and loadstart events
  8052. // which can happen in any order for a new source
  8053. if (!this.paused()) {
  8054. this.trigger('loadstart');
  8055. this.trigger('firstplay');
  8056. } else {
  8057. // reset the hasStarted state
  8058. this.hasStarted(false);
  8059. this.trigger('loadstart');
  8060. }
  8061. };
  8062. /**
  8063. * Add/remove the vjs-has-started class
  8064. *
  8065. * @param {Boolean} hasStarted The value of true adds the class the value of false remove the class
  8066. * @return {Boolean} Boolean value if has started
  8067. * @private
  8068. * @method hasStarted
  8069. */
  8070. Player.prototype.hasStarted = function hasStarted(_hasStarted) {
  8071. if (_hasStarted !== undefined) {
  8072. // only update if this is a new value
  8073. if (this.hasStarted_ !== _hasStarted) {
  8074. this.hasStarted_ = _hasStarted;
  8075. if (_hasStarted) {
  8076. this.addClass('vjs-has-started');
  8077. // trigger the firstplay event if this newly has played
  8078. this.trigger('firstplay');
  8079. } else {
  8080. this.removeClass('vjs-has-started');
  8081. }
  8082. }
  8083. return this;
  8084. }
  8085. return !!this.hasStarted_;
  8086. };
  8087. /**
  8088. * Fired whenever the media begins or resumes playback
  8089. *
  8090. * @private
  8091. * @method handleTechPlay_
  8092. */
  8093. Player.prototype.handleTechPlay_ = function handleTechPlay_() {
  8094. this.removeClass('vjs-ended');
  8095. this.removeClass('vjs-paused');
  8096. this.addClass('vjs-playing');
  8097. // hide the poster when the user hits play
  8098. // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-play
  8099. this.hasStarted(true);
  8100. this.trigger('play');
  8101. };
  8102. /**
  8103. * Fired whenever the media begins waiting
  8104. *
  8105. * @private
  8106. * @method handleTechWaiting_
  8107. */
  8108. Player.prototype.handleTechWaiting_ = function handleTechWaiting_() {
  8109. var _this2 = this;
  8110. this.addClass('vjs-waiting');
  8111. this.trigger('waiting');
  8112. this.one('timeupdate', function () {
  8113. return _this2.removeClass('vjs-waiting');
  8114. });
  8115. };
  8116. /**
  8117. * A handler for events that signal that waiting has ended
  8118. * which is not consistent between browsers. See #1351
  8119. *
  8120. * @private
  8121. * @method handleTechCanPlay_
  8122. */
  8123. Player.prototype.handleTechCanPlay_ = function handleTechCanPlay_() {
  8124. this.removeClass('vjs-waiting');
  8125. this.trigger('canplay');
  8126. };
  8127. /**
  8128. * A handler for events that signal that waiting has ended
  8129. * which is not consistent between browsers. See #1351
  8130. *
  8131. * @private
  8132. * @method handleTechCanPlayThrough_
  8133. */
  8134. Player.prototype.handleTechCanPlayThrough_ = function handleTechCanPlayThrough_() {
  8135. this.removeClass('vjs-waiting');
  8136. this.trigger('canplaythrough');
  8137. };
  8138. /**
  8139. * A handler for events that signal that waiting has ended
  8140. * which is not consistent between browsers. See #1351
  8141. *
  8142. * @private
  8143. * @method handleTechPlaying_
  8144. */
  8145. Player.prototype.handleTechPlaying_ = function handleTechPlaying_() {
  8146. this.removeClass('vjs-waiting');
  8147. this.trigger('playing');
  8148. };
  8149. /**
  8150. * Fired whenever the player is jumping to a new time
  8151. *
  8152. * @private
  8153. * @method handleTechSeeking_
  8154. */
  8155. Player.prototype.handleTechSeeking_ = function handleTechSeeking_() {
  8156. this.addClass('vjs-seeking');
  8157. this.trigger('seeking');
  8158. };
  8159. /**
  8160. * Fired when the player has finished jumping to a new time
  8161. *
  8162. * @private
  8163. * @method handleTechSeeked_
  8164. */
  8165. Player.prototype.handleTechSeeked_ = function handleTechSeeked_() {
  8166. this.removeClass('vjs-seeking');
  8167. this.trigger('seeked');
  8168. };
  8169. /**
  8170. * Fired the first time a video is played
  8171. * Not part of the HLS spec, and we're not sure if this is the best
  8172. * implementation yet, so use sparingly. If you don't have a reason to
  8173. * prevent playback, use `myPlayer.one('play');` instead.
  8174. *
  8175. * @private
  8176. * @method handleTechFirstPlay_
  8177. */
  8178. Player.prototype.handleTechFirstPlay_ = function handleTechFirstPlay_() {
  8179. //If the first starttime attribute is specified
  8180. //then we will start at the given offset in seconds
  8181. if (this.options_.starttime) {
  8182. this.currentTime(this.options_.starttime);
  8183. }
  8184. this.addClass('vjs-has-started');
  8185. this.trigger('firstplay');
  8186. };
  8187. /**
  8188. * Fired whenever the media has been paused
  8189. *
  8190. * @private
  8191. * @method handleTechPause_
  8192. */
  8193. Player.prototype.handleTechPause_ = function handleTechPause_() {
  8194. this.removeClass('vjs-playing');
  8195. this.addClass('vjs-paused');
  8196. this.trigger('pause');
  8197. };
  8198. /**
  8199. * Fired while the user agent is downloading media data
  8200. *
  8201. * @private
  8202. * @method handleTechProgress_
  8203. */
  8204. Player.prototype.handleTechProgress_ = function handleTechProgress_() {
  8205. this.trigger('progress');
  8206. };
  8207. /**
  8208. * Fired when the end of the media resource is reached (currentTime == duration)
  8209. *
  8210. * @private
  8211. * @method handleTechEnded_
  8212. */
  8213. Player.prototype.handleTechEnded_ = function handleTechEnded_() {
  8214. this.addClass('vjs-ended');
  8215. if (this.options_.loop) {
  8216. this.currentTime(0);
  8217. this.play();
  8218. } else if (!this.paused()) {
  8219. this.pause();
  8220. }
  8221. this.trigger('ended');
  8222. };
  8223. /**
  8224. * Fired when the duration of the media resource is first known or changed
  8225. *
  8226. * @private
  8227. * @method handleTechDurationChange_
  8228. */
  8229. Player.prototype.handleTechDurationChange_ = function handleTechDurationChange_() {
  8230. this.duration(this.techGet_('duration'));
  8231. };
  8232. /**
  8233. * Handle a click on the media element to play/pause
  8234. *
  8235. * @param {Object=} event Event object
  8236. * @private
  8237. * @method handleTechClick_
  8238. */
  8239. Player.prototype.handleTechClick_ = function handleTechClick_(event) {
  8240. // We're using mousedown to detect clicks thanks to Flash, but mousedown
  8241. // will also be triggered with right-clicks, so we need to prevent that
  8242. if (event.button !== 0) return;
  8243. // When controls are disabled a click should not toggle playback because
  8244. // the click is considered a control
  8245. if (this.controls()) {
  8246. if (this.paused()) {
  8247. this.play();
  8248. } else {
  8249. this.pause();
  8250. }
  8251. }
  8252. };
  8253. /**
  8254. * Handle a tap on the media element. It will toggle the user
  8255. * activity state, which hides and shows the controls.
  8256. *
  8257. * @private
  8258. * @method handleTechTap_
  8259. */
  8260. Player.prototype.handleTechTap_ = function handleTechTap_() {
  8261. this.userActive(!this.userActive());
  8262. };
  8263. /**
  8264. * Handle touch to start
  8265. *
  8266. * @private
  8267. * @method handleTechTouchStart_
  8268. */
  8269. Player.prototype.handleTechTouchStart_ = function handleTechTouchStart_() {
  8270. this.userWasActive = this.userActive();
  8271. };
  8272. /**
  8273. * Handle touch to move
  8274. *
  8275. * @private
  8276. * @method handleTechTouchMove_
  8277. */
  8278. Player.prototype.handleTechTouchMove_ = function handleTechTouchMove_() {
  8279. if (this.userWasActive) {
  8280. this.reportUserActivity();
  8281. }
  8282. };
  8283. /**
  8284. * Handle touch to end
  8285. *
  8286. * @private
  8287. * @method handleTechTouchEnd_
  8288. */
  8289. Player.prototype.handleTechTouchEnd_ = function handleTechTouchEnd_(event) {
  8290. // Stop the mouse events from also happening
  8291. event.preventDefault();
  8292. };
  8293. /**
  8294. * Fired when the player switches in or out of fullscreen mode
  8295. *
  8296. * @private
  8297. * @method handleFullscreenChange_
  8298. */
  8299. Player.prototype.handleFullscreenChange_ = function handleFullscreenChange_() {
  8300. if (this.isFullscreen()) {
  8301. this.addClass('vjs-fullscreen');
  8302. } else {
  8303. this.removeClass('vjs-fullscreen');
  8304. }
  8305. };
  8306. /**
  8307. * native click events on the SWF aren't triggered on IE11, Win8.1RT
  8308. * use stageclick events triggered from inside the SWF instead
  8309. *
  8310. * @private
  8311. * @method handleStageClick_
  8312. */
  8313. Player.prototype.handleStageClick_ = function handleStageClick_() {
  8314. this.reportUserActivity();
  8315. };
  8316. /**
  8317. * Handle Tech Fullscreen Change
  8318. *
  8319. * @private
  8320. * @method handleTechFullscreenChange_
  8321. */
  8322. Player.prototype.handleTechFullscreenChange_ = function handleTechFullscreenChange_(event, data) {
  8323. if (data) {
  8324. this.isFullscreen(data.isFullscreen);
  8325. }
  8326. this.trigger('fullscreenchange');
  8327. };
  8328. /**
  8329. * Fires when an error occurred during the loading of an audio/video
  8330. *
  8331. * @private
  8332. * @method handleTechError_
  8333. */
  8334. Player.prototype.handleTechError_ = function handleTechError_() {
  8335. var error = this.tech_.error();
  8336. this.error(error && error.code);
  8337. };
  8338. /**
  8339. * Fires when the browser is intentionally not getting media data
  8340. *
  8341. * @private
  8342. * @method handleTechSuspend_
  8343. */
  8344. Player.prototype.handleTechSuspend_ = function handleTechSuspend_() {
  8345. this.trigger('suspend');
  8346. };
  8347. /**
  8348. * Fires when the loading of an audio/video is aborted
  8349. *
  8350. * @private
  8351. * @method handleTechAbort_
  8352. */
  8353. Player.prototype.handleTechAbort_ = function handleTechAbort_() {
  8354. this.trigger('abort');
  8355. };
  8356. /**
  8357. * Fires when the current playlist is empty
  8358. *
  8359. * @private
  8360. * @method handleTechEmptied_
  8361. */
  8362. Player.prototype.handleTechEmptied_ = function handleTechEmptied_() {
  8363. this.trigger('emptied');
  8364. };
  8365. /**
  8366. * Fires when the browser is trying to get media data, but data is not available
  8367. *
  8368. * @private
  8369. * @method handleTechStalled_
  8370. */
  8371. Player.prototype.handleTechStalled_ = function handleTechStalled_() {
  8372. this.trigger('stalled');
  8373. };
  8374. /**
  8375. * Fires when the browser has loaded meta data for the audio/video
  8376. *
  8377. * @private
  8378. * @method handleTechLoadedMetaData_
  8379. */
  8380. Player.prototype.handleTechLoadedMetaData_ = function handleTechLoadedMetaData_() {
  8381. this.trigger('loadedmetadata');
  8382. };
  8383. /**
  8384. * Fires when the browser has loaded the current frame of the audio/video
  8385. *
  8386. * @private
  8387. * @method handleTechLoadedData_
  8388. */
  8389. Player.prototype.handleTechLoadedData_ = function handleTechLoadedData_() {
  8390. this.trigger('loadeddata');
  8391. };
  8392. /**
  8393. * Fires when the current playback position has changed
  8394. *
  8395. * @private
  8396. * @method handleTechTimeUpdate_
  8397. */
  8398. Player.prototype.handleTechTimeUpdate_ = function handleTechTimeUpdate_() {
  8399. this.trigger('timeupdate');
  8400. };
  8401. /**
  8402. * Fires when the playing speed of the audio/video is changed
  8403. *
  8404. * @private
  8405. * @method handleTechRateChange_
  8406. */
  8407. Player.prototype.handleTechRateChange_ = function handleTechRateChange_() {
  8408. this.trigger('ratechange');
  8409. };
  8410. /**
  8411. * Fires when the volume has been changed
  8412. *
  8413. * @private
  8414. * @method handleTechVolumeChange_
  8415. */
  8416. Player.prototype.handleTechVolumeChange_ = function handleTechVolumeChange_() {
  8417. this.trigger('volumechange');
  8418. };
  8419. /**
  8420. * Fires when the text track has been changed
  8421. *
  8422. * @private
  8423. * @method handleTechTextTrackChange_
  8424. */
  8425. Player.prototype.handleTechTextTrackChange_ = function handleTechTextTrackChange_() {
  8426. this.trigger('texttrackchange');
  8427. };
  8428. /**
  8429. * Get object for cached values.
  8430. *
  8431. * @return {Object}
  8432. * @method getCache
  8433. */
  8434. Player.prototype.getCache = function getCache() {
  8435. return this.cache_;
  8436. };
  8437. /**
  8438. * Pass values to the playback tech
  8439. *
  8440. * @param {String=} method Method
  8441. * @param {Object=} arg Argument
  8442. * @private
  8443. * @method techCall_
  8444. */
  8445. Player.prototype.techCall_ = function techCall_(method, arg) {
  8446. // If it's not ready yet, call method when it is
  8447. if (this.tech_ && !this.tech_.isReady_) {
  8448. this.tech_.ready(function () {
  8449. this[method](arg);
  8450. }, true);
  8451. // Otherwise call method now
  8452. } else {
  8453. try {
  8454. this.tech_[method](arg);
  8455. } catch (e) {
  8456. _utilsLogJs2['default'](e);
  8457. throw e;
  8458. }
  8459. }
  8460. };
  8461. /**
  8462. * Get calls can't wait for the tech, and sometimes don't need to.
  8463. *
  8464. * @param {String} method Tech method
  8465. * @return {Method}
  8466. * @private
  8467. * @method techGet_
  8468. */
  8469. Player.prototype.techGet_ = function techGet_(method) {
  8470. if (this.tech_ && this.tech_.isReady_) {
  8471. // Flash likes to die and reload when you hide or reposition it.
  8472. // In these cases the object methods go away and we get errors.
  8473. // When that happens we'll catch the errors and inform tech that it's not ready any more.
  8474. try {
  8475. return this.tech_[method]();
  8476. } catch (e) {
  8477. // When building additional tech libs, an expected method may not be defined yet
  8478. if (this.tech_[method] === undefined) {
  8479. _utilsLogJs2['default']('Video.js: ' + method + ' method not defined for ' + this.techName_ + ' playback technology.', e);
  8480. } else {
  8481. // When a method isn't available on the object it throws a TypeError
  8482. if (e.name === 'TypeError') {
  8483. _utilsLogJs2['default']('Video.js: ' + method + ' unavailable on ' + this.techName_ + ' playback technology element.', e);
  8484. this.tech_.isReady_ = false;
  8485. } else {
  8486. _utilsLogJs2['default'](e);
  8487. }
  8488. }
  8489. throw e;
  8490. }
  8491. }
  8492. return;
  8493. };
  8494. /**
  8495. * start media playback
  8496. * ```js
  8497. * myPlayer.play();
  8498. * ```
  8499. *
  8500. * @return {Player} self
  8501. * @method play
  8502. */
  8503. Player.prototype.play = function play() {
  8504. this.techCall_('play');
  8505. return this;
  8506. };
  8507. /**
  8508. * Pause the video playback
  8509. * ```js
  8510. * myPlayer.pause();
  8511. * ```
  8512. *
  8513. * @return {Player} self
  8514. * @method pause
  8515. */
  8516. Player.prototype.pause = function pause() {
  8517. this.techCall_('pause');
  8518. return this;
  8519. };
  8520. /**
  8521. * Check if the player is paused
  8522. * ```js
  8523. * var isPaused = myPlayer.paused();
  8524. * var isPlaying = !myPlayer.paused();
  8525. * ```
  8526. *
  8527. * @return {Boolean} false if the media is currently playing, or true otherwise
  8528. * @method paused
  8529. */
  8530. Player.prototype.paused = function paused() {
  8531. // The initial state of paused should be true (in Safari it's actually false)
  8532. return this.techGet_('paused') === false ? false : true;
  8533. };
  8534. /**
  8535. * Returns whether or not the user is "scrubbing". Scrubbing is when the user
  8536. * has clicked the progress bar handle and is dragging it along the progress bar.
  8537. *
  8538. * @param {Boolean} isScrubbing True/false the user is scrubbing
  8539. * @return {Boolean} The scrubbing status when getting
  8540. * @return {Object} The player when setting
  8541. * @method scrubbing
  8542. */
  8543. Player.prototype.scrubbing = function scrubbing(isScrubbing) {
  8544. if (isScrubbing !== undefined) {
  8545. this.scrubbing_ = !!isScrubbing;
  8546. if (isScrubbing) {
  8547. this.addClass('vjs-scrubbing');
  8548. } else {
  8549. this.removeClass('vjs-scrubbing');
  8550. }
  8551. return this;
  8552. }
  8553. return this.scrubbing_;
  8554. };
  8555. /**
  8556. * Get or set the current time (in seconds)
  8557. * ```js
  8558. * // get
  8559. * var whereYouAt = myPlayer.currentTime();
  8560. * // set
  8561. * myPlayer.currentTime(120); // 2 minutes into the video
  8562. * ```
  8563. *
  8564. * @param {Number|String=} seconds The time to seek to
  8565. * @return {Number} The time in seconds, when not setting
  8566. * @return {Player} self, when the current time is set
  8567. * @method currentTime
  8568. */
  8569. Player.prototype.currentTime = function currentTime(seconds) {
  8570. if (seconds !== undefined) {
  8571. this.techCall_('setCurrentTime', seconds);
  8572. return this;
  8573. }
  8574. // cache last currentTime and return. default to 0 seconds
  8575. //
  8576. // Caching the currentTime is meant to prevent a massive amount of reads on the tech's
  8577. // currentTime when scrubbing, but may not provide much performance benefit afterall.
  8578. // Should be tested. Also something has to read the actual current time or the cache will
  8579. // never get updated.
  8580. return this.cache_.currentTime = this.techGet_('currentTime') || 0;
  8581. };
  8582. /**
  8583. * Get the length in time of the video in seconds
  8584. * ```js
  8585. * var lengthOfVideo = myPlayer.duration();
  8586. * ```
  8587. * **NOTE**: The video must have started loading before the duration can be
  8588. * known, and in the case of Flash, may not be known until the video starts
  8589. * playing.
  8590. *
  8591. * @param {Number} seconds Duration when setting
  8592. * @return {Number} The duration of the video in seconds when getting
  8593. * @method duration
  8594. */
  8595. Player.prototype.duration = function duration(seconds) {
  8596. if (seconds === undefined) {
  8597. return this.cache_.duration || 0;
  8598. }
  8599. seconds = parseFloat(seconds) || 0;
  8600. // Standardize on Inifity for signaling video is live
  8601. if (seconds < 0) {
  8602. seconds = Infinity;
  8603. }
  8604. if (seconds !== this.cache_.duration) {
  8605. // Cache the last set value for optimized scrubbing (esp. Flash)
  8606. this.cache_.duration = seconds;
  8607. if (seconds === Infinity) {
  8608. this.addClass('vjs-live');
  8609. } else {
  8610. this.removeClass('vjs-live');
  8611. }
  8612. this.trigger('durationchange');
  8613. }
  8614. return this;
  8615. };
  8616. /**
  8617. * Calculates how much time is left.
  8618. * ```js
  8619. * var timeLeft = myPlayer.remainingTime();
  8620. * ```
  8621. * Not a native video element function, but useful
  8622. *
  8623. * @return {Number} The time remaining in seconds
  8624. * @method remainingTime
  8625. */
  8626. Player.prototype.remainingTime = function remainingTime() {
  8627. return this.duration() - this.currentTime();
  8628. };
  8629. // http://dev.w3.org/html5/spec/video.html#dom-media-buffered
  8630. // Buffered returns a timerange object.
  8631. // Kind of like an array of portions of the video that have been downloaded.
  8632. /**
  8633. * Get a TimeRange object with the times of the video that have been downloaded
  8634. * If you just want the percent of the video that's been downloaded,
  8635. * use bufferedPercent.
  8636. * ```js
  8637. * // Number of different ranges of time have been buffered. Usually 1.
  8638. * numberOfRanges = bufferedTimeRange.length,
  8639. * // Time in seconds when the first range starts. Usually 0.
  8640. * firstRangeStart = bufferedTimeRange.start(0),
  8641. * // Time in seconds when the first range ends
  8642. * firstRangeEnd = bufferedTimeRange.end(0),
  8643. * // Length in seconds of the first time range
  8644. * firstRangeLength = firstRangeEnd - firstRangeStart;
  8645. * ```
  8646. *
  8647. * @return {Object} A mock TimeRange object (following HTML spec)
  8648. * @method buffered
  8649. */
  8650. Player.prototype.buffered = function buffered() {
  8651. var buffered = this.techGet_('buffered');
  8652. if (!buffered || !buffered.length) {
  8653. buffered = _utilsTimeRangesJs.createTimeRange(0, 0);
  8654. }
  8655. return buffered;
  8656. };
  8657. /**
  8658. * Get the percent (as a decimal) of the video that's been downloaded
  8659. * ```js
  8660. * var howMuchIsDownloaded = myPlayer.bufferedPercent();
  8661. * ```
  8662. * 0 means none, 1 means all.
  8663. * (This method isn't in the HTML5 spec, but it's very convenient)
  8664. *
  8665. * @return {Number} A decimal between 0 and 1 representing the percent
  8666. * @method bufferedPercent
  8667. */
  8668. Player.prototype.bufferedPercent = function bufferedPercent() {
  8669. return _utilsBufferJs.bufferedPercent(this.buffered(), this.duration());
  8670. };
  8671. /**
  8672. * Get the ending time of the last buffered time range
  8673. * This is used in the progress bar to encapsulate all time ranges.
  8674. *
  8675. * @return {Number} The end of the last buffered time range
  8676. * @method bufferedEnd
  8677. */
  8678. Player.prototype.bufferedEnd = function bufferedEnd() {
  8679. var buffered = this.buffered(),
  8680. duration = this.duration(),
  8681. end = buffered.end(buffered.length - 1);
  8682. if (end > duration) {
  8683. end = duration;
  8684. }
  8685. return end;
  8686. };
  8687. /**
  8688. * Get or set the current volume of the media
  8689. * ```js
  8690. * // get
  8691. * var howLoudIsIt = myPlayer.volume();
  8692. * // set
  8693. * myPlayer.volume(0.5); // Set volume to half
  8694. * ```
  8695. * 0 is off (muted), 1.0 is all the way up, 0.5 is half way.
  8696. *
  8697. * @param {Number} percentAsDecimal The new volume as a decimal percent
  8698. * @return {Number} The current volume when getting
  8699. * @return {Player} self when setting
  8700. * @method volume
  8701. */
  8702. Player.prototype.volume = function volume(percentAsDecimal) {
  8703. var vol = undefined;
  8704. if (percentAsDecimal !== undefined) {
  8705. vol = Math.max(0, Math.min(1, parseFloat(percentAsDecimal))); // Force value to between 0 and 1
  8706. this.cache_.volume = vol;
  8707. this.techCall_('setVolume', vol);
  8708. return this;
  8709. }
  8710. // Default to 1 when returning current volume.
  8711. vol = parseFloat(this.techGet_('volume'));
  8712. return isNaN(vol) ? 1 : vol;
  8713. };
  8714. /**
  8715. * Get the current muted state, or turn mute on or off
  8716. * ```js
  8717. * // get
  8718. * var isVolumeMuted = myPlayer.muted();
  8719. * // set
  8720. * myPlayer.muted(true); // mute the volume
  8721. * ```
  8722. *
  8723. * @param {Boolean=} muted True to mute, false to unmute
  8724. * @return {Boolean} True if mute is on, false if not when getting
  8725. * @return {Player} self when setting mute
  8726. * @method muted
  8727. */
  8728. Player.prototype.muted = function muted(_muted) {
  8729. if (_muted !== undefined) {
  8730. this.techCall_('setMuted', _muted);
  8731. return this;
  8732. }
  8733. return this.techGet_('muted') || false; // Default to false
  8734. };
  8735. // Check if current tech can support native fullscreen
  8736. // (e.g. with built in controls like iOS, so not our flash swf)
  8737. /**
  8738. * Check to see if fullscreen is supported
  8739. *
  8740. * @return {Boolean}
  8741. * @method supportsFullScreen
  8742. */
  8743. Player.prototype.supportsFullScreen = function supportsFullScreen() {
  8744. return this.techGet_('supportsFullScreen') || false;
  8745. };
  8746. /**
  8747. * Check if the player is in fullscreen mode
  8748. * ```js
  8749. * // get
  8750. * var fullscreenOrNot = myPlayer.isFullscreen();
  8751. * // set
  8752. * myPlayer.isFullscreen(true); // tell the player it's in fullscreen
  8753. * ```
  8754. * NOTE: As of the latest HTML5 spec, isFullscreen is no longer an official
  8755. * property and instead document.fullscreenElement is used. But isFullscreen is
  8756. * still a valuable property for internal player workings.
  8757. *
  8758. * @param {Boolean=} isFS Update the player's fullscreen state
  8759. * @return {Boolean} true if fullscreen false if not when getting
  8760. * @return {Player} self when setting
  8761. * @method isFullscreen
  8762. */
  8763. Player.prototype.isFullscreen = function isFullscreen(isFS) {
  8764. if (isFS !== undefined) {
  8765. this.isFullscreen_ = !!isFS;
  8766. return this;
  8767. }
  8768. return !!this.isFullscreen_;
  8769. };
  8770. /**
  8771. * Increase the size of the video to full screen
  8772. * ```js
  8773. * myPlayer.requestFullscreen();
  8774. * ```
  8775. * In some browsers, full screen is not supported natively, so it enters
  8776. * "full window mode", where the video fills the browser window.
  8777. * In browsers and devices that support native full screen, sometimes the
  8778. * browser's default controls will be shown, and not the Video.js custom skin.
  8779. * This includes most mobile devices (iOS, Android) and older versions of
  8780. * Safari.
  8781. *
  8782. * @return {Player} self
  8783. * @method requestFullscreen
  8784. */
  8785. Player.prototype.requestFullscreen = function requestFullscreen() {
  8786. var fsApi = _fullscreenApiJs2['default'];
  8787. this.isFullscreen(true);
  8788. if (fsApi.requestFullscreen) {
  8789. // the browser supports going fullscreen at the element level so we can
  8790. // take the controls fullscreen as well as the video
  8791. // Trigger fullscreenchange event after change
  8792. // We have to specifically add this each time, and remove
  8793. // when canceling fullscreen. Otherwise if there's multiple
  8794. // players on a page, they would all be reacting to the same fullscreen
  8795. // events
  8796. Events.on(_globalDocument2['default'], fsApi.fullscreenchange, Fn.bind(this, function documentFullscreenChange(e) {
  8797. this.isFullscreen(_globalDocument2['default'][fsApi.fullscreenElement]);
  8798. // If cancelling fullscreen, remove event listener.
  8799. if (this.isFullscreen() === false) {
  8800. Events.off(_globalDocument2['default'], fsApi.fullscreenchange, documentFullscreenChange);
  8801. }
  8802. this.trigger('fullscreenchange');
  8803. }));
  8804. this.el_[fsApi.requestFullscreen]();
  8805. } else if (this.tech_.supportsFullScreen()) {
  8806. // we can't take the video.js controls fullscreen but we can go fullscreen
  8807. // with native controls
  8808. this.techCall_('enterFullScreen');
  8809. } else {
  8810. // fullscreen isn't supported so we'll just stretch the video element to
  8811. // fill the viewport
  8812. this.enterFullWindow();
  8813. this.trigger('fullscreenchange');
  8814. }
  8815. return this;
  8816. };
  8817. /**
  8818. * Return the video to its normal size after having been in full screen mode
  8819. * ```js
  8820. * myPlayer.exitFullscreen();
  8821. * ```
  8822. *
  8823. * @return {Player} self
  8824. * @method exitFullscreen
  8825. */
  8826. Player.prototype.exitFullscreen = function exitFullscreen() {
  8827. var fsApi = _fullscreenApiJs2['default'];
  8828. this.isFullscreen(false);
  8829. // Check for browser element fullscreen support
  8830. if (fsApi.requestFullscreen) {
  8831. _globalDocument2['default'][fsApi.exitFullscreen]();
  8832. } else if (this.tech_.supportsFullScreen()) {
  8833. this.techCall_('exitFullScreen');
  8834. } else {
  8835. this.exitFullWindow();
  8836. this.trigger('fullscreenchange');
  8837. }
  8838. return this;
  8839. };
  8840. /**
  8841. * When fullscreen isn't supported we can stretch the video container to as wide as the browser will let us.
  8842. *
  8843. * @method enterFullWindow
  8844. */
  8845. Player.prototype.enterFullWindow = function enterFullWindow() {
  8846. this.isFullWindow = true;
  8847. // Storing original doc overflow value to return to when fullscreen is off
  8848. this.docOrigOverflow = _globalDocument2['default'].documentElement.style.overflow;
  8849. // Add listener for esc key to exit fullscreen
  8850. Events.on(_globalDocument2['default'], 'keydown', Fn.bind(this, this.fullWindowOnEscKey));
  8851. // Hide any scroll bars
  8852. _globalDocument2['default'].documentElement.style.overflow = 'hidden';
  8853. // Apply fullscreen styles
  8854. Dom.addElClass(_globalDocument2['default'].body, 'vjs-full-window');
  8855. this.trigger('enterFullWindow');
  8856. };
  8857. /**
  8858. * Check for call to either exit full window or full screen on ESC key
  8859. *
  8860. * @param {String} event Event to check for key press
  8861. * @method fullWindowOnEscKey
  8862. */
  8863. Player.prototype.fullWindowOnEscKey = function fullWindowOnEscKey(event) {
  8864. if (event.keyCode === 27) {
  8865. if (this.isFullscreen() === true) {
  8866. this.exitFullscreen();
  8867. } else {
  8868. this.exitFullWindow();
  8869. }
  8870. }
  8871. };
  8872. /**
  8873. * Exit full window
  8874. *
  8875. * @method exitFullWindow
  8876. */
  8877. Player.prototype.exitFullWindow = function exitFullWindow() {
  8878. this.isFullWindow = false;
  8879. Events.off(_globalDocument2['default'], 'keydown', this.fullWindowOnEscKey);
  8880. // Unhide scroll bars.
  8881. _globalDocument2['default'].documentElement.style.overflow = this.docOrigOverflow;
  8882. // Remove fullscreen styles
  8883. Dom.removeElClass(_globalDocument2['default'].body, 'vjs-full-window');
  8884. // Resize the box, controller, and poster to original sizes
  8885. // this.positionAll();
  8886. this.trigger('exitFullWindow');
  8887. };
  8888. /**
  8889. * Check whether the player can play a given mimetype
  8890. *
  8891. * @param {String} type The mimetype to check
  8892. * @return {String} 'probably', 'maybe', or '' (empty string)
  8893. * @method canPlayType
  8894. */
  8895. Player.prototype.canPlayType = function canPlayType(type) {
  8896. var can = undefined;
  8897. // Loop through each playback technology in the options order
  8898. for (var i = 0, j = this.options_.techOrder; i < j.length; i++) {
  8899. var techName = _utilsToTitleCaseJs2['default'](j[i]);
  8900. var tech = _techTechJs2['default'].getTech(techName);
  8901. // Support old behavior of techs being registered as components.
  8902. // Remove once that deprecated behavior is removed.
  8903. if (!tech) {
  8904. tech = _componentJs2['default'].getComponent(techName);
  8905. }
  8906. // Check if the current tech is defined before continuing
  8907. if (!tech) {
  8908. _utilsLogJs2['default'].error('The "' + techName + '" tech is undefined. Skipped browser support check for that tech.');
  8909. continue;
  8910. }
  8911. // Check if the browser supports this technology
  8912. if (tech.isSupported()) {
  8913. can = tech.canPlayType(type);
  8914. if (can) {
  8915. return can;
  8916. }
  8917. }
  8918. }
  8919. return '';
  8920. };
  8921. /**
  8922. * Select source based on tech-order or source-order
  8923. * Uses source-order selection if `options.sourceOrder` is truthy. Otherwise,
  8924. * defaults to tech-order selection
  8925. *
  8926. * @param {Array} sources The sources for a media asset
  8927. * @return {Object|Boolean} Object of source and tech order, otherwise false
  8928. * @method selectSource
  8929. */
  8930. Player.prototype.selectSource = function selectSource(sources) {
  8931. // Get only the techs specified in `techOrder` that exist and are supported by the
  8932. // current platform
  8933. var techs = this.options_.techOrder.map(_utilsToTitleCaseJs2['default']).map(function (techName) {
  8934. // `Component.getComponent(...)` is for support of old behavior of techs
  8935. // being registered as components.
  8936. // Remove once that deprecated behavior is removed.
  8937. return [techName, _techTechJs2['default'].getTech(techName) || _componentJs2['default'].getComponent(techName)];
  8938. }).filter(function (_ref) {
  8939. var techName = _ref[0];
  8940. var tech = _ref[1];
  8941. // Check if the current tech is defined before continuing
  8942. if (tech) {
  8943. // Check if the browser supports this technology
  8944. return tech.isSupported();
  8945. }
  8946. _utilsLogJs2['default'].error('The "' + techName + '" tech is undefined. Skipped browser support check for that tech.');
  8947. return false;
  8948. });
  8949. // Iterate over each `innerArray` element once per `outerArray` element and execute
  8950. // `tester` with both. If `tester` returns a non-falsy value, exit early and return
  8951. // that value.
  8952. var findFirstPassingTechSourcePair = function findFirstPassingTechSourcePair(outerArray, innerArray, tester) {
  8953. var found = undefined;
  8954. outerArray.some(function (outerChoice) {
  8955. return innerArray.some(function (innerChoice) {
  8956. found = tester(outerChoice, innerChoice);
  8957. if (found) {
  8958. return true;
  8959. }
  8960. });
  8961. });
  8962. return found;
  8963. };
  8964. var foundSourceAndTech = undefined;
  8965. var flip = function flip(fn) {
  8966. return function (a, b) {
  8967. return fn(b, a);
  8968. };
  8969. };
  8970. var finder = function finder(_ref2, source) {
  8971. var techName = _ref2[0];
  8972. var tech = _ref2[1];
  8973. if (tech.canPlaySource(source)) {
  8974. return { source: source, tech: techName };
  8975. }
  8976. };
  8977. // Depending on the truthiness of `options.sourceOrder`, we swap the order of techs and sources
  8978. // to select from them based on their priority.
  8979. if (this.options_.sourceOrder) {
  8980. // Source-first ordering
  8981. foundSourceAndTech = findFirstPassingTechSourcePair(sources, techs, flip(finder));
  8982. } else {
  8983. // Tech-first ordering
  8984. foundSourceAndTech = findFirstPassingTechSourcePair(techs, sources, finder);
  8985. }
  8986. return foundSourceAndTech || false;
  8987. };
  8988. /**
  8989. * The source function updates the video source
  8990. * There are three types of variables you can pass as the argument.
  8991. * **URL String**: A URL to the the video file. Use this method if you are sure
  8992. * the current playback technology (HTML5/Flash) can support the source you
  8993. * provide. Currently only MP4 files can be used in both HTML5 and Flash.
  8994. * ```js
  8995. * myPlayer.src("http://www.example.com/path/to/video.mp4");
  8996. * ```
  8997. * **Source Object (or element):* * A javascript object containing information
  8998. * about the source file. Use this method if you want the player to determine if
  8999. * it can support the file using the type information.
  9000. * ```js
  9001. * myPlayer.src({ type: "video/mp4", src: "http://www.example.com/path/to/video.mp4" });
  9002. * ```
  9003. * **Array of Source Objects:* * To provide multiple versions of the source so
  9004. * that it can be played using HTML5 across browsers you can use an array of
  9005. * source objects. Video.js will detect which version is supported and load that
  9006. * file.
  9007. * ```js
  9008. * myPlayer.src([
  9009. * { type: "video/mp4", src: "http://www.example.com/path/to/video.mp4" },
  9010. * { type: "video/webm", src: "http://www.example.com/path/to/video.webm" },
  9011. * { type: "video/ogg", src: "http://www.example.com/path/to/video.ogv" }
  9012. * ]);
  9013. * ```
  9014. *
  9015. * @param {String|Object|Array=} source The source URL, object, or array of sources
  9016. * @return {String} The current video source when getting
  9017. * @return {String} The player when setting
  9018. * @method src
  9019. */
  9020. Player.prototype.src = function src(source) {
  9021. if (source === undefined) {
  9022. return this.techGet_('src');
  9023. }
  9024. var currentTech = _techTechJs2['default'].getTech(this.techName_);
  9025. // Support old behavior of techs being registered as components.
  9026. // Remove once that deprecated behavior is removed.
  9027. if (!currentTech) {
  9028. currentTech = _componentJs2['default'].getComponent(this.techName_);
  9029. }
  9030. // case: Array of source objects to choose from and pick the best to play
  9031. if (Array.isArray(source)) {
  9032. this.sourceList_(source);
  9033. // case: URL String (http://myvideo...)
  9034. } else if (typeof source === 'string') {
  9035. // create a source object from the string
  9036. this.src({ src: source });
  9037. // case: Source object { src: '', type: '' ... }
  9038. } else if (source instanceof Object) {
  9039. // check if the source has a type and the loaded tech cannot play the source
  9040. // if there's no type we'll just try the current tech
  9041. if (source.type && !currentTech.canPlaySource(source)) {
  9042. // create a source list with the current source and send through
  9043. // the tech loop to check for a compatible technology
  9044. this.sourceList_([source]);
  9045. } else {
  9046. this.cache_.src = source.src;
  9047. this.currentType_ = source.type || '';
  9048. // wait until the tech is ready to set the source
  9049. this.ready(function () {
  9050. // The setSource tech method was added with source handlers
  9051. // so older techs won't support it
  9052. // We need to check the direct prototype for the case where subclasses
  9053. // of the tech do not support source handlers
  9054. if (currentTech.prototype.hasOwnProperty('setSource')) {
  9055. this.techCall_('setSource', source);
  9056. } else {
  9057. this.techCall_('src', source.src);
  9058. }
  9059. if (this.options_.preload === 'auto') {
  9060. this.load();
  9061. }
  9062. if (this.options_.autoplay) {
  9063. this.play();
  9064. }
  9065. // Set the source synchronously if possible (#2326)
  9066. }, true);
  9067. }
  9068. }
  9069. return this;
  9070. };
  9071. /**
  9072. * Handle an array of source objects
  9073. *
  9074. * @param {Array} sources Array of source objects
  9075. * @private
  9076. * @method sourceList_
  9077. */
  9078. Player.prototype.sourceList_ = function sourceList_(sources) {
  9079. var sourceTech = this.selectSource(sources);
  9080. if (sourceTech) {
  9081. if (sourceTech.tech === this.techName_) {
  9082. // if this technology is already loaded, set the source
  9083. this.src(sourceTech.source);
  9084. } else {
  9085. // load this technology with the chosen source
  9086. this.loadTech_(sourceTech.tech, sourceTech.source);
  9087. }
  9088. } else {
  9089. // We need to wrap this in a timeout to give folks a chance to add error event handlers
  9090. this.setTimeout(function () {
  9091. this.error({ code: 4, message: this.localize(this.options_.notSupportedMessage) });
  9092. }, 0);
  9093. // we could not find an appropriate tech, but let's still notify the delegate that this is it
  9094. // this needs a better comment about why this is needed
  9095. this.triggerReady();
  9096. }
  9097. };
  9098. /**
  9099. * Begin loading the src data.
  9100. *
  9101. * @return {Player} Returns the player
  9102. * @method load
  9103. */
  9104. Player.prototype.load = function load() {
  9105. this.techCall_('load');
  9106. return this;
  9107. };
  9108. /**
  9109. * Reset the player. Loads the first tech in the techOrder,
  9110. * and calls `reset` on the tech`.
  9111. *
  9112. * @return {Player} Returns the player
  9113. * @method reset
  9114. */
  9115. Player.prototype.reset = function reset() {
  9116. this.loadTech_(_utilsToTitleCaseJs2['default'](this.options_.techOrder[0]), null);
  9117. this.techCall_('reset');
  9118. return this;
  9119. };
  9120. /**
  9121. * Returns the fully qualified URL of the current source value e.g. http://mysite.com/video.mp4
  9122. * Can be used in conjuction with `currentType` to assist in rebuilding the current source object.
  9123. *
  9124. * @return {String} The current source
  9125. * @method currentSrc
  9126. */
  9127. Player.prototype.currentSrc = function currentSrc() {
  9128. return this.techGet_('currentSrc') || this.cache_.src || '';
  9129. };
  9130. /**
  9131. * Get the current source type e.g. video/mp4
  9132. * This can allow you rebuild the current source object so that you could load the same
  9133. * source and tech later
  9134. *
  9135. * @return {String} The source MIME type
  9136. * @method currentType
  9137. */
  9138. Player.prototype.currentType = function currentType() {
  9139. return this.currentType_ || '';
  9140. };
  9141. /**
  9142. * Get or set the preload attribute
  9143. *
  9144. * @param {Boolean} value Boolean to determine if preload should be used
  9145. * @return {String} The preload attribute value when getting
  9146. * @return {Player} Returns the player when setting
  9147. * @method preload
  9148. */
  9149. Player.prototype.preload = function preload(value) {
  9150. if (value !== undefined) {
  9151. this.techCall_('setPreload', value);
  9152. this.options_.preload = value;
  9153. return this;
  9154. }
  9155. return this.techGet_('preload');
  9156. };
  9157. /**
  9158. * Get or set the autoplay attribute.
  9159. *
  9160. * @param {Boolean} value Boolean to determine if video should autoplay
  9161. * @return {String} The autoplay attribute value when getting
  9162. * @return {Player} Returns the player when setting
  9163. * @method autoplay
  9164. */
  9165. Player.prototype.autoplay = function autoplay(value) {
  9166. if (value !== undefined) {
  9167. this.techCall_('setAutoplay', value);
  9168. this.options_.autoplay = value;
  9169. return this;
  9170. }
  9171. return this.techGet_('autoplay', value);
  9172. };
  9173. /**
  9174. * Get or set the loop attribute on the video element.
  9175. *
  9176. * @param {Boolean} value Boolean to determine if video should loop
  9177. * @return {String} The loop attribute value when getting
  9178. * @return {Player} Returns the player when setting
  9179. * @method loop
  9180. */
  9181. Player.prototype.loop = function loop(value) {
  9182. if (value !== undefined) {
  9183. this.techCall_('setLoop', value);
  9184. this.options_['loop'] = value;
  9185. return this;
  9186. }
  9187. return this.techGet_('loop');
  9188. };
  9189. /**
  9190. * Get or set the poster image source url
  9191. *
  9192. * ##### EXAMPLE:
  9193. * ```js
  9194. * // get
  9195. * var currentPoster = myPlayer.poster();
  9196. * // set
  9197. * myPlayer.poster('http://example.com/myImage.jpg');
  9198. * ```
  9199. *
  9200. * @param {String=} src Poster image source URL
  9201. * @return {String} poster URL when getting
  9202. * @return {Player} self when setting
  9203. * @method poster
  9204. */
  9205. Player.prototype.poster = function poster(src) {
  9206. if (src === undefined) {
  9207. return this.poster_;
  9208. }
  9209. // The correct way to remove a poster is to set as an empty string
  9210. // other falsey values will throw errors
  9211. if (!src) {
  9212. src = '';
  9213. }
  9214. // update the internal poster variable
  9215. this.poster_ = src;
  9216. // update the tech's poster
  9217. this.techCall_('setPoster', src);
  9218. // alert components that the poster has been set
  9219. this.trigger('posterchange');
  9220. return this;
  9221. };
  9222. /**
  9223. * Some techs (e.g. YouTube) can provide a poster source in an
  9224. * asynchronous way. We want the poster component to use this
  9225. * poster source so that it covers up the tech's controls.
  9226. * (YouTube's play button). However we only want to use this
  9227. * soruce if the player user hasn't set a poster through
  9228. * the normal APIs.
  9229. *
  9230. * @private
  9231. * @method handleTechPosterChange_
  9232. */
  9233. Player.prototype.handleTechPosterChange_ = function handleTechPosterChange_() {
  9234. if (!this.poster_ && this.tech_ && this.tech_.poster) {
  9235. this.poster_ = this.tech_.poster() || '';
  9236. // Let components know the poster has changed
  9237. this.trigger('posterchange');
  9238. }
  9239. };
  9240. /**
  9241. * Get or set whether or not the controls are showing.
  9242. *
  9243. * @param {Boolean} bool Set controls to showing or not
  9244. * @return {Boolean} Controls are showing
  9245. * @method controls
  9246. */
  9247. Player.prototype.controls = function controls(bool) {
  9248. if (bool !== undefined) {
  9249. bool = !!bool; // force boolean
  9250. // Don't trigger a change event unless it actually changed
  9251. if (this.controls_ !== bool) {
  9252. this.controls_ = bool;
  9253. if (this.usingNativeControls()) {
  9254. this.techCall_('setControls', bool);
  9255. }
  9256. if (bool) {
  9257. this.removeClass('vjs-controls-disabled');
  9258. this.addClass('vjs-controls-enabled');
  9259. this.trigger('controlsenabled');
  9260. if (!this.usingNativeControls()) {
  9261. this.addTechControlsListeners_();
  9262. }
  9263. } else {
  9264. this.removeClass('vjs-controls-enabled');
  9265. this.addClass('vjs-controls-disabled');
  9266. this.trigger('controlsdisabled');
  9267. if (!this.usingNativeControls()) {
  9268. this.removeTechControlsListeners_();
  9269. }
  9270. }
  9271. }
  9272. return this;
  9273. }
  9274. return !!this.controls_;
  9275. };
  9276. /**
  9277. * Toggle native controls on/off. Native controls are the controls built into
  9278. * devices (e.g. default iPhone controls), Flash, or other techs
  9279. * (e.g. Vimeo Controls)
  9280. * **This should only be set by the current tech, because only the tech knows
  9281. * if it can support native controls**
  9282. *
  9283. * @param {Boolean} bool True signals that native controls are on
  9284. * @return {Player} Returns the player
  9285. * @private
  9286. * @method usingNativeControls
  9287. */
  9288. Player.prototype.usingNativeControls = function usingNativeControls(bool) {
  9289. if (bool !== undefined) {
  9290. bool = !!bool; // force boolean
  9291. // Don't trigger a change event unless it actually changed
  9292. if (this.usingNativeControls_ !== bool) {
  9293. this.usingNativeControls_ = bool;
  9294. if (bool) {
  9295. this.addClass('vjs-using-native-controls');
  9296. /**
  9297. * player is using the native device controls
  9298. *
  9299. * @event usingnativecontrols
  9300. * @memberof Player
  9301. * @instance
  9302. * @private
  9303. */
  9304. this.trigger('usingnativecontrols');
  9305. } else {
  9306. this.removeClass('vjs-using-native-controls');
  9307. /**
  9308. * player is using the custom HTML controls
  9309. *
  9310. * @event usingcustomcontrols
  9311. * @memberof Player
  9312. * @instance
  9313. * @private
  9314. */
  9315. this.trigger('usingcustomcontrols');
  9316. }
  9317. }
  9318. return this;
  9319. }
  9320. return !!this.usingNativeControls_;
  9321. };
  9322. /**
  9323. * Set or get the current MediaError
  9324. *
  9325. * @param {*} err A MediaError or a String/Number to be turned into a MediaError
  9326. * @return {MediaError|null} when getting
  9327. * @return {Player} when setting
  9328. * @method error
  9329. */
  9330. Player.prototype.error = function error(err) {
  9331. if (err === undefined) {
  9332. return this.error_ || null;
  9333. }
  9334. // restoring to default
  9335. if (err === null) {
  9336. this.error_ = err;
  9337. this.removeClass('vjs-error');
  9338. this.errorDisplay.close();
  9339. return this;
  9340. }
  9341. // error instance
  9342. if (err instanceof _mediaErrorJs2['default']) {
  9343. this.error_ = err;
  9344. } else {
  9345. this.error_ = new _mediaErrorJs2['default'](err);
  9346. }
  9347. // add the vjs-error classname to the player
  9348. this.addClass('vjs-error');
  9349. // log the name of the error type and any message
  9350. // ie8 just logs "[object object]" if you just log the error object
  9351. _utilsLogJs2['default'].error('(CODE:' + this.error_.code + ' ' + _mediaErrorJs2['default'].errorTypes[this.error_.code] + ')', this.error_.message, this.error_);
  9352. // fire an error event on the player
  9353. this.trigger('error');
  9354. return this;
  9355. };
  9356. /**
  9357. * Returns whether or not the player is in the "ended" state.
  9358. *
  9359. * @return {Boolean} True if the player is in the ended state, false if not.
  9360. * @method ended
  9361. */
  9362. Player.prototype.ended = function ended() {
  9363. return this.techGet_('ended');
  9364. };
  9365. /**
  9366. * Returns whether or not the player is in the "seeking" state.
  9367. *
  9368. * @return {Boolean} True if the player is in the seeking state, false if not.
  9369. * @method seeking
  9370. */
  9371. Player.prototype.seeking = function seeking() {
  9372. return this.techGet_('seeking');
  9373. };
  9374. /**
  9375. * Returns the TimeRanges of the media that are currently available
  9376. * for seeking to.
  9377. *
  9378. * @return {TimeRanges} the seekable intervals of the media timeline
  9379. * @method seekable
  9380. */
  9381. Player.prototype.seekable = function seekable() {
  9382. return this.techGet_('seekable');
  9383. };
  9384. /**
  9385. * Report user activity
  9386. *
  9387. * @param {Object} event Event object
  9388. * @method reportUserActivity
  9389. */
  9390. Player.prototype.reportUserActivity = function reportUserActivity(event) {
  9391. this.userActivity_ = true;
  9392. };
  9393. /**
  9394. * Get/set if user is active
  9395. *
  9396. * @param {Boolean} bool Value when setting
  9397. * @return {Boolean} Value if user is active user when getting
  9398. * @method userActive
  9399. */
  9400. Player.prototype.userActive = function userActive(bool) {
  9401. if (bool !== undefined) {
  9402. bool = !!bool;
  9403. if (bool !== this.userActive_) {
  9404. this.userActive_ = bool;
  9405. if (bool) {
  9406. // If the user was inactive and is now active we want to reset the
  9407. // inactivity timer
  9408. this.userActivity_ = true;
  9409. this.removeClass('vjs-user-inactive');
  9410. this.addClass('vjs-user-active');
  9411. this.trigger('useractive');
  9412. } else {
  9413. // We're switching the state to inactive manually, so erase any other
  9414. // activity
  9415. this.userActivity_ = false;
  9416. // Chrome/Safari/IE have bugs where when you change the cursor it can
  9417. // trigger a mousemove event. This causes an issue when you're hiding
  9418. // the cursor when the user is inactive, and a mousemove signals user
  9419. // activity. Making it impossible to go into inactive mode. Specifically
  9420. // this happens in fullscreen when we really need to hide the cursor.
  9421. //
  9422. // When this gets resolved in ALL browsers it can be removed
  9423. // https://code.google.com/p/chromium/issues/detail?id=103041
  9424. if (this.tech_) {
  9425. this.tech_.one('mousemove', function (e) {
  9426. e.stopPropagation();
  9427. e.preventDefault();
  9428. });
  9429. }
  9430. this.removeClass('vjs-user-active');
  9431. this.addClass('vjs-user-inactive');
  9432. this.trigger('userinactive');
  9433. }
  9434. }
  9435. return this;
  9436. }
  9437. return this.userActive_;
  9438. };
  9439. /**
  9440. * Listen for user activity based on timeout value
  9441. *
  9442. * @private
  9443. * @method listenForUserActivity_
  9444. */
  9445. Player.prototype.listenForUserActivity_ = function listenForUserActivity_() {
  9446. var mouseInProgress = undefined,
  9447. lastMoveX = undefined,
  9448. lastMoveY = undefined;
  9449. var handleActivity = Fn.bind(this, this.reportUserActivity);
  9450. var handleMouseMove = function handleMouseMove(e) {
  9451. // #1068 - Prevent mousemove spamming
  9452. // Chrome Bug: https://code.google.com/p/chromium/issues/detail?id=366970
  9453. if (e.screenX !== lastMoveX || e.screenY !== lastMoveY) {
  9454. lastMoveX = e.screenX;
  9455. lastMoveY = e.screenY;
  9456. handleActivity();
  9457. }
  9458. };
  9459. var handleMouseDown = function handleMouseDown() {
  9460. handleActivity();
  9461. // For as long as the they are touching the device or have their mouse down,
  9462. // we consider them active even if they're not moving their finger or mouse.
  9463. // So we want to continue to update that they are active
  9464. this.clearInterval(mouseInProgress);
  9465. // Setting userActivity=true now and setting the interval to the same time
  9466. // as the activityCheck interval (250) should ensure we never miss the
  9467. // next activityCheck
  9468. mouseInProgress = this.setInterval(handleActivity, 250);
  9469. };
  9470. var handleMouseUp = function handleMouseUp(event) {
  9471. handleActivity();
  9472. // Stop the interval that maintains activity if the mouse/touch is down
  9473. this.clearInterval(mouseInProgress);
  9474. };
  9475. // Any mouse movement will be considered user activity
  9476. this.on('mousedown', handleMouseDown);
  9477. this.on('mousemove', handleMouseMove);
  9478. this.on('mouseup', handleMouseUp);
  9479. // Listen for keyboard navigation
  9480. // Shouldn't need to use inProgress interval because of key repeat
  9481. this.on('keydown', handleActivity);
  9482. this.on('keyup', handleActivity);
  9483. // Run an interval every 250 milliseconds instead of stuffing everything into
  9484. // the mousemove/touchmove function itself, to prevent performance degradation.
  9485. // `this.reportUserActivity` simply sets this.userActivity_ to true, which
  9486. // then gets picked up by this loop
  9487. // http://ejohn.org/blog/learning-from-twitter/
  9488. var inactivityTimeout = undefined;
  9489. var activityCheck = this.setInterval(function () {
  9490. // Check to see if mouse/touch activity has happened
  9491. if (this.userActivity_) {
  9492. // Reset the activity tracker
  9493. this.userActivity_ = false;
  9494. // If the user state was inactive, set the state to active
  9495. this.userActive(true);
  9496. // Clear any existing inactivity timeout to start the timer over
  9497. this.clearTimeout(inactivityTimeout);
  9498. var timeout = this.options_['inactivityTimeout'];
  9499. if (timeout > 0) {
  9500. // In <timeout> milliseconds, if no more activity has occurred the
  9501. // user will be considered inactive
  9502. inactivityTimeout = this.setTimeout(function () {
  9503. // Protect against the case where the inactivityTimeout can trigger just
  9504. // before the next user activity is picked up by the activityCheck loop
  9505. // causing a flicker
  9506. if (!this.userActivity_) {
  9507. this.userActive(false);
  9508. }
  9509. }, timeout);
  9510. }
  9511. }
  9512. }, 250);
  9513. };
  9514. /**
  9515. * Gets or sets the current playback rate. A playback rate of
  9516. * 1.0 represents normal speed and 0.5 would indicate half-speed
  9517. * playback, for instance.
  9518. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-playbackrate
  9519. *
  9520. * @param {Number} rate New playback rate to set.
  9521. * @return {Number} Returns the new playback rate when setting
  9522. * @return {Number} Returns the current playback rate when getting
  9523. * @method playbackRate
  9524. */
  9525. Player.prototype.playbackRate = function playbackRate(rate) {
  9526. if (rate !== undefined) {
  9527. this.techCall_('setPlaybackRate', rate);
  9528. return this;
  9529. }
  9530. if (this.tech_ && this.tech_['featuresPlaybackRate']) {
  9531. return this.techGet_('playbackRate');
  9532. } else {
  9533. return 1.0;
  9534. }
  9535. };
  9536. /**
  9537. * Gets or sets the audio flag
  9538. *
  9539. * @param {Boolean} bool True signals that this is an audio player.
  9540. * @return {Boolean} Returns true if player is audio, false if not when getting
  9541. * @return {Player} Returns the player if setting
  9542. * @private
  9543. * @method isAudio
  9544. */
  9545. Player.prototype.isAudio = function isAudio(bool) {
  9546. if (bool !== undefined) {
  9547. this.isAudio_ = !!bool;
  9548. return this;
  9549. }
  9550. return !!this.isAudio_;
  9551. };
  9552. /**
  9553. * Returns the current state of network activity for the element, from
  9554. * the codes in the list below.
  9555. * - NETWORK_EMPTY (numeric value 0)
  9556. * The element has not yet been initialised. All attributes are in
  9557. * their initial states.
  9558. * - NETWORK_IDLE (numeric value 1)
  9559. * The element's resource selection algorithm is active and has
  9560. * selected a resource, but it is not actually using the network at
  9561. * this time.
  9562. * - NETWORK_LOADING (numeric value 2)
  9563. * The user agent is actively trying to download data.
  9564. * - NETWORK_NO_SOURCE (numeric value 3)
  9565. * The element's resource selection algorithm is active, but it has
  9566. * not yet found a resource to use.
  9567. *
  9568. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#network-states
  9569. * @return {Number} the current network activity state
  9570. * @method networkState
  9571. */
  9572. Player.prototype.networkState = function networkState() {
  9573. return this.techGet_('networkState');
  9574. };
  9575. /**
  9576. * Returns a value that expresses the current state of the element
  9577. * with respect to rendering the current playback position, from the
  9578. * codes in the list below.
  9579. * - HAVE_NOTHING (numeric value 0)
  9580. * No information regarding the media resource is available.
  9581. * - HAVE_METADATA (numeric value 1)
  9582. * Enough of the resource has been obtained that the duration of the
  9583. * resource is available.
  9584. * - HAVE_CURRENT_DATA (numeric value 2)
  9585. * Data for the immediate current playback position is available.
  9586. * - HAVE_FUTURE_DATA (numeric value 3)
  9587. * Data for the immediate current playback position is available, as
  9588. * well as enough data for the user agent to advance the current
  9589. * playback position in the direction of playback.
  9590. * - HAVE_ENOUGH_DATA (numeric value 4)
  9591. * The user agent estimates that enough data is available for
  9592. * playback to proceed uninterrupted.
  9593. *
  9594. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-readystate
  9595. * @return {Number} the current playback rendering state
  9596. * @method readyState
  9597. */
  9598. Player.prototype.readyState = function readyState() {
  9599. return this.techGet_('readyState');
  9600. };
  9601. /*
  9602. * Text tracks are tracks of timed text events.
  9603. * Captions - text displayed over the video for the hearing impaired
  9604. * Subtitles - text displayed over the video for those who don't understand language in the video
  9605. * Chapters - text displayed in a menu allowing the user to jump to particular points (chapters) in the video
  9606. * Descriptions (not supported yet) - audio descriptions that are read back to the user by a screen reading device
  9607. */
  9608. /**
  9609. * Get an array of associated text tracks. captions, subtitles, chapters, descriptions
  9610. * http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#dom-media-texttracks
  9611. *
  9612. * @return {Array} Array of track objects
  9613. * @method textTracks
  9614. */
  9615. Player.prototype.textTracks = function textTracks() {
  9616. // cannot use techGet_ directly because it checks to see whether the tech is ready.
  9617. // Flash is unlikely to be ready in time but textTracks should still work.
  9618. return this.tech_ && this.tech_['textTracks']();
  9619. };
  9620. /**
  9621. * Get an array of remote text tracks
  9622. *
  9623. * @return {Array}
  9624. * @method remoteTextTracks
  9625. */
  9626. Player.prototype.remoteTextTracks = function remoteTextTracks() {
  9627. return this.tech_ && this.tech_['remoteTextTracks']();
  9628. };
  9629. /**
  9630. * Get an array of remote html track elements
  9631. *
  9632. * @return {HTMLTrackElement[]}
  9633. * @method remoteTextTrackEls
  9634. */
  9635. Player.prototype.remoteTextTrackEls = function remoteTextTrackEls() {
  9636. return this.tech_ && this.tech_['remoteTextTrackEls']();
  9637. };
  9638. /**
  9639. * Add a text track
  9640. * In addition to the W3C settings we allow adding additional info through options.
  9641. * http://www.w3.org/html/wg/drafts/html/master/embedded-content-0.html#dom-media-addtexttrack
  9642. *
  9643. * @param {String} kind Captions, subtitles, chapters, descriptions, or metadata
  9644. * @param {String=} label Optional label
  9645. * @param {String=} language Optional language
  9646. * @method addTextTrack
  9647. */
  9648. Player.prototype.addTextTrack = function addTextTrack(kind, label, language) {
  9649. return this.tech_ && this.tech_['addTextTrack'](kind, label, language);
  9650. };
  9651. /**
  9652. * Add a remote text track
  9653. *
  9654. * @param {Object} options Options for remote text track
  9655. * @method addRemoteTextTrack
  9656. */
  9657. Player.prototype.addRemoteTextTrack = function addRemoteTextTrack(options) {
  9658. return this.tech_ && this.tech_['addRemoteTextTrack'](options);
  9659. };
  9660. /**
  9661. * Remove a remote text track
  9662. *
  9663. * @param {Object} track Remote text track to remove
  9664. * @method removeRemoteTextTrack
  9665. */
  9666. Player.prototype.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  9667. this.tech_ && this.tech_['removeRemoteTextTrack'](track);
  9668. };
  9669. /**
  9670. * Get video width
  9671. *
  9672. * @return {Number} Video width
  9673. * @method videoWidth
  9674. */
  9675. Player.prototype.videoWidth = function videoWidth() {
  9676. return this.tech_ && this.tech_.videoWidth && this.tech_.videoWidth() || 0;
  9677. };
  9678. /**
  9679. * Get video height
  9680. *
  9681. * @return {Number} Video height
  9682. * @method videoHeight
  9683. */
  9684. Player.prototype.videoHeight = function videoHeight() {
  9685. return this.tech_ && this.tech_.videoHeight && this.tech_.videoHeight() || 0;
  9686. };
  9687. // Methods to add support for
  9688. // initialTime: function(){ return this.techCall_('initialTime'); },
  9689. // startOffsetTime: function(){ return this.techCall_('startOffsetTime'); },
  9690. // played: function(){ return this.techCall_('played'); },
  9691. // videoTracks: function(){ return this.techCall_('videoTracks'); },
  9692. // audioTracks: function(){ return this.techCall_('audioTracks'); },
  9693. // defaultPlaybackRate: function(){ return this.techCall_('defaultPlaybackRate'); },
  9694. // defaultMuted: function(){ return this.techCall_('defaultMuted'); }
  9695. /**
  9696. * The player's language code
  9697. * NOTE: The language should be set in the player options if you want the
  9698. * the controls to be built with a specific language. Changing the lanugage
  9699. * later will not update controls text.
  9700. *
  9701. * @param {String} code The locale string
  9702. * @return {String} The locale string when getting
  9703. * @return {Player} self when setting
  9704. * @method language
  9705. */
  9706. Player.prototype.language = function language(code) {
  9707. if (code === undefined) {
  9708. return this.language_;
  9709. }
  9710. this.language_ = ('' + code).toLowerCase();
  9711. return this;
  9712. };
  9713. /**
  9714. * Get the player's language dictionary
  9715. * Merge every time, because a newly added plugin might call videojs.addLanguage() at any time
  9716. * Languages specified directly in the player options have precedence
  9717. *
  9718. * @return {Array} Array of languages
  9719. * @method languages
  9720. */
  9721. Player.prototype.languages = function languages() {
  9722. return _utilsMergeOptionsJs2['default'](Player.prototype.options_.languages, this.languages_);
  9723. };
  9724. /**
  9725. * Converts track info to JSON
  9726. *
  9727. * @return {Object} JSON object of options
  9728. * @method toJSON
  9729. */
  9730. Player.prototype.toJSON = function toJSON() {
  9731. var options = _utilsMergeOptionsJs2['default'](this.options_);
  9732. var tracks = options.tracks;
  9733. options.tracks = [];
  9734. for (var i = 0; i < tracks.length; i++) {
  9735. var track = tracks[i];
  9736. // deep merge tracks and null out player so no circular references
  9737. track = _utilsMergeOptionsJs2['default'](track);
  9738. track.player = undefined;
  9739. options.tracks[i] = track;
  9740. }
  9741. return options;
  9742. };
  9743. /**
  9744. * Creates a simple modal dialog (an instance of the `ModalDialog`
  9745. * component) that immediately overlays the player with arbitrary
  9746. * content and removes itself when closed.
  9747. *
  9748. * @param {String|Function|Element|Array|Null} content
  9749. * Same as `ModalDialog#content`'s param of the same name.
  9750. *
  9751. * The most straight-forward usage is to provide a string or DOM
  9752. * element.
  9753. *
  9754. * @param {Object} [options]
  9755. * Extra options which will be passed on to the `ModalDialog`.
  9756. *
  9757. * @return {ModalDialog}
  9758. */
  9759. Player.prototype.createModal = function createModal(content, options) {
  9760. var player = this;
  9761. options = options || {};
  9762. options.content = content || '';
  9763. var modal = new _modalDialog2['default'](player, options);
  9764. player.addChild(modal);
  9765. modal.on('dispose', function () {
  9766. player.removeChild(modal);
  9767. });
  9768. return modal.open();
  9769. };
  9770. /**
  9771. * Gets tag settings
  9772. *
  9773. * @param {Element} tag The player tag
  9774. * @return {Array} An array of sources and track objects
  9775. * @static
  9776. * @method getTagSettings
  9777. */
  9778. Player.getTagSettings = function getTagSettings(tag) {
  9779. var baseOptions = {
  9780. 'sources': [],
  9781. 'tracks': []
  9782. };
  9783. var tagOptions = Dom.getElAttributes(tag);
  9784. var dataSetup = tagOptions['data-setup'];
  9785. // Check if data-setup attr exists.
  9786. if (dataSetup !== null) {
  9787. // Parse options JSON
  9788. var _safeParseTuple = _safeJsonParseTuple2['default'](dataSetup || '{}');
  9789. var err = _safeParseTuple[0];
  9790. var data = _safeParseTuple[1];
  9791. if (err) {
  9792. _utilsLogJs2['default'].error(err);
  9793. }
  9794. _objectAssign2['default'](tagOptions, data);
  9795. }
  9796. _objectAssign2['default'](baseOptions, tagOptions);
  9797. // Get tag children settings
  9798. if (tag.hasChildNodes()) {
  9799. var children = tag.childNodes;
  9800. for (var i = 0, j = children.length; i < j; i++) {
  9801. var child = children[i];
  9802. // Change case needed: http://ejohn.org/blog/nodename-case-sensitivity/
  9803. var childName = child.nodeName.toLowerCase();
  9804. if (childName === 'source') {
  9805. baseOptions.sources.push(Dom.getElAttributes(child));
  9806. } else if (childName === 'track') {
  9807. baseOptions.tracks.push(Dom.getElAttributes(child));
  9808. }
  9809. }
  9810. }
  9811. return baseOptions;
  9812. };
  9813. return Player;
  9814. })(_componentJs2['default']);
  9815. Player.players = {};
  9816. var navigator = _globalWindow2['default'].navigator;
  9817. /*
  9818. * Player instance options, surfaced using options
  9819. * options = Player.prototype.options_
  9820. * Make changes in options, not here.
  9821. *
  9822. * @type {Object}
  9823. * @private
  9824. */
  9825. Player.prototype.options_ = {
  9826. // Default order of fallback technology
  9827. techOrder: ['html5', 'flash'],
  9828. // techOrder: ['flash','html5'],
  9829. html5: {},
  9830. flash: {},
  9831. // defaultVolume: 0.85,
  9832. defaultVolume: 0.00, // The freakin seaguls are driving me crazy!
  9833. // default inactivity timeout
  9834. inactivityTimeout: 2000,
  9835. // default playback rates
  9836. playbackRates: [],
  9837. // Add playback rate selection by adding rates
  9838. // 'playbackRates': [0.5, 1, 1.5, 2],
  9839. // Included control sets
  9840. children: ['mediaLoader', 'posterImage', 'textTrackDisplay', 'loadingSpinner', 'bigPlayButton', 'controlBar', 'errorDisplay', 'textTrackSettings'],
  9841. language: _globalDocument2['default'].getElementsByTagName('html')[0].getAttribute('lang') || navigator.languages && navigator.languages[0] || navigator.userLanguage || navigator.language || 'en',
  9842. // locales and their language translations
  9843. languages: {},
  9844. // Default message to show when a video cannot be played.
  9845. notSupportedMessage: 'No compatible source was found for this media.'
  9846. };
  9847. /**
  9848. * Fired when the player has initial duration and dimension information
  9849. *
  9850. * @event loadedmetadata
  9851. */
  9852. Player.prototype.handleLoadedMetaData_;
  9853. /**
  9854. * Fired when the player has downloaded data at the current playback position
  9855. *
  9856. * @event loadeddata
  9857. */
  9858. Player.prototype.handleLoadedData_;
  9859. /**
  9860. * Fired when the user is active, e.g. moves the mouse over the player
  9861. *
  9862. * @event useractive
  9863. */
  9864. Player.prototype.handleUserActive_;
  9865. /**
  9866. * Fired when the user is inactive, e.g. a short delay after the last mouse move or control interaction
  9867. *
  9868. * @event userinactive
  9869. */
  9870. Player.prototype.handleUserInactive_;
  9871. /**
  9872. * Fired when the current playback position has changed *
  9873. * During playback this is fired every 15-250 milliseconds, depending on the
  9874. * playback technology in use.
  9875. *
  9876. * @event timeupdate
  9877. */
  9878. Player.prototype.handleTimeUpdate_;
  9879. /**
  9880. * Fired when video playback ends
  9881. *
  9882. * @event ended
  9883. */
  9884. Player.prototype.handleTechEnded_;
  9885. /**
  9886. * Fired when the volume changes
  9887. *
  9888. * @event volumechange
  9889. */
  9890. Player.prototype.handleVolumeChange_;
  9891. /**
  9892. * Fired when an error occurs
  9893. *
  9894. * @event error
  9895. */
  9896. Player.prototype.handleError_;
  9897. Player.prototype.flexNotSupported_ = function () {
  9898. var elem = _globalDocument2['default'].createElement('i');
  9899. // Note: We don't actually use flexBasis (or flexOrder), but it's one of the more
  9900. // common flex features that we can rely on when checking for flex support.
  9901. return !('flexBasis' in elem.style || 'webkitFlexBasis' in elem.style || 'mozFlexBasis' in elem.style || 'msFlexBasis' in elem.style || 'msFlexOrder' in elem.style) /* IE10-specific (2012 flex spec) */;
  9902. };
  9903. _componentJs2['default'].registerComponent('Player', Player);
  9904. exports['default'] = Player;
  9905. module.exports = exports['default'];
  9906. // If empty string, make it a parsable json object.
  9907. },{"./big-play-button.js":63,"./component.js":67,"./control-bar/control-bar.js":68,"./error-display.js":98,"./fullscreen-api.js":101,"./loading-spinner.js":102,"./media-error.js":103,"./modal-dialog":107,"./poster-image.js":112,"./tech/html5.js":117,"./tech/loader.js":118,"./tech/tech.js":119,"./tracks/text-track-display.js":123,"./tracks/text-track-list-converter.js":125,"./tracks/text-track-settings.js":127,"./utils/browser.js":129,"./utils/buffer.js":130,"./utils/dom.js":132,"./utils/events.js":133,"./utils/fn.js":134,"./utils/guid.js":136,"./utils/log.js":137,"./utils/merge-options.js":138,"./utils/stylesheet.js":139,"./utils/time-ranges.js":140,"./utils/to-title-case.js":141,"global/document":1,"global/window":2,"object.assign":45,"safe-json-parse/tuple":54}],109:[function(_dereq_,module,exports){
  9908. /**
  9909. * @file plugins.js
  9910. */
  9911. 'use strict';
  9912. exports.__esModule = true;
  9913. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  9914. var _playerJs = _dereq_('./player.js');
  9915. var _playerJs2 = _interopRequireDefault(_playerJs);
  9916. /**
  9917. * The method for registering a video.js plugin
  9918. *
  9919. * @param {String} name The name of the plugin
  9920. * @param {Function} init The function that is run when the player inits
  9921. * @method plugin
  9922. */
  9923. var plugin = function plugin(name, init) {
  9924. _playerJs2['default'].prototype[name] = init;
  9925. };
  9926. exports['default'] = plugin;
  9927. module.exports = exports['default'];
  9928. },{"./player.js":108}],110:[function(_dereq_,module,exports){
  9929. /**
  9930. * @file popup-button.js
  9931. */
  9932. 'use strict';
  9933. exports.__esModule = true;
  9934. 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; } }
  9935. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  9936. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  9937. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  9938. var _clickableComponentJs = _dereq_('../clickable-component.js');
  9939. var _clickableComponentJs2 = _interopRequireDefault(_clickableComponentJs);
  9940. var _componentJs = _dereq_('../component.js');
  9941. var _componentJs2 = _interopRequireDefault(_componentJs);
  9942. var _popupJs = _dereq_('./popup.js');
  9943. var _popupJs2 = _interopRequireDefault(_popupJs);
  9944. var _utilsDomJs = _dereq_('../utils/dom.js');
  9945. var Dom = _interopRequireWildcard(_utilsDomJs);
  9946. var _utilsFnJs = _dereq_('../utils/fn.js');
  9947. var Fn = _interopRequireWildcard(_utilsFnJs);
  9948. var _utilsToTitleCaseJs = _dereq_('../utils/to-title-case.js');
  9949. var _utilsToTitleCaseJs2 = _interopRequireDefault(_utilsToTitleCaseJs);
  9950. /**
  9951. * A button class with a popup control
  9952. *
  9953. * @param {Player|Object} player
  9954. * @param {Object=} options
  9955. * @extends ClickableComponent
  9956. * @class PopupButton
  9957. */
  9958. var PopupButton = (function (_ClickableComponent) {
  9959. _inherits(PopupButton, _ClickableComponent);
  9960. function PopupButton(player) {
  9961. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  9962. _classCallCheck(this, PopupButton);
  9963. _ClickableComponent.call(this, player, options);
  9964. this.update();
  9965. }
  9966. /**
  9967. * Update popup
  9968. *
  9969. * @method update
  9970. */
  9971. PopupButton.prototype.update = function update() {
  9972. var popup = this.createPopup();
  9973. if (this.popup) {
  9974. this.removeChild(this.popup);
  9975. }
  9976. this.popup = popup;
  9977. this.addChild(popup);
  9978. if (this.items && this.items.length === 0) {
  9979. this.hide();
  9980. } else if (this.items && this.items.length > 1) {
  9981. this.show();
  9982. }
  9983. };
  9984. /**
  9985. * Create popup - Override with specific functionality for component
  9986. *
  9987. * @return {Popup} The constructed popup
  9988. * @method createPopup
  9989. */
  9990. PopupButton.prototype.createPopup = function createPopup() {};
  9991. /**
  9992. * Create the component's DOM element
  9993. *
  9994. * @return {Element}
  9995. * @method createEl
  9996. */
  9997. PopupButton.prototype.createEl = function createEl() {
  9998. return _ClickableComponent.prototype.createEl.call(this, 'div', {
  9999. className: this.buildCSSClass()
  10000. });
  10001. };
  10002. /**
  10003. * Allow sub components to stack CSS class names
  10004. *
  10005. * @return {String} The constructed class name
  10006. * @method buildCSSClass
  10007. */
  10008. PopupButton.prototype.buildCSSClass = function buildCSSClass() {
  10009. var menuButtonClass = 'vjs-menu-button';
  10010. // If the inline option is passed, we want to use different styles altogether.
  10011. if (this.options_.inline === true) {
  10012. menuButtonClass += '-inline';
  10013. } else {
  10014. menuButtonClass += '-popup';
  10015. }
  10016. return 'vjs-menu-button ' + menuButtonClass + ' ' + _ClickableComponent.prototype.buildCSSClass.call(this);
  10017. };
  10018. return PopupButton;
  10019. })(_clickableComponentJs2['default']);
  10020. _componentJs2['default'].registerComponent('PopupButton', PopupButton);
  10021. exports['default'] = PopupButton;
  10022. module.exports = exports['default'];
  10023. },{"../clickable-component.js":65,"../component.js":67,"../utils/dom.js":132,"../utils/fn.js":134,"../utils/to-title-case.js":141,"./popup.js":111}],111:[function(_dereq_,module,exports){
  10024. /**
  10025. * @file popup.js
  10026. */
  10027. 'use strict';
  10028. exports.__esModule = true;
  10029. 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; } }
  10030. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  10031. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  10032. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10033. var _componentJs = _dereq_('../component.js');
  10034. var _componentJs2 = _interopRequireDefault(_componentJs);
  10035. var _utilsDomJs = _dereq_('../utils/dom.js');
  10036. var Dom = _interopRequireWildcard(_utilsDomJs);
  10037. var _utilsFnJs = _dereq_('../utils/fn.js');
  10038. var Fn = _interopRequireWildcard(_utilsFnJs);
  10039. var _utilsEventsJs = _dereq_('../utils/events.js');
  10040. var Events = _interopRequireWildcard(_utilsEventsJs);
  10041. /**
  10042. * The Popup component is used to build pop up controls.
  10043. *
  10044. * @extends Component
  10045. * @class Popup
  10046. */
  10047. var Popup = (function (_Component) {
  10048. _inherits(Popup, _Component);
  10049. function Popup() {
  10050. _classCallCheck(this, Popup);
  10051. _Component.apply(this, arguments);
  10052. }
  10053. /**
  10054. * Add a popup item to the popup
  10055. *
  10056. * @param {Object|String} component Component or component type to add
  10057. * @method addItem
  10058. */
  10059. Popup.prototype.addItem = function addItem(component) {
  10060. this.addChild(component);
  10061. component.on('click', Fn.bind(this, function () {
  10062. this.unlockShowing();
  10063. }));
  10064. };
  10065. /**
  10066. * Create the component's DOM element
  10067. *
  10068. * @return {Element}
  10069. * @method createEl
  10070. */
  10071. Popup.prototype.createEl = function createEl() {
  10072. var contentElType = this.options_.contentElType || 'ul';
  10073. this.contentEl_ = Dom.createEl(contentElType, {
  10074. className: 'vjs-menu-content'
  10075. });
  10076. var el = _Component.prototype.createEl.call(this, 'div', {
  10077. append: this.contentEl_,
  10078. className: 'vjs-menu'
  10079. });
  10080. el.appendChild(this.contentEl_);
  10081. // Prevent clicks from bubbling up. Needed for Popup Buttons,
  10082. // where a click on the parent is significant
  10083. Events.on(el, 'click', function (event) {
  10084. event.preventDefault();
  10085. event.stopImmediatePropagation();
  10086. });
  10087. return el;
  10088. };
  10089. return Popup;
  10090. })(_componentJs2['default']);
  10091. _componentJs2['default'].registerComponent('Popup', Popup);
  10092. exports['default'] = Popup;
  10093. module.exports = exports['default'];
  10094. },{"../component.js":67,"../utils/dom.js":132,"../utils/events.js":133,"../utils/fn.js":134}],112:[function(_dereq_,module,exports){
  10095. /**
  10096. * @file poster-image.js
  10097. */
  10098. 'use strict';
  10099. exports.__esModule = true;
  10100. 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; } }
  10101. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  10102. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  10103. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10104. var _clickableComponentJs = _dereq_('./clickable-component.js');
  10105. var _clickableComponentJs2 = _interopRequireDefault(_clickableComponentJs);
  10106. var _componentJs = _dereq_('./component.js');
  10107. var _componentJs2 = _interopRequireDefault(_componentJs);
  10108. var _utilsFnJs = _dereq_('./utils/fn.js');
  10109. var Fn = _interopRequireWildcard(_utilsFnJs);
  10110. var _utilsDomJs = _dereq_('./utils/dom.js');
  10111. var Dom = _interopRequireWildcard(_utilsDomJs);
  10112. var _utilsBrowserJs = _dereq_('./utils/browser.js');
  10113. var browser = _interopRequireWildcard(_utilsBrowserJs);
  10114. /**
  10115. * The component that handles showing the poster image.
  10116. *
  10117. * @param {Player|Object} player
  10118. * @param {Object=} options
  10119. * @extends Button
  10120. * @class PosterImage
  10121. */
  10122. var PosterImage = (function (_ClickableComponent) {
  10123. _inherits(PosterImage, _ClickableComponent);
  10124. function PosterImage(player, options) {
  10125. _classCallCheck(this, PosterImage);
  10126. _ClickableComponent.call(this, player, options);
  10127. this.update();
  10128. player.on('posterchange', Fn.bind(this, this.update));
  10129. }
  10130. /**
  10131. * Clean up the poster image
  10132. *
  10133. * @method dispose
  10134. */
  10135. PosterImage.prototype.dispose = function dispose() {
  10136. this.player().off('posterchange', this.update);
  10137. _ClickableComponent.prototype.dispose.call(this);
  10138. };
  10139. /**
  10140. * Create the poster's image element
  10141. *
  10142. * @return {Element}
  10143. * @method createEl
  10144. */
  10145. PosterImage.prototype.createEl = function createEl() {
  10146. var el = Dom.createEl('div', {
  10147. className: 'vjs-poster',
  10148. // Don't want poster to be tabbable.
  10149. tabIndex: -1
  10150. });
  10151. // To ensure the poster image resizes while maintaining its original aspect
  10152. // ratio, use a div with `background-size` when available. For browsers that
  10153. // do not support `background-size` (e.g. IE8), fall back on using a regular
  10154. // img element.
  10155. if (!browser.BACKGROUND_SIZE_SUPPORTED) {
  10156. this.fallbackImg_ = Dom.createEl('img');
  10157. el.appendChild(this.fallbackImg_);
  10158. }
  10159. return el;
  10160. };
  10161. /**
  10162. * Event handler for updates to the player's poster source
  10163. *
  10164. * @method update
  10165. */
  10166. PosterImage.prototype.update = function update() {
  10167. var url = this.player().poster();
  10168. this.setSrc(url);
  10169. // If there's no poster source we should display:none on this component
  10170. // so it's not still clickable or right-clickable
  10171. if (url) {
  10172. this.show();
  10173. } else {
  10174. this.hide();
  10175. }
  10176. };
  10177. /**
  10178. * Set the poster source depending on the display method
  10179. *
  10180. * @param {String} url The URL to the poster source
  10181. * @method setSrc
  10182. */
  10183. PosterImage.prototype.setSrc = function setSrc(url) {
  10184. if (this.fallbackImg_) {
  10185. this.fallbackImg_.src = url;
  10186. } else {
  10187. var backgroundImage = '';
  10188. // Any falsey values should stay as an empty string, otherwise
  10189. // this will throw an extra error
  10190. if (url) {
  10191. backgroundImage = 'url("' + url + '")';
  10192. }
  10193. this.el_.style.backgroundImage = backgroundImage;
  10194. }
  10195. };
  10196. /**
  10197. * Event handler for clicks on the poster image
  10198. *
  10199. * @method handleClick
  10200. */
  10201. PosterImage.prototype.handleClick = function handleClick() {
  10202. // We don't want a click to trigger playback when controls are disabled
  10203. // but CSS should be hiding the poster to prevent that from happening
  10204. if (this.player_.paused()) {
  10205. this.player_.play();
  10206. } else {
  10207. this.player_.pause();
  10208. }
  10209. };
  10210. return PosterImage;
  10211. })(_clickableComponentJs2['default']);
  10212. _componentJs2['default'].registerComponent('PosterImage', PosterImage);
  10213. exports['default'] = PosterImage;
  10214. module.exports = exports['default'];
  10215. },{"./clickable-component.js":65,"./component.js":67,"./utils/browser.js":129,"./utils/dom.js":132,"./utils/fn.js":134}],113:[function(_dereq_,module,exports){
  10216. /**
  10217. * @file setup.js
  10218. *
  10219. * Functions for automatically setting up a player
  10220. * based on the data-setup attribute of the video tag
  10221. */
  10222. 'use strict';
  10223. exports.__esModule = true;
  10224. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  10225. 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; } }
  10226. var _utilsEventsJs = _dereq_('./utils/events.js');
  10227. var Events = _interopRequireWildcard(_utilsEventsJs);
  10228. var _globalDocument = _dereq_('global/document');
  10229. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  10230. var _globalWindow = _dereq_('global/window');
  10231. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  10232. var _windowLoaded = false;
  10233. var videojs = undefined;
  10234. // Automatically set up any tags that have a data-setup attribute
  10235. var autoSetup = function autoSetup() {
  10236. // One day, when we stop supporting IE8, go back to this, but in the meantime...*hack hack hack*
  10237. // var vids = Array.prototype.slice.call(document.getElementsByTagName('video'));
  10238. // var audios = Array.prototype.slice.call(document.getElementsByTagName('audio'));
  10239. // var mediaEls = vids.concat(audios);
  10240. // Because IE8 doesn't support calling slice on a node list, we need to loop through each list of elements
  10241. // to build up a new, combined list of elements.
  10242. var vids = _globalDocument2['default'].getElementsByTagName('video');
  10243. var audios = _globalDocument2['default'].getElementsByTagName('audio');
  10244. var mediaEls = [];
  10245. if (vids && vids.length > 0) {
  10246. for (var i = 0, e = vids.length; i < e; i++) {
  10247. mediaEls.push(vids[i]);
  10248. }
  10249. }
  10250. if (audios && audios.length > 0) {
  10251. for (var i = 0, e = audios.length; i < e; i++) {
  10252. mediaEls.push(audios[i]);
  10253. }
  10254. }
  10255. // Check if any media elements exist
  10256. if (mediaEls && mediaEls.length > 0) {
  10257. for (var i = 0, e = mediaEls.length; i < e; i++) {
  10258. var mediaEl = mediaEls[i];
  10259. // Check if element exists, has getAttribute func.
  10260. // IE seems to consider typeof el.getAttribute == 'object' instead of 'function' like expected, at least when loading the player immediately.
  10261. if (mediaEl && mediaEl.getAttribute) {
  10262. // Make sure this player hasn't already been set up.
  10263. if (mediaEl['player'] === undefined) {
  10264. var options = mediaEl.getAttribute('data-setup');
  10265. // Check if data-setup attr exists.
  10266. // We only auto-setup if they've added the data-setup attr.
  10267. if (options !== null) {
  10268. // Create new video.js instance.
  10269. var player = videojs(mediaEl);
  10270. }
  10271. }
  10272. // If getAttribute isn't defined, we need to wait for the DOM.
  10273. } else {
  10274. autoSetupTimeout(1);
  10275. break;
  10276. }
  10277. }
  10278. // No videos were found, so keep looping unless page is finished loading.
  10279. } else if (!_windowLoaded) {
  10280. autoSetupTimeout(1);
  10281. }
  10282. };
  10283. // Pause to let the DOM keep processing
  10284. var autoSetupTimeout = function autoSetupTimeout(wait, vjs) {
  10285. if (vjs) {
  10286. videojs = vjs;
  10287. }
  10288. setTimeout(autoSetup, wait);
  10289. };
  10290. if (_globalDocument2['default'].readyState === 'complete') {
  10291. _windowLoaded = true;
  10292. } else {
  10293. Events.one(_globalWindow2['default'], 'load', function () {
  10294. _windowLoaded = true;
  10295. });
  10296. }
  10297. var hasLoaded = function hasLoaded() {
  10298. return _windowLoaded;
  10299. };
  10300. exports.autoSetup = autoSetup;
  10301. exports.autoSetupTimeout = autoSetupTimeout;
  10302. exports.hasLoaded = hasLoaded;
  10303. },{"./utils/events.js":133,"global/document":1,"global/window":2}],114:[function(_dereq_,module,exports){
  10304. /**
  10305. * @file slider.js
  10306. */
  10307. 'use strict';
  10308. exports.__esModule = true;
  10309. 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; } }
  10310. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  10311. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  10312. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10313. var _componentJs = _dereq_('../component.js');
  10314. var _componentJs2 = _interopRequireDefault(_componentJs);
  10315. var _utilsDomJs = _dereq_('../utils/dom.js');
  10316. var Dom = _interopRequireWildcard(_utilsDomJs);
  10317. var _globalDocument = _dereq_('global/document');
  10318. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  10319. var _objectAssign = _dereq_('object.assign');
  10320. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  10321. /**
  10322. * The base functionality for sliders like the volume bar and seek bar
  10323. *
  10324. * @param {Player|Object} player
  10325. * @param {Object=} options
  10326. * @extends Component
  10327. * @class Slider
  10328. */
  10329. var Slider = (function (_Component) {
  10330. _inherits(Slider, _Component);
  10331. function Slider(player, options) {
  10332. _classCallCheck(this, Slider);
  10333. _Component.call(this, player, options);
  10334. // Set property names to bar to match with the child Slider class is looking for
  10335. this.bar = this.getChild(this.options_.barName);
  10336. // Set a horizontal or vertical class on the slider depending on the slider type
  10337. this.vertical(!!this.options_.vertical);
  10338. this.on('mousedown', this.handleMouseDown);
  10339. this.on('touchstart', this.handleMouseDown);
  10340. this.on('focus', this.handleFocus);
  10341. this.on('blur', this.handleBlur);
  10342. this.on('click', this.handleClick);
  10343. this.on(player, 'controlsvisible', this.update);
  10344. this.on(player, this.playerEvent, this.update);
  10345. }
  10346. /**
  10347. * Create the component's DOM element
  10348. *
  10349. * @param {String} type Type of element to create
  10350. * @param {Object=} props List of properties in Object form
  10351. * @return {Element}
  10352. * @method createEl
  10353. */
  10354. Slider.prototype.createEl = function createEl(type) {
  10355. var props = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  10356. var attributes = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  10357. // Add the slider element class to all sub classes
  10358. props.className = props.className + ' vjs-slider';
  10359. props = _objectAssign2['default']({
  10360. tabIndex: 0
  10361. }, props);
  10362. attributes = _objectAssign2['default']({
  10363. 'role': 'slider',
  10364. 'aria-valuenow': 0,
  10365. 'aria-valuemin': 0,
  10366. 'aria-valuemax': 100,
  10367. tabIndex: 0
  10368. }, attributes);
  10369. return _Component.prototype.createEl.call(this, type, props, attributes);
  10370. };
  10371. /**
  10372. * Handle mouse down on slider
  10373. *
  10374. * @param {Object} event Mouse down event object
  10375. * @method handleMouseDown
  10376. */
  10377. Slider.prototype.handleMouseDown = function handleMouseDown(event) {
  10378. event.preventDefault();
  10379. Dom.blockTextSelection();
  10380. this.addClass('vjs-sliding');
  10381. this.trigger('slideractive');
  10382. this.on(_globalDocument2['default'], 'mousemove', this.handleMouseMove);
  10383. this.on(_globalDocument2['default'], 'mouseup', this.handleMouseUp);
  10384. this.on(_globalDocument2['default'], 'touchmove', this.handleMouseMove);
  10385. this.on(_globalDocument2['default'], 'touchend', this.handleMouseUp);
  10386. this.handleMouseMove(event);
  10387. };
  10388. /**
  10389. * To be overridden by a subclass
  10390. *
  10391. * @method handleMouseMove
  10392. */
  10393. Slider.prototype.handleMouseMove = function handleMouseMove() {};
  10394. /**
  10395. * Handle mouse up on Slider
  10396. *
  10397. * @method handleMouseUp
  10398. */
  10399. Slider.prototype.handleMouseUp = function handleMouseUp() {
  10400. Dom.unblockTextSelection();
  10401. this.removeClass('vjs-sliding');
  10402. this.trigger('sliderinactive');
  10403. this.off(_globalDocument2['default'], 'mousemove', this.handleMouseMove);
  10404. this.off(_globalDocument2['default'], 'mouseup', this.handleMouseUp);
  10405. this.off(_globalDocument2['default'], 'touchmove', this.handleMouseMove);
  10406. this.off(_globalDocument2['default'], 'touchend', this.handleMouseUp);
  10407. this.update();
  10408. };
  10409. /**
  10410. * Update slider
  10411. *
  10412. * @method update
  10413. */
  10414. Slider.prototype.update = function update() {
  10415. // In VolumeBar init we have a setTimeout for update that pops and update to the end of the
  10416. // execution stack. The player is destroyed before then update will cause an error
  10417. if (!this.el_) return;
  10418. // If scrubbing, we could use a cached value to make the handle keep up with the user's mouse.
  10419. // On HTML5 browsers scrubbing is really smooth, but some flash players are slow, so we might want to utilize this later.
  10420. // var progress = (this.player_.scrubbing()) ? this.player_.getCache().currentTime / this.player_.duration() : this.player_.currentTime() / this.player_.duration();
  10421. var progress = this.getPercent();
  10422. var bar = this.bar;
  10423. // If there's no bar...
  10424. if (!bar) return;
  10425. // Protect against no duration and other division issues
  10426. if (typeof progress !== 'number' || progress !== progress || progress < 0 || progress === Infinity) {
  10427. progress = 0;
  10428. }
  10429. // Convert to a percentage for setting
  10430. var percentage = (progress * 100).toFixed(2) + '%';
  10431. // Set the new bar width or height
  10432. if (this.vertical()) {
  10433. bar.el().style.height = percentage;
  10434. } else {
  10435. bar.el().style.width = percentage;
  10436. }
  10437. };
  10438. /**
  10439. * Calculate distance for slider
  10440. *
  10441. * @param {Object} event Event object
  10442. * @method calculateDistance
  10443. */
  10444. Slider.prototype.calculateDistance = function calculateDistance(event) {
  10445. var position = Dom.getPointerPosition(this.el_, event);
  10446. if (this.vertical()) {
  10447. return position.y;
  10448. }
  10449. return position.x;
  10450. };
  10451. /**
  10452. * Handle on focus for slider
  10453. *
  10454. * @method handleFocus
  10455. */
  10456. Slider.prototype.handleFocus = function handleFocus() {
  10457. this.on(_globalDocument2['default'], 'keydown', this.handleKeyPress);
  10458. };
  10459. /**
  10460. * Handle key press for slider
  10461. *
  10462. * @param {Object} event Event object
  10463. * @method handleKeyPress
  10464. */
  10465. Slider.prototype.handleKeyPress = function handleKeyPress(event) {
  10466. if (event.which === 37 || event.which === 40) {
  10467. // Left and Down Arrows
  10468. event.preventDefault();
  10469. this.stepBack();
  10470. } else if (event.which === 38 || event.which === 39) {
  10471. // Up and Right Arrows
  10472. event.preventDefault();
  10473. this.stepForward();
  10474. }
  10475. };
  10476. /**
  10477. * Handle on blur for slider
  10478. *
  10479. * @method handleBlur
  10480. */
  10481. Slider.prototype.handleBlur = function handleBlur() {
  10482. this.off(_globalDocument2['default'], 'keydown', this.handleKeyPress);
  10483. };
  10484. /**
  10485. * Listener for click events on slider, used to prevent clicks
  10486. * from bubbling up to parent elements like button menus.
  10487. *
  10488. * @param {Object} event Event object
  10489. * @method handleClick
  10490. */
  10491. Slider.prototype.handleClick = function handleClick(event) {
  10492. event.stopImmediatePropagation();
  10493. event.preventDefault();
  10494. };
  10495. /**
  10496. * Get/set if slider is horizontal for vertical
  10497. *
  10498. * @param {Boolean} bool True if slider is vertical, false is horizontal
  10499. * @return {Boolean} True if slider is vertical, false is horizontal
  10500. * @method vertical
  10501. */
  10502. Slider.prototype.vertical = function vertical(bool) {
  10503. if (bool === undefined) {
  10504. return this.vertical_ || false;
  10505. }
  10506. this.vertical_ = !!bool;
  10507. if (this.vertical_) {
  10508. this.addClass('vjs-slider-vertical');
  10509. } else {
  10510. this.addClass('vjs-slider-horizontal');
  10511. }
  10512. return this;
  10513. };
  10514. return Slider;
  10515. })(_componentJs2['default']);
  10516. _componentJs2['default'].registerComponent('Slider', Slider);
  10517. exports['default'] = Slider;
  10518. module.exports = exports['default'];
  10519. },{"../component.js":67,"../utils/dom.js":132,"global/document":1,"object.assign":45}],115:[function(_dereq_,module,exports){
  10520. /**
  10521. * @file flash-rtmp.js
  10522. */
  10523. 'use strict';
  10524. exports.__esModule = true;
  10525. function FlashRtmpDecorator(Flash) {
  10526. Flash.streamingFormats = {
  10527. 'rtmp/mp4': 'MP4',
  10528. 'rtmp/flv': 'FLV'
  10529. };
  10530. Flash.streamFromParts = function (connection, stream) {
  10531. return connection + '&' + stream;
  10532. };
  10533. Flash.streamToParts = function (src) {
  10534. var parts = {
  10535. connection: '',
  10536. stream: ''
  10537. };
  10538. if (!src) return parts;
  10539. // Look for the normal URL separator we expect, '&'.
  10540. // If found, we split the URL into two pieces around the
  10541. // first '&'.
  10542. var connEnd = src.search(/&(?!\w+=)/);
  10543. var streamBegin = undefined;
  10544. if (connEnd !== -1) {
  10545. streamBegin = connEnd + 1;
  10546. } else {
  10547. // If there's not a '&', we use the last '/' as the delimiter.
  10548. connEnd = streamBegin = src.lastIndexOf('/') + 1;
  10549. if (connEnd === 0) {
  10550. // really, there's not a '/'?
  10551. connEnd = streamBegin = src.length;
  10552. }
  10553. }
  10554. parts.connection = src.substring(0, connEnd);
  10555. parts.stream = src.substring(streamBegin, src.length);
  10556. return parts;
  10557. };
  10558. Flash.isStreamingType = function (srcType) {
  10559. return srcType in Flash.streamingFormats;
  10560. };
  10561. // RTMP has four variations, any string starting
  10562. // with one of these protocols should be valid
  10563. Flash.RTMP_RE = /^rtmp[set]?:\/\//i;
  10564. Flash.isStreamingSrc = function (src) {
  10565. return Flash.RTMP_RE.test(src);
  10566. };
  10567. /**
  10568. * A source handler for RTMP urls
  10569. * @type {Object}
  10570. */
  10571. Flash.rtmpSourceHandler = {};
  10572. /**
  10573. * Check if Flash can play the given videotype
  10574. * @param {String} type The mimetype to check
  10575. * @return {String} 'probably', 'maybe', or '' (empty string)
  10576. */
  10577. Flash.rtmpSourceHandler.canPlayType = function (type) {
  10578. if (Flash.isStreamingType(type)) {
  10579. return 'maybe';
  10580. }
  10581. return '';
  10582. };
  10583. /**
  10584. * Check if Flash can handle the source natively
  10585. * @param {Object} source The source object
  10586. * @return {String} 'probably', 'maybe', or '' (empty string)
  10587. */
  10588. Flash.rtmpSourceHandler.canHandleSource = function (source) {
  10589. var can = Flash.rtmpSourceHandler.canPlayType(source.type);
  10590. if (can) {
  10591. return can;
  10592. }
  10593. if (Flash.isStreamingSrc(source.src)) {
  10594. return 'maybe';
  10595. }
  10596. return '';
  10597. };
  10598. /**
  10599. * Pass the source to the flash object
  10600. * Adaptive source handlers will have more complicated workflows before passing
  10601. * video data to the video element
  10602. * @param {Object} source The source object
  10603. * @param {Flash} tech The instance of the Flash tech
  10604. */
  10605. Flash.rtmpSourceHandler.handleSource = function (source, tech) {
  10606. var srcParts = Flash.streamToParts(source.src);
  10607. tech['setRtmpConnection'](srcParts.connection);
  10608. tech['setRtmpStream'](srcParts.stream);
  10609. };
  10610. // Register the native source handler
  10611. Flash.registerSourceHandler(Flash.rtmpSourceHandler);
  10612. return Flash;
  10613. }
  10614. exports['default'] = FlashRtmpDecorator;
  10615. module.exports = exports['default'];
  10616. },{}],116:[function(_dereq_,module,exports){
  10617. /**
  10618. * @file flash.js
  10619. * VideoJS-SWF - Custom Flash Player with HTML5-ish API
  10620. * https://github.com/zencoder/video-js-swf
  10621. * Not using setupTriggers. Using global onEvent func to distribute events
  10622. */
  10623. 'use strict';
  10624. exports.__esModule = true;
  10625. 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; } }
  10626. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  10627. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  10628. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  10629. var _tech = _dereq_('./tech');
  10630. var _tech2 = _interopRequireDefault(_tech);
  10631. var _utilsDomJs = _dereq_('../utils/dom.js');
  10632. var Dom = _interopRequireWildcard(_utilsDomJs);
  10633. var _utilsUrlJs = _dereq_('../utils/url.js');
  10634. var Url = _interopRequireWildcard(_utilsUrlJs);
  10635. var _utilsTimeRangesJs = _dereq_('../utils/time-ranges.js');
  10636. var _flashRtmp = _dereq_('./flash-rtmp');
  10637. var _flashRtmp2 = _interopRequireDefault(_flashRtmp);
  10638. var _component = _dereq_('../component');
  10639. var _component2 = _interopRequireDefault(_component);
  10640. var _globalWindow = _dereq_('global/window');
  10641. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  10642. var _objectAssign = _dereq_('object.assign');
  10643. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  10644. var navigator = _globalWindow2['default'].navigator;
  10645. /**
  10646. * Flash Media Controller - Wrapper for fallback SWF API
  10647. *
  10648. * @param {Object=} options Object of option names and values
  10649. * @param {Function=} ready Ready callback function
  10650. * @extends Tech
  10651. * @class Flash
  10652. */
  10653. var Flash = (function (_Tech) {
  10654. _inherits(Flash, _Tech);
  10655. function Flash(options, ready) {
  10656. _classCallCheck(this, Flash);
  10657. _Tech.call(this, options, ready);
  10658. // Set the source when ready
  10659. if (options.source) {
  10660. this.ready(function () {
  10661. this.setSource(options.source);
  10662. }, true);
  10663. }
  10664. // Having issues with Flash reloading on certain page actions (hide/resize/fullscreen) in certain browsers
  10665. // This allows resetting the playhead when we catch the reload
  10666. if (options.startTime) {
  10667. this.ready(function () {
  10668. this.load();
  10669. this.play();
  10670. this.currentTime(options.startTime);
  10671. }, true);
  10672. }
  10673. // Add global window functions that the swf expects
  10674. // A 4.x workflow we weren't able to solve for in 5.0
  10675. // because of the need to hard code these functions
  10676. // into the swf for security reasons
  10677. _globalWindow2['default'].videojs = _globalWindow2['default'].videojs || {};
  10678. _globalWindow2['default'].videojs.Flash = _globalWindow2['default'].videojs.Flash || {};
  10679. _globalWindow2['default'].videojs.Flash.onReady = Flash.onReady;
  10680. _globalWindow2['default'].videojs.Flash.onEvent = Flash.onEvent;
  10681. _globalWindow2['default'].videojs.Flash.onError = Flash.onError;
  10682. this.on('seeked', function () {
  10683. this.lastSeekTarget_ = undefined;
  10684. });
  10685. }
  10686. // Create setters and getters for attributes
  10687. /**
  10688. * Create the component's DOM element
  10689. *
  10690. * @return {Element}
  10691. * @method createEl
  10692. */
  10693. Flash.prototype.createEl = function createEl() {
  10694. var options = this.options_;
  10695. // If video.js is hosted locally you should also set the location
  10696. // for the hosted swf, which should be relative to the page (not video.js)
  10697. // Otherwise this adds a CDN url.
  10698. // The CDN also auto-adds a swf URL for that specific version.
  10699. if (!options.swf) {
  10700. options.swf = '//vjs.zencdn.net/swf/5.0.1/video-js.swf';
  10701. }
  10702. // Generate ID for swf object
  10703. var objId = options.techId;
  10704. // Merge default flashvars with ones passed in to init
  10705. var flashVars = _objectAssign2['default']({
  10706. // SWF Callback Functions
  10707. 'readyFunction': 'videojs.Flash.onReady',
  10708. 'eventProxyFunction': 'videojs.Flash.onEvent',
  10709. 'errorEventProxyFunction': 'videojs.Flash.onError',
  10710. // Player Settings
  10711. 'autoplay': options.autoplay,
  10712. 'preload': options.preload,
  10713. 'loop': options.loop,
  10714. 'muted': options.muted
  10715. }, options.flashVars);
  10716. // Merge default parames with ones passed in
  10717. var params = _objectAssign2['default']({
  10718. 'wmode': 'opaque', // Opaque is needed to overlay controls, but can affect playback performance
  10719. 'bgcolor': '#000000' // Using bgcolor prevents a white flash when the object is loading
  10720. }, options.params);
  10721. // Merge default attributes with ones passed in
  10722. var attributes = _objectAssign2['default']({
  10723. 'id': objId,
  10724. 'name': objId, // Both ID and Name needed or swf to identify itself
  10725. 'class': 'vjs-tech'
  10726. }, options.attributes);
  10727. this.el_ = Flash.embed(options.swf, flashVars, params, attributes);
  10728. this.el_.tech = this;
  10729. return this.el_;
  10730. };
  10731. /**
  10732. * Play for flash tech
  10733. *
  10734. * @method play
  10735. */
  10736. Flash.prototype.play = function play() {
  10737. if (this.ended()) {
  10738. this.setCurrentTime(0);
  10739. }
  10740. this.el_.vjs_play();
  10741. };
  10742. /**
  10743. * Pause for flash tech
  10744. *
  10745. * @method pause
  10746. */
  10747. Flash.prototype.pause = function pause() {
  10748. this.el_.vjs_pause();
  10749. };
  10750. /**
  10751. * Get/set video
  10752. *
  10753. * @param {Object=} src Source object
  10754. * @return {Object}
  10755. * @method src
  10756. */
  10757. Flash.prototype.src = function src(_src) {
  10758. if (_src === undefined) {
  10759. return this.currentSrc();
  10760. }
  10761. // Setting src through `src` not `setSrc` will be deprecated
  10762. return this.setSrc(_src);
  10763. };
  10764. /**
  10765. * Set video
  10766. *
  10767. * @param {Object=} src Source object
  10768. * @deprecated
  10769. * @method setSrc
  10770. */
  10771. Flash.prototype.setSrc = function setSrc(src) {
  10772. // Make sure source URL is absolute.
  10773. src = Url.getAbsoluteURL(src);
  10774. this.el_.vjs_src(src);
  10775. // Currently the SWF doesn't autoplay if you load a source later.
  10776. // e.g. Load player w/ no source, wait 2s, set src.
  10777. if (this.autoplay()) {
  10778. var tech = this;
  10779. this.setTimeout(function () {
  10780. tech.play();
  10781. }, 0);
  10782. }
  10783. };
  10784. /**
  10785. * Returns true if the tech is currently seeking.
  10786. * @return {boolean} true if seeking
  10787. */
  10788. Flash.prototype.seeking = function seeking() {
  10789. return this.lastSeekTarget_ !== undefined;
  10790. };
  10791. /**
  10792. * Set current time
  10793. *
  10794. * @param {Number} time Current time of video
  10795. * @method setCurrentTime
  10796. */
  10797. Flash.prototype.setCurrentTime = function setCurrentTime(time) {
  10798. var seekable = this.seekable();
  10799. if (seekable.length) {
  10800. // clamp to the current seekable range
  10801. time = time > seekable.start(0) ? time : seekable.start(0);
  10802. time = time < seekable.end(seekable.length - 1) ? time : seekable.end(seekable.length - 1);
  10803. this.lastSeekTarget_ = time;
  10804. this.trigger('seeking');
  10805. this.el_.vjs_setProperty('currentTime', time);
  10806. _Tech.prototype.setCurrentTime.call(this);
  10807. }
  10808. };
  10809. /**
  10810. * Get current time
  10811. *
  10812. * @param {Number=} time Current time of video
  10813. * @return {Number} Current time
  10814. * @method currentTime
  10815. */
  10816. Flash.prototype.currentTime = function currentTime(time) {
  10817. // when seeking make the reported time keep up with the requested time
  10818. // by reading the time we're seeking to
  10819. if (this.seeking()) {
  10820. return this.lastSeekTarget_ || 0;
  10821. }
  10822. return this.el_.vjs_getProperty('currentTime');
  10823. };
  10824. /**
  10825. * Get current source
  10826. *
  10827. * @method currentSrc
  10828. */
  10829. Flash.prototype.currentSrc = function currentSrc() {
  10830. if (this.currentSource_) {
  10831. return this.currentSource_.src;
  10832. } else {
  10833. return this.el_.vjs_getProperty('currentSrc');
  10834. }
  10835. };
  10836. /**
  10837. * Load media into player
  10838. *
  10839. * @method load
  10840. */
  10841. Flash.prototype.load = function load() {
  10842. this.el_.vjs_load();
  10843. };
  10844. /**
  10845. * Get poster
  10846. *
  10847. * @method poster
  10848. */
  10849. Flash.prototype.poster = function poster() {
  10850. this.el_.vjs_getProperty('poster');
  10851. };
  10852. /**
  10853. * Poster images are not handled by the Flash tech so make this a no-op
  10854. *
  10855. * @method setPoster
  10856. */
  10857. Flash.prototype.setPoster = function setPoster() {};
  10858. /**
  10859. * Determine if can seek in media
  10860. *
  10861. * @return {TimeRangeObject}
  10862. * @method seekable
  10863. */
  10864. Flash.prototype.seekable = function seekable() {
  10865. var duration = this.duration();
  10866. if (duration === 0) {
  10867. return _utilsTimeRangesJs.createTimeRange();
  10868. }
  10869. return _utilsTimeRangesJs.createTimeRange(0, duration);
  10870. };
  10871. /**
  10872. * Get buffered time range
  10873. *
  10874. * @return {TimeRangeObject}
  10875. * @method buffered
  10876. */
  10877. Flash.prototype.buffered = function buffered() {
  10878. var ranges = this.el_.vjs_getProperty('buffered');
  10879. if (ranges.length === 0) {
  10880. return _utilsTimeRangesJs.createTimeRange();
  10881. }
  10882. return _utilsTimeRangesJs.createTimeRange(ranges[0][0], ranges[0][1]);
  10883. };
  10884. /**
  10885. * Get fullscreen support -
  10886. * Flash does not allow fullscreen through javascript
  10887. * so always returns false
  10888. *
  10889. * @return {Boolean} false
  10890. * @method supportsFullScreen
  10891. */
  10892. Flash.prototype.supportsFullScreen = function supportsFullScreen() {
  10893. return false; // Flash does not allow fullscreen through javascript
  10894. };
  10895. /**
  10896. * Request to enter fullscreen
  10897. * Flash does not allow fullscreen through javascript
  10898. * so always returns false
  10899. *
  10900. * @return {Boolean} false
  10901. * @method enterFullScreen
  10902. */
  10903. Flash.prototype.enterFullScreen = function enterFullScreen() {
  10904. return false;
  10905. };
  10906. return Flash;
  10907. })(_tech2['default']);
  10908. var _api = Flash.prototype;
  10909. var _readWrite = 'rtmpConnection,rtmpStream,preload,defaultPlaybackRate,playbackRate,autoplay,loop,mediaGroup,controller,controls,volume,muted,defaultMuted'.split(',');
  10910. var _readOnly = 'networkState,readyState,initialTime,duration,startOffsetTime,paused,ended,videoTracks,audioTracks,videoWidth,videoHeight'.split(',');
  10911. function _createSetter(attr) {
  10912. var attrUpper = attr.charAt(0).toUpperCase() + attr.slice(1);
  10913. _api['set' + attrUpper] = function (val) {
  10914. return this.el_.vjs_setProperty(attr, val);
  10915. };
  10916. }
  10917. function _createGetter(attr) {
  10918. _api[attr] = function () {
  10919. return this.el_.vjs_getProperty(attr);
  10920. };
  10921. }
  10922. // Create getter and setters for all read/write attributes
  10923. for (var i = 0; i < _readWrite.length; i++) {
  10924. _createGetter(_readWrite[i]);
  10925. _createSetter(_readWrite[i]);
  10926. }
  10927. // Create getters for read-only attributes
  10928. for (var i = 0; i < _readOnly.length; i++) {
  10929. _createGetter(_readOnly[i]);
  10930. }
  10931. /* Flash Support Testing -------------------------------------------------------- */
  10932. Flash.isSupported = function () {
  10933. return Flash.version()[0] >= 10;
  10934. // return swfobject.hasFlashPlayerVersion('10');
  10935. };
  10936. // Add Source Handler pattern functions to this tech
  10937. _tech2['default'].withSourceHandlers(Flash);
  10938. /*
  10939. * The default native source handler.
  10940. * This simply passes the source to the video element. Nothing fancy.
  10941. *
  10942. * @param {Object} source The source object
  10943. * @param {Flash} tech The instance of the Flash tech
  10944. */
  10945. Flash.nativeSourceHandler = {};
  10946. /**
  10947. * Check if Flash can play the given videotype
  10948. * @param {String} type The mimetype to check
  10949. * @return {String} 'probably', 'maybe', or '' (empty string)
  10950. */
  10951. Flash.nativeSourceHandler.canPlayType = function (type) {
  10952. if (type in Flash.formats) {
  10953. return 'maybe';
  10954. }
  10955. return '';
  10956. };
  10957. /*
  10958. * Check Flash can handle the source natively
  10959. *
  10960. * @param {Object} source The source object
  10961. * @return {String} 'probably', 'maybe', or '' (empty string)
  10962. */
  10963. Flash.nativeSourceHandler.canHandleSource = function (source) {
  10964. var type;
  10965. function guessMimeType(src) {
  10966. var ext = Url.getFileExtension(src);
  10967. if (ext) {
  10968. return 'video/' + ext;
  10969. }
  10970. return '';
  10971. }
  10972. if (!source.type) {
  10973. type = guessMimeType(source.src);
  10974. } else {
  10975. // Strip code information from the type because we don't get that specific
  10976. type = source.type.replace(/;.*/, '').toLowerCase();
  10977. }
  10978. return Flash.nativeSourceHandler.canPlayType(type);
  10979. };
  10980. /*
  10981. * Pass the source to the flash object
  10982. * Adaptive source handlers will have more complicated workflows before passing
  10983. * video data to the video element
  10984. *
  10985. * @param {Object} source The source object
  10986. * @param {Flash} tech The instance of the Flash tech
  10987. */
  10988. Flash.nativeSourceHandler.handleSource = function (source, tech) {
  10989. tech.setSrc(source.src);
  10990. };
  10991. /*
  10992. * Clean up the source handler when disposing the player or switching sources..
  10993. * (no cleanup is needed when supporting the format natively)
  10994. */
  10995. Flash.nativeSourceHandler.dispose = function () {};
  10996. // Register the native source handler
  10997. Flash.registerSourceHandler(Flash.nativeSourceHandler);
  10998. Flash.formats = {
  10999. 'video/flv': 'FLV',
  11000. 'video/x-flv': 'FLV',
  11001. 'video/mp4': 'MP4',
  11002. 'video/m4v': 'MP4'
  11003. };
  11004. Flash.onReady = function (currSwf) {
  11005. var el = Dom.getEl(currSwf);
  11006. var tech = el && el.tech;
  11007. // if there is no el then the tech has been disposed
  11008. // and the tech element was removed from the player div
  11009. if (tech && tech.el()) {
  11010. // check that the flash object is really ready
  11011. Flash.checkReady(tech);
  11012. }
  11013. };
  11014. // The SWF isn't always ready when it says it is. Sometimes the API functions still need to be added to the object.
  11015. // If it's not ready, we set a timeout to check again shortly.
  11016. Flash.checkReady = function (tech) {
  11017. // stop worrying if the tech has been disposed
  11018. if (!tech.el()) {
  11019. return;
  11020. }
  11021. // check if API property exists
  11022. if (tech.el().vjs_getProperty) {
  11023. // tell tech it's ready
  11024. tech.triggerReady();
  11025. } else {
  11026. // wait longer
  11027. this.setTimeout(function () {
  11028. Flash['checkReady'](tech);
  11029. }, 50);
  11030. }
  11031. };
  11032. // Trigger events from the swf on the player
  11033. Flash.onEvent = function (swfID, eventName) {
  11034. var tech = Dom.getEl(swfID).tech;
  11035. tech.trigger(eventName);
  11036. };
  11037. // Log errors from the swf
  11038. Flash.onError = function (swfID, err) {
  11039. var tech = Dom.getEl(swfID).tech;
  11040. // trigger MEDIA_ERR_SRC_NOT_SUPPORTED
  11041. if (err === 'srcnotfound') {
  11042. return tech.error(4);
  11043. }
  11044. // trigger a custom error
  11045. tech.error('FLASH: ' + err);
  11046. };
  11047. // Flash Version Check
  11048. Flash.version = function () {
  11049. var version = '0,0,0';
  11050. // IE
  11051. try {
  11052. version = new _globalWindow2['default'].ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
  11053. // other browsers
  11054. } catch (e) {
  11055. try {
  11056. if (navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
  11057. version = (navigator.plugins['Shockwave Flash 2.0'] || navigator.plugins['Shockwave Flash']).description.replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
  11058. }
  11059. } catch (err) {}
  11060. }
  11061. return version.split(',');
  11062. };
  11063. // Flash embedding method. Only used in non-iframe mode
  11064. Flash.embed = function (swf, flashVars, params, attributes) {
  11065. var code = Flash.getEmbedCode(swf, flashVars, params, attributes);
  11066. // Get element by embedding code and retrieving created element
  11067. var obj = Dom.createEl('div', { innerHTML: code }).childNodes[0];
  11068. return obj;
  11069. };
  11070. Flash.getEmbedCode = function (swf, flashVars, params, attributes) {
  11071. var objTag = '<object type="application/x-shockwave-flash" ';
  11072. var flashVarsString = '';
  11073. var paramsString = '';
  11074. var attrsString = '';
  11075. // Convert flash vars to string
  11076. if (flashVars) {
  11077. Object.getOwnPropertyNames(flashVars).forEach(function (key) {
  11078. flashVarsString += key + '=' + flashVars[key] + '&amp;';
  11079. });
  11080. }
  11081. // Add swf, flashVars, and other default params
  11082. params = _objectAssign2['default']({
  11083. 'movie': swf,
  11084. 'flashvars': flashVarsString,
  11085. 'allowScriptAccess': 'always', // Required to talk to swf
  11086. 'allowNetworking': 'all' // All should be default, but having security issues.
  11087. }, params);
  11088. // Create param tags string
  11089. Object.getOwnPropertyNames(params).forEach(function (key) {
  11090. paramsString += '<param name="' + key + '" value="' + params[key] + '" />';
  11091. });
  11092. attributes = _objectAssign2['default']({
  11093. // Add swf to attributes (need both for IE and Others to work)
  11094. 'data': swf,
  11095. // Default to 100% width/height
  11096. 'width': '100%',
  11097. 'height': '100%'
  11098. }, attributes);
  11099. // Create Attributes string
  11100. Object.getOwnPropertyNames(attributes).forEach(function (key) {
  11101. attrsString += key + '="' + attributes[key] + '" ';
  11102. });
  11103. return '' + objTag + attrsString + '>' + paramsString + '</object>';
  11104. };
  11105. // Run Flash through the RTMP decorator
  11106. _flashRtmp2['default'](Flash);
  11107. _component2['default'].registerComponent('Flash', Flash);
  11108. _tech2['default'].registerTech('Flash', Flash);
  11109. exports['default'] = Flash;
  11110. module.exports = exports['default'];
  11111. },{"../component":67,"../utils/dom.js":132,"../utils/time-ranges.js":140,"../utils/url.js":142,"./flash-rtmp":115,"./tech":119,"global/window":2,"object.assign":45}],117:[function(_dereq_,module,exports){
  11112. /**
  11113. * @file html5.js
  11114. * HTML5 Media Controller - Wrapper for HTML5 Media API
  11115. */
  11116. 'use strict';
  11117. exports.__esModule = true;
  11118. 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; } }
  11119. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  11120. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  11121. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  11122. var _techJs = _dereq_('./tech.js');
  11123. var _techJs2 = _interopRequireDefault(_techJs);
  11124. var _component = _dereq_('../component');
  11125. var _component2 = _interopRequireDefault(_component);
  11126. var _utilsDomJs = _dereq_('../utils/dom.js');
  11127. var Dom = _interopRequireWildcard(_utilsDomJs);
  11128. var _utilsUrlJs = _dereq_('../utils/url.js');
  11129. var Url = _interopRequireWildcard(_utilsUrlJs);
  11130. var _utilsFnJs = _dereq_('../utils/fn.js');
  11131. var Fn = _interopRequireWildcard(_utilsFnJs);
  11132. var _utilsLogJs = _dereq_('../utils/log.js');
  11133. var _utilsLogJs2 = _interopRequireDefault(_utilsLogJs);
  11134. var _utilsBrowserJs = _dereq_('../utils/browser.js');
  11135. var browser = _interopRequireWildcard(_utilsBrowserJs);
  11136. var _globalDocument = _dereq_('global/document');
  11137. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  11138. var _globalWindow = _dereq_('global/window');
  11139. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  11140. var _objectAssign = _dereq_('object.assign');
  11141. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  11142. var _utilsMergeOptionsJs = _dereq_('../utils/merge-options.js');
  11143. var _utilsMergeOptionsJs2 = _interopRequireDefault(_utilsMergeOptionsJs);
  11144. /**
  11145. * HTML5 Media Controller - Wrapper for HTML5 Media API
  11146. *
  11147. * @param {Object=} options Object of option names and values
  11148. * @param {Function=} ready Ready callback function
  11149. * @extends Tech
  11150. * @class Html5
  11151. */
  11152. var Html5 = (function (_Tech) {
  11153. _inherits(Html5, _Tech);
  11154. function Html5(options, ready) {
  11155. _classCallCheck(this, Html5);
  11156. _Tech.call(this, options, ready);
  11157. var source = options.source;
  11158. // Set the source if one is provided
  11159. // 1) Check if the source is new (if not, we want to keep the original so playback isn't interrupted)
  11160. // 2) Check to see if the network state of the tag was failed at init, and if so, reset the source
  11161. // anyway so the error gets fired.
  11162. if (source && (this.el_.currentSrc !== source.src || options.tag && options.tag.initNetworkState_ === 3)) {
  11163. this.setSource(source);
  11164. } else {
  11165. this.handleLateInit_(this.el_);
  11166. }
  11167. if (this.el_.hasChildNodes()) {
  11168. var nodes = this.el_.childNodes;
  11169. var nodesLength = nodes.length;
  11170. var removeNodes = [];
  11171. while (nodesLength--) {
  11172. var node = nodes[nodesLength];
  11173. var nodeName = node.nodeName.toLowerCase();
  11174. if (nodeName === 'track') {
  11175. if (!this.featuresNativeTextTracks) {
  11176. // Empty video tag tracks so the built-in player doesn't use them also.
  11177. // This may not be fast enough to stop HTML5 browsers from reading the tags
  11178. // so we'll need to turn off any default tracks if we're manually doing
  11179. // captions and subtitles. videoElement.textTracks
  11180. removeNodes.push(node);
  11181. } else {
  11182. // store HTMLTrackElement and TextTrack to remote list
  11183. this.remoteTextTrackEls().addTrackElement_(node);
  11184. this.remoteTextTracks().addTrack_(node.track);
  11185. }
  11186. }
  11187. }
  11188. for (var i = 0; i < removeNodes.length; i++) {
  11189. this.el_.removeChild(removeNodes[i]);
  11190. }
  11191. }
  11192. if (this.featuresNativeTextTracks) {
  11193. this.handleTextTrackChange_ = Fn.bind(this, this.handleTextTrackChange);
  11194. this.handleTextTrackAdd_ = Fn.bind(this, this.handleTextTrackAdd);
  11195. this.handleTextTrackRemove_ = Fn.bind(this, this.handleTextTrackRemove);
  11196. this.proxyNativeTextTracks_();
  11197. }
  11198. // Determine if native controls should be used
  11199. // Our goal should be to get the custom controls on mobile solid everywhere
  11200. // so we can remove this all together. Right now this will block custom
  11201. // controls on touch enabled laptops like the Chrome Pixel
  11202. if (browser.TOUCH_ENABLED && options.nativeControlsForTouch === true || browser.IS_IPHONE || browser.IS_NATIVE_ANDROID) {
  11203. this.setControls(true);
  11204. }
  11205. this.triggerReady();
  11206. }
  11207. /* HTML5 Support Testing ---------------------------------------------------- */
  11208. /*
  11209. * Element for testing browser HTML5 video capabilities
  11210. *
  11211. * @type {Element}
  11212. * @constant
  11213. * @private
  11214. */
  11215. /**
  11216. * Dispose of html5 media element
  11217. *
  11218. * @method dispose
  11219. */
  11220. Html5.prototype.dispose = function dispose() {
  11221. var tt = this.el().textTracks;
  11222. var emulatedTt = this.textTracks();
  11223. // remove native event listeners
  11224. if (tt && tt.removeEventListener) {
  11225. tt.removeEventListener('change', this.handleTextTrackChange_);
  11226. tt.removeEventListener('addtrack', this.handleTextTrackAdd_);
  11227. tt.removeEventListener('removetrack', this.handleTextTrackRemove_);
  11228. }
  11229. // clearout the emulated text track list.
  11230. var i = emulatedTt.length;
  11231. while (i--) {
  11232. emulatedTt.removeTrack_(emulatedTt[i]);
  11233. }
  11234. Html5.disposeMediaElement(this.el_);
  11235. _Tech.prototype.dispose.call(this);
  11236. };
  11237. /**
  11238. * Create the component's DOM element
  11239. *
  11240. * @return {Element}
  11241. * @method createEl
  11242. */
  11243. Html5.prototype.createEl = function createEl() {
  11244. var el = this.options_.tag;
  11245. // Check if this browser supports moving the element into the box.
  11246. // On the iPhone video will break if you move the element,
  11247. // So we have to create a brand new element.
  11248. if (!el || this['movingMediaElementInDOM'] === false) {
  11249. // If the original tag is still there, clone and remove it.
  11250. if (el) {
  11251. var clone = el.cloneNode(true);
  11252. el.parentNode.insertBefore(clone, el);
  11253. Html5.disposeMediaElement(el);
  11254. el = clone;
  11255. } else {
  11256. el = _globalDocument2['default'].createElement('video');
  11257. // determine if native controls should be used
  11258. var tagAttributes = this.options_.tag && Dom.getElAttributes(this.options_.tag);
  11259. var attributes = _utilsMergeOptionsJs2['default']({}, tagAttributes);
  11260. if (!browser.TOUCH_ENABLED || this.options_.nativeControlsForTouch !== true) {
  11261. delete attributes.controls;
  11262. }
  11263. Dom.setElAttributes(el, _objectAssign2['default'](attributes, {
  11264. id: this.options_.techId,
  11265. 'class': 'vjs-tech'
  11266. }));
  11267. }
  11268. }
  11269. // Update specific tag settings, in case they were overridden
  11270. var settingsAttrs = ['autoplay', 'preload', 'loop', 'muted'];
  11271. for (var i = settingsAttrs.length - 1; i >= 0; i--) {
  11272. var attr = settingsAttrs[i];
  11273. var overwriteAttrs = {};
  11274. if (typeof this.options_[attr] !== 'undefined') {
  11275. overwriteAttrs[attr] = this.options_[attr];
  11276. }
  11277. Dom.setElAttributes(el, overwriteAttrs);
  11278. }
  11279. return el;
  11280. // jenniisawesome = true;
  11281. };
  11282. // If we're loading the playback object after it has started loading
  11283. // or playing the video (often with autoplay on) then the loadstart event
  11284. // has already fired and we need to fire it manually because many things
  11285. // rely on it.
  11286. Html5.prototype.handleLateInit_ = function handleLateInit_(el) {
  11287. var _this = this;
  11288. if (el.networkState === 0 || el.networkState === 3) {
  11289. // The video element hasn't started loading the source yet
  11290. // or didn't find a source
  11291. return;
  11292. }
  11293. if (el.readyState === 0) {
  11294. var _ret = (function () {
  11295. // NetworkState is set synchronously BUT loadstart is fired at the
  11296. // end of the current stack, usually before setInterval(fn, 0).
  11297. // So at this point we know loadstart may have already fired or is
  11298. // about to fire, and either way the player hasn't seen it yet.
  11299. // We don't want to fire loadstart prematurely here and cause a
  11300. // double loadstart so we'll wait and see if it happens between now
  11301. // and the next loop, and fire it if not.
  11302. // HOWEVER, we also want to make sure it fires before loadedmetadata
  11303. // which could also happen between now and the next loop, so we'll
  11304. // watch for that also.
  11305. var loadstartFired = false;
  11306. var setLoadstartFired = function setLoadstartFired() {
  11307. loadstartFired = true;
  11308. };
  11309. _this.on('loadstart', setLoadstartFired);
  11310. var triggerLoadstart = function triggerLoadstart() {
  11311. // We did miss the original loadstart. Make sure the player
  11312. // sees loadstart before loadedmetadata
  11313. if (!loadstartFired) {
  11314. this.trigger('loadstart');
  11315. }
  11316. };
  11317. _this.on('loadedmetadata', triggerLoadstart);
  11318. _this.ready(function () {
  11319. this.off('loadstart', setLoadstartFired);
  11320. this.off('loadedmetadata', triggerLoadstart);
  11321. if (!loadstartFired) {
  11322. // We did miss the original native loadstart. Fire it now.
  11323. this.trigger('loadstart');
  11324. }
  11325. });
  11326. return {
  11327. v: undefined
  11328. };
  11329. })();
  11330. if (typeof _ret === 'object') return _ret.v;
  11331. }
  11332. // From here on we know that loadstart already fired and we missed it.
  11333. // The other readyState events aren't as much of a problem if we double
  11334. // them, so not going to go to as much trouble as loadstart to prevent
  11335. // that unless we find reason to.
  11336. var eventsToTrigger = ['loadstart'];
  11337. // loadedmetadata: newly equal to HAVE_METADATA (1) or greater
  11338. eventsToTrigger.push('loadedmetadata');
  11339. // loadeddata: newly increased to HAVE_CURRENT_DATA (2) or greater
  11340. if (el.readyState >= 2) {
  11341. eventsToTrigger.push('loadeddata');
  11342. }
  11343. // canplay: newly increased to HAVE_FUTURE_DATA (3) or greater
  11344. if (el.readyState >= 3) {
  11345. eventsToTrigger.push('canplay');
  11346. }
  11347. // canplaythrough: newly equal to HAVE_ENOUGH_DATA (4)
  11348. if (el.readyState >= 4) {
  11349. eventsToTrigger.push('canplaythrough');
  11350. }
  11351. // We still need to give the player time to add event listeners
  11352. this.ready(function () {
  11353. eventsToTrigger.forEach(function (type) {
  11354. this.trigger(type);
  11355. }, this);
  11356. });
  11357. };
  11358. Html5.prototype.proxyNativeTextTracks_ = function proxyNativeTextTracks_() {
  11359. var tt = this.el().textTracks;
  11360. if (tt) {
  11361. // Add tracks - if player is initialised after DOM loaded, textTracks
  11362. // will not trigger addtrack
  11363. for (var i = 0; i < tt.length; i++) {
  11364. this.textTracks().addTrack_(tt[i]);
  11365. }
  11366. if (tt.addEventListener) {
  11367. tt.addEventListener('change', this.handleTextTrackChange_);
  11368. tt.addEventListener('addtrack', this.handleTextTrackAdd_);
  11369. tt.addEventListener('removetrack', this.handleTextTrackRemove_);
  11370. }
  11371. }
  11372. };
  11373. Html5.prototype.handleTextTrackChange = function handleTextTrackChange(e) {
  11374. var tt = this.textTracks();
  11375. this.textTracks().trigger({
  11376. type: 'change',
  11377. target: tt,
  11378. currentTarget: tt,
  11379. srcElement: tt
  11380. });
  11381. };
  11382. Html5.prototype.handleTextTrackAdd = function handleTextTrackAdd(e) {
  11383. this.textTracks().addTrack_(e.track);
  11384. };
  11385. Html5.prototype.handleTextTrackRemove = function handleTextTrackRemove(e) {
  11386. this.textTracks().removeTrack_(e.track);
  11387. };
  11388. /**
  11389. * Play for html5 tech
  11390. *
  11391. * @method play
  11392. */
  11393. Html5.prototype.play = function play() {
  11394. this.el_.play();
  11395. };
  11396. /**
  11397. * Pause for html5 tech
  11398. *
  11399. * @method pause
  11400. */
  11401. Html5.prototype.pause = function pause() {
  11402. this.el_.pause();
  11403. };
  11404. /**
  11405. * Paused for html5 tech
  11406. *
  11407. * @return {Boolean}
  11408. * @method paused
  11409. */
  11410. Html5.prototype.paused = function paused() {
  11411. return this.el_.paused;
  11412. };
  11413. /**
  11414. * Get current time
  11415. *
  11416. * @return {Number}
  11417. * @method currentTime
  11418. */
  11419. Html5.prototype.currentTime = function currentTime() {
  11420. return this.el_.currentTime;
  11421. };
  11422. /**
  11423. * Set current time
  11424. *
  11425. * @param {Number} seconds Current time of video
  11426. * @method setCurrentTime
  11427. */
  11428. Html5.prototype.setCurrentTime = function setCurrentTime(seconds) {
  11429. try {
  11430. this.el_.currentTime = seconds;
  11431. } catch (e) {
  11432. _utilsLogJs2['default'](e, 'Video is not ready. (Video.js)');
  11433. // this.warning(VideoJS.warnings.videoNotReady);
  11434. }
  11435. };
  11436. /**
  11437. * Get duration
  11438. *
  11439. * @return {Number}
  11440. * @method duration
  11441. */
  11442. Html5.prototype.duration = function duration() {
  11443. return this.el_.duration || 0;
  11444. };
  11445. /**
  11446. * Get a TimeRange object that represents the intersection
  11447. * of the time ranges for which the user agent has all
  11448. * relevant media
  11449. *
  11450. * @return {TimeRangeObject}
  11451. * @method buffered
  11452. */
  11453. Html5.prototype.buffered = function buffered() {
  11454. return this.el_.buffered;
  11455. };
  11456. /**
  11457. * Get volume level
  11458. *
  11459. * @return {Number}
  11460. * @method volume
  11461. */
  11462. Html5.prototype.volume = function volume() {
  11463. return this.el_.volume;
  11464. };
  11465. /**
  11466. * Set volume level
  11467. *
  11468. * @param {Number} percentAsDecimal Volume percent as a decimal
  11469. * @method setVolume
  11470. */
  11471. Html5.prototype.setVolume = function setVolume(percentAsDecimal) {
  11472. this.el_.volume = percentAsDecimal;
  11473. };
  11474. /**
  11475. * Get if muted
  11476. *
  11477. * @return {Boolean}
  11478. * @method muted
  11479. */
  11480. Html5.prototype.muted = function muted() {
  11481. return this.el_.muted;
  11482. };
  11483. /**
  11484. * Set muted
  11485. *
  11486. * @param {Boolean} If player is to be muted or note
  11487. * @method setMuted
  11488. */
  11489. Html5.prototype.setMuted = function setMuted(muted) {
  11490. this.el_.muted = muted;
  11491. };
  11492. /**
  11493. * Get player width
  11494. *
  11495. * @return {Number}
  11496. * @method width
  11497. */
  11498. Html5.prototype.width = function width() {
  11499. return this.el_.offsetWidth;
  11500. };
  11501. /**
  11502. * Get player height
  11503. *
  11504. * @return {Number}
  11505. * @method height
  11506. */
  11507. Html5.prototype.height = function height() {
  11508. return this.el_.offsetHeight;
  11509. };
  11510. /**
  11511. * Get if there is fullscreen support
  11512. *
  11513. * @return {Boolean}
  11514. * @method supportsFullScreen
  11515. */
  11516. Html5.prototype.supportsFullScreen = function supportsFullScreen() {
  11517. if (typeof this.el_.webkitEnterFullScreen === 'function') {
  11518. var userAgent = _globalWindow2['default'].navigator.userAgent;
  11519. // Seems to be broken in Chromium/Chrome && Safari in Leopard
  11520. if (/Android/.test(userAgent) || !/Chrome|Mac OS X 10.5/.test(userAgent)) {
  11521. return true;
  11522. }
  11523. }
  11524. return false;
  11525. };
  11526. /**
  11527. * Request to enter fullscreen
  11528. *
  11529. * @method enterFullScreen
  11530. */
  11531. Html5.prototype.enterFullScreen = function enterFullScreen() {
  11532. var video = this.el_;
  11533. if ('webkitDisplayingFullscreen' in video) {
  11534. this.one('webkitbeginfullscreen', function () {
  11535. this.one('webkitendfullscreen', function () {
  11536. this.trigger('fullscreenchange', { isFullscreen: false });
  11537. });
  11538. this.trigger('fullscreenchange', { isFullscreen: true });
  11539. });
  11540. }
  11541. if (video.paused && video.networkState <= video.HAVE_METADATA) {
  11542. // attempt to prime the video element for programmatic access
  11543. // this isn't necessary on the desktop but shouldn't hurt
  11544. this.el_.play();
  11545. // playing and pausing synchronously during the transition to fullscreen
  11546. // can get iOS ~6.1 devices into a play/pause loop
  11547. this.setTimeout(function () {
  11548. video.pause();
  11549. video.webkitEnterFullScreen();
  11550. }, 0);
  11551. } else {
  11552. video.webkitEnterFullScreen();
  11553. }
  11554. };
  11555. /**
  11556. * Request to exit fullscreen
  11557. *
  11558. * @method exitFullScreen
  11559. */
  11560. Html5.prototype.exitFullScreen = function exitFullScreen() {
  11561. this.el_.webkitExitFullScreen();
  11562. };
  11563. /**
  11564. * Get/set video
  11565. *
  11566. * @param {Object=} src Source object
  11567. * @return {Object}
  11568. * @method src
  11569. */
  11570. Html5.prototype.src = function src(_src) {
  11571. if (_src === undefined) {
  11572. return this.el_.src;
  11573. } else {
  11574. // Setting src through `src` instead of `setSrc` will be deprecated
  11575. this.setSrc(_src);
  11576. }
  11577. };
  11578. /**
  11579. * Set video
  11580. *
  11581. * @param {Object} src Source object
  11582. * @deprecated
  11583. * @method setSrc
  11584. */
  11585. Html5.prototype.setSrc = function setSrc(src) {
  11586. this.el_.src = src;
  11587. };
  11588. /**
  11589. * Load media into player
  11590. *
  11591. * @method load
  11592. */
  11593. Html5.prototype.load = function load() {
  11594. this.el_.load();
  11595. };
  11596. /**
  11597. * Reset the tech. Removes all sources and calls `load`.
  11598. *
  11599. * @method reset
  11600. */
  11601. Html5.prototype.reset = function reset() {
  11602. Html5.resetMediaElement(this.el_);
  11603. };
  11604. /**
  11605. * Get current source
  11606. *
  11607. * @return {Object}
  11608. * @method currentSrc
  11609. */
  11610. Html5.prototype.currentSrc = function currentSrc() {
  11611. if (this.currentSource_) {
  11612. return this.currentSource_.src;
  11613. } else {
  11614. return this.el_.currentSrc;
  11615. }
  11616. };
  11617. /**
  11618. * Get poster
  11619. *
  11620. * @return {String}
  11621. * @method poster
  11622. */
  11623. Html5.prototype.poster = function poster() {
  11624. return this.el_.poster;
  11625. };
  11626. /**
  11627. * Set poster
  11628. *
  11629. * @param {String} val URL to poster image
  11630. * @method
  11631. */
  11632. Html5.prototype.setPoster = function setPoster(val) {
  11633. this.el_.poster = val;
  11634. };
  11635. /**
  11636. * Get preload attribute
  11637. *
  11638. * @return {String}
  11639. * @method preload
  11640. */
  11641. Html5.prototype.preload = function preload() {
  11642. return this.el_.preload;
  11643. };
  11644. /**
  11645. * Set preload attribute
  11646. *
  11647. * @param {String} val Value for preload attribute
  11648. * @method setPreload
  11649. */
  11650. Html5.prototype.setPreload = function setPreload(val) {
  11651. this.el_.preload = val;
  11652. };
  11653. /**
  11654. * Get autoplay attribute
  11655. *
  11656. * @return {String}
  11657. * @method autoplay
  11658. */
  11659. Html5.prototype.autoplay = function autoplay() {
  11660. return this.el_.autoplay;
  11661. };
  11662. /**
  11663. * Set autoplay attribute
  11664. *
  11665. * @param {String} val Value for preload attribute
  11666. * @method setAutoplay
  11667. */
  11668. Html5.prototype.setAutoplay = function setAutoplay(val) {
  11669. this.el_.autoplay = val;
  11670. };
  11671. /**
  11672. * Get controls attribute
  11673. *
  11674. * @return {String}
  11675. * @method controls
  11676. */
  11677. Html5.prototype.controls = function controls() {
  11678. return this.el_.controls;
  11679. };
  11680. /**
  11681. * Set controls attribute
  11682. *
  11683. * @param {String} val Value for controls attribute
  11684. * @method setControls
  11685. */
  11686. Html5.prototype.setControls = function setControls(val) {
  11687. this.el_.controls = !!val;
  11688. };
  11689. /**
  11690. * Get loop attribute
  11691. *
  11692. * @return {String}
  11693. * @method loop
  11694. */
  11695. Html5.prototype.loop = function loop() {
  11696. return this.el_.loop;
  11697. };
  11698. /**
  11699. * Set loop attribute
  11700. *
  11701. * @param {String} val Value for loop attribute
  11702. * @method setLoop
  11703. */
  11704. Html5.prototype.setLoop = function setLoop(val) {
  11705. this.el_.loop = val;
  11706. };
  11707. /**
  11708. * Get error value
  11709. *
  11710. * @return {String}
  11711. * @method error
  11712. */
  11713. Html5.prototype.error = function error() {
  11714. return this.el_.error;
  11715. };
  11716. /**
  11717. * Get whether or not the player is in the "seeking" state
  11718. *
  11719. * @return {Boolean}
  11720. * @method seeking
  11721. */
  11722. Html5.prototype.seeking = function seeking() {
  11723. return this.el_.seeking;
  11724. };
  11725. /**
  11726. * Get a TimeRanges object that represents the
  11727. * ranges of the media resource to which it is possible
  11728. * for the user agent to seek.
  11729. *
  11730. * @return {TimeRangeObject}
  11731. * @method seekable
  11732. */
  11733. Html5.prototype.seekable = function seekable() {
  11734. return this.el_.seekable;
  11735. };
  11736. /**
  11737. * Get if video ended
  11738. *
  11739. * @return {Boolean}
  11740. * @method ended
  11741. */
  11742. Html5.prototype.ended = function ended() {
  11743. return this.el_.ended;
  11744. };
  11745. /**
  11746. * Get the value of the muted content attribute
  11747. * This attribute has no dynamic effect, it only
  11748. * controls the default state of the element
  11749. *
  11750. * @return {Boolean}
  11751. * @method defaultMuted
  11752. */
  11753. Html5.prototype.defaultMuted = function defaultMuted() {
  11754. return this.el_.defaultMuted;
  11755. };
  11756. /**
  11757. * Get desired speed at which the media resource is to play
  11758. *
  11759. * @return {Number}
  11760. * @method playbackRate
  11761. */
  11762. Html5.prototype.playbackRate = function playbackRate() {
  11763. return this.el_.playbackRate;
  11764. };
  11765. /**
  11766. * Returns a TimeRanges object that represents the ranges of the
  11767. * media resource that the user agent has played.
  11768. * @return {TimeRangeObject} the range of points on the media
  11769. * timeline that has been reached through normal playback
  11770. * @see https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-played
  11771. */
  11772. Html5.prototype.played = function played() {
  11773. return this.el_.played;
  11774. };
  11775. /**
  11776. * Set desired speed at which the media resource is to play
  11777. *
  11778. * @param {Number} val Speed at which the media resource is to play
  11779. * @method setPlaybackRate
  11780. */
  11781. Html5.prototype.setPlaybackRate = function setPlaybackRate(val) {
  11782. this.el_.playbackRate = val;
  11783. };
  11784. /**
  11785. * Get the current state of network activity for the element, from
  11786. * the list below
  11787. * NETWORK_EMPTY (numeric value 0)
  11788. * NETWORK_IDLE (numeric value 1)
  11789. * NETWORK_LOADING (numeric value 2)
  11790. * NETWORK_NO_SOURCE (numeric value 3)
  11791. *
  11792. * @return {Number}
  11793. * @method networkState
  11794. */
  11795. Html5.prototype.networkState = function networkState() {
  11796. return this.el_.networkState;
  11797. };
  11798. /**
  11799. * Get a value that expresses the current state of the element
  11800. * with respect to rendering the current playback position, from
  11801. * the codes in the list below
  11802. * HAVE_NOTHING (numeric value 0)
  11803. * HAVE_METADATA (numeric value 1)
  11804. * HAVE_CURRENT_DATA (numeric value 2)
  11805. * HAVE_FUTURE_DATA (numeric value 3)
  11806. * HAVE_ENOUGH_DATA (numeric value 4)
  11807. *
  11808. * @return {Number}
  11809. * @method readyState
  11810. */
  11811. Html5.prototype.readyState = function readyState() {
  11812. return this.el_.readyState;
  11813. };
  11814. /**
  11815. * Get width of video
  11816. *
  11817. * @return {Number}
  11818. * @method videoWidth
  11819. */
  11820. Html5.prototype.videoWidth = function videoWidth() {
  11821. return this.el_.videoWidth;
  11822. };
  11823. /**
  11824. * Get height of video
  11825. *
  11826. * @return {Number}
  11827. * @method videoHeight
  11828. */
  11829. Html5.prototype.videoHeight = function videoHeight() {
  11830. return this.el_.videoHeight;
  11831. };
  11832. /**
  11833. * Get text tracks
  11834. *
  11835. * @return {TextTrackList}
  11836. * @method textTracks
  11837. */
  11838. Html5.prototype.textTracks = function textTracks() {
  11839. return _Tech.prototype.textTracks.call(this);
  11840. };
  11841. /**
  11842. * Creates and returns a text track object
  11843. *
  11844. * @param {String} kind Text track kind (subtitles, captions, descriptions
  11845. * chapters and metadata)
  11846. * @param {String=} label Label to identify the text track
  11847. * @param {String=} language Two letter language abbreviation
  11848. * @return {TextTrackObject}
  11849. * @method addTextTrack
  11850. */
  11851. Html5.prototype.addTextTrack = function addTextTrack(kind, label, language) {
  11852. if (!this['featuresNativeTextTracks']) {
  11853. return _Tech.prototype.addTextTrack.call(this, kind, label, language);
  11854. }
  11855. return this.el_.addTextTrack(kind, label, language);
  11856. };
  11857. /**
  11858. * Creates a remote text track object and returns a html track element
  11859. *
  11860. * @param {Object} options The object should contain values for
  11861. * kind, language, label and src (location of the WebVTT file)
  11862. * @return {HTMLTrackElement}
  11863. * @method addRemoteTextTrack
  11864. */
  11865. Html5.prototype.addRemoteTextTrack = function addRemoteTextTrack() {
  11866. var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  11867. if (!this['featuresNativeTextTracks']) {
  11868. return _Tech.prototype.addRemoteTextTrack.call(this, options);
  11869. }
  11870. var htmlTrackElement = _globalDocument2['default'].createElement('track');
  11871. if (options.kind) {
  11872. htmlTrackElement.kind = options.kind;
  11873. }
  11874. if (options.label) {
  11875. htmlTrackElement.label = options.label;
  11876. }
  11877. if (options.language || options.srclang) {
  11878. htmlTrackElement.srclang = options.language || options.srclang;
  11879. }
  11880. if (options['default']) {
  11881. htmlTrackElement['default'] = options['default'];
  11882. }
  11883. if (options.id) {
  11884. htmlTrackElement.id = options.id;
  11885. }
  11886. if (options.src) {
  11887. htmlTrackElement.src = options.src;
  11888. }
  11889. this.el().appendChild(htmlTrackElement);
  11890. // store HTMLTrackElement and TextTrack to remote list
  11891. this.remoteTextTrackEls().addTrackElement_(htmlTrackElement);
  11892. this.remoteTextTracks().addTrack_(htmlTrackElement.track);
  11893. return htmlTrackElement;
  11894. };
  11895. /**
  11896. * Remove remote text track from TextTrackList object
  11897. *
  11898. * @param {TextTrackObject} track Texttrack object to remove
  11899. * @method removeRemoteTextTrack
  11900. */
  11901. Html5.prototype.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  11902. if (!this['featuresNativeTextTracks']) {
  11903. return _Tech.prototype.removeRemoteTextTrack.call(this, track);
  11904. }
  11905. var tracks = undefined,
  11906. i = undefined;
  11907. var trackElement = this.remoteTextTrackEls().getTrackElementByTrack_(track);
  11908. // remove HTMLTrackElement and TextTrack from remote list
  11909. this.remoteTextTrackEls().removeTrackElement_(trackElement);
  11910. this.remoteTextTracks().removeTrack_(track);
  11911. tracks = this.$$('track');
  11912. i = tracks.length;
  11913. while (i--) {
  11914. if (track === tracks[i] || track === tracks[i].track) {
  11915. this.el().removeChild(tracks[i]);
  11916. }
  11917. }
  11918. };
  11919. return Html5;
  11920. })(_techJs2['default']);
  11921. Html5.TEST_VID = _globalDocument2['default'].createElement('video');
  11922. var track = _globalDocument2['default'].createElement('track');
  11923. track.kind = 'captions';
  11924. track.srclang = 'en';
  11925. track.label = 'English';
  11926. Html5.TEST_VID.appendChild(track);
  11927. /*
  11928. * Check if HTML5 video is supported by this browser/device
  11929. *
  11930. * @return {Boolean}
  11931. */
  11932. Html5.isSupported = function () {
  11933. // IE9 with no Media Player is a LIAR! (#984)
  11934. try {
  11935. Html5.TEST_VID['volume'] = 0.5;
  11936. } catch (e) {
  11937. return false;
  11938. }
  11939. return !!Html5.TEST_VID.canPlayType;
  11940. };
  11941. // Add Source Handler pattern functions to this tech
  11942. _techJs2['default'].withSourceHandlers(Html5);
  11943. /*
  11944. * The default native source handler.
  11945. * This simply passes the source to the video element. Nothing fancy.
  11946. *
  11947. * @param {Object} source The source object
  11948. * @param {Html5} tech The instance of the HTML5 tech
  11949. */
  11950. Html5.nativeSourceHandler = {};
  11951. /*
  11952. * Check if the video element can play the given videotype
  11953. *
  11954. * @param {String} type The mimetype to check
  11955. * @return {String} 'probably', 'maybe', or '' (empty string)
  11956. */
  11957. Html5.nativeSourceHandler.canPlayType = function (type) {
  11958. // IE9 on Windows 7 without MediaPlayer throws an error here
  11959. // https://github.com/videojs/video.js/issues/519
  11960. try {
  11961. return Html5.TEST_VID.canPlayType(type);
  11962. } catch (e) {
  11963. return '';
  11964. }
  11965. };
  11966. /*
  11967. * Check if the video element can handle the source natively
  11968. *
  11969. * @param {Object} source The source object
  11970. * @return {String} 'probably', 'maybe', or '' (empty string)
  11971. */
  11972. Html5.nativeSourceHandler.canHandleSource = function (source) {
  11973. var match, ext;
  11974. // If a type was provided we should rely on that
  11975. if (source.type) {
  11976. return Html5.nativeSourceHandler.canPlayType(source.type);
  11977. } else if (source.src) {
  11978. // If no type, fall back to checking 'video/[EXTENSION]'
  11979. ext = Url.getFileExtension(source.src);
  11980. return Html5.nativeSourceHandler.canPlayType('video/' + ext);
  11981. }
  11982. return '';
  11983. };
  11984. /*
  11985. * Pass the source to the video element
  11986. * Adaptive source handlers will have more complicated workflows before passing
  11987. * video data to the video element
  11988. *
  11989. * @param {Object} source The source object
  11990. * @param {Html5} tech The instance of the Html5 tech
  11991. */
  11992. Html5.nativeSourceHandler.handleSource = function (source, tech) {
  11993. tech.setSrc(source.src);
  11994. };
  11995. /*
  11996. * Clean up the source handler when disposing the player or switching sources..
  11997. * (no cleanup is needed when supporting the format natively)
  11998. */
  11999. Html5.nativeSourceHandler.dispose = function () {};
  12000. // Register the native source handler
  12001. Html5.registerSourceHandler(Html5.nativeSourceHandler);
  12002. /*
  12003. * Check if the volume can be changed in this browser/device.
  12004. * Volume cannot be changed in a lot of mobile devices.
  12005. * Specifically, it can't be changed from 1 on iOS.
  12006. *
  12007. * @return {Boolean}
  12008. */
  12009. Html5.canControlVolume = function () {
  12010. var volume = Html5.TEST_VID.volume;
  12011. Html5.TEST_VID.volume = volume / 2 + 0.1;
  12012. return volume !== Html5.TEST_VID.volume;
  12013. };
  12014. /*
  12015. * Check if playbackRate is supported in this browser/device.
  12016. *
  12017. * @return {Number} [description]
  12018. */
  12019. Html5.canControlPlaybackRate = function () {
  12020. var playbackRate = Html5.TEST_VID.playbackRate;
  12021. Html5.TEST_VID.playbackRate = playbackRate / 2 + 0.1;
  12022. return playbackRate !== Html5.TEST_VID.playbackRate;
  12023. };
  12024. /*
  12025. * Check to see if native text tracks are supported by this browser/device
  12026. *
  12027. * @return {Boolean}
  12028. */
  12029. Html5.supportsNativeTextTracks = function () {
  12030. var supportsTextTracks;
  12031. // Figure out native text track support
  12032. // If mode is a number, we cannot change it because it'll disappear from view.
  12033. // Browsers with numeric modes include IE10 and older (<=2013) samsung android models.
  12034. // Firefox isn't playing nice either with modifying the mode
  12035. // TODO: Investigate firefox: https://github.com/videojs/video.js/issues/1862
  12036. supportsTextTracks = !!Html5.TEST_VID.textTracks;
  12037. if (supportsTextTracks && Html5.TEST_VID.textTracks.length > 0) {
  12038. supportsTextTracks = typeof Html5.TEST_VID.textTracks[0]['mode'] !== 'number';
  12039. }
  12040. if (supportsTextTracks && browser.IS_FIREFOX) {
  12041. supportsTextTracks = false;
  12042. }
  12043. if (supportsTextTracks && !('onremovetrack' in Html5.TEST_VID.textTracks)) {
  12044. supportsTextTracks = false;
  12045. }
  12046. return supportsTextTracks;
  12047. };
  12048. /**
  12049. * An array of events available on the Html5 tech.
  12050. *
  12051. * @private
  12052. * @type {Array}
  12053. */
  12054. Html5.Events = ['loadstart', 'suspend', 'abort', 'error', 'emptied', 'stalled', 'loadedmetadata', 'loadeddata', 'canplay', 'canplaythrough', 'playing', 'waiting', 'seeking', 'seeked', 'ended', 'durationchange', 'timeupdate', 'progress', 'play', 'pause', 'ratechange', 'volumechange'];
  12055. /*
  12056. * Set the tech's volume control support status
  12057. *
  12058. * @type {Boolean}
  12059. */
  12060. Html5.prototype['featuresVolumeControl'] = Html5.canControlVolume();
  12061. /*
  12062. * Set the tech's playbackRate support status
  12063. *
  12064. * @type {Boolean}
  12065. */
  12066. Html5.prototype['featuresPlaybackRate'] = Html5.canControlPlaybackRate();
  12067. /*
  12068. * Set the tech's status on moving the video element.
  12069. * In iOS, if you move a video element in the DOM, it breaks video playback.
  12070. *
  12071. * @type {Boolean}
  12072. */
  12073. Html5.prototype['movingMediaElementInDOM'] = !browser.IS_IOS;
  12074. /*
  12075. * Set the the tech's fullscreen resize support status.
  12076. * HTML video is able to automatically resize when going to fullscreen.
  12077. * (No longer appears to be used. Can probably be removed.)
  12078. */
  12079. Html5.prototype['featuresFullscreenResize'] = true;
  12080. /*
  12081. * Set the tech's progress event support status
  12082. * (this disables the manual progress events of the Tech)
  12083. */
  12084. Html5.prototype['featuresProgressEvents'] = true;
  12085. /*
  12086. * Sets the tech's status on native text track support
  12087. *
  12088. * @type {Boolean}
  12089. */
  12090. Html5.prototype['featuresNativeTextTracks'] = Html5.supportsNativeTextTracks();
  12091. // HTML5 Feature detection and Device Fixes --------------------------------- //
  12092. var canPlayType = undefined;
  12093. var mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i;
  12094. var mp4RE = /^video\/mp4/i;
  12095. Html5.patchCanPlayType = function () {
  12096. // Android 4.0 and above can play HLS to some extent but it reports being unable to do so
  12097. if (browser.ANDROID_VERSION >= 4.0) {
  12098. if (!canPlayType) {
  12099. canPlayType = Html5.TEST_VID.constructor.prototype.canPlayType;
  12100. }
  12101. Html5.TEST_VID.constructor.prototype.canPlayType = function (type) {
  12102. if (type && mpegurlRE.test(type)) {
  12103. return 'maybe';
  12104. }
  12105. return canPlayType.call(this, type);
  12106. };
  12107. }
  12108. // Override Android 2.2 and less canPlayType method which is broken
  12109. if (browser.IS_OLD_ANDROID) {
  12110. if (!canPlayType) {
  12111. canPlayType = Html5.TEST_VID.constructor.prototype.canPlayType;
  12112. }
  12113. Html5.TEST_VID.constructor.prototype.canPlayType = function (type) {
  12114. if (type && mp4RE.test(type)) {
  12115. return 'maybe';
  12116. }
  12117. return canPlayType.call(this, type);
  12118. };
  12119. }
  12120. };
  12121. Html5.unpatchCanPlayType = function () {
  12122. var r = Html5.TEST_VID.constructor.prototype.canPlayType;
  12123. Html5.TEST_VID.constructor.prototype.canPlayType = canPlayType;
  12124. canPlayType = null;
  12125. return r;
  12126. };
  12127. // by default, patch the video element
  12128. Html5.patchCanPlayType();
  12129. Html5.disposeMediaElement = function (el) {
  12130. if (!el) {
  12131. return;
  12132. }
  12133. if (el.parentNode) {
  12134. el.parentNode.removeChild(el);
  12135. }
  12136. // remove any child track or source nodes to prevent their loading
  12137. while (el.hasChildNodes()) {
  12138. el.removeChild(el.firstChild);
  12139. }
  12140. // remove any src reference. not setting `src=''` because that causes a warning
  12141. // in firefox
  12142. el.removeAttribute('src');
  12143. // force the media element to update its loading state by calling load()
  12144. // however IE on Windows 7N has a bug that throws an error so need a try/catch (#793)
  12145. if (typeof el.load === 'function') {
  12146. // wrapping in an iife so it's not deoptimized (#1060#discussion_r10324473)
  12147. (function () {
  12148. try {
  12149. el.load();
  12150. } catch (e) {
  12151. // not supported
  12152. }
  12153. })();
  12154. }
  12155. };
  12156. Html5.resetMediaElement = function (el) {
  12157. if (!el) {
  12158. return;
  12159. }
  12160. var sources = el.querySelectorAll('source');
  12161. var i = sources.length;
  12162. while (i--) {
  12163. el.removeChild(sources[i]);
  12164. }
  12165. // remove any src reference.
  12166. // not setting `src=''` because that throws an error
  12167. el.removeAttribute('src');
  12168. if (typeof el.load === 'function') {
  12169. // wrapping in an iife so it's not deoptimized (#1060#discussion_r10324473)
  12170. (function () {
  12171. try {
  12172. el.load();
  12173. } catch (e) {}
  12174. })();
  12175. }
  12176. };
  12177. _component2['default'].registerComponent('Html5', Html5);
  12178. _techJs2['default'].registerTech('Html5', Html5);
  12179. exports['default'] = Html5;
  12180. module.exports = exports['default'];
  12181. },{"../component":67,"../utils/browser.js":129,"../utils/dom.js":132,"../utils/fn.js":134,"../utils/log.js":137,"../utils/merge-options.js":138,"../utils/url.js":142,"./tech.js":119,"global/document":1,"global/window":2,"object.assign":45}],118:[function(_dereq_,module,exports){
  12182. /**
  12183. * @file loader.js
  12184. */
  12185. 'use strict';
  12186. exports.__esModule = true;
  12187. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  12188. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  12189. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  12190. var _componentJs = _dereq_('../component.js');
  12191. var _componentJs2 = _interopRequireDefault(_componentJs);
  12192. var _techJs = _dereq_('./tech.js');
  12193. var _techJs2 = _interopRequireDefault(_techJs);
  12194. var _globalWindow = _dereq_('global/window');
  12195. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  12196. var _utilsToTitleCaseJs = _dereq_('../utils/to-title-case.js');
  12197. var _utilsToTitleCaseJs2 = _interopRequireDefault(_utilsToTitleCaseJs);
  12198. /**
  12199. * The Media Loader is the component that decides which playback technology to load
  12200. * when the player is initialized.
  12201. *
  12202. * @param {Object} player Main Player
  12203. * @param {Object=} options Object of option names and values
  12204. * @param {Function=} ready Ready callback function
  12205. * @extends Component
  12206. * @class MediaLoader
  12207. */
  12208. var MediaLoader = (function (_Component) {
  12209. _inherits(MediaLoader, _Component);
  12210. function MediaLoader(player, options, ready) {
  12211. _classCallCheck(this, MediaLoader);
  12212. _Component.call(this, player, options, ready);
  12213. // If there are no sources when the player is initialized,
  12214. // load the first supported playback technology.
  12215. if (!options.playerOptions['sources'] || options.playerOptions['sources'].length === 0) {
  12216. for (var i = 0, j = options.playerOptions['techOrder']; i < j.length; i++) {
  12217. var techName = _utilsToTitleCaseJs2['default'](j[i]);
  12218. var tech = _techJs2['default'].getTech(techName);
  12219. // Support old behavior of techs being registered as components.
  12220. // Remove once that deprecated behavior is removed.
  12221. if (!techName) {
  12222. tech = _componentJs2['default'].getComponent(techName);
  12223. }
  12224. // Check if the browser supports this technology
  12225. if (tech && tech.isSupported()) {
  12226. player.loadTech_(techName);
  12227. break;
  12228. }
  12229. }
  12230. } else {
  12231. // // Loop through playback technologies (HTML5, Flash) and check for support.
  12232. // // Then load the best source.
  12233. // // A few assumptions here:
  12234. // // All playback technologies respect preload false.
  12235. player.src(options.playerOptions['sources']);
  12236. }
  12237. }
  12238. return MediaLoader;
  12239. })(_componentJs2['default']);
  12240. _componentJs2['default'].registerComponent('MediaLoader', MediaLoader);
  12241. exports['default'] = MediaLoader;
  12242. module.exports = exports['default'];
  12243. },{"../component.js":67,"../utils/to-title-case.js":141,"./tech.js":119,"global/window":2}],119:[function(_dereq_,module,exports){
  12244. /**
  12245. * @file tech.js
  12246. * Media Technology Controller - Base class for media playback
  12247. * technology controllers like Flash and HTML5
  12248. */
  12249. 'use strict';
  12250. exports.__esModule = true;
  12251. 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; } }
  12252. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  12253. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  12254. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  12255. var _component = _dereq_('../component');
  12256. var _component2 = _interopRequireDefault(_component);
  12257. var _tracksHtmlTrackElement = _dereq_('../tracks/html-track-element');
  12258. var _tracksHtmlTrackElement2 = _interopRequireDefault(_tracksHtmlTrackElement);
  12259. var _tracksHtmlTrackElementList = _dereq_('../tracks/html-track-element-list');
  12260. var _tracksHtmlTrackElementList2 = _interopRequireDefault(_tracksHtmlTrackElementList);
  12261. var _utilsMergeOptionsJs = _dereq_('../utils/merge-options.js');
  12262. var _utilsMergeOptionsJs2 = _interopRequireDefault(_utilsMergeOptionsJs);
  12263. var _tracksTextTrack = _dereq_('../tracks/text-track');
  12264. var _tracksTextTrack2 = _interopRequireDefault(_tracksTextTrack);
  12265. var _tracksTextTrackList = _dereq_('../tracks/text-track-list');
  12266. var _tracksTextTrackList2 = _interopRequireDefault(_tracksTextTrackList);
  12267. var _utilsFnJs = _dereq_('../utils/fn.js');
  12268. var Fn = _interopRequireWildcard(_utilsFnJs);
  12269. var _utilsLogJs = _dereq_('../utils/log.js');
  12270. var _utilsLogJs2 = _interopRequireDefault(_utilsLogJs);
  12271. var _utilsTimeRangesJs = _dereq_('../utils/time-ranges.js');
  12272. var _utilsBufferJs = _dereq_('../utils/buffer.js');
  12273. var _mediaErrorJs = _dereq_('../media-error.js');
  12274. var _mediaErrorJs2 = _interopRequireDefault(_mediaErrorJs);
  12275. var _globalWindow = _dereq_('global/window');
  12276. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  12277. var _globalDocument = _dereq_('global/document');
  12278. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  12279. /**
  12280. * Base class for media (HTML5 Video, Flash) controllers
  12281. *
  12282. * @param {Object=} options Options object
  12283. * @param {Function=} ready Ready callback function
  12284. * @extends Component
  12285. * @class Tech
  12286. */
  12287. var Tech = (function (_Component) {
  12288. _inherits(Tech, _Component);
  12289. function Tech() {
  12290. var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  12291. var ready = arguments.length <= 1 || arguments[1] === undefined ? function () {} : arguments[1];
  12292. _classCallCheck(this, Tech);
  12293. // we don't want the tech to report user activity automatically.
  12294. // This is done manually in addControlsListeners
  12295. options.reportTouchActivity = false;
  12296. _Component.call(this, null, options, ready);
  12297. // keep track of whether the current source has played at all to
  12298. // implement a very limited played()
  12299. this.hasStarted_ = false;
  12300. this.on('playing', function () {
  12301. this.hasStarted_ = true;
  12302. });
  12303. this.on('loadstart', function () {
  12304. this.hasStarted_ = false;
  12305. });
  12306. this.textTracks_ = options.textTracks;
  12307. // Manually track progress in cases where the browser/flash player doesn't report it.
  12308. if (!this.featuresProgressEvents) {
  12309. this.manualProgressOn();
  12310. }
  12311. // Manually track timeupdates in cases where the browser/flash player doesn't report it.
  12312. if (!this.featuresTimeupdateEvents) {
  12313. this.manualTimeUpdatesOn();
  12314. }
  12315. if (options.nativeCaptions === false || options.nativeTextTracks === false) {
  12316. this.featuresNativeTextTracks = false;
  12317. }
  12318. if (!this.featuresNativeTextTracks) {
  12319. this.on('ready', this.emulateTextTracks);
  12320. }
  12321. this.initTextTrackListeners();
  12322. // Turn on component tap events
  12323. this.emitTapEvents();
  12324. }
  12325. /*
  12326. * List of associated text tracks
  12327. *
  12328. * @type {Array}
  12329. * @private
  12330. */
  12331. /* Fallbacks for unsupported event types
  12332. ================================================================================ */
  12333. // Manually trigger progress events based on changes to the buffered amount
  12334. // Many flash players and older HTML5 browsers don't send progress or progress-like events
  12335. /**
  12336. * Turn on progress events
  12337. *
  12338. * @method manualProgressOn
  12339. */
  12340. Tech.prototype.manualProgressOn = function manualProgressOn() {
  12341. this.on('durationchange', this.onDurationChange);
  12342. this.manualProgress = true;
  12343. // Trigger progress watching when a source begins loading
  12344. this.one('ready', this.trackProgress);
  12345. };
  12346. /**
  12347. * Turn off progress events
  12348. *
  12349. * @method manualProgressOff
  12350. */
  12351. Tech.prototype.manualProgressOff = function manualProgressOff() {
  12352. this.manualProgress = false;
  12353. this.stopTrackingProgress();
  12354. this.off('durationchange', this.onDurationChange);
  12355. };
  12356. /**
  12357. * Track progress
  12358. *
  12359. * @method trackProgress
  12360. */
  12361. Tech.prototype.trackProgress = function trackProgress() {
  12362. this.stopTrackingProgress();
  12363. this.progressInterval = this.setInterval(Fn.bind(this, function () {
  12364. // Don't trigger unless buffered amount is greater than last time
  12365. var numBufferedPercent = this.bufferedPercent();
  12366. if (this.bufferedPercent_ !== numBufferedPercent) {
  12367. this.trigger('progress');
  12368. }
  12369. this.bufferedPercent_ = numBufferedPercent;
  12370. if (numBufferedPercent === 1) {
  12371. this.stopTrackingProgress();
  12372. }
  12373. }), 500);
  12374. };
  12375. /**
  12376. * Update duration
  12377. *
  12378. * @method onDurationChange
  12379. */
  12380. Tech.prototype.onDurationChange = function onDurationChange() {
  12381. this.duration_ = this.duration();
  12382. };
  12383. /**
  12384. * Create and get TimeRange object for buffering
  12385. *
  12386. * @return {TimeRangeObject}
  12387. * @method buffered
  12388. */
  12389. Tech.prototype.buffered = function buffered() {
  12390. return _utilsTimeRangesJs.createTimeRange(0, 0);
  12391. };
  12392. /**
  12393. * Get buffered percent
  12394. *
  12395. * @return {Number}
  12396. * @method bufferedPercent
  12397. */
  12398. Tech.prototype.bufferedPercent = function bufferedPercent() {
  12399. return _utilsBufferJs.bufferedPercent(this.buffered(), this.duration_);
  12400. };
  12401. /**
  12402. * Stops tracking progress by clearing progress interval
  12403. *
  12404. * @method stopTrackingProgress
  12405. */
  12406. Tech.prototype.stopTrackingProgress = function stopTrackingProgress() {
  12407. this.clearInterval(this.progressInterval);
  12408. };
  12409. /*! Time Tracking -------------------------------------------------------------- */
  12410. /**
  12411. * Set event listeners for on play and pause and tracking current time
  12412. *
  12413. * @method manualTimeUpdatesOn
  12414. */
  12415. Tech.prototype.manualTimeUpdatesOn = function manualTimeUpdatesOn() {
  12416. this.manualTimeUpdates = true;
  12417. this.on('play', this.trackCurrentTime);
  12418. this.on('pause', this.stopTrackingCurrentTime);
  12419. };
  12420. /**
  12421. * Remove event listeners for on play and pause and tracking current time
  12422. *
  12423. * @method manualTimeUpdatesOff
  12424. */
  12425. Tech.prototype.manualTimeUpdatesOff = function manualTimeUpdatesOff() {
  12426. this.manualTimeUpdates = false;
  12427. this.stopTrackingCurrentTime();
  12428. this.off('play', this.trackCurrentTime);
  12429. this.off('pause', this.stopTrackingCurrentTime);
  12430. };
  12431. /**
  12432. * Tracks current time
  12433. *
  12434. * @method trackCurrentTime
  12435. */
  12436. Tech.prototype.trackCurrentTime = function trackCurrentTime() {
  12437. if (this.currentTimeInterval) {
  12438. this.stopTrackingCurrentTime();
  12439. }
  12440. this.currentTimeInterval = this.setInterval(function () {
  12441. this.trigger({ type: 'timeupdate', target: this, manuallyTriggered: true });
  12442. }, 250); // 42 = 24 fps // 250 is what Webkit uses // FF uses 15
  12443. };
  12444. /**
  12445. * Turn off play progress tracking (when paused or dragging)
  12446. *
  12447. * @method stopTrackingCurrentTime
  12448. */
  12449. Tech.prototype.stopTrackingCurrentTime = function stopTrackingCurrentTime() {
  12450. this.clearInterval(this.currentTimeInterval);
  12451. // #1002 - if the video ends right before the next timeupdate would happen,
  12452. // the progress bar won't make it all the way to the end
  12453. this.trigger({ type: 'timeupdate', target: this, manuallyTriggered: true });
  12454. };
  12455. /**
  12456. * Turn off any manual progress or timeupdate tracking
  12457. *
  12458. * @method dispose
  12459. */
  12460. Tech.prototype.dispose = function dispose() {
  12461. // clear out text tracks because we can't reuse them between techs
  12462. var textTracks = this.textTracks();
  12463. if (textTracks) {
  12464. var i = textTracks.length;
  12465. while (i--) {
  12466. this.removeRemoteTextTrack(textTracks[i]);
  12467. }
  12468. }
  12469. // Turn off any manual progress or timeupdate tracking
  12470. if (this.manualProgress) {
  12471. this.manualProgressOff();
  12472. }
  12473. if (this.manualTimeUpdates) {
  12474. this.manualTimeUpdatesOff();
  12475. }
  12476. _Component.prototype.dispose.call(this);
  12477. };
  12478. /**
  12479. * Reset the tech. Removes all sources and resets readyState.
  12480. *
  12481. * @method reset
  12482. */
  12483. Tech.prototype.reset = function reset() {};
  12484. /**
  12485. * When invoked without an argument, returns a MediaError object
  12486. * representing the current error state of the player or null if
  12487. * there is no error. When invoked with an argument, set the current
  12488. * error state of the player.
  12489. * @param {MediaError=} err Optional an error object
  12490. * @return {MediaError} the current error object or null
  12491. * @method error
  12492. */
  12493. Tech.prototype.error = function error(err) {
  12494. if (err !== undefined) {
  12495. if (err instanceof _mediaErrorJs2['default']) {
  12496. this.error_ = err;
  12497. } else {
  12498. this.error_ = new _mediaErrorJs2['default'](err);
  12499. }
  12500. this.trigger('error');
  12501. }
  12502. return this.error_;
  12503. };
  12504. /**
  12505. * Return the time ranges that have been played through for the
  12506. * current source. This implementation is incomplete. It does not
  12507. * track the played time ranges, only whether the source has played
  12508. * at all or not.
  12509. * @return {TimeRangeObject} a single time range if this video has
  12510. * played or an empty set of ranges if not.
  12511. * @method played
  12512. */
  12513. Tech.prototype.played = function played() {
  12514. if (this.hasStarted_) {
  12515. return _utilsTimeRangesJs.createTimeRange(0, 0);
  12516. }
  12517. return _utilsTimeRangesJs.createTimeRange();
  12518. };
  12519. /**
  12520. * Set current time
  12521. *
  12522. * @method setCurrentTime
  12523. */
  12524. Tech.prototype.setCurrentTime = function setCurrentTime() {
  12525. // improve the accuracy of manual timeupdates
  12526. if (this.manualTimeUpdates) {
  12527. this.trigger({ type: 'timeupdate', target: this, manuallyTriggered: true });
  12528. }
  12529. };
  12530. /**
  12531. * Initialize texttrack listeners
  12532. *
  12533. * @method initTextTrackListeners
  12534. */
  12535. Tech.prototype.initTextTrackListeners = function initTextTrackListeners() {
  12536. var textTrackListChanges = Fn.bind(this, function () {
  12537. this.trigger('texttrackchange');
  12538. });
  12539. var tracks = this.textTracks();
  12540. if (!tracks) return;
  12541. tracks.addEventListener('removetrack', textTrackListChanges);
  12542. tracks.addEventListener('addtrack', textTrackListChanges);
  12543. this.on('dispose', Fn.bind(this, function () {
  12544. tracks.removeEventListener('removetrack', textTrackListChanges);
  12545. tracks.removeEventListener('addtrack', textTrackListChanges);
  12546. }));
  12547. };
  12548. /**
  12549. * Emulate texttracks
  12550. *
  12551. * @method emulateTextTracks
  12552. */
  12553. Tech.prototype.emulateTextTracks = function emulateTextTracks() {
  12554. var _this = this;
  12555. var tracks = this.textTracks();
  12556. if (!tracks) {
  12557. return;
  12558. }
  12559. if (!_globalWindow2['default']['WebVTT'] && this.el().parentNode != null) {
  12560. (function () {
  12561. var script = _globalDocument2['default'].createElement('script');
  12562. script.src = _this.options_['vtt.js'] || 'https://cdn.rawgit.com/gkatsev/vtt.js/vjs-v0.12.1/dist/vtt.min.js';
  12563. script.onload = function () {
  12564. _this.trigger('vttjsloaded');
  12565. };
  12566. script.onerror = function () {
  12567. _this.trigger('vttjserror');
  12568. };
  12569. _this.on('dispose', function () {
  12570. script.onload = null;
  12571. script.onerror = null;
  12572. });
  12573. _this.el().parentNode.appendChild(script);
  12574. _globalWindow2['default']['WebVTT'] = true;
  12575. })();
  12576. }
  12577. var updateDisplay = function updateDisplay() {
  12578. return _this.trigger('texttrackchange');
  12579. };
  12580. var textTracksChanges = function textTracksChanges() {
  12581. updateDisplay();
  12582. for (var i = 0; i < tracks.length; i++) {
  12583. var track = tracks[i];
  12584. track.removeEventListener('cuechange', updateDisplay);
  12585. if (track.mode === 'showing') {
  12586. track.addEventListener('cuechange', updateDisplay);
  12587. }
  12588. }
  12589. };
  12590. textTracksChanges();
  12591. tracks.addEventListener('change', textTracksChanges);
  12592. this.on('dispose', function () {
  12593. tracks.removeEventListener('change', textTracksChanges);
  12594. });
  12595. };
  12596. /*
  12597. * Provide default methods for text tracks.
  12598. *
  12599. * Html5 tech overrides these.
  12600. */
  12601. /**
  12602. * Get texttracks
  12603. *
  12604. * @returns {TextTrackList}
  12605. * @method textTracks
  12606. */
  12607. Tech.prototype.textTracks = function textTracks() {
  12608. this.textTracks_ = this.textTracks_ || new _tracksTextTrackList2['default']();
  12609. return this.textTracks_;
  12610. };
  12611. /**
  12612. * Get remote texttracks
  12613. *
  12614. * @returns {TextTrackList}
  12615. * @method remoteTextTracks
  12616. */
  12617. Tech.prototype.remoteTextTracks = function remoteTextTracks() {
  12618. this.remoteTextTracks_ = this.remoteTextTracks_ || new _tracksTextTrackList2['default']();
  12619. return this.remoteTextTracks_;
  12620. };
  12621. /**
  12622. * Get remote htmltrackelements
  12623. *
  12624. * @returns {HTMLTrackElementList}
  12625. * @method remoteTextTrackEls
  12626. */
  12627. Tech.prototype.remoteTextTrackEls = function remoteTextTrackEls() {
  12628. this.remoteTextTrackEls_ = this.remoteTextTrackEls_ || new _tracksHtmlTrackElementList2['default']();
  12629. return this.remoteTextTrackEls_;
  12630. };
  12631. /**
  12632. * Creates and returns a remote text track object
  12633. *
  12634. * @param {String} kind Text track kind (subtitles, captions, descriptions
  12635. * chapters and metadata)
  12636. * @param {String=} label Label to identify the text track
  12637. * @param {String=} language Two letter language abbreviation
  12638. * @return {TextTrackObject}
  12639. * @method addTextTrack
  12640. */
  12641. Tech.prototype.addTextTrack = function addTextTrack(kind, label, language) {
  12642. if (!kind) {
  12643. throw new Error('TextTrack kind is required but was not provided');
  12644. }
  12645. return createTrackHelper(this, kind, label, language);
  12646. };
  12647. /**
  12648. * Creates a remote text track object and returns a emulated html track element
  12649. *
  12650. * @param {Object} options The object should contain values for
  12651. * kind, language, label and src (location of the WebVTT file)
  12652. * @return {HTMLTrackElement}
  12653. * @method addRemoteTextTrack
  12654. */
  12655. Tech.prototype.addRemoteTextTrack = function addRemoteTextTrack(options) {
  12656. var track = _utilsMergeOptionsJs2['default'](options, {
  12657. tech: this
  12658. });
  12659. var htmlTrackElement = new _tracksHtmlTrackElement2['default'](track);
  12660. // store HTMLTrackElement and TextTrack to remote list
  12661. this.remoteTextTrackEls().addTrackElement_(htmlTrackElement);
  12662. this.remoteTextTracks().addTrack_(htmlTrackElement.track);
  12663. // must come after remoteTextTracks()
  12664. this.textTracks().addTrack_(htmlTrackElement.track);
  12665. return htmlTrackElement;
  12666. };
  12667. /**
  12668. * Remove remote texttrack
  12669. *
  12670. * @param {TextTrackObject} track Texttrack to remove
  12671. * @method removeRemoteTextTrack
  12672. */
  12673. Tech.prototype.removeRemoteTextTrack = function removeRemoteTextTrack(track) {
  12674. this.textTracks().removeTrack_(track);
  12675. var trackElement = this.remoteTextTrackEls().getTrackElementByTrack_(track);
  12676. // remove HTMLTrackElement and TextTrack from remote list
  12677. this.remoteTextTrackEls().removeTrackElement_(trackElement);
  12678. this.remoteTextTracks().removeTrack_(track);
  12679. };
  12680. /**
  12681. * Provide a default setPoster method for techs
  12682. * Poster support for techs should be optional, so we don't want techs to
  12683. * break if they don't have a way to set a poster.
  12684. *
  12685. * @method setPoster
  12686. */
  12687. Tech.prototype.setPoster = function setPoster() {};
  12688. /*
  12689. * Check if the tech can support the given type
  12690. *
  12691. * The base tech does not support any type, but source handlers might
  12692. * overwrite this.
  12693. *
  12694. * @param {String} type The mimetype to check
  12695. * @return {String} 'probably', 'maybe', or '' (empty string)
  12696. */
  12697. Tech.prototype.canPlayType = function canPlayType() {
  12698. return '';
  12699. };
  12700. /*
  12701. * Return whether the argument is a Tech or not.
  12702. * Can be passed either a Class like `Html5` or a instance like `player.tech_`
  12703. *
  12704. * @param {Object} component An item to check
  12705. * @return {Boolean} Whether it is a tech or not
  12706. */
  12707. Tech.isTech = function isTech(component) {
  12708. return component.prototype instanceof Tech || component instanceof Tech || component === Tech;
  12709. };
  12710. /**
  12711. * Registers a Tech
  12712. *
  12713. * @param {String} name Name of the Tech to register
  12714. * @param {Object} tech The tech to register
  12715. * @static
  12716. * @method registerComponent
  12717. */
  12718. Tech.registerTech = function registerTech(name, tech) {
  12719. if (!Tech.techs_) {
  12720. Tech.techs_ = {};
  12721. }
  12722. if (!Tech.isTech(tech)) {
  12723. throw new Error('Tech ' + name + ' must be a Tech');
  12724. }
  12725. Tech.techs_[name] = tech;
  12726. return tech;
  12727. };
  12728. /**
  12729. * Gets a component by name
  12730. *
  12731. * @param {String} name Name of the component to get
  12732. * @return {Component}
  12733. * @static
  12734. * @method getComponent
  12735. */
  12736. Tech.getTech = function getTech(name) {
  12737. if (Tech.techs_ && Tech.techs_[name]) {
  12738. return Tech.techs_[name];
  12739. }
  12740. if (_globalWindow2['default'] && _globalWindow2['default'].videojs && _globalWindow2['default'].videojs[name]) {
  12741. _utilsLogJs2['default'].warn('The ' + name + ' tech was added to the videojs object when it should be registered using videojs.registerTech(name, tech)');
  12742. return _globalWindow2['default'].videojs[name];
  12743. }
  12744. };
  12745. return Tech;
  12746. })(_component2['default']);
  12747. Tech.prototype.textTracks_;
  12748. var createTrackHelper = function createTrackHelper(self, kind, label, language) {
  12749. var options = arguments.length <= 4 || arguments[4] === undefined ? {} : arguments[4];
  12750. var tracks = self.textTracks();
  12751. options.kind = kind;
  12752. if (label) {
  12753. options.label = label;
  12754. }
  12755. if (language) {
  12756. options.language = language;
  12757. }
  12758. options.tech = self;
  12759. var track = new _tracksTextTrack2['default'](options);
  12760. tracks.addTrack_(track);
  12761. return track;
  12762. };
  12763. Tech.prototype.featuresVolumeControl = true;
  12764. // Resizing plugins using request fullscreen reloads the plugin
  12765. Tech.prototype.featuresFullscreenResize = false;
  12766. Tech.prototype.featuresPlaybackRate = false;
  12767. // Optional events that we can manually mimic with timers
  12768. // currently not triggered by video-js-swf
  12769. Tech.prototype.featuresProgressEvents = false;
  12770. Tech.prototype.featuresTimeupdateEvents = false;
  12771. Tech.prototype.featuresNativeTextTracks = false;
  12772. /*
  12773. * A functional mixin for techs that want to use the Source Handler pattern.
  12774. *
  12775. * ##### EXAMPLE:
  12776. *
  12777. * Tech.withSourceHandlers.call(MyTech);
  12778. *
  12779. */
  12780. Tech.withSourceHandlers = function (_Tech) {
  12781. /*
  12782. * Register a source handler
  12783. * Source handlers are scripts for handling specific formats.
  12784. * The source handler pattern is used for adaptive formats (HLS, DASH) that
  12785. * manually load video data and feed it into a Source Buffer (Media Source Extensions)
  12786. * @param {Function} handler The source handler
  12787. * @param {Boolean} first Register it before any existing handlers
  12788. */
  12789. _Tech.registerSourceHandler = function (handler, index) {
  12790. var handlers = _Tech.sourceHandlers;
  12791. if (!handlers) {
  12792. handlers = _Tech.sourceHandlers = [];
  12793. }
  12794. if (index === undefined) {
  12795. // add to the end of the list
  12796. index = handlers.length;
  12797. }
  12798. handlers.splice(index, 0, handler);
  12799. };
  12800. /*
  12801. * Check if the tech can support the given type
  12802. * @param {String} type The mimetype to check
  12803. * @return {String} 'probably', 'maybe', or '' (empty string)
  12804. */
  12805. _Tech.canPlayType = function (type) {
  12806. var handlers = _Tech.sourceHandlers || [];
  12807. var can = undefined;
  12808. for (var i = 0; i < handlers.length; i++) {
  12809. can = handlers[i].canPlayType(type);
  12810. if (can) {
  12811. return can;
  12812. }
  12813. }
  12814. return '';
  12815. };
  12816. /*
  12817. * Return the first source handler that supports the source
  12818. * TODO: Answer question: should 'probably' be prioritized over 'maybe'
  12819. * @param {Object} source The source object
  12820. * @returns {Object} The first source handler that supports the source
  12821. * @returns {null} Null if no source handler is found
  12822. */
  12823. _Tech.selectSourceHandler = function (source) {
  12824. var handlers = _Tech.sourceHandlers || [];
  12825. var can = undefined;
  12826. for (var i = 0; i < handlers.length; i++) {
  12827. can = handlers[i].canHandleSource(source);
  12828. if (can) {
  12829. return handlers[i];
  12830. }
  12831. }
  12832. return null;
  12833. };
  12834. /*
  12835. * Check if the tech can support the given source
  12836. * @param {Object} srcObj The source object
  12837. * @return {String} 'probably', 'maybe', or '' (empty string)
  12838. */
  12839. _Tech.canPlaySource = function (srcObj) {
  12840. var sh = _Tech.selectSourceHandler(srcObj);
  12841. if (sh) {
  12842. return sh.canHandleSource(srcObj);
  12843. }
  12844. return '';
  12845. };
  12846. /*
  12847. * When using a source handler, prefer its implementation of
  12848. * any function normally provided by the tech.
  12849. */
  12850. var deferrable = ['seekable', 'duration'];
  12851. deferrable.forEach(function (fnName) {
  12852. var originalFn = this[fnName];
  12853. if (typeof originalFn !== 'function') {
  12854. return;
  12855. }
  12856. this[fnName] = function () {
  12857. if (this.sourceHandler_ && this.sourceHandler_[fnName]) {
  12858. return this.sourceHandler_[fnName].apply(this.sourceHandler_, arguments);
  12859. }
  12860. return originalFn.apply(this, arguments);
  12861. };
  12862. }, _Tech.prototype);
  12863. /*
  12864. * Create a function for setting the source using a source object
  12865. * and source handlers.
  12866. * Should never be called unless a source handler was found.
  12867. * @param {Object} source A source object with src and type keys
  12868. * @return {Tech} self
  12869. */
  12870. _Tech.prototype.setSource = function (source) {
  12871. var sh = _Tech.selectSourceHandler(source);
  12872. if (!sh) {
  12873. // Fall back to a native source hander when unsupported sources are
  12874. // deliberately set
  12875. if (_Tech.nativeSourceHandler) {
  12876. sh = _Tech.nativeSourceHandler;
  12877. } else {
  12878. _utilsLogJs2['default'].error('No source hander found for the current source.');
  12879. }
  12880. }
  12881. // Dispose any existing source handler
  12882. this.disposeSourceHandler();
  12883. this.off('dispose', this.disposeSourceHandler);
  12884. this.currentSource_ = source;
  12885. this.sourceHandler_ = sh.handleSource(source, this);
  12886. this.on('dispose', this.disposeSourceHandler);
  12887. return this;
  12888. };
  12889. /*
  12890. * Clean up any existing source handler
  12891. */
  12892. _Tech.prototype.disposeSourceHandler = function () {
  12893. if (this.sourceHandler_ && this.sourceHandler_.dispose) {
  12894. this.sourceHandler_.dispose();
  12895. }
  12896. };
  12897. };
  12898. _component2['default'].registerComponent('Tech', Tech);
  12899. // Old name for Tech
  12900. _component2['default'].registerComponent('MediaTechController', Tech);
  12901. Tech.registerTech('Tech', Tech);
  12902. exports['default'] = Tech;
  12903. module.exports = exports['default'];
  12904. },{"../component":67,"../media-error.js":103,"../tracks/html-track-element":121,"../tracks/html-track-element-list":120,"../tracks/text-track":128,"../tracks/text-track-list":126,"../utils/buffer.js":130,"../utils/fn.js":134,"../utils/log.js":137,"../utils/merge-options.js":138,"../utils/time-ranges.js":140,"global/document":1,"global/window":2}],120:[function(_dereq_,module,exports){
  12905. /**
  12906. * @file html-track-element-list.js
  12907. */
  12908. 'use strict';
  12909. exports.__esModule = true;
  12910. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  12911. 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; } }
  12912. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  12913. var _utilsBrowserJs = _dereq_('../utils/browser.js');
  12914. var browser = _interopRequireWildcard(_utilsBrowserJs);
  12915. var _globalDocument = _dereq_('global/document');
  12916. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  12917. var HtmlTrackElementList = (function () {
  12918. function HtmlTrackElementList() {
  12919. var trackElements = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
  12920. _classCallCheck(this, HtmlTrackElementList);
  12921. var list = this;
  12922. if (browser.IS_IE8) {
  12923. list = _globalDocument2['default'].createElement('custom');
  12924. for (var prop in HtmlTrackElementList.prototype) {
  12925. if (prop !== 'constructor') {
  12926. list[prop] = HtmlTrackElementList.prototype[prop];
  12927. }
  12928. }
  12929. }
  12930. list.trackElements_ = [];
  12931. Object.defineProperty(list, 'length', {
  12932. get: function get() {
  12933. return this.trackElements_.length;
  12934. }
  12935. });
  12936. for (var i = 0, _length = trackElements.length; i < _length; i++) {
  12937. list.addTrackElement_(trackElements[i]);
  12938. }
  12939. if (browser.IS_IE8) {
  12940. return list;
  12941. }
  12942. }
  12943. HtmlTrackElementList.prototype.addTrackElement_ = function addTrackElement_(trackElement) {
  12944. this.trackElements_.push(trackElement);
  12945. };
  12946. HtmlTrackElementList.prototype.getTrackElementByTrack_ = function getTrackElementByTrack_(track) {
  12947. var trackElement_ = undefined;
  12948. for (var i = 0, _length2 = this.trackElements_.length; i < _length2; i++) {
  12949. if (track === this.trackElements_[i].track) {
  12950. trackElement_ = this.trackElements_[i];
  12951. break;
  12952. }
  12953. }
  12954. return trackElement_;
  12955. };
  12956. HtmlTrackElementList.prototype.removeTrackElement_ = function removeTrackElement_(trackElement) {
  12957. for (var i = 0, _length3 = this.trackElements_.length; i < _length3; i++) {
  12958. if (trackElement === this.trackElements_[i]) {
  12959. this.trackElements_.splice(i, 1);
  12960. break;
  12961. }
  12962. }
  12963. };
  12964. return HtmlTrackElementList;
  12965. })();
  12966. exports['default'] = HtmlTrackElementList;
  12967. module.exports = exports['default'];
  12968. },{"../utils/browser.js":129,"global/document":1}],121:[function(_dereq_,module,exports){
  12969. /**
  12970. * @file html-track-element.js
  12971. */
  12972. 'use strict';
  12973. exports.__esModule = true;
  12974. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  12975. 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; } }
  12976. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  12977. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  12978. var _utilsBrowserJs = _dereq_('../utils/browser.js');
  12979. var browser = _interopRequireWildcard(_utilsBrowserJs);
  12980. var _globalDocument = _dereq_('global/document');
  12981. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  12982. var _eventTarget = _dereq_('../event-target');
  12983. var _eventTarget2 = _interopRequireDefault(_eventTarget);
  12984. var _tracksTextTrack = _dereq_('../tracks/text-track');
  12985. var _tracksTextTrack2 = _interopRequireDefault(_tracksTextTrack);
  12986. var NONE = 0;
  12987. var LOADING = 1;
  12988. var LOADED = 2;
  12989. var ERROR = 3;
  12990. /**
  12991. * https://html.spec.whatwg.org/multipage/embedded-content.html#htmltrackelement
  12992. *
  12993. * interface HTMLTrackElement : HTMLElement {
  12994. * attribute DOMString kind;
  12995. * attribute DOMString src;
  12996. * attribute DOMString srclang;
  12997. * attribute DOMString label;
  12998. * attribute boolean default;
  12999. *
  13000. * const unsigned short NONE = 0;
  13001. * const unsigned short LOADING = 1;
  13002. * const unsigned short LOADED = 2;
  13003. * const unsigned short ERROR = 3;
  13004. * readonly attribute unsigned short readyState;
  13005. *
  13006. * readonly attribute TextTrack track;
  13007. * };
  13008. *
  13009. * @param {Object} options TextTrack configuration
  13010. * @class HTMLTrackElement
  13011. */
  13012. var HTMLTrackElement = (function (_EventTarget) {
  13013. _inherits(HTMLTrackElement, _EventTarget);
  13014. function HTMLTrackElement() {
  13015. var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  13016. _classCallCheck(this, HTMLTrackElement);
  13017. _EventTarget.call(this);
  13018. var readyState = undefined,
  13019. trackElement = this;
  13020. if (browser.IS_IE8) {
  13021. trackElement = _globalDocument2['default'].createElement('custom');
  13022. for (var prop in HTMLTrackElement.prototype) {
  13023. if (prop !== 'constructor') {
  13024. trackElement[prop] = HTMLTrackElement.prototype[prop];
  13025. }
  13026. }
  13027. }
  13028. var track = new _tracksTextTrack2['default'](options);
  13029. trackElement.kind = track.kind;
  13030. trackElement.src = track.src;
  13031. trackElement.srclang = track.language;
  13032. trackElement.label = track.label;
  13033. trackElement['default'] = track['default'];
  13034. Object.defineProperty(trackElement, 'readyState', {
  13035. get: function get() {
  13036. return readyState;
  13037. }
  13038. });
  13039. Object.defineProperty(trackElement, 'track', {
  13040. get: function get() {
  13041. return track;
  13042. }
  13043. });
  13044. readyState = NONE;
  13045. track.addEventListener('loadeddata', function () {
  13046. readyState = LOADED;
  13047. trackElement.trigger({
  13048. type: 'load',
  13049. target: trackElement
  13050. });
  13051. });
  13052. if (browser.IS_IE8) {
  13053. return trackElement;
  13054. }
  13055. }
  13056. return HTMLTrackElement;
  13057. })(_eventTarget2['default']);
  13058. HTMLTrackElement.prototype.allowedEvents_ = {
  13059. load: 'load'
  13060. };
  13061. HTMLTrackElement.NONE = NONE;
  13062. HTMLTrackElement.LOADING = LOADING;
  13063. HTMLTrackElement.LOADED = LOADED;
  13064. HTMLTrackElement.ERROR = ERROR;
  13065. exports['default'] = HTMLTrackElement;
  13066. module.exports = exports['default'];
  13067. },{"../event-target":99,"../tracks/text-track":128,"../utils/browser.js":129,"global/document":1}],122:[function(_dereq_,module,exports){
  13068. /**
  13069. * @file text-track-cue-list.js
  13070. */
  13071. 'use strict';
  13072. exports.__esModule = true;
  13073. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  13074. 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; } }
  13075. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  13076. var _utilsBrowserJs = _dereq_('../utils/browser.js');
  13077. var browser = _interopRequireWildcard(_utilsBrowserJs);
  13078. var _globalDocument = _dereq_('global/document');
  13079. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  13080. /**
  13081. * A List of text track cues as defined in:
  13082. * https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackcuelist
  13083. *
  13084. * interface TextTrackCueList {
  13085. * readonly attribute unsigned long length;
  13086. * getter TextTrackCue (unsigned long index);
  13087. * TextTrackCue? getCueById(DOMString id);
  13088. * };
  13089. *
  13090. * @param {Array} cues A list of cues to be initialized with
  13091. * @class TextTrackCueList
  13092. */
  13093. var TextTrackCueList = (function () {
  13094. function TextTrackCueList(cues) {
  13095. _classCallCheck(this, TextTrackCueList);
  13096. var list = this;
  13097. if (browser.IS_IE8) {
  13098. list = _globalDocument2['default'].createElement('custom');
  13099. for (var prop in TextTrackCueList.prototype) {
  13100. if (prop !== 'constructor') {
  13101. list[prop] = TextTrackCueList.prototype[prop];
  13102. }
  13103. }
  13104. }
  13105. TextTrackCueList.prototype.setCues_.call(list, cues);
  13106. Object.defineProperty(list, 'length', {
  13107. get: function get() {
  13108. return this.length_;
  13109. }
  13110. });
  13111. if (browser.IS_IE8) {
  13112. return list;
  13113. }
  13114. }
  13115. /**
  13116. * A setter for cues in this list
  13117. *
  13118. * @param {Array} cues an array of cues
  13119. * @method setCues_
  13120. * @private
  13121. */
  13122. TextTrackCueList.prototype.setCues_ = function setCues_(cues) {
  13123. var oldLength = this.length || 0;
  13124. var i = 0;
  13125. var l = cues.length;
  13126. this.cues_ = cues;
  13127. this.length_ = cues.length;
  13128. var defineProp = function defineProp(index) {
  13129. if (!('' + index in this)) {
  13130. Object.defineProperty(this, '' + index, {
  13131. get: function get() {
  13132. return this.cues_[index];
  13133. }
  13134. });
  13135. }
  13136. };
  13137. if (oldLength < l) {
  13138. i = oldLength;
  13139. for (; i < l; i++) {
  13140. defineProp.call(this, i);
  13141. }
  13142. }
  13143. };
  13144. /**
  13145. * Get a cue that is currently in the Cue list by id
  13146. *
  13147. * @param {String} id
  13148. * @method getCueById
  13149. * @return {Object} a single cue
  13150. */
  13151. TextTrackCueList.prototype.getCueById = function getCueById(id) {
  13152. var result = null;
  13153. for (var i = 0, l = this.length; i < l; i++) {
  13154. var cue = this[i];
  13155. if (cue.id === id) {
  13156. result = cue;
  13157. break;
  13158. }
  13159. }
  13160. return result;
  13161. };
  13162. return TextTrackCueList;
  13163. })();
  13164. exports['default'] = TextTrackCueList;
  13165. module.exports = exports['default'];
  13166. },{"../utils/browser.js":129,"global/document":1}],123:[function(_dereq_,module,exports){
  13167. /**
  13168. * @file text-track-display.js
  13169. */
  13170. 'use strict';
  13171. exports.__esModule = true;
  13172. 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; } }
  13173. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  13174. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  13175. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  13176. var _component = _dereq_('../component');
  13177. var _component2 = _interopRequireDefault(_component);
  13178. var _menuMenuJs = _dereq_('../menu/menu.js');
  13179. var _menuMenuJs2 = _interopRequireDefault(_menuMenuJs);
  13180. var _menuMenuItemJs = _dereq_('../menu/menu-item.js');
  13181. var _menuMenuItemJs2 = _interopRequireDefault(_menuMenuItemJs);
  13182. var _menuMenuButtonJs = _dereq_('../menu/menu-button.js');
  13183. var _menuMenuButtonJs2 = _interopRequireDefault(_menuMenuButtonJs);
  13184. var _utilsFnJs = _dereq_('../utils/fn.js');
  13185. var Fn = _interopRequireWildcard(_utilsFnJs);
  13186. var _globalDocument = _dereq_('global/document');
  13187. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  13188. var _globalWindow = _dereq_('global/window');
  13189. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  13190. var darkGray = '#222';
  13191. var lightGray = '#ccc';
  13192. var fontMap = {
  13193. monospace: 'monospace',
  13194. sansSerif: 'sans-serif',
  13195. serif: 'serif',
  13196. monospaceSansSerif: '"Andale Mono", "Lucida Console", monospace',
  13197. monospaceSerif: '"Courier New", monospace',
  13198. proportionalSansSerif: 'sans-serif',
  13199. proportionalSerif: 'serif',
  13200. casual: '"Comic Sans MS", Impact, fantasy',
  13201. script: '"Monotype Corsiva", cursive',
  13202. smallcaps: '"Andale Mono", "Lucida Console", monospace, sans-serif'
  13203. };
  13204. /**
  13205. * The component for displaying text track cues
  13206. *
  13207. * @param {Object} player Main Player
  13208. * @param {Object=} options Object of option names and values
  13209. * @param {Function=} ready Ready callback function
  13210. * @extends Component
  13211. * @class TextTrackDisplay
  13212. */
  13213. var TextTrackDisplay = (function (_Component) {
  13214. _inherits(TextTrackDisplay, _Component);
  13215. function TextTrackDisplay(player, options, ready) {
  13216. _classCallCheck(this, TextTrackDisplay);
  13217. _Component.call(this, player, options, ready);
  13218. player.on('loadstart', Fn.bind(this, this.toggleDisplay));
  13219. player.on('texttrackchange', Fn.bind(this, this.updateDisplay));
  13220. // This used to be called during player init, but was causing an error
  13221. // if a track should show by default and the display hadn't loaded yet.
  13222. // Should probably be moved to an external track loader when we support
  13223. // tracks that don't need a display.
  13224. player.ready(Fn.bind(this, function () {
  13225. if (player.tech_ && player.tech_['featuresNativeTextTracks']) {
  13226. this.hide();
  13227. return;
  13228. }
  13229. player.on('fullscreenchange', Fn.bind(this, this.updateDisplay));
  13230. var tracks = this.options_.playerOptions['tracks'] || [];
  13231. for (var i = 0; i < tracks.length; i++) {
  13232. var track = tracks[i];
  13233. this.player_.addRemoteTextTrack(track);
  13234. }
  13235. }));
  13236. }
  13237. /**
  13238. * Add cue HTML to display
  13239. *
  13240. * @param {Number} color Hex number for color, like #f0e
  13241. * @param {Number} opacity Value for opacity,0.0 - 1.0
  13242. * @return {RGBAColor} In the form 'rgba(255, 0, 0, 0.3)'
  13243. * @method constructColor
  13244. */
  13245. /**
  13246. * Toggle display texttracks
  13247. *
  13248. * @method toggleDisplay
  13249. */
  13250. TextTrackDisplay.prototype.toggleDisplay = function toggleDisplay() {
  13251. if (this.player_.tech_ && this.player_.tech_['featuresNativeTextTracks']) {
  13252. this.hide();
  13253. } else {
  13254. this.show();
  13255. }
  13256. };
  13257. /**
  13258. * Create the component's DOM element
  13259. *
  13260. * @return {Element}
  13261. * @method createEl
  13262. */
  13263. TextTrackDisplay.prototype.createEl = function createEl() {
  13264. return _Component.prototype.createEl.call(this, 'div', {
  13265. className: 'vjs-text-track-display'
  13266. });
  13267. };
  13268. /**
  13269. * Clear display texttracks
  13270. *
  13271. * @method clearDisplay
  13272. */
  13273. TextTrackDisplay.prototype.clearDisplay = function clearDisplay() {
  13274. if (typeof _globalWindow2['default']['WebVTT'] === 'function') {
  13275. _globalWindow2['default']['WebVTT']['processCues'](_globalWindow2['default'], [], this.el_);
  13276. }
  13277. };
  13278. /**
  13279. * Update display texttracks
  13280. *
  13281. * @method updateDisplay
  13282. */
  13283. TextTrackDisplay.prototype.updateDisplay = function updateDisplay() {
  13284. var tracks = this.player_.textTracks();
  13285. this.clearDisplay();
  13286. if (!tracks) {
  13287. return;
  13288. }
  13289. for (var i = 0; i < tracks.length; i++) {
  13290. var track = tracks[i];
  13291. if (track['mode'] === 'showing') {
  13292. this.updateForTrack(track);
  13293. }
  13294. }
  13295. };
  13296. /**
  13297. * Add texttrack to texttrack list
  13298. *
  13299. * @param {TextTrackObject} track Texttrack object to be added to list
  13300. * @method updateForTrack
  13301. */
  13302. TextTrackDisplay.prototype.updateForTrack = function updateForTrack(track) {
  13303. if (typeof _globalWindow2['default']['WebVTT'] !== 'function' || !track['activeCues']) {
  13304. return;
  13305. }
  13306. var overrides = this.player_['textTrackSettings'].getValues();
  13307. var cues = [];
  13308. for (var _i = 0; _i < track['activeCues'].length; _i++) {
  13309. cues.push(track['activeCues'][_i]);
  13310. }
  13311. _globalWindow2['default']['WebVTT']['processCues'](_globalWindow2['default'], track['activeCues'], this.el_);
  13312. var i = cues.length;
  13313. while (i--) {
  13314. var cue = cues[i];
  13315. if (!cue) {
  13316. continue;
  13317. }
  13318. var cueDiv = cue.displayState;
  13319. if (overrides.color) {
  13320. cueDiv.firstChild.style.color = overrides.color;
  13321. }
  13322. if (overrides.textOpacity) {
  13323. tryUpdateStyle(cueDiv.firstChild, 'color', constructColor(overrides.color || '#fff', overrides.textOpacity));
  13324. }
  13325. if (overrides.backgroundColor) {
  13326. cueDiv.firstChild.style.backgroundColor = overrides.backgroundColor;
  13327. }
  13328. if (overrides.backgroundOpacity) {
  13329. tryUpdateStyle(cueDiv.firstChild, 'backgroundColor', constructColor(overrides.backgroundColor || '#000', overrides.backgroundOpacity));
  13330. }
  13331. if (overrides.windowColor) {
  13332. if (overrides.windowOpacity) {
  13333. tryUpdateStyle(cueDiv, 'backgroundColor', constructColor(overrides.windowColor, overrides.windowOpacity));
  13334. } else {
  13335. cueDiv.style.backgroundColor = overrides.windowColor;
  13336. }
  13337. }
  13338. if (overrides.edgeStyle) {
  13339. if (overrides.edgeStyle === 'dropshadow') {
  13340. cueDiv.firstChild.style.textShadow = '2px 2px 3px ' + darkGray + ', 2px 2px 4px ' + darkGray + ', 2px 2px 5px ' + darkGray;
  13341. } else if (overrides.edgeStyle === 'raised') {
  13342. cueDiv.firstChild.style.textShadow = '1px 1px ' + darkGray + ', 2px 2px ' + darkGray + ', 3px 3px ' + darkGray;
  13343. } else if (overrides.edgeStyle === 'depressed') {
  13344. cueDiv.firstChild.style.textShadow = '1px 1px ' + lightGray + ', 0 1px ' + lightGray + ', -1px -1px ' + darkGray + ', 0 -1px ' + darkGray;
  13345. } else if (overrides.edgeStyle === 'uniform') {
  13346. cueDiv.firstChild.style.textShadow = '0 0 4px ' + darkGray + ', 0 0 4px ' + darkGray + ', 0 0 4px ' + darkGray + ', 0 0 4px ' + darkGray;
  13347. }
  13348. }
  13349. if (overrides.fontPercent && overrides.fontPercent !== 1) {
  13350. var fontSize = _globalWindow2['default'].parseFloat(cueDiv.style.fontSize);
  13351. cueDiv.style.fontSize = fontSize * overrides.fontPercent + 'px';
  13352. cueDiv.style.height = 'auto';
  13353. cueDiv.style.top = 'auto';
  13354. cueDiv.style.bottom = '2px';
  13355. }
  13356. if (overrides.fontFamily && overrides.fontFamily !== 'default') {
  13357. if (overrides.fontFamily === 'small-caps') {
  13358. cueDiv.firstChild.style.fontVariant = 'small-caps';
  13359. } else {
  13360. cueDiv.firstChild.style.fontFamily = fontMap[overrides.fontFamily];
  13361. }
  13362. }
  13363. }
  13364. };
  13365. return TextTrackDisplay;
  13366. })(_component2['default']);
  13367. function constructColor(color, opacity) {
  13368. return 'rgba(' +
  13369. // color looks like "#f0e"
  13370. parseInt(color[1] + color[1], 16) + ',' + parseInt(color[2] + color[2], 16) + ',' + parseInt(color[3] + color[3], 16) + ',' + opacity + ')';
  13371. }
  13372. /**
  13373. * Try to update style
  13374. * Some style changes will throw an error, particularly in IE8. Those should be noops.
  13375. *
  13376. * @param {Element} el The element to be styles
  13377. * @param {CSSProperty} style The CSS property to be styled
  13378. * @param {CSSStyle} rule The actual style to be applied to the property
  13379. * @method tryUpdateStyle
  13380. */
  13381. function tryUpdateStyle(el, style, rule) {
  13382. //
  13383. try {
  13384. el.style[style] = rule;
  13385. } catch (e) {}
  13386. }
  13387. _component2['default'].registerComponent('TextTrackDisplay', TextTrackDisplay);
  13388. exports['default'] = TextTrackDisplay;
  13389. module.exports = exports['default'];
  13390. },{"../component":67,"../menu/menu-button.js":104,"../menu/menu-item.js":105,"../menu/menu.js":106,"../utils/fn.js":134,"global/document":1,"global/window":2}],124:[function(_dereq_,module,exports){
  13391. /**
  13392. * @file text-track-enums.js
  13393. */
  13394. /**
  13395. * https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackmode
  13396. *
  13397. * enum TextTrackMode { "disabled", "hidden", "showing" };
  13398. */
  13399. 'use strict';
  13400. exports.__esModule = true;
  13401. var TextTrackMode = {
  13402. disabled: 'disabled',
  13403. hidden: 'hidden',
  13404. showing: 'showing'
  13405. };
  13406. /**
  13407. * https://html.spec.whatwg.org/multipage/embedded-content.html#texttrackkind
  13408. *
  13409. * enum TextTrackKind {
  13410. * "subtitles",
  13411. * "captions",
  13412. * "descriptions",
  13413. * "chapters",
  13414. * "metadata"
  13415. * };
  13416. */
  13417. var TextTrackKind = {
  13418. subtitles: 'subtitles',
  13419. captions: 'captions',
  13420. descriptions: 'descriptions',
  13421. chapters: 'chapters',
  13422. metadata: 'metadata'
  13423. };
  13424. /* jshint ignore:start */
  13425. // we ignore jshint here because it does not see
  13426. // TextTrackMode or TextTrackKind as defined here somehow...
  13427. exports.TextTrackMode = TextTrackMode;
  13428. exports.TextTrackKind = TextTrackKind;
  13429. /* jshint ignore:end */
  13430. },{}],125:[function(_dereq_,module,exports){
  13431. /**
  13432. * Utilities for capturing text track state and re-creating tracks
  13433. * based on a capture.
  13434. *
  13435. * @file text-track-list-converter.js
  13436. */
  13437. /**
  13438. * Examine a single text track and return a JSON-compatible javascript
  13439. * object that represents the text track's state.
  13440. * @param track {TextTrackObject} the text track to query
  13441. * @return {Object} a serializable javascript representation of the
  13442. * @private
  13443. */
  13444. 'use strict';
  13445. exports.__esModule = true;
  13446. var trackToJson_ = function trackToJson_(track) {
  13447. var ret = ['kind', 'label', 'language', 'id', 'inBandMetadataTrackDispatchType', 'mode', 'src'].reduce(function (acc, prop, i) {
  13448. if (track[prop]) {
  13449. acc[prop] = track[prop];
  13450. }
  13451. return acc;
  13452. }, {
  13453. cues: track.cues && Array.prototype.map.call(track.cues, function (cue) {
  13454. return {
  13455. startTime: cue.startTime,
  13456. endTime: cue.endTime,
  13457. text: cue.text,
  13458. id: cue.id
  13459. };
  13460. })
  13461. });
  13462. return ret;
  13463. };
  13464. /**
  13465. * Examine a tech and return a JSON-compatible javascript array that
  13466. * represents the state of all text tracks currently configured. The
  13467. * return array is compatible with `jsonToTextTracks`.
  13468. * @param tech {tech} the tech object to query
  13469. * @return {Array} a serializable javascript representation of the
  13470. * @function textTracksToJson
  13471. */
  13472. var textTracksToJson = function textTracksToJson(tech) {
  13473. var trackEls = tech.$$('track');
  13474. var trackObjs = Array.prototype.map.call(trackEls, function (t) {
  13475. return t.track;
  13476. });
  13477. var tracks = Array.prototype.map.call(trackEls, function (trackEl) {
  13478. var json = trackToJson_(trackEl.track);
  13479. if (trackEl.src) {
  13480. json.src = trackEl.src;
  13481. }
  13482. return json;
  13483. });
  13484. return tracks.concat(Array.prototype.filter.call(tech.textTracks(), function (track) {
  13485. return trackObjs.indexOf(track) === -1;
  13486. }).map(trackToJson_));
  13487. };
  13488. /**
  13489. * Creates a set of remote text tracks on a tech based on an array of
  13490. * javascript text track representations.
  13491. * @param json {Array} an array of text track representation objects,
  13492. * like those that would be produced by `textTracksToJson`
  13493. * @param tech {tech} the tech to create text tracks on
  13494. * @function jsonToTextTracks
  13495. */
  13496. var jsonToTextTracks = function jsonToTextTracks(json, tech) {
  13497. json.forEach(function (track) {
  13498. var addedTrack = tech.addRemoteTextTrack(track).track;
  13499. if (!track.src && track.cues) {
  13500. track.cues.forEach(function (cue) {
  13501. return addedTrack.addCue(cue);
  13502. });
  13503. }
  13504. });
  13505. return tech.textTracks();
  13506. };
  13507. exports['default'] = { textTracksToJson: textTracksToJson, jsonToTextTracks: jsonToTextTracks, trackToJson_: trackToJson_ };
  13508. module.exports = exports['default'];
  13509. },{}],126:[function(_dereq_,module,exports){
  13510. /**
  13511. * @file text-track-list.js
  13512. */
  13513. 'use strict';
  13514. exports.__esModule = true;
  13515. 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; } }
  13516. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  13517. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  13518. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  13519. var _eventTarget = _dereq_('../event-target');
  13520. var _eventTarget2 = _interopRequireDefault(_eventTarget);
  13521. var _utilsFnJs = _dereq_('../utils/fn.js');
  13522. var Fn = _interopRequireWildcard(_utilsFnJs);
  13523. var _utilsBrowserJs = _dereq_('../utils/browser.js');
  13524. var browser = _interopRequireWildcard(_utilsBrowserJs);
  13525. var _globalDocument = _dereq_('global/document');
  13526. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  13527. /**
  13528. * A text track list as defined in:
  13529. * https://html.spec.whatwg.org/multipage/embedded-content.html#texttracklist
  13530. *
  13531. * interface TextTrackList : EventTarget {
  13532. * readonly attribute unsigned long length;
  13533. * getter TextTrack (unsigned long index);
  13534. * TextTrack? getTrackById(DOMString id);
  13535. *
  13536. * attribute EventHandler onchange;
  13537. * attribute EventHandler onaddtrack;
  13538. * attribute EventHandler onremovetrack;
  13539. * };
  13540. *
  13541. * @param {Track[]} tracks A list of tracks to initialize the list with
  13542. * @extends EventTarget
  13543. * @class TextTrackList
  13544. */
  13545. var TextTrackList = (function (_EventTarget) {
  13546. _inherits(TextTrackList, _EventTarget);
  13547. function TextTrackList() {
  13548. var tracks = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
  13549. _classCallCheck(this, TextTrackList);
  13550. _EventTarget.call(this);
  13551. var list = this;
  13552. if (browser.IS_IE8) {
  13553. list = _globalDocument2['default'].createElement('custom');
  13554. for (var prop in TextTrackList.prototype) {
  13555. if (prop !== 'constructor') {
  13556. list[prop] = TextTrackList.prototype[prop];
  13557. }
  13558. }
  13559. }
  13560. list.tracks_ = [];
  13561. Object.defineProperty(list, 'length', {
  13562. get: function get() {
  13563. return this.tracks_.length;
  13564. }
  13565. });
  13566. for (var i = 0; i < tracks.length; i++) {
  13567. list.addTrack_(tracks[i]);
  13568. }
  13569. if (browser.IS_IE8) {
  13570. return list;
  13571. }
  13572. }
  13573. /**
  13574. * change - One or more tracks in the track list have been enabled or disabled.
  13575. * addtrack - A track has been added to the track list.
  13576. * removetrack - A track has been removed from the track list.
  13577. */
  13578. /**
  13579. * Add TextTrack from TextTrackList
  13580. *
  13581. * @param {TextTrack} track
  13582. * @method addTrack_
  13583. * @private
  13584. */
  13585. TextTrackList.prototype.addTrack_ = function addTrack_(track) {
  13586. var index = this.tracks_.length;
  13587. if (!('' + index in this)) {
  13588. Object.defineProperty(this, index, {
  13589. get: function get() {
  13590. return this.tracks_[index];
  13591. }
  13592. });
  13593. }
  13594. track.addEventListener('modechange', Fn.bind(this, function () {
  13595. this.trigger('change');
  13596. }));
  13597. // Do not add duplicate tracks
  13598. if (this.tracks_.indexOf(track) === -1) {
  13599. this.tracks_.push(track);
  13600. this.trigger({
  13601. track: track,
  13602. type: 'addtrack'
  13603. });
  13604. }
  13605. };
  13606. /**
  13607. * Remove TextTrack from TextTrackList
  13608. * NOTE: Be mindful of what is passed in as it may be a HTMLTrackElement
  13609. *
  13610. * @param {TextTrack} rtrack
  13611. * @method removeTrack_
  13612. * @private
  13613. */
  13614. TextTrackList.prototype.removeTrack_ = function removeTrack_(rtrack) {
  13615. var track = undefined;
  13616. for (var i = 0, l = this.length; i < l; i++) {
  13617. if (this[i] === rtrack) {
  13618. track = this[i];
  13619. if (track.off) {
  13620. track.off();
  13621. }
  13622. this.tracks_.splice(i, 1);
  13623. break;
  13624. }
  13625. }
  13626. if (!track) {
  13627. return;
  13628. }
  13629. this.trigger({
  13630. track: track,
  13631. type: 'removetrack'
  13632. });
  13633. };
  13634. /**
  13635. * Get a TextTrack from TextTrackList by a tracks id
  13636. *
  13637. * @param {String} id - the id of the track to get
  13638. * @method getTrackById
  13639. * @return {TextTrack}
  13640. * @private
  13641. */
  13642. TextTrackList.prototype.getTrackById = function getTrackById(id) {
  13643. var result = null;
  13644. for (var i = 0, l = this.length; i < l; i++) {
  13645. var track = this[i];
  13646. if (track.id === id) {
  13647. result = track;
  13648. break;
  13649. }
  13650. }
  13651. return result;
  13652. };
  13653. return TextTrackList;
  13654. })(_eventTarget2['default']);
  13655. TextTrackList.prototype.allowedEvents_ = {
  13656. change: 'change',
  13657. addtrack: 'addtrack',
  13658. removetrack: 'removetrack'
  13659. };
  13660. // emulate attribute EventHandler support to allow for feature detection
  13661. for (var _event in TextTrackList.prototype.allowedEvents_) {
  13662. TextTrackList.prototype['on' + _event] = null;
  13663. }
  13664. exports['default'] = TextTrackList;
  13665. module.exports = exports['default'];
  13666. },{"../event-target":99,"../utils/browser.js":129,"../utils/fn.js":134,"global/document":1}],127:[function(_dereq_,module,exports){
  13667. /**
  13668. * @file text-track-settings.js
  13669. */
  13670. 'use strict';
  13671. exports.__esModule = true;
  13672. 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; } }
  13673. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  13674. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  13675. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  13676. var _component = _dereq_('../component');
  13677. var _component2 = _interopRequireDefault(_component);
  13678. var _utilsEventsJs = _dereq_('../utils/events.js');
  13679. var Events = _interopRequireWildcard(_utilsEventsJs);
  13680. var _utilsFnJs = _dereq_('../utils/fn.js');
  13681. var Fn = _interopRequireWildcard(_utilsFnJs);
  13682. var _utilsLogJs = _dereq_('../utils/log.js');
  13683. var _utilsLogJs2 = _interopRequireDefault(_utilsLogJs);
  13684. var _safeJsonParseTuple = _dereq_('safe-json-parse/tuple');
  13685. var _safeJsonParseTuple2 = _interopRequireDefault(_safeJsonParseTuple);
  13686. var _globalWindow = _dereq_('global/window');
  13687. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  13688. /**
  13689. * Manipulate settings of texttracks
  13690. *
  13691. * @param {Object} player Main Player
  13692. * @param {Object=} options Object of option names and values
  13693. * @extends Component
  13694. * @class TextTrackSettings
  13695. */
  13696. var TextTrackSettings = (function (_Component) {
  13697. _inherits(TextTrackSettings, _Component);
  13698. function TextTrackSettings(player, options) {
  13699. _classCallCheck(this, TextTrackSettings);
  13700. _Component.call(this, player, options);
  13701. this.hide();
  13702. // Grab `persistTextTrackSettings` from the player options if not passed in child options
  13703. if (options.persistTextTrackSettings === undefined) {
  13704. this.options_.persistTextTrackSettings = this.options_.playerOptions.persistTextTrackSettings;
  13705. }
  13706. Events.on(this.$('.vjs-done-button'), 'click', Fn.bind(this, function () {
  13707. this.saveSettings();
  13708. this.hide();
  13709. }));
  13710. Events.on(this.$('.vjs-default-button'), 'click', Fn.bind(this, function () {
  13711. this.$('.vjs-fg-color > select').selectedIndex = 0;
  13712. this.$('.vjs-bg-color > select').selectedIndex = 0;
  13713. this.$('.window-color > select').selectedIndex = 0;
  13714. this.$('.vjs-text-opacity > select').selectedIndex = 0;
  13715. this.$('.vjs-bg-opacity > select').selectedIndex = 0;
  13716. this.$('.vjs-window-opacity > select').selectedIndex = 0;
  13717. this.$('.vjs-edge-style select').selectedIndex = 0;
  13718. this.$('.vjs-font-family select').selectedIndex = 0;
  13719. this.$('.vjs-font-percent select').selectedIndex = 2;
  13720. this.updateDisplay();
  13721. }));
  13722. Events.on(this.$('.vjs-fg-color > select'), 'change', Fn.bind(this, this.updateDisplay));
  13723. Events.on(this.$('.vjs-bg-color > select'), 'change', Fn.bind(this, this.updateDisplay));
  13724. Events.on(this.$('.window-color > select'), 'change', Fn.bind(this, this.updateDisplay));
  13725. Events.on(this.$('.vjs-text-opacity > select'), 'change', Fn.bind(this, this.updateDisplay));
  13726. Events.on(this.$('.vjs-bg-opacity > select'), 'change', Fn.bind(this, this.updateDisplay));
  13727. Events.on(this.$('.vjs-window-opacity > select'), 'change', Fn.bind(this, this.updateDisplay));
  13728. Events.on(this.$('.vjs-font-percent select'), 'change', Fn.bind(this, this.updateDisplay));
  13729. Events.on(this.$('.vjs-edge-style select'), 'change', Fn.bind(this, this.updateDisplay));
  13730. Events.on(this.$('.vjs-font-family select'), 'change', Fn.bind(this, this.updateDisplay));
  13731. if (this.options_.persistTextTrackSettings) {
  13732. this.restoreSettings();
  13733. }
  13734. }
  13735. /**
  13736. * Create the component's DOM element
  13737. *
  13738. * @return {Element}
  13739. * @method createEl
  13740. */
  13741. TextTrackSettings.prototype.createEl = function createEl() {
  13742. return _Component.prototype.createEl.call(this, 'div', {
  13743. className: 'vjs-caption-settings vjs-modal-overlay',
  13744. innerHTML: captionOptionsMenuTemplate()
  13745. });
  13746. };
  13747. /**
  13748. * Get texttrack settings
  13749. * Settings are
  13750. * .vjs-edge-style
  13751. * .vjs-font-family
  13752. * .vjs-fg-color
  13753. * .vjs-text-opacity
  13754. * .vjs-bg-color
  13755. * .vjs-bg-opacity
  13756. * .window-color
  13757. * .vjs-window-opacity
  13758. *
  13759. * @return {Object}
  13760. * @method getValues
  13761. */
  13762. TextTrackSettings.prototype.getValues = function getValues() {
  13763. var textEdge = getSelectedOptionValue(this.$('.vjs-edge-style select'));
  13764. var fontFamily = getSelectedOptionValue(this.$('.vjs-font-family select'));
  13765. var fgColor = getSelectedOptionValue(this.$('.vjs-fg-color > select'));
  13766. var textOpacity = getSelectedOptionValue(this.$('.vjs-text-opacity > select'));
  13767. var bgColor = getSelectedOptionValue(this.$('.vjs-bg-color > select'));
  13768. var bgOpacity = getSelectedOptionValue(this.$('.vjs-bg-opacity > select'));
  13769. var windowColor = getSelectedOptionValue(this.$('.window-color > select'));
  13770. var windowOpacity = getSelectedOptionValue(this.$('.vjs-window-opacity > select'));
  13771. var fontPercent = _globalWindow2['default']['parseFloat'](getSelectedOptionValue(this.$('.vjs-font-percent > select')));
  13772. var result = {
  13773. 'backgroundOpacity': bgOpacity,
  13774. 'textOpacity': textOpacity,
  13775. 'windowOpacity': windowOpacity,
  13776. 'edgeStyle': textEdge,
  13777. 'fontFamily': fontFamily,
  13778. 'color': fgColor,
  13779. 'backgroundColor': bgColor,
  13780. 'windowColor': windowColor,
  13781. 'fontPercent': fontPercent
  13782. };
  13783. for (var _name in result) {
  13784. if (result[_name] === '' || result[_name] === 'none' || _name === 'fontPercent' && result[_name] === 1.00) {
  13785. delete result[_name];
  13786. }
  13787. }
  13788. return result;
  13789. };
  13790. /**
  13791. * Set texttrack settings
  13792. * Settings are
  13793. * .vjs-edge-style
  13794. * .vjs-font-family
  13795. * .vjs-fg-color
  13796. * .vjs-text-opacity
  13797. * .vjs-bg-color
  13798. * .vjs-bg-opacity
  13799. * .window-color
  13800. * .vjs-window-opacity
  13801. *
  13802. * @param {Object} values Object with texttrack setting values
  13803. * @method setValues
  13804. */
  13805. TextTrackSettings.prototype.setValues = function setValues(values) {
  13806. setSelectedOption(this.$('.vjs-edge-style select'), values.edgeStyle);
  13807. setSelectedOption(this.$('.vjs-font-family select'), values.fontFamily);
  13808. setSelectedOption(this.$('.vjs-fg-color > select'), values.color);
  13809. setSelectedOption(this.$('.vjs-text-opacity > select'), values.textOpacity);
  13810. setSelectedOption(this.$('.vjs-bg-color > select'), values.backgroundColor);
  13811. setSelectedOption(this.$('.vjs-bg-opacity > select'), values.backgroundOpacity);
  13812. setSelectedOption(this.$('.window-color > select'), values.windowColor);
  13813. setSelectedOption(this.$('.vjs-window-opacity > select'), values.windowOpacity);
  13814. var fontPercent = values.fontPercent;
  13815. if (fontPercent) {
  13816. fontPercent = fontPercent.toFixed(2);
  13817. }
  13818. setSelectedOption(this.$('.vjs-font-percent > select'), fontPercent);
  13819. };
  13820. /**
  13821. * Restore texttrack settings
  13822. *
  13823. * @method restoreSettings
  13824. */
  13825. TextTrackSettings.prototype.restoreSettings = function restoreSettings() {
  13826. var err = undefined,
  13827. values = undefined;
  13828. try {
  13829. var _safeParseTuple = _safeJsonParseTuple2['default'](_globalWindow2['default'].localStorage.getItem('vjs-text-track-settings'));
  13830. err = _safeParseTuple[0];
  13831. values = _safeParseTuple[1];
  13832. if (err) {
  13833. _utilsLogJs2['default'].error(err);
  13834. }
  13835. } catch (e) {
  13836. _utilsLogJs2['default'].warn(e);
  13837. }
  13838. if (values) {
  13839. this.setValues(values);
  13840. }
  13841. };
  13842. /**
  13843. * Save texttrack settings to local storage
  13844. *
  13845. * @method saveSettings
  13846. */
  13847. TextTrackSettings.prototype.saveSettings = function saveSettings() {
  13848. if (!this.options_.persistTextTrackSettings) {
  13849. return;
  13850. }
  13851. var values = this.getValues();
  13852. try {
  13853. if (Object.getOwnPropertyNames(values).length > 0) {
  13854. _globalWindow2['default'].localStorage.setItem('vjs-text-track-settings', JSON.stringify(values));
  13855. } else {
  13856. _globalWindow2['default'].localStorage.removeItem('vjs-text-track-settings');
  13857. }
  13858. } catch (e) {
  13859. _utilsLogJs2['default'].warn(e);
  13860. }
  13861. };
  13862. /**
  13863. * Update display of texttrack settings
  13864. *
  13865. * @method updateDisplay
  13866. */
  13867. TextTrackSettings.prototype.updateDisplay = function updateDisplay() {
  13868. var ttDisplay = this.player_.getChild('textTrackDisplay');
  13869. if (ttDisplay) {
  13870. ttDisplay.updateDisplay();
  13871. }
  13872. };
  13873. return TextTrackSettings;
  13874. })(_component2['default']);
  13875. _component2['default'].registerComponent('TextTrackSettings', TextTrackSettings);
  13876. function getSelectedOptionValue(target) {
  13877. var selectedOption = undefined;
  13878. // not all browsers support selectedOptions, so, fallback to options
  13879. if (target.selectedOptions) {
  13880. selectedOption = target.selectedOptions[0];
  13881. } else if (target.options) {
  13882. selectedOption = target.options[target.options.selectedIndex];
  13883. }
  13884. return selectedOption.value;
  13885. }
  13886. function setSelectedOption(target, value) {
  13887. if (!value) {
  13888. return;
  13889. }
  13890. var i = undefined;
  13891. for (i = 0; i < target.options.length; i++) {
  13892. var option = target.options[i];
  13893. if (option.value === value) {
  13894. break;
  13895. }
  13896. }
  13897. target.selectedIndex = i;
  13898. }
  13899. function captionOptionsMenuTemplate() {
  13900. var template = '<div class="vjs-tracksettings">\n <div class="vjs-tracksettings-colors">\n <div class="vjs-fg-color vjs-tracksetting">\n <label class="vjs-label">Foreground</label>\n <select>\n <option value="">---</option>\n <option value="#FFF">White</option>\n <option value="#000">Black</option>\n <option value="#F00">Red</option>\n <option value="#0F0">Green</option>\n <option value="#00F">Blue</option>\n <option value="#FF0">Yellow</option>\n <option value="#F0F">Magenta</option>\n <option value="#0FF">Cyan</option>\n </select>\n <span class="vjs-text-opacity vjs-opacity">\n <select>\n <option value="">---</option>\n <option value="1">Opaque</option>\n <option value="0.5">Semi-Opaque</option>\n </select>\n </span>\n </div> <!-- vjs-fg-color -->\n <div class="vjs-bg-color vjs-tracksetting">\n <label class="vjs-label">Background</label>\n <select>\n <option value="">---</option>\n <option value="#FFF">White</option>\n <option value="#000">Black</option>\n <option value="#F00">Red</option>\n <option value="#0F0">Green</option>\n <option value="#00F">Blue</option>\n <option value="#FF0">Yellow</option>\n <option value="#F0F">Magenta</option>\n <option value="#0FF">Cyan</option>\n </select>\n <span class="vjs-bg-opacity vjs-opacity">\n <select>\n <option value="">---</option>\n <option value="1">Opaque</option>\n <option value="0.5">Semi-Transparent</option>\n <option value="0">Transparent</option>\n </select>\n </span>\n </div> <!-- vjs-bg-color -->\n <div class="window-color vjs-tracksetting">\n <label class="vjs-label">Window</label>\n <select>\n <option value="">---</option>\n <option value="#FFF">White</option>\n <option value="#000">Black</option>\n <option value="#F00">Red</option>\n <option value="#0F0">Green</option>\n <option value="#00F">Blue</option>\n <option value="#FF0">Yellow</option>\n <option value="#F0F">Magenta</option>\n <option value="#0FF">Cyan</option>\n </select>\n <span class="vjs-window-opacity vjs-opacity">\n <select>\n <option value="">---</option>\n <option value="1">Opaque</option>\n <option value="0.5">Semi-Transparent</option>\n <option value="0">Transparent</option>\n </select>\n </span>\n </div> <!-- vjs-window-color -->\n </div> <!-- vjs-tracksettings -->\n <div class="vjs-tracksettings-font">\n <div class="vjs-font-percent vjs-tracksetting">\n <label class="vjs-label">Font Size</label>\n <select>\n <option value="0.50">50%</option>\n <option value="0.75">75%</option>\n <option value="1.00" selected>100%</option>\n <option value="1.25">125%</option>\n <option value="1.50">150%</option>\n <option value="1.75">175%</option>\n <option value="2.00">200%</option>\n <option value="3.00">300%</option>\n <option value="4.00">400%</option>\n </select>\n </div> <!-- vjs-font-percent -->\n <div class="vjs-edge-style vjs-tracksetting">\n <label class="vjs-label">Text Edge Style</label>\n <select>\n <option value="none">None</option>\n <option value="raised">Raised</option>\n <option value="depressed">Depressed</option>\n <option value="uniform">Uniform</option>\n <option value="dropshadow">Dropshadow</option>\n </select>\n </div> <!-- vjs-edge-style -->\n <div class="vjs-font-family vjs-tracksetting">\n <label class="vjs-label">Font Family</label>\n <select>\n <option value="">Default</option>\n <option value="monospaceSerif">Monospace Serif</option>\n <option value="proportionalSerif">Proportional Serif</option>\n <option value="monospaceSansSerif">Monospace Sans-Serif</option>\n <option value="proportionalSansSerif">Proportional Sans-Serif</option>\n <option value="casual">Casual</option>\n <option value="script">Script</option>\n <option value="small-caps">Small Caps</option>\n </select>\n </div> <!-- vjs-font-family -->\n </div>\n </div>\n <div class="vjs-tracksettings-controls">\n <button class="vjs-default-button">Defaults</button>\n <button class="vjs-done-button">Done</button>\n </div>';
  13901. return template;
  13902. }
  13903. exports['default'] = TextTrackSettings;
  13904. module.exports = exports['default'];
  13905. },{"../component":67,"../utils/events.js":133,"../utils/fn.js":134,"../utils/log.js":137,"global/window":2,"safe-json-parse/tuple":54}],128:[function(_dereq_,module,exports){
  13906. /**
  13907. * @file text-track.js
  13908. */
  13909. 'use strict';
  13910. exports.__esModule = true;
  13911. 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; } }
  13912. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  13913. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  13914. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  13915. var _textTrackCueList = _dereq_('./text-track-cue-list');
  13916. var _textTrackCueList2 = _interopRequireDefault(_textTrackCueList);
  13917. var _utilsFnJs = _dereq_('../utils/fn.js');
  13918. var Fn = _interopRequireWildcard(_utilsFnJs);
  13919. var _utilsGuidJs = _dereq_('../utils/guid.js');
  13920. var Guid = _interopRequireWildcard(_utilsGuidJs);
  13921. var _utilsBrowserJs = _dereq_('../utils/browser.js');
  13922. var browser = _interopRequireWildcard(_utilsBrowserJs);
  13923. var _textTrackEnums = _dereq_('./text-track-enums');
  13924. var TextTrackEnum = _interopRequireWildcard(_textTrackEnums);
  13925. var _utilsLogJs = _dereq_('../utils/log.js');
  13926. var _utilsLogJs2 = _interopRequireDefault(_utilsLogJs);
  13927. var _eventTarget = _dereq_('../event-target');
  13928. var _eventTarget2 = _interopRequireDefault(_eventTarget);
  13929. var _globalDocument = _dereq_('global/document');
  13930. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  13931. var _globalWindow = _dereq_('global/window');
  13932. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  13933. var _utilsUrlJs = _dereq_('../utils/url.js');
  13934. var _xhr = _dereq_('xhr');
  13935. var _xhr2 = _interopRequireDefault(_xhr);
  13936. /**
  13937. * takes a webvtt file contents and parses it into cues
  13938. *
  13939. * @param {String} srcContent webVTT file contents
  13940. * @param {Track} track track to addcues to
  13941. */
  13942. var parseCues = function parseCues(srcContent, track) {
  13943. var parser = new _globalWindow2['default'].WebVTT.Parser(_globalWindow2['default'], _globalWindow2['default'].vttjs, _globalWindow2['default'].WebVTT.StringDecoder());
  13944. parser.oncue = function (cue) {
  13945. track.addCue(cue);
  13946. };
  13947. parser.onparsingerror = function (error) {
  13948. _utilsLogJs2['default'].error(error);
  13949. };
  13950. parser.onflush = function () {
  13951. track.trigger({
  13952. type: 'loadeddata',
  13953. target: track
  13954. });
  13955. };
  13956. parser.parse(srcContent);
  13957. parser.flush();
  13958. };
  13959. /**
  13960. * load a track from a specifed url
  13961. *
  13962. * @param {String} src url to load track from
  13963. * @param {Track} track track to addcues to
  13964. */
  13965. var loadTrack = function loadTrack(src, track) {
  13966. var opts = {
  13967. uri: src
  13968. };
  13969. var crossOrigin = _utilsUrlJs.isCrossOrigin(src);
  13970. if (crossOrigin) {
  13971. opts.cors = crossOrigin;
  13972. }
  13973. _xhr2['default'](opts, Fn.bind(this, function (err, response, responseBody) {
  13974. if (err) {
  13975. return _utilsLogJs2['default'].error(err, response);
  13976. }
  13977. track.loaded_ = true;
  13978. // Make sure that vttjs has loaded, otherwise, wait till it finished loading
  13979. // NOTE: this is only used for the alt/video.novtt.js build
  13980. if (typeof _globalWindow2['default'].WebVTT !== 'function') {
  13981. if (track.tech_) {
  13982. (function () {
  13983. var loadHandler = function loadHandler() {
  13984. return parseCues(responseBody, track);
  13985. };
  13986. track.tech_.on('vttjsloaded', loadHandler);
  13987. track.tech_.on('vttjserror', function () {
  13988. _utilsLogJs2['default'].error('vttjs failed to load, stopping trying to process ' + track.src);
  13989. track.tech_.off('vttjsloaded', loadHandler);
  13990. });
  13991. })();
  13992. }
  13993. } else {
  13994. parseCues(responseBody, track);
  13995. }
  13996. }));
  13997. };
  13998. /**
  13999. * A single text track as defined in:
  14000. * https://html.spec.whatwg.org/multipage/embedded-content.html#texttrack
  14001. *
  14002. * interface TextTrack : EventTarget {
  14003. * readonly attribute TextTrackKind kind;
  14004. * readonly attribute DOMString label;
  14005. * readonly attribute DOMString language;
  14006. *
  14007. * readonly attribute DOMString id;
  14008. * readonly attribute DOMString inBandMetadataTrackDispatchType;
  14009. *
  14010. * attribute TextTrackMode mode;
  14011. *
  14012. * readonly attribute TextTrackCueList? cues;
  14013. * readonly attribute TextTrackCueList? activeCues;
  14014. *
  14015. * void addCue(TextTrackCue cue);
  14016. * void removeCue(TextTrackCue cue);
  14017. *
  14018. * attribute EventHandler oncuechange;
  14019. * };
  14020. *
  14021. * @param {Object=} options Object of option names and values
  14022. * @extends EventTarget
  14023. * @class TextTrack
  14024. */
  14025. var TextTrack = (function (_EventTarget) {
  14026. _inherits(TextTrack, _EventTarget);
  14027. function TextTrack() {
  14028. var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
  14029. _classCallCheck(this, TextTrack);
  14030. _EventTarget.call(this);
  14031. if (!options.tech) {
  14032. throw new Error('A tech was not provided.');
  14033. }
  14034. var tt = this;
  14035. if (browser.IS_IE8) {
  14036. tt = _globalDocument2['default'].createElement('custom');
  14037. for (var prop in TextTrack.prototype) {
  14038. if (prop !== 'constructor') {
  14039. tt[prop] = TextTrack.prototype[prop];
  14040. }
  14041. }
  14042. }
  14043. tt.tech_ = options.tech;
  14044. var mode = TextTrackEnum.TextTrackMode[options.mode] || 'disabled';
  14045. var kind = TextTrackEnum.TextTrackKind[options.kind] || 'subtitles';
  14046. var label = options.label || '';
  14047. var language = options.language || options.srclang || '';
  14048. var id = options.id || 'vjs_text_track_' + Guid.newGUID();
  14049. if (kind === 'metadata' || kind === 'chapters') {
  14050. mode = 'hidden';
  14051. }
  14052. tt.cues_ = [];
  14053. tt.activeCues_ = [];
  14054. var cues = new _textTrackCueList2['default'](tt.cues_);
  14055. var activeCues = new _textTrackCueList2['default'](tt.activeCues_);
  14056. var changed = false;
  14057. var timeupdateHandler = Fn.bind(tt, function () {
  14058. this.activeCues;
  14059. if (changed) {
  14060. this.trigger('cuechange');
  14061. changed = false;
  14062. }
  14063. });
  14064. if (mode !== 'disabled') {
  14065. tt.tech_.on('timeupdate', timeupdateHandler);
  14066. }
  14067. Object.defineProperty(tt, 'kind', {
  14068. get: function get() {
  14069. return kind;
  14070. },
  14071. set: function set() {}
  14072. });
  14073. Object.defineProperty(tt, 'label', {
  14074. get: function get() {
  14075. return label;
  14076. },
  14077. set: function set() {}
  14078. });
  14079. Object.defineProperty(tt, 'language', {
  14080. get: function get() {
  14081. return language;
  14082. },
  14083. set: function set() {}
  14084. });
  14085. Object.defineProperty(tt, 'id', {
  14086. get: function get() {
  14087. return id;
  14088. },
  14089. set: function set() {}
  14090. });
  14091. Object.defineProperty(tt, 'mode', {
  14092. get: function get() {
  14093. return mode;
  14094. },
  14095. set: function set(newMode) {
  14096. if (!TextTrackEnum.TextTrackMode[newMode]) {
  14097. return;
  14098. }
  14099. mode = newMode;
  14100. if (mode === 'showing') {
  14101. this.tech_.on('timeupdate', timeupdateHandler);
  14102. }
  14103. this.trigger('modechange');
  14104. }
  14105. });
  14106. Object.defineProperty(tt, 'cues', {
  14107. get: function get() {
  14108. if (!this.loaded_) {
  14109. return null;
  14110. }
  14111. return cues;
  14112. },
  14113. set: function set() {}
  14114. });
  14115. Object.defineProperty(tt, 'activeCues', {
  14116. get: function get() {
  14117. if (!this.loaded_) {
  14118. return null;
  14119. }
  14120. // nothing to do
  14121. if (this.cues.length === 0) {
  14122. return activeCues;
  14123. }
  14124. var ct = this.tech_.currentTime();
  14125. var active = [];
  14126. for (var i = 0, l = this.cues.length; i < l; i++) {
  14127. var cue = this.cues[i];
  14128. if (cue.startTime <= ct && cue.endTime >= ct) {
  14129. active.push(cue);
  14130. } else if (cue.startTime === cue.endTime && cue.startTime <= ct && cue.startTime + 0.5 >= ct) {
  14131. active.push(cue);
  14132. }
  14133. }
  14134. changed = false;
  14135. if (active.length !== this.activeCues_.length) {
  14136. changed = true;
  14137. } else {
  14138. for (var i = 0; i < active.length; i++) {
  14139. if (this.activeCues_.indexOf(active[i]) === -1) {
  14140. changed = true;
  14141. }
  14142. }
  14143. }
  14144. this.activeCues_ = active;
  14145. activeCues.setCues_(this.activeCues_);
  14146. return activeCues;
  14147. },
  14148. set: function set() {}
  14149. });
  14150. if (options.src) {
  14151. tt.src = options.src;
  14152. loadTrack(options.src, tt);
  14153. } else {
  14154. tt.loaded_ = true;
  14155. }
  14156. if (browser.IS_IE8) {
  14157. return tt;
  14158. }
  14159. }
  14160. /**
  14161. * cuechange - One or more cues in the track have become active or stopped being active.
  14162. */
  14163. /**
  14164. * add a cue to the internal list of cues
  14165. *
  14166. * @param {Object} cue the cue to add to our internal list
  14167. * @method addCue
  14168. */
  14169. TextTrack.prototype.addCue = function addCue(cue) {
  14170. var tracks = this.tech_.textTracks();
  14171. if (tracks) {
  14172. for (var i = 0; i < tracks.length; i++) {
  14173. if (tracks[i] !== this) {
  14174. tracks[i].removeCue(cue);
  14175. }
  14176. }
  14177. }
  14178. this.cues_.push(cue);
  14179. this.cues.setCues_(this.cues_);
  14180. };
  14181. /**
  14182. * remvoe a cue from our internal list
  14183. *
  14184. * @param {Object} removeCue the cue to remove from our internal list
  14185. * @method removeCue
  14186. */
  14187. TextTrack.prototype.removeCue = function removeCue(_removeCue) {
  14188. var removed = false;
  14189. for (var i = 0, l = this.cues_.length; i < l; i++) {
  14190. var cue = this.cues_[i];
  14191. if (cue === _removeCue) {
  14192. this.cues_.splice(i, 1);
  14193. removed = true;
  14194. }
  14195. }
  14196. if (removed) {
  14197. this.cues.setCues_(this.cues_);
  14198. }
  14199. };
  14200. return TextTrack;
  14201. })(_eventTarget2['default']);
  14202. TextTrack.prototype.allowedEvents_ = {
  14203. cuechange: 'cuechange'
  14204. };
  14205. exports['default'] = TextTrack;
  14206. module.exports = exports['default'];
  14207. },{"../event-target":99,"../utils/browser.js":129,"../utils/fn.js":134,"../utils/guid.js":136,"../utils/log.js":137,"../utils/url.js":142,"./text-track-cue-list":122,"./text-track-enums":124,"global/document":1,"global/window":2,"xhr":56}],129:[function(_dereq_,module,exports){
  14208. /**
  14209. * @file browser.js
  14210. */
  14211. 'use strict';
  14212. exports.__esModule = true;
  14213. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  14214. var _globalDocument = _dereq_('global/document');
  14215. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  14216. var _globalWindow = _dereq_('global/window');
  14217. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  14218. var USER_AGENT = _globalWindow2['default'].navigator.userAgent;
  14219. var webkitVersionMap = /AppleWebKit\/([\d.]+)/i.exec(USER_AGENT);
  14220. var appleWebkitVersion = webkitVersionMap ? parseFloat(webkitVersionMap.pop()) : null;
  14221. /*
  14222. * Device is an iPhone
  14223. *
  14224. * @type {Boolean}
  14225. * @constant
  14226. * @private
  14227. */
  14228. var IS_IPAD = /iPad/i.test(USER_AGENT);
  14229. exports.IS_IPAD = IS_IPAD;
  14230. // The Facebook app's UIWebView identifies as both an iPhone and iPad, so
  14231. // to identify iPhones, we need to exclude iPads.
  14232. // http://artsy.github.io/blog/2012/10/18/the-perils-of-ios-user-agent-sniffing/
  14233. var IS_IPHONE = /iPhone/i.test(USER_AGENT) && !IS_IPAD;
  14234. exports.IS_IPHONE = IS_IPHONE;
  14235. var IS_IPOD = /iPod/i.test(USER_AGENT);
  14236. exports.IS_IPOD = IS_IPOD;
  14237. var IS_IOS = IS_IPHONE || IS_IPAD || IS_IPOD;
  14238. exports.IS_IOS = IS_IOS;
  14239. var IOS_VERSION = (function () {
  14240. var match = USER_AGENT.match(/OS (\d+)_/i);
  14241. if (match && match[1]) {
  14242. return match[1];
  14243. }
  14244. })();
  14245. exports.IOS_VERSION = IOS_VERSION;
  14246. var IS_ANDROID = /Android/i.test(USER_AGENT);
  14247. exports.IS_ANDROID = IS_ANDROID;
  14248. var ANDROID_VERSION = (function () {
  14249. // This matches Android Major.Minor.Patch versions
  14250. // ANDROID_VERSION is Major.Minor as a Number, if Minor isn't available, then only Major is returned
  14251. var match = USER_AGENT.match(/Android (\d+)(?:\.(\d+))?(?:\.(\d+))*/i),
  14252. major,
  14253. minor;
  14254. if (!match) {
  14255. return null;
  14256. }
  14257. major = match[1] && parseFloat(match[1]);
  14258. minor = match[2] && parseFloat(match[2]);
  14259. if (major && minor) {
  14260. return parseFloat(match[1] + '.' + match[2]);
  14261. } else if (major) {
  14262. return major;
  14263. } else {
  14264. return null;
  14265. }
  14266. })();
  14267. exports.ANDROID_VERSION = ANDROID_VERSION;
  14268. // Old Android is defined as Version older than 2.3, and requiring a webkit version of the android browser
  14269. var IS_OLD_ANDROID = IS_ANDROID && /webkit/i.test(USER_AGENT) && ANDROID_VERSION < 2.3;
  14270. exports.IS_OLD_ANDROID = IS_OLD_ANDROID;
  14271. var IS_NATIVE_ANDROID = IS_ANDROID && ANDROID_VERSION < 5 && appleWebkitVersion < 537;
  14272. exports.IS_NATIVE_ANDROID = IS_NATIVE_ANDROID;
  14273. var IS_FIREFOX = /Firefox/i.test(USER_AGENT);
  14274. exports.IS_FIREFOX = IS_FIREFOX;
  14275. var IS_CHROME = /Chrome/i.test(USER_AGENT);
  14276. exports.IS_CHROME = IS_CHROME;
  14277. var IS_IE8 = /MSIE\s8\.0/.test(USER_AGENT);
  14278. exports.IS_IE8 = IS_IE8;
  14279. var TOUCH_ENABLED = !!('ontouchstart' in _globalWindow2['default'] || _globalWindow2['default'].DocumentTouch && _globalDocument2['default'] instanceof _globalWindow2['default'].DocumentTouch);
  14280. exports.TOUCH_ENABLED = TOUCH_ENABLED;
  14281. var BACKGROUND_SIZE_SUPPORTED = ('backgroundSize' in _globalDocument2['default'].createElement('video').style);
  14282. exports.BACKGROUND_SIZE_SUPPORTED = BACKGROUND_SIZE_SUPPORTED;
  14283. },{"global/document":1,"global/window":2}],130:[function(_dereq_,module,exports){
  14284. /**
  14285. * @file buffer.js
  14286. */
  14287. 'use strict';
  14288. exports.__esModule = true;
  14289. exports.bufferedPercent = bufferedPercent;
  14290. var _timeRangesJs = _dereq_('./time-ranges.js');
  14291. /**
  14292. * Compute how much your video has been buffered
  14293. *
  14294. * @param {Object} Buffered object
  14295. * @param {Number} Total duration
  14296. * @return {Number} Percent buffered of the total duration
  14297. * @private
  14298. * @function bufferedPercent
  14299. */
  14300. function bufferedPercent(buffered, duration) {
  14301. var bufferedDuration = 0,
  14302. start,
  14303. end;
  14304. if (!duration) {
  14305. return 0;
  14306. }
  14307. if (!buffered || !buffered.length) {
  14308. buffered = _timeRangesJs.createTimeRange(0, 0);
  14309. }
  14310. for (var i = 0; i < buffered.length; i++) {
  14311. start = buffered.start(i);
  14312. end = buffered.end(i);
  14313. // buffered end can be bigger than duration by a very small fraction
  14314. if (end > duration) {
  14315. end = duration;
  14316. }
  14317. bufferedDuration += end - start;
  14318. }
  14319. return bufferedDuration / duration;
  14320. }
  14321. },{"./time-ranges.js":140}],131:[function(_dereq_,module,exports){
  14322. 'use strict';
  14323. exports.__esModule = true;
  14324. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  14325. var _logJs = _dereq_('./log.js');
  14326. var _logJs2 = _interopRequireDefault(_logJs);
  14327. /**
  14328. * Object containing the default behaviors for available handler methods.
  14329. *
  14330. * @private
  14331. * @type {Object}
  14332. */
  14333. var defaultBehaviors = {
  14334. get: function get(obj, key) {
  14335. return obj[key];
  14336. },
  14337. set: function set(obj, key, value) {
  14338. obj[key] = value;
  14339. return true;
  14340. }
  14341. };
  14342. /**
  14343. * Expose private objects publicly using a Proxy to log deprecation warnings.
  14344. *
  14345. * Browsers that do not support Proxy objects will simply return the `target`
  14346. * object, so it can be directly exposed.
  14347. *
  14348. * @param {Object} target The target object.
  14349. * @param {Object} messages Messages to display from a Proxy. Only operations
  14350. * with an associated message will be proxied.
  14351. * @param {String} [messages.get]
  14352. * @param {String} [messages.set]
  14353. * @return {Object} A Proxy if supported or the `target` argument.
  14354. */
  14355. exports['default'] = function (target) {
  14356. var messages = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  14357. if (typeof Proxy === 'function') {
  14358. var _ret = (function () {
  14359. var handler = {};
  14360. // Build a handler object based on those keys that have both messages
  14361. // and default behaviors.
  14362. Object.keys(messages).forEach(function (key) {
  14363. if (defaultBehaviors.hasOwnProperty(key)) {
  14364. handler[key] = function () {
  14365. _logJs2['default'].warn(messages[key]);
  14366. return defaultBehaviors[key].apply(this, arguments);
  14367. };
  14368. }
  14369. });
  14370. return {
  14371. v: new Proxy(target, handler)
  14372. };
  14373. })();
  14374. if (typeof _ret === 'object') return _ret.v;
  14375. }
  14376. return target;
  14377. };
  14378. module.exports = exports['default'];
  14379. },{"./log.js":137}],132:[function(_dereq_,module,exports){
  14380. /**
  14381. * @file dom.js
  14382. */
  14383. 'use strict';
  14384. exports.__esModule = true;
  14385. exports.getEl = getEl;
  14386. exports.createEl = createEl;
  14387. exports.textContent = textContent;
  14388. exports.insertElFirst = insertElFirst;
  14389. exports.getElData = getElData;
  14390. exports.hasElData = hasElData;
  14391. exports.removeElData = removeElData;
  14392. exports.hasElClass = hasElClass;
  14393. exports.addElClass = addElClass;
  14394. exports.removeElClass = removeElClass;
  14395. exports.toggleElClass = toggleElClass;
  14396. exports.setElAttributes = setElAttributes;
  14397. exports.getElAttributes = getElAttributes;
  14398. exports.blockTextSelection = blockTextSelection;
  14399. exports.unblockTextSelection = unblockTextSelection;
  14400. exports.findElPosition = findElPosition;
  14401. exports.getPointerPosition = getPointerPosition;
  14402. exports.isEl = isEl;
  14403. exports.isTextNode = isTextNode;
  14404. exports.emptyEl = emptyEl;
  14405. exports.normalizeContent = normalizeContent;
  14406. exports.appendContent = appendContent;
  14407. exports.insertContent = insertContent;
  14408. var _templateObject = _taggedTemplateLiteralLoose(['Setting attributes in the second argument of createEl()\n has been deprecated. Use the third argument instead.\n createEl(type, properties, attributes). Attempting to set ', ' to ', '.'], ['Setting attributes in the second argument of createEl()\n has been deprecated. Use the third argument instead.\n createEl(type, properties, attributes). Attempting to set ', ' to ', '.']);
  14409. 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; } }
  14410. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  14411. function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
  14412. var _globalDocument = _dereq_('global/document');
  14413. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  14414. var _globalWindow = _dereq_('global/window');
  14415. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  14416. var _guidJs = _dereq_('./guid.js');
  14417. var Guid = _interopRequireWildcard(_guidJs);
  14418. var _logJs = _dereq_('./log.js');
  14419. var _logJs2 = _interopRequireDefault(_logJs);
  14420. var _tsml = _dereq_('tsml');
  14421. var _tsml2 = _interopRequireDefault(_tsml);
  14422. /**
  14423. * Detect if a value is a string with any non-whitespace characters.
  14424. *
  14425. * @param {String} str
  14426. * @return {Boolean}
  14427. */
  14428. function isNonBlankString(str) {
  14429. return typeof str === 'string' && /\S/.test(str);
  14430. }
  14431. /**
  14432. * Throws an error if the passed string has whitespace. This is used by
  14433. * class methods to be relatively consistent with the classList API.
  14434. *
  14435. * @param {String} str
  14436. * @return {Boolean}
  14437. */
  14438. function throwIfWhitespace(str) {
  14439. if (/\s/.test(str)) {
  14440. throw new Error('class has illegal whitespace characters');
  14441. }
  14442. }
  14443. /**
  14444. * Produce a regular expression for matching a class name.
  14445. *
  14446. * @param {String} className
  14447. * @return {RegExp}
  14448. */
  14449. function classRegExp(className) {
  14450. return new RegExp('(^|\\s)' + className + '($|\\s)');
  14451. }
  14452. /**
  14453. * Creates functions to query the DOM using a given method.
  14454. *
  14455. * @function createQuerier
  14456. * @private
  14457. * @param {String} method
  14458. * @return {Function}
  14459. */
  14460. function createQuerier(method) {
  14461. return function (selector, context) {
  14462. if (!isNonBlankString(selector)) {
  14463. return _globalDocument2['default'][method](null);
  14464. }
  14465. if (isNonBlankString(context)) {
  14466. context = _globalDocument2['default'].querySelector(context);
  14467. }
  14468. return (isEl(context) ? context : _globalDocument2['default'])[method](selector);
  14469. };
  14470. }
  14471. /**
  14472. * Shorthand for document.getElementById()
  14473. * Also allows for CSS (jQuery) ID syntax. But nothing other than IDs.
  14474. *
  14475. * @param {String} id Element ID
  14476. * @return {Element} Element with supplied ID
  14477. * @function getEl
  14478. */
  14479. function getEl(id) {
  14480. if (id.indexOf('#') === 0) {
  14481. id = id.slice(1);
  14482. }
  14483. return _globalDocument2['default'].getElementById(id);
  14484. }
  14485. /**
  14486. * Creates an element and applies properties.
  14487. *
  14488. * @param {String} [tagName='div'] Name of tag to be created.
  14489. * @param {Object} [properties={}] Element properties to be applied.
  14490. * @param {Object} [attributes={}] Element attributes to be applied.
  14491. * @return {Element}
  14492. * @function createEl
  14493. */
  14494. function createEl() {
  14495. var tagName = arguments.length <= 0 || arguments[0] === undefined ? 'div' : arguments[0];
  14496. var properties = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  14497. var attributes = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
  14498. var el = _globalDocument2['default'].createElement(tagName);
  14499. Object.getOwnPropertyNames(properties).forEach(function (propName) {
  14500. var val = properties[propName];
  14501. // See #2176
  14502. // We originally were accepting both properties and attributes in the
  14503. // same object, but that doesn't work so well.
  14504. if (propName.indexOf('aria-') !== -1 || propName === 'role' || propName === 'type') {
  14505. _logJs2['default'].warn(_tsml2['default'](_templateObject, propName, val));
  14506. el.setAttribute(propName, val);
  14507. } else {
  14508. el[propName] = val;
  14509. }
  14510. });
  14511. Object.getOwnPropertyNames(attributes).forEach(function (attrName) {
  14512. var val = attributes[attrName];
  14513. el.setAttribute(attrName, attributes[attrName]);
  14514. });
  14515. return el;
  14516. }
  14517. /**
  14518. * Injects text into an element, replacing any existing contents entirely.
  14519. *
  14520. * @param {Element} el
  14521. * @param {String} text
  14522. * @return {Element}
  14523. * @function textContent
  14524. */
  14525. function textContent(el, text) {
  14526. if (typeof el.textContent === 'undefined') {
  14527. el.innerText = text;
  14528. } else {
  14529. el.textContent = text;
  14530. }
  14531. }
  14532. /**
  14533. * Insert an element as the first child node of another
  14534. *
  14535. * @param {Element} child Element to insert
  14536. * @param {Element} parent Element to insert child into
  14537. * @private
  14538. * @function insertElFirst
  14539. */
  14540. function insertElFirst(child, parent) {
  14541. if (parent.firstChild) {
  14542. parent.insertBefore(child, parent.firstChild);
  14543. } else {
  14544. parent.appendChild(child);
  14545. }
  14546. }
  14547. /**
  14548. * Element Data Store. Allows for binding data to an element without putting it directly on the element.
  14549. * Ex. Event listeners are stored here.
  14550. * (also from jsninja.com, slightly modified and updated for closure compiler)
  14551. *
  14552. * @type {Object}
  14553. * @private
  14554. */
  14555. var elData = {};
  14556. /*
  14557. * Unique attribute name to store an element's guid in
  14558. *
  14559. * @type {String}
  14560. * @constant
  14561. * @private
  14562. */
  14563. var elIdAttr = 'vdata' + new Date().getTime();
  14564. /**
  14565. * Returns the cache object where data for an element is stored
  14566. *
  14567. * @param {Element} el Element to store data for.
  14568. * @return {Object}
  14569. * @function getElData
  14570. */
  14571. function getElData(el) {
  14572. var id = el[elIdAttr];
  14573. if (!id) {
  14574. id = el[elIdAttr] = Guid.newGUID();
  14575. }
  14576. if (!elData[id]) {
  14577. elData[id] = {};
  14578. }
  14579. return elData[id];
  14580. }
  14581. /**
  14582. * Returns whether or not an element has cached data
  14583. *
  14584. * @param {Element} el A dom element
  14585. * @return {Boolean}
  14586. * @private
  14587. * @function hasElData
  14588. */
  14589. function hasElData(el) {
  14590. var id = el[elIdAttr];
  14591. if (!id) {
  14592. return false;
  14593. }
  14594. return !!Object.getOwnPropertyNames(elData[id]).length;
  14595. }
  14596. /**
  14597. * Delete data for the element from the cache and the guid attr from getElementById
  14598. *
  14599. * @param {Element} el Remove data for an element
  14600. * @private
  14601. * @function removeElData
  14602. */
  14603. function removeElData(el) {
  14604. var id = el[elIdAttr];
  14605. if (!id) {
  14606. return;
  14607. }
  14608. // Remove all stored data
  14609. delete elData[id];
  14610. // Remove the elIdAttr property from the DOM node
  14611. try {
  14612. delete el[elIdAttr];
  14613. } catch (e) {
  14614. if (el.removeAttribute) {
  14615. el.removeAttribute(elIdAttr);
  14616. } else {
  14617. // IE doesn't appear to support removeAttribute on the document element
  14618. el[elIdAttr] = null;
  14619. }
  14620. }
  14621. }
  14622. /**
  14623. * Check if an element has a CSS class
  14624. *
  14625. * @function hasElClass
  14626. * @param {Element} element Element to check
  14627. * @param {String} classToCheck Classname to check
  14628. */
  14629. function hasElClass(element, classToCheck) {
  14630. if (element.classList) {
  14631. return element.classList.contains(classToCheck);
  14632. } else {
  14633. throwIfWhitespace(classToCheck);
  14634. return classRegExp(classToCheck).test(element.className);
  14635. }
  14636. }
  14637. /**
  14638. * Add a CSS class name to an element
  14639. *
  14640. * @function addElClass
  14641. * @param {Element} element Element to add class name to
  14642. * @param {String} classToAdd Classname to add
  14643. */
  14644. function addElClass(element, classToAdd) {
  14645. if (element.classList) {
  14646. element.classList.add(classToAdd);
  14647. // Don't need to `throwIfWhitespace` here because `hasElClass` will do it
  14648. // in the case of classList not being supported.
  14649. } else if (!hasElClass(element, classToAdd)) {
  14650. element.className = (element.className + ' ' + classToAdd).trim();
  14651. }
  14652. return element;
  14653. }
  14654. /**
  14655. * Remove a CSS class name from an element
  14656. *
  14657. * @function removeElClass
  14658. * @param {Element} element Element to remove from class name
  14659. * @param {String} classToRemove Classname to remove
  14660. */
  14661. function removeElClass(element, classToRemove) {
  14662. if (element.classList) {
  14663. element.classList.remove(classToRemove);
  14664. } else {
  14665. throwIfWhitespace(classToRemove);
  14666. element.className = element.className.split(/\s+/).filter(function (c) {
  14667. return c !== classToRemove;
  14668. }).join(' ');
  14669. }
  14670. return element;
  14671. }
  14672. /**
  14673. * Adds or removes a CSS class name on an element depending on an optional
  14674. * condition or the presence/absence of the class name.
  14675. *
  14676. * @function toggleElClass
  14677. * @param {Element} element
  14678. * @param {String} classToToggle
  14679. * @param {Boolean|Function} [predicate]
  14680. * Can be a function that returns a Boolean. If `true`, the class
  14681. * will be added; if `false`, the class will be removed. If not
  14682. * given, the class will be added if not present and vice versa.
  14683. */
  14684. function toggleElClass(element, classToToggle, predicate) {
  14685. // This CANNOT use `classList` internally because IE does not support the
  14686. // second parameter to the `classList.toggle()` method! Which is fine because
  14687. // `classList` will be used by the add/remove functions.
  14688. var has = hasElClass(element, classToToggle);
  14689. if (typeof predicate === 'function') {
  14690. predicate = predicate(element, classToToggle);
  14691. }
  14692. if (typeof predicate !== 'boolean') {
  14693. predicate = !has;
  14694. }
  14695. // If the necessary class operation matches the current state of the
  14696. // element, no action is required.
  14697. if (predicate === has) {
  14698. return;
  14699. }
  14700. if (predicate) {
  14701. addElClass(element, classToToggle);
  14702. } else {
  14703. removeElClass(element, classToToggle);
  14704. }
  14705. return element;
  14706. }
  14707. /**
  14708. * Apply attributes to an HTML element.
  14709. *
  14710. * @param {Element} el Target element.
  14711. * @param {Object=} attributes Element attributes to be applied.
  14712. * @private
  14713. * @function setElAttributes
  14714. */
  14715. function setElAttributes(el, attributes) {
  14716. Object.getOwnPropertyNames(attributes).forEach(function (attrName) {
  14717. var attrValue = attributes[attrName];
  14718. if (attrValue === null || typeof attrValue === 'undefined' || attrValue === false) {
  14719. el.removeAttribute(attrName);
  14720. } else {
  14721. el.setAttribute(attrName, attrValue === true ? '' : attrValue);
  14722. }
  14723. });
  14724. }
  14725. /**
  14726. * Get an element's attribute values, as defined on the HTML tag
  14727. * Attributes are not the same as properties. They're defined on the tag
  14728. * or with setAttribute (which shouldn't be used with HTML)
  14729. * This will return true or false for boolean attributes.
  14730. *
  14731. * @param {Element} tag Element from which to get tag attributes
  14732. * @return {Object}
  14733. * @private
  14734. * @function getElAttributes
  14735. */
  14736. function getElAttributes(tag) {
  14737. var obj, knownBooleans, attrs, attrName, attrVal;
  14738. obj = {};
  14739. // known boolean attributes
  14740. // we can check for matching boolean properties, but older browsers
  14741. // won't know about HTML5 boolean attributes that we still read from
  14742. knownBooleans = ',' + 'autoplay,controls,loop,muted,default' + ',';
  14743. if (tag && tag.attributes && tag.attributes.length > 0) {
  14744. attrs = tag.attributes;
  14745. for (var i = attrs.length - 1; i >= 0; i--) {
  14746. attrName = attrs[i].name;
  14747. attrVal = attrs[i].value;
  14748. // check for known booleans
  14749. // the matching element property will return a value for typeof
  14750. if (typeof tag[attrName] === 'boolean' || knownBooleans.indexOf(',' + attrName + ',') !== -1) {
  14751. // the value of an included boolean attribute is typically an empty
  14752. // string ('') which would equal false if we just check for a false value.
  14753. // we also don't want support bad code like autoplay='false'
  14754. attrVal = attrVal !== null ? true : false;
  14755. }
  14756. obj[attrName] = attrVal;
  14757. }
  14758. }
  14759. return obj;
  14760. }
  14761. /**
  14762. * Attempt to block the ability to select text while dragging controls
  14763. *
  14764. * @return {Boolean}
  14765. * @function blockTextSelection
  14766. */
  14767. function blockTextSelection() {
  14768. _globalDocument2['default'].body.focus();
  14769. _globalDocument2['default'].onselectstart = function () {
  14770. return false;
  14771. };
  14772. }
  14773. /**
  14774. * Turn off text selection blocking
  14775. *
  14776. * @return {Boolean}
  14777. * @function unblockTextSelection
  14778. */
  14779. function unblockTextSelection() {
  14780. _globalDocument2['default'].onselectstart = function () {
  14781. return true;
  14782. };
  14783. }
  14784. /**
  14785. * Offset Left
  14786. * getBoundingClientRect technique from
  14787. * John Resig http://ejohn.org/blog/getboundingclientrect-is-awesome/
  14788. *
  14789. * @function findElPosition
  14790. * @param {Element} el Element from which to get offset
  14791. * @return {Object}
  14792. */
  14793. function findElPosition(el) {
  14794. var box = undefined;
  14795. if (el.getBoundingClientRect && el.parentNode) {
  14796. box = el.getBoundingClientRect();
  14797. }
  14798. if (!box) {
  14799. return {
  14800. left: 0,
  14801. top: 0
  14802. };
  14803. }
  14804. var docEl = _globalDocument2['default'].documentElement;
  14805. var body = _globalDocument2['default'].body;
  14806. var clientLeft = docEl.clientLeft || body.clientLeft || 0;
  14807. var scrollLeft = _globalWindow2['default'].pageXOffset || body.scrollLeft;
  14808. var left = box.left + scrollLeft - clientLeft;
  14809. var clientTop = docEl.clientTop || body.clientTop || 0;
  14810. var scrollTop = _globalWindow2['default'].pageYOffset || body.scrollTop;
  14811. var top = box.top + scrollTop - clientTop;
  14812. // Android sometimes returns slightly off decimal values, so need to round
  14813. return {
  14814. left: Math.round(left),
  14815. top: Math.round(top)
  14816. };
  14817. }
  14818. /**
  14819. * Get pointer position in element
  14820. * Returns an object with x and y coordinates.
  14821. * The base on the coordinates are the bottom left of the element.
  14822. *
  14823. * @function getPointerPosition
  14824. * @param {Element} el Element on which to get the pointer position on
  14825. * @param {Event} event Event object
  14826. * @return {Object} This object will have x and y coordinates corresponding to the mouse position
  14827. */
  14828. function getPointerPosition(el, event) {
  14829. var position = {};
  14830. var box = findElPosition(el);
  14831. var boxW = el.offsetWidth;
  14832. var boxH = el.offsetHeight;
  14833. var boxY = box.top;
  14834. var boxX = box.left;
  14835. var pageY = event.pageY;
  14836. var pageX = event.pageX;
  14837. if (event.changedTouches) {
  14838. pageX = event.changedTouches[0].pageX;
  14839. pageY = event.changedTouches[0].pageY;
  14840. }
  14841. position.y = Math.max(0, Math.min(1, (boxY - pageY + boxH) / boxH));
  14842. position.x = Math.max(0, Math.min(1, (pageX - boxX) / boxW));
  14843. return position;
  14844. }
  14845. /**
  14846. * Determines, via duck typing, whether or not a value is a DOM element.
  14847. *
  14848. * @function isEl
  14849. * @param {Mixed} value
  14850. * @return {Boolean}
  14851. */
  14852. function isEl(value) {
  14853. return !!value && typeof value === 'object' && value.nodeType === 1;
  14854. }
  14855. /**
  14856. * Determines, via duck typing, whether or not a value is a text node.
  14857. *
  14858. * @param {Mixed} value
  14859. * @return {Boolean}
  14860. */
  14861. function isTextNode(value) {
  14862. return !!value && typeof value === 'object' && value.nodeType === 3;
  14863. }
  14864. /**
  14865. * Empties the contents of an element.
  14866. *
  14867. * @function emptyEl
  14868. * @param {Element} el
  14869. * @return {Element}
  14870. */
  14871. function emptyEl(el) {
  14872. while (el.firstChild) {
  14873. el.removeChild(el.firstChild);
  14874. }
  14875. return el;
  14876. }
  14877. /**
  14878. * Normalizes content for eventual insertion into the DOM.
  14879. *
  14880. * This allows a wide range of content definition methods, but protects
  14881. * from falling into the trap of simply writing to `innerHTML`, which is
  14882. * an XSS concern.
  14883. *
  14884. * The content for an element can be passed in multiple types and
  14885. * combinations, whose behavior is as follows:
  14886. *
  14887. * - String
  14888. * Normalized into a text node.
  14889. *
  14890. * - Element, TextNode
  14891. * Passed through.
  14892. *
  14893. * - Array
  14894. * A one-dimensional array of strings, elements, nodes, or functions (which
  14895. * return single strings, elements, or nodes).
  14896. *
  14897. * - Function
  14898. * If the sole argument, is expected to produce a string, element,
  14899. * node, or array.
  14900. *
  14901. * @function normalizeContent
  14902. * @param {String|Element|TextNode|Array|Function} content
  14903. * @return {Array}
  14904. */
  14905. function normalizeContent(content) {
  14906. // First, invoke content if it is a function. If it produces an array,
  14907. // that needs to happen before normalization.
  14908. if (typeof content === 'function') {
  14909. content = content();
  14910. }
  14911. // Next up, normalize to an array, so one or many items can be normalized,
  14912. // filtered, and returned.
  14913. return (Array.isArray(content) ? content : [content]).map(function (value) {
  14914. // First, invoke value if it is a function to produce a new value,
  14915. // which will be subsequently normalized to a Node of some kind.
  14916. if (typeof value === 'function') {
  14917. value = value();
  14918. }
  14919. if (isEl(value) || isTextNode(value)) {
  14920. return value;
  14921. }
  14922. if (typeof value === 'string' && /\S/.test(value)) {
  14923. return _globalDocument2['default'].createTextNode(value);
  14924. }
  14925. }).filter(function (value) {
  14926. return value;
  14927. });
  14928. }
  14929. /**
  14930. * Normalizes and appends content to an element.
  14931. *
  14932. * @function appendContent
  14933. * @param {Element} el
  14934. * @param {String|Element|TextNode|Array|Function} content
  14935. * See: `normalizeContent`
  14936. * @return {Element}
  14937. */
  14938. function appendContent(el, content) {
  14939. normalizeContent(content).forEach(function (node) {
  14940. return el.appendChild(node);
  14941. });
  14942. return el;
  14943. }
  14944. /**
  14945. * Normalizes and inserts content into an element; this is identical to
  14946. * `appendContent()`, except it empties the element first.
  14947. *
  14948. * @function insertContent
  14949. * @param {Element} el
  14950. * @param {String|Element|TextNode|Array|Function} content
  14951. * See: `normalizeContent`
  14952. * @return {Element}
  14953. */
  14954. function insertContent(el, content) {
  14955. return appendContent(emptyEl(el), content);
  14956. }
  14957. /**
  14958. * Finds a single DOM element matching `selector` within the optional
  14959. * `context` of another DOM element (defaulting to `document`).
  14960. *
  14961. * @function $
  14962. * @param {String} selector
  14963. * A valid CSS selector, which will be passed to `querySelector`.
  14964. *
  14965. * @param {Element|String} [context=document]
  14966. * A DOM element within which to query. Can also be a selector
  14967. * string in which case the first matching element will be used
  14968. * as context. If missing (or no element matches selector), falls
  14969. * back to `document`.
  14970. *
  14971. * @return {Element|null}
  14972. */
  14973. var $ = createQuerier('querySelector');
  14974. exports.$ = $;
  14975. /**
  14976. * Finds a all DOM elements matching `selector` within the optional
  14977. * `context` of another DOM element (defaulting to `document`).
  14978. *
  14979. * @function $$
  14980. * @param {String} selector
  14981. * A valid CSS selector, which will be passed to `querySelectorAll`.
  14982. *
  14983. * @param {Element|String} [context=document]
  14984. * A DOM element within which to query. Can also be a selector
  14985. * string in which case the first matching element will be used
  14986. * as context. If missing (or no element matches selector), falls
  14987. * back to `document`.
  14988. *
  14989. * @return {NodeList}
  14990. */
  14991. var $$ = createQuerier('querySelectorAll');
  14992. exports.$$ = $$;
  14993. },{"./guid.js":136,"./log.js":137,"global/document":1,"global/window":2,"tsml":55}],133:[function(_dereq_,module,exports){
  14994. /**
  14995. * @file events.js
  14996. *
  14997. * Event System (John Resig - Secrets of a JS Ninja http://jsninja.com/)
  14998. * (Original book version wasn't completely usable, so fixed some things and made Closure Compiler compatible)
  14999. * This should work very similarly to jQuery's events, however it's based off the book version which isn't as
  15000. * robust as jquery's, so there's probably some differences.
  15001. */
  15002. 'use strict';
  15003. exports.__esModule = true;
  15004. exports.on = on;
  15005. exports.off = off;
  15006. exports.trigger = trigger;
  15007. exports.one = one;
  15008. exports.fixEvent = fixEvent;
  15009. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  15010. 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; } }
  15011. var _domJs = _dereq_('./dom.js');
  15012. var Dom = _interopRequireWildcard(_domJs);
  15013. var _guidJs = _dereq_('./guid.js');
  15014. var Guid = _interopRequireWildcard(_guidJs);
  15015. var _globalWindow = _dereq_('global/window');
  15016. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  15017. var _globalDocument = _dereq_('global/document');
  15018. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  15019. /**
  15020. * Add an event listener to element
  15021. * It stores the handler function in a separate cache object
  15022. * and adds a generic handler to the element's event,
  15023. * along with a unique id (guid) to the element.
  15024. *
  15025. * @param {Element|Object} elem Element or object to bind listeners to
  15026. * @param {String|Array} type Type of event to bind to.
  15027. * @param {Function} fn Event listener.
  15028. * @method on
  15029. */
  15030. function on(elem, type, fn) {
  15031. if (Array.isArray(type)) {
  15032. return _handleMultipleEvents(on, elem, type, fn);
  15033. }
  15034. var data = Dom.getElData(elem);
  15035. // We need a place to store all our handler data
  15036. if (!data.handlers) data.handlers = {};
  15037. if (!data.handlers[type]) data.handlers[type] = [];
  15038. if (!fn.guid) fn.guid = Guid.newGUID();
  15039. data.handlers[type].push(fn);
  15040. if (!data.dispatcher) {
  15041. data.disabled = false;
  15042. data.dispatcher = function (event, hash) {
  15043. if (data.disabled) return;
  15044. event = fixEvent(event);
  15045. var handlers = data.handlers[event.type];
  15046. if (handlers) {
  15047. // Copy handlers so if handlers are added/removed during the process it doesn't throw everything off.
  15048. var handlersCopy = handlers.slice(0);
  15049. for (var m = 0, n = handlersCopy.length; m < n; m++) {
  15050. if (event.isImmediatePropagationStopped()) {
  15051. break;
  15052. } else {
  15053. handlersCopy[m].call(elem, event, hash);
  15054. }
  15055. }
  15056. }
  15057. };
  15058. }
  15059. if (data.handlers[type].length === 1) {
  15060. if (elem.addEventListener) {
  15061. elem.addEventListener(type, data.dispatcher, false);
  15062. } else if (elem.attachEvent) {
  15063. elem.attachEvent('on' + type, data.dispatcher);
  15064. }
  15065. }
  15066. }
  15067. /**
  15068. * Removes event listeners from an element
  15069. *
  15070. * @param {Element|Object} elem Object to remove listeners from
  15071. * @param {String|Array=} type Type of listener to remove. Don't include to remove all events from element.
  15072. * @param {Function} fn Specific listener to remove. Don't include to remove listeners for an event type.
  15073. * @method off
  15074. */
  15075. function off(elem, type, fn) {
  15076. // Don't want to add a cache object through getElData if not needed
  15077. if (!Dom.hasElData(elem)) return;
  15078. var data = Dom.getElData(elem);
  15079. // If no events exist, nothing to unbind
  15080. if (!data.handlers) {
  15081. return;
  15082. }
  15083. if (Array.isArray(type)) {
  15084. return _handleMultipleEvents(off, elem, type, fn);
  15085. }
  15086. // Utility function
  15087. var removeType = function removeType(t) {
  15088. data.handlers[t] = [];
  15089. _cleanUpEvents(elem, t);
  15090. };
  15091. // Are we removing all bound events?
  15092. if (!type) {
  15093. for (var t in data.handlers) {
  15094. removeType(t);
  15095. }return;
  15096. }
  15097. var handlers = data.handlers[type];
  15098. // If no handlers exist, nothing to unbind
  15099. if (!handlers) return;
  15100. // If no listener was provided, remove all listeners for type
  15101. if (!fn) {
  15102. removeType(type);
  15103. return;
  15104. }
  15105. // We're only removing a single handler
  15106. if (fn.guid) {
  15107. for (var n = 0; n < handlers.length; n++) {
  15108. if (handlers[n].guid === fn.guid) {
  15109. handlers.splice(n--, 1);
  15110. }
  15111. }
  15112. }
  15113. _cleanUpEvents(elem, type);
  15114. }
  15115. /**
  15116. * Trigger an event for an element
  15117. *
  15118. * @param {Element|Object} elem Element to trigger an event on
  15119. * @param {Event|Object|String} event A string (the type) or an event object with a type attribute
  15120. * @param {Object} [hash] data hash to pass along with the event
  15121. * @return {Boolean=} Returned only if default was prevented
  15122. * @method trigger
  15123. */
  15124. function trigger(elem, event, hash) {
  15125. // Fetches element data and a reference to the parent (for bubbling).
  15126. // Don't want to add a data object to cache for every parent,
  15127. // so checking hasElData first.
  15128. var elemData = Dom.hasElData(elem) ? Dom.getElData(elem) : {};
  15129. var parent = elem.parentNode || elem.ownerDocument;
  15130. // type = event.type || event,
  15131. // handler;
  15132. // If an event name was passed as a string, creates an event out of it
  15133. if (typeof event === 'string') {
  15134. event = { type: event, target: elem };
  15135. }
  15136. // Normalizes the event properties.
  15137. event = fixEvent(event);
  15138. // If the passed element has a dispatcher, executes the established handlers.
  15139. if (elemData.dispatcher) {
  15140. elemData.dispatcher.call(elem, event, hash);
  15141. }
  15142. // Unless explicitly stopped or the event does not bubble (e.g. media events)
  15143. // recursively calls this function to bubble the event up the DOM.
  15144. if (parent && !event.isPropagationStopped() && event.bubbles === true) {
  15145. trigger.call(null, parent, event, hash);
  15146. // If at the top of the DOM, triggers the default action unless disabled.
  15147. } else if (!parent && !event.defaultPrevented) {
  15148. var targetData = Dom.getElData(event.target);
  15149. // Checks if the target has a default action for this event.
  15150. if (event.target[event.type]) {
  15151. // Temporarily disables event dispatching on the target as we have already executed the handler.
  15152. targetData.disabled = true;
  15153. // Executes the default action.
  15154. if (typeof event.target[event.type] === 'function') {
  15155. event.target[event.type]();
  15156. }
  15157. // Re-enables event dispatching.
  15158. targetData.disabled = false;
  15159. }
  15160. }
  15161. // Inform the triggerer if the default was prevented by returning false
  15162. return !event.defaultPrevented;
  15163. }
  15164. /**
  15165. * Trigger a listener only once for an event
  15166. *
  15167. * @param {Element|Object} elem Element or object to
  15168. * @param {String|Array} type Name/type of event
  15169. * @param {Function} fn Event handler function
  15170. * @method one
  15171. */
  15172. function one(elem, type, fn) {
  15173. if (Array.isArray(type)) {
  15174. return _handleMultipleEvents(one, elem, type, fn);
  15175. }
  15176. var func = function func() {
  15177. off(elem, type, func);
  15178. fn.apply(this, arguments);
  15179. };
  15180. // copy the guid to the new function so it can removed using the original function's ID
  15181. func.guid = fn.guid = fn.guid || Guid.newGUID();
  15182. on(elem, type, func);
  15183. }
  15184. /**
  15185. * Fix a native event to have standard property values
  15186. *
  15187. * @param {Object} event Event object to fix
  15188. * @return {Object}
  15189. * @private
  15190. * @method fixEvent
  15191. */
  15192. function fixEvent(event) {
  15193. function returnTrue() {
  15194. return true;
  15195. }
  15196. function returnFalse() {
  15197. return false;
  15198. }
  15199. // Test if fixing up is needed
  15200. // Used to check if !event.stopPropagation instead of isPropagationStopped
  15201. // But native events return true for stopPropagation, but don't have
  15202. // other expected methods like isPropagationStopped. Seems to be a problem
  15203. // with the Javascript Ninja code. So we're just overriding all events now.
  15204. if (!event || !event.isPropagationStopped) {
  15205. var old = event || _globalWindow2['default'].event;
  15206. event = {};
  15207. // Clone the old object so that we can modify the values event = {};
  15208. // IE8 Doesn't like when you mess with native event properties
  15209. // Firefox returns false for event.hasOwnProperty('type') and other props
  15210. // which makes copying more difficult.
  15211. // TODO: Probably best to create a whitelist of event props
  15212. for (var key in old) {
  15213. // Safari 6.0.3 warns you if you try to copy deprecated layerX/Y
  15214. // Chrome warns you if you try to copy deprecated keyboardEvent.keyLocation
  15215. // and webkitMovementX/Y
  15216. if (key !== 'layerX' && key !== 'layerY' && key !== 'keyLocation' && key !== 'webkitMovementX' && key !== 'webkitMovementY') {
  15217. // Chrome 32+ warns if you try to copy deprecated returnValue, but
  15218. // we still want to if preventDefault isn't supported (IE8).
  15219. if (!(key === 'returnValue' && old.preventDefault)) {
  15220. event[key] = old[key];
  15221. }
  15222. }
  15223. }
  15224. // The event occurred on this element
  15225. if (!event.target) {
  15226. event.target = event.srcElement || _globalDocument2['default'];
  15227. }
  15228. // Handle which other element the event is related to
  15229. if (!event.relatedTarget) {
  15230. event.relatedTarget = event.fromElement === event.target ? event.toElement : event.fromElement;
  15231. }
  15232. // Stop the default browser action
  15233. event.preventDefault = function () {
  15234. if (old.preventDefault) {
  15235. old.preventDefault();
  15236. }
  15237. event.returnValue = false;
  15238. old.returnValue = false;
  15239. event.defaultPrevented = true;
  15240. };
  15241. event.defaultPrevented = false;
  15242. // Stop the event from bubbling
  15243. event.stopPropagation = function () {
  15244. if (old.stopPropagation) {
  15245. old.stopPropagation();
  15246. }
  15247. event.cancelBubble = true;
  15248. old.cancelBubble = true;
  15249. event.isPropagationStopped = returnTrue;
  15250. };
  15251. event.isPropagationStopped = returnFalse;
  15252. // Stop the event from bubbling and executing other handlers
  15253. event.stopImmediatePropagation = function () {
  15254. if (old.stopImmediatePropagation) {
  15255. old.stopImmediatePropagation();
  15256. }
  15257. event.isImmediatePropagationStopped = returnTrue;
  15258. event.stopPropagation();
  15259. };
  15260. event.isImmediatePropagationStopped = returnFalse;
  15261. // Handle mouse position
  15262. if (event.clientX != null) {
  15263. var doc = _globalDocument2['default'].documentElement,
  15264. body = _globalDocument2['default'].body;
  15265. event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
  15266. event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
  15267. }
  15268. // Handle key presses
  15269. event.which = event.charCode || event.keyCode;
  15270. // Fix button for mouse clicks:
  15271. // 0 == left; 1 == middle; 2 == right
  15272. if (event.button != null) {
  15273. event.button = event.button & 1 ? 0 : event.button & 4 ? 1 : event.button & 2 ? 2 : 0;
  15274. }
  15275. }
  15276. // Returns fixed-up instance
  15277. return event;
  15278. }
  15279. /**
  15280. * Clean up the listener cache and dispatchers
  15281. *
  15282. * @param {Element|Object} elem Element to clean up
  15283. * @param {String} type Type of event to clean up
  15284. * @private
  15285. * @method _cleanUpEvents
  15286. */
  15287. function _cleanUpEvents(elem, type) {
  15288. var data = Dom.getElData(elem);
  15289. // Remove the events of a particular type if there are none left
  15290. if (data.handlers[type].length === 0) {
  15291. delete data.handlers[type];
  15292. // data.handlers[type] = null;
  15293. // Setting to null was causing an error with data.handlers
  15294. // Remove the meta-handler from the element
  15295. if (elem.removeEventListener) {
  15296. elem.removeEventListener(type, data.dispatcher, false);
  15297. } else if (elem.detachEvent) {
  15298. elem.detachEvent('on' + type, data.dispatcher);
  15299. }
  15300. }
  15301. // Remove the events object if there are no types left
  15302. if (Object.getOwnPropertyNames(data.handlers).length <= 0) {
  15303. delete data.handlers;
  15304. delete data.dispatcher;
  15305. delete data.disabled;
  15306. }
  15307. // Finally remove the element data if there is no data left
  15308. if (Object.getOwnPropertyNames(data).length === 0) {
  15309. Dom.removeElData(elem);
  15310. }
  15311. }
  15312. /**
  15313. * Loops through an array of event types and calls the requested method for each type.
  15314. *
  15315. * @param {Function} fn The event method we want to use.
  15316. * @param {Element|Object} elem Element or object to bind listeners to
  15317. * @param {String} type Type of event to bind to.
  15318. * @param {Function} callback Event listener.
  15319. * @private
  15320. * @function _handleMultipleEvents
  15321. */
  15322. function _handleMultipleEvents(fn, elem, types, callback) {
  15323. types.forEach(function (type) {
  15324. //Call the event method for each one of the types
  15325. fn(elem, type, callback);
  15326. });
  15327. }
  15328. },{"./dom.js":132,"./guid.js":136,"global/document":1,"global/window":2}],134:[function(_dereq_,module,exports){
  15329. /**
  15330. * @file fn.js
  15331. */
  15332. 'use strict';
  15333. exports.__esModule = true;
  15334. var _guidJs = _dereq_('./guid.js');
  15335. /**
  15336. * Bind (a.k.a proxy or Context). A simple method for changing the context of a function
  15337. * It also stores a unique id on the function so it can be easily removed from events
  15338. *
  15339. * @param {*} context The object to bind as scope
  15340. * @param {Function} fn The function to be bound to a scope
  15341. * @param {Number=} uid An optional unique ID for the function to be set
  15342. * @return {Function}
  15343. * @private
  15344. * @method bind
  15345. */
  15346. var bind = function bind(context, fn, uid) {
  15347. // Make sure the function has a unique ID
  15348. if (!fn.guid) {
  15349. fn.guid = _guidJs.newGUID();
  15350. }
  15351. // Create the new function that changes the context
  15352. var ret = function ret() {
  15353. return fn.apply(context, arguments);
  15354. };
  15355. // Allow for the ability to individualize this function
  15356. // Needed in the case where multiple objects might share the same prototype
  15357. // IF both items add an event listener with the same function, then you try to remove just one
  15358. // it will remove both because they both have the same guid.
  15359. // when using this, you need to use the bind method when you remove the listener as well.
  15360. // currently used in text tracks
  15361. ret.guid = uid ? uid + '_' + fn.guid : fn.guid;
  15362. return ret;
  15363. };
  15364. exports.bind = bind;
  15365. },{"./guid.js":136}],135:[function(_dereq_,module,exports){
  15366. /**
  15367. * @file format-time.js
  15368. *
  15369. * Format seconds as a time string, H:MM:SS or M:SS
  15370. * Supplying a guide (in seconds) will force a number of leading zeros
  15371. * to cover the length of the guide
  15372. *
  15373. * @param {Number} seconds Number of seconds to be turned into a string
  15374. * @param {Number} guide Number (in seconds) to model the string after
  15375. * @return {String} Time formatted as H:MM:SS or M:SS
  15376. * @private
  15377. * @function formatTime
  15378. */
  15379. 'use strict';
  15380. exports.__esModule = true;
  15381. function formatTime(seconds) {
  15382. var guide = arguments.length <= 1 || arguments[1] === undefined ? seconds : arguments[1];
  15383. return (function () {
  15384. seconds = seconds < 0 ? 0 : seconds;
  15385. var s = Math.floor(seconds % 60);
  15386. var m = Math.floor(seconds / 60 % 60);
  15387. var h = Math.floor(seconds / 3600);
  15388. var gm = Math.floor(guide / 60 % 60);
  15389. var gh = Math.floor(guide / 3600);
  15390. // handle invalid times
  15391. if (isNaN(seconds) || seconds === Infinity) {
  15392. // '-' is false for all relational operators (e.g. <, >=) so this setting
  15393. // will add the minimum number of fields specified by the guide
  15394. h = m = s = '-';
  15395. }
  15396. // Check if we need to show hours
  15397. h = h > 0 || gh > 0 ? h + ':' : '';
  15398. // If hours are showing, we may need to add a leading zero.
  15399. // Always show at least one digit of minutes.
  15400. m = ((h || gm >= 10) && m < 10 ? '0' + m : m) + ':';
  15401. // Check if leading zero is need for seconds
  15402. s = s < 10 ? '0' + s : s;
  15403. return h + m + s;
  15404. })();
  15405. }
  15406. exports['default'] = formatTime;
  15407. module.exports = exports['default'];
  15408. },{}],136:[function(_dereq_,module,exports){
  15409. /**
  15410. * @file guid.js
  15411. *
  15412. * Unique ID for an element or function
  15413. * @type {Number}
  15414. * @private
  15415. */
  15416. "use strict";
  15417. exports.__esModule = true;
  15418. exports.newGUID = newGUID;
  15419. var _guid = 1;
  15420. /**
  15421. * Get the next unique ID
  15422. *
  15423. * @return {String}
  15424. * @function newGUID
  15425. */
  15426. function newGUID() {
  15427. return _guid++;
  15428. }
  15429. },{}],137:[function(_dereq_,module,exports){
  15430. /**
  15431. * @file log.js
  15432. */
  15433. 'use strict';
  15434. exports.__esModule = true;
  15435. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  15436. var _globalWindow = _dereq_('global/window');
  15437. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  15438. /**
  15439. * Log plain debug messages
  15440. */
  15441. var log = function log() {
  15442. _logType(null, arguments);
  15443. };
  15444. /**
  15445. * Keep a history of log messages
  15446. * @type {Array}
  15447. */
  15448. log.history = [];
  15449. /**
  15450. * Log error messages
  15451. */
  15452. log.error = function () {
  15453. _logType('error', arguments);
  15454. };
  15455. /**
  15456. * Log warning messages
  15457. */
  15458. log.warn = function () {
  15459. _logType('warn', arguments);
  15460. };
  15461. /**
  15462. * Log messages to the console and history based on the type of message
  15463. *
  15464. * @param {String} type The type of message, or `null` for `log`
  15465. * @param {Object} args The args to be passed to the log
  15466. * @private
  15467. * @method _logType
  15468. */
  15469. function _logType(type, args) {
  15470. // convert args to an array to get array functions
  15471. var argsArray = Array.prototype.slice.call(args);
  15472. // if there's no console then don't try to output messages
  15473. // they will still be stored in log.history
  15474. // Was setting these once outside of this function, but containing them
  15475. // in the function makes it easier to test cases where console doesn't exist
  15476. var noop = function noop() {};
  15477. var console = _globalWindow2['default']['console'] || {
  15478. 'log': noop,
  15479. 'warn': noop,
  15480. 'error': noop
  15481. };
  15482. if (type) {
  15483. // add the type to the front of the message
  15484. argsArray.unshift(type.toUpperCase() + ':');
  15485. } else {
  15486. // default to log with no prefix
  15487. type = 'log';
  15488. }
  15489. // add to history
  15490. log.history.push(argsArray);
  15491. // add console prefix after adding to history
  15492. argsArray.unshift('VIDEOJS:');
  15493. // call appropriate log function
  15494. if (console[type].apply) {
  15495. console[type].apply(console, argsArray);
  15496. } else {
  15497. // ie8 doesn't allow error.apply, but it will just join() the array anyway
  15498. console[type](argsArray.join(' '));
  15499. }
  15500. }
  15501. exports['default'] = log;
  15502. module.exports = exports['default'];
  15503. },{"global/window":2}],138:[function(_dereq_,module,exports){
  15504. /**
  15505. * @file merge-options.js
  15506. */
  15507. 'use strict';
  15508. exports.__esModule = true;
  15509. exports['default'] = mergeOptions;
  15510. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  15511. var _lodashCompatObjectMerge = _dereq_('lodash-compat/object/merge');
  15512. var _lodashCompatObjectMerge2 = _interopRequireDefault(_lodashCompatObjectMerge);
  15513. function isPlain(obj) {
  15514. return !!obj && typeof obj === 'object' && obj.toString() === '[object Object]' && obj.constructor === Object;
  15515. }
  15516. /**
  15517. * Merge customizer. video.js simply overwrites non-simple objects
  15518. * (like arrays) instead of attempting to overlay them.
  15519. * @see https://lodash.com/docs#merge
  15520. */
  15521. var customizer = function customizer(destination, source) {
  15522. // If we're not working with a plain object, copy the value as is
  15523. // If source is an array, for instance, it will replace destination
  15524. if (!isPlain(source)) {
  15525. return source;
  15526. }
  15527. // If the new value is a plain object but the first object value is not
  15528. // we need to create a new object for the first object to merge with.
  15529. // This makes it consistent with how merge() works by default
  15530. // and also protects from later changes the to first object affecting
  15531. // the second object's values.
  15532. if (!isPlain(destination)) {
  15533. return mergeOptions(source);
  15534. }
  15535. };
  15536. /**
  15537. * Merge one or more options objects, recursively merging **only**
  15538. * plain object properties. Previously `deepMerge`.
  15539. *
  15540. * @param {...Object} source One or more objects to merge
  15541. * @returns {Object} a new object that is the union of all
  15542. * provided objects
  15543. * @function mergeOptions
  15544. */
  15545. function mergeOptions() {
  15546. // contruct the call dynamically to handle the variable number of
  15547. // objects to merge
  15548. var args = Array.prototype.slice.call(arguments);
  15549. // unshift an empty object into the front of the call as the target
  15550. // of the merge
  15551. args.unshift({});
  15552. // customize conflict resolution to match our historical merge behavior
  15553. args.push(customizer);
  15554. _lodashCompatObjectMerge2['default'].apply(null, args);
  15555. // return the mutated result object
  15556. return args[0];
  15557. }
  15558. module.exports = exports['default'];
  15559. },{"lodash-compat/object/merge":40}],139:[function(_dereq_,module,exports){
  15560. 'use strict';
  15561. exports.__esModule = true;
  15562. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  15563. var _globalDocument = _dereq_('global/document');
  15564. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  15565. var createStyleElement = function createStyleElement(className) {
  15566. var style = _globalDocument2['default'].createElement('style');
  15567. style.className = className;
  15568. return style;
  15569. };
  15570. exports.createStyleElement = createStyleElement;
  15571. var setTextContent = function setTextContent(el, content) {
  15572. if (el.styleSheet) {
  15573. el.styleSheet.cssText = content;
  15574. } else {
  15575. el.textContent = content;
  15576. }
  15577. };
  15578. exports.setTextContent = setTextContent;
  15579. },{"global/document":1}],140:[function(_dereq_,module,exports){
  15580. 'use strict';
  15581. exports.__esModule = true;
  15582. exports.createTimeRanges = createTimeRanges;
  15583. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  15584. var _logJs = _dereq_('./log.js');
  15585. var _logJs2 = _interopRequireDefault(_logJs);
  15586. /**
  15587. * @file time-ranges.js
  15588. *
  15589. * Should create a fake TimeRange object
  15590. * Mimics an HTML5 time range instance, which has functions that
  15591. * return the start and end times for a range
  15592. * TimeRanges are returned by the buffered() method
  15593. *
  15594. * @param {(Number|Array)} Start of a single range or an array of ranges
  15595. * @param {Number} End of a single range
  15596. * @private
  15597. * @method createTimeRanges
  15598. */
  15599. function createTimeRanges(start, end) {
  15600. if (Array.isArray(start)) {
  15601. return createTimeRangesObj(start);
  15602. } else if (start === undefined || end === undefined) {
  15603. return createTimeRangesObj();
  15604. }
  15605. return createTimeRangesObj([[start, end]]);
  15606. }
  15607. exports.createTimeRange = createTimeRanges;
  15608. function createTimeRangesObj(ranges) {
  15609. if (ranges === undefined || ranges.length === 0) {
  15610. return {
  15611. length: 0,
  15612. start: function start() {
  15613. throw new Error('This TimeRanges object is empty');
  15614. },
  15615. end: function end() {
  15616. throw new Error('This TimeRanges object is empty');
  15617. }
  15618. };
  15619. }
  15620. return {
  15621. length: ranges.length,
  15622. start: getRange.bind(null, 'start', 0, ranges),
  15623. end: getRange.bind(null, 'end', 1, ranges)
  15624. };
  15625. }
  15626. function getRange(fnName, valueIndex, ranges, rangeIndex) {
  15627. if (rangeIndex === undefined) {
  15628. _logJs2['default'].warn('DEPRECATED: Function \'' + fnName + '\' on \'TimeRanges\' called without an index argument.');
  15629. rangeIndex = 0;
  15630. }
  15631. rangeCheck(fnName, rangeIndex, ranges.length - 1);
  15632. return ranges[rangeIndex][valueIndex];
  15633. }
  15634. function rangeCheck(fnName, index, maxIndex) {
  15635. if (index < 0 || index > maxIndex) {
  15636. throw new Error('Failed to execute \'' + fnName + '\' on \'TimeRanges\': The index provided (' + index + ') is greater than or equal to the maximum bound (' + maxIndex + ').');
  15637. }
  15638. }
  15639. },{"./log.js":137}],141:[function(_dereq_,module,exports){
  15640. /**
  15641. * @file to-title-case.js
  15642. *
  15643. * Uppercase the first letter of a string
  15644. *
  15645. * @param {String} string String to be uppercased
  15646. * @return {String}
  15647. * @private
  15648. * @method toTitleCase
  15649. */
  15650. "use strict";
  15651. exports.__esModule = true;
  15652. function toTitleCase(string) {
  15653. return string.charAt(0).toUpperCase() + string.slice(1);
  15654. }
  15655. exports["default"] = toTitleCase;
  15656. module.exports = exports["default"];
  15657. },{}],142:[function(_dereq_,module,exports){
  15658. /**
  15659. * @file url.js
  15660. */
  15661. 'use strict';
  15662. exports.__esModule = true;
  15663. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  15664. var _globalDocument = _dereq_('global/document');
  15665. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  15666. var _globalWindow = _dereq_('global/window');
  15667. var _globalWindow2 = _interopRequireDefault(_globalWindow);
  15668. /**
  15669. * Resolve and parse the elements of a URL
  15670. *
  15671. * @param {String} url The url to parse
  15672. * @return {Object} An object of url details
  15673. * @method parseUrl
  15674. */
  15675. var parseUrl = function parseUrl(url) {
  15676. var props = ['protocol', 'hostname', 'port', 'pathname', 'search', 'hash', 'host'];
  15677. // add the url to an anchor and let the browser parse the URL
  15678. var a = _globalDocument2['default'].createElement('a');
  15679. a.href = url;
  15680. // IE8 (and 9?) Fix
  15681. // ie8 doesn't parse the URL correctly until the anchor is actually
  15682. // added to the body, and an innerHTML is needed to trigger the parsing
  15683. var addToBody = a.host === '' && a.protocol !== 'file:';
  15684. var div = undefined;
  15685. if (addToBody) {
  15686. div = _globalDocument2['default'].createElement('div');
  15687. div.innerHTML = '<a href="' + url + '"></a>';
  15688. a = div.firstChild;
  15689. // prevent the div from affecting layout
  15690. div.setAttribute('style', 'display:none; position:absolute;');
  15691. _globalDocument2['default'].body.appendChild(div);
  15692. }
  15693. // Copy the specific URL properties to a new object
  15694. // This is also needed for IE8 because the anchor loses its
  15695. // properties when it's removed from the dom
  15696. var details = {};
  15697. for (var i = 0; i < props.length; i++) {
  15698. details[props[i]] = a[props[i]];
  15699. }
  15700. // IE9 adds the port to the host property unlike everyone else. If
  15701. // a port identifier is added for standard ports, strip it.
  15702. if (details.protocol === 'http:') {
  15703. details.host = details.host.replace(/:80$/, '');
  15704. }
  15705. if (details.protocol === 'https:') {
  15706. details.host = details.host.replace(/:443$/, '');
  15707. }
  15708. if (addToBody) {
  15709. _globalDocument2['default'].body.removeChild(div);
  15710. }
  15711. return details;
  15712. };
  15713. exports.parseUrl = parseUrl;
  15714. /**
  15715. * Get absolute version of relative URL. Used to tell flash correct URL.
  15716. * http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue
  15717. *
  15718. * @param {String} url URL to make absolute
  15719. * @return {String} Absolute URL
  15720. * @private
  15721. * @method getAbsoluteURL
  15722. */
  15723. var getAbsoluteURL = function getAbsoluteURL(url) {
  15724. // Check if absolute URL
  15725. if (!url.match(/^https?:\/\//)) {
  15726. // Convert to absolute URL. Flash hosted off-site needs an absolute URL.
  15727. var div = _globalDocument2['default'].createElement('div');
  15728. div.innerHTML = '<a href="' + url + '">x</a>';
  15729. url = div.firstChild.href;
  15730. }
  15731. return url;
  15732. };
  15733. exports.getAbsoluteURL = getAbsoluteURL;
  15734. /**
  15735. * Returns the extension of the passed file name. It will return an empty string if you pass an invalid path
  15736. *
  15737. * @param {String} path The fileName path like '/path/to/file.mp4'
  15738. * @returns {String} The extension in lower case or an empty string if no extension could be found.
  15739. * @method getFileExtension
  15740. */
  15741. var getFileExtension = function getFileExtension(path) {
  15742. if (typeof path === 'string') {
  15743. var splitPathRe = /^(\/?)([\s\S]*?)((?:\.{1,2}|[^\/]+?)(\.([^\.\/\?]+)))(?:[\/]*|[\?].*)$/i;
  15744. var pathParts = splitPathRe.exec(path);
  15745. if (pathParts) {
  15746. return pathParts.pop().toLowerCase();
  15747. }
  15748. }
  15749. return '';
  15750. };
  15751. exports.getFileExtension = getFileExtension;
  15752. /**
  15753. * Returns whether the url passed is a cross domain request or not.
  15754. *
  15755. * @param {String} url The url to check
  15756. * @return {Boolean} Whether it is a cross domain request or not
  15757. * @method isCrossOrigin
  15758. */
  15759. var isCrossOrigin = function isCrossOrigin(url) {
  15760. var winLoc = _globalWindow2['default'].location;
  15761. var urlInfo = parseUrl(url);
  15762. // IE8 protocol relative urls will return ':' for protocol
  15763. var srcProtocol = urlInfo.protocol === ':' ? winLoc.protocol : urlInfo.protocol;
  15764. // Check if url is for another domain/origin
  15765. // IE8 doesn't know location.origin, so we won't rely on it here
  15766. var crossOrigin = srcProtocol + urlInfo.host !== winLoc.protocol + winLoc.host;
  15767. return crossOrigin;
  15768. };
  15769. exports.isCrossOrigin = isCrossOrigin;
  15770. },{"global/document":1,"global/window":2}],143:[function(_dereq_,module,exports){
  15771. /**
  15772. * @file video.js
  15773. */
  15774. 'use strict';
  15775. exports.__esModule = true;
  15776. 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; } }
  15777. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  15778. var _globalDocument = _dereq_('global/document');
  15779. var _globalDocument2 = _interopRequireDefault(_globalDocument);
  15780. var _setup = _dereq_('./setup');
  15781. var setup = _interopRequireWildcard(_setup);
  15782. var _utilsStylesheetJs = _dereq_('./utils/stylesheet.js');
  15783. var stylesheet = _interopRequireWildcard(_utilsStylesheetJs);
  15784. var _component = _dereq_('./component');
  15785. var _component2 = _interopRequireDefault(_component);
  15786. var _eventTarget = _dereq_('./event-target');
  15787. var _eventTarget2 = _interopRequireDefault(_eventTarget);
  15788. var _utilsEventsJs = _dereq_('./utils/events.js');
  15789. var Events = _interopRequireWildcard(_utilsEventsJs);
  15790. var _player = _dereq_('./player');
  15791. var _player2 = _interopRequireDefault(_player);
  15792. var _pluginsJs = _dereq_('./plugins.js');
  15793. var _pluginsJs2 = _interopRequireDefault(_pluginsJs);
  15794. var _srcJsUtilsMergeOptionsJs = _dereq_('../../src/js/utils/merge-options.js');
  15795. var _srcJsUtilsMergeOptionsJs2 = _interopRequireDefault(_srcJsUtilsMergeOptionsJs);
  15796. var _utilsFnJs = _dereq_('./utils/fn.js');
  15797. var Fn = _interopRequireWildcard(_utilsFnJs);
  15798. var _tracksTextTrackJs = _dereq_('./tracks/text-track.js');
  15799. var _tracksTextTrackJs2 = _interopRequireDefault(_tracksTextTrackJs);
  15800. var _objectAssign = _dereq_('object.assign');
  15801. var _objectAssign2 = _interopRequireDefault(_objectAssign);
  15802. var _utilsTimeRangesJs = _dereq_('./utils/time-ranges.js');
  15803. var _utilsFormatTimeJs = _dereq_('./utils/format-time.js');
  15804. var _utilsFormatTimeJs2 = _interopRequireDefault(_utilsFormatTimeJs);
  15805. var _utilsLogJs = _dereq_('./utils/log.js');
  15806. var _utilsLogJs2 = _interopRequireDefault(_utilsLogJs);
  15807. var _utilsDomJs = _dereq_('./utils/dom.js');
  15808. var Dom = _interopRequireWildcard(_utilsDomJs);
  15809. var _utilsBrowserJs = _dereq_('./utils/browser.js');
  15810. var browser = _interopRequireWildcard(_utilsBrowserJs);
  15811. var _utilsUrlJs = _dereq_('./utils/url.js');
  15812. var Url = _interopRequireWildcard(_utilsUrlJs);
  15813. var _extendJs = _dereq_('./extend.js');
  15814. var _extendJs2 = _interopRequireDefault(_extendJs);
  15815. var _lodashCompatObjectMerge = _dereq_('lodash-compat/object/merge');
  15816. var _lodashCompatObjectMerge2 = _interopRequireDefault(_lodashCompatObjectMerge);
  15817. var _utilsCreateDeprecationProxyJs = _dereq_('./utils/create-deprecation-proxy.js');
  15818. var _utilsCreateDeprecationProxyJs2 = _interopRequireDefault(_utilsCreateDeprecationProxyJs);
  15819. var _xhr = _dereq_('xhr');
  15820. var _xhr2 = _interopRequireDefault(_xhr);
  15821. // Include the built-in techs
  15822. var _techTechJs = _dereq_('./tech/tech.js');
  15823. var _techTechJs2 = _interopRequireDefault(_techTechJs);
  15824. var _techHtml5Js = _dereq_('./tech/html5.js');
  15825. var _techHtml5Js2 = _interopRequireDefault(_techHtml5Js);
  15826. var _techFlashJs = _dereq_('./tech/flash.js');
  15827. var _techFlashJs2 = _interopRequireDefault(_techFlashJs);
  15828. // HTML5 Element Shim for IE8
  15829. if (typeof HTMLVideoElement === 'undefined') {
  15830. _globalDocument2['default'].createElement('video');
  15831. _globalDocument2['default'].createElement('audio');
  15832. _globalDocument2['default'].createElement('track');
  15833. }
  15834. /**
  15835. * Doubles as the main function for users to create a player instance and also
  15836. * the main library object.
  15837. * The `videojs` function can be used to initialize or retrieve a player.
  15838. * ```js
  15839. * var myPlayer = videojs('my_video_id');
  15840. * ```
  15841. *
  15842. * @param {String|Element} id Video element or video element ID
  15843. * @param {Object=} options Optional options object for config/settings
  15844. * @param {Function=} ready Optional ready callback
  15845. * @return {Player} A player instance
  15846. * @mixes videojs
  15847. * @method videojs
  15848. */
  15849. var videojs = function videojs(id, options, ready) {
  15850. var tag = undefined; // Element of ID
  15851. // Allow for element or ID to be passed in
  15852. // String ID
  15853. if (typeof id === 'string') {
  15854. // Adjust for jQuery ID syntax
  15855. if (id.indexOf('#') === 0) {
  15856. id = id.slice(1);
  15857. }
  15858. // If a player instance has already been created for this ID return it.
  15859. if (videojs.getPlayers()[id]) {
  15860. // If options or ready funtion are passed, warn
  15861. if (options) {
  15862. _utilsLogJs2['default'].warn('Player "' + id + '" is already initialised. Options will not be applied.');
  15863. }
  15864. if (ready) {
  15865. videojs.getPlayers()[id].ready(ready);
  15866. }
  15867. return videojs.getPlayers()[id];
  15868. // Otherwise get element for ID
  15869. } else {
  15870. tag = Dom.getEl(id);
  15871. }
  15872. // ID is a media element
  15873. } else {
  15874. tag = id;
  15875. }
  15876. // Check for a useable element
  15877. if (!tag || !tag.nodeName) {
  15878. // re: nodeName, could be a box div also
  15879. throw new TypeError('The element or ID supplied is not valid. (videojs)'); // Returns
  15880. }
  15881. // Element may have a player attr referring to an already created player instance.
  15882. // If not, set up a new player and return the instance.
  15883. return tag['player'] || _player2['default'].players[tag.playerId] || new _player2['default'](tag, options, ready);
  15884. };
  15885. // Add default styles
  15886. var style = Dom.$('.vjs-styles-defaults');
  15887. if (!style) {
  15888. style = stylesheet.createStyleElement('vjs-styles-defaults');
  15889. var head = Dom.$('head');
  15890. head.insertBefore(style, head.firstChild);
  15891. stylesheet.setTextContent(style, '\n .video-js {\n width: 300px;\n height: 150px;\n }\n\n .vjs-fluid {\n padding-top: 56.25%\n }\n ');
  15892. }
  15893. // Run Auto-load players
  15894. // You have to wait at least once in case this script is loaded after your video in the DOM (weird behavior only with minified version)
  15895. setup.autoSetupTimeout(1, videojs);
  15896. /*
  15897. * Current software version (semver)
  15898. *
  15899. * @type {String}
  15900. */
  15901. videojs.VERSION = '5.8.8';
  15902. /**
  15903. * The global options object. These are the settings that take effect
  15904. * if no overrides are specified when the player is created.
  15905. *
  15906. * ```js
  15907. * videojs.options.autoplay = true
  15908. * // -> all players will autoplay by default
  15909. * ```
  15910. *
  15911. * @type {Object}
  15912. */
  15913. videojs.options = _player2['default'].prototype.options_;
  15914. /**
  15915. * Get an object with the currently created players, keyed by player ID
  15916. *
  15917. * @return {Object} The created players
  15918. * @mixes videojs
  15919. * @method getPlayers
  15920. */
  15921. videojs.getPlayers = function () {
  15922. return _player2['default'].players;
  15923. };
  15924. /**
  15925. * For backward compatibility, expose players object.
  15926. *
  15927. * @deprecated
  15928. * @memberOf videojs
  15929. * @property {Object|Proxy} players
  15930. */
  15931. videojs.players = _utilsCreateDeprecationProxyJs2['default'](_player2['default'].players, {
  15932. get: 'Access to videojs.players is deprecated; use videojs.getPlayers instead',
  15933. set: 'Modification of videojs.players is deprecated'
  15934. });
  15935. /**
  15936. * Get a component class object by name
  15937. * ```js
  15938. * var VjsButton = videojs.getComponent('Button');
  15939. * // Create a new instance of the component
  15940. * var myButton = new VjsButton(myPlayer);
  15941. * ```
  15942. *
  15943. * @return {Component} Component identified by name
  15944. * @mixes videojs
  15945. * @method getComponent
  15946. */
  15947. videojs.getComponent = _component2['default'].getComponent;
  15948. /**
  15949. * Register a component so it can referred to by name
  15950. * Used when adding to other
  15951. * components, either through addChild
  15952. * `component.addChild('myComponent')`
  15953. * or through default children options
  15954. * `{ children: ['myComponent'] }`.
  15955. * ```js
  15956. * // Get a component to subclass
  15957. * var VjsButton = videojs.getComponent('Button');
  15958. * // Subclass the component (see 'extend' doc for more info)
  15959. * var MySpecialButton = videojs.extend(VjsButton, {});
  15960. * // Register the new component
  15961. * VjsButton.registerComponent('MySepcialButton', MySepcialButton);
  15962. * // (optionally) add the new component as a default player child
  15963. * myPlayer.addChild('MySepcialButton');
  15964. * ```
  15965. * NOTE: You could also just initialize the component before adding.
  15966. * `component.addChild(new MyComponent());`
  15967. *
  15968. * @param {String} The class name of the component
  15969. * @param {Component} The component class
  15970. * @return {Component} The newly registered component
  15971. * @mixes videojs
  15972. * @method registerComponent
  15973. */
  15974. videojs.registerComponent = function (name, comp) {
  15975. if (_techTechJs2['default'].isTech(comp)) {
  15976. _utilsLogJs2['default'].warn('The ' + name + ' tech was registered as a component. It should instead be registered using videojs.registerTech(name, tech)');
  15977. }
  15978. _component2['default'].registerComponent.call(_component2['default'], name, comp);
  15979. };
  15980. /**
  15981. * Get a Tech class object by name
  15982. * ```js
  15983. * var Html5 = videojs.getTech('Html5');
  15984. * // Create a new instance of the component
  15985. * var html5 = new Html5(options);
  15986. * ```
  15987. *
  15988. * @return {Tech} Tech identified by name
  15989. * @mixes videojs
  15990. * @method getComponent
  15991. */
  15992. videojs.getTech = _techTechJs2['default'].getTech;
  15993. /**
  15994. * Register a Tech so it can referred to by name.
  15995. * This is used in the tech order for the player.
  15996. *
  15997. * ```js
  15998. * // get the Html5 Tech
  15999. * var Html5 = videojs.getTech('Html5');
  16000. * var MyTech = videojs.extend(Html5, {});
  16001. * // Register the new Tech
  16002. * VjsButton.registerTech('Tech', MyTech);
  16003. * var player = videojs('myplayer', {
  16004. * techOrder: ['myTech', 'html5']
  16005. * });
  16006. * ```
  16007. *
  16008. * @param {String} The class name of the tech
  16009. * @param {Tech} The tech class
  16010. * @return {Tech} The newly registered Tech
  16011. * @mixes videojs
  16012. * @method registerTech
  16013. */
  16014. videojs.registerTech = _techTechJs2['default'].registerTech;
  16015. /**
  16016. * A suite of browser and device tests
  16017. *
  16018. * @type {Object}
  16019. * @private
  16020. */
  16021. videojs.browser = browser;
  16022. /**
  16023. * Whether or not the browser supports touch events. Included for backward
  16024. * compatibility with 4.x, but deprecated. Use `videojs.browser.TOUCH_ENABLED`
  16025. * instead going forward.
  16026. *
  16027. * @deprecated
  16028. * @type {Boolean}
  16029. */
  16030. videojs.TOUCH_ENABLED = browser.TOUCH_ENABLED;
  16031. /**
  16032. * Subclass an existing class
  16033. * Mimics ES6 subclassing with the `extend` keyword
  16034. * ```js
  16035. * // Create a basic javascript 'class'
  16036. * function MyClass(name){
  16037. * // Set a property at initialization
  16038. * this.myName = name;
  16039. * }
  16040. * // Create an instance method
  16041. * MyClass.prototype.sayMyName = function(){
  16042. * alert(this.myName);
  16043. * };
  16044. * // Subclass the exisitng class and change the name
  16045. * // when initializing
  16046. * var MySubClass = videojs.extend(MyClass, {
  16047. * constructor: function(name) {
  16048. * // Call the super class constructor for the subclass
  16049. * MyClass.call(this, name)
  16050. * }
  16051. * });
  16052. * // Create an instance of the new sub class
  16053. * var myInstance = new MySubClass('John');
  16054. * myInstance.sayMyName(); // -> should alert "John"
  16055. * ```
  16056. *
  16057. * @param {Function} The Class to subclass
  16058. * @param {Object} An object including instace methods for the new class
  16059. * Optionally including a `constructor` function
  16060. * @return {Function} The newly created subclass
  16061. * @mixes videojs
  16062. * @method extend
  16063. */
  16064. videojs.extend = _extendJs2['default'];
  16065. /**
  16066. * Merge two options objects recursively
  16067. * Performs a deep merge like lodash.merge but **only merges plain objects**
  16068. * (not arrays, elements, anything else)
  16069. * Other values will be copied directly from the second object.
  16070. * ```js
  16071. * var defaultOptions = {
  16072. * foo: true,
  16073. * bar: {
  16074. * a: true,
  16075. * b: [1,2,3]
  16076. * }
  16077. * };
  16078. * var newOptions = {
  16079. * foo: false,
  16080. * bar: {
  16081. * b: [4,5,6]
  16082. * }
  16083. * };
  16084. * var result = videojs.mergeOptions(defaultOptions, newOptions);
  16085. * // result.foo = false;
  16086. * // result.bar.a = true;
  16087. * // result.bar.b = [4,5,6];
  16088. * ```
  16089. *
  16090. * @param {Object} defaults The options object whose values will be overriden
  16091. * @param {Object} overrides The options object with values to override the first
  16092. * @param {Object} etc Any number of additional options objects
  16093. *
  16094. * @return {Object} a new object with the merged values
  16095. * @mixes videojs
  16096. * @method mergeOptions
  16097. */
  16098. videojs.mergeOptions = _srcJsUtilsMergeOptionsJs2['default'];
  16099. /**
  16100. * Change the context (this) of a function
  16101. *
  16102. * videojs.bind(newContext, function(){
  16103. * this === newContext
  16104. * });
  16105. *
  16106. * NOTE: as of v5.0 we require an ES5 shim, so you should use the native
  16107. * `function(){}.bind(newContext);` instead of this.
  16108. *
  16109. * @param {*} context The object to bind as scope
  16110. * @param {Function} fn The function to be bound to a scope
  16111. * @param {Number=} uid An optional unique ID for the function to be set
  16112. * @return {Function}
  16113. */
  16114. videojs.bind = Fn.bind;
  16115. /**
  16116. * Create a Video.js player plugin
  16117. * Plugins are only initialized when options for the plugin are included
  16118. * in the player options, or the plugin function on the player instance is
  16119. * called.
  16120. * **See the plugin guide in the docs for a more detailed example**
  16121. * ```js
  16122. * // Make a plugin that alerts when the player plays
  16123. * videojs.plugin('myPlugin', function(myPluginOptions) {
  16124. * myPluginOptions = myPluginOptions || {};
  16125. *
  16126. * var player = this;
  16127. * var alertText = myPluginOptions.text || 'Player is playing!'
  16128. *
  16129. * player.on('play', function(){
  16130. * alert(alertText);
  16131. * });
  16132. * });
  16133. * // USAGE EXAMPLES
  16134. * // EXAMPLE 1: New player with plugin options, call plugin immediately
  16135. * var player1 = videojs('idOne', {
  16136. * myPlugin: {
  16137. * text: 'Custom text!'
  16138. * }
  16139. * });
  16140. * // Click play
  16141. * // --> Should alert 'Custom text!'
  16142. * // EXAMPLE 3: New player, initialize plugin later
  16143. * var player3 = videojs('idThree');
  16144. * // Click play
  16145. * // --> NO ALERT
  16146. * // Click pause
  16147. * // Initialize plugin using the plugin function on the player instance
  16148. * player3.myPlugin({
  16149. * text: 'Plugin added later!'
  16150. * });
  16151. * // Click play
  16152. * // --> Should alert 'Plugin added later!'
  16153. * ```
  16154. *
  16155. * @param {String} name The plugin name
  16156. * @param {Function} fn The plugin function that will be called with options
  16157. * @mixes videojs
  16158. * @method plugin
  16159. */
  16160. videojs.plugin = _pluginsJs2['default'];
  16161. /**
  16162. * Adding languages so that they're available to all players.
  16163. * ```js
  16164. * videojs.addLanguage('es', { 'Hello': 'Hola' });
  16165. * ```
  16166. *
  16167. * @param {String} code The language code or dictionary property
  16168. * @param {Object} data The data values to be translated
  16169. * @return {Object} The resulting language dictionary object
  16170. * @mixes videojs
  16171. * @method addLanguage
  16172. */
  16173. videojs.addLanguage = function (code, data) {
  16174. var _merge;
  16175. code = ('' + code).toLowerCase();
  16176. return _lodashCompatObjectMerge2['default'](videojs.options.languages, (_merge = {}, _merge[code] = data, _merge))[code];
  16177. };
  16178. /**
  16179. * Log debug messages.
  16180. *
  16181. * @param {...Object} messages One or more messages to log
  16182. */
  16183. videojs.log = _utilsLogJs2['default'];
  16184. /**
  16185. * Creates an emulated TimeRange object.
  16186. *
  16187. * @param {Number|Array} start Start time in seconds or an array of ranges
  16188. * @param {Number} end End time in seconds
  16189. * @return {Object} Fake TimeRange object
  16190. * @method createTimeRange
  16191. */
  16192. videojs.createTimeRange = videojs.createTimeRanges = _utilsTimeRangesJs.createTimeRanges;
  16193. /**
  16194. * Format seconds as a time string, H:MM:SS or M:SS
  16195. * Supplying a guide (in seconds) will force a number of leading zeros
  16196. * to cover the length of the guide
  16197. *
  16198. * @param {Number} seconds Number of seconds to be turned into a string
  16199. * @param {Number} guide Number (in seconds) to model the string after
  16200. * @return {String} Time formatted as H:MM:SS or M:SS
  16201. * @method formatTime
  16202. */
  16203. videojs.formatTime = _utilsFormatTimeJs2['default'];
  16204. /**
  16205. * Resolve and parse the elements of a URL
  16206. *
  16207. * @param {String} url The url to parse
  16208. * @return {Object} An object of url details
  16209. * @method parseUrl
  16210. */
  16211. videojs.parseUrl = Url.parseUrl;
  16212. /**
  16213. * Returns whether the url passed is a cross domain request or not.
  16214. *
  16215. * @param {String} url The url to check
  16216. * @return {Boolean} Whether it is a cross domain request or not
  16217. * @method isCrossOrigin
  16218. */
  16219. videojs.isCrossOrigin = Url.isCrossOrigin;
  16220. /**
  16221. * Event target class.
  16222. *
  16223. * @type {Function}
  16224. */
  16225. videojs.EventTarget = _eventTarget2['default'];
  16226. /**
  16227. * Add an event listener to element
  16228. * It stores the handler function in a separate cache object
  16229. * and adds a generic handler to the element's event,
  16230. * along with a unique id (guid) to the element.
  16231. *
  16232. * @param {Element|Object} elem Element or object to bind listeners to
  16233. * @param {String|Array} type Type of event to bind to.
  16234. * @param {Function} fn Event listener.
  16235. * @method on
  16236. */
  16237. videojs.on = Events.on;
  16238. /**
  16239. * Trigger a listener only once for an event
  16240. *
  16241. * @param {Element|Object} elem Element or object to
  16242. * @param {String|Array} type Name/type of event
  16243. * @param {Function} fn Event handler function
  16244. * @method one
  16245. */
  16246. videojs.one = Events.one;
  16247. /**
  16248. * Removes event listeners from an element
  16249. *
  16250. * @param {Element|Object} elem Object to remove listeners from
  16251. * @param {String|Array=} type Type of listener to remove. Don't include to remove all events from element.
  16252. * @param {Function} fn Specific listener to remove. Don't include to remove listeners for an event type.
  16253. * @method off
  16254. */
  16255. videojs.off = Events.off;
  16256. /**
  16257. * Trigger an event for an element
  16258. *
  16259. * @param {Element|Object} elem Element to trigger an event on
  16260. * @param {Event|Object|String} event A string (the type) or an event object with a type attribute
  16261. * @param {Object} [hash] data hash to pass along with the event
  16262. * @return {Boolean=} Returned only if default was prevented
  16263. * @method trigger
  16264. */
  16265. videojs.trigger = Events.trigger;
  16266. /**
  16267. * A cross-browser XMLHttpRequest wrapper. Here's a simple example:
  16268. *
  16269. * videojs.xhr({
  16270. * body: someJSONString,
  16271. * uri: "/foo",
  16272. * headers: {
  16273. * "Content-Type": "application/json"
  16274. * }
  16275. * }, function (err, resp, body) {
  16276. * // check resp.statusCode
  16277. * });
  16278. *
  16279. * Check out the [full
  16280. * documentation](https://github.com/Raynos/xhr/blob/v2.1.0/README.md)
  16281. * for more options.
  16282. *
  16283. * @param {Object} options settings for the request.
  16284. * @return {XMLHttpRequest|XDomainRequest} the request object.
  16285. * @see https://github.com/Raynos/xhr
  16286. */
  16287. videojs.xhr = _xhr2['default'];
  16288. /**
  16289. * TextTrack class
  16290. *
  16291. * @type {Function}
  16292. */
  16293. videojs.TextTrack = _tracksTextTrackJs2['default'];
  16294. /**
  16295. * Determines, via duck typing, whether or not a value is a DOM element.
  16296. *
  16297. * @method isEl
  16298. * @param {Mixed} value
  16299. * @return {Boolean}
  16300. */
  16301. videojs.isEl = Dom.isEl;
  16302. /**
  16303. * Determines, via duck typing, whether or not a value is a text node.
  16304. *
  16305. * @method isTextNode
  16306. * @param {Mixed} value
  16307. * @return {Boolean}
  16308. */
  16309. videojs.isTextNode = Dom.isTextNode;
  16310. /**
  16311. * Creates an element and applies properties.
  16312. *
  16313. * @method createEl
  16314. * @param {String} [tagName='div'] Name of tag to be created.
  16315. * @param {Object} [properties={}] Element properties to be applied.
  16316. * @param {Object} [attributes={}] Element attributes to be applied.
  16317. * @return {Element}
  16318. */
  16319. videojs.createEl = Dom.createEl;
  16320. /**
  16321. * Check if an element has a CSS class
  16322. *
  16323. * @method hasClass
  16324. * @param {Element} element Element to check
  16325. * @param {String} classToCheck Classname to check
  16326. */
  16327. videojs.hasClass = Dom.hasElClass;
  16328. /**
  16329. * Add a CSS class name to an element
  16330. *
  16331. * @method addClass
  16332. * @param {Element} element Element to add class name to
  16333. * @param {String} classToAdd Classname to add
  16334. */
  16335. videojs.addClass = Dom.addElClass;
  16336. /**
  16337. * Remove a CSS class name from an element
  16338. *
  16339. * @method removeClass
  16340. * @param {Element} element Element to remove from class name
  16341. * @param {String} classToRemove Classname to remove
  16342. */
  16343. videojs.removeClass = Dom.removeElClass;
  16344. /**
  16345. * Adds or removes a CSS class name on an element depending on an optional
  16346. * condition or the presence/absence of the class name.
  16347. *
  16348. * @method toggleElClass
  16349. * @param {Element} element
  16350. * @param {String} classToToggle
  16351. * @param {Boolean|Function} [predicate]
  16352. * Can be a function that returns a Boolean. If `true`, the class
  16353. * will be added; if `false`, the class will be removed. If not
  16354. * given, the class will be added if not present and vice versa.
  16355. */
  16356. videojs.toggleClass = Dom.toggleElClass;
  16357. /**
  16358. * Apply attributes to an HTML element.
  16359. *
  16360. * @method setAttributes
  16361. * @param {Element} el Target element.
  16362. * @param {Object=} attributes Element attributes to be applied.
  16363. */
  16364. videojs.setAttributes = Dom.setElAttributes;
  16365. /**
  16366. * Get an element's attribute values, as defined on the HTML tag
  16367. * Attributes are not the same as properties. They're defined on the tag
  16368. * or with setAttribute (which shouldn't be used with HTML)
  16369. * This will return true or false for boolean attributes.
  16370. *
  16371. * @method getAttributes
  16372. * @param {Element} tag Element from which to get tag attributes
  16373. * @return {Object}
  16374. */
  16375. videojs.getAttributes = Dom.getElAttributes;
  16376. /**
  16377. * Empties the contents of an element.
  16378. *
  16379. * @method emptyEl
  16380. * @param {Element} el
  16381. * @return {Element}
  16382. */
  16383. videojs.emptyEl = Dom.emptyEl;
  16384. /**
  16385. * Normalizes and appends content to an element.
  16386. *
  16387. * The content for an element can be passed in multiple types and
  16388. * combinations, whose behavior is as follows:
  16389. *
  16390. * - String
  16391. * Normalized into a text node.
  16392. *
  16393. * - Element, TextNode
  16394. * Passed through.
  16395. *
  16396. * - Array
  16397. * A one-dimensional array of strings, elements, nodes, or functions (which
  16398. * return single strings, elements, or nodes).
  16399. *
  16400. * - Function
  16401. * If the sole argument, is expected to produce a string, element,
  16402. * node, or array.
  16403. *
  16404. * @method appendContent
  16405. * @param {Element} el
  16406. * @param {String|Element|TextNode|Array|Function} content
  16407. * @return {Element}
  16408. */
  16409. videojs.appendContent = Dom.appendContent;
  16410. /**
  16411. * Normalizes and inserts content into an element; this is identical to
  16412. * `appendContent()`, except it empties the element first.
  16413. *
  16414. * The content for an element can be passed in multiple types and
  16415. * combinations, whose behavior is as follows:
  16416. *
  16417. * - String
  16418. * Normalized into a text node.
  16419. *
  16420. * - Element, TextNode
  16421. * Passed through.
  16422. *
  16423. * - Array
  16424. * A one-dimensional array of strings, elements, nodes, or functions (which
  16425. * return single strings, elements, or nodes).
  16426. *
  16427. * - Function
  16428. * If the sole argument, is expected to produce a string, element,
  16429. * node, or array.
  16430. *
  16431. * @method insertContent
  16432. * @param {Element} el
  16433. * @param {String|Element|TextNode|Array|Function} content
  16434. * @return {Element}
  16435. */
  16436. videojs.insertContent = Dom.insertContent;
  16437. /*
  16438. * Custom Universal Module Definition (UMD)
  16439. *
  16440. * Video.js will never be a non-browser lib so we can simplify UMD a bunch and
  16441. * still support requirejs and browserify. This also needs to be closure
  16442. * compiler compatible, so string keys are used.
  16443. */
  16444. if (typeof define === 'function' && define['amd']) {
  16445. define('videojs', [], function () {
  16446. return videojs;
  16447. });
  16448. // checking that module is an object too because of umdjs/umd#35
  16449. } else if (typeof exports === 'object' && typeof module === 'object') {
  16450. module['exports'] = videojs;
  16451. }
  16452. exports['default'] = videojs;
  16453. module.exports = exports['default'];
  16454. },{"../../src/js/utils/merge-options.js":138,"./component":67,"./event-target":99,"./extend.js":100,"./player":108,"./plugins.js":109,"./setup":113,"./tech/flash.js":116,"./tech/html5.js":117,"./tech/tech.js":119,"./tracks/text-track.js":128,"./utils/browser.js":129,"./utils/create-deprecation-proxy.js":131,"./utils/dom.js":132,"./utils/events.js":133,"./utils/fn.js":134,"./utils/format-time.js":135,"./utils/log.js":137,"./utils/stylesheet.js":139,"./utils/time-ranges.js":140,"./utils/url.js":142,"global/document":1,"lodash-compat/object/merge":40,"object.assign":45,"xhr":56}]},{},[143])(143)
  16455. });
  16456. //# sourceMappingURL=video.js.map
  16457. /* vtt.js - v0.12.1 (https://github.com/mozilla/vtt.js) built on 08-07-2015 */
  16458. (function(root) {
  16459. var vttjs = root.vttjs = {};
  16460. var cueShim = vttjs.VTTCue;
  16461. var regionShim = vttjs.VTTRegion;
  16462. var oldVTTCue = root.VTTCue;
  16463. var oldVTTRegion = root.VTTRegion;
  16464. vttjs.shim = function() {
  16465. vttjs.VTTCue = cueShim;
  16466. vttjs.VTTRegion = regionShim;
  16467. };
  16468. vttjs.restore = function() {
  16469. vttjs.VTTCue = oldVTTCue;
  16470. vttjs.VTTRegion = oldVTTRegion;
  16471. };
  16472. }(this));
  16473. /**
  16474. * Copyright 2013 vtt.js Contributors
  16475. *
  16476. * Licensed under the Apache License, Version 2.0 (the "License");
  16477. * you may not use this file except in compliance with the License.
  16478. * You may obtain a copy of the License at
  16479. *
  16480. * http://www.apache.org/licenses/LICENSE-2.0
  16481. *
  16482. * Unless required by applicable law or agreed to in writing, software
  16483. * distributed under the License is distributed on an "AS IS" BASIS,
  16484. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16485. * See the License for the specific language governing permissions and
  16486. * limitations under the License.
  16487. */
  16488. (function(root, vttjs) {
  16489. var autoKeyword = "auto";
  16490. var directionSetting = {
  16491. "": true,
  16492. "lr": true,
  16493. "rl": true
  16494. };
  16495. var alignSetting = {
  16496. "start": true,
  16497. "middle": true,
  16498. "end": true,
  16499. "left": true,
  16500. "right": true
  16501. };
  16502. function findDirectionSetting(value) {
  16503. if (typeof value !== "string") {
  16504. return false;
  16505. }
  16506. var dir = directionSetting[value.toLowerCase()];
  16507. return dir ? value.toLowerCase() : false;
  16508. }
  16509. function findAlignSetting(value) {
  16510. if (typeof value !== "string") {
  16511. return false;
  16512. }
  16513. var align = alignSetting[value.toLowerCase()];
  16514. return align ? value.toLowerCase() : false;
  16515. }
  16516. function extend(obj) {
  16517. var i = 1;
  16518. for (; i < arguments.length; i++) {
  16519. var cobj = arguments[i];
  16520. for (var p in cobj) {
  16521. obj[p] = cobj[p];
  16522. }
  16523. }
  16524. return obj;
  16525. }
  16526. function VTTCue(startTime, endTime, text) {
  16527. var cue = this;
  16528. var isIE8 = (/MSIE\s8\.0/).test(navigator.userAgent);
  16529. var baseObj = {};
  16530. if (isIE8) {
  16531. cue = document.createElement('custom');
  16532. } else {
  16533. baseObj.enumerable = true;
  16534. }
  16535. /**
  16536. * Shim implementation specific properties. These properties are not in
  16537. * the spec.
  16538. */
  16539. // Lets us know when the VTTCue's data has changed in such a way that we need
  16540. // to recompute its display state. This lets us compute its display state
  16541. // lazily.
  16542. cue.hasBeenReset = false;
  16543. /**
  16544. * VTTCue and TextTrackCue properties
  16545. * http://dev.w3.org/html5/webvtt/#vttcue-interface
  16546. */
  16547. var _id = "";
  16548. var _pauseOnExit = false;
  16549. var _startTime = startTime;
  16550. var _endTime = endTime;
  16551. var _text = text;
  16552. var _region = null;
  16553. var _vertical = "";
  16554. var _snapToLines = true;
  16555. var _line = "auto";
  16556. var _lineAlign = "start";
  16557. var _position = 50;
  16558. var _positionAlign = "middle";
  16559. var _size = 50;
  16560. var _align = "middle";
  16561. Object.defineProperty(cue,
  16562. "id", extend({}, baseObj, {
  16563. get: function() {
  16564. return _id;
  16565. },
  16566. set: function(value) {
  16567. _id = "" + value;
  16568. }
  16569. }));
  16570. Object.defineProperty(cue,
  16571. "pauseOnExit", extend({}, baseObj, {
  16572. get: function() {
  16573. return _pauseOnExit;
  16574. },
  16575. set: function(value) {
  16576. _pauseOnExit = !!value;
  16577. }
  16578. }));
  16579. Object.defineProperty(cue,
  16580. "startTime", extend({}, baseObj, {
  16581. get: function() {
  16582. return _startTime;
  16583. },
  16584. set: function(value) {
  16585. if (typeof value !== "number") {
  16586. throw new TypeError("Start time must be set to a number.");
  16587. }
  16588. _startTime = value;
  16589. this.hasBeenReset = true;
  16590. }
  16591. }));
  16592. Object.defineProperty(cue,
  16593. "endTime", extend({}, baseObj, {
  16594. get: function() {
  16595. return _endTime;
  16596. },
  16597. set: function(value) {
  16598. if (typeof value !== "number") {
  16599. throw new TypeError("End time must be set to a number.");
  16600. }
  16601. _endTime = value;
  16602. this.hasBeenReset = true;
  16603. }
  16604. }));
  16605. Object.defineProperty(cue,
  16606. "text", extend({}, baseObj, {
  16607. get: function() {
  16608. return _text;
  16609. },
  16610. set: function(value) {
  16611. _text = "" + value;
  16612. this.hasBeenReset = true;
  16613. }
  16614. }));
  16615. Object.defineProperty(cue,
  16616. "region", extend({}, baseObj, {
  16617. get: function() {
  16618. return _region;
  16619. },
  16620. set: function(value) {
  16621. _region = value;
  16622. this.hasBeenReset = true;
  16623. }
  16624. }));
  16625. Object.defineProperty(cue,
  16626. "vertical", extend({}, baseObj, {
  16627. get: function() {
  16628. return _vertical;
  16629. },
  16630. set: function(value) {
  16631. var setting = findDirectionSetting(value);
  16632. // Have to check for false because the setting an be an empty string.
  16633. if (setting === false) {
  16634. throw new SyntaxError("An invalid or illegal string was specified.");
  16635. }
  16636. _vertical = setting;
  16637. this.hasBeenReset = true;
  16638. }
  16639. }));
  16640. Object.defineProperty(cue,
  16641. "snapToLines", extend({}, baseObj, {
  16642. get: function() {
  16643. return _snapToLines;
  16644. },
  16645. set: function(value) {
  16646. _snapToLines = !!value;
  16647. this.hasBeenReset = true;
  16648. }
  16649. }));
  16650. Object.defineProperty(cue,
  16651. "line", extend({}, baseObj, {
  16652. get: function() {
  16653. return _line;
  16654. },
  16655. set: function(value) {
  16656. if (typeof value !== "number" && value !== autoKeyword) {
  16657. throw new SyntaxError("An invalid number or illegal string was specified.");
  16658. }
  16659. _line = value;
  16660. this.hasBeenReset = true;
  16661. }
  16662. }));
  16663. Object.defineProperty(cue,
  16664. "lineAlign", extend({}, baseObj, {
  16665. get: function() {
  16666. return _lineAlign;
  16667. },
  16668. set: function(value) {
  16669. var setting = findAlignSetting(value);
  16670. if (!setting) {
  16671. throw new SyntaxError("An invalid or illegal string was specified.");
  16672. }
  16673. _lineAlign = setting;
  16674. this.hasBeenReset = true;
  16675. }
  16676. }));
  16677. Object.defineProperty(cue,
  16678. "position", extend({}, baseObj, {
  16679. get: function() {
  16680. return _position;
  16681. },
  16682. set: function(value) {
  16683. if (value < 0 || value > 100) {
  16684. throw new Error("Position must be between 0 and 100.");
  16685. }
  16686. _position = value;
  16687. this.hasBeenReset = true;
  16688. }
  16689. }));
  16690. Object.defineProperty(cue,
  16691. "positionAlign", extend({}, baseObj, {
  16692. get: function() {
  16693. return _positionAlign;
  16694. },
  16695. set: function(value) {
  16696. var setting = findAlignSetting(value);
  16697. if (!setting) {
  16698. throw new SyntaxError("An invalid or illegal string was specified.");
  16699. }
  16700. _positionAlign = setting;
  16701. this.hasBeenReset = true;
  16702. }
  16703. }));
  16704. Object.defineProperty(cue,
  16705. "size", extend({}, baseObj, {
  16706. get: function() {
  16707. return _size;
  16708. },
  16709. set: function(value) {
  16710. if (value < 0 || value > 100) {
  16711. throw new Error("Size must be between 0 and 100.");
  16712. }
  16713. _size = value;
  16714. this.hasBeenReset = true;
  16715. }
  16716. }));
  16717. Object.defineProperty(cue,
  16718. "align", extend({}, baseObj, {
  16719. get: function() {
  16720. return _align;
  16721. },
  16722. set: function(value) {
  16723. var setting = findAlignSetting(value);
  16724. if (!setting) {
  16725. throw new SyntaxError("An invalid or illegal string was specified.");
  16726. }
  16727. _align = setting;
  16728. this.hasBeenReset = true;
  16729. }
  16730. }));
  16731. /**
  16732. * Other <track> spec defined properties
  16733. */
  16734. // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#text-track-cue-display-state
  16735. cue.displayState = undefined;
  16736. if (isIE8) {
  16737. return cue;
  16738. }
  16739. }
  16740. /**
  16741. * VTTCue methods
  16742. */
  16743. VTTCue.prototype.getCueAsHTML = function() {
  16744. // Assume WebVTT.convertCueToDOMTree is on the global.
  16745. return WebVTT.convertCueToDOMTree(window, this.text);
  16746. };
  16747. root.VTTCue = root.VTTCue || VTTCue;
  16748. vttjs.VTTCue = VTTCue;
  16749. }(this, (this.vttjs || {})));
  16750. /**
  16751. * Copyright 2013 vtt.js Contributors
  16752. *
  16753. * Licensed under the Apache License, Version 2.0 (the "License");
  16754. * you may not use this file except in compliance with the License.
  16755. * You may obtain a copy of the License at
  16756. *
  16757. * http://www.apache.org/licenses/LICENSE-2.0
  16758. *
  16759. * Unless required by applicable law or agreed to in writing, software
  16760. * distributed under the License is distributed on an "AS IS" BASIS,
  16761. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16762. * See the License for the specific language governing permissions and
  16763. * limitations under the License.
  16764. */
  16765. (function(root, vttjs) {
  16766. var scrollSetting = {
  16767. "": true,
  16768. "up": true
  16769. };
  16770. function findScrollSetting(value) {
  16771. if (typeof value !== "string") {
  16772. return false;
  16773. }
  16774. var scroll = scrollSetting[value.toLowerCase()];
  16775. return scroll ? value.toLowerCase() : false;
  16776. }
  16777. function isValidPercentValue(value) {
  16778. return typeof value === "number" && (value >= 0 && value <= 100);
  16779. }
  16780. // VTTRegion shim http://dev.w3.org/html5/webvtt/#vttregion-interface
  16781. function VTTRegion() {
  16782. var _width = 100;
  16783. var _lines = 3;
  16784. var _regionAnchorX = 0;
  16785. var _regionAnchorY = 100;
  16786. var _viewportAnchorX = 0;
  16787. var _viewportAnchorY = 100;
  16788. var _scroll = "";
  16789. Object.defineProperties(this, {
  16790. "width": {
  16791. enumerable: true,
  16792. get: function() {
  16793. return _width;
  16794. },
  16795. set: function(value) {
  16796. if (!isValidPercentValue(value)) {
  16797. throw new Error("Width must be between 0 and 100.");
  16798. }
  16799. _width = value;
  16800. }
  16801. },
  16802. "lines": {
  16803. enumerable: true,
  16804. get: function() {
  16805. return _lines;
  16806. },
  16807. set: function(value) {
  16808. if (typeof value !== "number") {
  16809. throw new TypeError("Lines must be set to a number.");
  16810. }
  16811. _lines = value;
  16812. }
  16813. },
  16814. "regionAnchorY": {
  16815. enumerable: true,
  16816. get: function() {
  16817. return _regionAnchorY;
  16818. },
  16819. set: function(value) {
  16820. if (!isValidPercentValue(value)) {
  16821. throw new Error("RegionAnchorX must be between 0 and 100.");
  16822. }
  16823. _regionAnchorY = value;
  16824. }
  16825. },
  16826. "regionAnchorX": {
  16827. enumerable: true,
  16828. get: function() {
  16829. return _regionAnchorX;
  16830. },
  16831. set: function(value) {
  16832. if(!isValidPercentValue(value)) {
  16833. throw new Error("RegionAnchorY must be between 0 and 100.");
  16834. }
  16835. _regionAnchorX = value;
  16836. }
  16837. },
  16838. "viewportAnchorY": {
  16839. enumerable: true,
  16840. get: function() {
  16841. return _viewportAnchorY;
  16842. },
  16843. set: function(value) {
  16844. if (!isValidPercentValue(value)) {
  16845. throw new Error("ViewportAnchorY must be between 0 and 100.");
  16846. }
  16847. _viewportAnchorY = value;
  16848. }
  16849. },
  16850. "viewportAnchorX": {
  16851. enumerable: true,
  16852. get: function() {
  16853. return _viewportAnchorX;
  16854. },
  16855. set: function(value) {
  16856. if (!isValidPercentValue(value)) {
  16857. throw new Error("ViewportAnchorX must be between 0 and 100.");
  16858. }
  16859. _viewportAnchorX = value;
  16860. }
  16861. },
  16862. "scroll": {
  16863. enumerable: true,
  16864. get: function() {
  16865. return _scroll;
  16866. },
  16867. set: function(value) {
  16868. var setting = findScrollSetting(value);
  16869. // Have to check for false as an empty string is a legal value.
  16870. if (setting === false) {
  16871. throw new SyntaxError("An invalid or illegal string was specified.");
  16872. }
  16873. _scroll = setting;
  16874. }
  16875. }
  16876. });
  16877. }
  16878. root.VTTRegion = root.VTTRegion || VTTRegion;
  16879. vttjs.VTTRegion = VTTRegion;
  16880. }(this, (this.vttjs || {})));
  16881. /**
  16882. * Copyright 2013 vtt.js Contributors
  16883. *
  16884. * Licensed under the Apache License, Version 2.0 (the "License");
  16885. * you may not use this file except in compliance with the License.
  16886. * You may obtain a copy of the License at
  16887. *
  16888. * http://www.apache.org/licenses/LICENSE-2.0
  16889. *
  16890. * Unless required by applicable law or agreed to in writing, software
  16891. * distributed under the License is distributed on an "AS IS" BASIS,
  16892. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16893. * See the License for the specific language governing permissions and
  16894. * limitations under the License.
  16895. */
  16896. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  16897. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  16898. (function(global) {
  16899. var _objCreate = Object.create || (function() {
  16900. function F() {}
  16901. return function(o) {
  16902. if (arguments.length !== 1) {
  16903. throw new Error('Object.create shim only accepts one parameter.');
  16904. }
  16905. F.prototype = o;
  16906. return new F();
  16907. };
  16908. })();
  16909. // Creates a new ParserError object from an errorData object. The errorData
  16910. // object should have default code and message properties. The default message
  16911. // property can be overriden by passing in a message parameter.
  16912. // See ParsingError.Errors below for acceptable errors.
  16913. function ParsingError(errorData, message) {
  16914. this.name = "ParsingError";
  16915. this.code = errorData.code;
  16916. this.message = message || errorData.message;
  16917. }
  16918. ParsingError.prototype = _objCreate(Error.prototype);
  16919. ParsingError.prototype.constructor = ParsingError;
  16920. // ParsingError metadata for acceptable ParsingErrors.
  16921. ParsingError.Errors = {
  16922. BadSignature: {
  16923. code: 0,
  16924. message: "Malformed WebVTT signature."
  16925. },
  16926. BadTimeStamp: {
  16927. code: 1,
  16928. message: "Malformed time stamp."
  16929. }
  16930. };
  16931. // Try to parse input as a time stamp.
  16932. function parseTimeStamp(input) {
  16933. function computeSeconds(h, m, s, f) {
  16934. return (h | 0) * 3600 + (m | 0) * 60 + (s | 0) + (f | 0) / 1000;
  16935. }
  16936. var m = input.match(/^(\d+):(\d{2})(:\d{2})?\.(\d{3})/);
  16937. if (!m) {
  16938. return null;
  16939. }
  16940. if (m[3]) {
  16941. // Timestamp takes the form of [hours]:[minutes]:[seconds].[milliseconds]
  16942. return computeSeconds(m[1], m[2], m[3].replace(":", ""), m[4]);
  16943. } else if (m[1] > 59) {
  16944. // Timestamp takes the form of [hours]:[minutes].[milliseconds]
  16945. // First position is hours as it's over 59.
  16946. return computeSeconds(m[1], m[2], 0, m[4]);
  16947. } else {
  16948. // Timestamp takes the form of [minutes]:[seconds].[milliseconds]
  16949. return computeSeconds(0, m[1], m[2], m[4]);
  16950. }
  16951. }
  16952. // A settings object holds key/value pairs and will ignore anything but the first
  16953. // assignment to a specific key.
  16954. function Settings() {
  16955. this.values = _objCreate(null);
  16956. }
  16957. Settings.prototype = {
  16958. // Only accept the first assignment to any key.
  16959. set: function(k, v) {
  16960. if (!this.get(k) && v !== "") {
  16961. this.values[k] = v;
  16962. }
  16963. },
  16964. // Return the value for a key, or a default value.
  16965. // If 'defaultKey' is passed then 'dflt' is assumed to be an object with
  16966. // a number of possible default values as properties where 'defaultKey' is
  16967. // the key of the property that will be chosen; otherwise it's assumed to be
  16968. // a single value.
  16969. get: function(k, dflt, defaultKey) {
  16970. if (defaultKey) {
  16971. return this.has(k) ? this.values[k] : dflt[defaultKey];
  16972. }
  16973. return this.has(k) ? this.values[k] : dflt;
  16974. },
  16975. // Check whether we have a value for a key.
  16976. has: function(k) {
  16977. return k in this.values;
  16978. },
  16979. // Accept a setting if its one of the given alternatives.
  16980. alt: function(k, v, a) {
  16981. for (var n = 0; n < a.length; ++n) {
  16982. if (v === a[n]) {
  16983. this.set(k, v);
  16984. break;
  16985. }
  16986. }
  16987. },
  16988. // Accept a setting if its a valid (signed) integer.
  16989. integer: function(k, v) {
  16990. if (/^-?\d+$/.test(v)) { // integer
  16991. this.set(k, parseInt(v, 10));
  16992. }
  16993. },
  16994. // Accept a setting if its a valid percentage.
  16995. percent: function(k, v) {
  16996. var m;
  16997. if ((m = v.match(/^([\d]{1,3})(\.[\d]*)?%$/))) {
  16998. v = parseFloat(v);
  16999. if (v >= 0 && v <= 100) {
  17000. this.set(k, v);
  17001. return true;
  17002. }
  17003. }
  17004. return false;
  17005. }
  17006. };
  17007. // Helper function to parse input into groups separated by 'groupDelim', and
  17008. // interprete each group as a key/value pair separated by 'keyValueDelim'.
  17009. function parseOptions(input, callback, keyValueDelim, groupDelim) {
  17010. var groups = groupDelim ? input.split(groupDelim) : [input];
  17011. for (var i in groups) {
  17012. if (typeof groups[i] !== "string") {
  17013. continue;
  17014. }
  17015. var kv = groups[i].split(keyValueDelim);
  17016. if (kv.length !== 2) {
  17017. continue;
  17018. }
  17019. var k = kv[0];
  17020. var v = kv[1];
  17021. callback(k, v);
  17022. }
  17023. }
  17024. function parseCue(input, cue, regionList) {
  17025. // Remember the original input if we need to throw an error.
  17026. var oInput = input;
  17027. // 4.1 WebVTT timestamp
  17028. function consumeTimeStamp() {
  17029. var ts = parseTimeStamp(input);
  17030. if (ts === null) {
  17031. throw new ParsingError(ParsingError.Errors.BadTimeStamp,
  17032. "Malformed timestamp: " + oInput);
  17033. }
  17034. // Remove time stamp from input.
  17035. input = input.replace(/^[^\sa-zA-Z-]+/, "");
  17036. return ts;
  17037. }
  17038. // 4.4.2 WebVTT cue settings
  17039. function consumeCueSettings(input, cue) {
  17040. var settings = new Settings();
  17041. parseOptions(input, function (k, v) {
  17042. switch (k) {
  17043. case "region":
  17044. // Find the last region we parsed with the same region id.
  17045. for (var i = regionList.length - 1; i >= 0; i--) {
  17046. if (regionList[i].id === v) {
  17047. settings.set(k, regionList[i].region);
  17048. break;
  17049. }
  17050. }
  17051. break;
  17052. case "vertical":
  17053. settings.alt(k, v, ["rl", "lr"]);
  17054. break;
  17055. case "line":
  17056. var vals = v.split(","),
  17057. vals0 = vals[0];
  17058. settings.integer(k, vals0);
  17059. settings.percent(k, vals0) ? settings.set("snapToLines", false) : null;
  17060. settings.alt(k, vals0, ["auto"]);
  17061. if (vals.length === 2) {
  17062. settings.alt("lineAlign", vals[1], ["start", "middle", "end"]);
  17063. }
  17064. break;
  17065. case "position":
  17066. vals = v.split(",");
  17067. settings.percent(k, vals[0]);
  17068. if (vals.length === 2) {
  17069. settings.alt("positionAlign", vals[1], ["start", "middle", "end"]);
  17070. }
  17071. break;
  17072. case "size":
  17073. settings.percent(k, v);
  17074. break;
  17075. case "align":
  17076. settings.alt(k, v, ["start", "middle", "end", "left", "right"]);
  17077. break;
  17078. }
  17079. }, /:/, /\s/);
  17080. // Apply default values for any missing fields.
  17081. cue.region = settings.get("region", null);
  17082. cue.vertical = settings.get("vertical", "");
  17083. cue.line = settings.get("line", "auto");
  17084. cue.lineAlign = settings.get("lineAlign", "start");
  17085. cue.snapToLines = settings.get("snapToLines", true);
  17086. cue.size = settings.get("size", 100);
  17087. cue.align = settings.get("align", "middle");
  17088. cue.position = settings.get("position", {
  17089. start: 0,
  17090. left: 0,
  17091. middle: 50,
  17092. end: 100,
  17093. right: 100
  17094. }, cue.align);
  17095. cue.positionAlign = settings.get("positionAlign", {
  17096. start: "start",
  17097. left: "start",
  17098. middle: "middle",
  17099. end: "end",
  17100. right: "end"
  17101. }, cue.align);
  17102. }
  17103. function skipWhitespace() {
  17104. input = input.replace(/^\s+/, "");
  17105. }
  17106. // 4.1 WebVTT cue timings.
  17107. skipWhitespace();
  17108. cue.startTime = consumeTimeStamp(); // (1) collect cue start time
  17109. skipWhitespace();
  17110. if (input.substr(0, 3) !== "-->") { // (3) next characters must match "-->"
  17111. throw new ParsingError(ParsingError.Errors.BadTimeStamp,
  17112. "Malformed time stamp (time stamps must be separated by '-->'): " +
  17113. oInput);
  17114. }
  17115. input = input.substr(3);
  17116. skipWhitespace();
  17117. cue.endTime = consumeTimeStamp(); // (5) collect cue end time
  17118. // 4.1 WebVTT cue settings list.
  17119. skipWhitespace();
  17120. consumeCueSettings(input, cue);
  17121. }
  17122. var ESCAPE = {
  17123. "&amp;": "&",
  17124. "&lt;": "<",
  17125. "&gt;": ">",
  17126. "&lrm;": "\u200e",
  17127. "&rlm;": "\u200f",
  17128. "&nbsp;": "\u00a0"
  17129. };
  17130. var TAG_NAME = {
  17131. c: "span",
  17132. i: "i",
  17133. b: "b",
  17134. u: "u",
  17135. ruby: "ruby",
  17136. rt: "rt",
  17137. v: "span",
  17138. lang: "span"
  17139. };
  17140. var TAG_ANNOTATION = {
  17141. v: "title",
  17142. lang: "lang"
  17143. };
  17144. var NEEDS_PARENT = {
  17145. rt: "ruby"
  17146. };
  17147. // Parse content into a document fragment.
  17148. function parseContent(window, input) {
  17149. function nextToken() {
  17150. // Check for end-of-string.
  17151. if (!input) {
  17152. return null;
  17153. }
  17154. // Consume 'n' characters from the input.
  17155. function consume(result) {
  17156. input = input.substr(result.length);
  17157. return result;
  17158. }
  17159. var m = input.match(/^([^<]*)(<[^>]+>?)?/);
  17160. // If there is some text before the next tag, return it, otherwise return
  17161. // the tag.
  17162. return consume(m[1] ? m[1] : m[2]);
  17163. }
  17164. // Unescape a string 's'.
  17165. function unescape1(e) {
  17166. return ESCAPE[e];
  17167. }
  17168. function unescape(s) {
  17169. while ((m = s.match(/&(amp|lt|gt|lrm|rlm|nbsp);/))) {
  17170. s = s.replace(m[0], unescape1);
  17171. }
  17172. return s;
  17173. }
  17174. function shouldAdd(current, element) {
  17175. return !NEEDS_PARENT[element.localName] ||
  17176. NEEDS_PARENT[element.localName] === current.localName;
  17177. }
  17178. // Create an element for this tag.
  17179. function createElement(type, annotation) {
  17180. var tagName = TAG_NAME[type];
  17181. if (!tagName) {
  17182. return null;
  17183. }
  17184. var element = window.document.createElement(tagName);
  17185. element.localName = tagName;
  17186. var name = TAG_ANNOTATION[type];
  17187. if (name && annotation) {
  17188. element[name] = annotation.trim();
  17189. }
  17190. return element;
  17191. }
  17192. var rootDiv = window.document.createElement("div"),
  17193. current = rootDiv,
  17194. t,
  17195. tagStack = [];
  17196. while ((t = nextToken()) !== null) {
  17197. if (t[0] === '<') {
  17198. if (t[1] === "/") {
  17199. // If the closing tag matches, move back up to the parent node.
  17200. if (tagStack.length &&
  17201. tagStack[tagStack.length - 1] === t.substr(2).replace(">", "")) {
  17202. tagStack.pop();
  17203. current = current.parentNode;
  17204. }
  17205. // Otherwise just ignore the end tag.
  17206. continue;
  17207. }
  17208. var ts = parseTimeStamp(t.substr(1, t.length - 2));
  17209. var node;
  17210. if (ts) {
  17211. // Timestamps are lead nodes as well.
  17212. node = window.document.createProcessingInstruction("timestamp", ts);
  17213. current.appendChild(node);
  17214. continue;
  17215. }
  17216. var m = t.match(/^<([^.\s/0-9>]+)(\.[^\s\\>]+)?([^>\\]+)?(\\?)>?$/);
  17217. // If we can't parse the tag, skip to the next tag.
  17218. if (!m) {
  17219. continue;
  17220. }
  17221. // Try to construct an element, and ignore the tag if we couldn't.
  17222. node = createElement(m[1], m[3]);
  17223. if (!node) {
  17224. continue;
  17225. }
  17226. // Determine if the tag should be added based on the context of where it
  17227. // is placed in the cuetext.
  17228. if (!shouldAdd(current, node)) {
  17229. continue;
  17230. }
  17231. // Set the class list (as a list of classes, separated by space).
  17232. if (m[2]) {
  17233. node.className = m[2].substr(1).replace('.', ' ');
  17234. }
  17235. // Append the node to the current node, and enter the scope of the new
  17236. // node.
  17237. tagStack.push(m[1]);
  17238. current.appendChild(node);
  17239. current = node;
  17240. continue;
  17241. }
  17242. // Text nodes are leaf nodes.
  17243. current.appendChild(window.document.createTextNode(unescape(t)));
  17244. }
  17245. return rootDiv;
  17246. }
  17247. // This is a list of all the Unicode characters that have a strong
  17248. // right-to-left category. What this means is that these characters are
  17249. // written right-to-left for sure. It was generated by pulling all the strong
  17250. // right-to-left characters out of the Unicode data table. That table can
  17251. // found at: http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
  17252. var strongRTLChars = [0x05BE, 0x05C0, 0x05C3, 0x05C6, 0x05D0, 0x05D1,
  17253. 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7, 0x05D8, 0x05D9, 0x05DA,
  17254. 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF, 0x05E0, 0x05E1, 0x05E2, 0x05E3,
  17255. 0x05E4, 0x05E5, 0x05E6, 0x05E7, 0x05E8, 0x05E9, 0x05EA, 0x05F0, 0x05F1,
  17256. 0x05F2, 0x05F3, 0x05F4, 0x0608, 0x060B, 0x060D, 0x061B, 0x061E, 0x061F,
  17257. 0x0620, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627, 0x0628,
  17258. 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F, 0x0630, 0x0631,
  17259. 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637, 0x0638, 0x0639, 0x063A,
  17260. 0x063B, 0x063C, 0x063D, 0x063E, 0x063F, 0x0640, 0x0641, 0x0642, 0x0643,
  17261. 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064A, 0x066D, 0x066E,
  17262. 0x066F, 0x0671, 0x0672, 0x0673, 0x0674, 0x0675, 0x0676, 0x0677, 0x0678,
  17263. 0x0679, 0x067A, 0x067B, 0x067C, 0x067D, 0x067E, 0x067F, 0x0680, 0x0681,
  17264. 0x0682, 0x0683, 0x0684, 0x0685, 0x0686, 0x0687, 0x0688, 0x0689, 0x068A,
  17265. 0x068B, 0x068C, 0x068D, 0x068E, 0x068F, 0x0690, 0x0691, 0x0692, 0x0693,
  17266. 0x0694, 0x0695, 0x0696, 0x0697, 0x0698, 0x0699, 0x069A, 0x069B, 0x069C,
  17267. 0x069D, 0x069E, 0x069F, 0x06A0, 0x06A1, 0x06A2, 0x06A3, 0x06A4, 0x06A5,
  17268. 0x06A6, 0x06A7, 0x06A8, 0x06A9, 0x06AA, 0x06AB, 0x06AC, 0x06AD, 0x06AE,
  17269. 0x06AF, 0x06B0, 0x06B1, 0x06B2, 0x06B3, 0x06B4, 0x06B5, 0x06B6, 0x06B7,
  17270. 0x06B8, 0x06B9, 0x06BA, 0x06BB, 0x06BC, 0x06BD, 0x06BE, 0x06BF, 0x06C0,
  17271. 0x06C1, 0x06C2, 0x06C3, 0x06C4, 0x06C5, 0x06C6, 0x06C7, 0x06C8, 0x06C9,
  17272. 0x06CA, 0x06CB, 0x06CC, 0x06CD, 0x06CE, 0x06CF, 0x06D0, 0x06D1, 0x06D2,
  17273. 0x06D3, 0x06D4, 0x06D5, 0x06E5, 0x06E6, 0x06EE, 0x06EF, 0x06FA, 0x06FB,
  17274. 0x06FC, 0x06FD, 0x06FE, 0x06FF, 0x0700, 0x0701, 0x0702, 0x0703, 0x0704,
  17275. 0x0705, 0x0706, 0x0707, 0x0708, 0x0709, 0x070A, 0x070B, 0x070C, 0x070D,
  17276. 0x070F, 0x0710, 0x0712, 0x0713, 0x0714, 0x0715, 0x0716, 0x0717, 0x0718,
  17277. 0x0719, 0x071A, 0x071B, 0x071C, 0x071D, 0x071E, 0x071F, 0x0720, 0x0721,
  17278. 0x0722, 0x0723, 0x0724, 0x0725, 0x0726, 0x0727, 0x0728, 0x0729, 0x072A,
  17279. 0x072B, 0x072C, 0x072D, 0x072E, 0x072F, 0x074D, 0x074E, 0x074F, 0x0750,
  17280. 0x0751, 0x0752, 0x0753, 0x0754, 0x0755, 0x0756, 0x0757, 0x0758, 0x0759,
  17281. 0x075A, 0x075B, 0x075C, 0x075D, 0x075E, 0x075F, 0x0760, 0x0761, 0x0762,
  17282. 0x0763, 0x0764, 0x0765, 0x0766, 0x0767, 0x0768, 0x0769, 0x076A, 0x076B,
  17283. 0x076C, 0x076D, 0x076E, 0x076F, 0x0770, 0x0771, 0x0772, 0x0773, 0x0774,
  17284. 0x0775, 0x0776, 0x0777, 0x0778, 0x0779, 0x077A, 0x077B, 0x077C, 0x077D,
  17285. 0x077E, 0x077F, 0x0780, 0x0781, 0x0782, 0x0783, 0x0784, 0x0785, 0x0786,
  17286. 0x0787, 0x0788, 0x0789, 0x078A, 0x078B, 0x078C, 0x078D, 0x078E, 0x078F,
  17287. 0x0790, 0x0791, 0x0792, 0x0793, 0x0794, 0x0795, 0x0796, 0x0797, 0x0798,
  17288. 0x0799, 0x079A, 0x079B, 0x079C, 0x079D, 0x079E, 0x079F, 0x07A0, 0x07A1,
  17289. 0x07A2, 0x07A3, 0x07A4, 0x07A5, 0x07B1, 0x07C0, 0x07C1, 0x07C2, 0x07C3,
  17290. 0x07C4, 0x07C5, 0x07C6, 0x07C7, 0x07C8, 0x07C9, 0x07CA, 0x07CB, 0x07CC,
  17291. 0x07CD, 0x07CE, 0x07CF, 0x07D0, 0x07D1, 0x07D2, 0x07D3, 0x07D4, 0x07D5,
  17292. 0x07D6, 0x07D7, 0x07D8, 0x07D9, 0x07DA, 0x07DB, 0x07DC, 0x07DD, 0x07DE,
  17293. 0x07DF, 0x07E0, 0x07E1, 0x07E2, 0x07E3, 0x07E4, 0x07E5, 0x07E6, 0x07E7,
  17294. 0x07E8, 0x07E9, 0x07EA, 0x07F4, 0x07F5, 0x07FA, 0x0800, 0x0801, 0x0802,
  17295. 0x0803, 0x0804, 0x0805, 0x0806, 0x0807, 0x0808, 0x0809, 0x080A, 0x080B,
  17296. 0x080C, 0x080D, 0x080E, 0x080F, 0x0810, 0x0811, 0x0812, 0x0813, 0x0814,
  17297. 0x0815, 0x081A, 0x0824, 0x0828, 0x0830, 0x0831, 0x0832, 0x0833, 0x0834,
  17298. 0x0835, 0x0836, 0x0837, 0x0838, 0x0839, 0x083A, 0x083B, 0x083C, 0x083D,
  17299. 0x083E, 0x0840, 0x0841, 0x0842, 0x0843, 0x0844, 0x0845, 0x0846, 0x0847,
  17300. 0x0848, 0x0849, 0x084A, 0x084B, 0x084C, 0x084D, 0x084E, 0x084F, 0x0850,
  17301. 0x0851, 0x0852, 0x0853, 0x0854, 0x0855, 0x0856, 0x0857, 0x0858, 0x085E,
  17302. 0x08A0, 0x08A2, 0x08A3, 0x08A4, 0x08A5, 0x08A6, 0x08A7, 0x08A8, 0x08A9,
  17303. 0x08AA, 0x08AB, 0x08AC, 0x200F, 0xFB1D, 0xFB1F, 0xFB20, 0xFB21, 0xFB22,
  17304. 0xFB23, 0xFB24, 0xFB25, 0xFB26, 0xFB27, 0xFB28, 0xFB2A, 0xFB2B, 0xFB2C,
  17305. 0xFB2D, 0xFB2E, 0xFB2F, 0xFB30, 0xFB31, 0xFB32, 0xFB33, 0xFB34, 0xFB35,
  17306. 0xFB36, 0xFB38, 0xFB39, 0xFB3A, 0xFB3B, 0xFB3C, 0xFB3E, 0xFB40, 0xFB41,
  17307. 0xFB43, 0xFB44, 0xFB46, 0xFB47, 0xFB48, 0xFB49, 0xFB4A, 0xFB4B, 0xFB4C,
  17308. 0xFB4D, 0xFB4E, 0xFB4F, 0xFB50, 0xFB51, 0xFB52, 0xFB53, 0xFB54, 0xFB55,
  17309. 0xFB56, 0xFB57, 0xFB58, 0xFB59, 0xFB5A, 0xFB5B, 0xFB5C, 0xFB5D, 0xFB5E,
  17310. 0xFB5F, 0xFB60, 0xFB61, 0xFB62, 0xFB63, 0xFB64, 0xFB65, 0xFB66, 0xFB67,
  17311. 0xFB68, 0xFB69, 0xFB6A, 0xFB6B, 0xFB6C, 0xFB6D, 0xFB6E, 0xFB6F, 0xFB70,
  17312. 0xFB71, 0xFB72, 0xFB73, 0xFB74, 0xFB75, 0xFB76, 0xFB77, 0xFB78, 0xFB79,
  17313. 0xFB7A, 0xFB7B, 0xFB7C, 0xFB7D, 0xFB7E, 0xFB7F, 0xFB80, 0xFB81, 0xFB82,
  17314. 0xFB83, 0xFB84, 0xFB85, 0xFB86, 0xFB87, 0xFB88, 0xFB89, 0xFB8A, 0xFB8B,
  17315. 0xFB8C, 0xFB8D, 0xFB8E, 0xFB8F, 0xFB90, 0xFB91, 0xFB92, 0xFB93, 0xFB94,
  17316. 0xFB95, 0xFB96, 0xFB97, 0xFB98, 0xFB99, 0xFB9A, 0xFB9B, 0xFB9C, 0xFB9D,
  17317. 0xFB9E, 0xFB9F, 0xFBA0, 0xFBA1, 0xFBA2, 0xFBA3, 0xFBA4, 0xFBA5, 0xFBA6,
  17318. 0xFBA7, 0xFBA8, 0xFBA9, 0xFBAA, 0xFBAB, 0xFBAC, 0xFBAD, 0xFBAE, 0xFBAF,
  17319. 0xFBB0, 0xFBB1, 0xFBB2, 0xFBB3, 0xFBB4, 0xFBB5, 0xFBB6, 0xFBB7, 0xFBB8,
  17320. 0xFBB9, 0xFBBA, 0xFBBB, 0xFBBC, 0xFBBD, 0xFBBE, 0xFBBF, 0xFBC0, 0xFBC1,
  17321. 0xFBD3, 0xFBD4, 0xFBD5, 0xFBD6, 0xFBD7, 0xFBD8, 0xFBD9, 0xFBDA, 0xFBDB,
  17322. 0xFBDC, 0xFBDD, 0xFBDE, 0xFBDF, 0xFBE0, 0xFBE1, 0xFBE2, 0xFBE3, 0xFBE4,
  17323. 0xFBE5, 0xFBE6, 0xFBE7, 0xFBE8, 0xFBE9, 0xFBEA, 0xFBEB, 0xFBEC, 0xFBED,
  17324. 0xFBEE, 0xFBEF, 0xFBF0, 0xFBF1, 0xFBF2, 0xFBF3, 0xFBF4, 0xFBF5, 0xFBF6,
  17325. 0xFBF7, 0xFBF8, 0xFBF9, 0xFBFA, 0xFBFB, 0xFBFC, 0xFBFD, 0xFBFE, 0xFBFF,
  17326. 0xFC00, 0xFC01, 0xFC02, 0xFC03, 0xFC04, 0xFC05, 0xFC06, 0xFC07, 0xFC08,
  17327. 0xFC09, 0xFC0A, 0xFC0B, 0xFC0C, 0xFC0D, 0xFC0E, 0xFC0F, 0xFC10, 0xFC11,
  17328. 0xFC12, 0xFC13, 0xFC14, 0xFC15, 0xFC16, 0xFC17, 0xFC18, 0xFC19, 0xFC1A,
  17329. 0xFC1B, 0xFC1C, 0xFC1D, 0xFC1E, 0xFC1F, 0xFC20, 0xFC21, 0xFC22, 0xFC23,
  17330. 0xFC24, 0xFC25, 0xFC26, 0xFC27, 0xFC28, 0xFC29, 0xFC2A, 0xFC2B, 0xFC2C,
  17331. 0xFC2D, 0xFC2E, 0xFC2F, 0xFC30, 0xFC31, 0xFC32, 0xFC33, 0xFC34, 0xFC35,
  17332. 0xFC36, 0xFC37, 0xFC38, 0xFC39, 0xFC3A, 0xFC3B, 0xFC3C, 0xFC3D, 0xFC3E,
  17333. 0xFC3F, 0xFC40, 0xFC41, 0xFC42, 0xFC43, 0xFC44, 0xFC45, 0xFC46, 0xFC47,
  17334. 0xFC48, 0xFC49, 0xFC4A, 0xFC4B, 0xFC4C, 0xFC4D, 0xFC4E, 0xFC4F, 0xFC50,
  17335. 0xFC51, 0xFC52, 0xFC53, 0xFC54, 0xFC55, 0xFC56, 0xFC57, 0xFC58, 0xFC59,
  17336. 0xFC5A, 0xFC5B, 0xFC5C, 0xFC5D, 0xFC5E, 0xFC5F, 0xFC60, 0xFC61, 0xFC62,
  17337. 0xFC63, 0xFC64, 0xFC65, 0xFC66, 0xFC67, 0xFC68, 0xFC69, 0xFC6A, 0xFC6B,
  17338. 0xFC6C, 0xFC6D, 0xFC6E, 0xFC6F, 0xFC70, 0xFC71, 0xFC72, 0xFC73, 0xFC74,
  17339. 0xFC75, 0xFC76, 0xFC77, 0xFC78, 0xFC79, 0xFC7A, 0xFC7B, 0xFC7C, 0xFC7D,
  17340. 0xFC7E, 0xFC7F, 0xFC80, 0xFC81, 0xFC82, 0xFC83, 0xFC84, 0xFC85, 0xFC86,
  17341. 0xFC87, 0xFC88, 0xFC89, 0xFC8A, 0xFC8B, 0xFC8C, 0xFC8D, 0xFC8E, 0xFC8F,
  17342. 0xFC90, 0xFC91, 0xFC92, 0xFC93, 0xFC94, 0xFC95, 0xFC96, 0xFC97, 0xFC98,
  17343. 0xFC99, 0xFC9A, 0xFC9B, 0xFC9C, 0xFC9D, 0xFC9E, 0xFC9F, 0xFCA0, 0xFCA1,
  17344. 0xFCA2, 0xFCA3, 0xFCA4, 0xFCA5, 0xFCA6, 0xFCA7, 0xFCA8, 0xFCA9, 0xFCAA,
  17345. 0xFCAB, 0xFCAC, 0xFCAD, 0xFCAE, 0xFCAF, 0xFCB0, 0xFCB1, 0xFCB2, 0xFCB3,
  17346. 0xFCB4, 0xFCB5, 0xFCB6, 0xFCB7, 0xFCB8, 0xFCB9, 0xFCBA, 0xFCBB, 0xFCBC,
  17347. 0xFCBD, 0xFCBE, 0xFCBF, 0xFCC0, 0xFCC1, 0xFCC2, 0xFCC3, 0xFCC4, 0xFCC5,
  17348. 0xFCC6, 0xFCC7, 0xFCC8, 0xFCC9, 0xFCCA, 0xFCCB, 0xFCCC, 0xFCCD, 0xFCCE,
  17349. 0xFCCF, 0xFCD0, 0xFCD1, 0xFCD2, 0xFCD3, 0xFCD4, 0xFCD5, 0xFCD6, 0xFCD7,
  17350. 0xFCD8, 0xFCD9, 0xFCDA, 0xFCDB, 0xFCDC, 0xFCDD, 0xFCDE, 0xFCDF, 0xFCE0,
  17351. 0xFCE1, 0xFCE2, 0xFCE3, 0xFCE4, 0xFCE5, 0xFCE6, 0xFCE7, 0xFCE8, 0xFCE9,
  17352. 0xFCEA, 0xFCEB, 0xFCEC, 0xFCED, 0xFCEE, 0xFCEF, 0xFCF0, 0xFCF1, 0xFCF2,
  17353. 0xFCF3, 0xFCF4, 0xFCF5, 0xFCF6, 0xFCF7, 0xFCF8, 0xFCF9, 0xFCFA, 0xFCFB,
  17354. 0xFCFC, 0xFCFD, 0xFCFE, 0xFCFF, 0xFD00, 0xFD01, 0xFD02, 0xFD03, 0xFD04,
  17355. 0xFD05, 0xFD06, 0xFD07, 0xFD08, 0xFD09, 0xFD0A, 0xFD0B, 0xFD0C, 0xFD0D,
  17356. 0xFD0E, 0xFD0F, 0xFD10, 0xFD11, 0xFD12, 0xFD13, 0xFD14, 0xFD15, 0xFD16,
  17357. 0xFD17, 0xFD18, 0xFD19, 0xFD1A, 0xFD1B, 0xFD1C, 0xFD1D, 0xFD1E, 0xFD1F,
  17358. 0xFD20, 0xFD21, 0xFD22, 0xFD23, 0xFD24, 0xFD25, 0xFD26, 0xFD27, 0xFD28,
  17359. 0xFD29, 0xFD2A, 0xFD2B, 0xFD2C, 0xFD2D, 0xFD2E, 0xFD2F, 0xFD30, 0xFD31,
  17360. 0xFD32, 0xFD33, 0xFD34, 0xFD35, 0xFD36, 0xFD37, 0xFD38, 0xFD39, 0xFD3A,
  17361. 0xFD3B, 0xFD3C, 0xFD3D, 0xFD50, 0xFD51, 0xFD52, 0xFD53, 0xFD54, 0xFD55,
  17362. 0xFD56, 0xFD57, 0xFD58, 0xFD59, 0xFD5A, 0xFD5B, 0xFD5C, 0xFD5D, 0xFD5E,
  17363. 0xFD5F, 0xFD60, 0xFD61, 0xFD62, 0xFD63, 0xFD64, 0xFD65, 0xFD66, 0xFD67,
  17364. 0xFD68, 0xFD69, 0xFD6A, 0xFD6B, 0xFD6C, 0xFD6D, 0xFD6E, 0xFD6F, 0xFD70,
  17365. 0xFD71, 0xFD72, 0xFD73, 0xFD74, 0xFD75, 0xFD76, 0xFD77, 0xFD78, 0xFD79,
  17366. 0xFD7A, 0xFD7B, 0xFD7C, 0xFD7D, 0xFD7E, 0xFD7F, 0xFD80, 0xFD81, 0xFD82,
  17367. 0xFD83, 0xFD84, 0xFD85, 0xFD86, 0xFD87, 0xFD88, 0xFD89, 0xFD8A, 0xFD8B,
  17368. 0xFD8C, 0xFD8D, 0xFD8E, 0xFD8F, 0xFD92, 0xFD93, 0xFD94, 0xFD95, 0xFD96,
  17369. 0xFD97, 0xFD98, 0xFD99, 0xFD9A, 0xFD9B, 0xFD9C, 0xFD9D, 0xFD9E, 0xFD9F,
  17370. 0xFDA0, 0xFDA1, 0xFDA2, 0xFDA3, 0xFDA4, 0xFDA5, 0xFDA6, 0xFDA7, 0xFDA8,
  17371. 0xFDA9, 0xFDAA, 0xFDAB, 0xFDAC, 0xFDAD, 0xFDAE, 0xFDAF, 0xFDB0, 0xFDB1,
  17372. 0xFDB2, 0xFDB3, 0xFDB4, 0xFDB5, 0xFDB6, 0xFDB7, 0xFDB8, 0xFDB9, 0xFDBA,
  17373. 0xFDBB, 0xFDBC, 0xFDBD, 0xFDBE, 0xFDBF, 0xFDC0, 0xFDC1, 0xFDC2, 0xFDC3,
  17374. 0xFDC4, 0xFDC5, 0xFDC6, 0xFDC7, 0xFDF0, 0xFDF1, 0xFDF2, 0xFDF3, 0xFDF4,
  17375. 0xFDF5, 0xFDF6, 0xFDF7, 0xFDF8, 0xFDF9, 0xFDFA, 0xFDFB, 0xFDFC, 0xFE70,
  17376. 0xFE71, 0xFE72, 0xFE73, 0xFE74, 0xFE76, 0xFE77, 0xFE78, 0xFE79, 0xFE7A,
  17377. 0xFE7B, 0xFE7C, 0xFE7D, 0xFE7E, 0xFE7F, 0xFE80, 0xFE81, 0xFE82, 0xFE83,
  17378. 0xFE84, 0xFE85, 0xFE86, 0xFE87, 0xFE88, 0xFE89, 0xFE8A, 0xFE8B, 0xFE8C,
  17379. 0xFE8D, 0xFE8E, 0xFE8F, 0xFE90, 0xFE91, 0xFE92, 0xFE93, 0xFE94, 0xFE95,
  17380. 0xFE96, 0xFE97, 0xFE98, 0xFE99, 0xFE9A, 0xFE9B, 0xFE9C, 0xFE9D, 0xFE9E,
  17381. 0xFE9F, 0xFEA0, 0xFEA1, 0xFEA2, 0xFEA3, 0xFEA4, 0xFEA5, 0xFEA6, 0xFEA7,
  17382. 0xFEA8, 0xFEA9, 0xFEAA, 0xFEAB, 0xFEAC, 0xFEAD, 0xFEAE, 0xFEAF, 0xFEB0,
  17383. 0xFEB1, 0xFEB2, 0xFEB3, 0xFEB4, 0xFEB5, 0xFEB6, 0xFEB7, 0xFEB8, 0xFEB9,
  17384. 0xFEBA, 0xFEBB, 0xFEBC, 0xFEBD, 0xFEBE, 0xFEBF, 0xFEC0, 0xFEC1, 0xFEC2,
  17385. 0xFEC3, 0xFEC4, 0xFEC5, 0xFEC6, 0xFEC7, 0xFEC8, 0xFEC9, 0xFECA, 0xFECB,
  17386. 0xFECC, 0xFECD, 0xFECE, 0xFECF, 0xFED0, 0xFED1, 0xFED2, 0xFED3, 0xFED4,
  17387. 0xFED5, 0xFED6, 0xFED7, 0xFED8, 0xFED9, 0xFEDA, 0xFEDB, 0xFEDC, 0xFEDD,
  17388. 0xFEDE, 0xFEDF, 0xFEE0, 0xFEE1, 0xFEE2, 0xFEE3, 0xFEE4, 0xFEE5, 0xFEE6,
  17389. 0xFEE7, 0xFEE8, 0xFEE9, 0xFEEA, 0xFEEB, 0xFEEC, 0xFEED, 0xFEEE, 0xFEEF,
  17390. 0xFEF0, 0xFEF1, 0xFEF2, 0xFEF3, 0xFEF4, 0xFEF5, 0xFEF6, 0xFEF7, 0xFEF8,
  17391. 0xFEF9, 0xFEFA, 0xFEFB, 0xFEFC, 0x10800, 0x10801, 0x10802, 0x10803,
  17392. 0x10804, 0x10805, 0x10808, 0x1080A, 0x1080B, 0x1080C, 0x1080D, 0x1080E,
  17393. 0x1080F, 0x10810, 0x10811, 0x10812, 0x10813, 0x10814, 0x10815, 0x10816,
  17394. 0x10817, 0x10818, 0x10819, 0x1081A, 0x1081B, 0x1081C, 0x1081D, 0x1081E,
  17395. 0x1081F, 0x10820, 0x10821, 0x10822, 0x10823, 0x10824, 0x10825, 0x10826,
  17396. 0x10827, 0x10828, 0x10829, 0x1082A, 0x1082B, 0x1082C, 0x1082D, 0x1082E,
  17397. 0x1082F, 0x10830, 0x10831, 0x10832, 0x10833, 0x10834, 0x10835, 0x10837,
  17398. 0x10838, 0x1083C, 0x1083F, 0x10840, 0x10841, 0x10842, 0x10843, 0x10844,
  17399. 0x10845, 0x10846, 0x10847, 0x10848, 0x10849, 0x1084A, 0x1084B, 0x1084C,
  17400. 0x1084D, 0x1084E, 0x1084F, 0x10850, 0x10851, 0x10852, 0x10853, 0x10854,
  17401. 0x10855, 0x10857, 0x10858, 0x10859, 0x1085A, 0x1085B, 0x1085C, 0x1085D,
  17402. 0x1085E, 0x1085F, 0x10900, 0x10901, 0x10902, 0x10903, 0x10904, 0x10905,
  17403. 0x10906, 0x10907, 0x10908, 0x10909, 0x1090A, 0x1090B, 0x1090C, 0x1090D,
  17404. 0x1090E, 0x1090F, 0x10910, 0x10911, 0x10912, 0x10913, 0x10914, 0x10915,
  17405. 0x10916, 0x10917, 0x10918, 0x10919, 0x1091A, 0x1091B, 0x10920, 0x10921,
  17406. 0x10922, 0x10923, 0x10924, 0x10925, 0x10926, 0x10927, 0x10928, 0x10929,
  17407. 0x1092A, 0x1092B, 0x1092C, 0x1092D, 0x1092E, 0x1092F, 0x10930, 0x10931,
  17408. 0x10932, 0x10933, 0x10934, 0x10935, 0x10936, 0x10937, 0x10938, 0x10939,
  17409. 0x1093F, 0x10980, 0x10981, 0x10982, 0x10983, 0x10984, 0x10985, 0x10986,
  17410. 0x10987, 0x10988, 0x10989, 0x1098A, 0x1098B, 0x1098C, 0x1098D, 0x1098E,
  17411. 0x1098F, 0x10990, 0x10991, 0x10992, 0x10993, 0x10994, 0x10995, 0x10996,
  17412. 0x10997, 0x10998, 0x10999, 0x1099A, 0x1099B, 0x1099C, 0x1099D, 0x1099E,
  17413. 0x1099F, 0x109A0, 0x109A1, 0x109A2, 0x109A3, 0x109A4, 0x109A5, 0x109A6,
  17414. 0x109A7, 0x109A8, 0x109A9, 0x109AA, 0x109AB, 0x109AC, 0x109AD, 0x109AE,
  17415. 0x109AF, 0x109B0, 0x109B1, 0x109B2, 0x109B3, 0x109B4, 0x109B5, 0x109B6,
  17416. 0x109B7, 0x109BE, 0x109BF, 0x10A00, 0x10A10, 0x10A11, 0x10A12, 0x10A13,
  17417. 0x10A15, 0x10A16, 0x10A17, 0x10A19, 0x10A1A, 0x10A1B, 0x10A1C, 0x10A1D,
  17418. 0x10A1E, 0x10A1F, 0x10A20, 0x10A21, 0x10A22, 0x10A23, 0x10A24, 0x10A25,
  17419. 0x10A26, 0x10A27, 0x10A28, 0x10A29, 0x10A2A, 0x10A2B, 0x10A2C, 0x10A2D,
  17420. 0x10A2E, 0x10A2F, 0x10A30, 0x10A31, 0x10A32, 0x10A33, 0x10A40, 0x10A41,
  17421. 0x10A42, 0x10A43, 0x10A44, 0x10A45, 0x10A46, 0x10A47, 0x10A50, 0x10A51,
  17422. 0x10A52, 0x10A53, 0x10A54, 0x10A55, 0x10A56, 0x10A57, 0x10A58, 0x10A60,
  17423. 0x10A61, 0x10A62, 0x10A63, 0x10A64, 0x10A65, 0x10A66, 0x10A67, 0x10A68,
  17424. 0x10A69, 0x10A6A, 0x10A6B, 0x10A6C, 0x10A6D, 0x10A6E, 0x10A6F, 0x10A70,
  17425. 0x10A71, 0x10A72, 0x10A73, 0x10A74, 0x10A75, 0x10A76, 0x10A77, 0x10A78,
  17426. 0x10A79, 0x10A7A, 0x10A7B, 0x10A7C, 0x10A7D, 0x10A7E, 0x10A7F, 0x10B00,
  17427. 0x10B01, 0x10B02, 0x10B03, 0x10B04, 0x10B05, 0x10B06, 0x10B07, 0x10B08,
  17428. 0x10B09, 0x10B0A, 0x10B0B, 0x10B0C, 0x10B0D, 0x10B0E, 0x10B0F, 0x10B10,
  17429. 0x10B11, 0x10B12, 0x10B13, 0x10B14, 0x10B15, 0x10B16, 0x10B17, 0x10B18,
  17430. 0x10B19, 0x10B1A, 0x10B1B, 0x10B1C, 0x10B1D, 0x10B1E, 0x10B1F, 0x10B20,
  17431. 0x10B21, 0x10B22, 0x10B23, 0x10B24, 0x10B25, 0x10B26, 0x10B27, 0x10B28,
  17432. 0x10B29, 0x10B2A, 0x10B2B, 0x10B2C, 0x10B2D, 0x10B2E, 0x10B2F, 0x10B30,
  17433. 0x10B31, 0x10B32, 0x10B33, 0x10B34, 0x10B35, 0x10B40, 0x10B41, 0x10B42,
  17434. 0x10B43, 0x10B44, 0x10B45, 0x10B46, 0x10B47, 0x10B48, 0x10B49, 0x10B4A,
  17435. 0x10B4B, 0x10B4C, 0x10B4D, 0x10B4E, 0x10B4F, 0x10B50, 0x10B51, 0x10B52,
  17436. 0x10B53, 0x10B54, 0x10B55, 0x10B58, 0x10B59, 0x10B5A, 0x10B5B, 0x10B5C,
  17437. 0x10B5D, 0x10B5E, 0x10B5F, 0x10B60, 0x10B61, 0x10B62, 0x10B63, 0x10B64,
  17438. 0x10B65, 0x10B66, 0x10B67, 0x10B68, 0x10B69, 0x10B6A, 0x10B6B, 0x10B6C,
  17439. 0x10B6D, 0x10B6E, 0x10B6F, 0x10B70, 0x10B71, 0x10B72, 0x10B78, 0x10B79,
  17440. 0x10B7A, 0x10B7B, 0x10B7C, 0x10B7D, 0x10B7E, 0x10B7F, 0x10C00, 0x10C01,
  17441. 0x10C02, 0x10C03, 0x10C04, 0x10C05, 0x10C06, 0x10C07, 0x10C08, 0x10C09,
  17442. 0x10C0A, 0x10C0B, 0x10C0C, 0x10C0D, 0x10C0E, 0x10C0F, 0x10C10, 0x10C11,
  17443. 0x10C12, 0x10C13, 0x10C14, 0x10C15, 0x10C16, 0x10C17, 0x10C18, 0x10C19,
  17444. 0x10C1A, 0x10C1B, 0x10C1C, 0x10C1D, 0x10C1E, 0x10C1F, 0x10C20, 0x10C21,
  17445. 0x10C22, 0x10C23, 0x10C24, 0x10C25, 0x10C26, 0x10C27, 0x10C28, 0x10C29,
  17446. 0x10C2A, 0x10C2B, 0x10C2C, 0x10C2D, 0x10C2E, 0x10C2F, 0x10C30, 0x10C31,
  17447. 0x10C32, 0x10C33, 0x10C34, 0x10C35, 0x10C36, 0x10C37, 0x10C38, 0x10C39,
  17448. 0x10C3A, 0x10C3B, 0x10C3C, 0x10C3D, 0x10C3E, 0x10C3F, 0x10C40, 0x10C41,
  17449. 0x10C42, 0x10C43, 0x10C44, 0x10C45, 0x10C46, 0x10C47, 0x10C48, 0x1EE00,
  17450. 0x1EE01, 0x1EE02, 0x1EE03, 0x1EE05, 0x1EE06, 0x1EE07, 0x1EE08, 0x1EE09,
  17451. 0x1EE0A, 0x1EE0B, 0x1EE0C, 0x1EE0D, 0x1EE0E, 0x1EE0F, 0x1EE10, 0x1EE11,
  17452. 0x1EE12, 0x1EE13, 0x1EE14, 0x1EE15, 0x1EE16, 0x1EE17, 0x1EE18, 0x1EE19,
  17453. 0x1EE1A, 0x1EE1B, 0x1EE1C, 0x1EE1D, 0x1EE1E, 0x1EE1F, 0x1EE21, 0x1EE22,
  17454. 0x1EE24, 0x1EE27, 0x1EE29, 0x1EE2A, 0x1EE2B, 0x1EE2C, 0x1EE2D, 0x1EE2E,
  17455. 0x1EE2F, 0x1EE30, 0x1EE31, 0x1EE32, 0x1EE34, 0x1EE35, 0x1EE36, 0x1EE37,
  17456. 0x1EE39, 0x1EE3B, 0x1EE42, 0x1EE47, 0x1EE49, 0x1EE4B, 0x1EE4D, 0x1EE4E,
  17457. 0x1EE4F, 0x1EE51, 0x1EE52, 0x1EE54, 0x1EE57, 0x1EE59, 0x1EE5B, 0x1EE5D,
  17458. 0x1EE5F, 0x1EE61, 0x1EE62, 0x1EE64, 0x1EE67, 0x1EE68, 0x1EE69, 0x1EE6A,
  17459. 0x1EE6C, 0x1EE6D, 0x1EE6E, 0x1EE6F, 0x1EE70, 0x1EE71, 0x1EE72, 0x1EE74,
  17460. 0x1EE75, 0x1EE76, 0x1EE77, 0x1EE79, 0x1EE7A, 0x1EE7B, 0x1EE7C, 0x1EE7E,
  17461. 0x1EE80, 0x1EE81, 0x1EE82, 0x1EE83, 0x1EE84, 0x1EE85, 0x1EE86, 0x1EE87,
  17462. 0x1EE88, 0x1EE89, 0x1EE8B, 0x1EE8C, 0x1EE8D, 0x1EE8E, 0x1EE8F, 0x1EE90,
  17463. 0x1EE91, 0x1EE92, 0x1EE93, 0x1EE94, 0x1EE95, 0x1EE96, 0x1EE97, 0x1EE98,
  17464. 0x1EE99, 0x1EE9A, 0x1EE9B, 0x1EEA1, 0x1EEA2, 0x1EEA3, 0x1EEA5, 0x1EEA6,
  17465. 0x1EEA7, 0x1EEA8, 0x1EEA9, 0x1EEAB, 0x1EEAC, 0x1EEAD, 0x1EEAE, 0x1EEAF,
  17466. 0x1EEB0, 0x1EEB1, 0x1EEB2, 0x1EEB3, 0x1EEB4, 0x1EEB5, 0x1EEB6, 0x1EEB7,
  17467. 0x1EEB8, 0x1EEB9, 0x1EEBA, 0x1EEBB, 0x10FFFD];
  17468. function determineBidi(cueDiv) {
  17469. var nodeStack = [],
  17470. text = "",
  17471. charCode;
  17472. if (!cueDiv || !cueDiv.childNodes) {
  17473. return "ltr";
  17474. }
  17475. function pushNodes(nodeStack, node) {
  17476. for (var i = node.childNodes.length - 1; i >= 0; i--) {
  17477. nodeStack.push(node.childNodes[i]);
  17478. }
  17479. }
  17480. function nextTextNode(nodeStack) {
  17481. if (!nodeStack || !nodeStack.length) {
  17482. return null;
  17483. }
  17484. var node = nodeStack.pop(),
  17485. text = node.textContent || node.innerText;
  17486. if (text) {
  17487. // TODO: This should match all unicode type B characters (paragraph
  17488. // separator characters). See issue #115.
  17489. var m = text.match(/^.*(\n|\r)/);
  17490. if (m) {
  17491. nodeStack.length = 0;
  17492. return m[0];
  17493. }
  17494. return text;
  17495. }
  17496. if (node.tagName === "ruby") {
  17497. return nextTextNode(nodeStack);
  17498. }
  17499. if (node.childNodes) {
  17500. pushNodes(nodeStack, node);
  17501. return nextTextNode(nodeStack);
  17502. }
  17503. }
  17504. pushNodes(nodeStack, cueDiv);
  17505. while ((text = nextTextNode(nodeStack))) {
  17506. for (var i = 0; i < text.length; i++) {
  17507. charCode = text.charCodeAt(i);
  17508. for (var j = 0; j < strongRTLChars.length; j++) {
  17509. if (strongRTLChars[j] === charCode) {
  17510. return "rtl";
  17511. }
  17512. }
  17513. }
  17514. }
  17515. return "ltr";
  17516. }
  17517. function computeLinePos(cue) {
  17518. if (typeof cue.line === "number" &&
  17519. (cue.snapToLines || (cue.line >= 0 && cue.line <= 100))) {
  17520. return cue.line;
  17521. }
  17522. if (!cue.track || !cue.track.textTrackList ||
  17523. !cue.track.textTrackList.mediaElement) {
  17524. return -1;
  17525. }
  17526. var track = cue.track,
  17527. trackList = track.textTrackList,
  17528. count = 0;
  17529. for (var i = 0; i < trackList.length && trackList[i] !== track; i++) {
  17530. if (trackList[i].mode === "showing") {
  17531. count++;
  17532. }
  17533. }
  17534. return ++count * -1;
  17535. }
  17536. function StyleBox() {
  17537. }
  17538. // Apply styles to a div. If there is no div passed then it defaults to the
  17539. // div on 'this'.
  17540. StyleBox.prototype.applyStyles = function(styles, div) {
  17541. div = div || this.div;
  17542. for (var prop in styles) {
  17543. if (styles.hasOwnProperty(prop)) {
  17544. div.style[prop] = styles[prop];
  17545. }
  17546. }
  17547. };
  17548. StyleBox.prototype.formatStyle = function(val, unit) {
  17549. return val === 0 ? 0 : val + unit;
  17550. };
  17551. // Constructs the computed display state of the cue (a div). Places the div
  17552. // into the overlay which should be a block level element (usually a div).
  17553. function CueStyleBox(window, cue, styleOptions) {
  17554. var isIE8 = (/MSIE\s8\.0/).test(navigator.userAgent);
  17555. var color = "rgba(255, 255, 255, 1)";
  17556. var backgroundColor = "rgba(0, 0, 0, 0.8)";
  17557. if (isIE8) {
  17558. color = "rgb(255, 255, 255)";
  17559. backgroundColor = "rgb(0, 0, 0)";
  17560. }
  17561. StyleBox.call(this);
  17562. this.cue = cue;
  17563. // Parse our cue's text into a DOM tree rooted at 'cueDiv'. This div will
  17564. // have inline positioning and will function as the cue background box.
  17565. this.cueDiv = parseContent(window, cue.text);
  17566. var styles = {
  17567. color: color,
  17568. backgroundColor: backgroundColor,
  17569. position: "relative",
  17570. left: 0,
  17571. right: 0,
  17572. top: 0,
  17573. bottom: 0,
  17574. display: "inline"
  17575. };
  17576. if (!isIE8) {
  17577. styles.writingMode = cue.vertical === "" ? "horizontal-tb"
  17578. : cue.vertical === "lr" ? "vertical-lr"
  17579. : "vertical-rl";
  17580. styles.unicodeBidi = "plaintext";
  17581. }
  17582. this.applyStyles(styles, this.cueDiv);
  17583. // Create an absolutely positioned div that will be used to position the cue
  17584. // div. Note, all WebVTT cue-setting alignments are equivalent to the CSS
  17585. // mirrors of them except "middle" which is "center" in CSS.
  17586. this.div = window.document.createElement("div");
  17587. styles = {
  17588. textAlign: cue.align === "middle" ? "center" : cue.align,
  17589. font: styleOptions.font,
  17590. whiteSpace: "pre-line",
  17591. position: "absolute"
  17592. };
  17593. if (!isIE8) {
  17594. styles.direction = determineBidi(this.cueDiv);
  17595. styles.writingMode = cue.vertical === "" ? "horizontal-tb"
  17596. : cue.vertical === "lr" ? "vertical-lr"
  17597. : "vertical-rl".
  17598. stylesunicodeBidi = "plaintext";
  17599. }
  17600. this.applyStyles(styles);
  17601. this.div.appendChild(this.cueDiv);
  17602. // Calculate the distance from the reference edge of the viewport to the text
  17603. // position of the cue box. The reference edge will be resolved later when
  17604. // the box orientation styles are applied.
  17605. var textPos = 0;
  17606. switch (cue.positionAlign) {
  17607. case "start":
  17608. textPos = cue.position;
  17609. break;
  17610. case "middle":
  17611. textPos = cue.position - (cue.size / 2);
  17612. break;
  17613. case "end":
  17614. textPos = cue.position - cue.size;
  17615. break;
  17616. }
  17617. // Horizontal box orientation; textPos is the distance from the left edge of the
  17618. // area to the left edge of the box and cue.size is the distance extending to
  17619. // the right from there.
  17620. if (cue.vertical === "") {
  17621. this.applyStyles({
  17622. left: this.formatStyle(textPos, "%"),
  17623. width: this.formatStyle(cue.size, "%")
  17624. });
  17625. // Vertical box orientation; textPos is the distance from the top edge of the
  17626. // area to the top edge of the box and cue.size is the height extending
  17627. // downwards from there.
  17628. } else {
  17629. this.applyStyles({
  17630. top: this.formatStyle(textPos, "%"),
  17631. height: this.formatStyle(cue.size, "%")
  17632. });
  17633. }
  17634. this.move = function(box) {
  17635. this.applyStyles({
  17636. top: this.formatStyle(box.top, "px"),
  17637. bottom: this.formatStyle(box.bottom, "px"),
  17638. left: this.formatStyle(box.left, "px"),
  17639. right: this.formatStyle(box.right, "px"),
  17640. height: this.formatStyle(box.height, "px"),
  17641. width: this.formatStyle(box.width, "px")
  17642. });
  17643. };
  17644. }
  17645. CueStyleBox.prototype = _objCreate(StyleBox.prototype);
  17646. CueStyleBox.prototype.constructor = CueStyleBox;
  17647. // Represents the co-ordinates of an Element in a way that we can easily
  17648. // compute things with such as if it overlaps or intersects with another Element.
  17649. // Can initialize it with either a StyleBox or another BoxPosition.
  17650. function BoxPosition(obj) {
  17651. var isIE8 = (/MSIE\s8\.0/).test(navigator.userAgent);
  17652. // Either a BoxPosition was passed in and we need to copy it, or a StyleBox
  17653. // was passed in and we need to copy the results of 'getBoundingClientRect'
  17654. // as the object returned is readonly. All co-ordinate values are in reference
  17655. // to the viewport origin (top left).
  17656. var lh, height, width, top;
  17657. if (obj.div) {
  17658. height = obj.div.offsetHeight;
  17659. width = obj.div.offsetWidth;
  17660. top = obj.div.offsetTop;
  17661. var rects = (rects = obj.div.childNodes) && (rects = rects[0]) &&
  17662. rects.getClientRects && rects.getClientRects();
  17663. obj = obj.div.getBoundingClientRect();
  17664. // In certain cases the outter div will be slightly larger then the sum of
  17665. // the inner div's lines. This could be due to bold text, etc, on some platforms.
  17666. // In this case we should get the average line height and use that. This will
  17667. // result in the desired behaviour.
  17668. lh = rects ? Math.max((rects[0] && rects[0].height) || 0, obj.height / rects.length)
  17669. : 0;
  17670. }
  17671. this.left = obj.left;
  17672. this.right = obj.right;
  17673. this.top = obj.top || top;
  17674. this.height = obj.height || height;
  17675. this.bottom = obj.bottom || (top + (obj.height || height));
  17676. this.width = obj.width || width;
  17677. this.lineHeight = lh !== undefined ? lh : obj.lineHeight;
  17678. if (isIE8 && !this.lineHeight) {
  17679. this.lineHeight = 13;
  17680. }
  17681. }
  17682. // Move the box along a particular axis. Optionally pass in an amount to move
  17683. // the box. If no amount is passed then the default is the line height of the
  17684. // box.
  17685. BoxPosition.prototype.move = function(axis, toMove) {
  17686. toMove = toMove !== undefined ? toMove : this.lineHeight;
  17687. switch (axis) {
  17688. case "+x":
  17689. this.left += toMove;
  17690. this.right += toMove;
  17691. break;
  17692. case "-x":
  17693. this.left -= toMove;
  17694. this.right -= toMove;
  17695. break;
  17696. case "+y":
  17697. this.top += toMove;
  17698. this.bottom += toMove;
  17699. break;
  17700. case "-y":
  17701. this.top -= toMove;
  17702. this.bottom -= toMove;
  17703. break;
  17704. }
  17705. };
  17706. // Check if this box overlaps another box, b2.
  17707. BoxPosition.prototype.overlaps = function(b2) {
  17708. return this.left < b2.right &&
  17709. this.right > b2.left &&
  17710. this.top < b2.bottom &&
  17711. this.bottom > b2.top;
  17712. };
  17713. // Check if this box overlaps any other boxes in boxes.
  17714. BoxPosition.prototype.overlapsAny = function(boxes) {
  17715. for (var i = 0; i < boxes.length; i++) {
  17716. if (this.overlaps(boxes[i])) {
  17717. return true;
  17718. }
  17719. }
  17720. return false;
  17721. };
  17722. // Check if this box is within another box.
  17723. BoxPosition.prototype.within = function(container) {
  17724. return this.top >= container.top &&
  17725. this.bottom <= container.bottom &&
  17726. this.left >= container.left &&
  17727. this.right <= container.right;
  17728. };
  17729. // Check if this box is entirely within the container or it is overlapping
  17730. // on the edge opposite of the axis direction passed. For example, if "+x" is
  17731. // passed and the box is overlapping on the left edge of the container, then
  17732. // return true.
  17733. BoxPosition.prototype.overlapsOppositeAxis = function(container, axis) {
  17734. switch (axis) {
  17735. case "+x":
  17736. return this.left < container.left;
  17737. case "-x":
  17738. return this.right > container.right;
  17739. case "+y":
  17740. return this.top < container.top;
  17741. case "-y":
  17742. return this.bottom > container.bottom;
  17743. }
  17744. };
  17745. // Find the percentage of the area that this box is overlapping with another
  17746. // box.
  17747. BoxPosition.prototype.intersectPercentage = function(b2) {
  17748. var x = Math.max(0, Math.min(this.right, b2.right) - Math.max(this.left, b2.left)),
  17749. y = Math.max(0, Math.min(this.bottom, b2.bottom) - Math.max(this.top, b2.top)),
  17750. intersectArea = x * y;
  17751. return intersectArea / (this.height * this.width);
  17752. };
  17753. // Convert the positions from this box to CSS compatible positions using
  17754. // the reference container's positions. This has to be done because this
  17755. // box's positions are in reference to the viewport origin, whereas, CSS
  17756. // values are in referecne to their respective edges.
  17757. BoxPosition.prototype.toCSSCompatValues = function(reference) {
  17758. return {
  17759. top: this.top - reference.top,
  17760. bottom: reference.bottom - this.bottom,
  17761. left: this.left - reference.left,
  17762. right: reference.right - this.right,
  17763. height: this.height,
  17764. width: this.width
  17765. };
  17766. };
  17767. // Get an object that represents the box's position without anything extra.
  17768. // Can pass a StyleBox, HTMLElement, or another BoxPositon.
  17769. BoxPosition.getSimpleBoxPosition = function(obj) {
  17770. var height = obj.div ? obj.div.offsetHeight : obj.tagName ? obj.offsetHeight : 0;
  17771. var width = obj.div ? obj.div.offsetWidth : obj.tagName ? obj.offsetWidth : 0;
  17772. var top = obj.div ? obj.div.offsetTop : obj.tagName ? obj.offsetTop : 0;
  17773. obj = obj.div ? obj.div.getBoundingClientRect() :
  17774. obj.tagName ? obj.getBoundingClientRect() : obj;
  17775. var ret = {
  17776. left: obj.left,
  17777. right: obj.right,
  17778. top: obj.top || top,
  17779. height: obj.height || height,
  17780. bottom: obj.bottom || (top + (obj.height || height)),
  17781. width: obj.width || width
  17782. };
  17783. return ret;
  17784. };
  17785. // Move a StyleBox to its specified, or next best, position. The containerBox
  17786. // is the box that contains the StyleBox, such as a div. boxPositions are
  17787. // a list of other boxes that the styleBox can't overlap with.
  17788. function moveBoxToLinePosition(window, styleBox, containerBox, boxPositions) {
  17789. // Find the best position for a cue box, b, on the video. The axis parameter
  17790. // is a list of axis, the order of which, it will move the box along. For example:
  17791. // Passing ["+x", "-x"] will move the box first along the x axis in the positive
  17792. // direction. If it doesn't find a good position for it there it will then move
  17793. // it along the x axis in the negative direction.
  17794. function findBestPosition(b, axis) {
  17795. var bestPosition,
  17796. specifiedPosition = new BoxPosition(b),
  17797. percentage = 1; // Highest possible so the first thing we get is better.
  17798. for (var i = 0; i < axis.length; i++) {
  17799. while (b.overlapsOppositeAxis(containerBox, axis[i]) ||
  17800. (b.within(containerBox) && b.overlapsAny(boxPositions))) {
  17801. b.move(axis[i]);
  17802. }
  17803. // We found a spot where we aren't overlapping anything. This is our
  17804. // best position.
  17805. if (b.within(containerBox)) {
  17806. return b;
  17807. }
  17808. var p = b.intersectPercentage(containerBox);
  17809. // If we're outside the container box less then we were on our last try
  17810. // then remember this position as the best position.
  17811. if (percentage > p) {
  17812. bestPosition = new BoxPosition(b);
  17813. percentage = p;
  17814. }
  17815. // Reset the box position to the specified position.
  17816. b = new BoxPosition(specifiedPosition);
  17817. }
  17818. return bestPosition || specifiedPosition;
  17819. }
  17820. var boxPosition = new BoxPosition(styleBox),
  17821. cue = styleBox.cue,
  17822. linePos = computeLinePos(cue),
  17823. axis = [];
  17824. // If we have a line number to align the cue to.
  17825. if (cue.snapToLines) {
  17826. var size;
  17827. switch (cue.vertical) {
  17828. case "":
  17829. axis = [ "+y", "-y" ];
  17830. size = "height";
  17831. break;
  17832. case "rl":
  17833. axis = [ "+x", "-x" ];
  17834. size = "width";
  17835. break;
  17836. case "lr":
  17837. axis = [ "-x", "+x" ];
  17838. size = "width";
  17839. break;
  17840. }
  17841. var step = boxPosition.lineHeight,
  17842. position = step * Math.round(linePos),
  17843. maxPosition = containerBox[size] + step,
  17844. initialAxis = axis[0];
  17845. // If the specified intial position is greater then the max position then
  17846. // clamp the box to the amount of steps it would take for the box to
  17847. // reach the max position.
  17848. if (Math.abs(position) > maxPosition) {
  17849. position = position < 0 ? -1 : 1;
  17850. position *= Math.ceil(maxPosition / step) * step;
  17851. }
  17852. // If computed line position returns negative then line numbers are
  17853. // relative to the bottom of the video instead of the top. Therefore, we
  17854. // need to increase our initial position by the length or width of the
  17855. // video, depending on the writing direction, and reverse our axis directions.
  17856. if (linePos < 0) {
  17857. position += cue.vertical === "" ? containerBox.height : containerBox.width;
  17858. axis = axis.reverse();
  17859. }
  17860. // Move the box to the specified position. This may not be its best
  17861. // position.
  17862. boxPosition.move(initialAxis, position);
  17863. } else {
  17864. // If we have a percentage line value for the cue.
  17865. var calculatedPercentage = (boxPosition.lineHeight / containerBox.height) * 100;
  17866. switch (cue.lineAlign) {
  17867. case "middle":
  17868. linePos -= (calculatedPercentage / 2);
  17869. break;
  17870. case "end":
  17871. linePos -= calculatedPercentage;
  17872. break;
  17873. }
  17874. // Apply initial line position to the cue box.
  17875. switch (cue.vertical) {
  17876. case "":
  17877. styleBox.applyStyles({
  17878. top: styleBox.formatStyle(linePos, "%")
  17879. });
  17880. break;
  17881. case "rl":
  17882. styleBox.applyStyles({
  17883. left: styleBox.formatStyle(linePos, "%")
  17884. });
  17885. break;
  17886. case "lr":
  17887. styleBox.applyStyles({
  17888. right: styleBox.formatStyle(linePos, "%")
  17889. });
  17890. break;
  17891. }
  17892. axis = [ "+y", "-x", "+x", "-y" ];
  17893. // Get the box position again after we've applied the specified positioning
  17894. // to it.
  17895. boxPosition = new BoxPosition(styleBox);
  17896. }
  17897. var bestPosition = findBestPosition(boxPosition, axis);
  17898. styleBox.move(bestPosition.toCSSCompatValues(containerBox));
  17899. }
  17900. function WebVTT() {
  17901. // Nothing
  17902. }
  17903. // Helper to allow strings to be decoded instead of the default binary utf8 data.
  17904. WebVTT.StringDecoder = function() {
  17905. return {
  17906. decode: function(data) {
  17907. if (!data) {
  17908. return "";
  17909. }
  17910. if (typeof data !== "string") {
  17911. throw new Error("Error - expected string data.");
  17912. }
  17913. return decodeURIComponent(encodeURIComponent(data));
  17914. }
  17915. };
  17916. };
  17917. WebVTT.convertCueToDOMTree = function(window, cuetext) {
  17918. if (!window || !cuetext) {
  17919. return null;
  17920. }
  17921. return parseContent(window, cuetext);
  17922. };
  17923. var FONT_SIZE_PERCENT = 0.05;
  17924. var FONT_STYLE = "sans-serif";
  17925. var CUE_BACKGROUND_PADDING = "1.5%";
  17926. // Runs the processing model over the cues and regions passed to it.
  17927. // @param overlay A block level element (usually a div) that the computed cues
  17928. // and regions will be placed into.
  17929. WebVTT.processCues = function(window, cues, overlay) {
  17930. if (!window || !cues || !overlay) {
  17931. return null;
  17932. }
  17933. // Remove all previous children.
  17934. while (overlay.firstChild) {
  17935. overlay.removeChild(overlay.firstChild);
  17936. }
  17937. var paddedOverlay = window.document.createElement("div");
  17938. paddedOverlay.style.position = "absolute";
  17939. paddedOverlay.style.left = "0";
  17940. paddedOverlay.style.right = "0";
  17941. paddedOverlay.style.top = "0";
  17942. paddedOverlay.style.bottom = "0";
  17943. paddedOverlay.style.margin = CUE_BACKGROUND_PADDING;
  17944. overlay.appendChild(paddedOverlay);
  17945. // Determine if we need to compute the display states of the cues. This could
  17946. // be the case if a cue's state has been changed since the last computation or
  17947. // if it has not been computed yet.
  17948. function shouldCompute(cues) {
  17949. for (var i = 0; i < cues.length; i++) {
  17950. if (cues[i].hasBeenReset || !cues[i].displayState) {
  17951. return true;
  17952. }
  17953. }
  17954. return false;
  17955. }
  17956. // We don't need to recompute the cues' display states. Just reuse them.
  17957. if (!shouldCompute(cues)) {
  17958. for (var i = 0; i < cues.length; i++) {
  17959. paddedOverlay.appendChild(cues[i].displayState);
  17960. }
  17961. return;
  17962. }
  17963. var boxPositions = [],
  17964. containerBox = BoxPosition.getSimpleBoxPosition(paddedOverlay),
  17965. fontSize = Math.round(containerBox.height * FONT_SIZE_PERCENT * 100) / 100;
  17966. var styleOptions = {
  17967. font: fontSize + "px " + FONT_STYLE
  17968. };
  17969. (function() {
  17970. var styleBox, cue;
  17971. for (var i = 0; i < cues.length; i++) {
  17972. cue = cues[i];
  17973. // Compute the intial position and styles of the cue div.
  17974. styleBox = new CueStyleBox(window, cue, styleOptions);
  17975. paddedOverlay.appendChild(styleBox.div);
  17976. // Move the cue div to it's correct line position.
  17977. moveBoxToLinePosition(window, styleBox, containerBox, boxPositions);
  17978. // Remember the computed div so that we don't have to recompute it later
  17979. // if we don't have too.
  17980. cue.displayState = styleBox.div;
  17981. boxPositions.push(BoxPosition.getSimpleBoxPosition(styleBox));
  17982. }
  17983. })();
  17984. };
  17985. WebVTT.Parser = function(window, vttjs, decoder) {
  17986. if (!decoder) {
  17987. decoder = vttjs;
  17988. vttjs = {};
  17989. }
  17990. if (!vttjs) {
  17991. vttjs = {};
  17992. }
  17993. this.window = window;
  17994. this.vttjs = vttjs;
  17995. this.state = "INITIAL";
  17996. this.buffer = "";
  17997. this.decoder = decoder || new TextDecoder("utf8");
  17998. this.regionList = [];
  17999. };
  18000. WebVTT.Parser.prototype = {
  18001. // If the error is a ParsingError then report it to the consumer if
  18002. // possible. If it's not a ParsingError then throw it like normal.
  18003. reportOrThrowError: function(e) {
  18004. if (e instanceof ParsingError) {
  18005. this.onparsingerror && this.onparsingerror(e);
  18006. } else {
  18007. throw e;
  18008. }
  18009. },
  18010. parse: function (data) {
  18011. var self = this;
  18012. // If there is no data then we won't decode it, but will just try to parse
  18013. // whatever is in buffer already. This may occur in circumstances, for
  18014. // example when flush() is called.
  18015. if (data) {
  18016. // Try to decode the data that we received.
  18017. self.buffer += self.decoder.decode(data, {stream: true});
  18018. }
  18019. function collectNextLine() {
  18020. var buffer = self.buffer;
  18021. var pos = 0;
  18022. while (pos < buffer.length && buffer[pos] !== '\r' && buffer[pos] !== '\n') {
  18023. ++pos;
  18024. }
  18025. var line = buffer.substr(0, pos);
  18026. // Advance the buffer early in case we fail below.
  18027. if (buffer[pos] === '\r') {
  18028. ++pos;
  18029. }
  18030. if (buffer[pos] === '\n') {
  18031. ++pos;
  18032. }
  18033. self.buffer = buffer.substr(pos);
  18034. return line;
  18035. }
  18036. // 3.4 WebVTT region and WebVTT region settings syntax
  18037. function parseRegion(input) {
  18038. var settings = new Settings();
  18039. parseOptions(input, function (k, v) {
  18040. switch (k) {
  18041. case "id":
  18042. settings.set(k, v);
  18043. break;
  18044. case "width":
  18045. settings.percent(k, v);
  18046. break;
  18047. case "lines":
  18048. settings.integer(k, v);
  18049. break;
  18050. case "regionanchor":
  18051. case "viewportanchor":
  18052. var xy = v.split(',');
  18053. if (xy.length !== 2) {
  18054. break;
  18055. }
  18056. // We have to make sure both x and y parse, so use a temporary
  18057. // settings object here.
  18058. var anchor = new Settings();
  18059. anchor.percent("x", xy[0]);
  18060. anchor.percent("y", xy[1]);
  18061. if (!anchor.has("x") || !anchor.has("y")) {
  18062. break;
  18063. }
  18064. settings.set(k + "X", anchor.get("x"));
  18065. settings.set(k + "Y", anchor.get("y"));
  18066. break;
  18067. case "scroll":
  18068. settings.alt(k, v, ["up"]);
  18069. break;
  18070. }
  18071. }, /=/, /\s/);
  18072. // Create the region, using default values for any values that were not
  18073. // specified.
  18074. if (settings.has("id")) {
  18075. var region = new (self.vttjs.VTTRegion || self.window.VTTRegion)();
  18076. region.width = settings.get("width", 100);
  18077. region.lines = settings.get("lines", 3);
  18078. region.regionAnchorX = settings.get("regionanchorX", 0);
  18079. region.regionAnchorY = settings.get("regionanchorY", 100);
  18080. region.viewportAnchorX = settings.get("viewportanchorX", 0);
  18081. region.viewportAnchorY = settings.get("viewportanchorY", 100);
  18082. region.scroll = settings.get("scroll", "");
  18083. // Register the region.
  18084. self.onregion && self.onregion(region);
  18085. // Remember the VTTRegion for later in case we parse any VTTCues that
  18086. // reference it.
  18087. self.regionList.push({
  18088. id: settings.get("id"),
  18089. region: region
  18090. });
  18091. }
  18092. }
  18093. // 3.2 WebVTT metadata header syntax
  18094. function parseHeader(input) {
  18095. parseOptions(input, function (k, v) {
  18096. switch (k) {
  18097. case "Region":
  18098. // 3.3 WebVTT region metadata header syntax
  18099. parseRegion(v);
  18100. break;
  18101. }
  18102. }, /:/);
  18103. }
  18104. // 5.1 WebVTT file parsing.
  18105. try {
  18106. var line;
  18107. if (self.state === "INITIAL") {
  18108. // We can't start parsing until we have the first line.
  18109. if (!/\r\n|\n/.test(self.buffer)) {
  18110. return this;
  18111. }
  18112. line = collectNextLine();
  18113. var m = line.match(/^WEBVTT([ \t].*)?$/);
  18114. if (!m || !m[0]) {
  18115. throw new ParsingError(ParsingError.Errors.BadSignature);
  18116. }
  18117. self.state = "HEADER";
  18118. }
  18119. var alreadyCollectedLine = false;
  18120. while (self.buffer) {
  18121. // We can't parse a line until we have the full line.
  18122. if (!/\r\n|\n/.test(self.buffer)) {
  18123. return this;
  18124. }
  18125. if (!alreadyCollectedLine) {
  18126. line = collectNextLine();
  18127. } else {
  18128. alreadyCollectedLine = false;
  18129. }
  18130. switch (self.state) {
  18131. case "HEADER":
  18132. // 13-18 - Allow a header (metadata) under the WEBVTT line.
  18133. if (/:/.test(line)) {
  18134. parseHeader(line);
  18135. } else if (!line) {
  18136. // An empty line terminates the header and starts the body (cues).
  18137. self.state = "ID";
  18138. }
  18139. continue;
  18140. case "NOTE":
  18141. // Ignore NOTE blocks.
  18142. if (!line) {
  18143. self.state = "ID";
  18144. }
  18145. continue;
  18146. case "ID":
  18147. // Check for the start of NOTE blocks.
  18148. if (/^NOTE($|[ \t])/.test(line)) {
  18149. self.state = "NOTE";
  18150. break;
  18151. }
  18152. // 19-29 - Allow any number of line terminators, then initialize new cue values.
  18153. if (!line) {
  18154. continue;
  18155. }
  18156. self.cue = new (self.vttjs.VTTCue || self.window.VTTCue)(0, 0, "");
  18157. self.state = "CUE";
  18158. // 30-39 - Check if self line contains an optional identifier or timing data.
  18159. if (line.indexOf("-->") === -1) {
  18160. self.cue.id = line;
  18161. continue;
  18162. }
  18163. // Process line as start of a cue.
  18164. /*falls through*/
  18165. case "CUE":
  18166. // 40 - Collect cue timings and settings.
  18167. try {
  18168. parseCue(line, self.cue, self.regionList);
  18169. } catch (e) {
  18170. self.reportOrThrowError(e);
  18171. // In case of an error ignore rest of the cue.
  18172. self.cue = null;
  18173. self.state = "BADCUE";
  18174. continue;
  18175. }
  18176. self.state = "CUETEXT";
  18177. continue;
  18178. case "CUETEXT":
  18179. var hasSubstring = line.indexOf("-->") !== -1;
  18180. // 34 - If we have an empty line then report the cue.
  18181. // 35 - If we have the special substring '-->' then report the cue,
  18182. // but do not collect the line as we need to process the current
  18183. // one as a new cue.
  18184. if (!line || hasSubstring && (alreadyCollectedLine = true)) {
  18185. // We are done parsing self cue.
  18186. self.oncue && self.oncue(self.cue);
  18187. self.cue = null;
  18188. self.state = "ID";
  18189. continue;
  18190. }
  18191. if (self.cue.text) {
  18192. self.cue.text += "\n";
  18193. }
  18194. self.cue.text += line;
  18195. continue;
  18196. case "BADCUE": // BADCUE
  18197. // 54-62 - Collect and discard the remaining cue.
  18198. if (!line) {
  18199. self.state = "ID";
  18200. }
  18201. continue;
  18202. }
  18203. }
  18204. } catch (e) {
  18205. self.reportOrThrowError(e);
  18206. // If we are currently parsing a cue, report what we have.
  18207. if (self.state === "CUETEXT" && self.cue && self.oncue) {
  18208. self.oncue(self.cue);
  18209. }
  18210. self.cue = null;
  18211. // Enter BADWEBVTT state if header was not parsed correctly otherwise
  18212. // another exception occurred so enter BADCUE state.
  18213. self.state = self.state === "INITIAL" ? "BADWEBVTT" : "BADCUE";
  18214. }
  18215. return this;
  18216. },
  18217. flush: function () {
  18218. var self = this;
  18219. try {
  18220. // Finish decoding the stream.
  18221. self.buffer += self.decoder.decode();
  18222. // Synthesize the end of the current cue or region.
  18223. if (self.cue || self.state === "HEADER") {
  18224. self.buffer += "\n\n";
  18225. self.parse();
  18226. }
  18227. // If we've flushed, parsed, and we're still on the INITIAL state then
  18228. // that means we don't have enough of the stream to parse the first
  18229. // line.
  18230. if (self.state === "INITIAL") {
  18231. throw new ParsingError(ParsingError.Errors.BadSignature);
  18232. }
  18233. } catch(e) {
  18234. self.reportOrThrowError(e);
  18235. }
  18236. self.onflush && self.onflush();
  18237. return this;
  18238. }
  18239. };
  18240. global.WebVTT = WebVTT;
  18241. }(this, (this.vttjs || {})));