polyfill_ie11.js 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  1. /* Polyfill service v3.105.0
  2. * For detailed credits and licence information see https://github.com/financial-times/polyfill-service.
  3. *
  4. * Features requested: IntersectionObserver,Object.assign
  5. *
  6. * - _ESAbstract.Call, License: CC0 (required by "Object.assign", "Object.getOwnPropertyDescriptor", "_ESAbstract.ToPropertyKey", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive", "_ESAbstract.OrdinaryToPrimitive")
  7. * - _ESAbstract.CreateMethodProperty, License: CC0 (required by "IntersectionObserver", "Event", "Array.prototype.includes")
  8. * - _ESAbstract.Get, License: CC0 (required by "Object.assign", "Object.getOwnPropertyDescriptor", "_ESAbstract.ToPropertyKey", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive", "_ESAbstract.OrdinaryToPrimitive")
  9. * - _ESAbstract.HasOwnProperty, License: CC0 (required by "Object.assign", "Object.getOwnPropertyDescriptor")
  10. * - _ESAbstract.IsCallable, License: CC0 (required by "Object.assign", "Object.getOwnPropertyDescriptor", "_ESAbstract.ToPropertyKey", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive", "_ESAbstract.OrdinaryToPrimitive")
  11. * - _ESAbstract.SameValueNonNumber, License: CC0 (required by "IntersectionObserver", "Event", "Array.prototype.includes", "_ESAbstract.SameValueZero")
  12. * - _ESAbstract.ToObject, License: CC0 (required by "Object.assign", "Object.getOwnPropertyDescriptor", "_ESAbstract.ToPropertyKey", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive", "_ESAbstract.GetMethod", "_ESAbstract.GetV")
  13. * - _ESAbstract.GetV, License: CC0 (required by "Object.assign", "Object.getOwnPropertyDescriptor", "_ESAbstract.ToPropertyKey", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive", "_ESAbstract.GetMethod")
  14. * - _ESAbstract.GetMethod, License: CC0 (required by "Object.assign", "Object.getOwnPropertyDescriptor", "_ESAbstract.ToPropertyKey", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive")
  15. * - _ESAbstract.Type, License: CC0 (required by "Object.assign", "Object.getOwnPropertyDescriptor", "_ESAbstract.ToPropertyKey", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive", "_ESAbstract.OrdinaryToPrimitive")
  16. * - _ESAbstract.OrdinaryToPrimitive, License: CC0 (required by "Object.assign", "Object.getOwnPropertyDescriptor", "_ESAbstract.ToPropertyKey", "_ESAbstract.ToString", "_ESAbstract.ToPrimitive")
  17. * - _ESAbstract.SameValueZero, License: CC0 (required by "IntersectionObserver", "Event", "Array.prototype.includes")
  18. * - _ESAbstract.ToInteger, License: CC0 (required by "IntersectionObserver", "Event", "Array.prototype.includes", "_ESAbstract.ToLength")
  19. * - _ESAbstract.ToLength, License: CC0 (required by "IntersectionObserver", "Event", "Array.prototype.includes")
  20. * - _ESAbstract.ToPrimitive, License: CC0 (required by "Object.assign", "Object.getOwnPropertyDescriptor", "_ESAbstract.ToPropertyKey", "_ESAbstract.ToString")
  21. * - _ESAbstract.ToString, License: CC0 (required by "Object.assign", "Object.getOwnPropertyDescriptor", "_ESAbstract.ToPropertyKey")
  22. * - _ESAbstract.ToPropertyKey, License: CC0 (required by "Object.assign", "Object.getOwnPropertyDescriptor")
  23. * - Array.prototype.includes, License: MIT (required by "IntersectionObserver", "Event")
  24. * - Event, License: CC0 (required by "IntersectionObserver")
  25. * - IntersectionObserver, License: CC0
  26. * - Object.getOwnPropertyDescriptor, License: CC0 (required by "Object.assign")
  27. * - Object.keys, License: MIT (required by "Object.assign")
  28. * - Object.assign, License: CC0 */
  29. (function(self, undefined) {
  30. // _ESAbstract.Call
  31. /* global IsCallable */
  32. // 7.3.12. Call ( F, V [ , argumentsList ] )
  33. function Call(F, V /* [, argumentsList] */) { // eslint-disable-line no-unused-vars
  34. // 1. If argumentsList is not present, set argumentsList to a new empty List.
  35. var argumentsList = arguments.length > 2 ? arguments[2] : [];
  36. // 2. If IsCallable(F) is false, throw a TypeError exception.
  37. if (IsCallable(F) === false) {
  38. throw new TypeError(Object.prototype.toString.call(F) + 'is not a function.');
  39. }
  40. // 3. Return ? F.[[Call]](V, argumentsList).
  41. return F.apply(V, argumentsList);
  42. }
  43. // _ESAbstract.CreateMethodProperty
  44. // 7.3.5. CreateMethodProperty ( O, P, V )
  45. function CreateMethodProperty(O, P, V) { // eslint-disable-line no-unused-vars
  46. // 1. Assert: Type(O) is Object.
  47. // 2. Assert: IsPropertyKey(P) is true.
  48. // 3. Let newDesc be the PropertyDescriptor{[[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}.
  49. var newDesc = {
  50. value: V,
  51. writable: true,
  52. enumerable: false,
  53. configurable: true
  54. };
  55. // 4. Return ? O.[[DefineOwnProperty]](P, newDesc).
  56. Object.defineProperty(O, P, newDesc);
  57. }
  58. // _ESAbstract.Get
  59. // 7.3.1. Get ( O, P )
  60. function Get(O, P) { // eslint-disable-line no-unused-vars
  61. // 1. Assert: Type(O) is Object.
  62. // 2. Assert: IsPropertyKey(P) is true.
  63. // 3. Return ? O.[[Get]](P, O).
  64. return O[P];
  65. }
  66. // _ESAbstract.HasOwnProperty
  67. // 7.3.11 HasOwnProperty (O, P)
  68. function HasOwnProperty(o, p) { // eslint-disable-line no-unused-vars
  69. // 1. Assert: Type(O) is Object.
  70. // 2. Assert: IsPropertyKey(P) is true.
  71. // 3. Let desc be ? O.[[GetOwnProperty]](P).
  72. // 4. If desc is undefined, return false.
  73. // 5. Return true.
  74. // Polyfill.io - As we expect user agents to support ES3 fully we can skip the above steps and use Object.prototype.hasOwnProperty to do them for us.
  75. return Object.prototype.hasOwnProperty.call(o, p);
  76. }
  77. // _ESAbstract.IsCallable
  78. // 7.2.3. IsCallable ( argument )
  79. function IsCallable(argument) { // eslint-disable-line no-unused-vars
  80. // 1. If Type(argument) is not Object, return false.
  81. // 2. If argument has a [[Call]] internal method, return true.
  82. // 3. Return false.
  83. // Polyfill.io - Only function objects have a [[Call]] internal method. This means we can simplify this function to check that the argument has a type of function.
  84. return typeof argument === 'function';
  85. }
  86. // _ESAbstract.SameValueNonNumber
  87. // 7.2.12. SameValueNonNumber ( x, y )
  88. function SameValueNonNumber(x, y) { // eslint-disable-line no-unused-vars
  89. // 1. Assert: Type(x) is not Number.
  90. // 2. Assert: Type(x) is the same as Type(y).
  91. // 3. If Type(x) is Undefined, return true.
  92. // 4. If Type(x) is Null, return true.
  93. // 5. If Type(x) is String, then
  94. // a. If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices), return true; otherwise, return false.
  95. // 6. If Type(x) is Boolean, then
  96. // a. If x and y are both true or both false, return true; otherwise, return false.
  97. // 7. If Type(x) is Symbol, then
  98. // a. If x and y are both the same Symbol value, return true; otherwise, return false.
  99. // 8. If x and y are the same Object value, return true. Otherwise, return false.
  100. // Polyfill.io - We can skip all above steps because the === operator does it all for us.
  101. return x === y;
  102. }
  103. // _ESAbstract.ToObject
  104. // 7.1.13 ToObject ( argument )
  105. // The abstract operation ToObject converts argument to a value of type Object according to Table 12:
  106. // Table 12: ToObject Conversions
  107. /*
  108. |----------------------------------------------------------------------------------------------------------------------------------------------------|
  109. | Argument Type | Result |
  110. |----------------------------------------------------------------------------------------------------------------------------------------------------|
  111. | Undefined | Throw a TypeError exception. |
  112. | Null | Throw a TypeError exception. |
  113. | Boolean | Return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See 19.3 for a description of Boolean objects. |
  114. | Number | Return a new Number object whose [[NumberData]] internal slot is set to argument. See 20.1 for a description of Number objects. |
  115. | String | Return a new String object whose [[StringData]] internal slot is set to argument. See 21.1 for a description of String objects. |
  116. | Symbol | Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See 19.4 for a description of Symbol objects. |
  117. | Object | Return argument. |
  118. |----------------------------------------------------------------------------------------------------------------------------------------------------|
  119. */
  120. function ToObject(argument) { // eslint-disable-line no-unused-vars
  121. if (argument === null || argument === undefined) {
  122. throw TypeError();
  123. }
  124. return Object(argument);
  125. }
  126. // _ESAbstract.GetV
  127. /* global ToObject */
  128. // 7.3.2 GetV (V, P)
  129. function GetV(v, p) { // eslint-disable-line no-unused-vars
  130. // 1. Assert: IsPropertyKey(P) is true.
  131. // 2. Let O be ? ToObject(V).
  132. var o = ToObject(v);
  133. // 3. Return ? O.[[Get]](P, V).
  134. return o[p];
  135. }
  136. // _ESAbstract.GetMethod
  137. /* global GetV, IsCallable */
  138. // 7.3.9. GetMethod ( V, P )
  139. function GetMethod(V, P) { // eslint-disable-line no-unused-vars
  140. // 1. Assert: IsPropertyKey(P) is true.
  141. // 2. Let func be ? GetV(V, P).
  142. var func = GetV(V, P);
  143. // 3. If func is either undefined or null, return undefined.
  144. if (func === null || func === undefined) {
  145. return undefined;
  146. }
  147. // 4. If IsCallable(func) is false, throw a TypeError exception.
  148. if (IsCallable(func) === false) {
  149. throw new TypeError('Method not callable: ' + P);
  150. }
  151. // 5. Return func.
  152. return func;
  153. }
  154. // _ESAbstract.Type
  155. // "Type(x)" is used as shorthand for "the type of x"...
  156. function Type(x) { // eslint-disable-line no-unused-vars
  157. switch (typeof x) {
  158. case 'undefined':
  159. return 'undefined';
  160. case 'boolean':
  161. return 'boolean';
  162. case 'number':
  163. return 'number';
  164. case 'string':
  165. return 'string';
  166. case 'symbol':
  167. return 'symbol';
  168. default:
  169. // typeof null is 'object'
  170. if (x === null) return 'null';
  171. // Polyfill.io - This is here because a Symbol polyfill will have a typeof `object`.
  172. if ('Symbol' in self && (x instanceof self.Symbol || x.constructor === self.Symbol)) return 'symbol';
  173. return 'object';
  174. }
  175. }
  176. // _ESAbstract.OrdinaryToPrimitive
  177. /* global Get, IsCallable, Call, Type */
  178. // 7.1.1.1. OrdinaryToPrimitive ( O, hint )
  179. function OrdinaryToPrimitive(O, hint) { // eslint-disable-line no-unused-vars
  180. // 1. Assert: Type(O) is Object.
  181. // 2. Assert: Type(hint) is String and its value is either "string" or "number".
  182. // 3. If hint is "string", then
  183. if (hint === 'string') {
  184. // a. Let methodNames be « "toString", "valueOf" ».
  185. var methodNames = ['toString', 'valueOf'];
  186. // 4. Else,
  187. } else {
  188. // a. Let methodNames be « "valueOf", "toString" ».
  189. methodNames = ['valueOf', 'toString'];
  190. }
  191. // 5. For each name in methodNames in List order, do
  192. for (var i = 0; i < methodNames.length; ++i) {
  193. var name = methodNames[i];
  194. // a. Let method be ? Get(O, name).
  195. var method = Get(O, name);
  196. // b. If IsCallable(method) is true, then
  197. if (IsCallable(method)) {
  198. // i. Let result be ? Call(method, O).
  199. var result = Call(method, O);
  200. // ii. If Type(result) is not Object, return result.
  201. if (Type(result) !== 'object') {
  202. return result;
  203. }
  204. }
  205. }
  206. // 6. Throw a TypeError exception.
  207. throw new TypeError('Cannot convert to primitive.');
  208. }
  209. // _ESAbstract.SameValueZero
  210. /* global Type, SameValueNonNumber */
  211. // 7.2.11. SameValueZero ( x, y )
  212. function SameValueZero (x, y) { // eslint-disable-line no-unused-vars
  213. // 1. If Type(x) is different from Type(y), return false.
  214. if (Type(x) !== Type(y)) {
  215. return false;
  216. }
  217. // 2. If Type(x) is Number, then
  218. if (Type(x) === 'number') {
  219. // a. If x is NaN and y is NaN, return true.
  220. if (isNaN(x) && isNaN(y)) {
  221. return true;
  222. }
  223. // b. If x is +0 and y is -0, return true.
  224. if (1/x === Infinity && 1/y === -Infinity) {
  225. return true;
  226. }
  227. // c. If x is -0 and y is +0, return true.
  228. if (1/x === -Infinity && 1/y === Infinity) {
  229. return true;
  230. }
  231. // d. If x is the same Number value as y, return true.
  232. if (x === y) {
  233. return true;
  234. }
  235. // e. Return false.
  236. return false;
  237. }
  238. // 3. Return SameValueNonNumber(x, y).
  239. return SameValueNonNumber(x, y);
  240. }
  241. // _ESAbstract.ToInteger
  242. /* global Type */
  243. // 7.1.4. ToInteger ( argument )
  244. function ToInteger(argument) { // eslint-disable-line no-unused-vars
  245. if (Type(argument) === 'symbol') {
  246. throw new TypeError('Cannot convert a Symbol value to a number');
  247. }
  248. // 1. Let number be ? ToNumber(argument).
  249. var number = Number(argument);
  250. // 2. If number is NaN, return +0.
  251. if (isNaN(number)) {
  252. return 0;
  253. }
  254. // 3. If number is +0, -0, +∞, or -∞, return number.
  255. if (1/number === Infinity || 1/number === -Infinity || number === Infinity || number === -Infinity) {
  256. return number;
  257. }
  258. // 4. Return the number value that is the same sign as number and whose magnitude is floor(abs(number)).
  259. return ((number < 0) ? -1 : 1) * Math.floor(Math.abs(number));
  260. }
  261. // _ESAbstract.ToLength
  262. /* global ToInteger */
  263. // 7.1.15. ToLength ( argument )
  264. function ToLength(argument) { // eslint-disable-line no-unused-vars
  265. // 1. Let len be ? ToInteger(argument).
  266. var len = ToInteger(argument);
  267. // 2. If len ≤ +0, return +0.
  268. if (len <= 0) {
  269. return 0;
  270. }
  271. // 3. Return min(len, 253-1).
  272. return Math.min(len, Math.pow(2, 53) -1);
  273. }
  274. // _ESAbstract.ToPrimitive
  275. /* global Type, GetMethod, Call, OrdinaryToPrimitive */
  276. // 7.1.1. ToPrimitive ( input [ , PreferredType ] )
  277. function ToPrimitive(input /* [, PreferredType] */) { // eslint-disable-line no-unused-vars
  278. var PreferredType = arguments.length > 1 ? arguments[1] : undefined;
  279. // 1. Assert: input is an ECMAScript language value.
  280. // 2. If Type(input) is Object, then
  281. if (Type(input) === 'object') {
  282. // a. If PreferredType is not present, let hint be "default".
  283. if (arguments.length < 2) {
  284. var hint = 'default';
  285. // b. Else if PreferredType is hint String, let hint be "string".
  286. } else if (PreferredType === String) {
  287. hint = 'string';
  288. // c. Else PreferredType is hint Number, let hint be "number".
  289. } else if (PreferredType === Number) {
  290. hint = 'number';
  291. }
  292. // d. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
  293. var exoticToPrim = typeof self.Symbol === 'function' && typeof self.Symbol.toPrimitive === 'symbol' ? GetMethod(input, self.Symbol.toPrimitive) : undefined;
  294. // e. If exoticToPrim is not undefined, then
  295. if (exoticToPrim !== undefined) {
  296. // i. Let result be ? Call(exoticToPrim, input, « hint »).
  297. var result = Call(exoticToPrim, input, [hint]);
  298. // ii. If Type(result) is not Object, return result.
  299. if (Type(result) !== 'object') {
  300. return result;
  301. }
  302. // iii. Throw a TypeError exception.
  303. throw new TypeError('Cannot convert exotic object to primitive.');
  304. }
  305. // f. If hint is "default", set hint to "number".
  306. if (hint === 'default') {
  307. hint = 'number';
  308. }
  309. // g. Return ? OrdinaryToPrimitive(input, hint).
  310. return OrdinaryToPrimitive(input, hint);
  311. }
  312. // 3. Return input
  313. return input;
  314. }
  315. // _ESAbstract.ToString
  316. /* global Type, ToPrimitive */
  317. // 7.1.12. ToString ( argument )
  318. // The abstract operation ToString converts argument to a value of type String according to Table 11:
  319. // Table 11: ToString Conversions
  320. /*
  321. |---------------|--------------------------------------------------------|
  322. | Argument Type | Result |
  323. |---------------|--------------------------------------------------------|
  324. | Undefined | Return "undefined". |
  325. |---------------|--------------------------------------------------------|
  326. | Null | Return "null". |
  327. |---------------|--------------------------------------------------------|
  328. | Boolean | If argument is true, return "true". |
  329. | | If argument is false, return "false". |
  330. |---------------|--------------------------------------------------------|
  331. | Number | Return NumberToString(argument). |
  332. |---------------|--------------------------------------------------------|
  333. | String | Return argument. |
  334. |---------------|--------------------------------------------------------|
  335. | Symbol | Throw a TypeError exception. |
  336. |---------------|--------------------------------------------------------|
  337. | Object | Apply the following steps: |
  338. | | Let primValue be ? ToPrimitive(argument, hint String). |
  339. | | Return ? ToString(primValue). |
  340. |---------------|--------------------------------------------------------|
  341. */
  342. function ToString(argument) { // eslint-disable-line no-unused-vars
  343. switch(Type(argument)) {
  344. case 'symbol':
  345. throw new TypeError('Cannot convert a Symbol value to a string');
  346. case 'object':
  347. var primValue = ToPrimitive(argument, String);
  348. return ToString(primValue); // eslint-disable-line no-unused-vars
  349. default:
  350. return String(argument);
  351. }
  352. }
  353. // _ESAbstract.ToPropertyKey
  354. /* globals ToPrimitive, Type, ToString */
  355. // 7.1.14. ToPropertyKey ( argument )
  356. function ToPropertyKey(argument) { // eslint-disable-line no-unused-vars
  357. // 1. Let key be ? ToPrimitive(argument, hint String).
  358. var key = ToPrimitive(argument, String);
  359. // 2. If Type(key) is Symbol, then
  360. if (Type(key) === 'symbol') {
  361. // a. Return key.
  362. return key;
  363. }
  364. // 3. Return ! ToString(key).
  365. return ToString(key);
  366. }
  367. if (!("includes"in Array.prototype
  368. )) {
  369. // Array.prototype.includes
  370. /* global CreateMethodProperty, Get, SameValueZero, ToInteger, ToLength, ToObject, ToString */
  371. // 22.1.3.11. Array.prototype.includes ( searchElement [ , fromIndex ] )
  372. CreateMethodProperty(Array.prototype, 'includes', function includes(searchElement /* [ , fromIndex ] */) {
  373. 'use strict';
  374. // 1. Let O be ? ToObject(this value).
  375. var O = ToObject(this);
  376. // 2. Let len be ? ToLength(? Get(O, "length")).
  377. var len = ToLength(Get(O, "length"));
  378. // 3. If len is 0, return false.
  379. if (len === 0) {
  380. return false;
  381. }
  382. // 4. Let n be ? ToInteger(fromIndex). (If fromIndex is undefined, this step produces the value 0.)
  383. var n = ToInteger(arguments[1]);
  384. // 5. If n ≥ 0, then
  385. if (n >= 0) {
  386. // a. Let k be n.
  387. var k = n;
  388. // 6. Else n < 0,
  389. } else {
  390. // a. Let k be len + n.
  391. k = len + n;
  392. // b. If k < 0, let k be 0.
  393. if (k < 0) {
  394. k = 0;
  395. }
  396. }
  397. // 7. Repeat, while k < len
  398. while (k < len) {
  399. // a. Let elementK be the result of ? Get(O, ! ToString(k)).
  400. var elementK = Get(O, ToString(k));
  401. // b. If SameValueZero(searchElement, elementK) is true, return true.
  402. if (SameValueZero(searchElement, elementK)) {
  403. return true;
  404. }
  405. // c. Increase k by 1.
  406. k = k + 1;
  407. }
  408. // 8. Return false.
  409. return false;
  410. });
  411. }
  412. if (!((function(n){if(!("Event"in n))return!1
  413. try{return new Event("click"),!0}catch(t){return!1}})(self)
  414. )) {
  415. // Event
  416. (function () {
  417. var unlistenableWindowEvents = {
  418. click: 1,
  419. dblclick: 1,
  420. keyup: 1,
  421. keypress: 1,
  422. keydown: 1,
  423. mousedown: 1,
  424. mouseup: 1,
  425. mousemove: 1,
  426. mouseover: 1,
  427. mouseenter: 1,
  428. mouseleave: 1,
  429. mouseout: 1,
  430. storage: 1,
  431. storagecommit: 1,
  432. textinput: 1
  433. };
  434. // This polyfill depends on availability of `document` so will not run in a worker
  435. // However, we asssume there are no browsers with worker support that lack proper
  436. // support for `Event` within the worker
  437. if (typeof document === 'undefined' || typeof window === 'undefined') return;
  438. var existingProto = (window.Event && window.Event.prototype) || null;
  439. function Event(type, eventInitDict) {
  440. if (!type) {
  441. throw new Error('Not enough arguments');
  442. }
  443. var event;
  444. // Shortcut if browser supports createEvent
  445. if ('createEvent' in document) {
  446. event = document.createEvent('Event');
  447. var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
  448. var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
  449. event.initEvent(type, bubbles, cancelable);
  450. return event;
  451. }
  452. event = document.createEventObject();
  453. event.type = type;
  454. event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
  455. event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
  456. return event;
  457. }
  458. Event.NONE = 0;
  459. Event.CAPTURING_PHASE = 1;
  460. Event.AT_TARGET = 2;
  461. Event.BUBBLING_PHASE = 3;
  462. window.Event = Window.prototype.Event = Event;
  463. if (existingProto) {
  464. Object.defineProperty(window.Event, 'prototype', {
  465. configurable: false,
  466. enumerable: false,
  467. writable: true,
  468. value: existingProto
  469. });
  470. }
  471. if (!('createEvent' in document)) {
  472. window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
  473. var
  474. element = this,
  475. type = arguments[0],
  476. listener = arguments[1];
  477. if (element === window && type in unlistenableWindowEvents) {
  478. throw new Error('In IE8 the event: ' + type + ' is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.');
  479. }
  480. if (!element._events) {
  481. element._events = {};
  482. }
  483. if (!element._events[type]) {
  484. element._events[type] = function (event) {
  485. var
  486. list = element._events[event.type].list,
  487. events = list.slice(),
  488. index = -1,
  489. length = events.length,
  490. eventElement;
  491. event.preventDefault = function preventDefault() {
  492. if (event.cancelable !== false) {
  493. event.returnValue = false;
  494. }
  495. };
  496. event.stopPropagation = function stopPropagation() {
  497. event.cancelBubble = true;
  498. };
  499. event.stopImmediatePropagation = function stopImmediatePropagation() {
  500. event.cancelBubble = true;
  501. event.cancelImmediate = true;
  502. };
  503. event.currentTarget = element;
  504. event.relatedTarget = event.fromElement || null;
  505. event.target = event.target || event.srcElement || element;
  506. event.timeStamp = new Date().getTime();
  507. if (event.clientX) {
  508. event.pageX = event.clientX + document.documentElement.scrollLeft;
  509. event.pageY = event.clientY + document.documentElement.scrollTop;
  510. }
  511. while (++index < length && !event.cancelImmediate) {
  512. if (index in events) {
  513. eventElement = events[index];
  514. if (list.includes(eventElement) && typeof eventElement === 'function') {
  515. eventElement.call(element, event);
  516. }
  517. }
  518. }
  519. };
  520. element._events[type].list = [];
  521. if (element.attachEvent) {
  522. element.attachEvent('on' + type, element._events[type]);
  523. }
  524. }
  525. element._events[type].list.push(listener);
  526. };
  527. window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
  528. var
  529. element = this,
  530. type = arguments[0],
  531. listener = arguments[1],
  532. index;
  533. if (element._events && element._events[type] && element._events[type].list) {
  534. index = element._events[type].list.indexOf(listener);
  535. if (index !== -1) {
  536. element._events[type].list.splice(index, 1);
  537. if (!element._events[type].list.length) {
  538. if (element.detachEvent) {
  539. element.detachEvent('on' + type, element._events[type]);
  540. }
  541. delete element._events[type];
  542. }
  543. }
  544. }
  545. };
  546. window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
  547. if (!arguments.length) {
  548. throw new Error('Not enough arguments');
  549. }
  550. if (!event || typeof event.type !== 'string') {
  551. throw new Error('DOM Events Exception 0');
  552. }
  553. var element = this, type = event.type;
  554. try {
  555. if (!event.bubbles) {
  556. event.cancelBubble = true;
  557. var cancelBubbleEvent = function (event) {
  558. event.cancelBubble = true;
  559. (element || window).detachEvent('on' + type, cancelBubbleEvent);
  560. };
  561. this.attachEvent('on' + type, cancelBubbleEvent);
  562. }
  563. this.fireEvent('on' + type, event);
  564. } catch (error) {
  565. event.target = element;
  566. do {
  567. event.currentTarget = element;
  568. if ('_events' in element && typeof element._events[type] === 'function') {
  569. element._events[type].call(element, event);
  570. }
  571. if (typeof element['on' + type] === 'function') {
  572. element['on' + type].call(element, event);
  573. }
  574. element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
  575. } while (element && !event.cancelBubble);
  576. }
  577. return true;
  578. };
  579. // Add the DOMContentLoaded Event
  580. document.attachEvent('onreadystatechange', function() {
  581. if (document.readyState === 'complete') {
  582. document.dispatchEvent(new Event('DOMContentLoaded', {
  583. bubbles: true
  584. }));
  585. }
  586. });
  587. }
  588. }());
  589. }
  590. if (!("IntersectionObserver"in window&&"IntersectionObserverEntry"in window&&"intersectionRatio"in window.IntersectionObserverEntry.prototype
  591. )) {
  592. // IntersectionObserver
  593. /**
  594. * Copyright 2016 Google Inc. All Rights Reserved.
  595. *
  596. * Licensed under the W3C SOFTWARE AND DOCUMENT NOTICE AND LICENSE.
  597. *
  598. * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
  599. *
  600. */
  601. (function(window, document) {
  602. 'use strict';
  603. /**
  604. * An IntersectionObserver registry. This registry exists to hold a strong
  605. * reference to IntersectionObserver instances currently observing a target
  606. * element. Without this registry, instances without another reference may be
  607. * garbage collected.
  608. */
  609. var registry = [];
  610. /**
  611. * Creates the global IntersectionObserverEntry constructor.
  612. * https://w3c.github.io/IntersectionObserver/#intersection-observer-entry
  613. * @param {Object} entry A dictionary of instance properties.
  614. * @constructor
  615. */
  616. function IntersectionObserverEntry(entry) {
  617. this.time = entry.time;
  618. this.target = entry.target;
  619. this.rootBounds = entry.rootBounds;
  620. this.boundingClientRect = entry.boundingClientRect;
  621. this.intersectionRect = entry.intersectionRect || getEmptyRect();
  622. try {
  623. this.isIntersecting = !!entry.intersectionRect;
  624. } catch (err) {
  625. // This means we are using the IntersectionObserverEntry polyfill which has only defined a getter
  626. }
  627. // Calculates the intersection ratio.
  628. var targetRect = this.boundingClientRect;
  629. var targetArea = targetRect.width * targetRect.height;
  630. var intersectionRect = this.intersectionRect;
  631. var intersectionArea = intersectionRect.width * intersectionRect.height;
  632. // Sets intersection ratio.
  633. if (targetArea) {
  634. // Round the intersection ratio to avoid floating point math issues:
  635. // https://github.com/w3c/IntersectionObserver/issues/324
  636. this.intersectionRatio = Number((intersectionArea / targetArea).toFixed(4));
  637. } else {
  638. // If area is zero and is intersecting, sets to 1, otherwise to 0
  639. this.intersectionRatio = this.isIntersecting ? 1 : 0;
  640. }
  641. }
  642. /**
  643. * Creates the global IntersectionObserver constructor.
  644. * https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
  645. * @param {Function} callback The function to be invoked after intersection
  646. * changes have queued. The function is not invoked if the queue has
  647. * been emptied by calling the `takeRecords` method.
  648. * @param {Object=} opt_options Optional configuration options.
  649. * @constructor
  650. */
  651. function IntersectionObserver(callback, opt_options) {
  652. var options = opt_options || {};
  653. if (typeof callback != 'function') {
  654. throw new Error('callback must be a function');
  655. }
  656. if (options.root && options.root.nodeType != 1) {
  657. throw new Error('root must be an Element');
  658. }
  659. // Binds and throttles `this._checkForIntersections`.
  660. this._checkForIntersections = throttle(
  661. this._checkForIntersections.bind(this), this.THROTTLE_TIMEOUT);
  662. // Private properties.
  663. this._callback = callback;
  664. this._observationTargets = [];
  665. this._queuedEntries = [];
  666. this._rootMarginValues = this._parseRootMargin(options.rootMargin);
  667. // Public properties.
  668. this.thresholds = this._initThresholds(options.threshold);
  669. this.root = options.root || null;
  670. this.rootMargin = this._rootMarginValues.map(function(margin) {
  671. return margin.value + margin.unit;
  672. }).join(' ');
  673. }
  674. /**
  675. * The minimum interval within which the document will be checked for
  676. * intersection changes.
  677. */
  678. IntersectionObserver.prototype.THROTTLE_TIMEOUT = 100;
  679. /**
  680. * The frequency in which the polyfill polls for intersection changes.
  681. * this can be updated on a per instance basis and must be set prior to
  682. * calling `observe` on the first target.
  683. */
  684. IntersectionObserver.prototype.POLL_INTERVAL = null;
  685. /**
  686. * Use a mutation observer on the root element
  687. * to detect intersection changes.
  688. */
  689. IntersectionObserver.prototype.USE_MUTATION_OBSERVER = true;
  690. /**
  691. * Starts observing a target element for intersection changes based on
  692. * the thresholds values.
  693. * @param {Element} target The DOM element to observe.
  694. */
  695. IntersectionObserver.prototype.observe = function(target) {
  696. var isTargetAlreadyObserved = this._observationTargets.some(function(item) {
  697. return item.element == target;
  698. });
  699. if (isTargetAlreadyObserved) {
  700. return;
  701. }
  702. if (!(target && target.nodeType == 1)) {
  703. throw new Error('target must be an Element');
  704. }
  705. this._registerInstance();
  706. this._observationTargets.push({element: target, entry: null});
  707. this._monitorIntersections();
  708. this._checkForIntersections();
  709. };
  710. /**
  711. * Stops observing a target element for intersection changes.
  712. * @param {Element} target The DOM element to observe.
  713. */
  714. IntersectionObserver.prototype.unobserve = function(target) {
  715. this._observationTargets =
  716. this._observationTargets.filter(function(item) {
  717. return item.element != target;
  718. });
  719. if (!this._observationTargets.length) {
  720. this._unmonitorIntersections();
  721. this._unregisterInstance();
  722. }
  723. };
  724. /**
  725. * Stops observing all target elements for intersection changes.
  726. */
  727. IntersectionObserver.prototype.disconnect = function() {
  728. this._observationTargets = [];
  729. this._unmonitorIntersections();
  730. this._unregisterInstance();
  731. };
  732. /**
  733. * Returns any queue entries that have not yet been reported to the
  734. * callback and clears the queue. This can be used in conjunction with the
  735. * callback to obtain the absolute most up-to-date intersection information.
  736. * @return {Array} The currently queued entries.
  737. */
  738. IntersectionObserver.prototype.takeRecords = function() {
  739. var records = this._queuedEntries.slice();
  740. this._queuedEntries = [];
  741. return records;
  742. };
  743. /**
  744. * Accepts the threshold value from the user configuration object and
  745. * returns a sorted array of unique threshold values. If a value is not
  746. * between 0 and 1 and error is thrown.
  747. * @private
  748. * @param {Array|number=} opt_threshold An optional threshold value or
  749. * a list of threshold values, defaulting to [0].
  750. * @return {Array} A sorted list of unique and valid threshold values.
  751. */
  752. IntersectionObserver.prototype._initThresholds = function(opt_threshold) {
  753. var threshold = opt_threshold || [0];
  754. if (!Array.isArray(threshold)) threshold = [threshold];
  755. return threshold.sort().filter(function(t, i, a) {
  756. if (typeof t != 'number' || isNaN(t) || t < 0 || t > 1) {
  757. throw new Error('threshold must be a number between 0 and 1 inclusively');
  758. }
  759. return t !== a[i - 1];
  760. });
  761. };
  762. /**
  763. * Accepts the rootMargin value from the user configuration object
  764. * and returns an array of the four margin values as an object containing
  765. * the value and unit properties. If any of the values are not properly
  766. * formatted or use a unit other than px or %, and error is thrown.
  767. * @private
  768. * @param {string=} opt_rootMargin An optional rootMargin value,
  769. * defaulting to '0px'.
  770. * @return {Array<Object>} An array of margin objects with the keys
  771. * value and unit.
  772. */
  773. IntersectionObserver.prototype._parseRootMargin = function(opt_rootMargin) {
  774. var marginString = opt_rootMargin || '0px';
  775. var margins = marginString.split(/\s+/).map(function(margin) {
  776. var parts = /^(-?\d*\.?\d+)(px|%)$/.exec(margin);
  777. if (!parts) {
  778. throw new Error('rootMargin must be specified in pixels or percent');
  779. }
  780. return {value: parseFloat(parts[1]), unit: parts[2]};
  781. });
  782. // Handles shorthand.
  783. margins[1] = margins[1] || margins[0];
  784. margins[2] = margins[2] || margins[0];
  785. margins[3] = margins[3] || margins[1];
  786. return margins;
  787. };
  788. /**
  789. * Starts polling for intersection changes if the polling is not already
  790. * happening, and if the page's visibility state is visible.
  791. * @private
  792. */
  793. IntersectionObserver.prototype._monitorIntersections = function() {
  794. if (!this._monitoringIntersections) {
  795. this._monitoringIntersections = true;
  796. // If a poll interval is set, use polling instead of listening to
  797. // resize and scroll events or DOM mutations.
  798. if (this.POLL_INTERVAL) {
  799. this._monitoringInterval = setInterval(
  800. this._checkForIntersections, this.POLL_INTERVAL);
  801. }
  802. else {
  803. addEvent(window, 'resize', this._checkForIntersections, true);
  804. addEvent(document, 'scroll', this._checkForIntersections, true);
  805. if (this.USE_MUTATION_OBSERVER && 'MutationObserver' in window) {
  806. this._domObserver = new MutationObserver(this._checkForIntersections);
  807. this._domObserver.observe(document, {
  808. attributes: true,
  809. childList: true,
  810. characterData: true,
  811. subtree: true
  812. });
  813. }
  814. }
  815. }
  816. };
  817. /**
  818. * Stops polling for intersection changes.
  819. * @private
  820. */
  821. IntersectionObserver.prototype._unmonitorIntersections = function() {
  822. if (this._monitoringIntersections) {
  823. this._monitoringIntersections = false;
  824. clearInterval(this._monitoringInterval);
  825. this._monitoringInterval = null;
  826. removeEvent(window, 'resize', this._checkForIntersections, true);
  827. removeEvent(document, 'scroll', this._checkForIntersections, true);
  828. if (this._domObserver) {
  829. this._domObserver.disconnect();
  830. this._domObserver = null;
  831. }
  832. }
  833. };
  834. /**
  835. * Scans each observation target for intersection changes and adds them
  836. * to the internal entries queue. If new entries are found, it
  837. * schedules the callback to be invoked.
  838. * @private
  839. */
  840. IntersectionObserver.prototype._checkForIntersections = function() {
  841. var rootIsInDom = this._rootIsInDom();
  842. var rootRect = rootIsInDom ? this._getRootRect() : getEmptyRect();
  843. this._observationTargets.forEach(function(item) {
  844. var target = item.element;
  845. var targetRect = getBoundingClientRect(target);
  846. var rootContainsTarget = this._rootContainsTarget(target);
  847. var oldEntry = item.entry;
  848. var intersectionRect = rootIsInDom && rootContainsTarget &&
  849. this._computeTargetAndRootIntersection(target, rootRect);
  850. var newEntry = item.entry = new IntersectionObserverEntry({
  851. time: now(),
  852. target: target,
  853. boundingClientRect: targetRect,
  854. rootBounds: rootRect,
  855. intersectionRect: intersectionRect
  856. });
  857. if (!oldEntry) {
  858. this._queuedEntries.push(newEntry);
  859. } else if (rootIsInDom && rootContainsTarget) {
  860. // If the new entry intersection ratio has crossed any of the
  861. // thresholds, add a new entry.
  862. if (this._hasCrossedThreshold(oldEntry, newEntry)) {
  863. this._queuedEntries.push(newEntry);
  864. }
  865. } else {
  866. // If the root is not in the DOM or target is not contained within
  867. // root but the previous entry for this target had an intersection,
  868. // add a new record indicating removal.
  869. if (oldEntry && oldEntry.isIntersecting) {
  870. this._queuedEntries.push(newEntry);
  871. }
  872. }
  873. }, this);
  874. if (this._queuedEntries.length) {
  875. this._callback(this.takeRecords(), this);
  876. }
  877. };
  878. /**
  879. * Accepts a target and root rect computes the intersection between then
  880. * following the algorithm in the spec.
  881. * TODO(philipwalton): at this time clip-path is not considered.
  882. * https://w3c.github.io/IntersectionObserver/#calculate-intersection-rect-algo
  883. * @param {Element} target The target DOM element
  884. * @param {Object} rootRect The bounding rect of the root after being
  885. * expanded by the rootMargin value.
  886. * @return {?Object} The final intersection rect object or undefined if no
  887. * intersection is found.
  888. * @private
  889. */
  890. IntersectionObserver.prototype._computeTargetAndRootIntersection =
  891. function(target, rootRect) {
  892. // If the element isn't displayed, an intersection can't happen.
  893. if (window.getComputedStyle(target).display == 'none') return;
  894. var targetRect = getBoundingClientRect(target);
  895. var intersectionRect = targetRect;
  896. var parent = getParentNode(target);
  897. var atRoot = false;
  898. while (!atRoot) {
  899. var parentRect = null;
  900. var parentComputedStyle = parent.nodeType == 1 ?
  901. window.getComputedStyle(parent) : {};
  902. // If the parent isn't displayed, an intersection can't happen.
  903. if (parentComputedStyle.display == 'none') return;
  904. if (parent == this.root || parent == document) {
  905. atRoot = true;
  906. parentRect = rootRect;
  907. } else {
  908. // If the element has a non-visible overflow, and it's not the <body>
  909. // or <html> element, update the intersection rect.
  910. // Note: <body> and <html> cannot be clipped to a rect that's not also
  911. // the document rect, so no need to compute a new intersection.
  912. if (parent != document.body &&
  913. parent != document.documentElement &&
  914. parentComputedStyle.overflow != 'visible') {
  915. parentRect = getBoundingClientRect(parent);
  916. }
  917. }
  918. // If either of the above conditionals set a new parentRect,
  919. // calculate new intersection data.
  920. if (parentRect) {
  921. intersectionRect = computeRectIntersection(parentRect, intersectionRect);
  922. if (!intersectionRect) break;
  923. }
  924. parent = getParentNode(parent);
  925. }
  926. return intersectionRect;
  927. };
  928. /**
  929. * Returns the root rect after being expanded by the rootMargin value.
  930. * @return {Object} The expanded root rect.
  931. * @private
  932. */
  933. IntersectionObserver.prototype._getRootRect = function() {
  934. var rootRect;
  935. if (this.root) {
  936. rootRect = getBoundingClientRect(this.root);
  937. } else {
  938. // Use <html>/<body> instead of window since scroll bars affect size.
  939. var html = document.documentElement;
  940. var body = document.body;
  941. rootRect = {
  942. top: 0,
  943. left: 0,
  944. right: html.clientWidth || body.clientWidth,
  945. width: html.clientWidth || body.clientWidth,
  946. bottom: html.clientHeight || body.clientHeight,
  947. height: html.clientHeight || body.clientHeight
  948. };
  949. }
  950. return this._expandRectByRootMargin(rootRect);
  951. };
  952. /**
  953. * Accepts a rect and expands it by the rootMargin value.
  954. * @param {Object} rect The rect object to expand.
  955. * @return {Object} The expanded rect.
  956. * @private
  957. */
  958. IntersectionObserver.prototype._expandRectByRootMargin = function(rect) {
  959. var margins = this._rootMarginValues.map(function(margin, i) {
  960. return margin.unit == 'px' ? margin.value :
  961. margin.value * (i % 2 ? rect.width : rect.height) / 100;
  962. });
  963. var newRect = {
  964. top: rect.top - margins[0],
  965. right: rect.right + margins[1],
  966. bottom: rect.bottom + margins[2],
  967. left: rect.left - margins[3]
  968. };
  969. newRect.width = newRect.right - newRect.left;
  970. newRect.height = newRect.bottom - newRect.top;
  971. return newRect;
  972. };
  973. /**
  974. * Accepts an old and new entry and returns true if at least one of the
  975. * threshold values has been crossed.
  976. * @param {?IntersectionObserverEntry} oldEntry The previous entry for a
  977. * particular target element or null if no previous entry exists.
  978. * @param {IntersectionObserverEntry} newEntry The current entry for a
  979. * particular target element.
  980. * @return {boolean} Returns true if a any threshold has been crossed.
  981. * @private
  982. */
  983. IntersectionObserver.prototype._hasCrossedThreshold =
  984. function(oldEntry, newEntry) {
  985. // To make comparing easier, an entry that has a ratio of 0
  986. // but does not actually intersect is given a value of -1
  987. var oldRatio = oldEntry && oldEntry.isIntersecting ?
  988. oldEntry.intersectionRatio || 0 : -1;
  989. var newRatio = newEntry.isIntersecting ?
  990. newEntry.intersectionRatio || 0 : -1;
  991. // Ignore unchanged ratios
  992. if (oldRatio === newRatio) return;
  993. for (var i = 0; i < this.thresholds.length; i++) {
  994. var threshold = this.thresholds[i];
  995. // Return true if an entry matches a threshold or if the new ratio
  996. // and the old ratio are on the opposite sides of a threshold.
  997. if (threshold == oldRatio || threshold == newRatio ||
  998. threshold < oldRatio !== threshold < newRatio) {
  999. return true;
  1000. }
  1001. }
  1002. };
  1003. /**
  1004. * Returns whether or not the root element is an element and is in the DOM.
  1005. * @return {boolean} True if the root element is an element and is in the DOM.
  1006. * @private
  1007. */
  1008. IntersectionObserver.prototype._rootIsInDom = function() {
  1009. return !this.root || containsDeep(document, this.root);
  1010. };
  1011. /**
  1012. * Returns whether or not the target element is a child of root.
  1013. * @param {Element} target The target element to check.
  1014. * @return {boolean} True if the target element is a child of root.
  1015. * @private
  1016. */
  1017. IntersectionObserver.prototype._rootContainsTarget = function(target) {
  1018. return containsDeep(this.root || document, target);
  1019. };
  1020. /**
  1021. * Adds the instance to the global IntersectionObserver registry if it isn't
  1022. * already present.
  1023. * @private
  1024. */
  1025. IntersectionObserver.prototype._registerInstance = function() {
  1026. if (registry.indexOf(this) < 0) {
  1027. registry.push(this);
  1028. }
  1029. };
  1030. /**
  1031. * Removes the instance from the global IntersectionObserver registry.
  1032. * @private
  1033. */
  1034. IntersectionObserver.prototype._unregisterInstance = function() {
  1035. var index = registry.indexOf(this);
  1036. if (index != -1) registry.splice(index, 1);
  1037. };
  1038. /**
  1039. * Returns the result of the performance.now() method or null in browsers
  1040. * that don't support the API.
  1041. * @return {number} The elapsed time since the page was requested.
  1042. */
  1043. function now() {
  1044. return window.performance && performance.now && performance.now();
  1045. }
  1046. /**
  1047. * Throttles a function and delays its execution, so it's only called at most
  1048. * once within a given time period.
  1049. * @param {Function} fn The function to throttle.
  1050. * @param {number} timeout The amount of time that must pass before the
  1051. * function can be called again.
  1052. * @return {Function} The throttled function.
  1053. */
  1054. function throttle(fn, timeout) {
  1055. var timer = null;
  1056. return function () {
  1057. if (!timer) {
  1058. timer = setTimeout(function() {
  1059. fn();
  1060. timer = null;
  1061. }, timeout);
  1062. }
  1063. };
  1064. }
  1065. /**
  1066. * Adds an event handler to a DOM node ensuring cross-browser compatibility.
  1067. * @param {Node} node The DOM node to add the event handler to.
  1068. * @param {string} event The event name.
  1069. * @param {Function} fn The event handler to add.
  1070. * @param {boolean} opt_useCapture Optionally adds the even to the capture
  1071. * phase. Note: this only works in modern browsers.
  1072. */
  1073. function addEvent(node, event, fn, opt_useCapture) {
  1074. if (typeof node.addEventListener == 'function') {
  1075. node.addEventListener(event, fn, opt_useCapture || false);
  1076. }
  1077. else if (typeof node.attachEvent == 'function') {
  1078. node.attachEvent('on' + event, fn);
  1079. }
  1080. }
  1081. /**
  1082. * Removes a previously added event handler from a DOM node.
  1083. * @param {Node} node The DOM node to remove the event handler from.
  1084. * @param {string} event The event name.
  1085. * @param {Function} fn The event handler to remove.
  1086. * @param {boolean} opt_useCapture If the event handler was added with this
  1087. * flag set to true, it should be set to true here in order to remove it.
  1088. */
  1089. function removeEvent(node, event, fn, opt_useCapture) {
  1090. if (typeof node.removeEventListener == 'function') {
  1091. node.removeEventListener(event, fn, opt_useCapture || false);
  1092. }
  1093. else if (typeof node.detatchEvent == 'function') {
  1094. node.detatchEvent('on' + event, fn);
  1095. }
  1096. }
  1097. /**
  1098. * Returns the intersection between two rect objects.
  1099. * @param {Object} rect1 The first rect.
  1100. * @param {Object} rect2 The second rect.
  1101. * @return {?Object} The intersection rect or undefined if no intersection
  1102. * is found.
  1103. */
  1104. function computeRectIntersection(rect1, rect2) {
  1105. var top = Math.max(rect1.top, rect2.top);
  1106. var bottom = Math.min(rect1.bottom, rect2.bottom);
  1107. var left = Math.max(rect1.left, rect2.left);
  1108. var right = Math.min(rect1.right, rect2.right);
  1109. var width = right - left;
  1110. var height = bottom - top;
  1111. return (width >= 0 && height >= 0) && {
  1112. top: top,
  1113. bottom: bottom,
  1114. left: left,
  1115. right: right,
  1116. width: width,
  1117. height: height
  1118. };
  1119. }
  1120. /**
  1121. * Shims the native getBoundingClientRect for compatibility with older IE.
  1122. * @param {Element} el The element whose bounding rect to get.
  1123. * @return {Object} The (possibly shimmed) rect of the element.
  1124. */
  1125. function getBoundingClientRect(el) {
  1126. var rect;
  1127. try {
  1128. rect = el.getBoundingClientRect();
  1129. } catch (err) {
  1130. // Ignore Windows 7 IE11 "Unspecified error"
  1131. // https://github.com/w3c/IntersectionObserver/pull/205
  1132. }
  1133. if (!rect) return getEmptyRect();
  1134. // Older IE
  1135. if (!(rect.width && rect.height)) {
  1136. rect = {
  1137. top: rect.top,
  1138. right: rect.right,
  1139. bottom: rect.bottom,
  1140. left: rect.left,
  1141. width: rect.right - rect.left,
  1142. height: rect.bottom - rect.top
  1143. };
  1144. }
  1145. return rect;
  1146. }
  1147. /**
  1148. * Returns an empty rect object. An empty rect is returned when an element
  1149. * is not in the DOM.
  1150. * @return {Object} The empty rect.
  1151. */
  1152. function getEmptyRect() {
  1153. return {
  1154. top: 0,
  1155. bottom: 0,
  1156. left: 0,
  1157. right: 0,
  1158. width: 0,
  1159. height: 0
  1160. };
  1161. }
  1162. /**
  1163. * Checks to see if a parent element contains a child element (including inside
  1164. * shadow DOM).
  1165. * @param {Node} parent The parent element.
  1166. * @param {Node} child The child element.
  1167. * @return {boolean} True if the parent node contains the child node.
  1168. */
  1169. function containsDeep(parent, child) {
  1170. var node = child;
  1171. while (node) {
  1172. if (node == parent) return true;
  1173. node = getParentNode(node);
  1174. }
  1175. return false;
  1176. }
  1177. /**
  1178. * Gets the parent node of an element or its host element if the parent node
  1179. * is a shadow root.
  1180. * @param {Node} node The node whose parent to get.
  1181. * @return {Node|null} The parent node or null if no parent exists.
  1182. */
  1183. function getParentNode(node) {
  1184. var parent = node.parentNode;
  1185. if (parent && parent.nodeType == 11 && parent.host) {
  1186. // If the parent is a shadow root, return the host element.
  1187. return parent.host;
  1188. }
  1189. if (parent && parent.assignedSlot) {
  1190. // If the parent is distributed in a <slot>, return the parent of a slot.
  1191. return parent.assignedSlot.parentNode;
  1192. }
  1193. return parent;
  1194. }
  1195. // Exposes the constructors globally.
  1196. window.IntersectionObserver = IntersectionObserver;
  1197. window.IntersectionObserverEntry = IntersectionObserverEntry;
  1198. }(window, document));
  1199. }
  1200. if (!("getOwnPropertyDescriptor"in Object&&"function"==typeof Object.getOwnPropertyDescriptor&&function(){try{return"3"===Object.getOwnPropertyDescriptor("13.7",1).value}catch(t){return!1}}()
  1201. )) {
  1202. // Object.getOwnPropertyDescriptor
  1203. /* global CreateMethodProperty, ToObject, ToPropertyKey, HasOwnProperty, Type */
  1204. (function () {
  1205. var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  1206. var supportsDOMDescriptors = (function () {
  1207. try {
  1208. return Object.defineProperty(document.createElement('div'), 'one', {
  1209. get: function () {
  1210. return 1;
  1211. }
  1212. }).one === 1;
  1213. } catch (e) {
  1214. return false;
  1215. }
  1216. });
  1217. var toString = ({}).toString;
  1218. var split = ''.split;
  1219. // 19.1.2.8 Object.getOwnPropertyDescriptor ( O, P )
  1220. CreateMethodProperty(Object, 'getOwnPropertyDescriptor', function getOwnPropertyDescriptor(O, P) {
  1221. // 1. Let obj be ? ToObject(O).
  1222. var obj = ToObject(O);
  1223. // Polyfill.io fallback for non-array-like strings which exist in some ES3 user-agents (IE 8)
  1224. obj = (Type(obj) === 'string' || obj instanceof String) && toString.call(O) == '[object String]' ? split.call(O, '') : Object(O);
  1225. // 2. Let key be ? ToPropertyKey(P).
  1226. var key = ToPropertyKey(P);
  1227. // 3. Let desc be ? obj.[[GetOwnProperty]](key).
  1228. // 4. Return FromPropertyDescriptor(desc).
  1229. // Polyfill.io Internet Explorer 8 natively supports property descriptors only on DOM objects.
  1230. // We will fallback to the polyfill implementation if the native implementation throws an error.
  1231. if (supportsDOMDescriptors) {
  1232. try {
  1233. return nativeGetOwnPropertyDescriptor(obj, key);
  1234. // eslint-disable-next-line no-empty
  1235. } catch (error) {}
  1236. }
  1237. if (HasOwnProperty(obj, key)) {
  1238. return {
  1239. enumerable: true,
  1240. configurable: true,
  1241. writable: true,
  1242. value: obj[key]
  1243. };
  1244. }
  1245. });
  1246. }());
  1247. }
  1248. if (!("keys"in Object&&function(){return 2===Object.keys(arguments).length}(1,2)&&function(){try{return Object.keys(""),!0}catch(t){return!1}}()
  1249. )) {
  1250. // Object.keys
  1251. /* global CreateMethodProperty */
  1252. CreateMethodProperty(Object, "keys", (function() {
  1253. 'use strict';
  1254. // modified from https://github.com/es-shims/object-keys
  1255. var has = Object.prototype.hasOwnProperty;
  1256. var toStr = Object.prototype.toString;
  1257. var isEnumerable = Object.prototype.propertyIsEnumerable;
  1258. var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
  1259. var hasPrototypeEnumBug = isEnumerable.call(function () { }, 'prototype');
  1260. function hasProtoEnumBug() {
  1261. // Object.create polyfill creates an enumerable __proto__
  1262. var createdObj;
  1263. try {
  1264. createdObj = Object.create({});
  1265. } catch (e) {
  1266. // If this fails the polyfil isn't loaded yet, but will be.
  1267. // Can't add it to depedencies because of it would create a circular depedency.
  1268. return true;
  1269. }
  1270. return isEnumerable.call(createdObj, '__proto__')
  1271. }
  1272. var dontEnums = [
  1273. 'toString',
  1274. 'toLocaleString',
  1275. 'valueOf',
  1276. 'hasOwnProperty',
  1277. 'isPrototypeOf',
  1278. 'propertyIsEnumerable',
  1279. 'constructor'
  1280. ];
  1281. var equalsConstructorPrototype = function (o) {
  1282. var ctor = o.constructor;
  1283. return ctor && ctor.prototype === o;
  1284. };
  1285. var excludedKeys = {
  1286. $console: true,
  1287. $external: true,
  1288. $frame: true,
  1289. $frameElement: true,
  1290. $frames: true,
  1291. $innerHeight: true,
  1292. $innerWidth: true,
  1293. $outerHeight: true,
  1294. $outerWidth: true,
  1295. $pageXOffset: true,
  1296. $pageYOffset: true,
  1297. $parent: true,
  1298. $scrollLeft: true,
  1299. $scrollTop: true,
  1300. $scrollX: true,
  1301. $scrollY: true,
  1302. $self: true,
  1303. $webkitIndexedDB: true,
  1304. $webkitStorageInfo: true,
  1305. $window: true
  1306. };
  1307. var hasAutomationEqualityBug = (function () {
  1308. if (typeof window === 'undefined') { return false; }
  1309. for (var k in window) {
  1310. try {
  1311. if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
  1312. try {
  1313. equalsConstructorPrototype(window[k]);
  1314. } catch (e) {
  1315. return true;
  1316. }
  1317. }
  1318. } catch (e) {
  1319. return true;
  1320. }
  1321. }
  1322. return false;
  1323. }());
  1324. var equalsConstructorPrototypeIfNotBuggy = function (o) {
  1325. if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
  1326. return equalsConstructorPrototype(o);
  1327. }
  1328. try {
  1329. return equalsConstructorPrototype(o);
  1330. } catch (e) {
  1331. return false;
  1332. }
  1333. };
  1334. function isArgumentsObject(value) {
  1335. var str = toStr.call(value);
  1336. var isArgs = str === '[object Arguments]';
  1337. if (!isArgs) {
  1338. isArgs = str !== '[object Array]' &&
  1339. value !== null &&
  1340. typeof value === 'object' &&
  1341. typeof value.length === 'number' &&
  1342. value.length >= 0 &&
  1343. toStr.call(value.callee) === '[object Function]';
  1344. }
  1345. return isArgs;
  1346. }
  1347. return function keys(object) {
  1348. var isFunction = toStr.call(object) === '[object Function]';
  1349. var isArguments = isArgumentsObject(object);
  1350. var isString = toStr.call(object) === '[object String]';
  1351. var theKeys = [];
  1352. if (object === undefined || object === null) {
  1353. throw new TypeError('Cannot convert undefined or null to object');
  1354. }
  1355. var skipPrototype = hasPrototypeEnumBug && isFunction;
  1356. if (isString && object.length > 0 && !has.call(object, 0)) {
  1357. for (var i = 0; i < object.length; ++i) {
  1358. theKeys.push(String(i));
  1359. }
  1360. }
  1361. if (isArguments && object.length > 0) {
  1362. for (var j = 0; j < object.length; ++j) {
  1363. theKeys.push(String(j));
  1364. }
  1365. } else {
  1366. for (var name in object) {
  1367. if (!(hasProtoEnumBug() && name === '__proto__') && !(skipPrototype && name === 'prototype') && has.call(object, name)) {
  1368. theKeys.push(String(name));
  1369. }
  1370. }
  1371. }
  1372. if (hasDontEnumBug) {
  1373. var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
  1374. for (var k = 0; k < dontEnums.length; ++k) {
  1375. if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
  1376. theKeys.push(dontEnums[k]);
  1377. }
  1378. }
  1379. }
  1380. return theKeys;
  1381. };
  1382. }()));
  1383. }
  1384. if (!("assign"in Object
  1385. )) {
  1386. // Object.assign
  1387. /* global CreateMethodProperty, Get, ToObject */
  1388. // 19.1.2.1 Object.assign ( target, ...sources )
  1389. CreateMethodProperty(Object, 'assign', function assign(target, source) { // eslint-disable-line no-unused-vars
  1390. // 1. Let to be ? ToObject(target).
  1391. var to = ToObject(target);
  1392. // 2. If only one argument was passed, return to.
  1393. if (arguments.length === 1) {
  1394. return to;
  1395. }
  1396. // 3. Let sources be the List of argument values starting with the second argument
  1397. var sources = Array.prototype.slice.call(arguments, 1);
  1398. // 4. For each element nextSource of sources, in ascending index order, do
  1399. var index1;
  1400. var index2;
  1401. var keys;
  1402. var from;
  1403. for (index1 = 0; index1 < sources.length; index1++) {
  1404. var nextSource = sources[index1];
  1405. // a. If nextSource is undefined or null, let keys be a new empty List.
  1406. if (nextSource === undefined || nextSource === null) {
  1407. keys = [];
  1408. // b. Else,
  1409. } else {
  1410. // Polyfill.io - In order to get strings in ES3 and old V8 working correctly we need to split them into an array ourselves.
  1411. // i. Let from be ! ToObject(nextSource).
  1412. from = Object.prototype.toString.call(nextSource) === '[object String]' ? String(nextSource).split('') : ToObject(nextSource);
  1413. // ii. Let keys be ? from.[[OwnPropertyKeys]]().
  1414. /*
  1415. This step in our polyfill is not complying with the specification.
  1416. [[OwnPropertyKeys]] is meant to return ALL keys, including non-enumerable and symbols.
  1417. TODO: When we have Reflect.ownKeys, use that instead as it is the userland equivalent of [[OwnPropertyKeys]].
  1418. */
  1419. keys = Object.keys(from);
  1420. }
  1421. // c. For each element nextKey of keys in List order, do
  1422. for (index2 = 0; index2 < keys.length; index2++) {
  1423. var nextKey = keys[index2];
  1424. var enumerable;
  1425. try {
  1426. // i. Let desc be ? from.[[GetOwnProperty]](nextKey).
  1427. var desc = Object.getOwnPropertyDescriptor(from, nextKey);
  1428. // ii. If desc is not undefined and desc.[[Enumerable]] is true, then
  1429. enumerable = desc !== undefined && desc.enumerable === true;
  1430. } catch (e) {
  1431. // Polyfill.io - We use Object.prototype.propertyIsEnumerable as a fallback
  1432. // because `Object.getOwnPropertyDescriptor(window.location, 'hash')` causes Internet Explorer 11 to crash.
  1433. enumerable = Object.prototype.propertyIsEnumerable.call(from, nextKey);
  1434. }
  1435. if (enumerable) {
  1436. // 1. Let propValue be ? Get(from, nextKey).
  1437. var propValue = Get(from, nextKey);
  1438. // 2. Perform ? Set(to, nextKey, propValue, true).
  1439. to[nextKey] = propValue;
  1440. }
  1441. }
  1442. }
  1443. // 5. Return to.
  1444. return to;
  1445. });
  1446. }
  1447. })
  1448. ('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});