mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +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
|
@ -14,22 +14,22 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
"use strict";
|
||||
|
||||
var VIEWER_URL = chrome.extension.getURL('content/web/viewer.html');
|
||||
var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html");
|
||||
|
||||
function getViewerURL(pdf_url) {
|
||||
return VIEWER_URL + '?file=' + encodeURIComponent(pdf_url);
|
||||
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url);
|
||||
}
|
||||
|
||||
if (CSS.supports('animation', '0s')) {
|
||||
document.addEventListener('animationstart', onAnimationStart, true);
|
||||
if (CSS.supports("animation", "0s")) {
|
||||
document.addEventListener("animationstart", onAnimationStart, true);
|
||||
} else {
|
||||
document.addEventListener('webkitAnimationStart', onAnimationStart, true);
|
||||
document.addEventListener("webkitAnimationStart", onAnimationStart, true);
|
||||
}
|
||||
|
||||
function onAnimationStart(event) {
|
||||
if (event.animationName === 'pdfjs-detected-object-or-embed') {
|
||||
if (event.animationName === "pdfjs-detected-object-or-embed") {
|
||||
watchObjectOrEmbed(event.target);
|
||||
}
|
||||
}
|
||||
|
@ -40,19 +40,23 @@ function onAnimationStart(event) {
|
|||
// invocations have no effect.
|
||||
function watchObjectOrEmbed(elem) {
|
||||
var mimeType = elem.type;
|
||||
if (mimeType && mimeType.toLowerCase() !== 'application/pdf') {
|
||||
if (mimeType && mimeType.toLowerCase() !== "application/pdf") {
|
||||
return;
|
||||
}
|
||||
// <embed src> <object data>
|
||||
var srcAttribute = 'src' in elem ? 'src' : 'data';
|
||||
var srcAttribute = "src" in elem ? "src" : "data";
|
||||
var path = elem[srcAttribute];
|
||||
if (!mimeType && !/\.pdf($|[?#])/i.test(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (elem.tagName === 'EMBED' && elem.name === 'plugin' &&
|
||||
elem.parentNode === document.body &&
|
||||
elem.parentNode.childElementCount === 1 && elem.src === location.href) {
|
||||
if (
|
||||
elem.tagName === "EMBED" &&
|
||||
elem.name === "plugin" &&
|
||||
elem.parentNode === document.body &&
|
||||
elem.parentNode.childElementCount === 1 &&
|
||||
elem.src === location.href
|
||||
) {
|
||||
// This page is most likely Chrome's default page that embeds a PDF file.
|
||||
// The fact that the extension's background page did not intercept and
|
||||
// redirect this PDF request means that this PDF cannot be opened by PDF.js,
|
||||
|
@ -62,7 +66,7 @@ function watchObjectOrEmbed(elem) {
|
|||
// Until #4483 is fixed, POST requests should be ignored.
|
||||
return;
|
||||
}
|
||||
if (elem.tagName === 'EMBED' && elem.src === 'about:blank') {
|
||||
if (elem.tagName === "EMBED" && elem.src === "about:blank") {
|
||||
// Starting from Chrome 76, internal embeds do not have the original URL,
|
||||
// but "about:blank" instead.
|
||||
// See https://github.com/mozilla/pdf.js/issues/11137
|
||||
|
@ -76,9 +80,9 @@ function watchObjectOrEmbed(elem) {
|
|||
|
||||
var tagName = elem.tagName.toUpperCase();
|
||||
var updateEmbedOrObject;
|
||||
if (tagName === 'EMBED') {
|
||||
if (tagName === "EMBED") {
|
||||
updateEmbedOrObject = updateEmbedElement;
|
||||
} else if (tagName === 'OBJECT') {
|
||||
} else if (tagName === "OBJECT") {
|
||||
updateEmbedOrObject = updateObjectElement;
|
||||
} else {
|
||||
return;
|
||||
|
@ -115,7 +119,7 @@ function watchObjectOrEmbed(elem) {
|
|||
|
||||
// Display the PDF Viewer in an <embed>.
|
||||
function updateEmbedElement(elem) {
|
||||
if (elem.type === 'text/html' && elem.src.lastIndexOf(VIEWER_URL, 0) === 0) {
|
||||
if (elem.type === "text/html" && elem.src.lastIndexOf(VIEWER_URL, 0) === 0) {
|
||||
// The viewer is already shown.
|
||||
return;
|
||||
}
|
||||
|
@ -126,7 +130,7 @@ function updateEmbedElement(elem) {
|
|||
if (parentNode) {
|
||||
parentNode.removeChild(elem);
|
||||
}
|
||||
elem.type = 'text/html';
|
||||
elem.type = "text/html";
|
||||
elem.src = getEmbeddedViewerURL(elem.src);
|
||||
if (parentNode) {
|
||||
parentNode.insertBefore(elem, nextSibling);
|
||||
|
@ -155,21 +159,21 @@ function updateObjectElement(elem) {
|
|||
var iframe = elem.firstElementChild;
|
||||
if (!iframe || !iframe.__inserted_by_pdfjs) {
|
||||
iframe = createFullSizeIframe();
|
||||
elem.textContent = '';
|
||||
elem.textContent = "";
|
||||
elem.appendChild(iframe);
|
||||
iframe.__inserted_by_pdfjs = true;
|
||||
}
|
||||
iframe.src = getEmbeddedViewerURL(elem.data);
|
||||
|
||||
// Some bogus content type that is not handled by any plugin.
|
||||
elem.type = 'application/not-a-pee-dee-eff-type';
|
||||
elem.type = "application/not-a-pee-dee-eff-type";
|
||||
// Force the <object> to reload and render its fallback content.
|
||||
elem.data += '';
|
||||
elem.data += "";
|
||||
|
||||
// Usually the browser renders plugin content in this tag, which is completely
|
||||
// oblivious of styles such as padding, but we insert and render child nodes,
|
||||
// so force padding to be zero to avoid undesired dimension changes.
|
||||
elem.style.padding = '0';
|
||||
elem.style.padding = "0";
|
||||
|
||||
// <object> and <embed> elements have a "display:inline" style by default.
|
||||
// Despite this property, when a plugin is loaded in the tag, the tag is
|
||||
|
@ -180,27 +184,27 @@ function updateObjectElement(elem) {
|
|||
// web pages is respected.
|
||||
// (<embed> behaves as expected with the default display value, but setting it
|
||||
// to display:inline-block doesn't hurt).
|
||||
elem.style.display = 'inline-block';
|
||||
elem.style.display = "inline-block";
|
||||
}
|
||||
|
||||
// Create an <iframe> element without borders that takes the full width and
|
||||
// height.
|
||||
function createFullSizeIframe() {
|
||||
var iframe = document.createElement('iframe');
|
||||
iframe.style.background = 'none';
|
||||
iframe.style.border = 'none';
|
||||
iframe.style.borderRadius = 'none';
|
||||
iframe.style.boxShadow = 'none';
|
||||
iframe.style.cssFloat = 'none';
|
||||
iframe.style.display = 'block';
|
||||
iframe.style.height = '100%';
|
||||
iframe.style.margin = '0';
|
||||
iframe.style.maxHeight = 'none';
|
||||
iframe.style.maxWidth = 'none';
|
||||
iframe.style.position = 'static';
|
||||
iframe.style.transform = 'none';
|
||||
iframe.style.visibility = 'visible';
|
||||
iframe.style.width = '100%';
|
||||
var iframe = document.createElement("iframe");
|
||||
iframe.style.background = "none";
|
||||
iframe.style.border = "none";
|
||||
iframe.style.borderRadius = "none";
|
||||
iframe.style.boxShadow = "none";
|
||||
iframe.style.cssFloat = "none";
|
||||
iframe.style.display = "block";
|
||||
iframe.style.height = "100%";
|
||||
iframe.style.margin = "0";
|
||||
iframe.style.maxHeight = "none";
|
||||
iframe.style.maxWidth = "none";
|
||||
iframe.style.position = "static";
|
||||
iframe.style.transform = "none";
|
||||
iframe.style.visibility = "visible";
|
||||
iframe.style.width = "100%";
|
||||
return iframe;
|
||||
}
|
||||
|
||||
|
@ -208,10 +212,10 @@ function createFullSizeIframe() {
|
|||
function getEmbeddedViewerURL(path) {
|
||||
var fragment = /^([^#]*)(#.*)?$/.exec(path);
|
||||
path = fragment[1];
|
||||
fragment = fragment[2] || '';
|
||||
fragment = fragment[2] || "";
|
||||
|
||||
// Resolve relative path to document.
|
||||
var a = document.createElement('a');
|
||||
var a = document.createElement("a");
|
||||
a.href = document.baseURI;
|
||||
a.href = path;
|
||||
path = a.href;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue