web/viewer.js: Persist the state of sidebar

Persist the state of content sidebar while browsing away from viewer and
initializing the same on returning back to the viewer. The state is saved
in persistent store preferences and used upon viewer initialization.

Fixes #6935
This commit is contained in:
Ankit Aggarwal 2016-04-13 18:58:53 +05:30 committed by Jonas Jenwald
parent 5657d082c7
commit 6ceda3f290

View File

@ -963,7 +963,7 @@ var PDFViewerApplication = {
}; };
store.initializedPromise.then(function resolved() { store.initializedPromise.then(function resolved() {
var storedHash = null; var storedHash = null, sidebarView = null;
if (self.preferenceShowPreviousViewOnLoad && if (self.preferenceShowPreviousViewOnLoad &&
store.get('exists', false)) { store.get('exists', false)) {
var pageNum = store.get('page', '1'); var pageNum = store.get('page', '1');
@ -974,10 +974,13 @@ var PDFViewerApplication = {
storedHash = 'page=' + pageNum + '&zoom=' + zoom + ',' + storedHash = 'page=' + pageNum + '&zoom=' + zoom + ',' +
left + ',' + top; left + ',' + top;
sidebarView = store.get('sidebarView', SidebarView.NONE);
} else if (self.preferenceDefaultZoomValue) { } else if (self.preferenceDefaultZoomValue) {
storedHash = 'page=1&zoom=' + self.preferenceDefaultZoomValue; storedHash = 'page=1&zoom=' + self.preferenceDefaultZoomValue;
} }
self.setInitialView(storedHash, scale); self.setInitialView(storedHash,
{ scale: scale, sidebarView: sidebarView });
initialParams.hash = storedHash; initialParams.hash = storedHash;
@ -988,7 +991,7 @@ var PDFViewerApplication = {
} }
}, function rejected(reason) { }, function rejected(reason) {
console.error(reason); console.error(reason);
self.setInitialView(null, scale); self.setInitialView(null, { scale: scale });
}); });
// For documents with different page sizes, // For documents with different page sizes,
@ -1112,7 +1115,10 @@ var PDFViewerApplication = {
}); });
}, },
setInitialView: function pdfViewSetInitialView(storedHash, scale) { setInitialView: function pdfViewSetInitialView(storedHash, options) {
var scale = options && options.scale;
var sidebarView = options && options.sidebarView;
this.isInitialViewSet = true; this.isInitialViewSet = true;
// When opening a new file, when one is already loaded in the viewer, // When opening a new file, when one is already loaded in the viewer,
@ -1120,7 +1126,8 @@ var PDFViewerApplication = {
document.getElementById('pageNumber').value = document.getElementById('pageNumber').value =
this.pdfViewer.currentPageNumber; this.pdfViewer.currentPageNumber;
this.pdfSidebar.setInitialView(this.preferenceSidebarViewOnLoad); this.pdfSidebar.setInitialView(this.preferenceSidebarViewOnLoad ||
(sidebarView | 0));
if (this.initialDestination) { if (this.initialDestination) {
this.pdfLinkService.navigateTo(this.initialDestination); this.pdfLinkService.navigateTo(this.initialDestination);
@ -1697,6 +1704,9 @@ window.addEventListener('sidebarviewchanged', function (evt) {
// Only update the storage when the document has been loaded *and* rendered. // Only update the storage when the document has been loaded *and* rendered.
return; return;
} }
store.initializedPromise.then(function() {
store.set('sidebarView', evt.detail.view).catch(function() {});
});
}, true); }, true);
window.addEventListener('updateviewarea', function (evt) { window.addEventListener('updateviewarea', function (evt) {