Implement new API calls for getStartCfi and getEndCfi
MODIFY
js/views/cfi_navigation_logic.js
js/views/cfi_navigation_logic.js
@@ -1313,6 +1313,25 @@ var CfiNavigationLogic = function (options) {
return visibleElements;
};
+ function getBaseCfiSelectedByFunc(pickerFunc) {
+ var $elements = self.getLeafNodeElements($(self.getBodyElement()));
+ var $selectedNode = pickerFunc($elements);
+ var collapseToStart = pickerFunc([true, false]);
+ var range = createRange();
+ range.selectNodeContents($selectedNode[0]);
+ range.collapse(collapseToStart);
+ return generateCfiFromDomRange(range);
+ }
+
+ this.getStartCfi = function () {
+ return getBaseCfiSelectedByFunc(_.first);
+ };
+
+
+ this.getEndCfi = function () {
+ return getBaseCfiSelectedByFunc(_.last);
+ };
+
this.getElementsWithFilter = function ($root, filterFunction) {
var $elements = [];

MODIFY
js/views/fixed_view.js
js/views/fixed_view.js
@@ -862,6 +862,14 @@ var FixedView = function(options, reader){
});
};
+ this.getStartCfi = function () {
+ return getDisplayingViews()[0].getStartCfi();
+ };
+
+ this.getEndCfi = function () {
+ return getDisplayingViews()[0].getEndCfi();
+ };
+
this.getNearestCfiFromElement = function(element) {
var views = getDisplayingViews();

MODIFY
js/views/one_page_view.js
js/views/one_page_view.js
@@ -1124,6 +1124,13 @@ var OnePageView = function (options, classes, enableBookStyleOverrides, reader)
return self.getNavigator().getElementFromPoint(x, y);
};
+ this.getStartCfi = function () {
+ return createBookmarkFromCfi(self.getNavigator().getStartCfi());
+ };
+
+ this.getEndCfi = function () {
+ return createBookmarkFromCfi(self.getNavigator().getEndCfi());
+ };
this.getNearestCfiFromElement = function(element) {
return createBookmarkFromCfi(self.getNavigator().getNearestCfiFromElement(element));

MODIFY
js/views/reader_view.js
js/views/reader_view.js
@@ -1628,6 +1628,29 @@ var ReaderView = function (options) {
}
return undefined;
};
+
+ /**
+ * Get CFI of the first element from the base of the document
+ * @returns {ReadiumSDK.Models.BookmarkData}
+ */
+ this.getStartCfi = function() {
+ if (_currentView) {
+ return _currentView.getStartCfi();
+ }
+ return undefined;
+ };
+
+ /**
+ * Get CFI of the last element from the base of the document
+ * @returns {ReadiumSDK.Models.BookmarkData}
+ */
+ this.getEndCfi = function() {
+ if (_currentView) {
+ return _currentView.getEndCfi();
+ }
+ return undefined;
+ };
+
/**
*
* @param {string} rangeCfi

MODIFY
js/views/reflowable_view.js
js/views/reflowable_view.js
@@ -1172,6 +1172,14 @@ var ReflowableView = function(options, reader){
return createBookmarkFromCfi(_navigationLogic.getLastVisibleCfi());
};
+ this.getStartCfi = function () {
+ return createBookmarkFromCfi(_navigationLogic.getStartCfi());
+ };
+
+ this.getEndCfi = function () {
+ return createBookmarkFromCfi(_navigationLogic.getEndCfi());
+ };
+
this.getDomRangeFromRangeCfi = function (rangeCfi, rangeCfi2, inclusive) {
if (rangeCfi2 && rangeCfi.idref !== rangeCfi2.idref) {
console.error("getDomRangeFromRangeCfi: both CFIs must be scoped under the same spineitem idref");

MODIFY
js/views/scroll_view.js
js/views/scroll_view.js
@@ -1441,6 +1441,18 @@ var ScrollView = function (options, isContinuousScroll, reader) {
});
};
+ this.getStartCfi = function () {
+ return callOnVisiblePageView(function (pageView) {
+ return pageView.getStartCfi();
+ });
+ };
+
+ this.getEndCfi = function () {
+ return callOnVisiblePageView(function (pageView) {
+ return pageView.getEndCfi();
+ });
+ };
+
this.getNearestCfiFromElement = function (element) {
return callOnVisiblePageView(function (pageView) {
return pageView.getNearestCfiFromElement(element);

Implement new API calls for getStartCfi and getEndCfi