diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /app/assets/javascripts/commons | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'app/assets/javascripts/commons')
7 files changed, 21 insertions, 190 deletions
diff --git a/app/assets/javascripts/commons/polyfills.js b/app/assets/javascripts/commons/polyfills.js index fdeb64a7644..655109bad9a 100644 --- a/app/assets/javascripts/commons/polyfills.js +++ b/app/assets/javascripts/commons/polyfills.js @@ -1,27 +1,24 @@ -// Browser polyfills - -/** - * Polyfill: fetch - * @what https://fetch.spec.whatwg.org/ - * @why Because Apollo GraphQL client relies on fetch - * @browsers Internet Explorer 11 - * @see https://caniuse.com/#feat=fetch - */ -import 'unfetch/polyfill/index'; - /** - * Polyfill: FormData APIs - * @what delete(), get(), getAll(), has(), set(), entries(), keys(), values(), - * and support for for...of - * @why Because Apollo GraphQL client relies on fetch - * @browsers Internet Explorer 11, Edge < 18 - * @see https://caniuse.com/#feat=mdn-api_formdata and subfeatures + * Polyfill + * @what requestIdleCallback + * @why To align browser features + * @browsers Safari (all versions) + * @see https://caniuse.com/#feat=requestidlecallback */ -import 'formdata-polyfill'; +window.requestIdleCallback = + window.requestIdleCallback || + function requestShim(cb) { + const start = Date.now(); + return setTimeout(() => { + cb({ + didTimeout: false, + timeRemaining: () => Math.max(0, 50 - (Date.now() - start)), + }); + }, 1); + }; -import './polyfills/custom_event'; -import './polyfills/element'; -import './polyfills/event'; -import './polyfills/nodelist'; -import './polyfills/request_idle_callback'; -import './polyfills/svg'; +window.cancelIdleCallback = + window.cancelIdleCallback || + function cancelShim(id) { + clearTimeout(id); + }; diff --git a/app/assets/javascripts/commons/polyfills/custom_event.js b/app/assets/javascripts/commons/polyfills/custom_event.js deleted file mode 100644 index 6b14eff6f05..00000000000 --- a/app/assets/javascripts/commons/polyfills/custom_event.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Polyfill: CustomEvent constructor - * @what new CustomEvent() - * @why Certain features, e.g. notes utilize this - * @browsers Internet Explorer 11 - * @see https://caniuse.com/#feat=customevent - */ -if (typeof window.CustomEvent !== 'function') { - window.CustomEvent = function CustomEvent(event, params) { - const evt = document.createEvent('CustomEvent'); - const evtParams = { - bubbles: false, - cancelable: false, - detail: undefined, - ...params, - }; - evt.initCustomEvent(event, evtParams.bubbles, evtParams.cancelable, evtParams.detail); - return evt; - }; - window.CustomEvent.prototype = Event; -} diff --git a/app/assets/javascripts/commons/polyfills/element.js b/app/assets/javascripts/commons/polyfills/element.js deleted file mode 100644 index b13ceccf511..00000000000 --- a/app/assets/javascripts/commons/polyfills/element.js +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Polyfill - * @what Element.classList - * @why In order to align browser features - * @browsers Internet Explorer 11 - * @see https://caniuse.com/#feat=classlist - */ -import 'classlist-polyfill'; - -/** - * Polyfill - * @what Element.closest - * @why In order to align browser features - * @browsers Internet Explorer 11 - * @see https://caniuse.com/#feat=element-closest - */ -Element.prototype.closest = - Element.prototype.closest || - function closest(selector, selectedElement = this) { - if (!selectedElement) return null; - return selectedElement.matches(selector) - ? selectedElement - : Element.prototype.closest(selector, selectedElement.parentElement); - }; - -/** - * Polyfill - * @what Element.matches - * @why In order to align browser features - * @browsers Internet Explorer 11 - * @see https://caniuse.com/#feat=mdn-api_element_matches - */ -Element.prototype.matches = - Element.prototype.matches || - Element.prototype.matchesSelector || - Element.prototype.mozMatchesSelector || - Element.prototype.msMatchesSelector || - Element.prototype.oMatchesSelector || - Element.prototype.webkitMatchesSelector || - function matches(selector) { - const elms = (this.document || this.ownerDocument).querySelectorAll(selector); - let i = elms.length - 1; - while (i >= 0 && elms.item(i) !== this) { - i -= 1; - } - return i > -1; - }; - -/** - * Polyfill - * @what ChildNode.remove, Element.remove, CharacterData.remove, DocumentType.remove - * @why In order to align browser features - * @browsers Internet Explorer 11 - * @see https://caniuse.com/#feat=childnode-remove - * - * From the polyfill on MDN, https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove#Polyfill - */ -(arr => { - arr.forEach(item => { - if (Object.prototype.hasOwnProperty.call(item, 'remove')) { - return; - } - Object.defineProperty(item, 'remove', { - configurable: true, - enumerable: true, - writable: true, - value: function remove() { - if (this.parentNode !== null) { - this.parentNode.removeChild(this); - } - }, - }); - }); -})([Element.prototype, CharacterData.prototype, DocumentType.prototype]); diff --git a/app/assets/javascripts/commons/polyfills/event.js b/app/assets/javascripts/commons/polyfills/event.js deleted file mode 100644 index 543dd5f9a93..00000000000 --- a/app/assets/javascripts/commons/polyfills/event.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Polyfill: Event constructor - * @what new Event() - * @why To align browser support - * @browsers Internet Explorer 11 - * @see https://caniuse.com/#feat=mdn-api_event_event - * - * Although `initEvent` is deprecated for modern browsers it is the one supported by IE - */ -if (typeof window.Event !== 'function') { - window.Event = function Event(event, params) { - const evt = document.createEvent('Event'); - const evtParams = { - bubbles: false, - cancelable: false, - ...params, - }; - evt.initEvent(event, evtParams.bubbles, evtParams.cancelable); - return evt; - }; - window.Event.prototype = Event; -} diff --git a/app/assets/javascripts/commons/polyfills/nodelist.js b/app/assets/javascripts/commons/polyfills/nodelist.js deleted file mode 100644 index 3a9111e64f8..00000000000 --- a/app/assets/javascripts/commons/polyfills/nodelist.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Polyfill - * @what NodeList.forEach - * @why To align browser support - * @browsers Internet Explorer 11 - * @see https://caniuse.com/#feat=mdn-api_nodelist_foreach - */ -if (window.NodeList && !NodeList.prototype.forEach) { - NodeList.prototype.forEach = function forEach(callback, thisArg = window) { - for (let i = 0; i < this.length; i += 1) { - callback.call(thisArg, this[i], i, this); - } - }; -} diff --git a/app/assets/javascripts/commons/polyfills/request_idle_callback.js b/app/assets/javascripts/commons/polyfills/request_idle_callback.js deleted file mode 100644 index 51dc82e593a..00000000000 --- a/app/assets/javascripts/commons/polyfills/request_idle_callback.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Polyfill - * @what requestIdleCallback - * @why To align browser features - * @browsers Safari (all versions), Internet Explorer 11 - * @see https://caniuse.com/#feat=requestidlecallback - */ -window.requestIdleCallback = - window.requestIdleCallback || - function requestShim(cb) { - const start = Date.now(); - return setTimeout(() => { - cb({ - didTimeout: false, - timeRemaining: () => Math.max(0, 50 - (Date.now() - start)), - }); - }, 1); - }; - -window.cancelIdleCallback = - window.cancelIdleCallback || - function cancelShim(id) { - clearTimeout(id); - }; diff --git a/app/assets/javascripts/commons/polyfills/svg.js b/app/assets/javascripts/commons/polyfills/svg.js deleted file mode 100644 index 92a8b03fbb4..00000000000 --- a/app/assets/javascripts/commons/polyfills/svg.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * polyfill support for external SVG file references via <use xlink:href> - * @what polyfill support for external SVG file references via <use xlink:href> - * @why This is used in our GitLab SVG icon library - * @browsers Internet Explorer 11 - * @see https://caniuse.com/#feat=mdn-svg_elements_use_external_uri - * @see https//css-tricks.com/svg-use-external-source/ - */ -import svg4everybody from 'svg4everybody'; - -svg4everybody(); |