Merge pull request #4669 from Snuffleupagus/sidebar-pref

Add a preference to set the sidebarView on load
This commit is contained in:
Tim van der Meij 2014-04-28 21:02:53 +02:00
commit 32a327b55b
3 changed files with 33 additions and 21 deletions

View File

@ -21,7 +21,7 @@
var DEFAULT_PREFERENCES = { var DEFAULT_PREFERENCES = {
showPreviousViewOnLoad: true, showPreviousViewOnLoad: true,
defaultZoomValue: '', defaultZoomValue: '',
ifAvailableShowOutlineOnLoad: false, sidebarViewOnLoad: 0,
enableHandToolOnLoad: false, enableHandToolOnLoad: false,
enableWebGL: false enableWebGL: false
}; };

View File

@ -20,6 +20,13 @@
//#include default_preferences.js //#include default_preferences.js
var SidebarView = {
NONE: 0,
THUMBS: 1,
OUTLINE: 2,
ATTACHMENTS: 3
};
/** /**
* Preferences - Utility for storing persistent settings. * Preferences - Utility for storing persistent settings.
* Used for settings that should be applied to all opened documents, * Used for settings that should be applied to all opened documents,

View File

@ -17,7 +17,7 @@
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar, CustomStyle, /* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, PDFFindBar, CustomStyle,
PDFFindController, ProgressBar, TextLayerBuilder, DownloadManager, PDFFindController, ProgressBar, TextLayerBuilder, DownloadManager,
getFileName, scrollIntoView, getPDFFileNameFromURL, PDFHistory, getFileName, scrollIntoView, getPDFFileNameFromURL, PDFHistory,
Preferences, ViewHistory, PageView, ThumbnailView, URL, Preferences, SidebarView, ViewHistory, PageView, ThumbnailView, URL,
noContextMenuHandler, SecondaryToolbar, PasswordPrompt, noContextMenuHandler, SecondaryToolbar, PasswordPrompt,
PresentationMode, HandTool, Promise, DocumentProperties, PresentationMode, HandTool, Promise, DocumentProperties,
DocumentOutlineView, DocumentAttachmentsView */ DocumentOutlineView, DocumentAttachmentsView */
@ -224,6 +224,9 @@ var PDFView = {
var initializedPromise = Promise.all([ var initializedPromise = Promise.all([
Preferences.get('enableWebGL').then(function resolved(value) { Preferences.get('enableWebGL').then(function resolved(value) {
PDFJS.disableWebGL = !value; PDFJS.disableWebGL = !value;
}, function rejected(reason) {}),
Preferences.get('sidebarViewOnLoad').then(function resolved(value) {
self.preferenceSidebarViewOnLoad = value;
}, function rejected(reason) {}) }, function rejected(reason) {})
// TODO move more preferences and other async stuff here // TODO move more preferences and other async stuff here
]); ]);
@ -1086,24 +1089,28 @@ var PDFView = {
self.outline = new DocumentOutlineView(outline); self.outline = new DocumentOutlineView(outline);
document.getElementById('viewOutline').disabled = !outline; document.getElementById('viewOutline').disabled = !outline;
if (outline) { if (outline &&
Preferences.get('ifAvailableShowOutlineOnLoad').then( self.preferenceSidebarViewOnLoad === SidebarView.OUTLINE) {
function (prefValue) { self.switchSidebarView('outline', true);
if (prefValue) {
if (!self.sidebarOpen) {
document.getElementById('sidebarToggle').click();
}
self.switchSidebarView('outline');
}
});
} }
}); });
pdfDocument.getAttachments().then(function(attachments) { pdfDocument.getAttachments().then(function(attachments) {
self.attachments = new DocumentAttachmentsView(attachments); self.attachments = new DocumentAttachmentsView(attachments);
document.getElementById('viewAttachments').disabled = !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) { pdfDocument.getMetadata().then(function(data) {
var info = data.info, metadata = data.metadata; var info = data.info, metadata = data.metadata;
self.documentInfo = info; self.documentInfo = info;
@ -1344,17 +1351,12 @@ var PDFView = {
this.page = pageNumber; // simple page this.page = pageNumber; // simple page
} }
if ('pagemode' in params) { if ('pagemode' in params) {
var toggle = document.getElementById('sidebarToggle');
if (params.pagemode === 'thumbs' || params.pagemode === 'bookmarks' || if (params.pagemode === 'thumbs' || params.pagemode === 'bookmarks' ||
params.pagemode === 'attachments') { params.pagemode === 'attachments') {
if (!this.sidebarOpen) { this.switchSidebarView((params.pagemode === 'bookmarks' ?
toggle.click(); 'outline' : params.pagemode), true);
}
this.switchSidebarView(params.pagemode === 'bookmarks' ?
'outline' :
params.pagemode);
} else if (params.pagemode === 'none' && this.sidebarOpen) { } else if (params.pagemode === 'none' && this.sidebarOpen) {
toggle.click(); document.getElementById('sidebarToggle').click();
} }
} }
} else if (/^\d+$/.test(hash)) { // page number } 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 thumbsView = document.getElementById('thumbnailView');
var outlineView = document.getElementById('outlineView'); var outlineView = document.getElementById('outlineView');
var attachmentsView = document.getElementById('attachmentsView'); var attachmentsView = document.getElementById('attachmentsView');