mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
Fix eslint errors
This commit is contained in:
parent
c99bfd07b7
commit
a435650c3b
31 changed files with 1077 additions and 1102 deletions
|
@ -1,9 +1,9 @@
|
|||
import {extend, defer, requestAnimationFrame} from '../../utils/core';
|
||||
import DefaultViewManager from '../default';
|
||||
import {extend, defer, requestAnimationFrame} from "../../utils/core";
|
||||
import DefaultViewManager from "../default";
|
||||
|
||||
class ContinuousViewManager extends DefaultViewManager {
|
||||
constructor(options) {
|
||||
super(options)
|
||||
super(options);
|
||||
// DefaultViewManager.apply(this, arguments); // call super constructor.
|
||||
|
||||
this.name = "continuous";
|
||||
|
@ -36,14 +36,14 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
|
||||
this.scrollTop = 0;
|
||||
this.scrollLeft = 0;
|
||||
};
|
||||
}
|
||||
|
||||
display(section, target){
|
||||
return DefaultViewManager.prototype.display.call(this, section, target)
|
||||
.then(function () {
|
||||
return this.fill();
|
||||
}.bind(this));
|
||||
};
|
||||
}
|
||||
|
||||
fill(_full){
|
||||
var full = _full || new defer();
|
||||
|
@ -80,7 +80,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
.then(function(){
|
||||
this.scrollBy(distX, distY);
|
||||
}.bind(this));
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
afterDisplayed(currView){
|
||||
|
@ -103,7 +103,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
// currView.onShown = this.afterDisplayed.bind(this);
|
||||
this.emit("added", currView.section);
|
||||
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
resize(width, height){
|
||||
|
@ -134,7 +134,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
height: this.stage.height
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
onResized(e) {
|
||||
|
||||
|
@ -144,11 +144,11 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
this.resizeTimeout = setTimeout(function(){
|
||||
this.resize();
|
||||
}.bind(this), 150);
|
||||
};
|
||||
}
|
||||
|
||||
afterResized(view){
|
||||
this.emit("resize", view.section);
|
||||
};
|
||||
}
|
||||
|
||||
// Remove Previous Listeners if present
|
||||
removeShownListeners(view){
|
||||
|
@ -157,7 +157,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
// view.off("shown", this.afterDisplayedAbove);
|
||||
view.onDisplayed = function(){};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// append(section){
|
||||
|
@ -182,7 +182,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
var view = this.createView(section);
|
||||
this.views.append(view);
|
||||
return view;
|
||||
};
|
||||
}
|
||||
|
||||
prepend(section){
|
||||
var view = this.createView(section);
|
||||
|
@ -191,7 +191,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
|
||||
this.views.prepend(view);
|
||||
return view;
|
||||
};
|
||||
}
|
||||
|
||||
counter(bounds){
|
||||
|
||||
|
@ -201,7 +201,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
this.scrollBy(bounds.widthDelta, 0, true);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
update(_offset){
|
||||
var container = this.bounds();
|
||||
|
@ -245,7 +245,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
return updating.promise;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
check(_offsetLeft, _offsetTop){
|
||||
var last, first, next, prev;
|
||||
|
@ -290,9 +290,9 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
// Promise.all(promises)
|
||||
// .then(function() {
|
||||
// Check to see if anything new is on screen after rendering
|
||||
return this.q.enqueue(function(){
|
||||
return this.update(delta);
|
||||
}.bind(this));
|
||||
return this.q.enqueue(function(){
|
||||
return this.update(delta);
|
||||
}.bind(this));
|
||||
|
||||
|
||||
// }.bind(this));
|
||||
|
@ -303,7 +303,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
trim(){
|
||||
var task = new defer();
|
||||
|
@ -327,7 +327,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
|
||||
task.resolve();
|
||||
return task.promise;
|
||||
};
|
||||
}
|
||||
|
||||
erase(view, above){ //Trim
|
||||
|
||||
|
@ -355,18 +355,18 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
addEventListeners(stage){
|
||||
|
||||
window.addEventListener('unload', function(e){
|
||||
window.addEventListener("unload", function(e){
|
||||
this.ignore = true;
|
||||
// this.scrollTo(0,0);
|
||||
this.destroy();
|
||||
}.bind(this));
|
||||
|
||||
this.addScrollListeners();
|
||||
};
|
||||
}
|
||||
|
||||
addScrollListeners() {
|
||||
var scroller;
|
||||
|
@ -400,7 +400,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
|
||||
this.scrolled = false;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
onScroll(){
|
||||
let scrollTop;
|
||||
|
@ -408,70 +408,70 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
|
||||
// if(!this.ignore) {
|
||||
|
||||
if(this.settings.height) {
|
||||
scrollTop = this.container.scrollTop;
|
||||
scrollLeft = this.container.scrollLeft;
|
||||
} else {
|
||||
scrollTop = window.scrollY;
|
||||
scrollLeft = window.scrollX;
|
||||
}
|
||||
if(this.settings.height) {
|
||||
scrollTop = this.container.scrollTop;
|
||||
scrollLeft = this.container.scrollLeft;
|
||||
} else {
|
||||
scrollTop = window.scrollY;
|
||||
scrollLeft = window.scrollX;
|
||||
}
|
||||
|
||||
this.scrollTop = scrollTop;
|
||||
this.scrollLeft = scrollLeft;
|
||||
this.scrollTop = scrollTop;
|
||||
this.scrollLeft = scrollLeft;
|
||||
|
||||
if(!this.ignore) {
|
||||
if(!this.ignore) {
|
||||
|
||||
if((this.scrollDeltaVert === 0 &&
|
||||
this.scrollDeltaHorz === 0) ||
|
||||
this.scrollDeltaVert > this.settings.offsetDelta ||
|
||||
this.scrollDeltaHorz > this.settings.offsetDelta) {
|
||||
if((this.scrollDeltaVert === 0 &&
|
||||
this.scrollDeltaHorz === 0) ||
|
||||
this.scrollDeltaVert > this.settings.offsetDelta ||
|
||||
this.scrollDeltaHorz > this.settings.offsetDelta) {
|
||||
|
||||
this.q.enqueue(function() {
|
||||
this.check();
|
||||
}.bind(this));
|
||||
// this.check();
|
||||
this.q.enqueue(function() {
|
||||
this.check();
|
||||
}.bind(this));
|
||||
// this.check();
|
||||
|
||||
this.scrollDeltaVert = 0;
|
||||
this.scrollDeltaHorz = 0;
|
||||
|
||||
this.emit("scroll", {
|
||||
top: scrollTop,
|
||||
left: scrollLeft
|
||||
});
|
||||
|
||||
clearTimeout(this.afterScrolled);
|
||||
this.afterScrolled = setTimeout(function () {
|
||||
this.emit("scrolled", {
|
||||
top: this.scrollTop,
|
||||
left: this.scrollLeft
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
this.ignore = false;
|
||||
}
|
||||
|
||||
this.scrollDeltaVert += Math.abs(scrollTop-this.prevScrollTop);
|
||||
this.scrollDeltaHorz += Math.abs(scrollLeft-this.prevScrollLeft);
|
||||
|
||||
this.prevScrollTop = scrollTop;
|
||||
this.prevScrollLeft = scrollLeft;
|
||||
|
||||
clearTimeout(this.scrollTimeout);
|
||||
this.scrollTimeout = setTimeout(function(){
|
||||
this.scrollDeltaVert = 0;
|
||||
this.scrollDeltaHorz = 0;
|
||||
}.bind(this), 150);
|
||||
|
||||
this.emit("scroll", {
|
||||
top: scrollTop,
|
||||
left: scrollLeft
|
||||
});
|
||||
|
||||
clearTimeout(this.afterScrolled);
|
||||
this.afterScrolled = setTimeout(function () {
|
||||
this.emit("scrolled", {
|
||||
top: this.scrollTop,
|
||||
left: this.scrollLeft
|
||||
});
|
||||
}.bind(this));
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
this.ignore = false;
|
||||
}
|
||||
|
||||
this.scrollDeltaVert += Math.abs(scrollTop-this.prevScrollTop);
|
||||
this.scrollDeltaHorz += Math.abs(scrollLeft-this.prevScrollLeft);
|
||||
|
||||
this.prevScrollTop = scrollTop;
|
||||
this.prevScrollLeft = scrollLeft;
|
||||
|
||||
clearTimeout(this.scrollTimeout);
|
||||
this.scrollTimeout = setTimeout(function(){
|
||||
this.scrollDeltaVert = 0;
|
||||
this.scrollDeltaHorz = 0;
|
||||
}.bind(this), 150);
|
||||
|
||||
|
||||
this.scrolled = false;
|
||||
this.scrolled = false;
|
||||
// }
|
||||
|
||||
// this.tick.call(window, this.onScroll.bind(this));
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// resizeView(view) {
|
||||
|
@ -493,14 +493,14 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
}
|
||||
|
||||
return this.location;
|
||||
};
|
||||
}
|
||||
|
||||
scrolledLocation(){
|
||||
|
||||
var visible = this.visible();
|
||||
var startPage, endPage;
|
||||
|
||||
var container = this.container.getBoundingClientRect();
|
||||
// var container = this.container.getBoundingClientRect();
|
||||
|
||||
if(visible.length === 1) {
|
||||
return this.mapping.page(visible[0].contents, visible[0].section.cfiBase);
|
||||
|
@ -517,7 +517,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
};
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
paginatedLocation(){
|
||||
var visible = this.visible();
|
||||
|
@ -550,7 +550,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
end: pageRight.end
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
current(what){
|
||||
|
@ -595,7 +595,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
}
|
||||
|
||||
return this._current;
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
updateLayout() {
|
||||
|
@ -626,7 +626,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
|
||||
this.setLayout(this.layout);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
next(){
|
||||
|
||||
|
@ -645,7 +645,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
} else {
|
||||
this.scrollBy(0, this.layout.height);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
prev(){
|
||||
if(this.settings.axis === "horizontal") {
|
||||
|
@ -653,7 +653,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
} else {
|
||||
this.scrollBy(0, -this.layout.height);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
updateFlow(flow){
|
||||
var axis = (flow === "paginated") ? "horizontal" : "vertical";
|
||||
|
@ -674,7 +674,7 @@ class ContinuousViewManager extends DefaultViewManager {
|
|||
this.settings.infinite = false;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default ContinuousViewManager;
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import EventEmitter from 'event-emitter';
|
||||
import {extend, defer} from '../../utils/core';
|
||||
import EpubCFI from '../../epubcfi';
|
||||
import Mapping from '../../mapping';
|
||||
import Queue from '../../queue';
|
||||
import Stage from '../helpers/stage';
|
||||
import Views from '../helpers/views';
|
||||
import EventEmitter from "event-emitter";
|
||||
import {extend, defer} from "../../utils/core";
|
||||
import Mapping from "../../mapping";
|
||||
import Queue from "../../utils/queue";
|
||||
import Stage from "../helpers/stage";
|
||||
import Views from "../helpers/views";
|
||||
|
||||
class DefaultViewManager {
|
||||
constructor(options) {
|
||||
|
@ -20,10 +19,10 @@ class DefaultViewManager {
|
|||
hidden: false,
|
||||
width: undefined,
|
||||
height: undefined,
|
||||
// globalLayoutProperties : { layout: 'reflowable', spread: 'auto', orientation: 'auto'},
|
||||
// globalLayoutProperties : { layout: "reflowable", spread: "auto", orientation: "auto"},
|
||||
// layout: null,
|
||||
axis: "vertical",
|
||||
ignoreClass: ''
|
||||
ignoreClass: ""
|
||||
});
|
||||
|
||||
extend(this.settings, options.settings || {});
|
||||
|
@ -77,13 +76,13 @@ class DefaultViewManager {
|
|||
if (this.layout) {
|
||||
this.updateLayout();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
addEventListeners(){
|
||||
window.addEventListener('unload', function(e){
|
||||
window.addEventListener("unload", function(e){
|
||||
this.destroy();
|
||||
}.bind(this));
|
||||
};
|
||||
}
|
||||
|
||||
destroy(){
|
||||
// this.views.each(function(view){
|
||||
|
@ -99,14 +98,14 @@ class DefaultViewManager {
|
|||
this.element.removeChild(this.container);
|
||||
}
|
||||
*/
|
||||
};
|
||||
}
|
||||
|
||||
onResized(e) {
|
||||
clearTimeout(this.resizeTimeout);
|
||||
this.resizeTimeout = setTimeout(function(){
|
||||
this.resize();
|
||||
}.bind(this), 150);
|
||||
};
|
||||
}
|
||||
|
||||
resize(width, height){
|
||||
|
||||
|
@ -132,11 +131,11 @@ class DefaultViewManager {
|
|||
height: this.stage.height
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
createView(section) {
|
||||
return new this.View(section, this.viewSettings);
|
||||
};
|
||||
}
|
||||
|
||||
display(section, target){
|
||||
|
||||
|
@ -185,23 +184,23 @@ class DefaultViewManager {
|
|||
|
||||
displaying.resolve();
|
||||
|
||||
}.bind(this))
|
||||
}.bind(this));
|
||||
// .then(function(){
|
||||
// return this.hooks.display.trigger(view);
|
||||
// }.bind(this))
|
||||
// .then(function(){
|
||||
// this.views.show();
|
||||
// }.bind(this));
|
||||
return displayed;
|
||||
};
|
||||
return displayed;
|
||||
}
|
||||
|
||||
afterDisplayed(view){
|
||||
this.emit("added", view);
|
||||
};
|
||||
}
|
||||
|
||||
afterResized(view){
|
||||
this.emit("resize", view.section);
|
||||
};
|
||||
}
|
||||
|
||||
// moveTo(offset){
|
||||
// this.scrollTo(offset.left, offset.top);
|
||||
|
@ -209,7 +208,7 @@ class DefaultViewManager {
|
|||
|
||||
moveTo(offset){
|
||||
var distX = 0,
|
||||
distY = 0;
|
||||
distY = 0;
|
||||
|
||||
if(this.settings.axis === "vertical") {
|
||||
distY = offset.top;
|
||||
|
@ -222,7 +221,7 @@ class DefaultViewManager {
|
|||
}
|
||||
|
||||
this.scrollTo(distX, distY);
|
||||
};
|
||||
}
|
||||
|
||||
add(section){
|
||||
var view = this.createView(section);
|
||||
|
@ -235,20 +234,20 @@ class DefaultViewManager {
|
|||
|
||||
return view.display(this.request);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
append(section){
|
||||
var view = this.createView(section);
|
||||
this.views.append(view);
|
||||
return view.display(this.request);
|
||||
};
|
||||
}
|
||||
|
||||
prepend(section){
|
||||
var view = this.createView(section);
|
||||
|
||||
this.views.prepend(view);
|
||||
return view.display(this.request);
|
||||
};
|
||||
}
|
||||
// resizeView(view) {
|
||||
//
|
||||
// if(this.settings.globalLayoutProperties.layout === "pre-paginated") {
|
||||
|
@ -261,7 +260,6 @@ class DefaultViewManager {
|
|||
|
||||
next(){
|
||||
var next;
|
||||
var view;
|
||||
var left;
|
||||
|
||||
if(!this.views.length) return;
|
||||
|
@ -306,11 +304,10 @@ class DefaultViewManager {
|
|||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
prev(){
|
||||
var prev;
|
||||
var view;
|
||||
var left;
|
||||
|
||||
if(!this.views.length) return;
|
||||
|
@ -354,7 +351,7 @@ class DefaultViewManager {
|
|||
this.views.show();
|
||||
}.bind(this));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
current(){
|
||||
var visible = this.visible();
|
||||
|
@ -363,7 +360,7 @@ class DefaultViewManager {
|
|||
return visible[visible.length-1];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
currentLocation(){
|
||||
|
||||
|
@ -373,7 +370,7 @@ class DefaultViewManager {
|
|||
this.location = this.paginatedLocation();
|
||||
}
|
||||
return this.location;
|
||||
};
|
||||
}
|
||||
|
||||
scrolledLocation(){
|
||||
var view;
|
||||
|
@ -383,7 +380,7 @@ class DefaultViewManager {
|
|||
return this.mapping.page(view, view.section.cfiBase);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
paginatedLocation(){
|
||||
var view;
|
||||
|
@ -396,7 +393,7 @@ class DefaultViewManager {
|
|||
return this.mapping.page(view, view.section.cfiBase, start, end);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
isVisible(view, offsetPrev, offsetNext, _container){
|
||||
var position = view.position();
|
||||
|
@ -417,7 +414,7 @@ class DefaultViewManager {
|
|||
|
||||
return false;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
visible(){
|
||||
// return this.views.displayed();
|
||||
|
@ -438,7 +435,7 @@ class DefaultViewManager {
|
|||
|
||||
}
|
||||
return visible;
|
||||
};
|
||||
}
|
||||
|
||||
scrollBy(x, y, silent){
|
||||
if(silent) {
|
||||
|
@ -456,7 +453,7 @@ class DefaultViewManager {
|
|||
// console.log("scrollBy", x, y);
|
||||
this.scrolled = true;
|
||||
this.onScroll();
|
||||
};
|
||||
}
|
||||
|
||||
scrollTo(x, y, silent){
|
||||
if(silent) {
|
||||
|
@ -478,11 +475,11 @@ class DefaultViewManager {
|
|||
// }.bind(this), 10);
|
||||
// return;
|
||||
// };
|
||||
};
|
||||
}
|
||||
|
||||
onScroll(){
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
bounds() {
|
||||
var bounds;
|
||||
|
@ -490,7 +487,7 @@ class DefaultViewManager {
|
|||
bounds = this.stage.bounds();
|
||||
|
||||
return bounds;
|
||||
};
|
||||
}
|
||||
|
||||
applyLayout(layout) {
|
||||
|
||||
|
@ -499,7 +496,7 @@ class DefaultViewManager {
|
|||
|
||||
this.mapping = new Mapping(this.layout);
|
||||
// this.manager.layout(this.layout.format);
|
||||
};
|
||||
}
|
||||
|
||||
updateLayout() {
|
||||
if (!this.stage) {
|
||||
|
@ -530,7 +527,7 @@ class DefaultViewManager {
|
|||
|
||||
this.setLayout(this.layout);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
setLayout(layout){
|
||||
|
||||
|
@ -544,7 +541,7 @@ class DefaultViewManager {
|
|||
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
updateFlow(flow){
|
||||
var axis = (flow === "paginated") ? "horizontal" : "vertical";
|
||||
|
@ -558,7 +555,7 @@ class DefaultViewManager {
|
|||
// view.setAxis(axis);
|
||||
// });
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
getContents(){
|
||||
var contents = [];
|
||||
|
@ -566,10 +563,10 @@ class DefaultViewManager {
|
|||
contents.push(view.contents);
|
||||
});
|
||||
return contents;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//-- Enable binding events to Manager
|
||||
EventEmitter(DefaultViewManager.prototype);
|
||||
//-- Enable binding events to Manager
|
||||
EventEmitter(DefaultViewManager.prototype);
|
||||
|
||||
export default DefaultViewManager;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {uuid, isNumber, isElement, windowBounds} from '../../utils/core';
|
||||
import {uuid, isNumber, isElement, windowBounds} from "../../utils/core";
|
||||
|
||||
class Stage {
|
||||
constructor(_options) {
|
||||
|
@ -60,7 +60,7 @@ class Stage {
|
|||
}
|
||||
|
||||
return container;
|
||||
};
|
||||
}
|
||||
|
||||
wrap(container) {
|
||||
var wrapper = document.createElement("div");
|
||||
|
@ -72,7 +72,7 @@ class Stage {
|
|||
|
||||
wrapper.appendChild(container);
|
||||
return wrapper;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
getElement(_element){
|
||||
|
@ -85,12 +85,11 @@ class Stage {
|
|||
}
|
||||
|
||||
if(!element){
|
||||
console.error("Not an Element");
|
||||
return;
|
||||
throw new Error("Not an Element");
|
||||
}
|
||||
|
||||
return element;
|
||||
};
|
||||
}
|
||||
|
||||
attachTo(what){
|
||||
|
||||
|
@ -113,11 +112,11 @@ class Stage {
|
|||
|
||||
return element;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
getContainer() {
|
||||
return this.container;
|
||||
};
|
||||
}
|
||||
|
||||
onResize(func){
|
||||
// Only listen to window for resize event if width and height are not fixed.
|
||||
|
@ -127,7 +126,7 @@ class Stage {
|
|||
window.addEventListener("resize", func, false);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
size(width, height){
|
||||
var bounds;
|
||||
|
@ -185,7 +184,7 @@ class Stage {
|
|||
this.containerPadding.bottom
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
bounds(){
|
||||
|
||||
|
@ -222,7 +221,7 @@ class Stage {
|
|||
rules += prop + ":" + set[prop] + ";";
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
this.sheet.insertRule(scope + selector + " {" + rules + "}", 0);
|
||||
}
|
||||
|
|
|
@ -4,31 +4,31 @@ class Views {
|
|||
this._views = [];
|
||||
this.length = 0;
|
||||
this.hidden = false;
|
||||
};
|
||||
}
|
||||
|
||||
all() {
|
||||
return this._views;
|
||||
};
|
||||
}
|
||||
|
||||
first() {
|
||||
return this._views[0];
|
||||
};
|
||||
}
|
||||
|
||||
last() {
|
||||
return this._views[this._views.length-1];
|
||||
};
|
||||
}
|
||||
|
||||
indexOf(view) {
|
||||
return this._views.indexOf(view);
|
||||
};
|
||||
}
|
||||
|
||||
slice() {
|
||||
return this._views.slice.apply(this._views, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
get(i) {
|
||||
return this._views[i];
|
||||
};
|
||||
}
|
||||
|
||||
append(view){
|
||||
this._views.push(view);
|
||||
|
@ -37,7 +37,7 @@ class Views {
|
|||
}
|
||||
this.length++;
|
||||
return view;
|
||||
};
|
||||
}
|
||||
|
||||
prepend(view){
|
||||
this._views.unshift(view);
|
||||
|
@ -46,7 +46,7 @@ class Views {
|
|||
}
|
||||
this.length++;
|
||||
return view;
|
||||
};
|
||||
}
|
||||
|
||||
insert(view, index) {
|
||||
this._views.splice(index, 0, view);
|
||||
|
@ -61,7 +61,7 @@ class Views {
|
|||
|
||||
this.length++;
|
||||
return view;
|
||||
};
|
||||
}
|
||||
|
||||
remove(view) {
|
||||
var index = this._views.indexOf(view);
|
||||
|
@ -74,7 +74,7 @@ class Views {
|
|||
this.destroy(view);
|
||||
|
||||
this.length--;
|
||||
};
|
||||
}
|
||||
|
||||
destroy(view) {
|
||||
if(view.displayed){
|
||||
|
@ -85,13 +85,13 @@ class Views {
|
|||
this.container.removeChild(view.element);
|
||||
}
|
||||
view = null;
|
||||
};
|
||||
}
|
||||
|
||||
// Iterators
|
||||
|
||||
each() {
|
||||
return this._views.forEach.apply(this._views, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
clear(){
|
||||
// Remove all views
|
||||
|
@ -107,7 +107,7 @@ class Views {
|
|||
|
||||
this._views = [];
|
||||
this.length = 0;
|
||||
};
|
||||
}
|
||||
|
||||
find(section){
|
||||
|
||||
|
@ -121,7 +121,7 @@ class Views {
|
|||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
displayed(){
|
||||
var displayed = [];
|
||||
|
@ -135,7 +135,7 @@ class Views {
|
|||
}
|
||||
}
|
||||
return displayed;
|
||||
};
|
||||
}
|
||||
|
||||
show(){
|
||||
var view;
|
||||
|
@ -148,7 +148,7 @@ class Views {
|
|||
}
|
||||
}
|
||||
this.hidden = false;
|
||||
};
|
||||
}
|
||||
|
||||
hide(){
|
||||
var view;
|
||||
|
@ -161,7 +161,7 @@ class Views {
|
|||
}
|
||||
}
|
||||
this.hidden = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default Views;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import EventEmitter from 'event-emitter';
|
||||
import {extend, borders, uuid, isNumber, bounds, defer} from '../../utils/core';
|
||||
import EpubCFI from '../../epubcfi';
|
||||
import Contents from '../../contents';
|
||||
import EventEmitter from "event-emitter";
|
||||
import {extend, borders, uuid, isNumber, bounds, defer} from "../../utils/core";
|
||||
import EpubCFI from "../../epubcfi";
|
||||
import Contents from "../../contents";
|
||||
|
||||
class IframeView {
|
||||
constructor(section, options) {
|
||||
this.settings = extend({
|
||||
ignoreClass : '',
|
||||
axis: 'vertical',
|
||||
ignoreClass : "",
|
||||
axis: "vertical",
|
||||
width: 0,
|
||||
height: 0,
|
||||
layout: undefined,
|
||||
|
@ -36,10 +36,10 @@ class IframeView {
|
|||
this.layout = this.settings.layout;
|
||||
// Dom events to listen for
|
||||
// this.listenedEvents = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click", "touchend", "touchstart"];
|
||||
};
|
||||
}
|
||||
|
||||
container(axis) {
|
||||
var element = document.createElement('div');
|
||||
var element = document.createElement("div");
|
||||
|
||||
element.classList.add("epub-view");
|
||||
|
||||
|
@ -55,7 +55,7 @@ class IframeView {
|
|||
}
|
||||
|
||||
return element;
|
||||
};
|
||||
}
|
||||
|
||||
create() {
|
||||
|
||||
|
@ -67,7 +67,7 @@ class IframeView {
|
|||
this.element = this.createContainer();
|
||||
}
|
||||
|
||||
this.iframe = document.createElement('iframe');
|
||||
this.iframe = document.createElement("iframe");
|
||||
this.iframe.id = this.id;
|
||||
this.iframe.scrolling = "no"; // Might need to be removed: breaks ios width calculations
|
||||
this.iframe.style.overflow = "hidden";
|
||||
|
@ -102,14 +102,14 @@ class IframeView {
|
|||
// Firefox has trouble with baseURI and srcdoc
|
||||
// TODO: Disable for now in firefox
|
||||
|
||||
if(!!("srcdoc" in this.iframe)) {
|
||||
if(!("srcdoc" in this.iframe)) {
|
||||
this.supportsSrcdoc = true;
|
||||
} else {
|
||||
this.supportsSrcdoc = false;
|
||||
}
|
||||
|
||||
return this.iframe;
|
||||
};
|
||||
}
|
||||
|
||||
render(request, show) {
|
||||
|
||||
|
@ -163,11 +163,10 @@ class IframeView {
|
|||
|
||||
}.bind(this))
|
||||
.catch(function(e){
|
||||
console.error(e);
|
||||
this.emit("loaderror", e);
|
||||
}.bind(this));
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// Determine locks base on settings
|
||||
size(_width, _height) {
|
||||
|
@ -182,7 +181,7 @@ class IframeView {
|
|||
this.lock("width", width, height);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// Lock an axis to element dimensions, taking borders into account
|
||||
lock(what, width, height) {
|
||||
|
@ -217,14 +216,14 @@ class IframeView {
|
|||
|
||||
if(this.displayed && this.iframe) {
|
||||
|
||||
// this.contents.layout();
|
||||
this.expand();
|
||||
// this.contents.layout();
|
||||
this.expand();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// Resize a single axis based on content dimensions
|
||||
expand(force) {
|
||||
|
@ -254,8 +253,8 @@ class IframeView {
|
|||
if ( this.settings.layout.divisor > 1 &&
|
||||
this.settings.layout.name === "reflowable" &&
|
||||
(columns % 2 > 0)) {
|
||||
// add a blank page
|
||||
width += this.settings.layout.gap + this.settings.layout.columnWidth;
|
||||
// add a blank page
|
||||
width += this.settings.layout.gap + this.settings.layout.columnWidth;
|
||||
}
|
||||
|
||||
// Save the textWdith
|
||||
|
@ -286,7 +285,7 @@ class IframeView {
|
|||
}
|
||||
|
||||
this._expanding = false;
|
||||
};
|
||||
}
|
||||
|
||||
contentWidth(min) {
|
||||
var prev;
|
||||
|
@ -302,7 +301,7 @@ class IframeView {
|
|||
// Reset iframe size back
|
||||
this.iframe.style.width = prev;
|
||||
return width;
|
||||
};
|
||||
}
|
||||
|
||||
contentHeight(min) {
|
||||
var prev;
|
||||
|
@ -314,7 +313,7 @@ class IframeView {
|
|||
|
||||
this.iframe.style.height = prev;
|
||||
return height;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
resize(width, height) {
|
||||
|
@ -335,7 +334,7 @@ class IframeView {
|
|||
|
||||
this.reframe(this.iframeBounds.width, this.iframeBounds.height);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
reframe(width, height) {
|
||||
var size;
|
||||
|
@ -367,7 +366,7 @@ class IframeView {
|
|||
|
||||
this.emit("resized", size);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
load(contents) {
|
||||
|
@ -403,35 +402,35 @@ class IframeView {
|
|||
}
|
||||
|
||||
return loaded;
|
||||
};
|
||||
}
|
||||
|
||||
onLoad(event, promise) {
|
||||
|
||||
this.window = this.iframe.contentWindow;
|
||||
this.document = this.iframe.contentDocument;
|
||||
this.window = this.iframe.contentWindow;
|
||||
this.document = this.iframe.contentDocument;
|
||||
|
||||
this.contents = new Contents(this.document, this.document.body, this.section.cfiBase);
|
||||
this.contents = new Contents(this.document, this.document.body, this.section.cfiBase);
|
||||
|
||||
this.rendering = false;
|
||||
this.rendering = false;
|
||||
|
||||
var link = this.document.querySelector("link[rel='canonical']");
|
||||
if (link) {
|
||||
link.setAttribute("href", this.section.url);
|
||||
} else {
|
||||
link = this.document.createElement("link");
|
||||
link.setAttribute("rel", "canonical");
|
||||
link.setAttribute("href", this.section.url);
|
||||
this.document.querySelector("head").appendChild(link);
|
||||
var link = this.document.querySelector("link[rel='canonical']");
|
||||
if (link) {
|
||||
link.setAttribute("href", this.section.url);
|
||||
} else {
|
||||
link = this.document.createElement("link");
|
||||
link.setAttribute("rel", "canonical");
|
||||
link.setAttribute("href", this.section.url);
|
||||
this.document.querySelector("head").appendChild(link);
|
||||
}
|
||||
|
||||
this.contents.on("expand", function () {
|
||||
if(this.displayed && this.iframe) {
|
||||
this.expand();
|
||||
}
|
||||
});
|
||||
|
||||
this.contents.on("expand", function () {
|
||||
if(this.displayed && this.iframe) {
|
||||
this.expand();
|
||||
}
|
||||
});
|
||||
|
||||
promise.resolve(this.contents);
|
||||
};
|
||||
promise.resolve(this.contents);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -458,25 +457,25 @@ class IframeView {
|
|||
|
||||
setLayout(layout) {
|
||||
this.layout = layout;
|
||||
};
|
||||
}
|
||||
|
||||
setAxis(axis) {
|
||||
this.settings.axis = axis;
|
||||
};
|
||||
}
|
||||
|
||||
resizeListenters() {
|
||||
// Test size again
|
||||
clearTimeout(this.expanding);
|
||||
this.expanding = setTimeout(this.expand.bind(this), 350);
|
||||
};
|
||||
}
|
||||
|
||||
addListeners() {
|
||||
//TODO: Add content listeners for expanding
|
||||
};
|
||||
}
|
||||
|
||||
removeListeners(layoutFunc) {
|
||||
//TODO: remove content listeners for expanding
|
||||
};
|
||||
}
|
||||
|
||||
display(request) {
|
||||
var displayed = new defer();
|
||||
|
@ -499,7 +498,7 @@ class IframeView {
|
|||
|
||||
|
||||
return displayed.promise;
|
||||
};
|
||||
}
|
||||
|
||||
show() {
|
||||
|
||||
|
@ -510,7 +509,7 @@ class IframeView {
|
|||
}
|
||||
|
||||
this.emit("shown", this);
|
||||
};
|
||||
}
|
||||
|
||||
hide() {
|
||||
// this.iframe.style.display = "none";
|
||||
|
@ -519,11 +518,11 @@ class IframeView {
|
|||
|
||||
this.stopExpanding = true;
|
||||
this.emit("hidden", this);
|
||||
};
|
||||
}
|
||||
|
||||
position() {
|
||||
return this.element.getBoundingClientRect();
|
||||
};
|
||||
}
|
||||
|
||||
locationOf(target) {
|
||||
var parentPos = this.iframe.getBoundingClientRect();
|
||||
|
@ -533,22 +532,22 @@ class IframeView {
|
|||
"left": window.scrollX + parentPos.left + targetPos.left,
|
||||
"top": window.scrollY + parentPos.top + targetPos.top
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
onDisplayed(view) {
|
||||
// Stub, override with a custom functions
|
||||
};
|
||||
}
|
||||
|
||||
onResize(view, e) {
|
||||
// Stub, override with a custom functions
|
||||
};
|
||||
}
|
||||
|
||||
bounds() {
|
||||
if(!this.elementBounds) {
|
||||
this.elementBounds = bounds(this.element);
|
||||
}
|
||||
return this.elementBounds;
|
||||
};
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
||||
|
@ -569,7 +568,7 @@ class IframeView {
|
|||
}
|
||||
// this.element.style.height = "0px";
|
||||
// this.element.style.width = "0px";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
EventEmitter(IframeView.prototype);
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
import EventEmitter from 'event-emitter';
|
||||
import {extend, borders, uuid, isNumber, bounds, defer} from '../../utils/core';
|
||||
import EpubCFI from '../../epubcfi';
|
||||
import Contents from '../../contents';
|
||||
// import URI from 'urijs';
|
||||
import EventEmitter from "event-emitter";
|
||||
import {extend, borders, uuid, isNumber, bounds, defer, qs, parse} from "../../utils/core";
|
||||
import EpubCFI from "../../epubcfi";
|
||||
import Contents from "../../contents";
|
||||
|
||||
class InlineView {
|
||||
constructor(section, options) {
|
||||
this.settings = extend({
|
||||
ignoreClass : '',
|
||||
axis: 'vertical',
|
||||
ignoreClass : "",
|
||||
axis: "vertical",
|
||||
width: 0,
|
||||
height: 0,
|
||||
layout: undefined,
|
||||
|
@ -38,10 +37,10 @@ class InlineView {
|
|||
// Dom events to listen for
|
||||
// this.listenedEvents = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click", "touchend", "touchstart"];
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
container(axis) {
|
||||
var element = document.createElement('div');
|
||||
var element = document.createElement("div");
|
||||
|
||||
element.classList.add("epub-view");
|
||||
|
||||
|
@ -62,7 +61,7 @@ class InlineView {
|
|||
}
|
||||
|
||||
return element;
|
||||
};
|
||||
}
|
||||
|
||||
create() {
|
||||
|
||||
|
@ -74,7 +73,7 @@ class InlineView {
|
|||
this.element = this.createContainer();
|
||||
}
|
||||
|
||||
this.frame = document.createElement('div');
|
||||
this.frame = document.createElement("div");
|
||||
this.frame.id = this.id;
|
||||
this.frame.style.overflow = "hidden";
|
||||
this.frame.style.wordSpacing = "initial";
|
||||
|
@ -103,7 +102,7 @@ class InlineView {
|
|||
this.elementBounds = bounds(this.element);
|
||||
|
||||
return this.frame;
|
||||
};
|
||||
}
|
||||
|
||||
render(request, show) {
|
||||
|
||||
|
@ -144,7 +143,7 @@ class InlineView {
|
|||
|
||||
if(show !== false) {
|
||||
//this.q.enqueue(function(view){
|
||||
this.show();
|
||||
this.show();
|
||||
//}, view);
|
||||
}
|
||||
// this.map = new Map(view, this.layout);
|
||||
|
@ -156,7 +155,7 @@ class InlineView {
|
|||
this.emit("loaderror", e);
|
||||
}.bind(this));
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// Determine locks base on settings
|
||||
size(_width, _height) {
|
||||
|
@ -172,7 +171,7 @@ class InlineView {
|
|||
this.lock("width", width, height);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// Lock an axis to element dimensions, taking borders into account
|
||||
lock(what, width, height) {
|
||||
|
@ -196,8 +195,8 @@ class InlineView {
|
|||
}
|
||||
|
||||
if(what === "both" &&
|
||||
isNumber(width) &&
|
||||
isNumber(height)){
|
||||
isNumber(width) &&
|
||||
isNumber(height)){
|
||||
|
||||
this.lockedWidth = width - elBorders.width - iframeBorders.width;
|
||||
this.lockedHeight = height - elBorders.height - iframeBorders.height;
|
||||
|
@ -205,7 +204,7 @@ class InlineView {
|
|||
this.resize(this.lockedWidth, this.lockedHeight);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// Resize a single axis based on content dimensions
|
||||
expand(force) {
|
||||
|
@ -233,16 +232,15 @@ class InlineView {
|
|||
}
|
||||
|
||||
this._expanding = false;
|
||||
};
|
||||
}
|
||||
|
||||
contentWidth(min) {
|
||||
return this.frame.scrollWidth;
|
||||
};
|
||||
}
|
||||
|
||||
contentHeight(min) {
|
||||
console.log(this.frame.scrollHeight);
|
||||
return this.frame.scrollHeight;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
resize(width, height) {
|
||||
|
@ -263,7 +261,7 @@ class InlineView {
|
|||
|
||||
this.elementBounds = bounds(this.element);
|
||||
|
||||
size = {
|
||||
let size = {
|
||||
width: this.elementBounds.width,
|
||||
height: this.elementBounds.height,
|
||||
widthDelta: this.elementBounds.width - this.prevBounds.width,
|
||||
|
@ -274,7 +272,7 @@ class InlineView {
|
|||
|
||||
this.emit("resized", size);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
load(contents) {
|
||||
|
@ -283,10 +281,12 @@ class InlineView {
|
|||
var doc = parse(contents, "text/html");
|
||||
var body = qs(doc, "body");
|
||||
|
||||
/*
|
||||
var srcs = doc.querySelectorAll("[src]");
|
||||
|
||||
Array.prototype.slice.call(srcs)
|
||||
.forEach(function(item) {
|
||||
var src = item.getAttribute('src');
|
||||
var src = item.getAttribute("src");
|
||||
var assetUri = URI(src);
|
||||
var origin = assetUri.origin();
|
||||
var absoluteUri;
|
||||
|
@ -296,7 +296,7 @@ class InlineView {
|
|||
item.src = absoluteUri;
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
*/
|
||||
this.frame.innerHTML = body.innerHTML;
|
||||
|
||||
this.document = this.frame.ownerDocument;
|
||||
|
@ -310,26 +310,26 @@ class InlineView {
|
|||
|
||||
|
||||
return loaded;
|
||||
};
|
||||
}
|
||||
|
||||
setLayout(layout) {
|
||||
this.layout = layout;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
resizeListenters() {
|
||||
// Test size again
|
||||
// clearTimeout(this.expanding);
|
||||
// this.expanding = setTimeout(this.expand.bind(this), 350);
|
||||
};
|
||||
}
|
||||
|
||||
addListeners() {
|
||||
//TODO: Add content listeners for expanding
|
||||
};
|
||||
}
|
||||
|
||||
removeListeners(layoutFunc) {
|
||||
//TODO: remove content listeners for expanding
|
||||
};
|
||||
}
|
||||
|
||||
display(request) {
|
||||
var displayed = new defer();
|
||||
|
@ -353,7 +353,7 @@ class InlineView {
|
|||
|
||||
|
||||
return displayed.promise;
|
||||
};
|
||||
}
|
||||
|
||||
show() {
|
||||
|
||||
|
@ -364,7 +364,7 @@ class InlineView {
|
|||
}
|
||||
|
||||
this.emit("shown", this);
|
||||
};
|
||||
}
|
||||
|
||||
hide() {
|
||||
// this.frame.style.display = "none";
|
||||
|
@ -373,11 +373,11 @@ class InlineView {
|
|||
|
||||
this.stopExpanding = true;
|
||||
this.emit("hidden", this);
|
||||
};
|
||||
}
|
||||
|
||||
position() {
|
||||
return this.element.getBoundingClientRect();
|
||||
};
|
||||
}
|
||||
|
||||
locationOf(target) {
|
||||
var parentPos = this.frame.getBoundingClientRect();
|
||||
|
@ -387,22 +387,22 @@ class InlineView {
|
|||
"left": window.scrollX + parentPos.left + targetPos.left,
|
||||
"top": window.scrollY + parentPos.top + targetPos.top
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
onDisplayed(view) {
|
||||
// Stub, override with a custom functions
|
||||
};
|
||||
}
|
||||
|
||||
onResize(view, e) {
|
||||
// Stub, override with a custom functions
|
||||
};
|
||||
}
|
||||
|
||||
bounds() {
|
||||
if(!this.elementBounds) {
|
||||
this.elementBounds = bounds(this.element);
|
||||
}
|
||||
return this.elementBounds;
|
||||
};
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
||||
|
@ -423,7 +423,7 @@ class InlineView {
|
|||
}
|
||||
// this.element.style.height = "0px";
|
||||
// this.element.style.width = "0px";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
EventEmitter(InlineView.prototype);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue