mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
remove any uses of offsetLeft, cleaned up storage
This commit is contained in:
parent
7f41f00775
commit
5d7a15eabd
14 changed files with 102 additions and 72 deletions
5
dev.html
5
dev.html
|
@ -21,6 +21,7 @@
|
|||
document.onreadystatechange = function () {
|
||||
if (document.readyState == "complete") {
|
||||
FP.filePath = "/fpjs/";
|
||||
FP.VERSION = "0.1.5";
|
||||
FPR.app.init();
|
||||
}
|
||||
};
|
||||
|
@ -35,6 +36,7 @@
|
|||
<script src="fpjs/render/queue.js"></script>
|
||||
<script src="fpjs/render/unarchiver.js"></script>
|
||||
<script src="fpjs/render/storage.js"></script>
|
||||
<script src="fpjs/render/storage_none.js"></script>
|
||||
<script src="fpjs/render/storage_ram.js"></script>
|
||||
<script src="fpjs/render/storage_websql.js"></script>
|
||||
<script src="fpjs/render/storage_indexeddb.js"></script>
|
||||
|
@ -46,10 +48,11 @@
|
|||
|
||||
<!-- Plugins -->
|
||||
<script async src="fpjs/hooks/transculsions.js"></script>
|
||||
<script async src="fpjs/hooks/music.js"></script>
|
||||
<script async src="fpjs/hooks/endnotes.js"></script>
|
||||
<script async src="fpjs/hooks/smartimages.js"></script>
|
||||
|
||||
<!-- <script async src="fpjs/hooks/extras/music.js"></script> -->
|
||||
|
||||
<!-- Reader -->
|
||||
<script async src="fpjs/reader/utils.js"></script>
|
||||
<script async src="fpjs/reader/app.js"></script>
|
||||
|
|
4
dist/hooks/hooks.min.js
vendored
4
dist/hooks/hooks.min.js
vendored
|
@ -1,2 +1,2 @@
|
|||
/*! FuturePress - v0.1.0 - 2013-03-26 */
|
||||
FP.Hooks.register("beforeChapterDisplay").endnotes=function(e,t){var n=t.doc.querySelectorAll("a[href]"),r=Array.prototype.slice.call(n),i="epub:type",s="noteref",o={};FP.core.addCss("css/popup.css",!1,t.doc.head),r.forEach(function(e){function d(){var n,r=t.iframe.height,i=t.iframe.width,s,f,d=225;p||(f=a.cloneNode(!0),p=f.querySelector("p")),o[u]||(o[u]=document.createElement("div"),o[u].setAttribute("class","popup"),pop_content=document.createElement("div"),o[u].appendChild(pop_content),pop_content.appendChild(p),pop_content.setAttribute("class","pop_content"),t.bodyEl.appendChild(o[u]),o[u].addEventListener("mouseover",v,!1),o[u].addEventListener("mouseout",m,!1),t.book.listenUntil("book:pageChanged","book:chapterDestroy",g),t.book.listenUntil("book:pageChanged","book:chapterDestroy",m)),f=o[u],l=e.getBoundingClientRect(),c=l.left,h=l.top,f.classList.add("show"),f.style.left=c-f.offsetWidth/2+"px",f.style.top=h+"px",n=f.getBoundingClientRect(),d>r/2.5&&(d=r/2.5,pop_content.style.maxHeight=d+"px"),n.height+h>=r-25?(f.style.top=h-n.height+"px",f.classList.add("above")):f.classList.remove("above"),c-n.width<=0?(f.style.left=c+"px",f.classList.add("left")):f.classList.remove("left"),c+n.width/2>=i?(console.log("right"),f.style.left=c-300+"px",n=f.getBoundingClientRect(),f.style.left=c-n.width+"px",n.height+h>=r-25?(f.style.top=h-n.height+"px",f.classList.add("above")):f.classList.remove("above"),f.classList.add("right")):f.classList.remove("right")}function v(){o[u].classList.add("on")}function m(){o[u].classList.remove("on")}function g(){setTimeout(function(){o[u].classList.remove("show")},100)}var n=e.getAttribute(i),r,u,a,f,l,c,h,p;if(n!=s)return;r=e.getAttribute("href"),u=r.replace("#",""),a=t.doc.getElementById(u),e.addEventListener("mouseover",d,!1),e.addEventListener("mouseout",g,!1)}),e&&e()},FP.Hooks.register("beforeChapterDisplay").smartimages=function(e,t){var n=t.doc.querySelectorAll("img"),r=Array.prototype.slice.call(n),i=t.iframe.height,s;r.forEach(function(e){function n(){var n=e.offsetHeight,r=e.offsetTop;i=t.iframe.height,n+r>=i?r<i/2?e.style.maxHeight=i-r+"px":(e.style.maxHeight=(n<i?n:i)+"px",e.style.marginTop=i-r+"px"):(e.style.removeProperty("max-height"),e.style.removeProperty("margin-top"))}t.book.listenUntil("book:resized","book:chapterDestroy",n),n()}),e&&e()},FP.Hooks.register("beforeChapterDisplay").transculsions=function(e,t){var n=t.doc.querySelectorAll("[transclusion]"),r=Array.prototype.slice.call(n);r.forEach(function(e){function l(){u=i,a=s,u>t.colWidth&&(f=t.colWidth/u,u=t.colWidth,a*=f),r.width=u,r.height=a}var n=e.getAttribute("ref"),r=document.createElement("iframe"),i=e.getAttribute("width"),s=e.getAttribute("height"),o=e.parentNode,u=i,a=s,f;l(),t.book.listenUntil("book:resized","book:chapterDestroy",l),r.src=n,o.replaceChild(r,e)}),e&&e()};
|
||||
/*! FuturePress - v0.1.0 - 2013-03-27 */
|
||||
FP.Hooks.register("beforeChapterDisplay").endnotes=function(e,t){var n=t.doc.querySelectorAll("a[href]"),r=Array.prototype.slice.call(n),i="epub:type",s="noteref",o={};FP.core.addCss("css/popup.css",!1,t.doc.head),r.forEach(function(e){function d(){var n,r=t.iframe.height,i=t.iframe.width,s,f,d=225;p||(f=a.cloneNode(!0),p=f.querySelector("p")),o[u]||(o[u]=document.createElement("div"),o[u].setAttribute("class","popup"),pop_content=document.createElement("div"),o[u].appendChild(pop_content),pop_content.appendChild(p),pop_content.setAttribute("class","pop_content"),t.bodyEl.appendChild(o[u]),o[u].addEventListener("mouseover",v,!1),o[u].addEventListener("mouseout",m,!1),t.book.listenUntil("book:pageChanged","book:chapterDestroy",g),t.book.listenUntil("book:pageChanged","book:chapterDestroy",m)),f=o[u],itemRect=e.getBoundingClientRect(),c=l.left,h=l.top,f.classList.add("show"),f.style.left=c-itemRect.width/2+"px",f.style.top=h+"px",popRect=f.getBoundingClientRect(),d>r/2.5&&(d=r/2.5,pop_content.style.maxHeight=d+"px"),n.height+h>=r-25?(f.style.top=h-popRect.height+"px",f.classList.add("above")):f.classList.remove("above"),c-popRect.width<=0?(f.style.left=c+"px",f.classList.add("left")):f.classList.remove("left"),c+popRect.width/2>=i?(f.style.left=c-300+"px",popRect=f.getBoundingClientRect(),f.style.left=c-popRect.width+"px",popRect.height+h>=r-25?(f.style.top=h-popRect.height+"px",f.classList.add("above")):f.classList.remove("above"),f.classList.add("right")):f.classList.remove("right")}function v(){o[u].classList.add("on")}function m(){o[u].classList.remove("on")}function g(){setTimeout(function(){o[u].classList.remove("show")},100)}var n=e.getAttribute(i),r,u,a,f,l,c,h,p;if(n!=s)return;r=e.getAttribute("href"),u=r.replace("#",""),a=t.doc.getElementById(u),e.addEventListener("mouseover",d,!1),e.addEventListener("mouseout",g,!1)}),e&&e()},FP.Hooks.register("beforeChapterDisplay").smartimages=function(e,t){var n=t.doc.querySelectorAll("img"),r=Array.prototype.slice.call(n),i=t.iframe.height,s;r.forEach(function(e){function n(){var n=e.getBoundingClientRect(),r=n.height,s=n.top;i=t.iframe.height,r+s>=i?s<i/2?e.style.maxHeight=i-s+"px":(e.style.maxHeight=(r<i?r:i)+"px",e.style.marginTop=i-s+"px"):(e.style.removeProperty("max-height"),e.style.removeProperty("margin-top"))}t.book.listenUntil("book:resized","book:chapterDestroy",n),n()}),e&&e()},FP.Hooks.register("beforeChapterDisplay").transculsions=function(e,t){var n=t.doc.querySelectorAll("[transclusion]"),r=Array.prototype.slice.call(n);r.forEach(function(e){function l(){u=i,a=s,u>t.colWidth&&(f=t.colWidth/u,u=t.colWidth,a*=f),r.width=u,r.height=a}var n=e.getAttribute("ref"),r=document.createElement("iframe"),i=e.getAttribute("width"),s=e.getAttribute("height"),o=e.parentNode,u=i,a=s,f;l(),t.book.listenUntil("book:resized","book:chapterDestroy",l),r.src=n,o.replaceChild(r,e)}),e&&e()};
|
4
dist/reader.min.js
vendored
4
dist/reader.min.js
vendored
|
@ -1,2 +1,2 @@
|
|||
/*! FuturePress - v0.1.0 - 2013-03-26 */
|
||||
var FPR=FPR||{};FPR.app={},FPR.app.init=function(e){"use strict";function s(n){var s=window.location.search.match(/book=(.*)/),n=n||(s?s[1]:"moby-dick");FP.core.crossBrowserColumnCss(),i=e(window).width(),i>550?e("#main").width(i-r):e("#main").width(i),a(),t=new FP.Book("area"),t.listen("book:metadataReady",o),t.listen("book:tocReady",u),t.listen("book:bookReady",l),t.listen("book:chapterReady",p),t.listen("book:online",c),t.listen("book:offline",h),t.start(n),e(function(){d()})}function o(){var n=t.getTitle(),r=t.getCreator(),i=e("#book-title"),s=e("#chapter-title"),o=e("#title-seperator");document.title=n+" – "+r,i.html(n),s.html(r),o.show()}function u(){var n=t.getTOC(),r=e("#toc"),i,s;r.empty(),s=f(n,1),r.append(s),i=e(".toc_link"),i.on("click",function(n){var r=e(this),i=r.data("url");e(".openChapter").removeClass("openChapter"),r.parents("li").addClass("openChapter"),t.useHash||(t.show(i),n.preventDefault())})}function a(){var n="";localStorage.getItem("fontSize")?n=localStorage.getItem("fontSize"):(n="medium",localStorage.setItem("fontSize",n));var r=e("#settingsPanel");r.append("<ul></ul>");var i=e("<li><h3></h3></li>"),s=e("<input type='radio' name='fontSize' value='x-small'><span class='xsmall'>Extra Small</span><br><input type='radio' name='fontSize' value='small'><span class='small'>Small</span><br><input type='radio' name='fontSize' value='medium'><span class='medium'>Medium</span><br><input type='radio' name='fontSize' value='large'><span class='large'>Large</span><br><input type='radio' name='fontSize' value='x-large'><span class='xlarge'>Extra Large</span>");i.find("h3").text("Font Size").after(s),r.find("ul").append(i);var o=e('input[name="fontSize"]');o.each(function(){e(this).attr("value")==n&&e(this).attr("checked","checked"),e(this).on("click",function(){localStorage.setItem("fontSize",e(this).attr("value")),t.iframe.contentDocument.location.reload(!0)})})}function f(t,n){var r=e("<ul>"),i=n==1?"chapter":"section";return t.forEach(function(t){var s,o=e("<li id='toc-"+t.id+"'>"),u=e("<a class='toc_link "+i+"' href='#/"+t.href+"' data-url='"+t.href+"'>"+t.label+"</a>");o.append(u),t.subitems&&t.subitems.length&&(n++,s=f(t.subitems,n),o.append(s)),r.append(o)}),r}function l(){var n=e("#divider"),r=e("#loader");r.hide(),t.single||n.addClass("show")}function c(){var t=e("#store");n=!1,t.attr("src","img/save.png")}function h(){var t=e("#store");n=!0,t.attr("src","img/saved.png")}function p(t){var n=t.msg,r=e("#toc-"+n),i=e(".currentChapter");r.length&&(i.removeClass("currentChapter"),r.addClass("currentChapter"))}function d(){function y(){f.addClass("open"),u.addClass("closed"),c.attr("src","img/close.png")}function b(){a.css("pointer-events","visible"),f.removeClass("open"),u.removeClass("closed"),c.attr("src","img/menu-icon.png")}function w(){v.hide(),d.show()}function E(){d.hide(),v.show()}var s=e("#next"),o=e("#prev"),u=e("#main"),a=e("#area"),f=e("#sidebar"),l=e("#open"),c=l.find("img"),h=e("#network"),p=e("#setting"),d=e("#settingsPanel"),v=e("#toc"),m=e(window);m.on("resize",function(){i=e(window).width(),i>550?u.width(i-r):u.width(i)}),s.on("click",function(){t.nextPage()}),o.on("click",function(){t.prevPage()}),p.on("click",function(){d.is(":visible")?E():w()}),m.bind("touchy-swipe",function(e,n,r,i){(i.direction="left")&&t.nextPage(),(i.direction="right")&&t.prevPage()});var g=!1;e(document).keydown(function(e){if(g)return;if(e.keyCode==37)return o.trigger("click"),g=!0,setTimeout(function(){g=!1},100),!1;if(e.keyCode==39)return s.trigger("click"),g=!0,setTimeout(function(){g=!1},100),!1}),l.on("click",function(){f.hasClass("open")?b():y()}),h.on("click",function(){n=!n,t.fromStorage(n)})}var t,n=!1,r=0,i;return s}(jQuery),jQuery.fn.extend({clickOutside:function(e,t){var n=this;return jQuery(document).on("click.offer",function(r){if(t&&jQuery.inArray(r.target,t)>-1)return;if(jQuery.contains(n[0],r.target))return;jQuery(document).off("click.offer"),e(r,n)}),this}}),Modernizr.addTest("filesystem",function(){var e=Modernizr._domPrefixes;for(var t=-1,n=e.length;++t<n;)if(window[e[t]+"RequestFileSystem"])return!0;return"requestFileSystem"in window});
|
||||
/*! FuturePress - v0.1.0 - 2013-03-27 */
|
||||
var FPR=FPR||{};FPR.app={},FPR.app.init=function(e){"use strict";function s(n){var s=window.location.search.match(/book=(.*)/),n=n||(s?s[1]:"moby-dick");FP.core.crossBrowserColumnCss(),i=e(window).width(),i>550?e("#main").width(i-r):e("#main").width(i),a(),t=new FP.Book("area"),t.listen("book:metadataReady",o),t.listen("book:tocReady",u),t.listen("book:bookReady",l),t.listen("book:chapterReady",p),t.listen("book:online",c),t.listen("book:offline",h),t.start(n),e(function(){d()})}function o(){var n=t.getTitle(),r=t.getCreator(),i=e("#book-title"),s=e("#chapter-title"),o=e("#title-seperator");document.title=n+" – "+r,i.html(n),s.html(r),o.show()}function u(){var n=t.getTOC(),r=e("#toc"),i,s;r.empty(),s=f(n,1),r.append(s),i=e(".toc_link"),i.on("click",function(n){var r=e(this),i=r.data("url");e(".openChapter").removeClass("openChapter"),r.parents("li").addClass("openChapter"),t.useHash||(t.show(i),n.preventDefault())})}function a(){var n="";localStorage.getItem("fontSize")?n=localStorage.getItem("fontSize"):(n="medium",localStorage.setItem("fontSize",n));var r=e("#settingsPanel");r.append("<ul></ul>");var i=e("<li><h3></h3></li>"),s=e("<input type='radio' name='fontSize' value='x-small'><span class='xsmall'>Extra Small</span><br><input type='radio' name='fontSize' value='small'><span class='small'>Small</span><br><input type='radio' name='fontSize' value='medium'><span class='medium'>Medium</span><br><input type='radio' name='fontSize' value='large'><span class='large'>Large</span><br><input type='radio' name='fontSize' value='x-large'><span class='xlarge'>Extra Large</span>");i.find("h3").text("Font Size").after(s),r.find("ul").append(i);var o=e('input[name="fontSize"]');o.each(function(){e(this).attr("value")==n&&e(this).attr("checked","checked"),e(this).on("click",function(){localStorage.setItem("fontSize",e(this).attr("value")),t.iframe.contentDocument.location.reload(!0)})})}function f(t,n){var r=e("<ul>"),i=n==1?"chapter":"section";return t.forEach(function(t){var s,o=e("<li id='toc-"+t.id+"'>"),u=e("<a class='toc_link "+i+"' href='#/"+t.href+"' data-url='"+t.href+"'>"+t.label+"</a>");o.append(u),t.subitems&&t.subitems.length&&(n++,s=f(t.subitems,n),o.append(s)),r.append(o)}),r}function l(){var n=e("#divider"),r=e("#loader");r.hide(),t.single||n.addClass("show")}function c(){var t=e("#store");n=!1,t.attr("src","img/save.png")}function h(){var t=e("#store");n=!0,t.attr("src","img/saved.png")}function p(t){var n=t.msg,r=e("#toc-"+n),i=e(".currentChapter");r.length&&(i.removeClass("currentChapter"),r.addClass("currentChapter"))}function d(){function y(){f.addClass("open"),u.addClass("closed"),c.attr("src","img/close.png")}function b(){a.css("pointer-events","visible"),f.removeClass("open"),u.removeClass("closed"),c.attr("src","img/menu-icon.png")}function w(){v.hide(),d.show()}function E(){d.hide(),v.show()}var s=e("#next"),o=e("#prev"),u=e("#main"),a=e("#area"),f=e("#sidebar"),l=e("#open"),c=l.find("img"),h=e("#network"),p=e("#setting"),d=e("#settingsPanel"),v=e("#toc"),m=e(window);m.on("resize",function(){i=e(window).width(),i>550?u.width(i-r):u.width(i)}),s.on("click",function(){t.nextPage()}),o.on("click",function(){t.prevPage()}),p.on("click",function(){d.is(":visible")?E():w()}),m.bind("touchy-swipe",function(e,n,r,i){(i.direction="left")&&t.nextPage(),(i.direction="right")&&t.prevPage()});var g=!1;e(document).keydown(function(e){if(g)return;if(e.keyCode==37)return o.trigger("click"),g=!0,setTimeout(function(){g=!1},100),!1;if(e.keyCode==39)return s.trigger("click"),g=!0,setTimeout(function(){g=!1},100),!1}),l.on("click",function(){f.hasClass("open")?b():y()}),h.on("click",function(){n=!n,t.fromStorage(n)})}var t,n=!1,r=0,i;return s}(jQuery),jQuery.fn.extend({clickOutside:function(e,t){var n=this;return jQuery(document).on("click.offer",function(r){if(t&&jQuery.inArray(r.target,t)>-1)return;if(jQuery.contains(n[0],r.target))return;jQuery(document).off("click.offer"),e(r,n)}),this}});
|
4
dist/render.min.js
vendored
4
dist/render.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/workers/loader_filesystem.js
vendored
2
dist/workers/loader_filesystem.js
vendored
|
@ -1,2 +1,2 @@
|
|||
/*! FuturePress - v0.1.0 - 2013-03-26 */
|
||||
/*! FuturePress - v0.1.0 - 2013-03-27 */
|
||||
;
|
|
@ -72,7 +72,7 @@ FP.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chapter)
|
|||
|
||||
|
||||
//-- get location of item
|
||||
pos = item.getBoundingClientRect();
|
||||
itemRect = item.getBoundingClientRect();
|
||||
left = pos.left;
|
||||
top = pos.top;
|
||||
|
||||
|
@ -80,11 +80,11 @@ FP.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chapter)
|
|||
pop.classList.add("show");
|
||||
|
||||
//-- position the popup
|
||||
pop.style.left = left - pop.offsetWidth / 2 + "px";
|
||||
pop.style.left = left - itemRect.width / 2 + "px";
|
||||
pop.style.top = top + "px";
|
||||
|
||||
//-- checking to keep within current column
|
||||
poppos = pop.getBoundingClientRect();
|
||||
popRect = pop.getBoundingClientRect();
|
||||
|
||||
//-- Adjust max height
|
||||
if(maxHeight > iheight / 2.5) {
|
||||
|
@ -94,14 +94,14 @@ FP.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chapter)
|
|||
|
||||
//-- switch above / below
|
||||
if(poppos.height + top >= iheight - 25) {
|
||||
pop.style.top = top - poppos.height + "px";
|
||||
pop.style.top = top - popRect.height + "px";
|
||||
pop.classList.add("above");
|
||||
}else{
|
||||
pop.classList.remove("above");
|
||||
}
|
||||
|
||||
//-- switch left
|
||||
if(left - poppos.width <= 0) {
|
||||
if(left - popRect.width <= 0) {
|
||||
pop.style.left = left + "px";
|
||||
pop.classList.add("left");
|
||||
}else{
|
||||
|
@ -109,16 +109,15 @@ FP.Hooks.register("beforeChapterDisplay").endnotes = function(callback, chapter)
|
|||
}
|
||||
|
||||
//-- switch right
|
||||
if(left + poppos.width / 2 >= iwidth) {
|
||||
console.log("right")
|
||||
if(left + popRect.width / 2 >= iwidth) {
|
||||
//-- TEMP MOVE: 300
|
||||
pop.style.left = left - 300 + "px";
|
||||
|
||||
poppos = pop.getBoundingClientRect();
|
||||
pop.style.left = left - poppos.width + "px";
|
||||
popRect = pop.getBoundingClientRect();
|
||||
pop.style.left = left - popRect.width + "px";
|
||||
//-- switch above / below again
|
||||
if(poppos.height + top >= iheight - 25) {
|
||||
pop.style.top = top - poppos.height + "px";
|
||||
if(popRect.height + top >= iheight - 25) {
|
||||
pop.style.top = top - popRect.height + "px";
|
||||
pop.classList.add("above");
|
||||
}else{
|
||||
pop.classList.remove("above");
|
||||
|
|
|
@ -8,8 +8,9 @@ FP.Hooks.register("beforeChapterDisplay").smartimages = function(callback, chapt
|
|||
items.forEach(function(item){
|
||||
|
||||
function size() {
|
||||
var height = item.offsetHeight,
|
||||
top = item.offsetTop;
|
||||
var itemRect = item.getBoundingClientRect(),
|
||||
height = itemRect.height,
|
||||
top = itemRect.top;
|
||||
|
||||
iheight = chapter.iframe.height;
|
||||
|
||||
|
|
|
@ -19,15 +19,3 @@ jQuery.fn.extend({
|
|||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
Modernizr.addTest('filesystem', function(){
|
||||
|
||||
var prefixes = Modernizr._domPrefixes;
|
||||
|
||||
for ( var i = -1, len = prefixes.length; ++i < len; ){
|
||||
if ( window[prefixes[i] + 'RequestFileSystem'] ) return true;
|
||||
}
|
||||
return 'requestFileSystem' in window;
|
||||
|
||||
});
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
var FP = FP || {};
|
||||
FP.VERSION = "0.1.4";
|
||||
FP.VERSION = "0.1.5";
|
||||
|
||||
FP.plugins = FP.plugins || {};
|
||||
|
||||
|
|
|
@ -39,8 +39,10 @@ FP.Book = function(elem, bookPath){
|
|||
this.listeners();
|
||||
|
||||
//-- Determine storage method
|
||||
//-- Override options: none | ram | websql | indexedDB | filesystem
|
||||
this.determineStorageMethod();
|
||||
//-- Override options: none | ram | websqldatabase | indexeddb | filesystem
|
||||
//FP.storageOverride = "none"
|
||||
|
||||
FP.storage.determineStorageMethod(FP.storageOverride);
|
||||
|
||||
// BookUrl is optional, but if present start loading process
|
||||
if(bookPath) {
|
||||
|
@ -682,20 +684,6 @@ FP.Book.prototype.fromStorage = function(stored) {
|
|||
|
||||
}
|
||||
|
||||
FP.Book.prototype.determineStorageMethod = function(override) {
|
||||
var method = 'ram';
|
||||
|
||||
if(override){
|
||||
method = override;
|
||||
}else{
|
||||
if (Modernizr.websqldatabase) { method = "websql" }
|
||||
if (Modernizr.indexeddb) { method = "indexedDB" }
|
||||
if (Modernizr.filesystem) { method = "filesystem" }
|
||||
}
|
||||
|
||||
FP.storage.storageMethod(method);
|
||||
}
|
||||
|
||||
FP.Book.prototype.route = function(hash, callback){
|
||||
var location = window.location.hash.replace('#/', '');
|
||||
if(this.useHash && location.length && location != this.prevLocation){
|
||||
|
|
|
@ -303,11 +303,9 @@ FP.Chapter.prototype.section = function(fragment){
|
|||
var el = this.doc.getElementById(fragment),
|
||||
left, pg;
|
||||
|
||||
|
||||
if(el){
|
||||
left = this.leftPos + el.offsetLeft, //-- Calculate left offset compaired to scrolled position
|
||||
left = this.leftPos + el.getBoundingClientRect().left, //-- Calculate left offset compaired to scrolled position
|
||||
pg = Math.floor(left / this.spreadWidth) + 1; //-- pages start at 1
|
||||
|
||||
this.page(pg);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,42 +1,67 @@
|
|||
FP.storage = function(){
|
||||
|
||||
this._URL = window.URL;
|
||||
|
||||
var _supported = {},
|
||||
_storageType,
|
||||
_store;
|
||||
|
||||
|
||||
function storageMethod(storageType){
|
||||
console.log("storageMethod", storageType)
|
||||
|
||||
//-- Pick store type
|
||||
if(!storageType || typeof(FP.store[storageType]) == "undefined"){
|
||||
this.storageType = "none";
|
||||
if( !storageType || typeof(FP.store[storageType]) == "undefined"){
|
||||
_storageType = "none";
|
||||
}else{
|
||||
this.storageType = storageType;
|
||||
_storageType = storageType;
|
||||
}
|
||||
|
||||
//-- Create a new store of that type
|
||||
this._store = new FP.store[this.storageType];
|
||||
_store = new FP.store[_storageType];
|
||||
|
||||
//-- Handle load errors
|
||||
this._store.failed = _error;
|
||||
_store.failed = _error;
|
||||
|
||||
}
|
||||
|
||||
function determineStorageMethod(override) {
|
||||
var methods = ["filesystem", "indexeddb", "websqldatabase", "ram"],
|
||||
method = 'none';
|
||||
|
||||
checkSupport();
|
||||
|
||||
if(override && (override == "none" || _supported[override])){
|
||||
method = override;
|
||||
}else{
|
||||
for ( var i = -1, len = methods.length; ++i < len; ){
|
||||
if ( _supported[methods[i]] ) {
|
||||
method = methods[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
storageMethod(method);
|
||||
}
|
||||
|
||||
function get(path, callback) {
|
||||
return this._store.get(path, callback);
|
||||
return _store.get(path, callback);
|
||||
}
|
||||
|
||||
function preload(path, callback) {
|
||||
return this._store.preload(path, callback);
|
||||
return _store.preload(path, callback);
|
||||
}
|
||||
|
||||
function batch(group, callback) {
|
||||
return this._store.batch(group, callback);
|
||||
return _store.batch(group, callback);
|
||||
}
|
||||
|
||||
function getURL(path) {
|
||||
return this._store.getURL(path);
|
||||
return _store.getURL(path);
|
||||
}
|
||||
|
||||
function save(path, file, callback) {
|
||||
return this._store.save(path, file, callback);
|
||||
return _store.save(path, file, callback);
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,7 +70,32 @@ FP.storage = function(){
|
|||
}
|
||||
|
||||
function getStorageType(){
|
||||
return this.storageType;
|
||||
return _storageType;
|
||||
}
|
||||
|
||||
function checkSupport() {
|
||||
var support = "filesystem indexeddb websqldatabase ram".split(' '),
|
||||
toTest = "RequestFileSystem IndexedDB openDatabase URL".split(' ');
|
||||
|
||||
for ( var t = -1, len = support.length; ++t < len; ){
|
||||
|
||||
var test = support[t],
|
||||
method = toTest[t];
|
||||
|
||||
_supported[test] = testSupport(method);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function testSupport(method) {
|
||||
prefixes = ['webkit', 'moz', 'o', 'ms'];
|
||||
|
||||
for ( var i = -1, len = prefixes.length; ++i < len; ){
|
||||
if ( window[prefixes[i] + method] ) return true;
|
||||
}
|
||||
return method in window;
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -55,7 +105,8 @@ FP.storage = function(){
|
|||
"storageMethod": storageMethod,
|
||||
"getURL": getURL,
|
||||
"save" : save,
|
||||
"getStorageType" : getStorageType
|
||||
"getStorageType" : getStorageType,
|
||||
"determineStorageMethod": determineStorageMethod
|
||||
}
|
||||
|
||||
}();
|
|
@ -3,7 +3,8 @@ FP.store = FP.store || {};
|
|||
FP.store.ram = function() {
|
||||
var _store = {},
|
||||
_blobs = {},
|
||||
_queue = new FP.Queue(loader, 6);
|
||||
_queue = new FP.Queue(loader, 6),
|
||||
_URL = window.URL;
|
||||
//-- max of 6 concurrent requests: http://www.browserscope.org/?category=network
|
||||
|
||||
|
||||
|
@ -94,7 +95,7 @@ FP.store.ram = function() {
|
|||
return _blobs[path];
|
||||
}
|
||||
|
||||
url = this._URL.createObjectURL(file);
|
||||
url = _URL.createObjectURL(file);
|
||||
|
||||
//-- need to revokeObjectURL previous urls, but only when cleaning cache
|
||||
// this.createdURLs.forEach(function(url){
|
||||
|
|
|
@ -3,7 +3,8 @@ FP.store = FP.store || {};
|
|||
FP.store.websql = function() {
|
||||
var _blobs = {},
|
||||
_queue = new FP.Queue(loader, 6),
|
||||
_db;
|
||||
_db,
|
||||
_URL = window.URL;
|
||||
|
||||
const DBNAME = "fpjs_db";
|
||||
const DBVERSION = "1";
|
||||
|
@ -176,7 +177,7 @@ FP.store.websql = function() {
|
|||
}
|
||||
|
||||
blob = FP.core.dataURLToBlob(file); //go from data url to blob
|
||||
url = this._URL.createObjectURL(blob);
|
||||
url = _URL.createObjectURL(blob);
|
||||
|
||||
//-- need to revokeObjectURL previous urls, but only when cleaning cache
|
||||
// this.createdURLs.forEach(function(url){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue