Merge pull request #7944 from yurydelendik/rm-defpref
Removes Promise usage from preferences.js
This commit is contained in:
commit
e5cea05881
@ -1,36 +0,0 @@
|
|||||||
/* Copyright 2013 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var DEFAULT_PREFERENCES;
|
|
||||||
|
|
||||||
(function defaultPreferencesLoaderWrapper() {
|
|
||||||
function loaded() {
|
|
||||||
try {
|
|
||||||
DEFAULT_PREFERENCES = JSON.parse(xhr.responseText);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Unable to load DEFAULT_PREFERENCES: ' + e);
|
|
||||||
DEFAULT_PREFERENCES = {};
|
|
||||||
}
|
|
||||||
var event = document.createEvent('CustomEvent');
|
|
||||||
event.initCustomEvent('defaultpreferencesloaded', true, true, null);
|
|
||||||
document.dispatchEvent(event);
|
|
||||||
}
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open('GET', 'default_preferences.json');
|
|
||||||
xhr.onload = xhr.onerror = loaded;
|
|
||||||
xhr.send();
|
|
||||||
})();
|
|
@ -12,7 +12,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals DEFAULT_PREFERENCES */
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -26,21 +25,29 @@
|
|||||||
}
|
}
|
||||||
}(this, function (exports) {
|
}(this, function (exports) {
|
||||||
|
|
||||||
var defaultPreferences;
|
var defaultPreferences = null;
|
||||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
|
function getDefaultPreferences() {
|
||||||
defaultPreferences = Promise.resolve(
|
if (!defaultPreferences) {
|
||||||
PDFJSDev.json('$ROOT/web/default_preferences.json'));
|
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
|
||||||
} else {
|
defaultPreferences = Promise.resolve(
|
||||||
defaultPreferences = new Promise(function (resolve) {
|
PDFJSDev.json('$ROOT/web/default_preferences.json'));
|
||||||
if (DEFAULT_PREFERENCES) {
|
} else {
|
||||||
resolve(DEFAULT_PREFERENCES);
|
defaultPreferences = new Promise(function (resolve) {
|
||||||
return;
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('GET', 'default_preferences.json');
|
||||||
|
xhr.onload = xhr.onerror = function loaded() {
|
||||||
|
try {
|
||||||
|
resolve(JSON.parse(xhr.responseText));
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Unable to load default preferences: ' + e);
|
||||||
|
resolve({});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.send();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
document.addEventListener('defaultpreferencesloaded', function loaded() {
|
}
|
||||||
resolve(DEFAULT_PREFERENCES);
|
return defaultPreferences;
|
||||||
document.removeEventListener('defaultpreferencesloaded', loaded);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cloneObj(obj) {
|
function cloneObj(obj) {
|
||||||
@ -69,7 +76,7 @@ var Preferences = {
|
|||||||
* have been initialized.
|
* have been initialized.
|
||||||
*/
|
*/
|
||||||
initialize: function preferencesInitialize() {
|
initialize: function preferencesInitialize() {
|
||||||
return this.initializedPromise = defaultPreferences.then(
|
return this.initializedPromise = getDefaultPreferences().then(
|
||||||
function (defaults) {
|
function (defaults) {
|
||||||
|
|
||||||
Object.defineProperty(this, 'defaults', {
|
Object.defineProperty(this, 'defaults', {
|
||||||
|
@ -60,10 +60,6 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||||||
<!--#include viewer-snippet.html-->
|
<!--#include viewer-snippet.html-->
|
||||||
<!--#endif-->
|
<!--#endif-->
|
||||||
|
|
||||||
<!--#if !PRODUCTION-->
|
|
||||||
<script src="default_preferences.js"></script>
|
|
||||||
<!--#endif-->
|
|
||||||
|
|
||||||
<!--#if !MINIFIED -->
|
<!--#if !MINIFIED -->
|
||||||
<script src="viewer.js"></script>
|
<script src="viewer.js"></script>
|
||||||
<!--#else-->
|
<!--#else-->
|
||||||
|
@ -169,15 +169,9 @@ function webViewerLoad() {
|
|||||||
var config = getViewerConfiguration();
|
var config = getViewerConfiguration();
|
||||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
||||||
require.config({paths: {'pdfjs': '../src', 'pdfjs-web': '.'}});
|
require.config({paths: {'pdfjs': '../src', 'pdfjs-web': '.'}});
|
||||||
require(['pdfjs-web/pdfjs'], function () {
|
require(['pdfjs-web/app', 'pdfjs-web/pdf_print_service'], function (web) {
|
||||||
// Ensure that src/main_loader.js has loaded all the necessary
|
window.PDFViewerApplication = web.PDFViewerApplication;
|
||||||
// dependencies *before* the viewer loads, to prevent issues in browsers
|
web.PDFViewerApplication.run(config);
|
||||||
// relying on e.g. the Promise/URL polyfill in src/shared/util.js (fixes
|
|
||||||
// issue 7448).
|
|
||||||
require(['pdfjs-web/app', 'pdfjs-web/pdf_print_service'], function (web) {
|
|
||||||
window.PDFViewerApplication = web.PDFViewerApplication;
|
|
||||||
web.PDFViewerApplication.run(config);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
window.PDFViewerApplication = pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication;
|
window.PDFViewerApplication = pdfjsWebLibs.pdfjsWebApp.PDFViewerApplication;
|
||||||
@ -185,4 +179,9 @@ function webViewerLoad() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', webViewerLoad, true);
|
if (document.readyState === 'interactive' ||
|
||||||
|
document.readyState === 'complete') {
|
||||||
|
webViewerLoad();
|
||||||
|
} else {
|
||||||
|
document.addEventListener('DOMContentLoaded', webViewerLoad, true);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user