Prepare viewer.js for async loading and module separation.

This commit is contained in:
Yury Delendik 2016-04-01 10:29:44 -05:00
parent b371785fbb
commit 313b418a20
5 changed files with 93 additions and 54 deletions

View File

@ -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;

View File

@ -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

View File

@ -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)

View File

@ -65,6 +65,7 @@ See https://github.com/adobe-type-tools/cmap-resources
<script src="default_preferences.js"></script>
<script src="preferences.js"></script>
<script src="download_manager.js"></script>
<script src="platform_integration.js"></script>
<script src="view_history.js"></script>
<script src="pdf_link_service.js"></script>
<script src="pdf_rendering_queue.js"></script>
@ -87,6 +88,7 @@ See https://github.com/adobe-type-tools/cmap-resources
<script src="overlay_manager.js"></script>
<script src="password_prompt.js"></script>
<script src="pdf_document_properties.js"></script>
<script src="app.js"></script>
<!--#endif-->
<!--#if !MINIFIED -->

51
web/viewer.js Normal file
View File

@ -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);