1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

Update display to accept percentages, handle getting location of collapsed ranges

This commit is contained in:
Fred Chasen 2016-11-23 20:47:07 +01:00
parent db798e7934
commit fb04ac2c25
10 changed files with 390 additions and 204 deletions

469
dist/epub.js vendored

File diff suppressed because it is too large Load diff

2
dist/epub.js.map vendored

File diff suppressed because one or more lines are too long

28
dist/polyfills.js vendored
View file

@ -76,7 +76,7 @@ return /******/ (function(modules) { // webpackBootstrap
/************************************************************************/ /************************************************************************/
/******/ ({ /******/ ({
/***/ 14: /***/ 15:
/***/ function(module, exports, __webpack_require__) { /***/ function(module, exports, __webpack_require__) {
"use strict"; "use strict";
@ -709,7 +709,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
/***/ }, /***/ },
/***/ 15: /***/ 16:
/***/ function(module, exports, __webpack_require__) { /***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process, global) {var require;/*! /* WEBPACK VAR INJECTION */(function(process, global) {var require;/*!
@ -1871,11 +1871,11 @@ return Promise;
ES6Promise.polyfill(); ES6Promise.polyfill();
//# sourceMappingURL=es6-promise.auto.map //# sourceMappingURL=es6-promise.auto.map
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4), __webpack_require__(35))) /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5), __webpack_require__(4)))
/***/ }, /***/ },
/***/ 35: /***/ 4:
/***/ function(module, exports) { /***/ function(module, exports) {
var g; var g;
@ -1901,7 +1901,14 @@ module.exports = g;
/***/ }, /***/ },
/***/ 4: /***/ 49:
/***/ function(module, exports) {
/* (ignored) */
/***/ },
/***/ 5:
/***/ function(module, exports) { /***/ function(module, exports) {
// shim for using process in browser // shim for using process in browser
@ -2086,20 +2093,13 @@ process.chdir = function (dir) {
process.umask = function() { return 0; }; process.umask = function() { return 0; };
/***/ },
/***/ 49:
/***/ function(module, exports) {
/* (ignored) */
/***/ }, /***/ },
/***/ 51: /***/ 51:
/***/ function(module, exports, __webpack_require__) { /***/ function(module, exports, __webpack_require__) {
__webpack_require__(15); __webpack_require__(16);
module.exports = __webpack_require__(14); module.exports = __webpack_require__(15);
/***/ } /***/ }

File diff suppressed because one or more lines are too long

View file

@ -387,8 +387,14 @@ Contents.prototype.locationOf = function(target, ignoreClass) {
position = range.startContainer.getBoundingClientRect(); position = range.startContainer.getBoundingClientRect();
targetPos.left = position.left; targetPos.left = position.left;
targetPos.top = position.top; targetPos.top = position.top;
} else {
// Webkit does not handle collapsed range bounds correctly
// https://bugs.webkit.org/show_bug.cgi?id=138949
if (range.collapsed) {
position = range.getClientRects()[0];
} else { } else {
position = range.getBoundingClientRect(); position = range.getBoundingClientRect();
}
targetPos.left = position.left; targetPos.left = position.left;
targetPos.top = position.top; targetPos.top = position.top;
} }

View file

@ -238,6 +238,10 @@ function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n); return !isNaN(parseFloat(n)) && isFinite(n);
}; };
function isFloat(n) {
return isNumber(n) && (Math.floor(n) !== n);
}
function prefixed(unprefixed) { function prefixed(unprefixed) {
var vendors = ["Webkit", "Moz", "O", "ms" ], var vendors = ["Webkit", "Moz", "O", "ms" ],
prefixes = ['-Webkit-', '-moz-', '-o-', '-ms-'], prefixes = ['-Webkit-', '-moz-', '-o-', '-ms-'],
@ -682,6 +686,7 @@ module.exports = {
'indexOfSorted': indexOfSorted, 'indexOfSorted': indexOfSorted,
'documentHeight': documentHeight, 'documentHeight': documentHeight,
'isNumber': isNumber, 'isNumber': isNumber,
'isFloat': isFloat,
'prefixed': prefixed, 'prefixed': prefixed,
'defaults': defaults, 'defaults': defaults,
'extend': extend, 'extend': extend,

View file

@ -69,7 +69,7 @@ EpubCFI.prototype.checkType = function(cfi) {
if (this.isCfiString(cfi)) { if (this.isCfiString(cfi)) {
return 'string'; return 'string';
// Is a range object // Is a range object
} else if (typeof cfi === 'object' && (core.type(cfi) === "Range" || typeof(cfi.startContainer) != "undefined")){ } else if (typeof cfi === 'object' && (core.type(cfi) === "Range" || typeof(cfi.startContainer) != "undefined")){
return 'range'; return 'range';
} else if (typeof cfi === 'object' && typeof(cfi.nodeType) != "undefined" ){ // || typeof cfi === 'function' } else if (typeof cfi === 'object' && typeof(cfi.nodeType) != "undefined" ){ // || typeof cfi === 'function'
return 'node'; return 'node';

View file

@ -93,7 +93,7 @@ Layout.prototype.calculate = function(_width, _height, _gap){
//-- Double Page //-- Double Page
if(divisor > 1) { if(divisor > 1) {
colWidth = Math.floor((width - gap) / divisor); colWidth = (width - gap) / divisor;
} else { } else {
colWidth = width; colWidth = width;
} }

View file

@ -248,6 +248,10 @@ Object.defineProperty(Locations.prototype, 'currentLocation', {
} }
}); });
Locations.prototype.length = function () {
return this._locations.length;
};
EventEmitter(Locations.prototype); EventEmitter(Locations.prototype);
module.exports = Locations; module.exports = Locations;

View file

@ -208,11 +208,6 @@ Rendition.prototype.attachTo = function(element){
*/ */
Rendition.prototype.display = function(target){ Rendition.prototype.display = function(target){
// if (!this.book.spine.spineItems.length > 0) {
// Book isn't open yet
// return this.q.enqueue(this.display, target);
// }
return this.q.enqueue(this._display, target); return this.q.enqueue(this._display, target);
}; };
@ -230,6 +225,13 @@ Rendition.prototype._display = function(target){
var section; var section;
var moveTo; var moveTo;
// Check if this is a book percentage
if (this.book.locations.length && core.isFloat(target)) {
console.log("percentage", target);
target = book.locations.cfiFromPercentage(target);
console.log("cfi", target);
}
section = this.book.spine.get(target); section = this.book.spine.get(target);
if(!section){ if(!section){