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

Add support for classList.toggle with the, optional, "force" parameter #10152

Merged
merged 2 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions src/shared/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
};
})();

// 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;
}
const originalDOMTokenListToggle = DOMTokenList.prototype.toggle;

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

// Provides support for String.prototype.includes in legacy browsers.
// Support: IE, Chrome<41
(function checkStringIncludes() {
Expand Down
14 changes: 4 additions & 10 deletions web/base_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,16 +1038,10 @@ class BaseViewer {
_updateScrollMode(pageNumber = null) {
const scrollMode = this._scrollMode, viewer = this.viewer;

if (scrollMode === ScrollMode.HORIZONTAL) {
viewer.classList.add('scrollHorizontal');
} else {
viewer.classList.remove('scrollHorizontal');
}
if (scrollMode === ScrollMode.WRAPPED) {
viewer.classList.add('scrollWrapped');
} else {
viewer.classList.remove('scrollWrapped');
}
viewer.classList.toggle('scrollHorizontal',
scrollMode === ScrollMode.HORIZONTAL);
viewer.classList.toggle('scrollWrapped',
scrollMode === ScrollMode.WRAPPED);

if (!this.pdfDocument || !pageNumber) {
return;
Expand Down
8 changes: 2 additions & 6 deletions web/pdf_find_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,9 @@ class PDFFindBar {
break;
}

if (notFound) {
this.findField.classList.add('notFound');
} else {
this.findField.classList.remove('notFound');
}

this.findField.classList.toggle('notFound', notFound);
this.findField.setAttribute('data-status', status);

Promise.resolve(findMsg).then((msg) => {
this.findMsg.textContent = msg;
this._adjustWidth();
Expand Down
8 changes: 4 additions & 4 deletions web/secondary_toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ class SecondaryToolbar {
// current `BaseViewer` instance (in particular `PDFSinglePageViewer`).
this.eventBus.on('baseviewerinit', (evt) => {
if (evt.source instanceof PDFSinglePageViewer) {
this.toolbarButtonContainer.classList.add('hiddenScrollModeButtons');
this.toolbarButtonContainer.classList.add('hiddenSpreadModeButtons');
this.toolbarButtonContainer.classList.add('hiddenScrollModeButtons',
'hiddenSpreadModeButtons');
} else {
this.toolbarButtonContainer.classList.remove('hiddenScrollModeButtons');
this.toolbarButtonContainer.classList.remove('hiddenSpreadModeButtons');
this.toolbarButtonContainer.classList.remove('hiddenScrollModeButtons',
'hiddenSpreadModeButtons');
}
});
}
Expand Down
6 changes: 1 addition & 5 deletions web/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,7 @@ class Toolbar {
updateLoadingIndicatorState(loading = false) {
let pageNumberInput = this.items.pageNumber;

if (loading) {
pageNumberInput.classList.add(PAGE_NUMBER_LOADING_INDICATOR);
} else {
pageNumberInput.classList.remove(PAGE_NUMBER_LOADING_INDICATOR);
}
pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
}

_adjustScaleWidth() {
Expand Down