silvermine-videojs-quality-selector.js 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980
  1. (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. (function(){
  3. var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
  4. // The base Class implementation (does nothing)
  5. this.Class = function(){};
  6. // Create a new Class that inherits from this class
  7. Class.extend = function(className, prop) {
  8. if(prop == undefined) {
  9. prop = className;
  10. className = "Class";
  11. }
  12. var _super = this.prototype;
  13. // Instantiate a base class (but only create the instance,
  14. // don't run the init constructor)
  15. initializing = true;
  16. var prototype = new this();
  17. initializing = false;
  18. // Copy the properties over onto the new prototype
  19. for (var name in prop) {
  20. // Check if we're overwriting an existing function
  21. prototype[name] = typeof prop[name] == "function" &&
  22. typeof _super[name] == "function" && fnTest.test(prop[name]) ?
  23. (function(name, fn){
  24. return function() {
  25. var tmp = this._super;
  26. // Add a new ._super() method that is the same method
  27. // but on the super-class
  28. this._super = _super[name];
  29. // The method only need to be bound temporarily, so we
  30. // remove it when we're done executing
  31. var ret = fn.apply(this, arguments);
  32. this._super = tmp;
  33. return ret;
  34. };
  35. })(name, prop[name]) :
  36. prop[name];
  37. }
  38. // The dummy class constructor
  39. function Class() {
  40. // All construction is actually done in the init method
  41. if ( !initializing && this.init )
  42. this.init.apply(this, arguments);
  43. }
  44. // Populate our constructed prototype object
  45. Class.prototype = prototype;
  46. // Enforce the constructor to be what we expect
  47. var func = new Function(
  48. "return function " + className + "(){ }"
  49. )();
  50. Class.prototype.constructor = func;
  51. // And make this class extendable
  52. Class.extend = arguments.callee;
  53. return Class;
  54. };
  55. //I only added this line
  56. module.exports = Class;
  57. })();
  58. },{}],2:[function(require,module,exports){
  59. // Underscore.js 1.8.3
  60. // http://underscorejs.org
  61. // (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  62. // Underscore may be freely distributed under the MIT license.
  63. (function() {
  64. // Baseline setup
  65. // --------------
  66. // Establish the root object, `window` in the browser, or `exports` on the server.
  67. var root = this;
  68. // Save the previous value of the `_` variable.
  69. var previousUnderscore = root._;
  70. // Save bytes in the minified (but not gzipped) version:
  71. var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
  72. // Create quick reference variables for speed access to core prototypes.
  73. var
  74. push = ArrayProto.push,
  75. slice = ArrayProto.slice,
  76. toString = ObjProto.toString,
  77. hasOwnProperty = ObjProto.hasOwnProperty;
  78. // All **ECMAScript 5** native function implementations that we hope to use
  79. // are declared here.
  80. var
  81. nativeIsArray = Array.isArray,
  82. nativeKeys = Object.keys,
  83. nativeBind = FuncProto.bind,
  84. nativeCreate = Object.create;
  85. // Naked function reference for surrogate-prototype-swapping.
  86. var Ctor = function(){};
  87. // Create a safe reference to the Underscore object for use below.
  88. var _ = function(obj) {
  89. if (obj instanceof _) return obj;
  90. if (!(this instanceof _)) return new _(obj);
  91. this._wrapped = obj;
  92. };
  93. // Export the Underscore object for **Node.js**, with
  94. // backwards-compatibility for the old `require()` API. If we're in
  95. // the browser, add `_` as a global object.
  96. if (typeof exports !== 'undefined') {
  97. if (typeof module !== 'undefined' && module.exports) {
  98. exports = module.exports = _;
  99. }
  100. exports._ = _;
  101. } else {
  102. root._ = _;
  103. }
  104. // Current version.
  105. _.VERSION = '1.8.3';
  106. // Internal function that returns an efficient (for current engines) version
  107. // of the passed-in callback, to be repeatedly applied in other Underscore
  108. // functions.
  109. var optimizeCb = function(func, context, argCount) {
  110. if (context === void 0) return func;
  111. switch (argCount == null ? 3 : argCount) {
  112. case 1: return function(value) {
  113. return func.call(context, value);
  114. };
  115. case 2: return function(value, other) {
  116. return func.call(context, value, other);
  117. };
  118. case 3: return function(value, index, collection) {
  119. return func.call(context, value, index, collection);
  120. };
  121. case 4: return function(accumulator, value, index, collection) {
  122. return func.call(context, accumulator, value, index, collection);
  123. };
  124. }
  125. return function() {
  126. return func.apply(context, arguments);
  127. };
  128. };
  129. // A mostly-internal function to generate callbacks that can be applied
  130. // to each element in a collection, returning the desired result — either
  131. // identity, an arbitrary callback, a property matcher, or a property accessor.
  132. var cb = function(value, context, argCount) {
  133. if (value == null) return _.identity;
  134. if (_.isFunction(value)) return optimizeCb(value, context, argCount);
  135. if (_.isObject(value)) return _.matcher(value);
  136. return _.property(value);
  137. };
  138. _.iteratee = function(value, context) {
  139. return cb(value, context, Infinity);
  140. };
  141. // An internal function for creating assigner functions.
  142. var createAssigner = function(keysFunc, undefinedOnly) {
  143. return function(obj) {
  144. var length = arguments.length;
  145. if (length < 2 || obj == null) return obj;
  146. for (var index = 1; index < length; index++) {
  147. var source = arguments[index],
  148. keys = keysFunc(source),
  149. l = keys.length;
  150. for (var i = 0; i < l; i++) {
  151. var key = keys[i];
  152. if (!undefinedOnly || obj[key] === void 0) obj[key] = source[key];
  153. }
  154. }
  155. return obj;
  156. };
  157. };
  158. // An internal function for creating a new object that inherits from another.
  159. var baseCreate = function(prototype) {
  160. if (!_.isObject(prototype)) return {};
  161. if (nativeCreate) return nativeCreate(prototype);
  162. Ctor.prototype = prototype;
  163. var result = new Ctor;
  164. Ctor.prototype = null;
  165. return result;
  166. };
  167. var property = function(key) {
  168. return function(obj) {
  169. return obj == null ? void 0 : obj[key];
  170. };
  171. };
  172. // Helper for collection methods to determine whether a collection
  173. // should be iterated as an array or as an object
  174. // Related: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
  175. // Avoids a very nasty iOS 8 JIT bug on ARM-64. #2094
  176. var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
  177. var getLength = property('length');
  178. var isArrayLike = function(collection) {
  179. var length = getLength(collection);
  180. return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX;
  181. };
  182. // Collection Functions
  183. // --------------------
  184. // The cornerstone, an `each` implementation, aka `forEach`.
  185. // Handles raw objects in addition to array-likes. Treats all
  186. // sparse array-likes as if they were dense.
  187. _.each = _.forEach = function(obj, iteratee, context) {
  188. iteratee = optimizeCb(iteratee, context);
  189. var i, length;
  190. if (isArrayLike(obj)) {
  191. for (i = 0, length = obj.length; i < length; i++) {
  192. iteratee(obj[i], i, obj);
  193. }
  194. } else {
  195. var keys = _.keys(obj);
  196. for (i = 0, length = keys.length; i < length; i++) {
  197. iteratee(obj[keys[i]], keys[i], obj);
  198. }
  199. }
  200. return obj;
  201. };
  202. // Return the results of applying the iteratee to each element.
  203. _.map = _.collect = function(obj, iteratee, context) {
  204. iteratee = cb(iteratee, context);
  205. var keys = !isArrayLike(obj) && _.keys(obj),
  206. length = (keys || obj).length,
  207. results = Array(length);
  208. for (var index = 0; index < length; index++) {
  209. var currentKey = keys ? keys[index] : index;
  210. results[index] = iteratee(obj[currentKey], currentKey, obj);
  211. }
  212. return results;
  213. };
  214. // Create a reducing function iterating left or right.
  215. function createReduce(dir) {
  216. // Optimized iterator function as using arguments.length
  217. // in the main function will deoptimize the, see #1991.
  218. function iterator(obj, iteratee, memo, keys, index, length) {
  219. for (; index >= 0 && index < length; index += dir) {
  220. var currentKey = keys ? keys[index] : index;
  221. memo = iteratee(memo, obj[currentKey], currentKey, obj);
  222. }
  223. return memo;
  224. }
  225. return function(obj, iteratee, memo, context) {
  226. iteratee = optimizeCb(iteratee, context, 4);
  227. var keys = !isArrayLike(obj) && _.keys(obj),
  228. length = (keys || obj).length,
  229. index = dir > 0 ? 0 : length - 1;
  230. // Determine the initial value if none is provided.
  231. if (arguments.length < 3) {
  232. memo = obj[keys ? keys[index] : index];
  233. index += dir;
  234. }
  235. return iterator(obj, iteratee, memo, keys, index, length);
  236. };
  237. }
  238. // **Reduce** builds up a single result from a list of values, aka `inject`,
  239. // or `foldl`.
  240. _.reduce = _.foldl = _.inject = createReduce(1);
  241. // The right-associative version of reduce, also known as `foldr`.
  242. _.reduceRight = _.foldr = createReduce(-1);
  243. // Return the first value which passes a truth test. Aliased as `detect`.
  244. _.find = _.detect = function(obj, predicate, context) {
  245. var key;
  246. if (isArrayLike(obj)) {
  247. key = _.findIndex(obj, predicate, context);
  248. } else {
  249. key = _.findKey(obj, predicate, context);
  250. }
  251. if (key !== void 0 && key !== -1) return obj[key];
  252. };
  253. // Return all the elements that pass a truth test.
  254. // Aliased as `select`.
  255. _.filter = _.select = function(obj, predicate, context) {
  256. var results = [];
  257. predicate = cb(predicate, context);
  258. _.each(obj, function(value, index, list) {
  259. if (predicate(value, index, list)) results.push(value);
  260. });
  261. return results;
  262. };
  263. // Return all the elements for which a truth test fails.
  264. _.reject = function(obj, predicate, context) {
  265. return _.filter(obj, _.negate(cb(predicate)), context);
  266. };
  267. // Determine whether all of the elements match a truth test.
  268. // Aliased as `all`.
  269. _.every = _.all = function(obj, predicate, context) {
  270. predicate = cb(predicate, context);
  271. var keys = !isArrayLike(obj) && _.keys(obj),
  272. length = (keys || obj).length;
  273. for (var index = 0; index < length; index++) {
  274. var currentKey = keys ? keys[index] : index;
  275. if (!predicate(obj[currentKey], currentKey, obj)) return false;
  276. }
  277. return true;
  278. };
  279. // Determine if at least one element in the object matches a truth test.
  280. // Aliased as `any`.
  281. _.some = _.any = function(obj, predicate, context) {
  282. predicate = cb(predicate, context);
  283. var keys = !isArrayLike(obj) && _.keys(obj),
  284. length = (keys || obj).length;
  285. for (var index = 0; index < length; index++) {
  286. var currentKey = keys ? keys[index] : index;
  287. if (predicate(obj[currentKey], currentKey, obj)) return true;
  288. }
  289. return false;
  290. };
  291. // Determine if the array or object contains a given item (using `===`).
  292. // Aliased as `includes` and `include`.
  293. _.contains = _.includes = _.include = function(obj, item, fromIndex, guard) {
  294. if (!isArrayLike(obj)) obj = _.values(obj);
  295. if (typeof fromIndex != 'number' || guard) fromIndex = 0;
  296. return _.indexOf(obj, item, fromIndex) >= 0;
  297. };
  298. // Invoke a method (with arguments) on every item in a collection.
  299. _.invoke = function(obj, method) {
  300. var args = slice.call(arguments, 2);
  301. var isFunc = _.isFunction(method);
  302. return _.map(obj, function(value) {
  303. var func = isFunc ? method : value[method];
  304. return func == null ? func : func.apply(value, args);
  305. });
  306. };
  307. // Convenience version of a common use case of `map`: fetching a property.
  308. _.pluck = function(obj, key) {
  309. return _.map(obj, _.property(key));
  310. };
  311. // Convenience version of a common use case of `filter`: selecting only objects
  312. // containing specific `key:value` pairs.
  313. _.where = function(obj, attrs) {
  314. return _.filter(obj, _.matcher(attrs));
  315. };
  316. // Convenience version of a common use case of `find`: getting the first object
  317. // containing specific `key:value` pairs.
  318. _.findWhere = function(obj, attrs) {
  319. return _.find(obj, _.matcher(attrs));
  320. };
  321. // Return the maximum element (or element-based computation).
  322. _.max = function(obj, iteratee, context) {
  323. var result = -Infinity, lastComputed = -Infinity,
  324. value, computed;
  325. if (iteratee == null && obj != null) {
  326. obj = isArrayLike(obj) ? obj : _.values(obj);
  327. for (var i = 0, length = obj.length; i < length; i++) {
  328. value = obj[i];
  329. if (value > result) {
  330. result = value;
  331. }
  332. }
  333. } else {
  334. iteratee = cb(iteratee, context);
  335. _.each(obj, function(value, index, list) {
  336. computed = iteratee(value, index, list);
  337. if (computed > lastComputed || computed === -Infinity && result === -Infinity) {
  338. result = value;
  339. lastComputed = computed;
  340. }
  341. });
  342. }
  343. return result;
  344. };
  345. // Return the minimum element (or element-based computation).
  346. _.min = function(obj, iteratee, context) {
  347. var result = Infinity, lastComputed = Infinity,
  348. value, computed;
  349. if (iteratee == null && obj != null) {
  350. obj = isArrayLike(obj) ? obj : _.values(obj);
  351. for (var i = 0, length = obj.length; i < length; i++) {
  352. value = obj[i];
  353. if (value < result) {
  354. result = value;
  355. }
  356. }
  357. } else {
  358. iteratee = cb(iteratee, context);
  359. _.each(obj, function(value, index, list) {
  360. computed = iteratee(value, index, list);
  361. if (computed < lastComputed || computed === Infinity && result === Infinity) {
  362. result = value;
  363. lastComputed = computed;
  364. }
  365. });
  366. }
  367. return result;
  368. };
  369. // Shuffle a collection, using the modern version of the
  370. // [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
  371. _.shuffle = function(obj) {
  372. var set = isArrayLike(obj) ? obj : _.values(obj);
  373. var length = set.length;
  374. var shuffled = Array(length);
  375. for (var index = 0, rand; index < length; index++) {
  376. rand = _.random(0, index);
  377. if (rand !== index) shuffled[index] = shuffled[rand];
  378. shuffled[rand] = set[index];
  379. }
  380. return shuffled;
  381. };
  382. // Sample **n** random values from a collection.
  383. // If **n** is not specified, returns a single random element.
  384. // The internal `guard` argument allows it to work with `map`.
  385. _.sample = function(obj, n, guard) {
  386. if (n == null || guard) {
  387. if (!isArrayLike(obj)) obj = _.values(obj);
  388. return obj[_.random(obj.length - 1)];
  389. }
  390. return _.shuffle(obj).slice(0, Math.max(0, n));
  391. };
  392. // Sort the object's values by a criterion produced by an iteratee.
  393. _.sortBy = function(obj, iteratee, context) {
  394. iteratee = cb(iteratee, context);
  395. return _.pluck(_.map(obj, function(value, index, list) {
  396. return {
  397. value: value,
  398. index: index,
  399. criteria: iteratee(value, index, list)
  400. };
  401. }).sort(function(left, right) {
  402. var a = left.criteria;
  403. var b = right.criteria;
  404. if (a !== b) {
  405. if (a > b || a === void 0) return 1;
  406. if (a < b || b === void 0) return -1;
  407. }
  408. return left.index - right.index;
  409. }), 'value');
  410. };
  411. // An internal function used for aggregate "group by" operations.
  412. var group = function(behavior) {
  413. return function(obj, iteratee, context) {
  414. var result = {};
  415. iteratee = cb(iteratee, context);
  416. _.each(obj, function(value, index) {
  417. var key = iteratee(value, index, obj);
  418. behavior(result, value, key);
  419. });
  420. return result;
  421. };
  422. };
  423. // Groups the object's values by a criterion. Pass either a string attribute
  424. // to group by, or a function that returns the criterion.
  425. _.groupBy = group(function(result, value, key) {
  426. if (_.has(result, key)) result[key].push(value); else result[key] = [value];
  427. });
  428. // Indexes the object's values by a criterion, similar to `groupBy`, but for
  429. // when you know that your index values will be unique.
  430. _.indexBy = group(function(result, value, key) {
  431. result[key] = value;
  432. });
  433. // Counts instances of an object that group by a certain criterion. Pass
  434. // either a string attribute to count by, or a function that returns the
  435. // criterion.
  436. _.countBy = group(function(result, value, key) {
  437. if (_.has(result, key)) result[key]++; else result[key] = 1;
  438. });
  439. // Safely create a real, live array from anything iterable.
  440. _.toArray = function(obj) {
  441. if (!obj) return [];
  442. if (_.isArray(obj)) return slice.call(obj);
  443. if (isArrayLike(obj)) return _.map(obj, _.identity);
  444. return _.values(obj);
  445. };
  446. // Return the number of elements in an object.
  447. _.size = function(obj) {
  448. if (obj == null) return 0;
  449. return isArrayLike(obj) ? obj.length : _.keys(obj).length;
  450. };
  451. // Split a collection into two arrays: one whose elements all satisfy the given
  452. // predicate, and one whose elements all do not satisfy the predicate.
  453. _.partition = function(obj, predicate, context) {
  454. predicate = cb(predicate, context);
  455. var pass = [], fail = [];
  456. _.each(obj, function(value, key, obj) {
  457. (predicate(value, key, obj) ? pass : fail).push(value);
  458. });
  459. return [pass, fail];
  460. };
  461. // Array Functions
  462. // ---------------
  463. // Get the first element of an array. Passing **n** will return the first N
  464. // values in the array. Aliased as `head` and `take`. The **guard** check
  465. // allows it to work with `_.map`.
  466. _.first = _.head = _.take = function(array, n, guard) {
  467. if (array == null) return void 0;
  468. if (n == null || guard) return array[0];
  469. return _.initial(array, array.length - n);
  470. };
  471. // Returns everything but the last entry of the array. Especially useful on
  472. // the arguments object. Passing **n** will return all the values in
  473. // the array, excluding the last N.
  474. _.initial = function(array, n, guard) {
  475. return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
  476. };
  477. // Get the last element of an array. Passing **n** will return the last N
  478. // values in the array.
  479. _.last = function(array, n, guard) {
  480. if (array == null) return void 0;
  481. if (n == null || guard) return array[array.length - 1];
  482. return _.rest(array, Math.max(0, array.length - n));
  483. };
  484. // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
  485. // Especially useful on the arguments object. Passing an **n** will return
  486. // the rest N values in the array.
  487. _.rest = _.tail = _.drop = function(array, n, guard) {
  488. return slice.call(array, n == null || guard ? 1 : n);
  489. };
  490. // Trim out all falsy values from an array.
  491. _.compact = function(array) {
  492. return _.filter(array, _.identity);
  493. };
  494. // Internal implementation of a recursive `flatten` function.
  495. var flatten = function(input, shallow, strict, startIndex) {
  496. var output = [], idx = 0;
  497. for (var i = startIndex || 0, length = getLength(input); i < length; i++) {
  498. var value = input[i];
  499. if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) {
  500. //flatten current level of array or arguments object
  501. if (!shallow) value = flatten(value, shallow, strict);
  502. var j = 0, len = value.length;
  503. output.length += len;
  504. while (j < len) {
  505. output[idx++] = value[j++];
  506. }
  507. } else if (!strict) {
  508. output[idx++] = value;
  509. }
  510. }
  511. return output;
  512. };
  513. // Flatten out an array, either recursively (by default), or just one level.
  514. _.flatten = function(array, shallow) {
  515. return flatten(array, shallow, false);
  516. };
  517. // Return a version of the array that does not contain the specified value(s).
  518. _.without = function(array) {
  519. return _.difference(array, slice.call(arguments, 1));
  520. };
  521. // Produce a duplicate-free version of the array. If the array has already
  522. // been sorted, you have the option of using a faster algorithm.
  523. // Aliased as `unique`.
  524. _.uniq = _.unique = function(array, isSorted, iteratee, context) {
  525. if (!_.isBoolean(isSorted)) {
  526. context = iteratee;
  527. iteratee = isSorted;
  528. isSorted = false;
  529. }
  530. if (iteratee != null) iteratee = cb(iteratee, context);
  531. var result = [];
  532. var seen = [];
  533. for (var i = 0, length = getLength(array); i < length; i++) {
  534. var value = array[i],
  535. computed = iteratee ? iteratee(value, i, array) : value;
  536. if (isSorted) {
  537. if (!i || seen !== computed) result.push(value);
  538. seen = computed;
  539. } else if (iteratee) {
  540. if (!_.contains(seen, computed)) {
  541. seen.push(computed);
  542. result.push(value);
  543. }
  544. } else if (!_.contains(result, value)) {
  545. result.push(value);
  546. }
  547. }
  548. return result;
  549. };
  550. // Produce an array that contains the union: each distinct element from all of
  551. // the passed-in arrays.
  552. _.union = function() {
  553. return _.uniq(flatten(arguments, true, true));
  554. };
  555. // Produce an array that contains every item shared between all the
  556. // passed-in arrays.
  557. _.intersection = function(array) {
  558. var result = [];
  559. var argsLength = arguments.length;
  560. for (var i = 0, length = getLength(array); i < length; i++) {
  561. var item = array[i];
  562. if (_.contains(result, item)) continue;
  563. for (var j = 1; j < argsLength; j++) {
  564. if (!_.contains(arguments[j], item)) break;
  565. }
  566. if (j === argsLength) result.push(item);
  567. }
  568. return result;
  569. };
  570. // Take the difference between one array and a number of other arrays.
  571. // Only the elements present in just the first array will remain.
  572. _.difference = function(array) {
  573. var rest = flatten(arguments, true, true, 1);
  574. return _.filter(array, function(value){
  575. return !_.contains(rest, value);
  576. });
  577. };
  578. // Zip together multiple lists into a single array -- elements that share
  579. // an index go together.
  580. _.zip = function() {
  581. return _.unzip(arguments);
  582. };
  583. // Complement of _.zip. Unzip accepts an array of arrays and groups
  584. // each array's elements on shared indices
  585. _.unzip = function(array) {
  586. var length = array && _.max(array, getLength).length || 0;
  587. var result = Array(length);
  588. for (var index = 0; index < length; index++) {
  589. result[index] = _.pluck(array, index);
  590. }
  591. return result;
  592. };
  593. // Converts lists into objects. Pass either a single array of `[key, value]`
  594. // pairs, or two parallel arrays of the same length -- one of keys, and one of
  595. // the corresponding values.
  596. _.object = function(list, values) {
  597. var result = {};
  598. for (var i = 0, length = getLength(list); i < length; i++) {
  599. if (values) {
  600. result[list[i]] = values[i];
  601. } else {
  602. result[list[i][0]] = list[i][1];
  603. }
  604. }
  605. return result;
  606. };
  607. // Generator function to create the findIndex and findLastIndex functions
  608. function createPredicateIndexFinder(dir) {
  609. return function(array, predicate, context) {
  610. predicate = cb(predicate, context);
  611. var length = getLength(array);
  612. var index = dir > 0 ? 0 : length - 1;
  613. for (; index >= 0 && index < length; index += dir) {
  614. if (predicate(array[index], index, array)) return index;
  615. }
  616. return -1;
  617. };
  618. }
  619. // Returns the first index on an array-like that passes a predicate test
  620. _.findIndex = createPredicateIndexFinder(1);
  621. _.findLastIndex = createPredicateIndexFinder(-1);
  622. // Use a comparator function to figure out the smallest index at which
  623. // an object should be inserted so as to maintain order. Uses binary search.
  624. _.sortedIndex = function(array, obj, iteratee, context) {
  625. iteratee = cb(iteratee, context, 1);
  626. var value = iteratee(obj);
  627. var low = 0, high = getLength(array);
  628. while (low < high) {
  629. var mid = Math.floor((low + high) / 2);
  630. if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
  631. }
  632. return low;
  633. };
  634. // Generator function to create the indexOf and lastIndexOf functions
  635. function createIndexFinder(dir, predicateFind, sortedIndex) {
  636. return function(array, item, idx) {
  637. var i = 0, length = getLength(array);
  638. if (typeof idx == 'number') {
  639. if (dir > 0) {
  640. i = idx >= 0 ? idx : Math.max(idx + length, i);
  641. } else {
  642. length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1;
  643. }
  644. } else if (sortedIndex && idx && length) {
  645. idx = sortedIndex(array, item);
  646. return array[idx] === item ? idx : -1;
  647. }
  648. if (item !== item) {
  649. idx = predicateFind(slice.call(array, i, length), _.isNaN);
  650. return idx >= 0 ? idx + i : -1;
  651. }
  652. for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) {
  653. if (array[idx] === item) return idx;
  654. }
  655. return -1;
  656. };
  657. }
  658. // Return the position of the first occurrence of an item in an array,
  659. // or -1 if the item is not included in the array.
  660. // If the array is large and already in sort order, pass `true`
  661. // for **isSorted** to use binary search.
  662. _.indexOf = createIndexFinder(1, _.findIndex, _.sortedIndex);
  663. _.lastIndexOf = createIndexFinder(-1, _.findLastIndex);
  664. // Generate an integer Array containing an arithmetic progression. A port of
  665. // the native Python `range()` function. See
  666. // [the Python documentation](http://docs.python.org/library/functions.html#range).
  667. _.range = function(start, stop, step) {
  668. if (stop == null) {
  669. stop = start || 0;
  670. start = 0;
  671. }
  672. step = step || 1;
  673. var length = Math.max(Math.ceil((stop - start) / step), 0);
  674. var range = Array(length);
  675. for (var idx = 0; idx < length; idx++, start += step) {
  676. range[idx] = start;
  677. }
  678. return range;
  679. };
  680. // Function (ahem) Functions
  681. // ------------------
  682. // Determines whether to execute a function as a constructor
  683. // or a normal function with the provided arguments
  684. var executeBound = function(sourceFunc, boundFunc, context, callingContext, args) {
  685. if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
  686. var self = baseCreate(sourceFunc.prototype);
  687. var result = sourceFunc.apply(self, args);
  688. if (_.isObject(result)) return result;
  689. return self;
  690. };
  691. // Create a function bound to a given object (assigning `this`, and arguments,
  692. // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
  693. // available.
  694. _.bind = function(func, context) {
  695. if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
  696. if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function');
  697. var args = slice.call(arguments, 2);
  698. var bound = function() {
  699. return executeBound(func, bound, context, this, args.concat(slice.call(arguments)));
  700. };
  701. return bound;
  702. };
  703. // Partially apply a function by creating a version that has had some of its
  704. // arguments pre-filled, without changing its dynamic `this` context. _ acts
  705. // as a placeholder, allowing any combination of arguments to be pre-filled.
  706. _.partial = function(func) {
  707. var boundArgs = slice.call(arguments, 1);
  708. var bound = function() {
  709. var position = 0, length = boundArgs.length;
  710. var args = Array(length);
  711. for (var i = 0; i < length; i++) {
  712. args[i] = boundArgs[i] === _ ? arguments[position++] : boundArgs[i];
  713. }
  714. while (position < arguments.length) args.push(arguments[position++]);
  715. return executeBound(func, bound, this, this, args);
  716. };
  717. return bound;
  718. };
  719. // Bind a number of an object's methods to that object. Remaining arguments
  720. // are the method names to be bound. Useful for ensuring that all callbacks
  721. // defined on an object belong to it.
  722. _.bindAll = function(obj) {
  723. var i, length = arguments.length, key;
  724. if (length <= 1) throw new Error('bindAll must be passed function names');
  725. for (i = 1; i < length; i++) {
  726. key = arguments[i];
  727. obj[key] = _.bind(obj[key], obj);
  728. }
  729. return obj;
  730. };
  731. // Memoize an expensive function by storing its results.
  732. _.memoize = function(func, hasher) {
  733. var memoize = function(key) {
  734. var cache = memoize.cache;
  735. var address = '' + (hasher ? hasher.apply(this, arguments) : key);
  736. if (!_.has(cache, address)) cache[address] = func.apply(this, arguments);
  737. return cache[address];
  738. };
  739. memoize.cache = {};
  740. return memoize;
  741. };
  742. // Delays a function for the given number of milliseconds, and then calls
  743. // it with the arguments supplied.
  744. _.delay = function(func, wait) {
  745. var args = slice.call(arguments, 2);
  746. return setTimeout(function(){
  747. return func.apply(null, args);
  748. }, wait);
  749. };
  750. // Defers a function, scheduling it to run after the current call stack has
  751. // cleared.
  752. _.defer = _.partial(_.delay, _, 1);
  753. // Returns a function, that, when invoked, will only be triggered at most once
  754. // during a given window of time. Normally, the throttled function will run
  755. // as much as it can, without ever going more than once per `wait` duration;
  756. // but if you'd like to disable the execution on the leading edge, pass
  757. // `{leading: false}`. To disable execution on the trailing edge, ditto.
  758. _.throttle = function(func, wait, options) {
  759. var context, args, result;
  760. var timeout = null;
  761. var previous = 0;
  762. if (!options) options = {};
  763. var later = function() {
  764. previous = options.leading === false ? 0 : _.now();
  765. timeout = null;
  766. result = func.apply(context, args);
  767. if (!timeout) context = args = null;
  768. };
  769. return function() {
  770. var now = _.now();
  771. if (!previous && options.leading === false) previous = now;
  772. var remaining = wait - (now - previous);
  773. context = this;
  774. args = arguments;
  775. if (remaining <= 0 || remaining > wait) {
  776. if (timeout) {
  777. clearTimeout(timeout);
  778. timeout = null;
  779. }
  780. previous = now;
  781. result = func.apply(context, args);
  782. if (!timeout) context = args = null;
  783. } else if (!timeout && options.trailing !== false) {
  784. timeout = setTimeout(later, remaining);
  785. }
  786. return result;
  787. };
  788. };
  789. // Returns a function, that, as long as it continues to be invoked, will not
  790. // be triggered. The function will be called after it stops being called for
  791. // N milliseconds. If `immediate` is passed, trigger the function on the
  792. // leading edge, instead of the trailing.
  793. _.debounce = function(func, wait, immediate) {
  794. var timeout, args, context, timestamp, result;
  795. var later = function() {
  796. var last = _.now() - timestamp;
  797. if (last < wait && last >= 0) {
  798. timeout = setTimeout(later, wait - last);
  799. } else {
  800. timeout = null;
  801. if (!immediate) {
  802. result = func.apply(context, args);
  803. if (!timeout) context = args = null;
  804. }
  805. }
  806. };
  807. return function() {
  808. context = this;
  809. args = arguments;
  810. timestamp = _.now();
  811. var callNow = immediate && !timeout;
  812. if (!timeout) timeout = setTimeout(later, wait);
  813. if (callNow) {
  814. result = func.apply(context, args);
  815. context = args = null;
  816. }
  817. return result;
  818. };
  819. };
  820. // Returns the first function passed as an argument to the second,
  821. // allowing you to adjust arguments, run code before and after, and
  822. // conditionally execute the original function.
  823. _.wrap = function(func, wrapper) {
  824. return _.partial(wrapper, func);
  825. };
  826. // Returns a negated version of the passed-in predicate.
  827. _.negate = function(predicate) {
  828. return function() {
  829. return !predicate.apply(this, arguments);
  830. };
  831. };
  832. // Returns a function that is the composition of a list of functions, each
  833. // consuming the return value of the function that follows.
  834. _.compose = function() {
  835. var args = arguments;
  836. var start = args.length - 1;
  837. return function() {
  838. var i = start;
  839. var result = args[start].apply(this, arguments);
  840. while (i--) result = args[i].call(this, result);
  841. return result;
  842. };
  843. };
  844. // Returns a function that will only be executed on and after the Nth call.
  845. _.after = function(times, func) {
  846. return function() {
  847. if (--times < 1) {
  848. return func.apply(this, arguments);
  849. }
  850. };
  851. };
  852. // Returns a function that will only be executed up to (but not including) the Nth call.
  853. _.before = function(times, func) {
  854. var memo;
  855. return function() {
  856. if (--times > 0) {
  857. memo = func.apply(this, arguments);
  858. }
  859. if (times <= 1) func = null;
  860. return memo;
  861. };
  862. };
  863. // Returns a function that will be executed at most one time, no matter how
  864. // often you call it. Useful for lazy initialization.
  865. _.once = _.partial(_.before, 2);
  866. // Object Functions
  867. // ----------------
  868. // Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
  869. var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
  870. var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
  871. 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
  872. function collectNonEnumProps(obj, keys) {
  873. var nonEnumIdx = nonEnumerableProps.length;
  874. var constructor = obj.constructor;
  875. var proto = (_.isFunction(constructor) && constructor.prototype) || ObjProto;
  876. // Constructor is a special case.
  877. var prop = 'constructor';
  878. if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop);
  879. while (nonEnumIdx--) {
  880. prop = nonEnumerableProps[nonEnumIdx];
  881. if (prop in obj && obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
  882. keys.push(prop);
  883. }
  884. }
  885. }
  886. // Retrieve the names of an object's own properties.
  887. // Delegates to **ECMAScript 5**'s native `Object.keys`
  888. _.keys = function(obj) {
  889. if (!_.isObject(obj)) return [];
  890. if (nativeKeys) return nativeKeys(obj);
  891. var keys = [];
  892. for (var key in obj) if (_.has(obj, key)) keys.push(key);
  893. // Ahem, IE < 9.
  894. if (hasEnumBug) collectNonEnumProps(obj, keys);
  895. return keys;
  896. };
  897. // Retrieve all the property names of an object.
  898. _.allKeys = function(obj) {
  899. if (!_.isObject(obj)) return [];
  900. var keys = [];
  901. for (var key in obj) keys.push(key);
  902. // Ahem, IE < 9.
  903. if (hasEnumBug) collectNonEnumProps(obj, keys);
  904. return keys;
  905. };
  906. // Retrieve the values of an object's properties.
  907. _.values = function(obj) {
  908. var keys = _.keys(obj);
  909. var length = keys.length;
  910. var values = Array(length);
  911. for (var i = 0; i < length; i++) {
  912. values[i] = obj[keys[i]];
  913. }
  914. return values;
  915. };
  916. // Returns the results of applying the iteratee to each element of the object
  917. // In contrast to _.map it returns an object
  918. _.mapObject = function(obj, iteratee, context) {
  919. iteratee = cb(iteratee, context);
  920. var keys = _.keys(obj),
  921. length = keys.length,
  922. results = {},
  923. currentKey;
  924. for (var index = 0; index < length; index++) {
  925. currentKey = keys[index];
  926. results[currentKey] = iteratee(obj[currentKey], currentKey, obj);
  927. }
  928. return results;
  929. };
  930. // Convert an object into a list of `[key, value]` pairs.
  931. _.pairs = function(obj) {
  932. var keys = _.keys(obj);
  933. var length = keys.length;
  934. var pairs = Array(length);
  935. for (var i = 0; i < length; i++) {
  936. pairs[i] = [keys[i], obj[keys[i]]];
  937. }
  938. return pairs;
  939. };
  940. // Invert the keys and values of an object. The values must be serializable.
  941. _.invert = function(obj) {
  942. var result = {};
  943. var keys = _.keys(obj);
  944. for (var i = 0, length = keys.length; i < length; i++) {
  945. result[obj[keys[i]]] = keys[i];
  946. }
  947. return result;
  948. };
  949. // Return a sorted list of the function names available on the object.
  950. // Aliased as `methods`
  951. _.functions = _.methods = function(obj) {
  952. var names = [];
  953. for (var key in obj) {
  954. if (_.isFunction(obj[key])) names.push(key);
  955. }
  956. return names.sort();
  957. };
  958. // Extend a given object with all the properties in passed-in object(s).
  959. _.extend = createAssigner(_.allKeys);
  960. // Assigns a given object with all the own properties in the passed-in object(s)
  961. // (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
  962. _.extendOwn = _.assign = createAssigner(_.keys);
  963. // Returns the first key on an object that passes a predicate test
  964. _.findKey = function(obj, predicate, context) {
  965. predicate = cb(predicate, context);
  966. var keys = _.keys(obj), key;
  967. for (var i = 0, length = keys.length; i < length; i++) {
  968. key = keys[i];
  969. if (predicate(obj[key], key, obj)) return key;
  970. }
  971. };
  972. // Return a copy of the object only containing the whitelisted properties.
  973. _.pick = function(object, oiteratee, context) {
  974. var result = {}, obj = object, iteratee, keys;
  975. if (obj == null) return result;
  976. if (_.isFunction(oiteratee)) {
  977. keys = _.allKeys(obj);
  978. iteratee = optimizeCb(oiteratee, context);
  979. } else {
  980. keys = flatten(arguments, false, false, 1);
  981. iteratee = function(value, key, obj) { return key in obj; };
  982. obj = Object(obj);
  983. }
  984. for (var i = 0, length = keys.length; i < length; i++) {
  985. var key = keys[i];
  986. var value = obj[key];
  987. if (iteratee(value, key, obj)) result[key] = value;
  988. }
  989. return result;
  990. };
  991. // Return a copy of the object without the blacklisted properties.
  992. _.omit = function(obj, iteratee, context) {
  993. if (_.isFunction(iteratee)) {
  994. iteratee = _.negate(iteratee);
  995. } else {
  996. var keys = _.map(flatten(arguments, false, false, 1), String);
  997. iteratee = function(value, key) {
  998. return !_.contains(keys, key);
  999. };
  1000. }
  1001. return _.pick(obj, iteratee, context);
  1002. };
  1003. // Fill in a given object with default properties.
  1004. _.defaults = createAssigner(_.allKeys, true);
  1005. // Creates an object that inherits from the given prototype object.
  1006. // If additional properties are provided then they will be added to the
  1007. // created object.
  1008. _.create = function(prototype, props) {
  1009. var result = baseCreate(prototype);
  1010. if (props) _.extendOwn(result, props);
  1011. return result;
  1012. };
  1013. // Create a (shallow-cloned) duplicate of an object.
  1014. _.clone = function(obj) {
  1015. if (!_.isObject(obj)) return obj;
  1016. return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
  1017. };
  1018. // Invokes interceptor with the obj, and then returns obj.
  1019. // The primary purpose of this method is to "tap into" a method chain, in
  1020. // order to perform operations on intermediate results within the chain.
  1021. _.tap = function(obj, interceptor) {
  1022. interceptor(obj);
  1023. return obj;
  1024. };
  1025. // Returns whether an object has a given set of `key:value` pairs.
  1026. _.isMatch = function(object, attrs) {
  1027. var keys = _.keys(attrs), length = keys.length;
  1028. if (object == null) return !length;
  1029. var obj = Object(object);
  1030. for (var i = 0; i < length; i++) {
  1031. var key = keys[i];
  1032. if (attrs[key] !== obj[key] || !(key in obj)) return false;
  1033. }
  1034. return true;
  1035. };
  1036. // Internal recursive comparison function for `isEqual`.
  1037. var eq = function(a, b, aStack, bStack) {
  1038. // Identical objects are equal. `0 === -0`, but they aren't identical.
  1039. // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
  1040. if (a === b) return a !== 0 || 1 / a === 1 / b;
  1041. // A strict comparison is necessary because `null == undefined`.
  1042. if (a == null || b == null) return a === b;
  1043. // Unwrap any wrapped objects.
  1044. if (a instanceof _) a = a._wrapped;
  1045. if (b instanceof _) b = b._wrapped;
  1046. // Compare `[[Class]]` names.
  1047. var className = toString.call(a);
  1048. if (className !== toString.call(b)) return false;
  1049. switch (className) {
  1050. // Strings, numbers, regular expressions, dates, and booleans are compared by value.
  1051. case '[object RegExp]':
  1052. // RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
  1053. case '[object String]':
  1054. // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
  1055. // equivalent to `new String("5")`.
  1056. return '' + a === '' + b;
  1057. case '[object Number]':
  1058. // `NaN`s are equivalent, but non-reflexive.
  1059. // Object(NaN) is equivalent to NaN
  1060. if (+a !== +a) return +b !== +b;
  1061. // An `egal` comparison is performed for other numeric values.
  1062. return +a === 0 ? 1 / +a === 1 / b : +a === +b;
  1063. case '[object Date]':
  1064. case '[object Boolean]':
  1065. // Coerce dates and booleans to numeric primitive values. Dates are compared by their
  1066. // millisecond representations. Note that invalid dates with millisecond representations
  1067. // of `NaN` are not equivalent.
  1068. return +a === +b;
  1069. }
  1070. var areArrays = className === '[object Array]';
  1071. if (!areArrays) {
  1072. if (typeof a != 'object' || typeof b != 'object') return false;
  1073. // Objects with different constructors are not equivalent, but `Object`s or `Array`s
  1074. // from different frames are.
  1075. var aCtor = a.constructor, bCtor = b.constructor;
  1076. if (aCtor !== bCtor && !(_.isFunction(aCtor) && aCtor instanceof aCtor &&
  1077. _.isFunction(bCtor) && bCtor instanceof bCtor)
  1078. && ('constructor' in a && 'constructor' in b)) {
  1079. return false;
  1080. }
  1081. }
  1082. // Assume equality for cyclic structures. The algorithm for detecting cyclic
  1083. // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
  1084. // Initializing stack of traversed objects.
  1085. // It's done here since we only need them for objects and arrays comparison.
  1086. aStack = aStack || [];
  1087. bStack = bStack || [];
  1088. var length = aStack.length;
  1089. while (length--) {
  1090. // Linear search. Performance is inversely proportional to the number of
  1091. // unique nested structures.
  1092. if (aStack[length] === a) return bStack[length] === b;
  1093. }
  1094. // Add the first object to the stack of traversed objects.
  1095. aStack.push(a);
  1096. bStack.push(b);
  1097. // Recursively compare objects and arrays.
  1098. if (areArrays) {
  1099. // Compare array lengths to determine if a deep comparison is necessary.
  1100. length = a.length;
  1101. if (length !== b.length) return false;
  1102. // Deep compare the contents, ignoring non-numeric properties.
  1103. while (length--) {
  1104. if (!eq(a[length], b[length], aStack, bStack)) return false;
  1105. }
  1106. } else {
  1107. // Deep compare objects.
  1108. var keys = _.keys(a), key;
  1109. length = keys.length;
  1110. // Ensure that both objects contain the same number of properties before comparing deep equality.
  1111. if (_.keys(b).length !== length) return false;
  1112. while (length--) {
  1113. // Deep compare each member
  1114. key = keys[length];
  1115. if (!(_.has(b, key) && eq(a[key], b[key], aStack, bStack))) return false;
  1116. }
  1117. }
  1118. // Remove the first object from the stack of traversed objects.
  1119. aStack.pop();
  1120. bStack.pop();
  1121. return true;
  1122. };
  1123. // Perform a deep comparison to check if two objects are equal.
  1124. _.isEqual = function(a, b) {
  1125. return eq(a, b);
  1126. };
  1127. // Is a given array, string, or object empty?
  1128. // An "empty" object has no enumerable own-properties.
  1129. _.isEmpty = function(obj) {
  1130. if (obj == null) return true;
  1131. if (isArrayLike(obj) && (_.isArray(obj) || _.isString(obj) || _.isArguments(obj))) return obj.length === 0;
  1132. return _.keys(obj).length === 0;
  1133. };
  1134. // Is a given value a DOM element?
  1135. _.isElement = function(obj) {
  1136. return !!(obj && obj.nodeType === 1);
  1137. };
  1138. // Is a given value an array?
  1139. // Delegates to ECMA5's native Array.isArray
  1140. _.isArray = nativeIsArray || function(obj) {
  1141. return toString.call(obj) === '[object Array]';
  1142. };
  1143. // Is a given variable an object?
  1144. _.isObject = function(obj) {
  1145. var type = typeof obj;
  1146. return type === 'function' || type === 'object' && !!obj;
  1147. };
  1148. // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError.
  1149. _.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'], function(name) {
  1150. _['is' + name] = function(obj) {
  1151. return toString.call(obj) === '[object ' + name + ']';
  1152. };
  1153. });
  1154. // Define a fallback version of the method in browsers (ahem, IE < 9), where
  1155. // there isn't any inspectable "Arguments" type.
  1156. if (!_.isArguments(arguments)) {
  1157. _.isArguments = function(obj) {
  1158. return _.has(obj, 'callee');
  1159. };
  1160. }
  1161. // Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8,
  1162. // IE 11 (#1621), and in Safari 8 (#1929).
  1163. if (typeof /./ != 'function' && typeof Int8Array != 'object') {
  1164. _.isFunction = function(obj) {
  1165. return typeof obj == 'function' || false;
  1166. };
  1167. }
  1168. // Is a given object a finite number?
  1169. _.isFinite = function(obj) {
  1170. return isFinite(obj) && !isNaN(parseFloat(obj));
  1171. };
  1172. // Is the given value `NaN`? (NaN is the only number which does not equal itself).
  1173. _.isNaN = function(obj) {
  1174. return _.isNumber(obj) && obj !== +obj;
  1175. };
  1176. // Is a given value a boolean?
  1177. _.isBoolean = function(obj) {
  1178. return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
  1179. };
  1180. // Is a given value equal to null?
  1181. _.isNull = function(obj) {
  1182. return obj === null;
  1183. };
  1184. // Is a given variable undefined?
  1185. _.isUndefined = function(obj) {
  1186. return obj === void 0;
  1187. };
  1188. // Shortcut function for checking if an object has a given property directly
  1189. // on itself (in other words, not on a prototype).
  1190. _.has = function(obj, key) {
  1191. return obj != null && hasOwnProperty.call(obj, key);
  1192. };
  1193. // Utility Functions
  1194. // -----------------
  1195. // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
  1196. // previous owner. Returns a reference to the Underscore object.
  1197. _.noConflict = function() {
  1198. root._ = previousUnderscore;
  1199. return this;
  1200. };
  1201. // Keep the identity function around for default iteratees.
  1202. _.identity = function(value) {
  1203. return value;
  1204. };
  1205. // Predicate-generating functions. Often useful outside of Underscore.
  1206. _.constant = function(value) {
  1207. return function() {
  1208. return value;
  1209. };
  1210. };
  1211. _.noop = function(){};
  1212. _.property = property;
  1213. // Generates a function for a given object that returns a given property.
  1214. _.propertyOf = function(obj) {
  1215. return obj == null ? function(){} : function(key) {
  1216. return obj[key];
  1217. };
  1218. };
  1219. // Returns a predicate for checking whether an object has a given set of
  1220. // `key:value` pairs.
  1221. _.matcher = _.matches = function(attrs) {
  1222. attrs = _.extendOwn({}, attrs);
  1223. return function(obj) {
  1224. return _.isMatch(obj, attrs);
  1225. };
  1226. };
  1227. // Run a function **n** times.
  1228. _.times = function(n, iteratee, context) {
  1229. var accum = Array(Math.max(0, n));
  1230. iteratee = optimizeCb(iteratee, context, 1);
  1231. for (var i = 0; i < n; i++) accum[i] = iteratee(i);
  1232. return accum;
  1233. };
  1234. // Return a random integer between min and max (inclusive).
  1235. _.random = function(min, max) {
  1236. if (max == null) {
  1237. max = min;
  1238. min = 0;
  1239. }
  1240. return min + Math.floor(Math.random() * (max - min + 1));
  1241. };
  1242. // A (possibly faster) way to get the current timestamp as an integer.
  1243. _.now = Date.now || function() {
  1244. return new Date().getTime();
  1245. };
  1246. // List of HTML entities for escaping.
  1247. var escapeMap = {
  1248. '&': '&amp;',
  1249. '<': '&lt;',
  1250. '>': '&gt;',
  1251. '"': '&quot;',
  1252. "'": '&#x27;',
  1253. '`': '&#x60;'
  1254. };
  1255. var unescapeMap = _.invert(escapeMap);
  1256. // Functions for escaping and unescaping strings to/from HTML interpolation.
  1257. var createEscaper = function(map) {
  1258. var escaper = function(match) {
  1259. return map[match];
  1260. };
  1261. // Regexes for identifying a key that needs to be escaped
  1262. var source = '(?:' + _.keys(map).join('|') + ')';
  1263. var testRegexp = RegExp(source);
  1264. var replaceRegexp = RegExp(source, 'g');
  1265. return function(string) {
  1266. string = string == null ? '' : '' + string;
  1267. return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
  1268. };
  1269. };
  1270. _.escape = createEscaper(escapeMap);
  1271. _.unescape = createEscaper(unescapeMap);
  1272. // If the value of the named `property` is a function then invoke it with the
  1273. // `object` as context; otherwise, return it.
  1274. _.result = function(object, property, fallback) {
  1275. var value = object == null ? void 0 : object[property];
  1276. if (value === void 0) {
  1277. value = fallback;
  1278. }
  1279. return _.isFunction(value) ? value.call(object) : value;
  1280. };
  1281. // Generate a unique integer id (unique within the entire client session).
  1282. // Useful for temporary DOM ids.
  1283. var idCounter = 0;
  1284. _.uniqueId = function(prefix) {
  1285. var id = ++idCounter + '';
  1286. return prefix ? prefix + id : id;
  1287. };
  1288. // By default, Underscore uses ERB-style template delimiters, change the
  1289. // following template settings to use alternative delimiters.
  1290. _.templateSettings = {
  1291. evaluate : /<%([\s\S]+?)%>/g,
  1292. interpolate : /<%=([\s\S]+?)%>/g,
  1293. escape : /<%-([\s\S]+?)%>/g
  1294. };
  1295. // When customizing `templateSettings`, if you don't want to define an
  1296. // interpolation, evaluation or escaping regex, we need one that is
  1297. // guaranteed not to match.
  1298. var noMatch = /(.)^/;
  1299. // Certain characters need to be escaped so that they can be put into a
  1300. // string literal.
  1301. var escapes = {
  1302. "'": "'",
  1303. '\\': '\\',
  1304. '\r': 'r',
  1305. '\n': 'n',
  1306. '\u2028': 'u2028',
  1307. '\u2029': 'u2029'
  1308. };
  1309. var escaper = /\\|'|\r|\n|\u2028|\u2029/g;
  1310. var escapeChar = function(match) {
  1311. return '\\' + escapes[match];
  1312. };
  1313. // JavaScript micro-templating, similar to John Resig's implementation.
  1314. // Underscore templating handles arbitrary delimiters, preserves whitespace,
  1315. // and correctly escapes quotes within interpolated code.
  1316. // NB: `oldSettings` only exists for backwards compatibility.
  1317. _.template = function(text, settings, oldSettings) {
  1318. if (!settings && oldSettings) settings = oldSettings;
  1319. settings = _.defaults({}, settings, _.templateSettings);
  1320. // Combine delimiters into one regular expression via alternation.
  1321. var matcher = RegExp([
  1322. (settings.escape || noMatch).source,
  1323. (settings.interpolate || noMatch).source,
  1324. (settings.evaluate || noMatch).source
  1325. ].join('|') + '|$', 'g');
  1326. // Compile the template source, escaping string literals appropriately.
  1327. var index = 0;
  1328. var source = "__p+='";
  1329. text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
  1330. source += text.slice(index, offset).replace(escaper, escapeChar);
  1331. index = offset + match.length;
  1332. if (escape) {
  1333. source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
  1334. } else if (interpolate) {
  1335. source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
  1336. } else if (evaluate) {
  1337. source += "';\n" + evaluate + "\n__p+='";
  1338. }
  1339. // Adobe VMs need the match returned to produce the correct offest.
  1340. return match;
  1341. });
  1342. source += "';\n";
  1343. // If a variable is not specified, place data values in local scope.
  1344. if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
  1345. source = "var __t,__p='',__j=Array.prototype.join," +
  1346. "print=function(){__p+=__j.call(arguments,'');};\n" +
  1347. source + 'return __p;\n';
  1348. try {
  1349. var render = new Function(settings.variable || 'obj', '_', source);
  1350. } catch (e) {
  1351. e.source = source;
  1352. throw e;
  1353. }
  1354. var template = function(data) {
  1355. return render.call(this, data, _);
  1356. };
  1357. // Provide the compiled source as a convenience for precompilation.
  1358. var argument = settings.variable || 'obj';
  1359. template.source = 'function(' + argument + '){\n' + source + '}';
  1360. return template;
  1361. };
  1362. // Add a "chain" function. Start chaining a wrapped Underscore object.
  1363. _.chain = function(obj) {
  1364. var instance = _(obj);
  1365. instance._chain = true;
  1366. return instance;
  1367. };
  1368. // OOP
  1369. // ---------------
  1370. // If Underscore is called as a function, it returns a wrapped object that
  1371. // can be used OO-style. This wrapper holds altered versions of all the
  1372. // underscore functions. Wrapped objects may be chained.
  1373. // Helper function to continue chaining intermediate results.
  1374. var result = function(instance, obj) {
  1375. return instance._chain ? _(obj).chain() : obj;
  1376. };
  1377. // Add your own custom functions to the Underscore object.
  1378. _.mixin = function(obj) {
  1379. _.each(_.functions(obj), function(name) {
  1380. var func = _[name] = obj[name];
  1381. _.prototype[name] = function() {
  1382. var args = [this._wrapped];
  1383. push.apply(args, arguments);
  1384. return result(this, func.apply(_, args));
  1385. };
  1386. });
  1387. };
  1388. // Add all of the Underscore functions to the wrapper object.
  1389. _.mixin(_);
  1390. // Add all mutator Array functions to the wrapper.
  1391. _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
  1392. var method = ArrayProto[name];
  1393. _.prototype[name] = function() {
  1394. var obj = this._wrapped;
  1395. method.apply(obj, arguments);
  1396. if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
  1397. return result(this, obj);
  1398. };
  1399. });
  1400. // Add all accessor Array functions to the wrapper.
  1401. _.each(['concat', 'join', 'slice'], function(name) {
  1402. var method = ArrayProto[name];
  1403. _.prototype[name] = function() {
  1404. return result(this, method.apply(this._wrapped, arguments));
  1405. };
  1406. });
  1407. // Extracts the result from a wrapped and chained object.
  1408. _.prototype.value = function() {
  1409. return this._wrapped;
  1410. };
  1411. // Provide unwrapping proxy for some methods used in engine operations
  1412. // such as arithmetic and JSON stringification.
  1413. _.prototype.valueOf = _.prototype.toJSON = _.prototype.value;
  1414. _.prototype.toString = function() {
  1415. return '' + this._wrapped;
  1416. };
  1417. // AMD registration happens at the end for compatibility with AMD loaders
  1418. // that may not enforce next-turn semantics on modules. Even though general
  1419. // practice for AMD registration is to be anonymous, underscore registers
  1420. // as a named module because, like jQuery, it is a base library that is
  1421. // popular enough to be bundled in a third party lib, but not be part of
  1422. // an AMD load request. Those cases could generate an error when an
  1423. // anonymous define() is called outside of a loader request.
  1424. if (typeof define === 'function' && define.amd) {
  1425. define('underscore', [], function() {
  1426. return _;
  1427. });
  1428. }
  1429. }.call(this));
  1430. },{}],3:[function(require,module,exports){
  1431. 'use strict';
  1432. var _ = require('underscore'),
  1433. events = require('../events');
  1434. module.exports = function(videojs) {
  1435. var MenuItem = videojs.getComponent('MenuItem');
  1436. /**
  1437. * A MenuItem to represent a video resolution
  1438. *
  1439. * @class QualityOption
  1440. * @extends videojs.MenuItem
  1441. */
  1442. return videojs.extend(MenuItem, {
  1443. /**
  1444. * @inheritdoc
  1445. */
  1446. constructor: function(player, options) {
  1447. var source = options.source;
  1448. if (!_.isObject(source)) {
  1449. throw new Error('was not provided a "source" object, but rather: ' + (typeof source));
  1450. }
  1451. options = _.extend({
  1452. selectable: true,
  1453. label: source.label,
  1454. }, options);
  1455. MenuItem.call(this, player, options);
  1456. this.source = source;
  1457. },
  1458. /**
  1459. * @inheritdoc
  1460. */
  1461. handleClick: function(event) {
  1462. MenuItem.prototype.handleClick.call(this, event);
  1463. this.player().trigger(events.QUALITY_REQUESTED, this.source);
  1464. },
  1465. });
  1466. };
  1467. },{"../events":5,"underscore":2}],4:[function(require,module,exports){
  1468. 'use strict';
  1469. var _ = require('underscore'),
  1470. events = require('../events'),
  1471. qualityOptionFactory = require('./QualityOption'),
  1472. QUALITY_CHANGE_CLASS = 'vjs-quality-changing';
  1473. module.exports = function(videojs) {
  1474. var MenuButton = videojs.getComponent('MenuButton'),
  1475. QualityOption = qualityOptionFactory(videojs),
  1476. QualitySelector;
  1477. /**
  1478. * A component for changing video resolutions
  1479. *
  1480. * @class QualitySelector
  1481. * @extends videojs.Button
  1482. */
  1483. QualitySelector = videojs.extend(MenuButton, {
  1484. /**
  1485. * @inheritdoc
  1486. */
  1487. constructor: function(player, options) {
  1488. MenuButton.call(this, player, options);
  1489. // Update interface instantly so the user's change is acknowledged
  1490. player.on(events.QUALITY_REQUESTED, function(event, newSource) {
  1491. this.setSelectedSource(newSource);
  1492. player.addClass(QUALITY_CHANGE_CLASS);
  1493. player.one('loadeddata', function() {
  1494. player.removeClass(QUALITY_CHANGE_CLASS);
  1495. });
  1496. }.bind(this));
  1497. player.on(events.QUALITY_SELECTED, function(event, newSource) {
  1498. // Update the selected source with the source that was actually selected
  1499. this.setSelectedSource(newSource);
  1500. }.bind(this));
  1501. // Since it's possible for the player to get a source before the selector is
  1502. // created, make sure to update once we get a "ready" signal.
  1503. player.one('ready', function() {
  1504. this.selectedSrc = player.src();
  1505. this.update();
  1506. }.bind(this));
  1507. this.controlText('Open quality selector menu');
  1508. },
  1509. /**
  1510. * Updates the source that is selected in the menu
  1511. *
  1512. * @param source {object} player source to display as selected
  1513. */
  1514. setSelectedSource: function(source) {
  1515. var src = (source ? source.src : undefined);
  1516. if (this.selectedSrc !== src) {
  1517. this.selectedSrc = src;
  1518. this.update();
  1519. }
  1520. },
  1521. /**
  1522. * @inheritdoc
  1523. */
  1524. createItems: function() {
  1525. var player = this.player(),
  1526. sources = player.currentSources();
  1527. return _.map(sources, function(source) {
  1528. return new QualityOption(player, {
  1529. source: source,
  1530. selected: source.src === this.selectedSrc,
  1531. });
  1532. }.bind(this));
  1533. },
  1534. /**
  1535. * @inheritdoc
  1536. */
  1537. buildWrapperCSSClass: function() {
  1538. return 'vjs-quality-selector ' + MenuButton.prototype.buildWrapperCSSClass.call(this);
  1539. },
  1540. });
  1541. videojs.registerComponent('QualitySelector', QualitySelector);
  1542. return QualitySelector;
  1543. };
  1544. },{"../events":5,"./QualityOption":3,"underscore":2}],5:[function(require,module,exports){
  1545. 'use strict';
  1546. module.exports = {
  1547. QUALITY_REQUESTED: 'qualityRequested',
  1548. QUALITY_SELECTED: 'qualitySelected',
  1549. };
  1550. },{}],6:[function(require,module,exports){
  1551. 'use strict';
  1552. var _ = require('underscore'),
  1553. events = require('./events'),
  1554. qualitySelectorFactory = require('./components/QualitySelector'),
  1555. sourceInterceptorFactory = require('./middleware/SourceInterceptor'),
  1556. SafeSeek = require('./util/SafeSeek');
  1557. module.exports = function(videojs) {
  1558. videojs = videojs || window.videojs;
  1559. qualitySelectorFactory(videojs);
  1560. sourceInterceptorFactory(videojs);
  1561. videojs.hook('setup', function(player) {
  1562. function changeQuality(event, newSource) {
  1563. var sources = player.currentSources(),
  1564. currentTime = player.currentTime(),
  1565. currentPlaybackRate = player.playbackRate(),
  1566. isPaused = player.paused(),
  1567. selectedSource;
  1568. // Clear out any previously selected sources (see: #11)
  1569. _.each(sources, function(source) {
  1570. source.selected = false;
  1571. });
  1572. selectedSource = _.findWhere(sources, { src: newSource.src });
  1573. // Note: `_.findWhere` returns a reference to an object. Thus the
  1574. // following updates the original object in `sources`.
  1575. selectedSource.selected = true;
  1576. if (player._qualitySelectorSafeSeek) {
  1577. player._qualitySelectorSafeSeek.onQualitySelectionChange();
  1578. }
  1579. player.src(sources);
  1580. player.ready(function() {
  1581. if (!player._qualitySelectorSafeSeek || player._qualitySelectorSafeSeek.hasFinished()) {
  1582. // Either we don't have a pending seek action or the one that we have is no
  1583. // longer applicable. This block must be within a `player.ready` callback
  1584. // because the call to `player.src` above is asynchronous, and so not
  1585. // having it within this `ready` callback would cause the SourceInterceptor
  1586. // to execute after this block instead of before.
  1587. //
  1588. // We save the `currentTime` within the SafeSeek instance because if
  1589. // multiple QUALITY_REQUESTED events are received before the SafeSeek
  1590. // operation finishes, the player's `currentTime` will be `0` if the
  1591. // player's `src` is updated but the player's `currentTime` has not yet
  1592. // been set by the SafeSeek operation.
  1593. player._qualitySelectorSafeSeek = new SafeSeek(player, currentTime);
  1594. player.playbackRate = playbackRate;
  1595. }
  1596. if (!isPaused) {
  1597. player.play();
  1598. }
  1599. });
  1600. }
  1601. // Add handler to switch sources when the user requests a change
  1602. player.on(events.QUALITY_REQUESTED, changeQuality);
  1603. });
  1604. };
  1605. module.exports.EVENTS = events;
  1606. },{"./components/QualitySelector":4,"./events":5,"./middleware/SourceInterceptor":7,"./util/SafeSeek":9,"underscore":2}],7:[function(require,module,exports){
  1607. 'use strict';
  1608. var _ = require('underscore'),
  1609. events = require('../events');
  1610. module.exports = function(videojs) {
  1611. videojs.use('*', function(player) {
  1612. return {
  1613. setSource: function(playerSelectedSource, next) {
  1614. var sources = player.currentSources(),
  1615. userSelectedSource, chosenSource;
  1616. if (player._qualitySelectorSafeSeek) {
  1617. player._qualitySelectorSafeSeek.onPlayerSourcesChange();
  1618. }
  1619. // There are generally two source options, the one that videojs
  1620. // auto-selects and the one that a "user" of this plugin has
  1621. // supplied via the `selected` property. `selected` can come from
  1622. // either the `<source>` tag or the list of sources passed to
  1623. // videojs using `src()`.
  1624. userSelectedSource = _.find(sources, function(source) {
  1625. // Must check for both boolean and string 'true' as sources set
  1626. // programmatically should use a boolean, but those coming from
  1627. // a `<source>` tag will use a string.
  1628. return source.selected === true || source.selected === 'true';
  1629. });
  1630. chosenSource = userSelectedSource || playerSelectedSource;
  1631. player.trigger(events.QUALITY_SELECTED, chosenSource);
  1632. // Pass along the chosen source
  1633. next(null, chosenSource);
  1634. },
  1635. };
  1636. });
  1637. };
  1638. },{"../events":5,"underscore":2}],8:[function(require,module,exports){
  1639. 'use strict';
  1640. require('./index')();
  1641. },{"./index":6}],9:[function(require,module,exports){
  1642. 'use strict';
  1643. var Class = require('class.extend');
  1644. module.exports = Class.extend({
  1645. init: function(player, seekToTime) {
  1646. this._player = player;
  1647. this._seekToTime = seekToTime;
  1648. this._hasFinished = false;
  1649. this._keepThisInstanceWhenPlayerSourcesChange = false;
  1650. this._seekWhenSafe();
  1651. },
  1652. _seekWhenSafe: function() {
  1653. var HAVE_FUTURE_DATA = 3;
  1654. // `readyState` in Video.js is the same as the HTML5 Media element's `readyState`
  1655. // property.
  1656. //
  1657. // `readyState` is an enum of 5 values (0-4), each of which represent a state of
  1658. // readiness to play. The meaning of the values range from HAVE_NOTHING (0), meaning
  1659. // no data is available to HAVE_ENOUGH_DATA (4), meaning all data is loaded and the
  1660. // video can be played all the way through.
  1661. //
  1662. // In order to seek successfully, the `readyState` must be at least HAVE_FUTURE_DATA
  1663. // (3).
  1664. //
  1665. // @see http://docs.videojs.com/player#readyState
  1666. // @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/readyState
  1667. // @see https://dev.w3.org/html5/spec-preview/media-elements.html#seek-the-media-controller
  1668. if (this._player.readyState() < HAVE_FUTURE_DATA) {
  1669. this._seekFn = this._seek.bind(this);
  1670. // The `canplay` event means that the `readyState` is at least HAVE_FUTURE_DATA.
  1671. this._player.one('canplay', this._seekFn);
  1672. } else {
  1673. this._seek();
  1674. }
  1675. },
  1676. onPlayerSourcesChange: function() {
  1677. if (this._keepThisInstanceWhenPlayerSourcesChange) {
  1678. // By setting this to `false`, we know that if the player sources change again
  1679. // the change did not originate from a quality selection change, the new sources
  1680. // are likely different from the old sources, and so this pending seek no longer
  1681. // applies.
  1682. this._keepThisInstanceWhenPlayerSourcesChange = false;
  1683. } else {
  1684. this.cancel();
  1685. }
  1686. },
  1687. onQualitySelectionChange: function() {
  1688. // `onPlayerSourcesChange` will cancel this pending seek unless we tell it not to.
  1689. // We need to reuse this same pending seek instance because when the player is
  1690. // paused, the `preload` attribute is set to `none`, and the user selects one
  1691. // quality option and then another, the player cannot seek until the player has
  1692. // enough data to do so (and the `canplay` event is fired) and thus on the second
  1693. // selection the player's `currentTime()` is `0` and when the video plays we would
  1694. // seek to `0` instead of the correct time.
  1695. if (!this.hasFinished()) {
  1696. this._keepThisInstanceWhenPlayerSourcesChange = true;
  1697. }
  1698. },
  1699. _seek: function() {
  1700. this._player.currentTime(this._seekToTime);
  1701. this._keepThisInstanceWhenPlayerSourcesChange = false;
  1702. this._hasFinished = true;
  1703. },
  1704. hasFinished: function() {
  1705. return this._hasFinished;
  1706. },
  1707. cancel: function() {
  1708. this._player.off('canplay', this._seekFn);
  1709. this._keepThisInstanceWhenPlayerSourcesChange = false;
  1710. this._hasFinished = true;
  1711. },
  1712. });
  1713. },{"class.extend":1}]},{},[8]);