From b371785fbbe5ae6d0bcf1adeaa215ee60a86796d Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Fri, 1 Apr 2016 10:27:16 -0500 Subject: [PATCH 1/2] Rename web/viewer.js -> web/app.js --- web/{viewer.js => app.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename web/{viewer.js => app.js} (100%) diff --git a/web/viewer.js b/web/app.js similarity index 100% rename from web/viewer.js rename to web/app.js From 313b418a20f3cb72975c1977288706689f69ce06 Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Fri, 1 Apr 2016 10:29:44 -0500 Subject: [PATCH 2/2] Prepare viewer.js for async loading and module separation. --- web/app.js | 62 +++++-------------------------------- web/platform_integration.js | 30 ++++++++++++++++++ web/ui_utils.js | 2 ++ web/viewer.html | 2 ++ web/viewer.js | 51 ++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 54 deletions(-) create mode 100644 web/platform_integration.js create mode 100644 web/viewer.js diff --git a/web/app.js b/web/app.js index 487d4cb59..0f65a8864 100644 --- a/web/app.js +++ b/web/app.js @@ -20,12 +20,11 @@ PDFOutlineViewer, PDFAttachmentViewer, OverlayManager, PDFFindController, PDFFindBar, PDFViewer, PDFRenderingQueue, PresentationModeState, parseQueryString, RenderingStates, - UNKNOWN_SCALE, DEFAULT_SCALE_VALUE, + UNKNOWN_SCALE, DEFAULT_SCALE_VALUE, DEFAULT_URL, mozL10n, IGNORE_CURRENT_POSITION_ON_ZOOM: true */ 'use strict'; -var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf'; var DEFAULT_SCALE_DELTA = 1.1; var MIN_SCALE = 0.25; var MAX_SCALE = 10.0; @@ -49,27 +48,9 @@ function configure(PDFJS) { //#endif } -var mozL10n = document.mozL10n || document.webL10n; - //#include ui_utils.js //#include preferences.js - -//#if !(FIREFOX || MOZCENTRAL) -//#include mozPrintCallback_polyfill.js -//#endif - -//#if GENERIC || CHROME -//#include download_manager.js -//#endif - -//#if FIREFOX || MOZCENTRAL -//#include firefoxcom.js -//#endif - -//#if CHROME -//#include chromecom.js -//#endif - +//#include platform_integration.js //#include view_history.js //#include pdf_find_bar.js //#include pdf_find_controller.js @@ -127,6 +108,8 @@ var PDFViewerApplication = { // called once when the document is loaded initialize: function pdfViewInitialize() { + configure(PDFJS); + var pdfRenderingQueue = new PDFRenderingQueue(); pdfRenderingQueue.onIdle = this.cleanup.bind(this); this.pdfRenderingQueue = pdfRenderingQueue; @@ -346,6 +329,10 @@ var PDFViewerApplication = { }); }, + run: function pdfViewRun() { + this.initialize().then(webViewerInitialized); + }, + zoomIn: function pdfViewZoomIn(ticks) { var newScale = this.pdfViewer.currentScale; do { @@ -1245,23 +1232,6 @@ var PDFViewerApplication = { window.PDFView = PDFViewerApplication; // obsolete name, using it as an alias //#endif -//#if CHROME -//(function rewriteUrlClosure() { -// // Run this code outside DOMContentLoaded to make sure that the URL -// // is rewritten as soon as possible. -// var queryString = document.location.search.slice(1); -// var params = parseQueryString(queryString); -// DEFAULT_URL = params.file || ''; -// -// // Example: chrome-extension://.../http://example.com/file.pdf -// var humanReadableUrl = '/' + DEFAULT_URL + location.hash; -// history.replaceState(history.state, '', humanReadableUrl); -// if (top === window) { -// chrome.runtime.sendMessage('showPageAction'); -// } -//})(); -//#endif - //#if GENERIC var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io']; @@ -1293,20 +1263,6 @@ function validateFileURL(file) { } //#endif -function webViewerLoad(evt) { -//#if !PRODUCTION - require.config({paths: {'pdfjs': '../src'}}); - require(['pdfjs/main_loader'], - function (loader) { - configure(PDFJS); - PDFViewerApplication.initialize().then(webViewerInitialized); - }); -//#else -// configure(PDFJS); -// PDFViewerApplication.initialize().then(webViewerInitialized); -//#endif -} - function webViewerInitialized() { //#if GENERIC var queryString = document.location.search.substring(1); @@ -1550,8 +1506,6 @@ function webViewerInitialized() { //#endif } -document.addEventListener('DOMContentLoaded', webViewerLoad, true); - document.addEventListener('pagerendered', function (e) { var pageNumber = e.detail.pageNumber; var pageIndex = pageNumber - 1; diff --git a/web/platform_integration.js b/web/platform_integration.js new file mode 100644 index 000000000..bd7f80d3d --- /dev/null +++ b/web/platform_integration.js @@ -0,0 +1,30 @@ +/* Copyright 2016 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//#if !(FIREFOX || MOZCENTRAL) +//#include mozPrintCallback_polyfill.js +//#endif + +//#if GENERIC || CHROME +//#include download_manager.js +//#endif + +//#if FIREFOX || MOZCENTRAL +//#include firefoxcom.js +//#endif + +//#if CHROME +//#include chromecom.js +//#endif diff --git a/web/ui_utils.js b/web/ui_utils.js index 5bb0592ad..976a45f02 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -23,6 +23,8 @@ var MAX_AUTO_SCALE = 1.25; var SCROLLBAR_PADDING = 40; var VERTICAL_PADDING = 5; +var mozL10n = document.mozL10n || document.webL10n; + /** * Returns scale factor for the canvas. It makes sense for the HiDPI displays. * @return {Object} The object with horizontal (sx) and vertical (sy) diff --git a/web/viewer.html b/web/viewer.html index 98ee82954..0018bbadc 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -65,6 +65,7 @@ See https://github.com/adobe-type-tools/cmap-resources + @@ -87,6 +88,7 @@ See https://github.com/adobe-type-tools/cmap-resources + diff --git a/web/viewer.js b/web/viewer.js new file mode 100644 index 000000000..9709d3579 --- /dev/null +++ b/web/viewer.js @@ -0,0 +1,51 @@ +/* Copyright 2016 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/*globals require, parseQueryString, chrome, PDFViewerApplication */ + +'use strict'; + +var DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf'; + +//#include app.js + +//#if CHROME +//(function rewriteUrlClosure() { +// // Run this code outside DOMContentLoaded to make sure that the URL +// // is rewritten as soon as possible. +// var queryString = document.location.search.slice(1); +// var params = parseQueryString(queryString); +// DEFAULT_URL = params.file || ''; +// +// // Example: chrome-extension://.../http://example.com/file.pdf +// var humanReadableUrl = '/' + DEFAULT_URL + location.hash; +// history.replaceState(history.state, '', humanReadableUrl); +// if (top === window) { +// chrome.runtime.sendMessage('showPageAction'); +// } +//})(); +//#endif + +function webViewerLoad() { +//#if !PRODUCTION + require.config({paths: {'pdfjs': '../src'}}); + require(['pdfjs/main_loader'], function (loader) { + PDFViewerApplication.run(); + }); +//#else +//PDFViewerApplication.run(); +//#endif +} + +document.addEventListener('DOMContentLoaded', webViewerLoad, true);