mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-04 15:09:16 +02:00
upgraded rsvp.js, small bug fixes
This commit is contained in:
parent
8bc693b2ce
commit
f525d86fb1
20 changed files with 2488 additions and 1370 deletions
|
@ -8,7 +8,7 @@ module.exports = function(grunt) {
|
||||||
'<%= grunt.template.today("yyyy-mm-dd") %> */'
|
'<%= grunt.template.today("yyyy-mm-dd") %> */'
|
||||||
},
|
},
|
||||||
concat : {
|
concat : {
|
||||||
'build/epub.js': ['<banner>', 'libs/rsvp/rsvp.min.js', 'src/*.js'],
|
'build/epub.js': ['<banner>', 'libs/rsvp/rsvp.js', 'src/*.js'],
|
||||||
'build/reader.js': ['<banner>', 'reader/*.js'],
|
'build/reader.js': ['<banner>', 'reader/*.js'],
|
||||||
'build/hooks.js': ['<banner>', 'hooks/default/*.js'],
|
'build/hooks.js': ['<banner>', 'hooks/default/*.js'],
|
||||||
'demo/js/libs/fileStorage.min.js': 'libs/fileStorage/fileStorage.min.js',
|
'demo/js/libs/fileStorage.min.js': 'libs/fileStorage/fileStorage.min.js',
|
||||||
|
@ -24,9 +24,9 @@ module.exports = function(grunt) {
|
||||||
files: {
|
files: {
|
||||||
'demo/js/epub.min.js': ['libs/underscore/underscore-min.js', 'build/epub.js'],
|
'demo/js/epub.min.js': ['libs/underscore/underscore-min.js', 'build/epub.js'],
|
||||||
'build/epub.min.js': ['libs/underscore/underscore-min.js', 'build/epub.js'],
|
'build/epub.min.js': ['libs/underscore/underscore-min.js', 'build/epub.js'],
|
||||||
'demo/js/reader.min.js': 'build/reader.js',
|
'demo/js/reader.min.js': ['build/reader.js'],
|
||||||
'demo/js/hooks.min.js': 'build/hooks.js',
|
'demo/js/hooks.min.js': ['build/hooks.js'],
|
||||||
'build/hooks.min.js': 'build/hooks.js',
|
'build/hooks.min.js': ['build/hooks.js'],
|
||||||
'demo/js/libs/zip.min.js': ['libs/zip/zip.js', 'libs/zip/zip-fs.js', 'libs/zip/zip-ext.js', 'libs/zip/mime-types.js'],
|
'demo/js/libs/zip.min.js': ['libs/zip/zip.js', 'libs/zip/zip-fs.js', 'libs/zip/zip-ext.js', 'libs/zip/mime-types.js'],
|
||||||
'demo/js/libs/inflate.min.js': ['libs/zip/inflate.js'],
|
'demo/js/libs/inflate.min.js': ['libs/zip/inflate.js'],
|
||||||
'build/libs/zip.min.js': ['libs/zip/zip.js', 'libs/zip/zip-fs.js', 'libs/zip/zip-ext.js', 'libs/zip/mime-types.js'],
|
'build/libs/zip.min.js': ['libs/zip/zip.js', 'libs/zip/zip-fs.js', 'libs/zip/zip-ext.js', 'libs/zip/mime-types.js'],
|
||||||
|
|
911
build/epub.js
911
build/epub.js
File diff suppressed because it is too large
Load diff
4
build/epub.min.js
vendored
4
build/epub.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -45,6 +45,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
|
||||||
txt = pop.querySelector("p");
|
txt = pop.querySelector("p");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chapter.replaceLinks.bind(this)
|
||||||
//-- create a popup with endnote inside of it
|
//-- create a popup with endnote inside of it
|
||||||
if(!popups[id]) {
|
if(!popups[id]) {
|
||||||
popups[id] = document.createElement("div");
|
popups[id] = document.createElement("div");
|
||||||
|
|
2
build/hooks.min.js
vendored
2
build/hooks.min.js
vendored
|
@ -1 +1 @@
|
||||||
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.doc.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=g+EPUBJS.cssPath||g,i={};EPUBJS.core.addCss(h+"popup.css",!1,b.doc.head),d.forEach(function(a){function c(){var c,e=b.iframe.height,f=b.iframe.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),i[k]||(i[k]=document.createElement("div"),i[k].setAttribute("class","popup"),pop_content=document.createElement("div"),i[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),b.bodyEl.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.book.on("renderer:pageChanged",h,this),b.book.on("renderer:pageChanged",g,this)),c=i[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.doc.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.doc.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.bodyEl.clientHeight;d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f;e=b.docEl.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g,a.style.maxHeight=c+"px",a.style.width="auto"):(c=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto",console.log(c)),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.doc.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>b.colWidth&&(d=b.colWidth/j,j=b.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.book.listenUntil("book:resized","book:chapterDestroy",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
|
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.doc.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=g+EPUBJS.cssPath||g,i={};EPUBJS.core.addCss(h+"popup.css",!1,b.doc.head),d.forEach(function(a){function c(){var c,e=b.iframe.height,f=b.iframe.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),b.replaceLinks.bind(this),i[k]||(i[k]=document.createElement("div"),i[k].setAttribute("class","popup"),pop_content=document.createElement("div"),i[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),b.bodyEl.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.book.on("renderer:pageChanged",h,this),b.book.on("renderer:pageChanged",g,this)),c=i[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.doc.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.doc.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.bodyEl.clientHeight;d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f;e=b.docEl.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g,a.style.maxHeight=c+"px",a.style.width="auto"):(c=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto",console.log(c)),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.doc.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>b.colWidth&&(d=b.colWidth/j,j=b.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.book.listenUntil("book:resized","book:chapterDestroy",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
|
4
demo/js/epub.min.js
vendored
4
demo/js/epub.min.js
vendored
File diff suppressed because one or more lines are too long
2
demo/js/hooks.min.js
vendored
2
demo/js/hooks.min.js
vendored
|
@ -1 +1 @@
|
||||||
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.doc.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=g+EPUBJS.cssPath||g,i={};EPUBJS.core.addCss(h+"popup.css",!1,b.doc.head),d.forEach(function(a){function c(){var c,e=b.iframe.height,f=b.iframe.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),i[k]||(i[k]=document.createElement("div"),i[k].setAttribute("class","popup"),pop_content=document.createElement("div"),i[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),b.bodyEl.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.book.on("renderer:pageChanged",h,this),b.book.on("renderer:pageChanged",g,this)),c=i[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.doc.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.doc.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.bodyEl.clientHeight;d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f;e=b.docEl.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g,a.style.maxHeight=c+"px",a.style.width="auto"):(c=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto",console.log(c)),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.doc.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>b.colWidth&&(d=b.colWidth/j,j=b.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.book.listenUntil("book:resized","book:chapterDestroy",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
|
EPUBJS.Hooks.register("beforeChapterDisplay").endnotes=function(a,b){var c=b.doc.querySelectorAll("a[href]"),d=Array.prototype.slice.call(c),e="epub:type",f="noteref",g=EPUBJS.core.folder(location.pathname),h=g+EPUBJS.cssPath||g,i={};EPUBJS.core.addCss(h+"popup.css",!1,b.doc.head),d.forEach(function(a){function c(){var c,e=b.iframe.height,f=b.iframe.width,j=225;o||(c=l.cloneNode(!0),o=c.querySelector("p")),b.replaceLinks.bind(this),i[k]||(i[k]=document.createElement("div"),i[k].setAttribute("class","popup"),pop_content=document.createElement("div"),i[k].appendChild(pop_content),pop_content.appendChild(o),pop_content.setAttribute("class","pop_content"),b.bodyEl.appendChild(i[k]),i[k].addEventListener("mouseover",d,!1),i[k].addEventListener("mouseout",g,!1),b.book.on("renderer:pageChanged",h,this),b.book.on("renderer:pageChanged",g,this)),c=i[k],itemRect=a.getBoundingClientRect(),m=itemRect.left,n=itemRect.top,c.classList.add("show"),popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width/2+"px",c.style.top=n+"px",j>e/2.5&&(j=e/2.5,pop_content.style.maxHeight=j+"px"),popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),m-popRect.width<=0?(c.style.left=m+"px",c.classList.add("left")):c.classList.remove("left"),m+popRect.width/2>=f?(c.style.left=m-300+"px",popRect=c.getBoundingClientRect(),c.style.left=m-popRect.width+"px",popRect.height+n>=e-25?(c.style.top=n-popRect.height+"px",c.classList.add("above")):c.classList.remove("above"),c.classList.add("right")):c.classList.remove("right")}function d(){i[k].classList.add("on")}function g(){i[k].classList.remove("on")}function h(){setTimeout(function(){i[k].classList.remove("show")},100)}var j,k,l,m,n,o,p=a.getAttribute(e);p==f&&(j=a.getAttribute("href"),k=j.replace("#",""),l=b.doc.getElementById(k),a.addEventListener("mouseover",c,!1),a.addEventListener("mouseout",h,!1))}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").smartimages=function(a,b){var c=b.doc.querySelectorAll("img"),d=Array.prototype.slice.call(c),e=b.bodyEl.clientHeight;d.forEach(function(a){function c(){var c,d=a.getBoundingClientRect(),f=d.height,g=d.top,h=a.getAttribute("data-height"),i=h||f;e=b.docEl.clientHeight,0>g&&(g=0),i+g>=e?(e/2>g?(c=e-g,a.style.maxHeight=c+"px",a.style.width="auto"):(c=e>i?i:e,a.style.maxHeight=c+"px",a.style.marginTop=e-g+"px",a.style.width="auto",console.log(c)),a.setAttribute("data-height",c)):(a.style.removeProperty("max-height"),a.style.removeProperty("margin-top"))}a.addEventListener("load",c,!1),b.on("renderer:resized",c),b.on("renderer:chapterUnloaded",function(){a.removeEventListener("load",c),b.off("renderer:resized",c)}),c()}),a&&a()},EPUBJS.Hooks.register("beforeChapterDisplay").transculsions=function(a,b){var c=b.doc.querySelectorAll("[transclusion]"),d=Array.prototype.slice.call(c);d.forEach(function(a){function c(){j=g,k=h,j>b.colWidth&&(d=b.colWidth/j,j=b.colWidth,k*=d),f.width=j,f.height=k}var d,e=a.getAttribute("ref"),f=document.createElement("iframe"),g=a.getAttribute("width"),h=a.getAttribute("height"),i=a.parentNode,j=g,k=h;c(),b.book.listenUntil("book:resized","book:chapterDestroy",c),f.src=e,i.replaceChild(f,a)}),a&&a()};
|
|
@ -49,13 +49,14 @@
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
|
||||||
body {
|
body {
|
||||||
overflow: hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#main {
|
#main {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
#area {
|
#area {
|
||||||
|
@ -103,7 +104,7 @@
|
||||||
<script>
|
<script>
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Book = ePub("../demo/moby-dick.epub", {restore: true, reload: true });
|
var Book = ePub("../demo/moby-dick/", {restore: true, reload: false });
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -45,6 +45,7 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
|
||||||
txt = pop.querySelector("p");
|
txt = pop.querySelector("p");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chapter.replaceLinks.bind(this)
|
||||||
//-- create a popup with endnote inside of it
|
//-- create a popup with endnote inside of it
|
||||||
if(!popups[id]) {
|
if(!popups[id]) {
|
||||||
popups[id] = document.createElement("div");
|
popups[id] = document.createElement("div");
|
||||||
|
|
|
@ -1,32 +1,106 @@
|
||||||
(function(exports) {
|
(function(globals) {
|
||||||
"use strict";
|
var define, requireModule;
|
||||||
var config = {};
|
|
||||||
|
|
||||||
var browserGlobal = (typeof window !== 'undefined') ? window : {};
|
(function() {
|
||||||
|
var registry = {}, seen = {};
|
||||||
|
|
||||||
var MutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
|
define = function(name, deps, callback) {
|
||||||
var RSVP;
|
registry[name] = { deps: deps, callback: callback };
|
||||||
|
|
||||||
if (typeof process !== 'undefined' &&
|
|
||||||
{}.toString.call(process) === '[object process]') {
|
|
||||||
config.async = function(callback, binding) {
|
|
||||||
process.nextTick(function() {
|
|
||||||
callback.call(binding);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
} else if (MutationObserver) {
|
|
||||||
var queue = [];
|
|
||||||
|
|
||||||
var observer = new MutationObserver(function() {
|
requireModule = function(name) {
|
||||||
var toProcess = queue.slice();
|
if (seen[name]) { return seen[name]; }
|
||||||
queue = [];
|
seen[name] = {};
|
||||||
|
|
||||||
toProcess.forEach(function(tuple) {
|
var mod = registry[name];
|
||||||
var callback = tuple[0], binding = tuple[1];
|
if (!mod) {
|
||||||
callback.call(binding);
|
throw new Error("Module '" + name + "' not found.");
|
||||||
});
|
}
|
||||||
|
|
||||||
|
var deps = mod.deps,
|
||||||
|
callback = mod.callback,
|
||||||
|
reified = [],
|
||||||
|
exports;
|
||||||
|
|
||||||
|
for (var i=0, l=deps.length; i<l; i++) {
|
||||||
|
if (deps[i] === 'exports') {
|
||||||
|
reified.push(exports = {});
|
||||||
|
} else {
|
||||||
|
reified.push(requireModule(deps[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var value = callback.apply(this, reified);
|
||||||
|
return seen[name] = exports || value;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
define("rsvp/all",
|
||||||
|
["rsvp/promise","exports"],
|
||||||
|
function(__dependency1__, __exports__) {
|
||||||
|
"use strict";
|
||||||
|
var Promise = __dependency1__.Promise;
|
||||||
|
/* global toString */
|
||||||
|
|
||||||
|
|
||||||
|
function all(promises) {
|
||||||
|
if (Object.prototype.toString.call(promises) !== "[object Array]") {
|
||||||
|
throw new TypeError('You must pass an array to all.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
var results = [], remaining = promises.length,
|
||||||
|
promise;
|
||||||
|
|
||||||
|
if (remaining === 0) {
|
||||||
|
resolve([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolver(index) {
|
||||||
|
return function(value) {
|
||||||
|
resolveAll(index, value);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveAll(index, value) {
|
||||||
|
results[index] = value;
|
||||||
|
if (--remaining === 0) {
|
||||||
|
resolve(results);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < promises.length; i++) {
|
||||||
|
promise = promises[i];
|
||||||
|
|
||||||
|
if (promise && typeof promise.then === 'function') {
|
||||||
|
promise.then(resolver(i), reject);
|
||||||
|
} else {
|
||||||
|
resolveAll(i, promise);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__exports__.all = all;
|
||||||
|
});
|
||||||
|
define("rsvp/async",
|
||||||
|
["exports"],
|
||||||
|
function(__exports__) {
|
||||||
|
"use strict";
|
||||||
|
var browserGlobal = (typeof window !== 'undefined') ? window : {};
|
||||||
|
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
|
||||||
|
var local = (typeof global !== 'undefined') ? global : this;
|
||||||
|
|
||||||
|
// node
|
||||||
|
function useNextTick() {
|
||||||
|
return function() {
|
||||||
|
process.nextTick(flush);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function useMutationObserver() {
|
||||||
|
var observer = new BrowserMutationObserver(flush);
|
||||||
var element = document.createElement('div');
|
var element = document.createElement('div');
|
||||||
observer.observe(element, { attributes: true });
|
observer.observe(element, { attributes: true });
|
||||||
|
|
||||||
|
@ -34,20 +108,94 @@
|
||||||
window.addEventListener('unload', function(){
|
window.addEventListener('unload', function(){
|
||||||
observer.disconnect();
|
observer.disconnect();
|
||||||
observer = null;
|
observer = null;
|
||||||
});
|
}, false);
|
||||||
|
|
||||||
config.async = function(callback, binding) {
|
return function() {
|
||||||
queue.push([callback, binding]);
|
|
||||||
element.setAttribute('drainQueue', 'drainQueue');
|
element.setAttribute('drainQueue', 'drainQueue');
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
config.async = function(callback, binding) {
|
|
||||||
setTimeout(function() {
|
|
||||||
callback.call(binding);
|
|
||||||
}, 1);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function useSetTimeout() {
|
||||||
|
return function() {
|
||||||
|
local.setTimeout(flush, 1);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var queue = [];
|
||||||
|
function flush() {
|
||||||
|
for (var i = 0; i < queue.length; i++) {
|
||||||
|
var tuple = queue[i];
|
||||||
|
var callback = tuple[0], arg = tuple[1];
|
||||||
|
callback(arg);
|
||||||
|
}
|
||||||
|
queue = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var scheduleFlush;
|
||||||
|
|
||||||
|
// Decide what async method to use to triggering processing of queued callbacks:
|
||||||
|
if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
|
||||||
|
scheduleFlush = useNextTick();
|
||||||
|
} else if (BrowserMutationObserver) {
|
||||||
|
scheduleFlush = useMutationObserver();
|
||||||
|
} else {
|
||||||
|
scheduleFlush = useSetTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
function async(callback, arg) {
|
||||||
|
var length = queue.push([callback, arg]);
|
||||||
|
if (length === 1) {
|
||||||
|
// If length is 1, that means that we need to schedule an async flush.
|
||||||
|
// If additional callbacks are queued before the queue is flushed, they
|
||||||
|
// will be processed by this flush that we are scheduling.
|
||||||
|
scheduleFlush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__exports__.async = async;
|
||||||
|
});
|
||||||
|
define("rsvp/config",
|
||||||
|
["rsvp/async","exports"],
|
||||||
|
function(__dependency1__, __exports__) {
|
||||||
|
"use strict";
|
||||||
|
var async = __dependency1__.async;
|
||||||
|
|
||||||
|
var config = {};
|
||||||
|
config.async = async;
|
||||||
|
|
||||||
|
|
||||||
|
__exports__.config = config;
|
||||||
|
});
|
||||||
|
define("rsvp/defer",
|
||||||
|
["rsvp/promise","exports"],
|
||||||
|
function(__dependency1__, __exports__) {
|
||||||
|
"use strict";
|
||||||
|
var Promise = __dependency1__.Promise;
|
||||||
|
|
||||||
|
function defer() {
|
||||||
|
var deferred = {
|
||||||
|
// pre-allocate shape
|
||||||
|
resolve: undefined,
|
||||||
|
reject: undefined,
|
||||||
|
promise: undefined
|
||||||
|
};
|
||||||
|
|
||||||
|
deferred.promise = new Promise(function(resolve, reject) {
|
||||||
|
deferred.resolve = resolve;
|
||||||
|
deferred.reject = reject;
|
||||||
|
});
|
||||||
|
|
||||||
|
return deferred;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__exports__.defer = defer;
|
||||||
|
});
|
||||||
|
define("rsvp/events",
|
||||||
|
["exports"],
|
||||||
|
function(__exports__) {
|
||||||
|
"use strict";
|
||||||
var Event = function(type, options) {
|
var Event = function(type, options) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
||||||
|
@ -125,7 +273,8 @@
|
||||||
callbacks, callbackTuple, callback, binding, event;
|
callbacks, callbackTuple, callback, binding, event;
|
||||||
|
|
||||||
if (callbacks = allCallbacks[eventName]) {
|
if (callbacks = allCallbacks[eventName]) {
|
||||||
for (var i=0, l=callbacks.length; i<l; i++) {
|
// Don't cache the callbacks.length since it may grow
|
||||||
|
for (var i=0; i<callbacks.length; i++) {
|
||||||
callbackTuple = callbacks[i];
|
callbackTuple = callbacks[i];
|
||||||
callback = callbackTuple[0];
|
callback = callbackTuple[0];
|
||||||
binding = callbackTuple[1];
|
binding = callbackTuple[1];
|
||||||
|
@ -141,20 +290,169 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var Promise = function() {
|
|
||||||
this.on('promise:resolved', function(event) {
|
__exports__.EventTarget = EventTarget;
|
||||||
this.trigger('success', { detail: event.detail });
|
});
|
||||||
}, this);
|
define("rsvp/hash",
|
||||||
|
["rsvp/defer","exports"],
|
||||||
|
function(__dependency1__, __exports__) {
|
||||||
|
"use strict";
|
||||||
|
var defer = __dependency1__.defer;
|
||||||
|
|
||||||
|
function size(object) {
|
||||||
|
var s = 0;
|
||||||
|
|
||||||
|
for (var prop in object) {
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hash(promises) {
|
||||||
|
var results = {}, deferred = defer(), remaining = size(promises);
|
||||||
|
|
||||||
|
if (remaining === 0) {
|
||||||
|
deferred.resolve({});
|
||||||
|
}
|
||||||
|
|
||||||
|
var resolver = function(prop) {
|
||||||
|
return function(value) {
|
||||||
|
resolveAll(prop, value);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
var resolveAll = function(prop, value) {
|
||||||
|
results[prop] = value;
|
||||||
|
if (--remaining === 0) {
|
||||||
|
deferred.resolve(results);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var rejectAll = function(error) {
|
||||||
|
deferred.reject(error);
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var prop in promises) {
|
||||||
|
if (promises[prop] && typeof promises[prop].then === 'function') {
|
||||||
|
promises[prop].then(resolver(prop), rejectAll);
|
||||||
|
} else {
|
||||||
|
resolveAll(prop, promises[prop]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__exports__.hash = hash;
|
||||||
|
});
|
||||||
|
define("rsvp/node",
|
||||||
|
["rsvp/promise","rsvp/all","exports"],
|
||||||
|
function(__dependency1__, __dependency2__, __exports__) {
|
||||||
|
"use strict";
|
||||||
|
var Promise = __dependency1__.Promise;
|
||||||
|
var all = __dependency2__.all;
|
||||||
|
|
||||||
|
function makeNodeCallbackFor(resolve, reject) {
|
||||||
|
return function (error, value) {
|
||||||
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else if (arguments.length > 2) {
|
||||||
|
resolve(Array.prototype.slice.call(arguments, 1));
|
||||||
|
} else {
|
||||||
|
resolve(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function denodeify(nodeFunc) {
|
||||||
|
return function() {
|
||||||
|
var nodeArgs = Array.prototype.slice.call(arguments), resolve, reject;
|
||||||
|
var thisArg = this;
|
||||||
|
|
||||||
|
var promise = new Promise(function(nodeResolve, nodeReject) {
|
||||||
|
resolve = nodeResolve;
|
||||||
|
reject = nodeReject;
|
||||||
|
});
|
||||||
|
|
||||||
|
all(nodeArgs).then(function(nodeArgs) {
|
||||||
|
nodeArgs.push(makeNodeCallbackFor(resolve, reject));
|
||||||
|
|
||||||
|
try {
|
||||||
|
nodeFunc.apply(thisArg, nodeArgs);
|
||||||
|
} catch(e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__exports__.denodeify = denodeify;
|
||||||
|
});
|
||||||
|
define("rsvp/promise",
|
||||||
|
["rsvp/config","rsvp/events","exports"],
|
||||||
|
function(__dependency1__, __dependency2__, __exports__) {
|
||||||
|
"use strict";
|
||||||
|
var config = __dependency1__.config;
|
||||||
|
var EventTarget = __dependency2__.EventTarget;
|
||||||
|
|
||||||
|
function objectOrFunction(x) {
|
||||||
|
return isFunction(x) || (typeof x === "object" && x !== null);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isFunction(x){
|
||||||
|
return typeof x === "function";
|
||||||
|
}
|
||||||
|
|
||||||
|
var Promise = function(resolver) {
|
||||||
|
var promise = this,
|
||||||
|
resolved = false;
|
||||||
|
|
||||||
|
if (typeof resolver !== 'function') {
|
||||||
|
throw new TypeError('You must pass a resolver function as the sole argument to the promise constructor');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(promise instanceof Promise)) {
|
||||||
|
return new Promise(resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
var resolvePromise = function(value) {
|
||||||
|
if (resolved) { return; }
|
||||||
|
resolved = true;
|
||||||
|
resolve(promise, value);
|
||||||
|
};
|
||||||
|
|
||||||
|
var rejectPromise = function(value) {
|
||||||
|
if (resolved) { return; }
|
||||||
|
resolved = true;
|
||||||
|
reject(promise, value);
|
||||||
|
};
|
||||||
|
|
||||||
this.on('promise:failed', function(event) {
|
this.on('promise:failed', function(event) {
|
||||||
this.trigger('error', { detail: event.detail });
|
this.trigger('error', { detail: event.detail });
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
this.on('error', onerror);
|
||||||
|
|
||||||
|
try {
|
||||||
|
resolver(resolvePromise, rejectPromise);
|
||||||
|
} catch(e) {
|
||||||
|
rejectPromise(e);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var noop = function() {};
|
function onerror(event) {
|
||||||
|
if (config.onerror) {
|
||||||
|
config.onerror(event.detail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var invokeCallback = function(type, promise, callback, event) {
|
var invokeCallback = function(type, promise, callback, event) {
|
||||||
var hasCallback = typeof callback === 'function',
|
var hasCallback = isFunction(callback),
|
||||||
value, error, succeeded, failed;
|
value, error, succeeded, failed;
|
||||||
|
|
||||||
if (hasCallback) {
|
if (hasCallback) {
|
||||||
|
@ -170,34 +468,41 @@
|
||||||
succeeded = true;
|
succeeded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value && typeof value.then === 'function') {
|
if (handleThenable(promise, value)) {
|
||||||
value.then(function(value) {
|
return;
|
||||||
promise.resolve(value);
|
|
||||||
}, function(error) {
|
|
||||||
promise.reject(error);
|
|
||||||
});
|
|
||||||
} else if (hasCallback && succeeded) {
|
} else if (hasCallback && succeeded) {
|
||||||
promise.resolve(value);
|
resolve(promise, value);
|
||||||
} else if (failed) {
|
} else if (failed) {
|
||||||
promise.reject(error);
|
reject(promise, error);
|
||||||
} else {
|
} else if (type === 'resolve') {
|
||||||
promise[type](value);
|
resolve(promise, value);
|
||||||
|
} else if (type === 'reject') {
|
||||||
|
reject(promise, value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Promise.prototype = {
|
Promise.prototype = {
|
||||||
then: function(done, fail) {
|
constructor: Promise,
|
||||||
var thenPromise = new Promise();
|
|
||||||
|
|
||||||
if (this.isResolved) {
|
isRejected: undefined,
|
||||||
config.async(function() {
|
isFulfilled: undefined,
|
||||||
invokeCallback('resolve', thenPromise, done, { detail: this.resolvedValue });
|
rejectedReason: undefined,
|
||||||
|
fulfillmentValue: undefined,
|
||||||
|
|
||||||
|
then: function(done, fail) {
|
||||||
|
this.off('error', onerror);
|
||||||
|
|
||||||
|
var thenPromise = new this.constructor(function() {});
|
||||||
|
|
||||||
|
if (this.isFulfilled) {
|
||||||
|
config.async(function(promise) {
|
||||||
|
invokeCallback('resolve', thenPromise, done, { detail: promise.fulfillmentValue });
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isRejected) {
|
if (this.isRejected) {
|
||||||
config.async(function() {
|
config.async(function(promise) {
|
||||||
invokeCallback('reject', thenPromise, fail, { detail: this.rejectedValue });
|
invokeCallback('reject', thenPromise, fail, { detail: promise.rejectedReason });
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,26 +517,66 @@
|
||||||
return thenPromise;
|
return thenPromise;
|
||||||
},
|
},
|
||||||
|
|
||||||
resolve: function(value) {
|
fail: function(fail) {
|
||||||
resolve(this, value);
|
return this.then(null, fail);
|
||||||
|
|
||||||
this.resolve = noop;
|
|
||||||
this.reject = noop;
|
|
||||||
},
|
|
||||||
|
|
||||||
reject: function(value) {
|
|
||||||
reject(this, value);
|
|
||||||
|
|
||||||
this.resolve = noop;
|
|
||||||
this.reject = noop;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EventTarget.mixin(Promise.prototype);
|
||||||
|
|
||||||
function resolve(promise, value) {
|
function resolve(promise, value) {
|
||||||
|
if (promise === value) {
|
||||||
|
fulfill(promise, value);
|
||||||
|
} else if (!handleThenable(promise, value)) {
|
||||||
|
fulfill(promise, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleThenable(promise, value) {
|
||||||
|
var then = null,
|
||||||
|
resolved;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (promise === value) {
|
||||||
|
throw new TypeError("A promises callback cannot return that same promise.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectOrFunction(value)) {
|
||||||
|
then = value.then;
|
||||||
|
|
||||||
|
if (isFunction(then)) {
|
||||||
|
then.call(value, function(val) {
|
||||||
|
if (resolved) { return true; }
|
||||||
|
resolved = true;
|
||||||
|
|
||||||
|
if (value !== val) {
|
||||||
|
resolve(promise, val);
|
||||||
|
} else {
|
||||||
|
fulfill(promise, val);
|
||||||
|
}
|
||||||
|
}, function(val) {
|
||||||
|
if (resolved) { return true; }
|
||||||
|
resolved = true;
|
||||||
|
|
||||||
|
reject(promise, val);
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
reject(promise, error);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fulfill(promise, value) {
|
||||||
config.async(function() {
|
config.async(function() {
|
||||||
promise.trigger('promise:resolved', { detail: value });
|
promise.trigger('promise:resolved', { detail: value });
|
||||||
promise.isResolved = true;
|
promise.isFulfilled = true;
|
||||||
promise.resolvedValue = value;
|
promise.fulfillmentValue = value;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,51 +584,89 @@
|
||||||
config.async(function() {
|
config.async(function() {
|
||||||
promise.trigger('promise:failed', { detail: value });
|
promise.trigger('promise:failed', { detail: value });
|
||||||
promise.isRejected = true;
|
promise.isRejected = true;
|
||||||
promise.rejectedValue = value;
|
promise.rejectedReason = value;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function all(promises) {
|
|
||||||
var i, results = [];
|
|
||||||
var allPromise = new Promise();
|
|
||||||
var remaining = promises.length;
|
|
||||||
|
|
||||||
if (remaining === 0) {
|
__exports__.Promise = Promise;
|
||||||
allPromise.resolve([]);
|
});
|
||||||
|
define("rsvp/reject",
|
||||||
|
["rsvp/promise","exports"],
|
||||||
|
function(__dependency1__, __exports__) {
|
||||||
|
"use strict";
|
||||||
|
var Promise = __dependency1__.Promise;
|
||||||
|
|
||||||
|
function reject(reason) {
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
reject(reason);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var resolver = function(index) {
|
|
||||||
return function(value) {
|
|
||||||
resolve(index, value);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
var resolve = function(index, value) {
|
__exports__.reject = reject;
|
||||||
results[index] = value;
|
});
|
||||||
if (--remaining === 0) {
|
define("rsvp/resolve",
|
||||||
allPromise.resolve(results);
|
["rsvp/promise","exports"],
|
||||||
}
|
function(__dependency1__, __exports__) {
|
||||||
};
|
"use strict";
|
||||||
|
var Promise = __dependency1__.Promise;
|
||||||
|
|
||||||
var reject = function(error) {
|
function resolve(thenable) {
|
||||||
allPromise.reject(error);
|
return new Promise(function(resolve, reject) {
|
||||||
};
|
resolve(thenable);
|
||||||
|
});
|
||||||
for (i = 0; i < remaining; i++) {
|
|
||||||
promises[i].then(resolver(i), reject);
|
|
||||||
}
|
|
||||||
return allPromise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EventTarget.mixin(Promise.prototype);
|
|
||||||
|
__exports__.resolve = resolve;
|
||||||
|
});
|
||||||
|
define("rsvp/rethrow",
|
||||||
|
["exports"],
|
||||||
|
function(__exports__) {
|
||||||
|
"use strict";
|
||||||
|
var local = (typeof global === "undefined") ? this : global;
|
||||||
|
|
||||||
|
function rethrow(reason) {
|
||||||
|
local.setTimeout(function() {
|
||||||
|
throw reason;
|
||||||
|
});
|
||||||
|
throw reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__exports__.rethrow = rethrow;
|
||||||
|
});
|
||||||
|
define("rsvp",
|
||||||
|
["rsvp/events","rsvp/promise","rsvp/node","rsvp/all","rsvp/hash","rsvp/rethrow","rsvp/defer","rsvp/config","rsvp/resolve","rsvp/reject","exports"],
|
||||||
|
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __dependency8__, __dependency9__, __dependency10__, __exports__) {
|
||||||
|
"use strict";
|
||||||
|
var EventTarget = __dependency1__.EventTarget;
|
||||||
|
var Promise = __dependency2__.Promise;
|
||||||
|
var denodeify = __dependency3__.denodeify;
|
||||||
|
var all = __dependency4__.all;
|
||||||
|
var hash = __dependency5__.hash;
|
||||||
|
var rethrow = __dependency6__.rethrow;
|
||||||
|
var defer = __dependency7__.defer;
|
||||||
|
var config = __dependency8__.config;
|
||||||
|
var resolve = __dependency9__.resolve;
|
||||||
|
var reject = __dependency10__.reject;
|
||||||
|
|
||||||
function configure(name, value) {
|
function configure(name, value) {
|
||||||
config[name] = value;
|
config[name] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Promise = Promise;
|
|
||||||
exports.Event = Event;
|
__exports__.Promise = Promise;
|
||||||
exports.EventTarget = EventTarget;
|
__exports__.EventTarget = EventTarget;
|
||||||
exports.all = all;
|
__exports__.all = all;
|
||||||
exports.configure = configure;
|
__exports__.hash = hash;
|
||||||
})(window.RSVP = {});
|
__exports__.rethrow = rethrow;
|
||||||
|
__exports__.defer = defer;
|
||||||
|
__exports__.denodeify = denodeify;
|
||||||
|
__exports__.configure = configure;
|
||||||
|
__exports__.resolve = resolve;
|
||||||
|
__exports__.reject = reject;
|
||||||
|
});
|
||||||
|
window.RSVP = requireModule("rsvp");
|
||||||
|
})(window);
|
1
libs/rsvp/rsvp.min.js
vendored
1
libs/rsvp/rsvp.min.js
vendored
|
@ -1 +0,0 @@
|
||||||
(function(e){"use strict";function v(e,n){t.async(function(){e.trigger("promise:resolved",{detail:n}),e.isResolved=!0,e.resolvedValue=n})}function m(e,n){t.async(function(){e.trigger("promise:failed",{detail:n}),e.isRejected=!0,e.rejectedValue=n})}function g(e){var t,n=[],r=new h,i=e.length;i===0&&r.resolve([]);var s=function(e){return function(t){o(e,t)}},o=function(e,t){n[e]=t,--i===0&&r.resolve(n)},u=function(e){r.reject(e)};for(t=0;t<i;t++)e[t].then(s(t),u);return r}function y(e,n){t[e]=n}var t={},n=typeof window!="undefined"?window:{},r=n.MutationObserver||n.WebKitMutationObserver,i;if(typeof process!="undefined"&&{}.toString.call(process)==="[object process]")t.async=function(e,t){process.nextTick(function(){e.call(t)})};else if(r){var s=[],o=new r(function(){var e=s.slice();s=[],e.forEach(function(e){var t=e[0],n=e[1];t.call(n)})}),u=document.createElement("div");o.observe(u,{attributes:!0}),window.addEventListener("unload",function(){o.disconnect(),o=null}),t.async=function(e,t){s.push([e,t]),u.setAttribute("drainQueue","drainQueue")}}else t.async=function(e,t){setTimeout(function(){e.call(t)},1)};var a=function(e,t){this.type=e;for(var n in t){if(!t.hasOwnProperty(n))continue;this[n]=t[n]}},f=function(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n][0]===t)return n;return-1},l=function(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t},c={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e},on:function(e,t,n){var r=l(this),i,s;e=e.split(/\s+/),n=n||this;while(s=e.shift())i=r[s],i||(i=r[s]=[]),f(i,t)===-1&&i.push([t,n])},off:function(e,t){var n=l(this),r,i,s;e=e.split(/\s+/);while(i=e.shift()){if(!t){n[i]=[];continue}r=n[i],s=f(r,t),s!==-1&&r.splice(s,1)}},trigger:function(e,t){var n=l(this),r,i,s,o,u;if(r=n[e])for(var f=0,c=r.length;f<c;f++)i=r[f],s=i[0],o=i[1],typeof t!="object"&&(t={detail:t}),u=new a(e,t),s.call(o,u)}},h=function(){this.on("promise:resolved",function(e){this.trigger("success",{detail:e.detail})},this),this.on("promise:failed",function(e){this.trigger("error",{detail:e.detail})},this)},p=function(){},d=function(e,t,n,r){var i=typeof n=="function",s,o,u,a;if(i)try{s=n(r.detail),u=!0}catch(f){a=!0,o=f}else s=r.detail,u=!0;s&&typeof s.then=="function"?s.then(function(e){t.resolve(e)},function(e){t.reject(e)}):i&&u?t.resolve(s):a?t.reject(o):t[e](s)};h.prototype={then:function(e,n){var r=new h;return this.isResolved&&t.async(function(){d("resolve",r,e,{detail:this.resolvedValue})},this),this.isRejected&&t.async(function(){d("reject",r,n,{detail:this.rejectedValue})},this),this.on("promise:resolved",function(t){d("resolve",r,e,t)}),this.on("promise:failed",function(e){d("reject",r,n,e)}),r},resolve:function(e){v(this,e),this.resolve=p,this.reject=p},reject:function(e){m(this,e),this.resolve=p,this.reject=p}},c.mixin(h.prototype),e.Promise=h,e.Event=a,e.EventTarget=c,e.all=g,e.configure=y})(window.RSVP={});
|
|
82
src/book.js
82
src/book.js
|
@ -56,14 +56,22 @@ EPUBJS.Book = function(options){
|
||||||
|
|
||||||
|
|
||||||
this.ready = {
|
this.ready = {
|
||||||
manifest: new RSVP.Promise(),
|
manifest: new RSVP.defer(),
|
||||||
spine: new RSVP.Promise(),
|
spine: new RSVP.defer(),
|
||||||
metadata: new RSVP.Promise(),
|
metadata: new RSVP.defer(),
|
||||||
cover: new RSVP.Promise(),
|
cover: new RSVP.defer(),
|
||||||
toc: new RSVP.Promise()
|
toc: new RSVP.defer()
|
||||||
};
|
};
|
||||||
|
|
||||||
this.ready.all = RSVP.all(_.values(this.ready));
|
this.readyPromises = [
|
||||||
|
this.ready.manifest.promise,
|
||||||
|
this.ready.spine.promise,
|
||||||
|
this.ready.metadata.promise,
|
||||||
|
this.ready.cover.promise,
|
||||||
|
this.ready.toc.promise
|
||||||
|
];
|
||||||
|
|
||||||
|
this.ready.all = RSVP.all(this.readyPromises);
|
||||||
|
|
||||||
this.ready.all.then(this._ready);
|
this.ready.all.then(this._ready);
|
||||||
|
|
||||||
|
@ -72,7 +80,8 @@ EPUBJS.Book = function(options){
|
||||||
this._rendering = false;
|
this._rendering = false;
|
||||||
this._displayQ = [];
|
this._displayQ = [];
|
||||||
|
|
||||||
this.opened = new RSVP.Promise();
|
this.defer_opened = new RSVP.defer();
|
||||||
|
this.opened = this.defer_opened.promise;
|
||||||
// BookUrl is optional, but if present start loading process
|
// BookUrl is optional, but if present start loading process
|
||||||
if(this.settings.bookPath) {
|
if(this.settings.bookPath) {
|
||||||
this.open(this.settings.bookPath, this.settings.reload);
|
this.open(this.settings.bookPath, this.settings.reload);
|
||||||
|
@ -144,7 +153,7 @@ EPUBJS.Book.prototype.open = function(bookPath, forceReload){
|
||||||
}
|
}
|
||||||
|
|
||||||
opened.then(function(){
|
opened.then(function(){
|
||||||
book.opened.resolve();
|
book.defer_opened.resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
return opened;
|
return opened;
|
||||||
|
@ -205,7 +214,7 @@ EPUBJS.Book.prototype.unpack = function(containerPath){
|
||||||
}
|
}
|
||||||
|
|
||||||
}).
|
}).
|
||||||
then(null, function(error) {
|
fail(function(error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -213,11 +222,11 @@ EPUBJS.Book.prototype.unpack = function(containerPath){
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Book.prototype.getMetadata = function() {
|
EPUBJS.Book.prototype.getMetadata = function() {
|
||||||
return this.ready.metadata;
|
return this.ready.metadata.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Book.prototype.getToc = function() {
|
EPUBJS.Book.prototype.getToc = function() {
|
||||||
return this.ready.toc;
|
return this.ready.toc.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Private Helpers */
|
/* Private Helpers */
|
||||||
|
@ -255,10 +264,18 @@ EPUBJS.Book.prototype.urlFrom = function(bookPath){
|
||||||
fromRoot = bookPath[0] == "/",
|
fromRoot = bookPath[0] == "/",
|
||||||
location = window.location,
|
location = window.location,
|
||||||
//-- Get URL orgin, try for native or combine
|
//-- Get URL orgin, try for native or combine
|
||||||
origin = location.origin || location.protocol + "//" + location.host;
|
origin = location.origin || location.protocol + "//" + location.host,
|
||||||
|
baseTag = document.getElementsByTagName('base'),
|
||||||
|
base;
|
||||||
|
|
||||||
// if(bookPath[bookPath.length - 1] != "/") bookPath += "/";
|
// if(bookPath[bookPath.length - 1] != "/") bookPath += "/";
|
||||||
|
|
||||||
|
//-- Check is Base tag is set
|
||||||
|
|
||||||
|
if(baseTag.length) {
|
||||||
|
base = baseTag[0].href;
|
||||||
|
}
|
||||||
|
|
||||||
//-- 1. Check if url is absolute
|
//-- 1. Check if url is absolute
|
||||||
if(absolute){
|
if(absolute){
|
||||||
return bookPath;
|
return bookPath;
|
||||||
|
@ -266,22 +283,31 @@ EPUBJS.Book.prototype.urlFrom = function(bookPath){
|
||||||
|
|
||||||
//-- 2. Check if url starts with /, add base url
|
//-- 2. Check if url starts with /, add base url
|
||||||
if(!absolute && fromRoot){
|
if(!absolute && fromRoot){
|
||||||
|
if(base) {
|
||||||
|
return base + bookPath;
|
||||||
|
} else {
|
||||||
return origin + bookPath;
|
return origin + bookPath;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-- 3. Or find full path to url and add that
|
//-- 3. Or find full path to url and add that
|
||||||
if(!absolute && !fromRoot){
|
if(!absolute && !fromRoot){
|
||||||
|
|
||||||
//-- go back
|
//-- go back
|
||||||
if(bookPath.slice(0, 3) == "../"){
|
if(bookPath.slice(0, 3) == "../"){
|
||||||
return EPUBJS.core.resolveUrl(location.href, bookPath);
|
return EPUBJS.core.resolveUrl(base || location.pathname, bookPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(base) {
|
||||||
|
return base + bookPath;
|
||||||
|
} else {
|
||||||
return origin + EPUBJS.core.folder(location.pathname) + bookPath;
|
return origin + EPUBJS.core.folder(location.pathname) + bookPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
EPUBJS.Book.prototype.unarchive = function(bookPath){
|
EPUBJS.Book.prototype.unarchive = function(bookPath){
|
||||||
var book = this,
|
var book = this,
|
||||||
|
@ -407,7 +433,9 @@ EPUBJS.Book.prototype.startDisplay = function(){
|
||||||
display = this.displayChapter(this.settings.previousLocationCfi);
|
display = this.displayChapter(this.settings.previousLocationCfi);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
display = this.displayChapter(this.spinePos);
|
display = this.displayChapter(this.spinePos);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return display;
|
return display;
|
||||||
|
@ -417,7 +445,7 @@ EPUBJS.Book.prototype.restore = function(reject){
|
||||||
|
|
||||||
var book = this,
|
var book = this,
|
||||||
contentsKey = this.settings.bookPath + ":contents:" + this.settings.version,
|
contentsKey = this.settings.bookPath + ":contents:" + this.settings.version,
|
||||||
promise = new RSVP.Promise(),
|
deferred = new RSVP.defer(),
|
||||||
fetch = ['manifest', 'spine', 'metadata', 'cover', 'toc', 'spineNodeIndex', 'spineIndexByURL'],
|
fetch = ['manifest', 'spine', 'metadata', 'cover', 'toc', 'spineNodeIndex', 'spineIndexByURL'],
|
||||||
reject = reject || false,
|
reject = reject || false,
|
||||||
fromStore = localStorage.getItem(contentsKey);
|
fromStore = localStorage.getItem(contentsKey);
|
||||||
|
@ -444,8 +472,8 @@ EPUBJS.Book.prototype.restore = function(reject){
|
||||||
this.ready.metadata.resolve(this.metadata);
|
this.ready.metadata.resolve(this.metadata);
|
||||||
this.ready.cover.resolve(this.cover);
|
this.ready.cover.resolve(this.cover);
|
||||||
this.ready.toc.resolve(this.toc);
|
this.ready.toc.resolve(this.toc);
|
||||||
promise.resolve();
|
deferred.resolve();
|
||||||
return promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -473,14 +501,8 @@ EPUBJS.Book.prototype.displayChapter = function(chap, end){
|
||||||
pos = cfi.spinePos;
|
pos = cfi.spinePos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(pos < 0 || pos >= this.spine.length){
|
||||||
if(pos >= this.spine.length){
|
console.error("Not A Valid Chapter");
|
||||||
// console.log("Reached End of Book");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pos < 0){
|
|
||||||
// console.log("Reached Start of Book");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -555,19 +577,26 @@ EPUBJS.Book.prototype.prevPage = function() {
|
||||||
|
|
||||||
EPUBJS.Book.prototype.nextChapter = function() {
|
EPUBJS.Book.prototype.nextChapter = function() {
|
||||||
this.spinePos++;
|
this.spinePos++;
|
||||||
|
if(this.spinePos > this.spine.length) return;
|
||||||
|
|
||||||
return this.displayChapter(this.spinePos);
|
return this.displayChapter(this.spinePos);
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Book.prototype.prevChapter = function() {
|
EPUBJS.Book.prototype.prevChapter = function() {
|
||||||
this.spinePos--;
|
this.spinePos--;
|
||||||
|
if(this.spinePos < 0) return;
|
||||||
|
|
||||||
return this.displayChapter(this.spinePos, true);
|
return this.displayChapter(this.spinePos, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EPUBJS.Book.prototype.gotoCfi = function(cfi){
|
||||||
|
if(!this.isRendered) return this._enqueue("gotoCfi", arguments);
|
||||||
|
return this.displayChapter(cfi)
|
||||||
|
}
|
||||||
|
|
||||||
EPUBJS.Book.prototype.goto = function(url){
|
EPUBJS.Book.prototype.goto = function(url){
|
||||||
var split, chapter, section, absoluteURL, spinePos;
|
var split, chapter, section, absoluteURL, spinePos;
|
||||||
|
var deferred = new RSVP.defer();
|
||||||
if(!this.isRendered) return this._enqueue("goto", arguments);
|
if(!this.isRendered) return this._enqueue("goto", arguments);
|
||||||
|
|
||||||
split = url.split("#"),
|
split = url.split("#"),
|
||||||
|
@ -592,7 +621,8 @@ EPUBJS.Book.prototype.goto = function(url){
|
||||||
}else{
|
}else{
|
||||||
//-- Only goto section
|
//-- Only goto section
|
||||||
if(section) this.render.section(section);
|
if(section) this.render.section(section);
|
||||||
return new RSVP.Promise().resolve(this.currentChapter);
|
deferred.resolve(this.currentChapter);
|
||||||
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ EPUBJS.Chapter.prototype.contents = function(store){
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Chapter.prototype.url = function(store){
|
EPUBJS.Chapter.prototype.url = function(store){
|
||||||
var promise = new RSVP.Promise();
|
var deferred = new RSVP.defer();
|
||||||
|
|
||||||
if(store){
|
if(store){
|
||||||
if(!this.tempUrl) {
|
if(!this.tempUrl) {
|
||||||
|
@ -27,8 +27,8 @@ EPUBJS.Chapter.prototype.url = function(store){
|
||||||
}
|
}
|
||||||
return this.tempUrl;
|
return this.tempUrl;
|
||||||
}else{
|
}else{
|
||||||
promise.resolve(this.href); //-- this is less than ideal but keeps it a promise
|
deferred.resolve(this.href); //-- this is less than ideal but keeps it a promise
|
||||||
return promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ EPUBJS.core.request = function(url, type) {
|
||||||
var supportsURL = window.URL;
|
var supportsURL = window.URL;
|
||||||
var BLOB_RESPONSE = supportsURL ? "blob" : "arraybuffer";
|
var BLOB_RESPONSE = supportsURL ? "blob" : "arraybuffer";
|
||||||
|
|
||||||
var promise = new RSVP.Promise();
|
var deferred = new RSVP.defer();
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
|
@ -61,14 +61,14 @@ EPUBJS.core.request = function(url, type) {
|
||||||
r = this.response;
|
r = this.response;
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.resolve(r);
|
deferred.resolve(r);
|
||||||
}
|
}
|
||||||
else { promise.reject(this); }
|
else { deferred.reject(this); }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
// EPUBJS.core.loadXML = function(url, callback){
|
// EPUBJS.core.loadXML = function(url, callback){
|
||||||
|
|
|
@ -100,7 +100,7 @@ EPUBJS.EpubCFI.prototype.parse = function(cfiStr) {
|
||||||
|
|
||||||
chapId = cfi.chapter.match(/\[(.*)\]/);
|
chapId = cfi.chapter.match(/\[(.*)\]/);
|
||||||
|
|
||||||
cfi.spineId = chapId[1] || false;
|
cfi.spineId = chapId ? chapId[1] : false;
|
||||||
|
|
||||||
path = cfi.fragment.split('/');
|
path = cfi.fragment.split('/');
|
||||||
end = path[path.length-1];
|
end = path[path.length-1];
|
||||||
|
|
103
src/renderer.js
103
src/renderer.js
|
@ -27,23 +27,22 @@ EPUBJS.Renderer.prototype.initialize = function(){
|
||||||
this.iframe.scrolling = "no";
|
this.iframe.scrolling = "no";
|
||||||
|
|
||||||
if(this.book.settings.width || this.book.settings.height){
|
if(this.book.settings.width || this.book.settings.height){
|
||||||
this.resizeIframe(false, this.book.settings.width || this.el.clientWidth, this.book.settings.height || this.el.clientHeight);
|
this.resizeIframe(this.book.settings.width || this.el.clientWidth, this.book.settings.height || this.el.clientHeight);
|
||||||
} else {
|
} else {
|
||||||
this.resizeIframe(false, this.el.clientWidth, this.el.clientHeight);
|
// this.resizeIframe(false, this.el.clientWidth, this.el.clientHeight);
|
||||||
|
this.resizeIframe('100%', '100%');
|
||||||
|
|
||||||
this.on("renderer:resized", this.resizeIframe, this);
|
// this.on("renderer:resized", this.resizeIframe, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.el.appendChild(this.iframe);
|
this.el.appendChild(this.iframe);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-- Listeners for browser events
|
//-- Listeners for browser events
|
||||||
EPUBJS.Renderer.prototype.listeners = function(){
|
EPUBJS.Renderer.prototype.listeners = function(){
|
||||||
this.resized = _.debounce(this.onResized.bind(this), 10);
|
|
||||||
|
|
||||||
window.addEventListener("resize", this.resized, false);
|
this.resized = _.throttle(this.onResized.bind(this), 10);
|
||||||
|
|
||||||
// window.addEventListener("hashchange", book.route.bind(this), false);
|
// window.addEventListener("hashchange", book.route.bind(this), false);
|
||||||
|
|
||||||
|
@ -90,10 +89,6 @@ EPUBJS.Renderer.prototype.chapter = function(chapter){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.route = function(hash, callback){
|
EPUBJS.Renderer.prototype.route = function(hash, callback){
|
||||||
|
@ -112,17 +107,22 @@ EPUBJS.Renderer.prototype.hideHashChanges = function(){
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.onResized = function(){
|
EPUBJS.Renderer.prototype.onResized = function(e){
|
||||||
|
|
||||||
var msg = {
|
var msg = {
|
||||||
width: this.el.clientWidth,
|
width: this.iframe.clientWidth,
|
||||||
height: this.el.clientHeight
|
height: this.iframe.clientHeight
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(this.doc){
|
||||||
|
this.reformat();
|
||||||
|
}
|
||||||
|
|
||||||
this.trigger("renderer:resized", msg);
|
this.trigger("renderer:resized", msg);
|
||||||
this.book.trigger("book:resized", msg);
|
this.book.trigger("book:resized", msg);
|
||||||
|
|
||||||
this.reformat();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.reformat = function(){
|
EPUBJS.Renderer.prototype.reformat = function(){
|
||||||
|
@ -151,26 +151,17 @@ EPUBJS.Renderer.prototype.reformat = function(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.resizeIframe = function(e, cWidth, cHeight){
|
EPUBJS.Renderer.prototype.resizeIframe = function(width, height){
|
||||||
var width, height;
|
|
||||||
|
|
||||||
//-- Can be resized by the window resize event, or by passed height
|
|
||||||
if(!e){
|
|
||||||
width = cWidth;
|
|
||||||
height = cHeight;
|
|
||||||
}else{
|
|
||||||
width = e.width;
|
|
||||||
height = e.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.iframe.height = height;
|
this.iframe.height = height;
|
||||||
|
|
||||||
if(width % 2 != 0){
|
if(!isNaN(width) && width % 2 != 0){
|
||||||
width += 1; //-- Prevent cutting off edges of text in columns
|
width += 1; //-- Prevent cutting off edges of text in columns
|
||||||
}
|
}
|
||||||
|
|
||||||
this.iframe.width = width;
|
this.iframe.width = width;
|
||||||
|
|
||||||
|
this.onResized();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +179,7 @@ EPUBJS.Renderer.prototype.crossBrowserColumnCss = function(){
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.setIframeSrc = function(url){
|
EPUBJS.Renderer.prototype.setIframeSrc = function(url){
|
||||||
var renderer = this,
|
var renderer = this,
|
||||||
promise = new RSVP.Promise();
|
deferred = new RSVP.defer();
|
||||||
|
|
||||||
this.visible(false);
|
this.visible(false);
|
||||||
|
|
||||||
|
@ -210,20 +201,22 @@ EPUBJS.Renderer.prototype.setIframeSrc = function(url){
|
||||||
|
|
||||||
//-- Trigger registered hooks before displaying
|
//-- Trigger registered hooks before displaying
|
||||||
renderer.beforeDisplay(function(){
|
renderer.beforeDisplay(function(){
|
||||||
|
var msg = renderer.currentChapter;
|
||||||
|
|
||||||
renderer.calcPages();
|
renderer.calcPages();
|
||||||
|
|
||||||
promise.resolve(renderer);
|
deferred.resolve(renderer);
|
||||||
|
|
||||||
renderer.currentLocationCfi = renderer.getPageCfi();
|
msg.cfi = renderer.currentLocationCfi = renderer.getPageCfi();
|
||||||
|
|
||||||
renderer.trigger("renderer:chapterDisplayed", renderer.currentChapter);
|
renderer.trigger("renderer:chapterDisplayed", msg);
|
||||||
renderer.book.trigger("renderer:chapterDisplayed", renderer.currentChapter);
|
renderer.book.trigger("renderer:chapterDisplayed", msg);
|
||||||
|
|
||||||
renderer.visible(true);
|
renderer.visible(true);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
renderer.iframe.contentWindow.addEventListener("resize", renderer.resized, false);
|
||||||
|
|
||||||
// that.afterLoaded(that);
|
// that.afterLoaded(that);
|
||||||
|
|
||||||
|
@ -233,7 +226,7 @@ EPUBJS.Renderer.prototype.setIframeSrc = function(url){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -242,16 +235,24 @@ EPUBJS.Renderer.prototype.formatSpread = function(){
|
||||||
var divisor = 2,
|
var divisor = 2,
|
||||||
cutoff = 800;
|
cutoff = 800;
|
||||||
|
|
||||||
if(this.colWidth){
|
// if(this.colWidth){
|
||||||
this.OldcolWidth = this.colWidth;
|
// this.OldcolWidth = this.colWidth;
|
||||||
this.OldspreadWidth = this.spreadWidth;
|
// this.OldspreadWidth = this.spreadWidth;
|
||||||
}
|
// }
|
||||||
|
|
||||||
//-- Check the width and decied on columns
|
//-- Check the width and decied on columns
|
||||||
//-- Todo: a better place for this?
|
//-- Todo: a better place for this?
|
||||||
this.elWidth = this.iframe.width;
|
this.elWidth = this.iframe.clientWidth;
|
||||||
|
if(this.elWidth % 2 != 0){
|
||||||
|
this.elWidth -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
this.gap = this.gap || Math.ceil(this.elWidth / 8);
|
// this.gap = this.gap || Math.ceil(this.elWidth / 8);
|
||||||
|
this.gap = Math.ceil(this.elWidth / 8);
|
||||||
|
|
||||||
|
if(this.gap % 2 != 0){
|
||||||
|
this.gap += 1;
|
||||||
|
}
|
||||||
|
|
||||||
if(this.elWidth < cutoff || !this.book.settings.spreads) {
|
if(this.elWidth < cutoff || !this.book.settings.spreads) {
|
||||||
this.spread = false; //-- Single Page
|
this.spread = false; //-- Single Page
|
||||||
|
@ -263,16 +264,15 @@ EPUBJS.Renderer.prototype.formatSpread = function(){
|
||||||
|
|
||||||
this.colWidth = Math.floor((this.elWidth - this.gap) / divisor);
|
this.colWidth = Math.floor((this.elWidth - this.gap) / divisor);
|
||||||
|
|
||||||
/* - Was causing jumps, doesn't seem to be needed anymore
|
// - Was causing jumps, doesn't seem to be needed anymore
|
||||||
//-- Must be even for firefox
|
//-- Must be even for firefox
|
||||||
if(this.colWidth % 2 != 0){
|
// if(this.colWidth % 2 != 0){
|
||||||
this.colWidth -= 1;
|
// this.colWidth -= 1;
|
||||||
}
|
// }
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.spreadWidth = (this.colWidth + this.gap) * divisor;
|
this.spreadWidth = (this.colWidth + this.gap) * divisor;
|
||||||
|
|
||||||
// if(this.bodyEl) this.bodyEl.style.margin = 0;
|
// if(this.bodyEl) this.bodyEl.style.margin = 0;
|
||||||
// this.bodyEl.style.fontSize = localStorage.getItem("fontSize") || "medium";
|
// this.bodyEl.style.fontSize = localStorage.getItem("fontSize") || "medium";
|
||||||
|
|
||||||
|
@ -281,18 +281,16 @@ EPUBJS.Renderer.prototype.formatSpread = function(){
|
||||||
|
|
||||||
this.docEl.style.overflow = "hidden";
|
this.docEl.style.overflow = "hidden";
|
||||||
|
|
||||||
this.docEl.style.width = this.elWidth;
|
this.docEl.style.width = this.elWidth + "px";
|
||||||
|
|
||||||
//-- Adjust height
|
//-- Adjust height
|
||||||
this.docEl.style.height = this.iframe.height + "px";
|
this.docEl.style.height = this.iframe.clientHeight + "px";
|
||||||
|
|
||||||
//-- Add columns
|
//-- Add columns
|
||||||
this.docEl.style[EPUBJS.Renderer.columnAxis] = "horizontal";
|
this.docEl.style[EPUBJS.Renderer.columnAxis] = "horizontal";
|
||||||
this.docEl.style[EPUBJS.Renderer.columnGap] = this.gap+"px";
|
this.docEl.style[EPUBJS.Renderer.columnGap] = this.gap+"px";
|
||||||
this.docEl.style[EPUBJS.Renderer.columnWidth] = this.colWidth+"px";
|
this.docEl.style[EPUBJS.Renderer.columnWidth] = this.colWidth+"px";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.fixedLayout = function(){
|
EPUBJS.Renderer.prototype.fixedLayout = function(){
|
||||||
|
@ -603,8 +601,11 @@ EPUBJS.Renderer.prototype.walk = function(node) {
|
||||||
if(!r && node && node.childElementCount > 0){
|
if(!r && node && node.childElementCount > 0){
|
||||||
|
|
||||||
children = node.children;
|
children = node.children;
|
||||||
leng = children.length;
|
if (children && children.length) {
|
||||||
|
leng = children.length ? children.length : 0;
|
||||||
|
} else {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0; i < leng; i++) {
|
for (var i = 0; i < leng; i++) {
|
||||||
if(children[i] != prevNode) stack.push(children[i]);
|
if(children[i] != prevNode) stack.push(children[i]);
|
||||||
|
@ -696,7 +697,7 @@ EPUBJS.Renderer.prototype.height = function(el){
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Renderer.prototype.remove = function() {
|
EPUBJS.Renderer.prototype.remove = function() {
|
||||||
window.removeEventListener("resize", this.resized);
|
this.iframe.contentWindow.removeEventListener("resize", this.resized);
|
||||||
this.el.removeChild(this.iframe);
|
this.el.removeChild(this.iframe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ EPUBJS.replace.links = function(_store, full, done, link){
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.replace.stylesheets = function(_store, full) {
|
EPUBJS.replace.stylesheets = function(_store, full) {
|
||||||
var promise = new RSVP.Promise();
|
var deferred = new RSVP.defer();
|
||||||
|
|
||||||
if(!_store) return;
|
if(!_store) return;
|
||||||
|
|
||||||
|
@ -57,25 +57,25 @@ EPUBJS.replace.stylesheets = function(_store, full) {
|
||||||
var blob = new Blob([newText], { "type" : "text\/css" }),
|
var blob = new Blob([newText], { "type" : "text\/css" }),
|
||||||
url = _URL.createObjectURL(blob);
|
url = _URL.createObjectURL(blob);
|
||||||
|
|
||||||
promise.resolve(url);
|
deferred.resolve(url);
|
||||||
|
|
||||||
}, function(e) {console.error(e)});
|
}, function(e) {console.error(e)});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.replace.cssUrls = function(_store, base, text){
|
EPUBJS.replace.cssUrls = function(_store, base, text){
|
||||||
var promise = new RSVP.Promise(),
|
var deferred = new RSVP.defer(),
|
||||||
promises = [],
|
promises = [],
|
||||||
matches = text.match(/url\(\'?\"?([^\'|^\"]*)\'?\"?\)/g);
|
matches = text.match(/url\(\'?\"?([^\'|^\"]*)\'?\"?\)/g);
|
||||||
|
|
||||||
if(!_store) return;
|
if(!_store) return;
|
||||||
|
|
||||||
if(!matches){
|
if(!matches){
|
||||||
promise.resolve(text);
|
deferred.resolve(text);
|
||||||
return promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
matches.forEach(function(str){
|
matches.forEach(function(str){
|
||||||
|
@ -88,8 +88,8 @@ EPUBJS.replace.cssUrls = function(_store, base, text){
|
||||||
});
|
});
|
||||||
|
|
||||||
RSVP.all(promises).then(function(){
|
RSVP.all(promises).then(function(){
|
||||||
promise.resolve(text);
|
deferred.resolve(text);
|
||||||
});
|
});
|
||||||
|
|
||||||
return promise;
|
return deferred.promise;
|
||||||
}
|
}
|
|
@ -28,13 +28,13 @@ EPUBJS.Unarchiver.prototype.loadLib = function(callback){
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Unarchiver.prototype.openZip = function(zipUrl, callback){
|
EPUBJS.Unarchiver.prototype.openZip = function(zipUrl, callback){
|
||||||
var promise = new RSVP.Promise();
|
var deferred = new RSVP.defer();
|
||||||
var zipFs = this.zipFs;
|
var zipFs = this.zipFs;
|
||||||
zipFs.importHttpContent(zipUrl, false, function() {
|
zipFs.importHttpContent(zipUrl, false, function() {
|
||||||
promise.resolve(zipFs);
|
deferred.resolve(zipFs);
|
||||||
}, this.failed);
|
}, this.failed);
|
||||||
|
|
||||||
return promise
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
// EPUBJS.Unarchiver.prototype.getXml = function(url){
|
// EPUBJS.Unarchiver.prototype.getXml = function(url){
|
||||||
|
@ -63,29 +63,29 @@ EPUBJS.Unarchiver.prototype.getXml = function(url){
|
||||||
|
|
||||||
EPUBJS.Unarchiver.prototype.getUrl = function(url, mime){
|
EPUBJS.Unarchiver.prototype.getUrl = function(url, mime){
|
||||||
var unarchiver = this;
|
var unarchiver = this;
|
||||||
var promise = new RSVP.Promise();
|
var deferred = new RSVP.defer();
|
||||||
var entry = this.zipFs.find(url);
|
var entry = this.zipFs.find(url);
|
||||||
var _URL = window.URL || window.webkitURL || window.mozURL;
|
var _URL = window.URL || window.webkitURL || window.mozURL;
|
||||||
|
|
||||||
if(!entry) console.error(url);
|
if(!entry) console.error(url);
|
||||||
|
|
||||||
if(url in this.urlCache) {
|
if(url in this.urlCache) {
|
||||||
promise.resolve(this.urlCache[url]);
|
deferred.resolve(this.urlCache[url]);
|
||||||
return promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.getBlob(mime || zip.getMimeType(entry.name), function(blob){
|
entry.getBlob(mime || zip.getMimeType(entry.name), function(blob){
|
||||||
var tempUrl = _URL.createObjectURL(blob);
|
var tempUrl = _URL.createObjectURL(blob);
|
||||||
promise.resolve(tempUrl);
|
deferred.resolve(tempUrl);
|
||||||
unarchiver.urlCache[url] = tempUrl;
|
unarchiver.urlCache[url] = tempUrl;
|
||||||
});
|
});
|
||||||
|
|
||||||
return promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Unarchiver.prototype.getText = function(url){
|
EPUBJS.Unarchiver.prototype.getText = function(url){
|
||||||
var unarchiver = this;
|
var unarchiver = this;
|
||||||
var promise = new RSVP.Promise();
|
var deferred = new RSVP.defer();
|
||||||
var entry = this.zipFs.find(url);
|
var entry = this.zipFs.find(url);
|
||||||
var _URL = window.URL || window.webkitURL || window.mozURL;
|
var _URL = window.URL || window.webkitURL || window.mozURL;
|
||||||
|
|
||||||
|
@ -93,10 +93,10 @@ EPUBJS.Unarchiver.prototype.getText = function(url){
|
||||||
|
|
||||||
|
|
||||||
entry.getText(function(text){
|
entry.getText(function(text){
|
||||||
promise.resolve(text);
|
deferred.resolve(text);
|
||||||
}, null, null, 'ISO-8859-1');
|
}, null, null, 'ISO-8859-1');
|
||||||
|
|
||||||
return promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
EPUBJS.Unarchiver.prototype.revokeUrl = function(url){
|
EPUBJS.Unarchiver.prototype.revokeUrl = function(url){
|
||||||
|
|
|
@ -23,7 +23,7 @@ asyncTest("Get book URL from bookPath", 1, function() {
|
||||||
var opended = Book.open('/demo/moby-dick/');
|
var opended = Book.open('/demo/moby-dick/');
|
||||||
|
|
||||||
opended.then(function(){
|
opended.then(function(){
|
||||||
equal( Book.bookUrl, location.href.replace("tests/", '') + "/demo/moby-dick/", "bookUrl is correctly resolved" );
|
equal( Book.bookUrl, location.href.replace("tests/", '') + "demo/moby-dick/", "bookUrl is correctly resolved" );
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ asyncTest("Get book URL from ../bookPath", 1, function() {
|
||||||
var Book = ePub();
|
var Book = ePub();
|
||||||
var opended = Book.open('../demo/moby-dick/');
|
var opended = Book.open('../demo/moby-dick/');
|
||||||
opended.then(function(){
|
opended.then(function(){
|
||||||
equal( Book.bookUrl, location.href.replace("tests/", '') + "/demo/moby-dick/", "bookUrl with ../ is correctly resolved" );
|
equal( Book.bookUrl, "/demo/moby-dick/", "bookUrl with ../ is correctly resolved" );
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ asyncTest("Get Contents from Uncompressed Epub", 5, function() {
|
||||||
|
|
||||||
Book.ready.all.then(function(){
|
Book.ready.all.then(function(){
|
||||||
ok( true, "Book is all ready" );
|
ok( true, "Book is all ready" );
|
||||||
|
|
||||||
equal( Book.cover, Book.settings.contentsPath + "images/9780316000000.jpg", "Cover url is set");
|
equal( Book.cover, Book.settings.contentsPath + "images/9780316000000.jpg", "Cover url is set");
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
|
@ -117,7 +118,7 @@ asyncTest("Get Contents from Restored Epub", 7, function() {
|
||||||
|
|
||||||
var Book = ePub('../demo/moby-dick/', { restore: true });
|
var Book = ePub('../demo/moby-dick/', { restore: true });
|
||||||
|
|
||||||
equal( Book.settings.contentsPath, location.href.replace("tests/", '') + "/demo/moby-dick/OPS/", "contentsPath was restored");
|
equal( Book.settings.contentsPath, "/demo/moby-dick/OPS/", "contentsPath was restored");
|
||||||
|
|
||||||
Book.getMetadata().then(function(meta){
|
Book.getMetadata().then(function(meta){
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue