Clarify that the page index values returned by the CFI nav are actually delta values
MODIFY
js/views/cfi_navigation_logic.js
js/views/cfi_navigation_logic.js
@@ -330,13 +330,13 @@ var CfiNavigationLogic = function (options) {
}
/**
- * Finds a page index (0-based) for a specific element.
+ * Finds a page index (0-based) delta for a specific element.
* Calculations are based on rectangles retrieved with getClientRects() method.
*
* @param {jQuery} $element
* @returns {number|null}
*/
- function findPageByRectangles($element) {
+ function findPageIndexDeltaByRectangles($element) {
var visibleContentOffsets = getVisibleContentOffsets();
@@ -345,19 +345,19 @@ var CfiNavigationLogic = function (options) {
return null;
}
- return calculatePageIndexByRectangles(clientRectangles);
+ return calculatePageIndexDeltaByRectangles(clientRectangles);
}
/**
* @private
- * Calculate a page index (0-based) for given client rectangles.
+ * Calculate a page index (0-based) delta for given client rectangles.
*
* @param {object[]} clientRectangles
* @param {object} [frameDimensions]
* @param {number} [columnFullWidth]
* @returns {number|null}
*/
- function calculatePageIndexByRectangles(clientRectangles, frameDimensions, columnFullWidth) {
+ function calculatePageIndexDeltaByRectangles(clientRectangles, frameDimensions, columnFullWidth) {
var isRtl = isPageProgressionRightToLeft();
var isVwm = isVerticalWritingMode();
columnFullWidth = columnFullWidth || getColumnFullWidth();
@@ -385,7 +385,7 @@ var CfiNavigationLogic = function (options) {
}
/**
- * Finds a page index (0-based) for a specific client rectangle.
+ * Finds a page index (0-based) delta for a specific client rectangle.
* Calculations are based on viewport dimensions, offsets, and rectangle coordinates
*
* @param {ClientRect} clientRectangle
@@ -393,14 +393,14 @@ var CfiNavigationLogic = function (options) {
* @param {Object} [frameDimensions]
* @returns {number|null}
*/
- function findPageBySingleRectangle(clientRectangle, visibleContentOffsets, frameDimensions) {
+ function findPageIndexDeltaBySingleRectangle(clientRectangle, visibleContentOffsets, frameDimensions) {
visibleContentOffsets = visibleContentOffsets || getVisibleContentOffsets();
frameDimensions = frameDimensions || getFrameDimensions();
var normalizedRectangle = normalizeRectangle(
clientRectangle, visibleContentOffsets.left, visibleContentOffsets.top);
- return calculatePageIndexByRectangles([normalizedRectangle], frameDimensions);
+ return calculatePageIndexDeltaByRectangles([normalizedRectangle], frameDimensions);
}
/**
@@ -971,13 +971,13 @@ var CfiNavigationLogic = function (options) {
return EPUBcfi.Interpreter.hasTextTerminus(getWrappedCfi(partialCfi));
}
- this.getPageIndexForCfi = function (partialCfi, classBlacklist, elementBlacklist, idBlacklist) {
+ this.getPageIndexDeltaForCfi = function (partialCfi, classBlacklist, elementBlacklist, idBlacklist) {
if (this.isRangeCfi(partialCfi)) {
//if given a range cfi the exact page index needs to be calculated by getting node info from the range cfi
var nodeRangeInfoFromCfi = this.getNodeRangeInfoFromCfi(partialCfi);
//the page index is calculated from the node's client rectangle
- return findPageBySingleRectangle(nodeRangeInfoFromCfi.clientRect);
+ return findPageIndexDeltaBySingleRectangle(nodeRangeInfoFromCfi.clientRect);
}
var $element = getElementByPartialCfi(partialCfi, classBlacklist, elementBlacklist, idBlacklist);
@@ -986,7 +986,7 @@ var CfiNavigationLogic = function (options) {
return -1;
}
- return this.getPageIndexForElement($element);
+ return this.getPageIndexDeltaForElement($element);
};
function getElementByPartialCfi(cfi, classBlacklist, elementBlacklist, idBlacklist) {
@@ -1168,12 +1168,12 @@ var CfiNavigationLogic = function (options) {
return getElementByPartialCfi(partialCfi, classBlacklist, elementBlacklist, idBlacklist);
};
- this.getPageIndexForElement = function ($element) {
+ this.getPageIndexDeltaForElement = function ($element) {
- var pageIndex = findPageByRectangles($element);
+ var pageIndex = findPageIndexDeltaByRectangles($element);
if (pageIndex === null) {
//Attempted to locate a hidden element, try a fallback with best guess
- return findPageByRectangles(this.getNearestCfiFromElement($element[0]));
+ return findPageIndexDeltaByRectangles(this.getNearestCfiFromElement($element[0]));
}
return pageIndex;
};
@@ -1192,14 +1192,14 @@ var CfiNavigationLogic = function (options) {
return $element;
};
- this.getPageIndexForElementId = function (id) {
+ this.getPageIndexDeltaForElementId = function (id) {
var $element = this.getElementById(id);
if (!$element) {
return -1;
}
- return this.getPageIndexForElement($element);
+ return this.getPageIndexDeltaForElement($element);
};
// returns raw DOM element (not $ jQuery-wrapped)

MODIFY
js/views/reflowable_view.js
js/views/reflowable_view.js
@@ -457,14 +457,14 @@ var ReflowableView = function(options, reader){
pageIndex = pageRequest.spineItemPageIndex;
}
else if(pageRequest.elementId) {
- pageIndex = _paginationInfo.currentPageIndex + _navigationLogic.getPageIndexForElementId(pageRequest.elementId);
+ pageIndex = _paginationInfo.currentPageIndex + _navigationLogic.getPageIndexDeltaForElementId(pageRequest.elementId);
}
else if(pageRequest.firstVisibleCfi && pageRequest.lastVisibleCfi) {
var firstPageIndex;
var lastPageIndex;
try
{
- firstPageIndex = _navigationLogic.getPageIndexForCfi(pageRequest.firstVisibleCfi,
+ firstPageIndex = _navigationLogic.getPageIndexDeltaForCfi(pageRequest.firstVisibleCfi,
_cfiClassBlacklist,
_cfiElementBlacklist,
_cfiIdBlacklist);
@@ -476,7 +476,7 @@ var ReflowableView = function(options, reader){
}
try
{
- lastPageIndex = _navigationLogic.getPageIndexForCfi(pageRequest.lastVisibleCfi,
+ lastPageIndex = _navigationLogic.getPageIndexDeltaForCfi(pageRequest.lastVisibleCfi,
_cfiClassBlacklist,
_cfiElementBlacklist,
_cfiIdBlacklist);
@@ -492,7 +492,7 @@ var ReflowableView = function(options, reader){
else if(pageRequest.elementCfi) {
try
{
- pageIndex = _paginationInfo.currentPageIndex + _navigationLogic.getPageIndexForCfi(pageRequest.elementCfi,
+ pageIndex = _paginationInfo.currentPageIndex + _navigationLogic.getPageIndexDeltaForCfi(pageRequest.elementCfi,
_cfiClassBlacklist,
_cfiElementBlacklist,
_cfiIdBlacklist);

Clarify that the page index values returned by the CFI nav are actually delta values