Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove, manually implemented, DOM polyfills only necessary for IE 11 support #12336

Merged
merged 1 commit into from
Sep 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 0 additions & 92 deletions src/shared/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ if (
}
globalThis._pdfjsCompatibilityChecked = true;

const hasDOM = typeof window === "object" && typeof document === "object";
const userAgent =
(typeof navigator !== "undefined" && navigator.userAgent) || "";
const isIE = /Trident/.test(userAgent);

// Support: Node.js
(function checkNodeBtoa() {
if (globalThis.btoa || !isNodeJS) {
Expand All @@ -56,93 +51,6 @@ if (
};
})();

// Provides support for ChildNode.remove in legacy browsers.
// Support: IE.
(function checkChildNodeRemove() {
if (!hasDOM) {
return;
}
if (typeof Element.prototype.remove !== "undefined") {
return;
}
Element.prototype.remove = function () {
if (this.parentNode) {
// eslint-disable-next-line mozilla/avoid-removeChild
this.parentNode.removeChild(this);
}
};
})();

// Provides support for DOMTokenList.prototype.{add, remove}, with more than
// one parameter, in legacy browsers.
// Support: IE
(function checkDOMTokenListAddRemove() {
if (!hasDOM || isNodeJS) {
return;
}
const div = document.createElement("div");
div.classList.add("testOne", "testTwo");

if (
div.classList.contains("testOne") === true &&
div.classList.contains("testTwo") === true
) {
return;
}
const OriginalDOMTokenListAdd = DOMTokenList.prototype.add;
const OriginalDOMTokenListRemove = DOMTokenList.prototype.remove;

DOMTokenList.prototype.add = function (...tokens) {
for (const token of tokens) {
OriginalDOMTokenListAdd.call(this, token);
}
};
DOMTokenList.prototype.remove = function (...tokens) {
for (const token of tokens) {
OriginalDOMTokenListRemove.call(this, token);
}
};
})();

// Provides support for DOMTokenList.prototype.toggle, with the optional
// "force" parameter, in legacy browsers.
// Support: IE
(function checkDOMTokenListToggle() {
if (!hasDOM || isNodeJS) {
return;
}
const div = document.createElement("div");
if (div.classList.toggle("test", 0) === false) {
return;
}

DOMTokenList.prototype.toggle = function (token) {
const force =
arguments.length > 1 ? !!arguments[1] : !this.contains(token);
return this[force ? "add" : "remove"](token), force;
};
})();

// Provides support for window.history.{pushState, replaceState}, with the
// `url` parameter set to `undefined`, without breaking the document URL.
// Support: IE
(function checkWindowHistoryPushStateReplaceState() {
if (!hasDOM || !isIE) {
return;
}
const OriginalPushState = window.history.pushState;
const OriginalReplaceState = window.history.replaceState;

window.history.pushState = function (state, title, url) {
const args = url === undefined ? [state, title] : [state, title, url];
OriginalPushState.apply(this, args);
};
window.history.replaceState = function (state, title, url) {
const args = url === undefined ? [state, title] : [state, title, url];
OriginalReplaceState.apply(this, args);
};
})();

// Provides support for String.prototype.startsWith in legacy browsers.
// Support: IE, Chrome<41
(function checkStringStartsWith() {
Expand Down