[Pkg-javascript-commits] [pdf.js] 36/210: Add a preference to set the sidebarView on load
David Prévot
taffit at moszumanska.debian.org
Thu Jun 5 14:20:59 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch upstream
in repository pdf.js.
commit c53bcb29926ac09b563b7de6d555f964f4abf660
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date: Mon Apr 28 16:07:53 2014 +0200
Add a preference to set the sidebarView on load
---
web/default_preferences.js | 2 +-
web/preferences.js | 7 +++++++
web/viewer.js | 45 +++++++++++++++++++++++++--------------------
3 files changed, 33 insertions(+), 21 deletions(-)
diff --git a/web/default_preferences.js b/web/default_preferences.js
index 77b82cf..bfd2321 100644
--- a/web/default_preferences.js
+++ b/web/default_preferences.js
@@ -21,7 +21,7 @@
var DEFAULT_PREFERENCES = {
showPreviousViewOnLoad: true,
defaultZoomValue: '',
- ifAvailableShowOutlineOnLoad: false,
+ sidebarViewOnLoad: 0,
enableHandToolOnLoad: false,
enableWebGL: false
};
diff --git a/web/preferences.js b/web/preferences.js
index 95ce3cd..c1082dd 100644
--- a/web/preferences.js
+++ b/web/preferences.js
@@ -20,6 +20,13 @@
//#include default_preferences.js
+var SidebarView = {
+ NONE: 0,
+ THUMBS: 1,
+ OUTLINE: 2,
+ ATTACHMENTS: 3
+};
+
/**
* Preferences - Utility for storing persistent settings.
* Used for settings that should be applied to all opened documents,
diff --git a/web/viewer.js b/web/viewer.js
index ca85c1c..b1c5162 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -17,7 +17,7 @@
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar, CustomStyle,
PDFFindController, ProgressBar, TextLayerBuilder, DownloadManager,
getFileName, scrollIntoView, getPDFFileNameFromURL, PDFHistory,
- Preferences, ViewHistory, PageView, ThumbnailView, URL,
+ Preferences, SidebarView, ViewHistory, PageView, ThumbnailView, URL,
noContextMenuHandler, SecondaryToolbar, PasswordPrompt,
PresentationMode, HandTool, Promise, DocumentProperties,
DocumentOutlineView, DocumentAttachmentsView */
@@ -224,6 +224,9 @@ var PDFView = {
var initializedPromise = Promise.all([
Preferences.get('enableWebGL').then(function resolved(value) {
PDFJS.disableWebGL = !value;
+ }, function rejected(reason) {}),
+ Preferences.get('sidebarViewOnLoad').then(function resolved(value) {
+ self.preferenceSidebarViewOnLoad = value;
}, function rejected(reason) {})
// TODO move more preferences and other async stuff here
]);
@@ -1086,24 +1089,28 @@ var PDFView = {
self.outline = new DocumentOutlineView(outline);
document.getElementById('viewOutline').disabled = !outline;
- if (outline) {
- Preferences.get('ifAvailableShowOutlineOnLoad').then(
- function (prefValue) {
- if (prefValue) {
- if (!self.sidebarOpen) {
- document.getElementById('sidebarToggle').click();
- }
- self.switchSidebarView('outline');
- }
- });
+ if (outline &&
+ self.preferenceSidebarViewOnLoad === SidebarView.OUTLINE) {
+ self.switchSidebarView('outline', true);
}
});
pdfDocument.getAttachments().then(function(attachments) {
self.attachments = new DocumentAttachmentsView(attachments);
document.getElementById('viewAttachments').disabled = !attachments;
+
+ if (attachments &&
+ self.preferenceSidebarViewOnLoad === SidebarView.ATTACHMENTS) {
+ self.switchSidebarView('attachments', true);
+ }
});
});
+ if (self.preferenceSidebarViewOnLoad === SidebarView.THUMBS) {
+ Promise.all([firstPagePromise, onePageRendered]).then(function () {
+ self.switchSidebarView('thumbs', true);
+ });
+ }
+
pdfDocument.getMetadata().then(function(data) {
var info = data.info, metadata = data.metadata;
self.documentInfo = info;
@@ -1344,17 +1351,12 @@ var PDFView = {
this.page = pageNumber; // simple page
}
if ('pagemode' in params) {
- var toggle = document.getElementById('sidebarToggle');
if (params.pagemode === 'thumbs' || params.pagemode === 'bookmarks' ||
params.pagemode === 'attachments') {
- if (!this.sidebarOpen) {
- toggle.click();
- }
- this.switchSidebarView(params.pagemode === 'bookmarks' ?
- 'outline' :
- params.pagemode);
+ this.switchSidebarView((params.pagemode === 'bookmarks' ?
+ 'outline' : params.pagemode), true);
} else if (params.pagemode === 'none' && this.sidebarOpen) {
- toggle.click();
+ document.getElementById('sidebarToggle').click();
}
}
} else if (/^\d+$/.test(hash)) { // page number
@@ -1365,7 +1367,10 @@ var PDFView = {
}
},
- switchSidebarView: function pdfViewSwitchSidebarView(view) {
+ switchSidebarView: function pdfViewSwitchSidebarView(view, openSidebar) {
+ if (openSidebar && !this.sidebarOpen) {
+ document.getElementById('sidebarToggle').click();
+ }
var thumbsView = document.getElementById('thumbnailView');
var outlineView = document.getElementById('outlineView');
var attachmentsView = document.getElementById('attachmentsView');
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list