mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes). Prettier is being used for a couple of reasons: - To be consistent with `mozilla-central`, where Prettier is already in use across the tree. - To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters. Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some). Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long. *Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit. (On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
This commit is contained in:
parent
8ec1dfde49
commit
de36b2aaba
205 changed files with 40024 additions and 31859 deletions
255
web/ui_utils.js
255
web/ui_utils.js
|
@ -15,9 +15,9 @@
|
|||
/* eslint no-var: error, prefer-const: error */
|
||||
|
||||
const CSS_UNITS = 96.0 / 72.0;
|
||||
const DEFAULT_SCALE_VALUE = 'auto';
|
||||
const DEFAULT_SCALE_VALUE = "auto";
|
||||
const DEFAULT_SCALE = 1.0;
|
||||
const MIN_SCALE = 0.10;
|
||||
const MIN_SCALE = 0.1;
|
||||
const MAX_SCALE = 10.0;
|
||||
const UNKNOWN_SCALE = 0;
|
||||
const MAX_AUTO_SCALE = 1.25;
|
||||
|
@ -32,8 +32,8 @@ const PresentationModeState = {
|
|||
};
|
||||
|
||||
const RendererType = {
|
||||
CANVAS: 'canvas',
|
||||
SVG: 'svg',
|
||||
CANVAS: "canvas",
|
||||
SVG: "svg",
|
||||
};
|
||||
|
||||
const TextLayerMode = {
|
||||
|
@ -62,7 +62,7 @@ function formatL10nValue(text, args) {
|
|||
return text;
|
||||
}
|
||||
return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
|
||||
return (name in args ? args[name] : '{{' + name + '}}');
|
||||
return name in args ? args[name] : "{{" + name + "}}";
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -72,18 +72,18 @@ function formatL10nValue(text, args) {
|
|||
*/
|
||||
const NullL10n = {
|
||||
async getLanguage() {
|
||||
return 'en-us';
|
||||
return "en-us";
|
||||
},
|
||||
|
||||
async getDirection() {
|
||||
return 'ltr';
|
||||
return "ltr";
|
||||
},
|
||||
|
||||
async get(property, args, fallback) {
|
||||
return formatL10nValue(fallback, args);
|
||||
},
|
||||
|
||||
async translate(element) { },
|
||||
async translate(element) {},
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -94,11 +94,13 @@ const NullL10n = {
|
|||
*/
|
||||
function getOutputScale(ctx) {
|
||||
const devicePixelRatio = window.devicePixelRatio || 1;
|
||||
const backingStoreRatio = ctx.webkitBackingStorePixelRatio ||
|
||||
ctx.mozBackingStorePixelRatio ||
|
||||
ctx.msBackingStorePixelRatio ||
|
||||
ctx.oBackingStorePixelRatio ||
|
||||
ctx.backingStorePixelRatio || 1;
|
||||
const backingStoreRatio =
|
||||
ctx.webkitBackingStorePixelRatio ||
|
||||
ctx.mozBackingStorePixelRatio ||
|
||||
ctx.msBackingStorePixelRatio ||
|
||||
ctx.oBackingStorePixelRatio ||
|
||||
ctx.backingStorePixelRatio ||
|
||||
1;
|
||||
const pixelRatio = devicePixelRatio / backingStoreRatio;
|
||||
return {
|
||||
sx: pixelRatio,
|
||||
|
@ -121,15 +123,17 @@ function scrollIntoView(element, spot, skipOverflowHiddenElements = false) {
|
|||
// producing the error. See also animationStarted.
|
||||
let parent = element.offsetParent;
|
||||
if (!parent) {
|
||||
console.error('offsetParent is not set -- cannot scroll');
|
||||
console.error("offsetParent is not set -- cannot scroll");
|
||||
return;
|
||||
}
|
||||
let offsetY = element.offsetTop + element.clientTop;
|
||||
let offsetX = element.offsetLeft + element.clientLeft;
|
||||
while ((parent.clientHeight === parent.scrollHeight &&
|
||||
parent.clientWidth === parent.scrollWidth) ||
|
||||
(skipOverflowHiddenElements &&
|
||||
getComputedStyle(parent).overflow === 'hidden')) {
|
||||
while (
|
||||
(parent.clientHeight === parent.scrollHeight &&
|
||||
parent.clientWidth === parent.scrollWidth) ||
|
||||
(skipOverflowHiddenElements &&
|
||||
getComputedStyle(parent).overflow === "hidden")
|
||||
) {
|
||||
if (parent.dataset._scaleY) {
|
||||
offsetY /= parent.dataset._scaleY;
|
||||
offsetX /= parent.dataset._scaleX;
|
||||
|
@ -191,7 +195,7 @@ function watchScroll(viewAreaElement, callback) {
|
|||
};
|
||||
|
||||
let rAF = null;
|
||||
viewAreaElement.addEventListener('scroll', debounceScroll, true);
|
||||
viewAreaElement.addEventListener("scroll", debounceScroll, true);
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -199,10 +203,10 @@ function watchScroll(viewAreaElement, callback) {
|
|||
* Helper function to parse query string (e.g. ?param1=value&parm2=...).
|
||||
*/
|
||||
function parseQueryString(query) {
|
||||
const parts = query.split('&');
|
||||
const parts = query.split("&");
|
||||
const params = Object.create(null);
|
||||
for (let i = 0, ii = parts.length; i < ii; ++i) {
|
||||
const param = parts[i].split('=');
|
||||
const param = parts[i].split("=");
|
||||
const key = param[0].toLowerCase();
|
||||
const value = param.length > 1 ? param[1] : null;
|
||||
params[decodeURIComponent(key)] = decodeURIComponent(value);
|
||||
|
@ -264,18 +268,24 @@ function approximateFraction(x) {
|
|||
|
||||
const x_ = x > 1 ? xinv : x;
|
||||
// a/b and c/d are neighbours in Farey sequence.
|
||||
let a = 0, b = 1, c = 1, d = 1;
|
||||
let a = 0,
|
||||
b = 1,
|
||||
c = 1,
|
||||
d = 1;
|
||||
// Limiting search to order 8.
|
||||
while (true) {
|
||||
// Generating next term in sequence (order of q).
|
||||
const p = a + c, q = b + d;
|
||||
const p = a + c,
|
||||
q = b + d;
|
||||
if (q > limit) {
|
||||
break;
|
||||
}
|
||||
if (x_ <= p / q) {
|
||||
c = p; d = q;
|
||||
c = p;
|
||||
d = q;
|
||||
} else {
|
||||
a = p; b = q;
|
||||
a = p;
|
||||
b = q;
|
||||
}
|
||||
}
|
||||
let result;
|
||||
|
@ -300,17 +310,17 @@ function roundToDivide(x, div) {
|
|||
* @returns {Object} An Object containing the properties: {number} `width`
|
||||
* and {number} `height`, given in inches.
|
||||
*/
|
||||
function getPageSizeInches({ view, userUnit, rotate, }) {
|
||||
function getPageSizeInches({ view, userUnit, rotate }) {
|
||||
const [x1, y1, x2, y2] = view;
|
||||
// We need to take the page rotation into account as well.
|
||||
const changeOrientation = rotate % 180 !== 0;
|
||||
|
||||
const width = (x2 - x1) / 72 * userUnit;
|
||||
const height = (y2 - y1) / 72 * userUnit;
|
||||
const width = ((x2 - x1) / 72) * userUnit;
|
||||
const height = ((y2 - y1) / 72) * userUnit;
|
||||
|
||||
return {
|
||||
width: (changeOrientation ? height : width),
|
||||
height: (changeOrientation ? width : height),
|
||||
width: changeOrientation ? height : width,
|
||||
height: changeOrientation ? width : height,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -426,10 +436,16 @@ function backtrackBeforeAllVisibleElements(index, views, top) {
|
|||
* out horizontally instead of vertically
|
||||
* @returns {Object} `{ first, last, views: [{ id, x, y, view, percent }] }`
|
||||
*/
|
||||
function getVisibleElements(scrollEl, views, sortByVisibility = false,
|
||||
horizontal = false) {
|
||||
const top = scrollEl.scrollTop, bottom = top + scrollEl.clientHeight;
|
||||
const left = scrollEl.scrollLeft, right = left + scrollEl.clientWidth;
|
||||
function getVisibleElements(
|
||||
scrollEl,
|
||||
views,
|
||||
sortByVisibility = false,
|
||||
horizontal = false
|
||||
) {
|
||||
const top = scrollEl.scrollTop,
|
||||
bottom = top + scrollEl.clientHeight;
|
||||
const left = scrollEl.scrollLeft,
|
||||
right = left + scrollEl.clientWidth;
|
||||
|
||||
// Throughout this "generic" function, comments will assume we're working with
|
||||
// PDF document pages, which is the most important and complex case. In this
|
||||
|
@ -454,22 +470,33 @@ function getVisibleElements(scrollEl, views, sortByVisibility = false,
|
|||
return elementRight > left;
|
||||
}
|
||||
|
||||
const visible = [], numViews = views.length;
|
||||
let firstVisibleElementInd = numViews === 0 ? 0 :
|
||||
binarySearchFirstItem(views, horizontal ? isElementRightAfterViewLeft :
|
||||
isElementBottomAfterViewTop);
|
||||
const visible = [],
|
||||
numViews = views.length;
|
||||
let firstVisibleElementInd =
|
||||
numViews === 0
|
||||
? 0
|
||||
: binarySearchFirstItem(
|
||||
views,
|
||||
horizontal ? isElementRightAfterViewLeft : isElementBottomAfterViewTop
|
||||
);
|
||||
|
||||
// Please note the return value of the `binarySearchFirstItem` function when
|
||||
// no valid element is found (hence the `firstVisibleElementInd` check below).
|
||||
if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews &&
|
||||
!horizontal) {
|
||||
if (
|
||||
firstVisibleElementInd > 0 &&
|
||||
firstVisibleElementInd < numViews &&
|
||||
!horizontal
|
||||
) {
|
||||
// In wrapped scrolling (or vertical scrolling with spreads), with some page
|
||||
// sizes, isElementBottomAfterViewTop doesn't satisfy the binary search
|
||||
// condition: there can be pages with bottoms above the view top between
|
||||
// pages with bottoms below. This function detects and corrects that error;
|
||||
// see it for more comments.
|
||||
firstVisibleElementInd =
|
||||
backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
|
||||
firstVisibleElementInd = backtrackBeforeAllVisibleElements(
|
||||
firstVisibleElementInd,
|
||||
views,
|
||||
top
|
||||
);
|
||||
}
|
||||
|
||||
// lastEdge acts as a cutoff for us to stop looping, because we know all
|
||||
|
@ -483,10 +510,12 @@ function getVisibleElements(scrollEl, views, sortByVisibility = false,
|
|||
let lastEdge = horizontal ? right : -1;
|
||||
|
||||
for (let i = firstVisibleElementInd; i < numViews; i++) {
|
||||
const view = views[i], element = view.div;
|
||||
const view = views[i],
|
||||
element = view.div;
|
||||
const currentWidth = element.offsetLeft + element.clientLeft;
|
||||
const currentHeight = element.offsetTop + element.clientTop;
|
||||
const viewWidth = element.clientWidth, viewHeight = element.clientHeight;
|
||||
const viewWidth = element.clientWidth,
|
||||
viewHeight = element.clientHeight;
|
||||
const viewRight = currentWidth + viewWidth;
|
||||
const viewBottom = currentHeight + viewHeight;
|
||||
|
||||
|
@ -502,17 +531,24 @@ function getVisibleElements(scrollEl, views, sortByVisibility = false,
|
|||
break;
|
||||
}
|
||||
|
||||
if (viewBottom <= top || currentHeight >= bottom ||
|
||||
viewRight <= left || currentWidth >= right) {
|
||||
if (
|
||||
viewBottom <= top ||
|
||||
currentHeight >= bottom ||
|
||||
viewRight <= left ||
|
||||
currentWidth >= right
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const hiddenHeight = Math.max(0, top - currentHeight) +
|
||||
Math.max(0, viewBottom - bottom);
|
||||
const hiddenWidth = Math.max(0, left - currentWidth) +
|
||||
Math.max(0, viewRight - right);
|
||||
const percent = ((viewHeight - hiddenHeight) * (viewWidth - hiddenWidth) *
|
||||
100 / viewHeight / viewWidth) | 0;
|
||||
const hiddenHeight =
|
||||
Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
|
||||
const hiddenWidth =
|
||||
Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
|
||||
const percent =
|
||||
(((viewHeight - hiddenHeight) * (viewWidth - hiddenWidth) * 100) /
|
||||
viewHeight /
|
||||
viewWidth) |
|
||||
0;
|
||||
visible.push({
|
||||
id: view.id,
|
||||
x: currentWidth,
|
||||
|
@ -522,7 +558,8 @@ function getVisibleElements(scrollEl, views, sortByVisibility = false,
|
|||
});
|
||||
}
|
||||
|
||||
const first = visible[0], last = visible[visible.length - 1];
|
||||
const first = visible[0],
|
||||
last = visible[visible.length - 1];
|
||||
|
||||
if (sortByVisibility) {
|
||||
visible.sort(function(a, b) {
|
||||
|
@ -533,7 +570,7 @@ function getVisibleElements(scrollEl, views, sortByVisibility = false,
|
|||
return a.id - b.id; // ensure stability
|
||||
});
|
||||
}
|
||||
return { first, last, views: visible, };
|
||||
return { first, last, views: visible };
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -546,10 +583,10 @@ function noContextMenuHandler(evt) {
|
|||
function isDataSchema(url) {
|
||||
let i = 0;
|
||||
const ii = url.length;
|
||||
while (i < ii && url[i].trim() === '') {
|
||||
while (i < ii && url[i].trim() === "") {
|
||||
i++;
|
||||
}
|
||||
return url.substring(i, i + 5).toLowerCase() === 'data:';
|
||||
return url.substring(i, i + 5).toLowerCase() === "data:";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -559,13 +596,15 @@ function isDataSchema(url) {
|
|||
* unknown, or the protocol is unsupported.
|
||||
* @returns {string} Guessed PDF filename.
|
||||
*/
|
||||
function getPDFFileNameFromURL(url, defaultFilename = 'document.pdf') {
|
||||
if (typeof url !== 'string') {
|
||||
function getPDFFileNameFromURL(url, defaultFilename = "document.pdf") {
|
||||
if (typeof url !== "string") {
|
||||
return defaultFilename;
|
||||
}
|
||||
if (isDataSchema(url)) {
|
||||
console.warn('getPDFFileNameFromURL: ' +
|
||||
'ignoring "data:" URL for performance reasons.');
|
||||
console.warn(
|
||||
"getPDFFileNameFromURL: " +
|
||||
'ignoring "data:" URL for performance reasons.'
|
||||
);
|
||||
return defaultFilename;
|
||||
}
|
||||
const reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
|
||||
|
@ -573,17 +612,20 @@ function getPDFFileNameFromURL(url, defaultFilename = 'document.pdf') {
|
|||
// Pattern to get last matching NAME.pdf
|
||||
const reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
|
||||
const splitURI = reURI.exec(url);
|
||||
let suggestedFilename = reFilename.exec(splitURI[1]) ||
|
||||
reFilename.exec(splitURI[2]) ||
|
||||
reFilename.exec(splitURI[3]);
|
||||
let suggestedFilename =
|
||||
reFilename.exec(splitURI[1]) ||
|
||||
reFilename.exec(splitURI[2]) ||
|
||||
reFilename.exec(splitURI[3]);
|
||||
if (suggestedFilename) {
|
||||
suggestedFilename = suggestedFilename[0];
|
||||
if (suggestedFilename.includes('%')) {
|
||||
if (suggestedFilename.includes("%")) {
|
||||
// URL-encoded %2Fpath%2Fto%2Ffile.pdf should be file.pdf
|
||||
try {
|
||||
suggestedFilename =
|
||||
reFilename.exec(decodeURIComponent(suggestedFilename))[0];
|
||||
} catch (ex) { // Possible (extremely rare) errors:
|
||||
suggestedFilename = reFilename.exec(
|
||||
decodeURIComponent(suggestedFilename)
|
||||
)[0];
|
||||
} catch (ex) {
|
||||
// Possible (extremely rare) errors:
|
||||
// URIError "Malformed URI", e.g. for "%AA.pdf"
|
||||
// TypeError "null has no properties", e.g. for "%2F.pdf"
|
||||
}
|
||||
|
@ -619,13 +661,19 @@ function isValidRotation(angle) {
|
|||
}
|
||||
|
||||
function isValidScrollMode(mode) {
|
||||
return (Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) &&
|
||||
mode !== ScrollMode.UNKNOWN);
|
||||
return (
|
||||
Number.isInteger(mode) &&
|
||||
Object.values(ScrollMode).includes(mode) &&
|
||||
mode !== ScrollMode.UNKNOWN
|
||||
);
|
||||
}
|
||||
|
||||
function isValidSpreadMode(mode) {
|
||||
return (Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) &&
|
||||
mode !== SpreadMode.UNKNOWN);
|
||||
return (
|
||||
Number.isInteger(mode) &&
|
||||
Object.values(SpreadMode).includes(mode) &&
|
||||
mode !== SpreadMode.UNKNOWN
|
||||
);
|
||||
}
|
||||
|
||||
function isPortraitOrientation(size) {
|
||||
|
@ -633,8 +681,8 @@ function isPortraitOrientation(size) {
|
|||
}
|
||||
|
||||
const WaitOnType = {
|
||||
EVENT: 'event',
|
||||
TIMEOUT: 'timeout',
|
||||
EVENT: "event",
|
||||
TIMEOUT: "timeout",
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -654,11 +702,14 @@ const WaitOnType = {
|
|||
* @param {WaitOnEventOrTimeoutParameters}
|
||||
* @returns {Promise} A promise that is resolved with a {WaitOnType} value.
|
||||
*/
|
||||
function waitOnEventOrTimeout({ target, name, delay = 0, }) {
|
||||
function waitOnEventOrTimeout({ target, name, delay = 0 }) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (typeof target !== 'object' || !(name && typeof name === 'string') ||
|
||||
!(Number.isInteger(delay) && delay >= 0)) {
|
||||
throw new Error('waitOnEventOrTimeout - invalid parameters.');
|
||||
if (
|
||||
typeof target !== "object" ||
|
||||
!(name && typeof name === "string") ||
|
||||
!(Number.isInteger(delay) && delay >= 0)
|
||||
) {
|
||||
throw new Error("waitOnEventOrTimeout - invalid parameters.");
|
||||
}
|
||||
|
||||
function handler(type) {
|
||||
|
@ -689,9 +740,12 @@ function waitOnEventOrTimeout({ target, name, delay = 0, }) {
|
|||
/**
|
||||
* Promise that is resolved when DOM window becomes visible.
|
||||
*/
|
||||
const animationStarted = new Promise(function (resolve) {
|
||||
if ((typeof PDFJSDev !== 'undefined' && PDFJSDev.test('LIB')) &&
|
||||
typeof window === 'undefined') {
|
||||
const animationStarted = new Promise(function(resolve) {
|
||||
if (
|
||||
typeof PDFJSDev !== "undefined" &&
|
||||
PDFJSDev.test("LIB") &&
|
||||
typeof window === "undefined"
|
||||
) {
|
||||
// Prevent "ReferenceError: window is not defined" errors when running the
|
||||
// unit-tests in Node.js/Travis.
|
||||
setTimeout(resolve, 20);
|
||||
|
@ -706,7 +760,7 @@ const animationStarted = new Promise(function (resolve) {
|
|||
* used.
|
||||
*/
|
||||
class EventBus {
|
||||
constructor({ dispatchToDOM = false, } = {}) {
|
||||
constructor({ dispatchToDOM = false } = {}) {
|
||||
this._listeners = Object.create(null);
|
||||
this._dispatchToDOM = dispatchToDOM === true;
|
||||
}
|
||||
|
@ -723,7 +777,7 @@ class EventBus {
|
|||
off(eventName, listener) {
|
||||
const eventListeners = this._listeners[eventName];
|
||||
let i;
|
||||
if (!eventListeners || ((i = eventListeners.indexOf(listener)) < 0)) {
|
||||
if (!eventListeners || (i = eventListeners.indexOf(listener)) < 0) {
|
||||
return;
|
||||
}
|
||||
eventListeners.splice(i, 1);
|
||||
|
@ -742,7 +796,7 @@ class EventBus {
|
|||
const args = Array.prototype.slice.call(arguments, 1);
|
||||
// Making copy of the listeners array in case if it will be modified
|
||||
// during dispatch.
|
||||
eventListeners.slice(0).forEach(function (listener) {
|
||||
eventListeners.slice(0).forEach(function(listener) {
|
||||
listener.apply(null, args);
|
||||
});
|
||||
if (this._dispatchToDOM) {
|
||||
|
@ -759,7 +813,7 @@ class EventBus {
|
|||
const obj = args[0];
|
||||
for (const key in obj) {
|
||||
const value = obj[key];
|
||||
if (key === 'source') {
|
||||
if (key === "source") {
|
||||
if (value === window || value === document) {
|
||||
return; // No need to re-dispatch (already) global events.
|
||||
}
|
||||
|
@ -768,7 +822,7 @@ class EventBus {
|
|||
details[key] = value;
|
||||
}
|
||||
}
|
||||
const event = document.createEvent('CustomEvent');
|
||||
const event = document.createEvent("CustomEvent");
|
||||
event.initCustomEvent(eventName, true, true, details);
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
@ -777,7 +831,7 @@ class EventBus {
|
|||
let globalEventBus = null;
|
||||
function getGlobalEventBus(dispatchToDOM = false) {
|
||||
if (!globalEventBus) {
|
||||
globalEventBus = new EventBus({ dispatchToDOM, });
|
||||
globalEventBus = new EventBus({ dispatchToDOM });
|
||||
}
|
||||
return globalEventBus;
|
||||
}
|
||||
|
@ -787,18 +841,18 @@ function clamp(v, min, max) {
|
|||
}
|
||||
|
||||
class ProgressBar {
|
||||
constructor(id, { height, width, units, } = {}) {
|
||||
constructor(id, { height, width, units } = {}) {
|
||||
this.visible = true;
|
||||
|
||||
// Fetch the sub-elements for later.
|
||||
this.div = document.querySelector(id + ' .progress');
|
||||
this.div = document.querySelector(id + " .progress");
|
||||
// Get the loading bar element, so it can be resized to fit the viewer.
|
||||
this.bar = this.div.parentNode;
|
||||
|
||||
// Get options, with sensible defaults.
|
||||
this.height = height || 100;
|
||||
this.width = width || 100;
|
||||
this.units = units || '%';
|
||||
this.units = units || "%";
|
||||
|
||||
// Initialize heights.
|
||||
this.div.style.height = this.height + this.units;
|
||||
|
@ -807,13 +861,13 @@ class ProgressBar {
|
|||
|
||||
_updateBar() {
|
||||
if (this._indeterminate) {
|
||||
this.div.classList.add('indeterminate');
|
||||
this.div.classList.add("indeterminate");
|
||||
this.div.style.width = this.width + this.units;
|
||||
return;
|
||||
}
|
||||
|
||||
this.div.classList.remove('indeterminate');
|
||||
const progressSize = this.width * this._percent / 100;
|
||||
this.div.classList.remove("indeterminate");
|
||||
const progressSize = (this.width * this._percent) / 100;
|
||||
this.div.style.width = progressSize + this.units;
|
||||
}
|
||||
|
||||
|
@ -834,8 +888,10 @@ class ProgressBar {
|
|||
const container = viewer.parentNode;
|
||||
const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
|
||||
if (scrollbarWidth > 0) {
|
||||
this.bar.setAttribute('style', 'width: calc(100% - ' +
|
||||
scrollbarWidth + 'px);');
|
||||
this.bar.setAttribute(
|
||||
"style",
|
||||
"width: calc(100% - " + scrollbarWidth + "px);"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -844,8 +900,8 @@ class ProgressBar {
|
|||
return;
|
||||
}
|
||||
this.visible = false;
|
||||
this.bar.classList.add('hidden');
|
||||
document.body.classList.remove('loadingInProgress');
|
||||
this.bar.classList.add("hidden");
|
||||
document.body.classList.remove("loadingInProgress");
|
||||
}
|
||||
|
||||
show() {
|
||||
|
@ -853,8 +909,8 @@ class ProgressBar {
|
|||
return;
|
||||
}
|
||||
this.visible = true;
|
||||
document.body.classList.add('loadingInProgress');
|
||||
this.bar.classList.remove('hidden');
|
||||
document.body.classList.add("loadingInProgress");
|
||||
this.bar.classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -863,7 +919,8 @@ class ProgressBar {
|
|||
* array, preserving the order of the rest.
|
||||
*/
|
||||
function moveToEndOfArray(arr, condition) {
|
||||
const moved = [], len = arr.length;
|
||||
const moved = [],
|
||||
len = arr.length;
|
||||
let write = 0;
|
||||
for (let read = 0; read < len; ++read) {
|
||||
if (condition(arr[read])) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue