Commit 0f6a8c46 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'leipert-polyfills-improvements' into 'master'

Polyfill fetch for Internet Explorer 11

See merge request gitlab-org/gitlab!26366
parents 1dfddd9e 046e75fd
// 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
*/
import 'formdata-polyfill';
import './polyfills/custom_event';
import './polyfills/element';
import './polyfills/event';
......
/**
* 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');
......
// polyfill Element.classList and DOMTokenList with classList.js
/**
* 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) {
......@@ -10,6 +23,13 @@ Element.prototype.closest =
: 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 ||
......@@ -26,7 +46,15 @@ Element.prototype.matches =
return i > -1;
};
// From the polyfill on MDN, https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove#Polyfill
/**
* 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')) {
......
/**
* Polyfill for IE11 support.
* new Event() is not supported by IE11.
* 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') {
......
/**
* 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) {
......
/**
* 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) {
......
/**
* 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';
// polyfill support for external SVG file references via <use xlink:href>
// @see https://css-tricks.com/svg-use-external-source/
svg4everybody();
---
title: Polyfill fetch for Internet Explorer 11
merge_request: 26366
author:
type: fixed
......@@ -11453,6 +11453,11 @@ underscore@~1.8.3:
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022"
integrity sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=
unfetch@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-4.1.0.tgz#6ec2dd0de887e58a4dee83a050ded80ffc4137db"
integrity sha512-crP/n3eAPUJxZXM9T80/yv0YhkTEx2K1D3h7D1AJM6fzsWZrxdyRuLN0JH/dkZh1LNH8LxCnBzoPFCPbb2iGpg==
unherit@^1.0.4:
version "1.1.1"
resolved "https://registry.yarnpkg.com/unherit/-/unherit-1.1.1.tgz#132748da3e88eab767e08fabfbb89c5e9d28628c"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment