Merge pull request #11318 from Snuffleupagus/IE-polyfill-pushState-replaceState
[PDFHistory] Move the IE11 `pushState`/`replaceState` work-around to `src/shared/compatibility.js` (PR 10461 follow-up)
This commit is contained in:
commit
3a05f6fe25
@ -25,6 +25,9 @@ globalScope._pdfjsCompatibilityChecked = true;
|
||||
const { isNodeJS, } = require('./is_node');
|
||||
|
||||
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() {
|
||||
@ -112,6 +115,26 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
|
||||
};
|
||||
})();
|
||||
|
||||
// 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() {
|
||||
|
@ -306,18 +306,10 @@ class PDFHistory {
|
||||
}
|
||||
}
|
||||
if (shouldReplace) {
|
||||
if (newUrl) {
|
||||
window.history.replaceState(newState, '', newUrl);
|
||||
} else {
|
||||
window.history.replaceState(newState, '');
|
||||
}
|
||||
window.history.replaceState(newState, '', newUrl);
|
||||
} else {
|
||||
this._maxUid = this._uid;
|
||||
if (newUrl) {
|
||||
window.history.pushState(newState, '', newUrl);
|
||||
} else {
|
||||
window.history.pushState(newState, '');
|
||||
}
|
||||
window.history.pushState(newState, '', newUrl);
|
||||
}
|
||||
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME') &&
|
||||
|
Loading…
Reference in New Issue
Block a user