1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00

Moved replacements to replacment.js

This commit is contained in:
Fred Chasen 2013-07-22 19:04:14 -07:00
parent 55813bfe69
commit d8edee0793
10 changed files with 385 additions and 434 deletions

View file

@ -423,7 +423,8 @@ EPUBJS.Book.prototype.removeSavedContents = function() {
//-- Takes a string or a element
EPUBJS.Book.prototype.renderTo = function(elem){
var book = this;
var book = this,
rendered;
if(_.isElement(elem)) {
this.element = elem;
@ -434,12 +435,16 @@ EPUBJS.Book.prototype.renderTo = function(elem){
return;
}
return this.opened.
then(function(){
book.render = new EPUBJS.Renderer(book);
rendered = this.opened.
then(function(){
book.render = new EPUBJS.Renderer(book);
return book.startDisplay();
})
return book.startDisplay();
}, function(error) { console.error(error) });
rendered.then(null, function(error) { console.error(error) });
return rendered;
}
EPUBJS.Book.prototype.startDisplay = function(){
@ -763,7 +768,6 @@ EPUBJS.Book.prototype.triggerHooks = function(type, callback, passed){
hooks = this.hooks[type];
count = hooks.length;
function countdown(){
count--;
if(count <= 0 && callback) callback();
@ -1614,13 +1618,8 @@ EPUBJS.Renderer = function(book) {
this.el = book.element;
this.book = book;
this.settings = book.settings;
book.registerHook("beforeChapterDisplay",
[this.replaceLinks.bind(this),
this.replaceResources.bind(this),
this.replaceHead.bind(this)], true);
// this.settings = book.settings;
this.caches = {};
this.crossBrowserColumnCss();
@ -1642,8 +1641,8 @@ EPUBJS.Renderer.prototype.initialize = function(){
this.iframe = document.createElement('iframe');
//this.iframe.id = "epubjs-iframe";
if(this.settings.width || this.settings.height){
this.resizeIframe(false, this.settings.width || this.el.clientWidth, this.settings.height || this.el.clientHeight);
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);
} else {
this.resizeIframe(false, this.el.clientWidth, this.el.clientHeight);
@ -1663,6 +1662,18 @@ EPUBJS.Renderer.prototype.listeners = function(){
// window.addEventListener("hashchange", book.route.bind(this), false);
this.book.registerHook("beforeChapterDisplay", this.replaceLinks.bind(this), true);
if(this.determineStore()) {
this.book.registerHook("beforeChapterDisplay", [
EPUBJS.replace.head,
EPUBJS.replace.resources,
EPUBJS.replace.svg
], true);
}
}
EPUBJS.Renderer.prototype.chapter = function(chapter){
@ -2019,25 +2030,6 @@ EPUBJS.Renderer.prototype.setLeft = function(leftPos){
this.doc.defaultView.scrollTo(leftPos, 0);
}
EPUBJS.Renderer.prototype.replace = function(query, func, callback){
var items, resources, count;
items = this.doc.querySelectorAll(query);
resources = Array.prototype.slice.call(items);
count = resources.length;
resources.forEach(function(item){
func(item, function(){
count--;
if(count <= 0 && callback) callback();
});
}.bind(this));
if(count === 0) callback();
}
EPUBJS.Renderer.prototype.determineStore = function(callback){
if(this.book.fromStorage) {
@ -2059,164 +2051,90 @@ EPUBJS.Renderer.prototype.determineStore = function(callback){
}
}
//-- Replaces links in head, such as stylesheets
EPUBJS.Renderer.prototype.replaceHead = function(callback){
var srcs, resources, count, oldUrls,
newUrls = {},
unarchiver = this,
store = this.determineStore(),
replaceUrl = function(link, url){
link.setAttribute("href", url);
link.onload = function(){
count--;
if(count <= 0) finished();
}
},
finished = function() {
if(callback) callback();
_.each(oldUrls, function(url){
store.revokeUrl(url);
});
unarchiver.urlCache = newUrls;
EPUBJS.Renderer.prototype.replace = function(query, func, finished, progress){
var items = this.doc.querySelectorAll(query),
resources = Array.prototype.slice.call(items),
count = resources.length,
after = function(result){
count--;
if(progress) progress(result, count);
if(count <= 0 && finished) finished(true);
};
if(!store) {
if(callback) callback();
return false;
if(count === 0) {
finished(false);
return;
}
srcs = this.doc.head.querySelectorAll('[href]');
resources = Array.prototype.slice.call(srcs);
count = resources.length;
if(!this.urlCache) this.urlCache = {};
oldUrls = _.clone(this.urlCache);
resources.forEach(function(link){
var src = link.getAttribute("href"),
full = this.book.settings.contentsPath + src;
if(full in oldUrls){
replaceUrl(link, oldUrls[full]);
newUrls[full] = oldUrls[full];
delete oldUrls[full];
}else{
//-- Handle replacing urls in CSS
if(link.getAttribute("rel") === "stylesheet") {
store.getText(full).then(function(text){
var url;
unarchiver.replaceUrlsInCss(full, text).then(function(newText){
var _URL = window.URL || window.webkitURL || window.mozURL;
var blob = new Blob([newText], { "type" : "text\/css" }),
url = _URL.createObjectURL(blob);
replaceUrl(link, url);
newUrls[full] = url;
}, function(e) {console.error(e)});
});
}else{
store.getUrl(full).then(function(url){
replaceUrl(link, url);
newUrls[full] = url;
});
}
}
resources.forEach(function(item){
func(item, after);
}.bind(this));
if(count === 0) finished();
}
EPUBJS.Renderer.prototype.replaceUrlsInCss = function(base, text){
var promise = new RSVP.Promise(),
promises = [],
store = this.determineStore(),
matches = text.match(/url\(\'?\"?([^\'|^\"]*)\'?\"?\)/g);
EPUBJS.Renderer.prototype.replaceWithStored = function(query, attr, func, callback) {
var _oldUrls,
_newUrls = {},
_store = this.determineStore(),
_cache = this.caches[query],
_contentsPath = this.book.settings.contentsPath,
_attr = attr,
progress = function(url, full, count) {
_newUrls[full] = url;
},
finished = function(notempty) {
if(!matches){
promise.resolve(text);
return promise;
}
if(callback) callback();
matches.forEach(function(str){
var full = EPUBJS.core.resolveUrl(base, str.replace(/url\(|[|\)|\'|\"]/g, ''));
replaced = store.getUrl(full).then(function(url){
text = text.replace(str, 'url("'+url+'")');
}, function(e) {console.error(e)} );
_.each(_oldUrls, function(url){
_store.revokeUrl(url);
});
promises.push(replaced);
});
_cache = _newUrls;
};
RSVP.all(promises).then(function(){
promise.resolve(text);
});
if(!_store) return;
return promise;
}
/*
//-- Replaces links in head, such as stylesheets
EPUBJS.Renderer.prototype.replaceCss = function(callback){
var styleSheets = this.doc.styleSheets,
store = this.determineStore(),
rules = [];
if(!_cache) _cache = {};
_oldUrls = _.clone(_cache);
_.each(styleSheets, function(sheet){
_.each(sheet.cssRules, function(rule, index){
if(rule.type == 5) {
//url("../fonts/STIXGeneral.otf")
// if()
var urlString = rule.cssText.match(/url\(\'?\"?([^\'|^\"]*)\'?\"?\)/),
full;
// rule.cssText = ""
// console.log(rule.style.src, rule.style[3])
// console.log(urlString)
this.replace(query, function(link, done){
if(urlString[1]){
full = "OPS/" + urlString[1].slice(3);
store.getUrl(full).then(function(url){
var newRule = rule.cssText.replace(/url\(\'?\"?([^\'|^\"]*)\'?\"?\)/, 'url("'+url+'")');
sheet.deleteRule(index)
sheet.insertRule(newRule, false);
});
var src = link.getAttribute(_attr),
full = EPUBJS.core.resolveUrl(_contentsPath, src),
replaceUrl = function(url) {
link.setAttribute(_attr, url);
link.onload = function(){
done(url, full);
}
}
});
});
};
if(full in _oldUrls){
replaceUrl(_oldUrls[full]);
_newUrls[full] = _oldUrls[full];
delete _oldUrls[full];
}else{
func(_store, full, replaceUrl, link);
}
}, finished, progress);
}
*/
//-- Replaces the relative links within the book to use our internal page changer
EPUBJS.Renderer.prototype.replaceLinks = function(callback){
var hrefs = this.doc.querySelectorAll('a'),
links = Array.prototype.slice.call(hrefs),
that = this;
links.forEach(function(link){
var path,
href = link.getAttribute("href"),
relative,
fragment;
var renderer = this;
if(!href) return;
this.replace("a[href]", function(link, done){
relative = href.search("://"),
fragment = href[0] == "#";
var href = link.getAttribute("href"),
relative = href.search("://"),
fragment = href[0] == "#";
if(relative != -1){
@ -2225,49 +2143,17 @@ EPUBJS.Renderer.prototype.replaceLinks = function(callback){
}else{
link.onclick = function(){
that.book.goto(href);
renderer.book.goto(href);
return false;
}
}
});
done();
}, callback);
if(callback) callback();
}
//-- Replaces assets src's to point to stored version if browser is offline
EPUBJS.Renderer.prototype.replaceResources = function(callback){
var srcs, resources, count;
var store = this.determineStore();
if(!store) {
if(callback) callback();
return false;
}
srcs = this.doc.querySelectorAll('[src]');
resources = Array.prototype.slice.call(srcs);
count = resources.length;
resources.forEach(function(link){
var src = link.getAttribute("src"),
full = this.book.settings.contentsPath + src;
store.getUrl(full).then(function(url){
// link.setAttribute("src", url);
link.src = url;
link.onload = function(){
count--;
if(count <= 0 && callback) callback();
}
});
}.bind(this));
if(count === 0) callback();
}
EPUBJS.Renderer.prototype.page = function(pg){
if(pg >= 1 && pg <= this.displayedPages){
@ -2432,6 +2318,101 @@ EPUBJS.Renderer.prototype.remove = function() {
//-- Enable binding events to parser
RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);
var EPUBJS = EPUBJS || {};
EPUBJS.replace = {};
EPUBJS.replace.head = function(callback, renderer) {
renderer.replaceWithStored("link[href]", "href", EPUBJS.replace.links, callback);
}
//-- Replaces assets src's to point to stored version if browser is offline
EPUBJS.replace.resources = function(callback, renderer){
//srcs = this.doc.querySelectorAll('[src]');
renderer.replaceWithStored("[src]", "src", EPUBJS.replace.srcs, callback);
}
EPUBJS.replace.svg = function(callback, renderer) {
renderer.replaceWithStored("image", "xlink:href", function(_store, full, done){
_store.getUrl(full).then(done);
}, callback);
}
EPUBJS.replace.srcs = function(_store, full, done){
_store.getUrl(full).then(done);
}
//-- Replaces links in head, such as stylesheets - link[href]
EPUBJS.replace.links = function(_store, full, done, link){
//-- Handle replacing urls in CSS
if(link.getAttribute("rel") === "stylesheet") {
EPUBJS.replace.stylesheets(_store, full).then(done);
}else{
_store.getUrl(full).then(done);
}
}
EPUBJS.replace.stylesheets = function(_store, full) {
var promise = new RSVP.Promise();
if(!_store) return;
_store.getText(full).then(function(text){
var url;
EPUBJS.replace.cssUrls(_store, full, text).then(function(newText){
var _URL = window.URL || window.webkitURL || window.mozURL;
var blob = new Blob([newText], { "type" : "text\/css" }),
url = _URL.createObjectURL(blob);
promise.resolve(url);
}, function(e) {console.error(e)});
});
return promise;
}
EPUBJS.replace.cssUrls = function(_store, base, text){
var promise = new RSVP.Promise(),
promises = [],
matches = text.match(/url\(\'?\"?([^\'|^\"]*)\'?\"?\)/g);
if(!_store) return;
if(!matches){
promise.resolve(text);
return promise;
}
matches.forEach(function(str){
var full = EPUBJS.core.resolveUrl(base, str.replace(/url\(|[|\)|\'|\"]/g, ''));
replaced = _store.getUrl(full).then(function(url){
text = text.replace(str, 'url("'+url+'")');
}, function(e) {console.error(e)} );
promises.push(replaced);
});
RSVP.all(promises).then(function(){
promise.resolve(text);
});
return promise;
}
EPUBJS.Unarchiver = function(url){

4
build/epub.min.js vendored

File diff suppressed because one or more lines are too long

4
demo/js/epub.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -32,12 +32,20 @@
<script src="../src/chapter.js"></script>
<script src="../src/renderer.js"></script>
<script src="../src/epubcfi.js"></script>
<script src="../src/replace.js"></script>
<!-- Hooks -->
<!-- <script src="../hooks/default/transculsions.js"></script> -->
<!-- <script src="../hooks/default/endnotes.js"></script> -->
<!-- <script src="../hooks/default/smartimages.js"></script> -->
<script>
EPUBJS.filePath = "../demo/js/libs/";
EPUBJS.cssPath = "../demo/css/";
</script>
<style type="text/css">
body {
@ -95,7 +103,7 @@
<script>
"use strict";
var Book = ePub("../demo/moby-dick/");
var Book = ePub("../demo/moby-dick/", {restore: true});
</script>
</head>
@ -110,6 +118,7 @@
Book.renderTo("area");
</script>
</body>
</html>

View file

@ -15,10 +15,17 @@
<!-- Zip JS -->
<script src="/demo/js/libs/zip.min.js"></script>
<script>
EPUBJS.filePath = "../demo/js/libs/";
EPUBJS.cssPath = "../demo/css/";
</script>
<script>
"use strict";
var Book = ePub("../demo/moby-dick/");
var Book = ePub("../demo/moby-dick.epub");
</script>
</head>

View file

@ -1,5 +1,6 @@
<!DOCTYPE html>
<html class="no-js">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus SVG 1.1//EN"
"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
@ -10,6 +11,11 @@
<!-- EPUBJS Renderer -->
<script src="../build/epub.min.js"></script>
<script>
var qs = document.querySelector;
document.querySelector = null;
document.querySelectorAll = null;
</script>
<script src="../hooks/extensions/hypothesis.js"></script>
<link rel="stylesheet" href="basic.css">

View file

@ -25,6 +25,7 @@
background: #6b6b6b;
}
}
epub-viewer {
width: 80%;
height: 80%;
@ -68,6 +69,28 @@
padding: 0 6px;
}
@media only screen and (min-width: 901px) and (max-width: 1040px) {
epub-viewer {
width: 50%;
margin-left: 25%;
}
}
@media only screen and (min-width: 551px) and (max-width: 900px) {
epub-viewer {
width: 60%;
margin-left: 20%;
}
}
@media only screen and (max-width: 550px) {
epub-viewer {
width: 80%;
margin-left: 10%;
}
}
</style>
<epub-sidebar id="sidebar"

View file

@ -67,7 +67,46 @@
margin: -33px 0 0 -33px;
}
@media only screen and (max-width: 1040px) {
#divider,
#divider.show {
display: none;
}
}
@media only screen and (min-width: 551px) and (max-width: 900px) {
#prev {
left: 20px;
}
#next {
right: 20px;
}
}
@media only screen and (max-width: 550px) {
#prev {
left: 0;
}
#next {
right: 0;
}
.arrow {
height: 100%;
top: 45px;
width: 10%;
text-indent: -10000px;
}
}
/* and (orientation : landscape) */
</style>
<div id="divider"></div>
@ -106,10 +145,10 @@
this.$.loader.style.display = "none";
},
bookDisplayed: function() {
this.$.divider.style.display = "block";
this.$.divider.classList.add('show');
},
bookUnloaded: function() {
this.$.divider.style.display = "none";
this.$.divider.classList.remove('show');
},
srcChanged: function() {

View file

@ -358,7 +358,8 @@ EPUBJS.Book.prototype.removeSavedContents = function() {
//-- Takes a string or a element
EPUBJS.Book.prototype.renderTo = function(elem){
var book = this;
var book = this,
rendered;
if(_.isElement(elem)) {
this.element = elem;
@ -369,12 +370,16 @@ EPUBJS.Book.prototype.renderTo = function(elem){
return;
}
return this.opened.
then(function(){
book.render = new EPUBJS.Renderer(book);
rendered = this.opened.
then(function(){
book.render = new EPUBJS.Renderer(book);
return book.startDisplay();
})
return book.startDisplay();
}, function(error) { console.error(error) });
rendered.then(null, function(error) { console.error(error) });
return rendered;
}
EPUBJS.Book.prototype.startDisplay = function(){
@ -698,7 +703,6 @@ EPUBJS.Book.prototype.triggerHooks = function(type, callback, passed){
hooks = this.hooks[type];
count = hooks.length;
function countdown(){
count--;
if(count <= 0 && callback) callback();

View file

@ -2,13 +2,8 @@ EPUBJS.Renderer = function(book) {
this.el = book.element;
this.book = book;
this.settings = book.settings;
book.registerHook("beforeChapterDisplay",
[this.replaceLinks.bind(this),
this.replaceResources.bind(this),
this.replaceHead.bind(this)], true);
// this.settings = book.settings;
this.caches = {};
this.crossBrowserColumnCss();
@ -30,8 +25,8 @@ EPUBJS.Renderer.prototype.initialize = function(){
this.iframe = document.createElement('iframe');
//this.iframe.id = "epubjs-iframe";
if(this.settings.width || this.settings.height){
this.resizeIframe(false, this.settings.width || this.el.clientWidth, this.settings.height || this.el.clientHeight);
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);
} else {
this.resizeIframe(false, this.el.clientWidth, this.el.clientHeight);
@ -51,6 +46,18 @@ EPUBJS.Renderer.prototype.listeners = function(){
// window.addEventListener("hashchange", book.route.bind(this), false);
this.book.registerHook("beforeChapterDisplay", this.replaceLinks.bind(this), true);
if(this.determineStore()) {
this.book.registerHook("beforeChapterDisplay", [
EPUBJS.replace.head,
EPUBJS.replace.resources,
EPUBJS.replace.svg
], true);
}
}
EPUBJS.Renderer.prototype.chapter = function(chapter){
@ -407,25 +414,6 @@ EPUBJS.Renderer.prototype.setLeft = function(leftPos){
this.doc.defaultView.scrollTo(leftPos, 0);
}
EPUBJS.Renderer.prototype.replace = function(query, func, callback){
var items, resources, count;
items = this.doc.querySelectorAll(query);
resources = Array.prototype.slice.call(items);
count = resources.length;
resources.forEach(function(item){
func(item, function(){
count--;
if(count <= 0 && callback) callback();
});
}.bind(this));
if(count === 0) callback();
}
EPUBJS.Renderer.prototype.determineStore = function(callback){
if(this.book.fromStorage) {
@ -447,164 +435,90 @@ EPUBJS.Renderer.prototype.determineStore = function(callback){
}
}
//-- Replaces links in head, such as stylesheets
EPUBJS.Renderer.prototype.replaceHead = function(callback){
var srcs, resources, count, oldUrls,
newUrls = {},
unarchiver = this,
store = this.determineStore(),
replaceUrl = function(link, url){
link.setAttribute("href", url);
link.onload = function(){
count--;
if(count <= 0) finished();
}
},
finished = function() {
if(callback) callback();
_.each(oldUrls, function(url){
store.revokeUrl(url);
});
unarchiver.urlCache = newUrls;
EPUBJS.Renderer.prototype.replace = function(query, func, finished, progress){
var items = this.doc.querySelectorAll(query),
resources = Array.prototype.slice.call(items),
count = resources.length,
after = function(result){
count--;
if(progress) progress(result, count);
if(count <= 0 && finished) finished(true);
};
if(!store) {
if(callback) callback();
return false;
if(count === 0) {
finished(false);
return;
}
srcs = this.doc.head.querySelectorAll('[href]');
resources = Array.prototype.slice.call(srcs);
count = resources.length;
if(!this.urlCache) this.urlCache = {};
oldUrls = _.clone(this.urlCache);
resources.forEach(function(link){
var src = link.getAttribute("href"),
full = this.book.settings.contentsPath + src;
if(full in oldUrls){
replaceUrl(link, oldUrls[full]);
newUrls[full] = oldUrls[full];
delete oldUrls[full];
}else{
//-- Handle replacing urls in CSS
if(link.getAttribute("rel") === "stylesheet") {
store.getText(full).then(function(text){
var url;
unarchiver.replaceUrlsInCss(full, text).then(function(newText){
var _URL = window.URL || window.webkitURL || window.mozURL;
var blob = new Blob([newText], { "type" : "text\/css" }),
url = _URL.createObjectURL(blob);
replaceUrl(link, url);
newUrls[full] = url;
}, function(e) {console.error(e)});
});
}else{
store.getUrl(full).then(function(url){
replaceUrl(link, url);
newUrls[full] = url;
});
}
}
resources.forEach(function(item){
func(item, after);
}.bind(this));
if(count === 0) finished();
}
EPUBJS.Renderer.prototype.replaceUrlsInCss = function(base, text){
var promise = new RSVP.Promise(),
promises = [],
store = this.determineStore(),
matches = text.match(/url\(\'?\"?([^\'|^\"]*)\'?\"?\)/g);
EPUBJS.Renderer.prototype.replaceWithStored = function(query, attr, func, callback) {
var _oldUrls,
_newUrls = {},
_store = this.determineStore(),
_cache = this.caches[query],
_contentsPath = this.book.settings.contentsPath,
_attr = attr,
progress = function(url, full, count) {
_newUrls[full] = url;
},
finished = function(notempty) {
if(!matches){
promise.resolve(text);
return promise;
}
if(callback) callback();
matches.forEach(function(str){
var full = EPUBJS.core.resolveUrl(base, str.replace(/url\(|[|\)|\'|\"]/g, ''));
replaced = store.getUrl(full).then(function(url){
text = text.replace(str, 'url("'+url+'")');
}, function(e) {console.error(e)} );
_.each(_oldUrls, function(url){
_store.revokeUrl(url);
});
promises.push(replaced);
});
_cache = _newUrls;
};
RSVP.all(promises).then(function(){
promise.resolve(text);
});
if(!_store) return;
return promise;
}
/*
//-- Replaces links in head, such as stylesheets
EPUBJS.Renderer.prototype.replaceCss = function(callback){
var styleSheets = this.doc.styleSheets,
store = this.determineStore(),
rules = [];
if(!_cache) _cache = {};
_oldUrls = _.clone(_cache);
_.each(styleSheets, function(sheet){
_.each(sheet.cssRules, function(rule, index){
if(rule.type == 5) {
//url("../fonts/STIXGeneral.otf")
// if()
var urlString = rule.cssText.match(/url\(\'?\"?([^\'|^\"]*)\'?\"?\)/),
full;
// rule.cssText = ""
// console.log(rule.style.src, rule.style[3])
// console.log(urlString)
this.replace(query, function(link, done){
if(urlString[1]){
full = "OPS/" + urlString[1].slice(3);
store.getUrl(full).then(function(url){
var newRule = rule.cssText.replace(/url\(\'?\"?([^\'|^\"]*)\'?\"?\)/, 'url("'+url+'")');
sheet.deleteRule(index)
sheet.insertRule(newRule, false);
});
var src = link.getAttribute(_attr),
full = EPUBJS.core.resolveUrl(_contentsPath, src),
replaceUrl = function(url) {
link.setAttribute(_attr, url);
link.onload = function(){
done(url, full);
}
}
});
});
};
if(full in _oldUrls){
replaceUrl(_oldUrls[full]);
_newUrls[full] = _oldUrls[full];
delete _oldUrls[full];
}else{
func(_store, full, replaceUrl, link);
}
}, finished, progress);
}
*/
//-- Replaces the relative links within the book to use our internal page changer
EPUBJS.Renderer.prototype.replaceLinks = function(callback){
var hrefs = this.doc.querySelectorAll('a'),
links = Array.prototype.slice.call(hrefs),
that = this;
links.forEach(function(link){
var path,
href = link.getAttribute("href"),
relative,
fragment;
var renderer = this;
if(!href) return;
this.replace("a[href]", function(link, done){
relative = href.search("://"),
fragment = href[0] == "#";
var href = link.getAttribute("href"),
relative = href.search("://"),
fragment = href[0] == "#";
if(relative != -1){
@ -613,49 +527,17 @@ EPUBJS.Renderer.prototype.replaceLinks = function(callback){
}else{
link.onclick = function(){
that.book.goto(href);
renderer.book.goto(href);
return false;
}
}
});
done();
}, callback);
if(callback) callback();
}
//-- Replaces assets src's to point to stored version if browser is offline
EPUBJS.Renderer.prototype.replaceResources = function(callback){
var srcs, resources, count;
var store = this.determineStore();
if(!store) {
if(callback) callback();
return false;
}
srcs = this.doc.querySelectorAll('[src]');
resources = Array.prototype.slice.call(srcs);
count = resources.length;
resources.forEach(function(link){
var src = link.getAttribute("src"),
full = this.book.settings.contentsPath + src;
store.getUrl(full).then(function(url){
// link.setAttribute("src", url);
link.src = url;
link.onload = function(){
count--;
if(count <= 0 && callback) callback();
}
});
}.bind(this));
if(count === 0) callback();
}
EPUBJS.Renderer.prototype.page = function(pg){
if(pg >= 1 && pg <= this.displayedPages){