Readium.js讀取epub目錄問題
最近要做一個手機讀書軟件
在網上下載了Readium.js庫,能讀取出epub的內容,上下翻頁都可以行,但是epub目錄toc調用以及顯示不出來,求救
關於toc在Readium.js中的代碼
getPackageDocumentDOM : function (callback) {
this.get('epubFetch').getPackageDom(callback);
},
getToc : function () {
var item = this.getTocItem();
if (item) {
var href = item.get("contentDocumentURI");
return href;
}
return null;
},
getTocText: function (callback) {
var tocUrl = this.getToc();
console.log('tocUrl: [' + tocUrl + ']');
this.get('epubFetch').relativeToPackageFetchFileContents(tocUrl, 'text', function (tocDocumentText) {
callback(tocDocumentText)
}, function (err) {
console.error('ERROR fetching TOC from [' + this.getToc() + ']:');
console.error(err);
callback(undefined);
});
},
getTocDom: function (callback) {
this.getTocText(function (tocText) {
if (typeof tocText === 'string') {
var tocDom = (new DOMParser()).parseFromString(tocText, "text/xml");
callback(tocDom);
} else {
callback(undefined);
}
});
},
// Description: This is a convenience method that will generate an html list structure from an ncx XML
// document.
generateTocListDOM: function (callback) {
var that = this;
that.getTocDom(function (tocDom) {
if (tocDom) {
if (that.tocIsNcx()) {
var $ncxOrderedList;
$ncxOrderedList = that.getNcxOrderedList($("navMap", tocDom));
callback($ncxOrderedList[0]);
} else {
var packageDocumentURL = that.get('epubFetch').getPackageDocumentURL();
var packageDocumentAbsoluteURL = new URI(packageDocumentURL).absoluteTo(document.URL);
var tocDocumentAbsoluteURL = new URI(that.getToc()).absoluteTo(document.URL);
// add a BASE tag to change the TOC document's baseURI.
var oldBaseTag = $(tocDom).remove('base');
var newBaseTag = $('<base></base>');
$(newBaseTag).attr('href', tocDocumentAbsoluteURL);
$(tocDom).find('head').append(newBaseTag);
// TODO: fix TOC hrefs both for exploded in zipped EPUBs
callback(tocDom);
}
} else {
callback(undefined);
}
});
},
tocIsNcx : function () {
var tocItem = this.getTocItem();
var contentDocURI = tocItem.get("contentDocumentURI");
var fileExtension = contentDocURI.substr(contentDocURI.lastIndexOf('.') + 1);
if (fileExtension.trim().toLowerCase() === "ncx") {
return true;
}
else {
return false;
}
},
// ----------------------- PRIVATE HELPERS -------------------------------- //
getNcxOrderedList : function ($navMapDOM) {
var that = this;
var $ol = $("<ol></ol>");
$.each($navMapDOM.children("navPoint"), function (index, navPoint) {
that.addNavPointElements($(navPoint), $ol);
});
return $ol;
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TOC好像设置了Hidden属性