Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for setting multiple values at once in ViewHistory #4692

Merged
merged 2 commits into from
Apr 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions web/view_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,43 @@ var ViewHistory = (function ViewHistoryClosure() {
this.database = database;
},

set: function ViewHistory_set(name, val) {
if (!this.isInitializedPromiseResolved) {
return;
}
var file = this.file;
file[name] = val;
var database = JSON.stringify(this.database);
_writeToStorage: function ViewHistory_writeToStorage() {
var databaseStr = JSON.stringify(this.database);

//#if B2G
// asyncStorage.setItem('database', database);
// asyncStorage.setItem('database', databaseStr);
//#endif

//#if FIREFOX || MOZCENTRAL
// try {
// // See comment in try-catch block above.
// sessionStorage.setItem('pdfjsHistory', database);
// sessionStorage.setItem('pdfjsHistory', databaseStr);
// } catch (ex) {}
//#endif

//#if !(FIREFOX || MOZCENTRAL || B2G)
localStorage.setItem('database', database);
localStorage.setItem('database', databaseStr);
//#endif
},

set: function ViewHistory_set(name, val) {
if (!this.isInitializedPromiseResolved) {
return;
}
this.file[name] = val;
this._writeToStorage();
},

setMultiple: function ViewHistory_setMultiple(properties) {
if (!this.isInitializedPromiseResolved) {
return;
}
for (var name in properties) {
this.file[name] = properties[name];
}
this._writeToStorage();
},

get: function ViewHistory_get(name, defaultValue) {
if (!this.isInitializedPromiseResolved) {
return defaultValue;
Expand Down
15 changes: 8 additions & 7 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1970,13 +1970,14 @@ function updateViewarea() {
PDFView.currentPosition = { page: pageNumber, left: intLeft, top: intTop };
}

var store = PDFView.store;
store.initializedPromise.then(function() {
store.set('exists', true);
store.set('page', pageNumber);
store.set('zoom', normalizedScaleValue);
store.set('scrollLeft', intLeft);
store.set('scrollTop', intTop);
PDFView.store.initializedPromise.then(function() {
PDFView.store.setMultiple({
'exists': true,
'page': pageNumber,
'zoom': normalizedScaleValue,
'scrollLeft': intLeft,
'scrollTop': intTop
});
});
var href = PDFView.getAnchorUrl(pdfOpenParams);
document.getElementById('viewBookmark').href = href;
Expand Down