Skip to content

Commit

Permalink
web/viewer.js: Persist the state of sidebar
Browse files Browse the repository at this point in the history
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 mozilla#6935
  • Loading branch information
ankitaggarwal011 committed Feb 28, 2016
1 parent 9ff6c83 commit ab9403b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ var PDFViewerApplication = {
};

store.initializedPromise.then(function resolved() {
var storedHash = null;
var storedHash = null, sidebarView;
if (self.preferenceShowPreviousViewOnLoad &&
store.get('exists', false)) {
var pageNum = store.get('page', '1');
Expand All @@ -928,10 +928,14 @@ var PDFViewerApplication = {

storedHash = 'page=' + pageNum + '&zoom=' + zoom + ',' +
left + ',' + top;

sidebarView = store.get('sidebarView', SidebarView.NONE);
} else if (self.preferenceDefaultZoomValue) {
storedHash = 'page=1&zoom=' + self.preferenceDefaultZoomValue;
}
self.setInitialView(storedHash, scale);
self.setInitialView(storedHash, { scale: scale,
sidebarView: sidebarView
});

initialParams.hash = storedHash;

Expand All @@ -942,7 +946,7 @@ var PDFViewerApplication = {
}
}, function rejected(reason) {
console.error(reason);
self.setInitialView(null, scale);
self.setInitialView(null, { scale: scale });
});

// For documents with different page sizes,
Expand Down Expand Up @@ -1066,15 +1070,19 @@ 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;

// When opening a new file, when one is already loaded in the viewer,
// ensure that the 'pageNumber' element displays the correct value.
document.getElementById('pageNumber').value =
this.pdfViewer.currentPageNumber;

this.pdfSidebar.setInitialView(this.preferenceSidebarViewOnLoad);
this.pdfSidebar.setInitialView(this.preferenceSidebarViewOnLoad ||
(sidebarView | 0));

if (this.initialDestination) {
this.pdfLinkService.navigateTo(this.initialDestination);
Expand Down Expand Up @@ -1693,7 +1701,8 @@ window.addEventListener('updateviewarea', function (evt) {
'page': location.pageNumber,
'zoom': location.scale,
'scrollLeft': location.left,
'scrollTop': location.top
'scrollTop': location.top,
'sidebarView': PDFViewerApplication.pdfSidebar.visibleView
}).catch(function() {
// unable to write to storage
});
Expand Down

0 comments on commit ab9403b

Please sign in to comment.