1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Move the regular expression, used with auto printing in the viewer, to web/ui_utils.js and also use it in the API unit-tests

Rather than having a copy of this regular expression in the `test/unit/api_spec.js` file, with a comment about keeping it up-to-date with the code in the viewer (note the incorrect file reference as well), we can just import it instead to simplify all of this.
This commit is contained in:
Jonas Jenwald 2019-12-26 16:13:49 +01:00
parent db8fcdf34a
commit d9d856020f
3 changed files with 11 additions and 10 deletions

View file

@ -16,6 +16,7 @@
import {
animationStarted,
AutoPrintRegExp,
DEFAULT_SCALE_VALUE,
getGlobalEventBus,
getPDFFileNameFromURL,
@ -1229,10 +1230,8 @@ let PDFViewerApplication = {
});
// Hack to support auto printing.
let regex = /\bprint\s*\(/;
for (let i = 0, ii = javaScript.length; i < ii; i++) {
let js = javaScript[i];
if (js && regex.test(js)) {
for (const js of javaScript) {
if (js && AutoPrintRegExp.test(js)) {
setTimeout(function() {
window.print();
});

View file

@ -56,6 +56,9 @@ const SpreadMode = {
EVEN: 2,
};
// Used by `PDFViewerApplication`, and by the API unit-tests.
const AutoPrintRegExp = /\bprint\s*\(/;
// Replaces {{arguments}} with their values.
function formatL10nValue(text, args) {
if (!args) {
@ -936,6 +939,7 @@ function moveToEndOfArray(arr, condition) {
}
export {
AutoPrintRegExp,
CSS_UNITS,
DEFAULT_SCALE_VALUE,
DEFAULT_SCALE,