mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Reversed order of Nav TOC items
This commit is contained in:
parent
4bf7e5f0ef
commit
dbb07acd06
15 changed files with 133 additions and 115 deletions
2
books
2
books
|
@ -1 +1 @@
|
|||
Subproject commit ab9755a74714b647290c861f666515de220935d8
|
||||
Subproject commit 09bd1725f5839996e747cf83500a2526b86ae6af
|
100
build/epub.js
100
build/epub.js
|
@ -902,72 +902,66 @@ EPUBJS.Book.prototype.unpack = function(containerPath){
|
|||
|
||||
//-- Return chain of promises
|
||||
return book.loadXml(book.bookUrl + containerPath).
|
||||
then(function(containerXml){
|
||||
then(function(containerXml){
|
||||
return parse.container(containerXml); // Container has path to content
|
||||
}).
|
||||
then(function(paths){
|
||||
}).
|
||||
then(function(paths){
|
||||
book.settings.contentsPath = book.bookUrl + paths.basePath;
|
||||
book.settings.packageUrl = book.bookUrl + paths.packagePath;
|
||||
return book.loadXml(book.settings.packageUrl); // Containes manifest, spine and metadata
|
||||
}).
|
||||
then(function(packageXml){
|
||||
return parse.package(packageXml, book.settings.contentsPath); // Extract info from contents
|
||||
}).
|
||||
then(function(contents){
|
||||
}).
|
||||
then(function(packageXml){
|
||||
return parse.package(packageXml, book.settings.contentsPath); // Extract info from contents
|
||||
}).
|
||||
then(function(contents){
|
||||
book.contents = contents;
|
||||
book.manifest = book.contents.manifest;
|
||||
book.spine = book.contents.spine;
|
||||
book.spineIndexByURL = book.contents.spineIndexByURL;
|
||||
book.metadata = book.contents.metadata;
|
||||
|
||||
book.contents = contents;
|
||||
book.manifest = book.contents.manifest;
|
||||
book.spine = book.contents.spine;
|
||||
book.spineIndexByURL = book.contents.spineIndexByURL;
|
||||
book.metadata = book.contents.metadata;
|
||||
book.cover = book.contents.cover = book.settings.contentsPath + contents.coverPath;
|
||||
|
||||
book.cover = book.contents.cover = book.settings.contentsPath + contents.coverPath;
|
||||
book.spineNodeIndex = book.contents.spineNodeIndex = contents.spineNodeIndex;
|
||||
|
||||
book.spineNodeIndex = book.contents.spineNodeIndex = contents.spineNodeIndex;
|
||||
book.ready.manifest.resolve(book.contents.manifest);
|
||||
book.ready.spine.resolve(book.contents.spine);
|
||||
book.ready.metadata.resolve(book.contents.metadata);
|
||||
book.ready.cover.resolve(book.contents.cover);
|
||||
|
||||
book.ready.manifest.resolve(book.contents.manifest);
|
||||
book.ready.spine.resolve(book.contents.spine);
|
||||
book.ready.metadata.resolve(book.contents.metadata);
|
||||
book.ready.cover.resolve(book.contents.cover);
|
||||
//-- Adjust setting based on metadata
|
||||
|
||||
//-- Adjust setting based on metadata
|
||||
//-- Load the TOC, optional; either the EPUB3 XHTML Navigation file or the EPUB2 NCX file
|
||||
if(contents.navPath) {
|
||||
book.settings.navUrl = book.settings.contentsPath + contents.navPath;
|
||||
|
||||
//-- Load the TOC, optional; either the EPUB3 XHTML Navigation file or the EPUB2 NCX file
|
||||
if(contents.navPath) {
|
||||
book.loadXml(book.settings.navUrl).
|
||||
then(function(navHtml){
|
||||
return parse.nav(navHtml); // Grab Table of Contents
|
||||
}).then(function(toc){
|
||||
book.toc = book.contents.toc = toc;
|
||||
book.ready.toc.resolve(book.contents.toc);
|
||||
});
|
||||
|
||||
book.settings.navUrl = book.settings.contentsPath + contents.navPath;
|
||||
} else if(contents.tocPath) {
|
||||
book.settings.tocUrl = book.settings.contentsPath + contents.tocPath;
|
||||
|
||||
book.loadXml(book.settings.navUrl).
|
||||
then(function(navHtml){
|
||||
return parse.nav(navHtml); // Grab Table of Contents
|
||||
}).then(function(toc){
|
||||
book.toc = book.contents.toc = toc;
|
||||
book.ready.toc.resolve(book.contents.toc);
|
||||
});
|
||||
|
||||
} else if(contents.tocPath) {
|
||||
|
||||
book.settings.tocUrl = book.settings.contentsPath + contents.tocPath;
|
||||
|
||||
book.loadXml(book.settings.tocUrl).
|
||||
then(function(tocXml){
|
||||
book.loadXml(book.settings.tocUrl).
|
||||
then(function(tocXml){
|
||||
return parse.toc(tocXml); // Grab Table of Contents
|
||||
}).then(function(toc){
|
||||
book.toc = book.contents.toc = toc;
|
||||
book.ready.toc.resolve(book.contents.toc);
|
||||
// book.saveSettings();
|
||||
});
|
||||
|
||||
} else {
|
||||
book.ready.toc.resolve(false);
|
||||
}
|
||||
|
||||
}).
|
||||
fail(function(error) {
|
||||
}).
|
||||
fail(function(error) {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
EPUBJS.Book.prototype.getMetadata = function() {
|
||||
|
@ -1613,6 +1607,7 @@ EPUBJS.Chapter.prototype.unload = function(store){
|
|||
this.tempUrl = false;
|
||||
}
|
||||
}
|
||||
|
||||
var EPUBJS = EPUBJS || {};
|
||||
EPUBJS.core = {}
|
||||
|
||||
|
@ -2244,7 +2239,7 @@ EPUBJS.Parser.prototype.package = function(packageXml, baseUrl){
|
|||
'tocPath' : tocPath,
|
||||
'coverPath': coverPath,
|
||||
'spineNodeIndex' : spineNodeIndex,
|
||||
'spineIndexByURL': spineIndexByURL
|
||||
'spineIndexByURL' : spineIndexByURL
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2334,12 +2329,14 @@ EPUBJS.Parser.prototype.manifest = function(manifestXml){
|
|||
items.forEach(function(item){
|
||||
var id = item.getAttribute('id'),
|
||||
href = item.getAttribute('href') || '',
|
||||
type = item.getAttribute('media-type') || '';
|
||||
type = item.getAttribute('media-type') || '',
|
||||
properties = item.getAttribute('properties') || '';
|
||||
|
||||
manifest[id] = {
|
||||
'href' : baseUrl + href, //-- Absolute URL for loading with a web worker
|
||||
'type' : type
|
||||
'type' : type,
|
||||
'properties' : properties
|
||||
};
|
||||
|
||||
});
|
||||
|
@ -2357,16 +2354,14 @@ EPUBJS.Parser.prototype.spine = function(spineXml, manifest){
|
|||
//-- Add to array to mantain ordering and cross reference with manifest
|
||||
items.forEach(function(item, index){
|
||||
var Id = item.getAttribute('idref');
|
||||
c
|
||||
var vert = {
|
||||
'id' : Id,
|
||||
'linear' : item.getAttribute('linear') || '',
|
||||
'properties' : item.getAttribute('properties') || '',
|
||||
'properties' : manifest[Id].properties || '',
|
||||
'href' : manifest[Id].href,
|
||||
'index' : index
|
||||
}
|
||||
|
||||
|
||||
spine.push(vert);
|
||||
});
|
||||
|
||||
|
@ -2422,7 +2417,7 @@ EPUBJS.Parser.prototype.nav = function(navHtml){
|
|||
text = content.textContent || "",
|
||||
subitems = getTOC(item);
|
||||
item.setAttribute('id', id); // Ensure all elements have an id
|
||||
list.unshift({
|
||||
list.push({
|
||||
"id": id,
|
||||
"href": href,
|
||||
"label": text,
|
||||
|
@ -2457,9 +2452,9 @@ EPUBJS.Parser.prototype.toc = function(tocXml){
|
|||
|
||||
while(iter--){
|
||||
node = nodesArray[iter];
|
||||
if(node.nodeName === "navPoint") {
|
||||
items.push(node);
|
||||
}
|
||||
if(node.nodeName === "navPoint") {
|
||||
items.push(node);
|
||||
}
|
||||
}
|
||||
|
||||
items.forEach(function(item){
|
||||
|
@ -3196,6 +3191,7 @@ EPUBJS.Renderer.prototype.remove = function() {
|
|||
|
||||
//-- Enable binding events to parser
|
||||
RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);
|
||||
|
||||
var EPUBJS = EPUBJS || {};
|
||||
EPUBJS.replace = {};
|
||||
|
||||
|
|
4
build/epub.min.js
vendored
4
build/epub.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -157,6 +157,33 @@ EPUBJS.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chap
|
|||
|
||||
}
|
||||
|
||||
EPUBJS.Hooks.register("beforeChapterDisplay").mathml = function(callback, renderer){
|
||||
|
||||
// check of currentChapter properties contains 'mathml'
|
||||
if(renderer.currentChapter.properties.indexOf("mathml") !== -1 ){
|
||||
|
||||
// Assign callback to be inside iframe window
|
||||
renderer.iframe.contentWindow.mathmlCallback = callback;
|
||||
|
||||
// add MathJax config script tag to the renderer body
|
||||
var s = document.createElement("script");
|
||||
s.type = 'text/x-mathjax-config';
|
||||
s.innerHTML = '\
|
||||
MathJax.Hub.Register.StartupHook("End",function () { \
|
||||
console.log("The TeX input jax is loaded and ready!"); \
|
||||
// window.mathmlCallback() \
|
||||
});\
|
||||
MathJax.Hub.Config({jax: ["input/TeX","input/MathML","output/SVG"],extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],TeX: {extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]},MathMenu: {showRenderer: false},menuSettings: {zoom: "Click"},messageStyle: "none"}); \
|
||||
';
|
||||
renderer.doc.body.appendChild(s);
|
||||
// add MathJax.js to renderer head
|
||||
EPUBJS.core.addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML", null, renderer.doc.head);
|
||||
|
||||
} else {
|
||||
if(callback) callback();
|
||||
}
|
||||
}
|
||||
|
||||
EPUBJS.Hooks.register("beforeChapterDisplay").smartimages = function(callback, chapter){
|
||||
var images = chapter.doc.querySelectorAll('img'),
|
||||
items = Array.prototype.slice.call(images),
|
||||
|
|
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")),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()};
|
||||
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").mathml=function(a,b){if(-1!==b.currentChapter.properties.indexOf("mathml")){b.iframe.contentWindow.mathmlCallback=a;var c=document.createElement("script");c.type="text/x-mathjax-config",c.innerHTML=' MathJax.Hub.Register.StartupHook("End",function () { console.log("The TeX input jax is loaded and ready!"); // window.mathmlCallback() }); MathJax.Hub.Config({jax: ["input/TeX","input/MathML","output/SVG"],extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],TeX: {extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]},MathMenu: {showRenderer: false},menuSettings: {zoom: "Click"},messageStyle: "none"}); ',b.doc.body.appendChild(c),EPUBJS.core.addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",null,b.doc.head)}else 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()};
|
File diff suppressed because one or more lines are too long
2
build/libs/zip.min.js
vendored
2
build/libs/zip.min.js
vendored
File diff suppressed because one or more lines are too long
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")),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()};
|
||||
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").mathml=function(a,b){if(-1!==b.currentChapter.properties.indexOf("mathml")){b.iframe.contentWindow.mathmlCallback=a;var c=document.createElement("script");c.type="text/x-mathjax-config",c.innerHTML=' MathJax.Hub.Register.StartupHook("End",function () { console.log("The TeX input jax is loaded and ready!"); // window.mathmlCallback() }); MathJax.Hub.Config({jax: ["input/TeX","input/MathML","output/SVG"],extensions: ["tex2jax.js","mml2jax.js","MathEvents.js"],TeX: {extensions: ["noErrors.js","noUndefined.js","autoload-all.js"]},MathMenu: {showRenderer: false},menuSettings: {zoom: "Click"},messageStyle: "none"}); ',b.doc.body.appendChild(c),EPUBJS.core.addScript("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML",null,b.doc.head)}else 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()};
|
2
demo/js/libs/inflate.min.js
vendored
2
demo/js/libs/inflate.min.js
vendored
File diff suppressed because one or more lines are too long
2
demo/js/libs/zip.min.js
vendored
2
demo/js/libs/zip.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -103,8 +103,8 @@
|
|||
<script>
|
||||
"use strict";
|
||||
|
||||
// var Book = ePub("../demo/moby-dick/", {restore: true, reload: false });
|
||||
var Book = ePub("../books/demo-book-gh-pages/", {restore: true, reload: false });
|
||||
var Book = ePub("../demo/moby-dick/", {restore: true, reload: true });
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"name": "EpubJS",
|
||||
"version": "0.1.0",
|
||||
"repository": "https://github.com/futurepress/epub.js",
|
||||
"devDependencies": {
|
||||
"grunt": "~0.4.1",
|
||||
"grunt-contrib-connect": "~0.3.0",
|
||||
|
|
80
src/book.js
80
src/book.js
|
@ -167,72 +167,66 @@ EPUBJS.Book.prototype.unpack = function(containerPath){
|
|||
|
||||
//-- Return chain of promises
|
||||
return book.loadXml(book.bookUrl + containerPath).
|
||||
then(function(containerXml){
|
||||
then(function(containerXml){
|
||||
return parse.container(containerXml); // Container has path to content
|
||||
}).
|
||||
then(function(paths){
|
||||
}).
|
||||
then(function(paths){
|
||||
book.settings.contentsPath = book.bookUrl + paths.basePath;
|
||||
book.settings.packageUrl = book.bookUrl + paths.packagePath;
|
||||
return book.loadXml(book.settings.packageUrl); // Containes manifest, spine and metadata
|
||||
}).
|
||||
then(function(packageXml){
|
||||
return parse.package(packageXml, book.settings.contentsPath); // Extract info from contents
|
||||
}).
|
||||
then(function(contents){
|
||||
}).
|
||||
then(function(packageXml){
|
||||
return parse.package(packageXml, book.settings.contentsPath); // Extract info from contents
|
||||
}).
|
||||
then(function(contents){
|
||||
book.contents = contents;
|
||||
book.manifest = book.contents.manifest;
|
||||
book.spine = book.contents.spine;
|
||||
book.spineIndexByURL = book.contents.spineIndexByURL;
|
||||
book.metadata = book.contents.metadata;
|
||||
|
||||
book.contents = contents;
|
||||
book.manifest = book.contents.manifest;
|
||||
book.spine = book.contents.spine;
|
||||
book.spineIndexByURL = book.contents.spineIndexByURL;
|
||||
book.metadata = book.contents.metadata;
|
||||
book.cover = book.contents.cover = book.settings.contentsPath + contents.coverPath;
|
||||
|
||||
book.cover = book.contents.cover = book.settings.contentsPath + contents.coverPath;
|
||||
book.spineNodeIndex = book.contents.spineNodeIndex = contents.spineNodeIndex;
|
||||
|
||||
book.spineNodeIndex = book.contents.spineNodeIndex = contents.spineNodeIndex;
|
||||
book.ready.manifest.resolve(book.contents.manifest);
|
||||
book.ready.spine.resolve(book.contents.spine);
|
||||
book.ready.metadata.resolve(book.contents.metadata);
|
||||
book.ready.cover.resolve(book.contents.cover);
|
||||
|
||||
book.ready.manifest.resolve(book.contents.manifest);
|
||||
book.ready.spine.resolve(book.contents.spine);
|
||||
book.ready.metadata.resolve(book.contents.metadata);
|
||||
book.ready.cover.resolve(book.contents.cover);
|
||||
//-- Adjust setting based on metadata
|
||||
|
||||
//-- Adjust setting based on metadata
|
||||
//-- Load the TOC, optional; either the EPUB3 XHTML Navigation file or the EPUB2 NCX file
|
||||
if(contents.navPath) {
|
||||
book.settings.navUrl = book.settings.contentsPath + contents.navPath;
|
||||
|
||||
//-- Load the TOC, optional; either the EPUB3 XHTML Navigation file or the EPUB2 NCX file
|
||||
if(contents.navPath) {
|
||||
book.loadXml(book.settings.navUrl).
|
||||
then(function(navHtml){
|
||||
return parse.nav(navHtml); // Grab Table of Contents
|
||||
}).then(function(toc){
|
||||
book.toc = book.contents.toc = toc;
|
||||
book.ready.toc.resolve(book.contents.toc);
|
||||
});
|
||||
|
||||
book.settings.navUrl = book.settings.contentsPath + contents.navPath;
|
||||
} else if(contents.tocPath) {
|
||||
book.settings.tocUrl = book.settings.contentsPath + contents.tocPath;
|
||||
|
||||
book.loadXml(book.settings.navUrl).
|
||||
then(function(navHtml){
|
||||
return parse.nav(navHtml); // Grab Table of Contents
|
||||
}).then(function(toc){
|
||||
book.toc = book.contents.toc = toc;
|
||||
book.ready.toc.resolve(book.contents.toc);
|
||||
});
|
||||
|
||||
} else if(contents.tocPath) {
|
||||
|
||||
book.settings.tocUrl = book.settings.contentsPath + contents.tocPath;
|
||||
|
||||
book.loadXml(book.settings.tocUrl).
|
||||
then(function(tocXml){
|
||||
book.loadXml(book.settings.tocUrl).
|
||||
then(function(tocXml){
|
||||
return parse.toc(tocXml); // Grab Table of Contents
|
||||
}).then(function(toc){
|
||||
book.toc = book.contents.toc = toc;
|
||||
book.ready.toc.resolve(book.contents.toc);
|
||||
// book.saveSettings();
|
||||
});
|
||||
|
||||
} else {
|
||||
book.ready.toc.resolve(false);
|
||||
}
|
||||
|
||||
}).
|
||||
fail(function(error) {
|
||||
}).
|
||||
fail(function(error) {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
EPUBJS.Book.prototype.getMetadata = function() {
|
||||
|
|
|
@ -225,7 +225,7 @@ EPUBJS.Parser.prototype.nav = function(navHtml){
|
|||
text = content.textContent || "",
|
||||
subitems = getTOC(item);
|
||||
item.setAttribute('id', id); // Ensure all elements have an id
|
||||
list.unshift({
|
||||
list.push({
|
||||
"id": id,
|
||||
"href": href,
|
||||
"label": text,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue