Merge pull request #14767 from Snuffleupagus/fileInput-refactor
[GENERIC viewer] Re-factor the `fileInput` initialization
This commit is contained in:
commit
143ba30bef
38
web/app.js
38
web/app.js
@ -2085,7 +2085,7 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|||||||
"https://mozilla.github.io",
|
"https://mozilla.github.io",
|
||||||
];
|
];
|
||||||
validateFileURL = function (file) {
|
validateFileURL = function (file) {
|
||||||
if (file === undefined) {
|
if (!file) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -2142,7 +2142,7 @@ function reportPageStatsPDFBug({ pageNumber }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function webViewerInitialized() {
|
function webViewerInitialized() {
|
||||||
const appConfig = PDFViewerApplication.appConfig;
|
const { appConfig, eventBus } = PDFViewerApplication;
|
||||||
let file;
|
let file;
|
||||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||||
const queryString = document.location.search.substring(1);
|
const queryString = document.location.search.substring(1);
|
||||||
@ -2156,31 +2156,15 @@ function webViewerInitialized() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||||
const fileInput = document.createElement("input");
|
const fileInput = appConfig.openFileInput;
|
||||||
fileInput.id = appConfig.openFileInputName;
|
fileInput.value = null;
|
||||||
fileInput.className = "fileInput";
|
|
||||||
fileInput.setAttribute("type", "file");
|
|
||||||
fileInput.oncontextmenu = noContextMenuHandler;
|
|
||||||
document.body.appendChild(fileInput);
|
|
||||||
|
|
||||||
if (
|
|
||||||
!window.File ||
|
|
||||||
!window.FileReader ||
|
|
||||||
!window.FileList ||
|
|
||||||
!window.Blob
|
|
||||||
) {
|
|
||||||
appConfig.toolbar.openFile.hidden = true;
|
|
||||||
appConfig.secondaryToolbar.openFileButton.hidden = true;
|
|
||||||
} else {
|
|
||||||
fileInput.value = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
fileInput.addEventListener("change", function (evt) {
|
fileInput.addEventListener("change", function (evt) {
|
||||||
const files = evt.target.files;
|
const { files } = evt.target;
|
||||||
if (!files || files.length === 0) {
|
if (!files || files.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PDFViewerApplication.eventBus.dispatch("fileinputchange", {
|
eventBus.dispatch("fileinputchange", {
|
||||||
source: this,
|
source: this,
|
||||||
fileInput: evt.target,
|
fileInput: evt.target,
|
||||||
});
|
});
|
||||||
@ -2195,11 +2179,11 @@ function webViewerInitialized() {
|
|||||||
appConfig.mainContainer.addEventListener("drop", function (evt) {
|
appConfig.mainContainer.addEventListener("drop", function (evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
const files = evt.dataTransfer.files;
|
const { files } = evt.dataTransfer;
|
||||||
if (!files || files.length === 0) {
|
if (!files || files.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PDFViewerApplication.eventBus.dispatch("fileinputchange", {
|
eventBus.dispatch("fileinputchange", {
|
||||||
source: this,
|
source: this,
|
||||||
fileInput: evt.dataTransfer,
|
fileInput: evt.dataTransfer,
|
||||||
});
|
});
|
||||||
@ -2234,7 +2218,7 @@ function webViewerInitialized() {
|
|||||||
"transitionend",
|
"transitionend",
|
||||||
function (evt) {
|
function (evt) {
|
||||||
if (evt.target === /* mainContainer */ this) {
|
if (evt.target === /* mainContainer */ this) {
|
||||||
PDFViewerApplication.eventBus.dispatch("resize", { source: this });
|
eventBus.dispatch("resize", { source: this });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
true
|
true
|
||||||
@ -2460,8 +2444,8 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
webViewerOpenFile = function (evt) {
|
webViewerOpenFile = function (evt) {
|
||||||
const openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
|
const fileInput = PDFViewerApplication.appConfig.openFileInput;
|
||||||
document.getElementById(openFileInputName).click();
|
fileInput.click();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1364,16 +1364,6 @@ dialog :link {
|
|||||||
clear: both;
|
clear: both;
|
||||||
}
|
}
|
||||||
|
|
||||||
.fileInput {
|
|
||||||
background: rgba(255, 255, 255, 1);
|
|
||||||
color: rgba(0, 0, 0, 1);
|
|
||||||
margin-top: 5px;
|
|
||||||
visibility: hidden;
|
|
||||||
position: fixed;
|
|
||||||
right: 0;
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#PDFBug {
|
#PDFBug {
|
||||||
background: none repeat scroll 0 0 rgba(255, 255, 255, 1);
|
background: none repeat scroll 0 0 rgba(255, 255, 255, 1);
|
||||||
border: 1px solid rgba(102, 102, 102, 1);
|
border: 1px solid rgba(102, 102, 102, 1);
|
||||||
@ -1537,10 +1527,6 @@ dialog :link {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.fileInput {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Rules for browsers that support PDF.js printing */
|
/* Rules for browsers that support PDF.js printing */
|
||||||
body[data-pdfjsprinting] #outerContainer {
|
body[data-pdfjsprinting] #outerContainer {
|
||||||
display: none;
|
display: none;
|
||||||
|
@ -448,5 +448,9 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||||||
|
|
||||||
</div> <!-- outerContainer -->
|
</div> <!-- outerContainer -->
|
||||||
<div id="printContainer"></div>
|
<div id="printContainer"></div>
|
||||||
|
|
||||||
|
<!--#if GENERIC -->
|
||||||
|
<input type="file" id="fileInput" class="hidden">
|
||||||
|
<!--#endif-->
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -189,7 +189,10 @@ function getViewerConfiguration() {
|
|||||||
},
|
},
|
||||||
errorWrapper,
|
errorWrapper,
|
||||||
printContainer: document.getElementById("printContainer"),
|
printContainer: document.getElementById("printContainer"),
|
||||||
openFileInputName: "fileInput",
|
openFileInput:
|
||||||
|
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
|
||||||
|
? document.getElementById("fileInput")
|
||||||
|
: null,
|
||||||
debuggerScriptPath: "./debugger.js",
|
debuggerScriptPath: "./debugger.js",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user