PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/memo-leonardo/src/main/resources/map/polyfill.js

https://gitlab.com/geekysquirrel/memo
JavaScript | 507 lines | 398 code | 73 blank | 36 comment | 75 complexity | 7818ba11bec6635d1205e6779ada55a7 MD5 | raw file
  1. /* Polyfill service v3.16.0-0
  2. * For detailed credits and licence information see https://github.com/financial-times/polyfill-service.
  3. *
  4. * UA detected: chrome/10.0.0
  5. * Features requested: Element.prototype.classList,URL,requestAnimationFrame
  6. *
  7. * - URL, License: CC0
  8. * - performance.now, License: CC0 (required by "requestAnimationFrame")
  9. * - requestAnimationFrame, License: MIT */
  10. (function(undefined) {
  11. // URL
  12. // URL Polyfill
  13. // Draft specification: https://url.spec.whatwg.org
  14. // Notes:
  15. // - Primarily useful for parsing URLs and modifying query parameters
  16. // - Should work in IE8+ and everything more modern
  17. (function (global) {
  18. 'use strict';
  19. // Browsers may have:
  20. // * No global URL object
  21. // * URL with static methods only - may have a dummy constructor
  22. // * URL with members except searchParams
  23. // * Full URL API support
  24. var origURL = global.URL;
  25. var nativeURL;
  26. try {
  27. if (origURL) {
  28. nativeURL = new global.URL('http://example.com');
  29. if ('searchParams' in nativeURL)
  30. return;
  31. if (!('href' in nativeURL))
  32. nativeURL = undefined;
  33. }
  34. } catch (_) {}
  35. // NOTE: Doesn't do the encoding/decoding dance
  36. function urlencoded_serialize(pairs) {
  37. var output = '', first = true;
  38. pairs.forEach(function (pair) {
  39. var name = encodeURIComponent(pair.name);
  40. var value = encodeURIComponent(pair.value);
  41. if (!first) output += '&';
  42. output += name + '=' + value;
  43. first = false;
  44. });
  45. return output.replace(/%20/g, '+');
  46. }
  47. // NOTE: Doesn't do the encoding/decoding dance
  48. function urlencoded_parse(input, isindex) {
  49. var sequences = input.split('&');
  50. if (isindex && sequences[0].indexOf('=') === -1)
  51. sequences[0] = '=' + sequences[0];
  52. var pairs = [];
  53. sequences.forEach(function (bytes) {
  54. if (bytes.length === 0) return;
  55. var index = bytes.indexOf('=');
  56. if (index !== -1) {
  57. var name = bytes.substring(0, index);
  58. var value = bytes.substring(index + 1);
  59. } else {
  60. name = bytes;
  61. value = '';
  62. }
  63. name = name.replace(/\+/g, ' ');
  64. value = value.replace(/\+/g, ' ');
  65. pairs.push({ name: name, value: value });
  66. });
  67. var output = [];
  68. pairs.forEach(function (pair) {
  69. output.push({
  70. name: decodeURIComponent(pair.name),
  71. value: decodeURIComponent(pair.value)
  72. });
  73. });
  74. return output;
  75. }
  76. function URLUtils(url) {
  77. if (nativeURL)
  78. return new origURL(url);
  79. var anchor = document.createElement('a');
  80. anchor.href = url;
  81. return anchor;
  82. }
  83. function URLSearchParams(init) {
  84. var $this = this;
  85. this._list = [];
  86. if (init === undefined || init === null)
  87. init = '';
  88. if (Object(init) !== init || !(init instanceof URLSearchParams))
  89. init = String(init);
  90. if (typeof init === 'string' && init.substring(0, 1) === '?')
  91. init = init.substring(1);
  92. if (typeof init === 'string')
  93. this._list = urlencoded_parse(init);
  94. else
  95. this._list = init._list.slice();
  96. this._url_object = null;
  97. this._setList = function (list) { if (!updating) $this._list = list; };
  98. var updating = false;
  99. this._update_steps = function() {
  100. if (updating) return;
  101. updating = true;
  102. if (!$this._url_object) return;
  103. // Partial workaround for IE issue with 'about:'
  104. if ($this._url_object.protocol === 'about:' &&
  105. $this._url_object.pathname.indexOf('?') !== -1) {
  106. $this._url_object.pathname = $this._url_object.pathname.split('?')[0];
  107. }
  108. $this._url_object.search = urlencoded_serialize($this._list);
  109. updating = false;
  110. };
  111. }
  112. Object.defineProperties(URLSearchParams.prototype, {
  113. append: {
  114. value: function (name, value) {
  115. this._list.push({ name: name, value: value });
  116. this._update_steps();
  117. }, writable: true, enumerable: true, configurable: true
  118. },
  119. 'delete': {
  120. value: function (name) {
  121. for (var i = 0; i < this._list.length;) {
  122. if (this._list[i].name === name)
  123. this._list.splice(i, 1);
  124. else
  125. ++i;
  126. }
  127. this._update_steps();
  128. }, writable: true, enumerable: true, configurable: true
  129. },
  130. get: {
  131. value: function (name) {
  132. for (var i = 0; i < this._list.length; ++i) {
  133. if (this._list[i].name === name)
  134. return this._list[i].value;
  135. }
  136. return null;
  137. }, writable: true, enumerable: true, configurable: true
  138. },
  139. getAll: {
  140. value: function (name) {
  141. var result = [];
  142. for (var i = 0; i < this._list.length; ++i) {
  143. if (this._list[i].name === name)
  144. result.push(this._list[i].value);
  145. }
  146. return result;
  147. }, writable: true, enumerable: true, configurable: true
  148. },
  149. has: {
  150. value: function (name) {
  151. for (var i = 0; i < this._list.length; ++i) {
  152. if (this._list[i].name === name)
  153. return true;
  154. }
  155. return false;
  156. }, writable: true, enumerable: true, configurable: true
  157. },
  158. set: {
  159. value: function (name, value) {
  160. var found = false;
  161. for (var i = 0; i < this._list.length;) {
  162. if (this._list[i].name === name) {
  163. if (!found) {
  164. this._list[i].value = value;
  165. found = true;
  166. ++i;
  167. } else {
  168. this._list.splice(i, 1);
  169. }
  170. } else {
  171. ++i;
  172. }
  173. }
  174. if (!found)
  175. this._list.push({ name: name, value: value });
  176. this._update_steps();
  177. }, writable: true, enumerable: true, configurable: true
  178. },
  179. entries: {
  180. value: function() {
  181. var $this = this, index = 0;
  182. return { next: function() {
  183. if (index >= $this._list.length)
  184. return {done: true, value: undefined};
  185. var pair = $this._list[index++];
  186. return {done: false, value: [pair.name, pair.value]};
  187. }};
  188. }, writable: true, enumerable: true, configurable: true
  189. },
  190. keys: {
  191. value: function() {
  192. var $this = this, index = 0;
  193. return { next: function() {
  194. if (index >= $this._list.length)
  195. return {done: true, value: undefined};
  196. var pair = $this._list[index++];
  197. return {done: false, value: pair.name};
  198. }};
  199. }, writable: true, enumerable: true, configurable: true
  200. },
  201. values: {
  202. value: function() {
  203. var $this = this, index = 0;
  204. return { next: function() {
  205. if (index >= $this._list.length)
  206. return {done: true, value: undefined};
  207. var pair = $this._list[index++];
  208. return {done: false, value: pair.value};
  209. }};
  210. }, writable: true, enumerable: true, configurable: true
  211. },
  212. forEach: {
  213. value: function(callback) {
  214. var thisArg = (arguments.length > 1) ? arguments[1] : undefined;
  215. this._list.forEach(function(pair, index) {
  216. callback.call(thisArg, pair.name, pair.value);
  217. });
  218. }, writable: true, enumerable: true, configurable: true
  219. },
  220. toString: {
  221. value: function () {
  222. return urlencoded_serialize(this._list);
  223. }, writable: true, enumerable: false, configurable: true
  224. }
  225. });
  226. if ('Symbol' in global && 'iterator' in global.Symbol) {
  227. Object.defineProperty(URLSearchParams.prototype, global.Symbol.iterator, {
  228. value: URLSearchParams.prototype.entries,
  229. writable: true, enumerable: true, configurable: true});
  230. }
  231. function URL(url, base) {
  232. if (!(this instanceof global.URL))
  233. throw new TypeError("Failed to construct 'URL': Please use the 'new' operator.");
  234. if (base) {
  235. url = (function () {
  236. if (nativeURL) return new origURL(url, base).href;
  237. var doc;
  238. // Use another document/base tag/anchor for relative URL resolution, if possible
  239. if (document.implementation && document.implementation.createHTMLDocument) {
  240. doc = document.implementation.createHTMLDocument('');
  241. } else if (document.implementation && document.implementation.createDocument) {
  242. doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
  243. doc.documentElement.appendChild(doc.createElement('head'));
  244. doc.documentElement.appendChild(doc.createElement('body'));
  245. } else if (window.ActiveXObject) {
  246. doc = new window.ActiveXObject('htmlfile');
  247. doc.write('<head><\/head><body><\/body>');
  248. doc.close();
  249. }
  250. if (!doc) throw Error('base not supported');
  251. var baseTag = doc.createElement('base');
  252. baseTag.href = base;
  253. doc.getElementsByTagName('head')[0].appendChild(baseTag);
  254. var anchor = doc.createElement('a');
  255. anchor.href = url;
  256. return anchor.href;
  257. }());
  258. }
  259. // An inner object implementing URLUtils (either a native URL
  260. // object or an HTMLAnchorElement instance) is used to perform the
  261. // URL algorithms. With full ES5 getter/setter support, return a
  262. // regular object For IE8's limited getter/setter support, a
  263. // different HTMLAnchorElement is returned with properties
  264. // overridden
  265. var instance = URLUtils(url || '');
  266. // Detect for ES5 getter/setter support
  267. // (an Object.defineProperties polyfill that doesn't support getters/setters may throw)
  268. var ES5_GET_SET = (function() {
  269. if (!('defineProperties' in Object)) return false;
  270. try {
  271. var obj = {};
  272. Object.defineProperties(obj, { prop: { 'get': function () { return true; } } });
  273. return obj.prop;
  274. } catch (_) {
  275. return false;
  276. }
  277. })();
  278. var self = ES5_GET_SET ? this : document.createElement('a');
  279. var query_object = new URLSearchParams(
  280. instance.search ? instance.search.substring(1) : null);
  281. query_object._url_object = self;
  282. Object.defineProperties(self, {
  283. href: {
  284. get: function () { return instance.href; },
  285. set: function (v) { instance.href = v; tidy_instance(); update_steps(); },
  286. enumerable: true, configurable: true
  287. },
  288. origin: {
  289. get: function () {
  290. if ('origin' in instance) return instance.origin;
  291. return this.protocol + '//' + this.host;
  292. },
  293. enumerable: true, configurable: true
  294. },
  295. protocol: {
  296. get: function () { return instance.protocol; },
  297. set: function (v) { instance.protocol = v; },
  298. enumerable: true, configurable: true
  299. },
  300. username: {
  301. get: function () { return instance.username; },
  302. set: function (v) { instance.username = v; },
  303. enumerable: true, configurable: true
  304. },
  305. password: {
  306. get: function () { return instance.password; },
  307. set: function (v) { instance.password = v; },
  308. enumerable: true, configurable: true
  309. },
  310. host: {
  311. get: function () {
  312. // IE returns default port in |host|
  313. var re = {'http:': /:80$/, 'https:': /:443$/, 'ftp:': /:21$/}[instance.protocol];
  314. return re ? instance.host.replace(re, '') : instance.host;
  315. },
  316. set: function (v) { instance.host = v; },
  317. enumerable: true, configurable: true
  318. },
  319. hostname: {
  320. get: function () { return instance.hostname; },
  321. set: function (v) { instance.hostname = v; },
  322. enumerable: true, configurable: true
  323. },
  324. port: {
  325. get: function () { return instance.port; },
  326. set: function (v) { instance.port = v; },
  327. enumerable: true, configurable: true
  328. },
  329. pathname: {
  330. get: function () {
  331. // IE does not include leading '/' in |pathname|
  332. if (instance.pathname.charAt(0) !== '/') return '/' + instance.pathname;
  333. return instance.pathname;
  334. },
  335. set: function (v) { instance.pathname = v; },
  336. enumerable: true, configurable: true
  337. },
  338. search: {
  339. get: function () { return instance.search; },
  340. set: function (v) {
  341. if (instance.search === v) return;
  342. instance.search = v; tidy_instance(); update_steps();
  343. },
  344. enumerable: true, configurable: true
  345. },
  346. searchParams: {
  347. get: function () { return query_object; },
  348. enumerable: true, configurable: true
  349. },
  350. hash: {
  351. get: function () { return instance.hash; },
  352. set: function (v) { instance.hash = v; tidy_instance(); },
  353. enumerable: true, configurable: true
  354. },
  355. toString: {
  356. value: function() { return instance.toString(); },
  357. enumerable: false, configurable: true
  358. },
  359. valueOf: {
  360. value: function() { return instance.valueOf(); },
  361. enumerable: false, configurable: true
  362. }
  363. });
  364. function tidy_instance() {
  365. var href = instance.href.replace(/#$|\?$|\?(?=#)/g, '');
  366. if (instance.href !== href)
  367. instance.href = href;
  368. }
  369. function update_steps() {
  370. query_object._setList(instance.search ? urlencoded_parse(instance.search.substring(1)) : []);
  371. query_object._update_steps();
  372. };
  373. return self;
  374. }
  375. if (origURL) {
  376. for (var i in origURL) {
  377. if (origURL.hasOwnProperty(i) && typeof origURL[i] === 'function')
  378. URL[i] = origURL[i];
  379. }
  380. }
  381. global.URL = URL;
  382. global.URLSearchParams = URLSearchParams;
  383. }(self));
  384. // performance.now
  385. (function (global) {
  386. var
  387. startTime = Date.now();
  388. if (!global.performance) {
  389. global.performance = {};
  390. }
  391. global.performance.now = function () {
  392. return Date.now() - startTime;
  393. };
  394. }(this));
  395. // requestAnimationFrame
  396. (function (global) {
  397. var rafPrefix;
  398. if ('mozRequestAnimationFrame' in global) {
  399. rafPrefix = 'moz';
  400. } else if ('webkitRequestAnimationFrame' in global) {
  401. rafPrefix = 'webkit';
  402. }
  403. if (rafPrefix) {
  404. global.requestAnimationFrame = function (callback) {
  405. return global[rafPrefix + 'RequestAnimationFrame'](function () {
  406. callback(performance.now());
  407. });
  408. };
  409. global.cancelAnimationFrame = global[rafPrefix + 'CancelAnimationFrame'];
  410. } else {
  411. var lastTime = Date.now();
  412. global.requestAnimationFrame = function (callback) {
  413. if (typeof callback !== 'function') {
  414. throw new TypeError(callback + ' is not a function');
  415. }
  416. var
  417. currentTime = Date.now(),
  418. delay = 16 + lastTime - currentTime;
  419. if (delay < 0) {
  420. delay = 0;
  421. }
  422. lastTime = currentTime;
  423. return setTimeout(function () {
  424. lastTime = Date.now();
  425. callback(performance.now());
  426. }, delay);
  427. };
  428. global.cancelAnimationFrame = function (id) {
  429. clearTimeout(id);
  430. };
  431. }
  432. }(this));
  433. })
  434. .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});