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

Replace font loader with a resize event in reflow and scroll view #308

Merged
Prev Previous commit
Next Next commit
Save last page request or position in ScrollView
  • Loading branch information
olivierkorner committed Sep 12, 2016
commit d6be8ae3b8cde7273fc1067cfe5a95c33a54f9e5
48 changes: 46 additions & 2 deletions js/views/scroll_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var ScrollView = function (options, isContinuousScroll, reader) {
var _spine = options.spine;
var _userStyles = options.userStyles;
var _deferredPageRequest;
var _currentPageRequest;
var _$contentFrame;
var _$el;

Expand Down Expand Up @@ -274,9 +275,17 @@ var ScrollView = function (options, isContinuousScroll, reader) {
&& !_isSettingScrollPosition
&& !_isLoadingNewSpineItemOnPageRequest) {

self.resetCurrentPosition();

updateTransientViews();
onPaginationChanged(self);

_.defer(function() {
if (!_currentPageRequest) {
self.saveCurrentPosition();
}
})

var settings = reader.viewerSettings();
if (!settings.mediaOverlaysPreservePlaybackWhenScroll)
{
Expand Down Expand Up @@ -473,6 +482,31 @@ var ScrollView = function (options, isContinuousScroll, reader) {
}
};

this.resetCurrentPosition = function() {
_currentPageRequest = undefined;
};

this.saveCurrentPosition = function() {
// If there's a deferred page request, there's no point in saving the current position
// as it's going to change soon
if (_deferredPageRequest) {
return;
}

var _firstVisibleCfi = self.getFirstVisibleCfi();
var spineItem = _spine.getItemById(_firstVisibleCfi.idref);
if (spineItem) {
_currentPageRequest = new PageOpenRequest(spineItem, self);
_currentPageRequest.setElementCfi(_firstVisibleCfi.contentCFI);
}
};

this.restoreCurrentPosition = function() {
if (_currentPageRequest) {
this.openPageInternal(_currentPageRequest);
}
};

var _viewSettings = undefined;
this.setViewSettings = function (settings) {

Expand Down Expand Up @@ -509,6 +543,9 @@ var ScrollView = function (options, isContinuousScroll, reader) {
updatePageViewSize(pageView);
onPaginationChanged(self);
updateTransientViews();
if (_currentPageRequest && !_deferredPageRequest) {
self.restoreCurrentPosition();
}
}
var updatePageViewSizeAndPagination = _.debounce(updatePageViewSizeAndPagination_, 100);

Expand Down Expand Up @@ -672,7 +709,7 @@ var ScrollView = function (options, isContinuousScroll, reader) {
};


this.openPage = function (pageRequest) {
this.openPageInternal = function (pageRequest) {

_stopTransientViewUpdate = true;

Expand Down Expand Up @@ -721,6 +758,12 @@ var ScrollView = function (options, isContinuousScroll, reader) {
}
};

this.openPage = function(pageRequest) {
this.resetCurrentPosition();
_currentPageRequest = pageRequest;
this.openPageInternal(pageRequest);
}

function openPageViewElement(pageView, pageRequest) {

var topOffset = 0;
Expand Down Expand Up @@ -767,7 +810,8 @@ var ScrollView = function (options, isContinuousScroll, reader) {
return;
}

topOffset = sfiNav.getVerticalOffsetForElement($element) + pageRange.top;
var elementRange = getElementRange(pageView, $element);
topOffset = elementRange.top + pageRange.top;

}
else if (pageView && pageRequest.elementCfi) {
Expand Down