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:
parent
db798e7934
commit
fb04ac2c25
10 changed files with 390 additions and 204 deletions
529
dist/epub.js
vendored
529
dist/epub.js
vendored
File diff suppressed because it is too large
Load diff
2
dist/epub.js.map
vendored
2
dist/epub.js.map
vendored
File diff suppressed because one or more lines are too long
28
dist/polyfills.js
vendored
28
dist/polyfills.js
vendored
|
@ -76,7 +76,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
/************************************************************************/
|
||||
/******/ ({
|
||||
|
||||
/***/ 14:
|
||||
/***/ 15:
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
@ -709,7 +709,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
|
|||
|
||||
/***/ },
|
||||
|
||||
/***/ 15:
|
||||
/***/ 16:
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
/* WEBPACK VAR INJECTION */(function(process, global) {var require;/*!
|
||||
|
@ -1871,11 +1871,11 @@ return Promise;
|
|||
|
||||
ES6Promise.polyfill();
|
||||
//# 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) {
|
||||
|
||||
var g;
|
||||
|
@ -1901,7 +1901,14 @@ module.exports = g;
|
|||
|
||||
/***/ },
|
||||
|
||||
/***/ 4:
|
||||
/***/ 49:
|
||||
/***/ function(module, exports) {
|
||||
|
||||
/* (ignored) */
|
||||
|
||||
/***/ },
|
||||
|
||||
/***/ 5:
|
||||
/***/ function(module, exports) {
|
||||
|
||||
// shim for using process in browser
|
||||
|
@ -2086,20 +2093,13 @@ process.chdir = function (dir) {
|
|||
process.umask = function() { return 0; };
|
||||
|
||||
|
||||
/***/ },
|
||||
|
||||
/***/ 49:
|
||||
/***/ function(module, exports) {
|
||||
|
||||
/* (ignored) */
|
||||
|
||||
/***/ },
|
||||
|
||||
/***/ 51:
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
__webpack_require__(15);
|
||||
module.exports = __webpack_require__(14);
|
||||
__webpack_require__(16);
|
||||
module.exports = __webpack_require__(15);
|
||||
|
||||
|
||||
/***/ }
|
||||
|
|
2
dist/polyfills.js.map
vendored
2
dist/polyfills.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -388,7 +388,13 @@ Contents.prototype.locationOf = function(target, ignoreClass) {
|
|||
targetPos.left = position.left;
|
||||
targetPos.top = position.top;
|
||||
} else {
|
||||
position = range.getBoundingClientRect();
|
||||
// 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 {
|
||||
position = range.getBoundingClientRect();
|
||||
}
|
||||
targetPos.left = position.left;
|
||||
targetPos.top = position.top;
|
||||
}
|
||||
|
|
|
@ -238,6 +238,10 @@ function isNumber(n) {
|
|||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
};
|
||||
|
||||
function isFloat(n) {
|
||||
return isNumber(n) && (Math.floor(n) !== n);
|
||||
}
|
||||
|
||||
function prefixed(unprefixed) {
|
||||
var vendors = ["Webkit", "Moz", "O", "ms" ],
|
||||
prefixes = ['-Webkit-', '-moz-', '-o-', '-ms-'],
|
||||
|
@ -682,6 +686,7 @@ module.exports = {
|
|||
'indexOfSorted': indexOfSorted,
|
||||
'documentHeight': documentHeight,
|
||||
'isNumber': isNumber,
|
||||
'isFloat': isFloat,
|
||||
'prefixed': prefixed,
|
||||
'defaults': defaults,
|
||||
'extend': extend,
|
||||
|
|
|
@ -69,7 +69,7 @@ EpubCFI.prototype.checkType = function(cfi) {
|
|||
if (this.isCfiString(cfi)) {
|
||||
return 'string';
|
||||
// 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';
|
||||
} else if (typeof cfi === 'object' && typeof(cfi.nodeType) != "undefined" ){ // || typeof cfi === 'function'
|
||||
return 'node';
|
||||
|
|
|
@ -93,7 +93,7 @@ Layout.prototype.calculate = function(_width, _height, _gap){
|
|||
|
||||
//-- Double Page
|
||||
if(divisor > 1) {
|
||||
colWidth = Math.floor((width - gap) / divisor);
|
||||
colWidth = (width - gap) / divisor;
|
||||
} else {
|
||||
colWidth = width;
|
||||
}
|
||||
|
|
|
@ -248,6 +248,10 @@ Object.defineProperty(Locations.prototype, 'currentLocation', {
|
|||
}
|
||||
});
|
||||
|
||||
Locations.prototype.length = function () {
|
||||
return this._locations.length;
|
||||
};
|
||||
|
||||
EventEmitter(Locations.prototype);
|
||||
|
||||
module.exports = Locations;
|
||||
|
|
|
@ -208,11 +208,6 @@ Rendition.prototype.attachTo = function(element){
|
|||
*/
|
||||
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);
|
||||
|
||||
};
|
||||
|
@ -230,6 +225,13 @@ Rendition.prototype._display = function(target){
|
|||
var section;
|
||||
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);
|
||||
|
||||
if(!section){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue