mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
added fileStore
This commit is contained in:
parent
5d7a15eabd
commit
2d81246827
25 changed files with 29 additions and 1399 deletions
|
@ -73,7 +73,7 @@ The eBook reader uses persistence to cache the files from an epub for offline vi
|
||||||
|
|
||||||
Currently, there is not a great cross browser solution for dynamic file storage. Chrome supports the Filesystem API, Firefox/IE support indexedDB, and Safari/Safari Mobile support Web SQL.
|
Currently, there is not a great cross browser solution for dynamic file storage. Chrome supports the Filesystem API, Firefox/IE support indexedDB, and Safari/Safari Mobile support Web SQL.
|
||||||
|
|
||||||
The reader detects the storage capabilities of the browser and picks the best available option. When internet is available, the entire book is loaded into storage. When possible, Web Workers is used to handle loading and saving the files in a different thread, so as not to interfere with the reading experience.
|
The reader detects the storage capabilities of the browser and picks the best available option. When internet is available, the entire book is loaded into storage. When possible, Web Workers is used to handle loading and saving the files, so as not to interfere with the reading experience.
|
||||||
|
|
||||||
The browser tells the reader when there is Internet connectivity, and by listening to those events, it automatically switches to using the stored files. Users can also manually switch to offline mode in the interface.
|
The browser tells the reader when there is Internet connectivity, and by listening to those events, it automatically switches to using the stored files. Users can also manually switch to offline mode in the interface.
|
||||||
|
|
||||||
|
|
11
dev.html
11
dev.html
|
@ -21,6 +21,8 @@
|
||||||
document.onreadystatechange = function () {
|
document.onreadystatechange = function () {
|
||||||
if (document.readyState == "complete") {
|
if (document.readyState == "complete") {
|
||||||
FP.filePath = "/fpjs/";
|
FP.filePath = "/fpjs/";
|
||||||
|
fileStorage.filePath = FP.filePath + "libs/";
|
||||||
|
|
||||||
FP.VERSION = "0.1.5";
|
FP.VERSION = "0.1.5";
|
||||||
FPR.app.init();
|
FPR.app.init();
|
||||||
}
|
}
|
||||||
|
@ -33,14 +35,9 @@
|
||||||
<!-- Render -->
|
<!-- Render -->
|
||||||
<script src="fpjs/render/base.js"></script>
|
<script src="fpjs/render/base.js"></script>
|
||||||
<script src="fpjs/render/core.js"></script>
|
<script src="fpjs/render/core.js"></script>
|
||||||
<script src="fpjs/render/queue.js"></script>
|
|
||||||
<script src="fpjs/render/unarchiver.js"></script>
|
<script src="fpjs/render/unarchiver.js"></script>
|
||||||
<script src="fpjs/render/storage.js"></script>
|
<script src="fpjs/libs/fileStorage.min.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>
|
|
||||||
<script src="fpjs/render/storage_filesystem.js"></script>
|
|
||||||
<script src="fpjs/render/events.js"></script>
|
<script src="fpjs/render/events.js"></script>
|
||||||
<script src="fpjs/render/hooks.js"></script>
|
<script src="fpjs/render/hooks.js"></script>
|
||||||
<script src="fpjs/render/book.js"></script>
|
<script src="fpjs/render/book.js"></script>
|
||||||
|
|
BIN
dist/.DS_Store
vendored
BIN
dist/.DS_Store
vendored
Binary file not shown.
2
dist/hooks/hooks.min.js
vendored
2
dist/hooks/hooks.min.js
vendored
|
@ -1,2 +1,2 @@
|
||||||
/*! FuturePress - v0.1.0 - 2013-03-27 */
|
/*! FuturePress - v0.1.0 - 2013-03-28 */
|
||||||
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()};
|
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()};
|
1
dist/libs/fileStorage.min.js
vendored
Normal file
1
dist/libs/fileStorage.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/libs/loader_filesystem.js
vendored
Normal file
1
dist/libs/loader_filesystem.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
var fileStorage=fileStorage||{},_requestFileSystem=self.requestFileSystem||self.webkitRequestFileSystem;const DBSIZE=5242880,DBTYPE=TEMPORARY;self.onmessage=function(e){var t=e.data;self.request(t,function(e){self.save(t,e,function(){self.postMessage(t)})})},self.openFs=function(e){if(self._fs){e&&e(self._fs);return}_requestFileSystem(DBTYPE,DBSIZE,function(t){self._fs=t,e&&e(t)},self.failure)},self.request=function(e,t){var n=new self.loadFile(e);n.succeeded=function(e){t&&t(e)},n.failed=function(e){self.postMessage("failed: "+e.toString())},n.start()},self.save=function(e,t,n){self.openFs(function(r){var i=e.split("/").slice(0,-1);self.createDir(r.root,i),r.root.getFile(e,{create:!0},function(r){r.createWriter(function(r){r.onwriteend=function(e){n(e)},r.onerror=function(t){self.postMessage("write error:"+self.errorHandler(err)+" path="+e)},r.write(t)})},self.failure)})},self.createDir=function(e,t){if(t[0]=="."||t[0]=="")t=t.slice(1);e.getDirectory(t[0],{create:!0},function(e){t.length&&createDir(e,t.slice(1))},self.failure)},self.failure=function(e){self.postMessage("failed: "+self.errorHandler(e))},self.errorHandler=function(e){switch(e.code){case FileError.QUOTA_EXCEEDED_ERR:return"QUOTA_EXCEEDED_ERR";case FileError.NOT_FOUND_ERR:return"NOT_FOUND_ERR";case FileError.SECURITY_ERR:return"SECURITY_ERR";case FileError.INVALID_MODIFICATION_ERR:return"INVALID_MODIFICATION_ERR";case FileError.INVALID_STATE_ERR:return"INVALID_STATE_ERR";default:return"Unknown Error"}},self.loadFile=function(e,t){var n=new XMLHttpRequest;return this.succeeded=function(e){t&&t(e)},this.failed=function(e){console.log("Error:",e)},this.start=function(){var t=this;n.open("GET",e,!0),n.responseType="blob",n.onload=function(e){this.status==200&&t.succeeded(this.response)},n.onerror=function(e){t.failed(this.status)},n.send()},{start:this.start,succeeded:this.succeeded,failed:this.failed}},self.openFs();
|
2
dist/reader.min.js
vendored
2
dist/reader.min.js
vendored
|
@ -1,2 +1,2 @@
|
||||||
/*! FuturePress - v0.1.0 - 2013-03-27 */
|
/*! FuturePress - v0.1.0 - 2013-03-28 */
|
||||||
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}});
|
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 +0,0 @@
|
||||||
/*! FuturePress - v0.1.0 - 2013-03-27 */
|
|
||||||
;
|
|
BIN
fpjs/.DS_Store
vendored
BIN
fpjs/.DS_Store
vendored
Binary file not shown.
2
fpjs/libs/fileStorage.min.js
vendored
Normal file
2
fpjs/libs/fileStorage.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
fpjs/libs/loader_filesystem.js
Normal file
2
fpjs/libs/loader_filesystem.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/*! fileStorage - v0.1.0 - 2013-03-28 */var fileStorage = fileStorage || {};
|
||||||
|
var _requestFileSystem=self.requestFileSystem||self.webkitRequestFileSystem;const DBSIZE=5242880,DBTYPE=TEMPORARY;self.onmessage=function(e){var t=e.data;self.request(t,function(e){self.save(t,e,function(){self.postMessage(t)})})},self.openFs=function(e){if(self._fs){e&&e(self._fs);return}_requestFileSystem(DBTYPE,DBSIZE,function(t){self._fs=t,e&&e(t)},self.failure)},self.request=function(e,t){var n=new self.loadFile(e);n.succeeded=function(e){t&&t(e)},n.failed=function(e){self.postMessage("failed: "+e.toString())},n.start()},self.save=function(e,t,n){self.openFs(function(r){var i=e.split("/").slice(0,-1);self.createDir(r.root,i),r.root.getFile(e,{create:!0},function(r){r.createWriter(function(r){r.onwriteend=function(e){n(e)},r.onerror=function(t){self.postMessage("write error:"+self.errorHandler(err)+" path="+e)},r.write(t)})},self.failure)})},self.createDir=function(e,t){if(t[0]=="."||t[0]=="")t=t.slice(1);e.getDirectory(t[0],{create:!0},function(e){t.length&&createDir(e,t.slice(1))},self.failure)},self.failure=function(e){self.postMessage("failed: "+self.errorHandler(e))},self.errorHandler=function(e){switch(e.code){case FileError.QUOTA_EXCEEDED_ERR:return"QUOTA_EXCEEDED_ERR";case FileError.NOT_FOUND_ERR:return"NOT_FOUND_ERR";case FileError.SECURITY_ERR:return"SECURITY_ERR";case FileError.INVALID_MODIFICATION_ERR:return"INVALID_MODIFICATION_ERR";case FileError.INVALID_STATE_ERR:return"INVALID_STATE_ERR";default:return"Unknown Error"}},self.loadFile=function(e,t){var n=new XMLHttpRequest;return this.succeeded=function(e){t&&t(e)},this.failed=function(e){console.log("Error:",e)},this.start=function(){var t=this;n.open("GET",e,!0),n.responseType="blob",n.onload=function(e){this.status==200&&t.succeeded(this.response)},n.onerror=function(e){t.failed(this.status)},n.send()},{start:this.start,succeeded:this.succeeded,failed:this.failed}},self.openFs();
|
|
@ -41,8 +41,7 @@ FP.Book = function(elem, bookPath){
|
||||||
//-- Determine storage method
|
//-- Determine storage method
|
||||||
//-- Override options: none | ram | websqldatabase | indexeddb | filesystem
|
//-- Override options: none | ram | websqldatabase | indexeddb | filesystem
|
||||||
//FP.storageOverride = "none"
|
//FP.storageOverride = "none"
|
||||||
|
FP.storage = new fileStorage.storage(FP.storageOverride);
|
||||||
FP.storage.determineStorageMethod(FP.storageOverride);
|
|
||||||
|
|
||||||
// BookUrl is optional, but if present start loading process
|
// BookUrl is optional, but if present start loading process
|
||||||
if(bookPath) {
|
if(bookPath) {
|
||||||
|
|
|
@ -105,10 +105,13 @@ FP.Chapter.prototype.formatSpread = function(){
|
||||||
this.spread = true; //-- Double Page
|
this.spread = true; //-- Double Page
|
||||||
|
|
||||||
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
|
||||||
//-- 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;
|
||||||
|
@ -132,9 +135,7 @@ FP.Chapter.prototype.formatSpread = function(){
|
||||||
|
|
||||||
//-- Go to current page after resize
|
//-- Go to current page after resize
|
||||||
if(this.OldcolWidth){
|
if(this.OldcolWidth){
|
||||||
this.leftPos = (this.chapterPos - 1 ) * this.spreadWidth;
|
this.setLeft((this.chapterPos - 1 ) * this.spreadWidth);
|
||||||
this.bodyEl.scrollLeft = this.leftPos;
|
|
||||||
//this.visible(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,167 +0,0 @@
|
||||||
FP.Queue = function(worker, concurrency){
|
|
||||||
this._q = [];
|
|
||||||
this._tasks = {};
|
|
||||||
this.idCount = 0;
|
|
||||||
this.concurrency = 0;
|
|
||||||
|
|
||||||
this.workers = [];
|
|
||||||
this.available = [];
|
|
||||||
|
|
||||||
if(typeof(worker) === "string") {
|
|
||||||
this.workerStr = worker;
|
|
||||||
this.addWorkers(concurrency || 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(typeof(worker) === "function") {
|
|
||||||
this.workerFunction = worker;
|
|
||||||
this.addFakeWorkers(concurrency || 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
FP.Queue.prototype.addWorkers = function(concurrency){
|
|
||||||
var min = this.concurrency,
|
|
||||||
max = min + concurrency;
|
|
||||||
|
|
||||||
//-- Stop running jobs or something?
|
|
||||||
|
|
||||||
for(var i=min; i < concurrency; i++){
|
|
||||||
var worker = new Worker(this.workerStr);
|
|
||||||
this.workers.push(worker); //-- Add new work
|
|
||||||
this.available.push(i); //-- Make available to start tasks
|
|
||||||
}
|
|
||||||
|
|
||||||
this.concurrency = concurrency;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
FP.Queue.prototype.addFakeWorkers = function(concurrency){
|
|
||||||
var min = this.concurrency,
|
|
||||||
max = min + concurrency;
|
|
||||||
|
|
||||||
//-- Stop running jobs or something?
|
|
||||||
|
|
||||||
for(var i=min; i < concurrency; i++){
|
|
||||||
var worker = new FP.FakeWorker(this.workerFunction);
|
|
||||||
this.workers.push(worker); //-- Add new work
|
|
||||||
this.available.push(i); //-- Make available to start tasks
|
|
||||||
}
|
|
||||||
|
|
||||||
this.concurrency = concurrency;
|
|
||||||
}
|
|
||||||
|
|
||||||
FP.Queue.prototype.add = function(msg, callback, priority){
|
|
||||||
var ID = this.idCount;
|
|
||||||
//-- Add to task object : maybe check for dups
|
|
||||||
this._tasks[ID] = {
|
|
||||||
"msg": msg,
|
|
||||||
"callback": callback || function(){}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- Add id to queue
|
|
||||||
if(!priority){
|
|
||||||
this._q.push(ID);
|
|
||||||
}else{
|
|
||||||
this._q.unshift(ID);
|
|
||||||
if(!this.running) this.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- Increment ID for next task
|
|
||||||
this.idCount++;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
FP.Queue.prototype.addGroup = function(group, callback){
|
|
||||||
var that = this,
|
|
||||||
counter = group.length,
|
|
||||||
after = function(){
|
|
||||||
counter--;
|
|
||||||
if(counter <= 0) callback();
|
|
||||||
};
|
|
||||||
|
|
||||||
group.forEach(function(msg){
|
|
||||||
that.add(msg, after);
|
|
||||||
});
|
|
||||||
|
|
||||||
if(!this.running) this.run();
|
|
||||||
|
|
||||||
return after;
|
|
||||||
}
|
|
||||||
|
|
||||||
FP.Queue.prototype.run = function(id){
|
|
||||||
if(this.running) return;
|
|
||||||
this.running = true;
|
|
||||||
|
|
||||||
while(this.available.length) {
|
|
||||||
var next = this.next();
|
|
||||||
if(!next) break; //-- no tasks left or error
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
FP.Queue.prototype.find = function(msg){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
FP.Queue.prototype.next = function(){
|
|
||||||
var that = this,
|
|
||||||
curr = this._q.shift(),
|
|
||||||
task,
|
|
||||||
workerID,
|
|
||||||
worker;
|
|
||||||
|
|
||||||
if(typeof(curr) === "undefined"){
|
|
||||||
//-- Nothing left on queue
|
|
||||||
this.running = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
task = this._tasks[curr];
|
|
||||||
workerID = this.available.pop();
|
|
||||||
worker = this.workers[workerID];
|
|
||||||
|
|
||||||
//-- give worker new task
|
|
||||||
worker.postMessage(task.msg);
|
|
||||||
|
|
||||||
//-- listen for worker response
|
|
||||||
worker.onmessage = function(e){
|
|
||||||
var data = e.data;
|
|
||||||
//console.log("data", data)
|
|
||||||
task.callback(data);
|
|
||||||
delete that._tasks[curr]; //-- Remove task
|
|
||||||
|
|
||||||
that.available.push(workerID);
|
|
||||||
that.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
return worker;
|
|
||||||
}
|
|
||||||
|
|
||||||
FP.Queue.prototype.empty = function(){
|
|
||||||
this._q = [];
|
|
||||||
this._tasks = {};
|
|
||||||
//-- TODO: close workers
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- A super simplistic fake worker, is passed a function instead of a script
|
|
||||||
|
|
||||||
FP.FakeWorker = function(func){
|
|
||||||
this.func = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
FP.FakeWorker.prototype.postMessage = function(msg){
|
|
||||||
setTimeout(function(){
|
|
||||||
this.func(msg, this.onmessage);
|
|
||||||
}.bind(this), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
FP.FakeWorker.prototype.onmessage = function(e){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
FP.FakeWorker.prototype.close = function(e){
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,112 +0,0 @@
|
||||||
FP.storage = function(){
|
|
||||||
|
|
||||||
|
|
||||||
var _supported = {},
|
|
||||||
_storageType,
|
|
||||||
_store;
|
|
||||||
|
|
||||||
|
|
||||||
function storageMethod(storageType){
|
|
||||||
console.log("storageMethod", storageType)
|
|
||||||
|
|
||||||
//-- Pick store type
|
|
||||||
if( !storageType || typeof(FP.store[storageType]) == "undefined"){
|
|
||||||
_storageType = "none";
|
|
||||||
}else{
|
|
||||||
_storageType = storageType;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- Create a new store of that type
|
|
||||||
_store = new FP.store[_storageType];
|
|
||||||
|
|
||||||
//-- Handle load errors
|
|
||||||
_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 _store.get(path, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
function preload(path, callback) {
|
|
||||||
return _store.preload(path, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
function batch(group, callback) {
|
|
||||||
return _store.batch(group, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getURL(path) {
|
|
||||||
return _store.getURL(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
function save(path, file, callback) {
|
|
||||||
return _store.save(path, file, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function _error(err){
|
|
||||||
console.log("error", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStorageType(){
|
|
||||||
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 {
|
|
||||||
"get" : get,
|
|
||||||
"preload" : preload,
|
|
||||||
"batch" : batch,
|
|
||||||
"storageMethod": storageMethod,
|
|
||||||
"getURL": getURL,
|
|
||||||
"save" : save,
|
|
||||||
"getStorageType" : getStorageType,
|
|
||||||
"determineStorageMethod": determineStorageMethod
|
|
||||||
}
|
|
||||||
|
|
||||||
}();
|
|
|
@ -1,202 +0,0 @@
|
||||||
FP.store = FP.store || {};
|
|
||||||
|
|
||||||
FP.store.filesystem = function() {
|
|
||||||
var _urls = {},
|
|
||||||
_queue = new FP.Queue(FP.filePath + "workers/loader_filesystem.js", 6),
|
|
||||||
_requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem,
|
|
||||||
_fs;
|
|
||||||
|
|
||||||
const DBSIZE = 5*1024*1024;
|
|
||||||
const DBTYPE = TEMPORARY;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function openFs(callback){
|
|
||||||
|
|
||||||
if(_fs){
|
|
||||||
callback(_fs);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_requestFileSystem(DBTYPE, DBSIZE, function(fs){
|
|
||||||
_fs = fs;
|
|
||||||
callback(fs);
|
|
||||||
}, _error);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function preload(path) {
|
|
||||||
// var fromCache = check(path);
|
|
||||||
//
|
|
||||||
// if(!fromCache){
|
|
||||||
// _queue.add(path);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
function batch(group, callback){
|
|
||||||
_queue.addGroup(group, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- Fetches url
|
|
||||||
function get(path, callback) {
|
|
||||||
|
|
||||||
if(typeof(_urls[path]) != "undefined"){
|
|
||||||
return _urls[path];
|
|
||||||
}
|
|
||||||
|
|
||||||
check(path, function(fromCache){
|
|
||||||
|
|
||||||
var url;
|
|
||||||
//-- should only be checking urls? but blank on reload?
|
|
||||||
if(fromCache){
|
|
||||||
url = getURL(path, fromCache);
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(url);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
_queue.add(path, function(url){
|
|
||||||
check(url, function(file){
|
|
||||||
url = getURL(path, file);
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(url);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function check(path, callback) {
|
|
||||||
var request,
|
|
||||||
objectStore;
|
|
||||||
|
|
||||||
openFs(function(fs){
|
|
||||||
fs.root.getFile(path, {},
|
|
||||||
function(fileEntry) {
|
|
||||||
callback(fileEntry);
|
|
||||||
},
|
|
||||||
function(){
|
|
||||||
callback(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- should be in worker
|
|
||||||
|
|
||||||
function request(path, callback) {
|
|
||||||
var xhr = new FP.core.loadFile(path);
|
|
||||||
|
|
||||||
xhr.succeeded = function(file) {
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xhr.failed = _error;
|
|
||||||
|
|
||||||
xhr.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
function save(path, file, callback) {
|
|
||||||
openFs(function(fs){
|
|
||||||
var base = path.split('/').slice(0,-1);
|
|
||||||
createDir(fs.root, base);
|
|
||||||
|
|
||||||
fs.root.getFile(path, {create: true},
|
|
||||||
function(fileEntry) {
|
|
||||||
|
|
||||||
fileEntry.createWriter(function(fileWriter) {
|
|
||||||
|
|
||||||
fileWriter.onwriteend = function(e) {
|
|
||||||
if(callback) callback(e);
|
|
||||||
};
|
|
||||||
|
|
||||||
fileWriter.onerror = function(e){
|
|
||||||
_error(err);
|
|
||||||
};
|
|
||||||
|
|
||||||
fileWriter.write(file);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}, _error );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function createDir(rootDirEntry, folders) {
|
|
||||||
// Throw out './' or '/' and move on to prevent something like '/foo/.//bar'.
|
|
||||||
if (folders[0] == '.' || folders[0] == '') {
|
|
||||||
folders = folders.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
rootDirEntry.getDirectory(folders[0], {create: true}, function(dirEntry) {
|
|
||||||
// Recursively add the new subfolder (if we still have another to create).
|
|
||||||
if (folders.length) {
|
|
||||||
createDir(dirEntry, folders.slice(1));
|
|
||||||
}
|
|
||||||
}, _error);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- end worker
|
|
||||||
|
|
||||||
function getURL(path, fileEntry){
|
|
||||||
var url;
|
|
||||||
|
|
||||||
if(typeof(_urls[path]) != "undefined"){
|
|
||||||
return _urls[path];
|
|
||||||
}
|
|
||||||
|
|
||||||
url = fileEntry.toURL();
|
|
||||||
|
|
||||||
_urls[path] = url;
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _error(err){
|
|
||||||
if(typeof(this.failed) == "undefined"){
|
|
||||||
console.log("Error: ", errorHandler(err));
|
|
||||||
}else{
|
|
||||||
this.failed(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function errorHandler(e) {
|
|
||||||
switch (e.code) {
|
|
||||||
case FileError.QUOTA_EXCEEDED_ERR:
|
|
||||||
return 'QUOTA_EXCEEDED_ERR';
|
|
||||||
break;
|
|
||||||
case FileError.NOT_FOUND_ERR:
|
|
||||||
return 'NOT_FOUND_ERR';
|
|
||||||
break;
|
|
||||||
case FileError.SECURITY_ERR:
|
|
||||||
return 'SECURITY_ERR';
|
|
||||||
break;
|
|
||||||
case FileError.INVALID_MODIFICATION_ERR:
|
|
||||||
return 'INVALID_MODIFICATION_ERR';
|
|
||||||
break;
|
|
||||||
case FileError.INVALID_STATE_ERR:
|
|
||||||
return 'INVALID_STATE_ERR';
|
|
||||||
break;
|
|
||||||
case FileError.TYPE_MISMATCH_ERR:
|
|
||||||
return 'TYPE_MISMATCH_ERR';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return 'Unknown Error:' + e.code ;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
|
||||||
"get" : get,
|
|
||||||
"preload" : preload,
|
|
||||||
"batch" : batch,
|
|
||||||
"getURL" : getURL,
|
|
||||||
"save" : save
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,204 +0,0 @@
|
||||||
FP.store = FP.store || {};
|
|
||||||
|
|
||||||
FP.store.indexedDB = function() {
|
|
||||||
var _store = {},
|
|
||||||
_blobs = {},
|
|
||||||
_queue = new FP.Queue(loader, 6),
|
|
||||||
_indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB,
|
|
||||||
_db;
|
|
||||||
|
|
||||||
const DBNAME = "fpjs_db";
|
|
||||||
|
|
||||||
//-- max of 6 concurrent requests: http://www.browserscope.org/?category=network
|
|
||||||
function loader(msg, postMessage){
|
|
||||||
var e = {"data":null},
|
|
||||||
path = msg;
|
|
||||||
|
|
||||||
request(msg, function(file){
|
|
||||||
save(path, file);
|
|
||||||
postMessage(e);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function opendb(callback){
|
|
||||||
var request;
|
|
||||||
|
|
||||||
if(_db){
|
|
||||||
callback(_db);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
request = indexedDB.open(DBNAME);
|
|
||||||
|
|
||||||
|
|
||||||
request.onsuccess = function(event) {
|
|
||||||
_db = request.result;
|
|
||||||
|
|
||||||
_db.onerror = function(event) {
|
|
||||||
console.log("Database error: " + event.target.errorCode);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
if(callback) callback(_db);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
request.onerror = function(event) {
|
|
||||||
// Handle errors.
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
request.onupgradeneeded = function(event) {
|
|
||||||
var db = event.target.result,
|
|
||||||
objectStore = db.createObjectStore("files", { keyPath: "path" }); //keyPath: "id", autoIncrement: true
|
|
||||||
|
|
||||||
//objectStore.createIndex("path", "path", { unique: true });
|
|
||||||
|
|
||||||
//objectStore.createIndex("file", "file", { unique: false });
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function preload(path) {
|
|
||||||
// var fromCache = check(path);
|
|
||||||
//
|
|
||||||
// if(!fromCache){
|
|
||||||
// _queue.add(path);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
function batch(group, callback){
|
|
||||||
_queue.addGroup(group, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- Fetches url
|
|
||||||
function get(path, callback) {
|
|
||||||
|
|
||||||
if(typeof(_blobs[path]) != "undefined"){
|
|
||||||
callback(_blobs[path]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
check(path, function(fromCache){
|
|
||||||
|
|
||||||
var url;
|
|
||||||
|
|
||||||
if(fromCache){
|
|
||||||
url = getURL(path, fromCache);
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(url);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
_queue.add(path, function(file){
|
|
||||||
url = getURL(path, file);
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(url);
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function check(path, callback) {
|
|
||||||
var request,
|
|
||||||
objectStore;
|
|
||||||
|
|
||||||
opendb(function(db){
|
|
||||||
objectStore = db.transaction(["files"]).objectStore("files");
|
|
||||||
request = objectStore.get(path);
|
|
||||||
|
|
||||||
request.onerror = function(event) {
|
|
||||||
callback(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onsuccess = function(event) {
|
|
||||||
callback(request.result.file);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- should be in worker
|
|
||||||
|
|
||||||
function request(path, callback) {
|
|
||||||
var xhr = new FP.core.loadFile(path);
|
|
||||||
|
|
||||||
xhr.succeeded = function(file) {
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xhr.failed = _error;
|
|
||||||
|
|
||||||
xhr.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
function save(path, file) {
|
|
||||||
var entry = {"path" : path, "file": file},
|
|
||||||
request;
|
|
||||||
|
|
||||||
opendb(function(db){
|
|
||||||
var transaction = db.transaction(["files"], "readwrite");
|
|
||||||
var store = transaction.objectStore("files");
|
|
||||||
request = store.put(entry);
|
|
||||||
|
|
||||||
request.onerror = function(event) {
|
|
||||||
console.log("failed: " + event.target.errorCode);
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onsuccess = function(event) {
|
|
||||||
//-- Do nothing for now
|
|
||||||
console.log("saved", path);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- end worker
|
|
||||||
|
|
||||||
function getURL(path, file){
|
|
||||||
var url;
|
|
||||||
|
|
||||||
if(typeof(_blobs[path]) != "undefined"){
|
|
||||||
callback(_blobs[path]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
url = this._URL.createObjectURL(file);
|
|
||||||
|
|
||||||
//-- need to revokeObjectURL previous urls, but only when cleaning cache
|
|
||||||
// this.createdURLs.forEach(function(url){
|
|
||||||
// this._URL.revokeObjectURL(url);
|
|
||||||
// });
|
|
||||||
|
|
||||||
_blobs[path] = url;
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _error(err){
|
|
||||||
if(typeof(this.failed) == "undefined"){
|
|
||||||
console.log("Error: ", err);
|
|
||||||
}else{
|
|
||||||
this.failed(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
|
||||||
"get" : get,
|
|
||||||
"preload" : preload,
|
|
||||||
"batch" : batch,
|
|
||||||
"getURL" : getURL,
|
|
||||||
"save" : save
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,103 +0,0 @@
|
||||||
FP.store = FP.store || {};
|
|
||||||
|
|
||||||
FP.store.none = function() {
|
|
||||||
var _store = {},
|
|
||||||
_blobs = {},
|
|
||||||
_queue = new FP.Queue(loader, 6);
|
|
||||||
//-- max of 6 concurrent requests: http://www.browserscope.org/?category=network
|
|
||||||
|
|
||||||
|
|
||||||
function loader(msg, callback){
|
|
||||||
var e = {"data":null},
|
|
||||||
fromCache = check(msg);
|
|
||||||
|
|
||||||
if(fromCache){
|
|
||||||
e.data = fromCache;
|
|
||||||
callback(e);
|
|
||||||
}else{
|
|
||||||
request(msg, function(url){
|
|
||||||
e.data = url;
|
|
||||||
callback(e);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function preload(path) {
|
|
||||||
var fromCache = check(path);
|
|
||||||
|
|
||||||
if(!fromCache){
|
|
||||||
_queue.add(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function batch(group, callback){
|
|
||||||
_queue.addGroup(group, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- Fetches url
|
|
||||||
function get(path, callback) {
|
|
||||||
var fromCache = check(path),
|
|
||||||
url;
|
|
||||||
|
|
||||||
if(fromCache){
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(fromCache);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
_queue.add(path, function(file){
|
|
||||||
url = getURL(path, file);
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(url);
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function check(path) {
|
|
||||||
var url = _store[path];
|
|
||||||
|
|
||||||
if(typeof(url) != "undefined"){
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function request(path, callback) {
|
|
||||||
var xhr = new FP.core.loadFile(path);
|
|
||||||
|
|
||||||
xhr.succeeded = function(file) {
|
|
||||||
//console.log("file", file)
|
|
||||||
cache(path, file);
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xhr.failed = _error;
|
|
||||||
|
|
||||||
xhr.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
function cache(path, file) {
|
|
||||||
if(_store[path]) return;
|
|
||||||
|
|
||||||
_store[path] = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function _error(err){
|
|
||||||
if(typeof(this.failed) == "undefined"){
|
|
||||||
console.log("Error: ", err);
|
|
||||||
}else{
|
|
||||||
this.failed(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"get" : get,
|
|
||||||
"preload" : preload,
|
|
||||||
"batch" : batch
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,131 +0,0 @@
|
||||||
FP.store = FP.store || {};
|
|
||||||
|
|
||||||
FP.store.ram = function() {
|
|
||||||
var _store = {},
|
|
||||||
_blobs = {},
|
|
||||||
_queue = new FP.Queue(loader, 6),
|
|
||||||
_URL = window.URL;
|
|
||||||
//-- max of 6 concurrent requests: http://www.browserscope.org/?category=network
|
|
||||||
|
|
||||||
|
|
||||||
function loader(msg, callback){
|
|
||||||
var e = {"data":null},
|
|
||||||
fromCache = check(msg);
|
|
||||||
|
|
||||||
if(fromCache){
|
|
||||||
e.data = fromCache;
|
|
||||||
callback(e);
|
|
||||||
}else{
|
|
||||||
request(msg, function(file){
|
|
||||||
e.data = file;
|
|
||||||
callback(e);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function preload(path) {
|
|
||||||
var fromCache = check(path);
|
|
||||||
|
|
||||||
if(!fromCache){
|
|
||||||
_queue.add(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function batch(group, callback){
|
|
||||||
_queue.addGroup(group, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- Fetches url
|
|
||||||
function get(path, callback) {
|
|
||||||
var fromCache = check(path),
|
|
||||||
url;
|
|
||||||
|
|
||||||
if(fromCache){
|
|
||||||
url = getURL(path, fromCache);
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(url);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
_queue.add(path, function(file){
|
|
||||||
url = getURL(path, file);
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(url);
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function check(path) {
|
|
||||||
var file = _store[path];
|
|
||||||
|
|
||||||
if(typeof(file) != "undefined"){
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function request(path, callback) {
|
|
||||||
var xhr = new FP.core.loadFile(path);
|
|
||||||
|
|
||||||
xhr.succeeded = function(file) {
|
|
||||||
//console.log("file", file)
|
|
||||||
cache(path, file);
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xhr.failed = _error;
|
|
||||||
|
|
||||||
xhr.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
function cache(path, file) {
|
|
||||||
if(_store[path]) return;
|
|
||||||
|
|
||||||
_store[path] = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getURL(path, file){
|
|
||||||
var url;
|
|
||||||
|
|
||||||
if(typeof(_blobs[path]) != "undefined"){
|
|
||||||
return _blobs[path];
|
|
||||||
}
|
|
||||||
|
|
||||||
url = _URL.createObjectURL(file);
|
|
||||||
|
|
||||||
//-- need to revokeObjectURL previous urls, but only when cleaning cache
|
|
||||||
// this.createdURLs.forEach(function(url){
|
|
||||||
// this._URL.revokeObjectURL(url);
|
|
||||||
// });
|
|
||||||
|
|
||||||
_blobs[path] = url;
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this.succeeded = function(){
|
|
||||||
// console.log("loaded");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// this.failed = function(){
|
|
||||||
// console.log("loaded");
|
|
||||||
// }
|
|
||||||
|
|
||||||
function _error(err){
|
|
||||||
if(typeof(this.failed) == "undefined"){
|
|
||||||
console.log("Error: ", err);
|
|
||||||
}else{
|
|
||||||
this.failed(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"get" : get,
|
|
||||||
"preload" : preload,
|
|
||||||
"batch" : batch
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,209 +0,0 @@
|
||||||
FP.store = FP.store || {};
|
|
||||||
|
|
||||||
FP.store.websql = function() {
|
|
||||||
var _blobs = {},
|
|
||||||
_queue = new FP.Queue(loader, 6),
|
|
||||||
_db,
|
|
||||||
_URL = window.URL;
|
|
||||||
|
|
||||||
const DBNAME = "fpjs_db";
|
|
||||||
const DBVERSION = "1";
|
|
||||||
const DBDESC = "cache for files";
|
|
||||||
const DBSIZE = 5 * 1024 * 1024;
|
|
||||||
const TABLENAME = "files";
|
|
||||||
|
|
||||||
function loader(msg, postMessage){
|
|
||||||
var e = {"data":null},
|
|
||||||
path = msg;
|
|
||||||
|
|
||||||
request(msg, function(file){
|
|
||||||
save(path, file);
|
|
||||||
postMessage(e);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function opendb(callback){
|
|
||||||
|
|
||||||
if(_db){
|
|
||||||
callback(_db);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_db = openDatabase(DBNAME, DBVERSION, DBDESC, DBSIZE);
|
|
||||||
|
|
||||||
if(!_db){
|
|
||||||
console.error("Database error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_db.transaction(function (tx) {
|
|
||||||
tx.executeSql('CREATE TABLE IF NOT EXISTS '+ TABLENAME +' (path TEXT PRIMARY KEY ASC UNIQUE, file BLOB, type TEXT)');
|
|
||||||
if(callback) callback(_db);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function preload(path) {
|
|
||||||
// var fromCache = check(path);
|
|
||||||
//
|
|
||||||
// if(!fromCache){
|
|
||||||
// _queue.add(path);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
function batch(group, callback){
|
|
||||||
_queue.addGroup(group, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-- Fetches url
|
|
||||||
function get(path, callback) {
|
|
||||||
|
|
||||||
if(typeof(_blobs[path]) != "undefined"){
|
|
||||||
callback(_blobs[path]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
check(path, function(fromCache){
|
|
||||||
|
|
||||||
var url;
|
|
||||||
|
|
||||||
if(fromCache){
|
|
||||||
url = getURL(path, fromCache);
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(url);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
_queue.add(path, function(file){
|
|
||||||
url = getURL(path, file);
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(url);
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function check(path, callback) {
|
|
||||||
var request = {};
|
|
||||||
|
|
||||||
request.onError = function(event, err) {
|
|
||||||
console.log("get Error", err);
|
|
||||||
|
|
||||||
callback(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onSuccess = function(transaction, result) {
|
|
||||||
var row;
|
|
||||||
|
|
||||||
if(result.rows.length){
|
|
||||||
row = result.rows.item(0);
|
|
||||||
callback(row.file);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
opendb(function(db){
|
|
||||||
|
|
||||||
db.transaction(function(tx){
|
|
||||||
tx.executeSql("SELECT * FROM "+TABLENAME+" WHERE path='"+path+"' LIMIT 1",
|
|
||||||
[],
|
|
||||||
request.onSuccess,
|
|
||||||
request.onError);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function request(path, callback) {
|
|
||||||
var xhr = new FP.core.loadFile(path);
|
|
||||||
|
|
||||||
xhr.succeeded = function(file) {
|
|
||||||
if(typeof(callback) != "undefined"){
|
|
||||||
callback(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xhr.failed = _error;
|
|
||||||
|
|
||||||
xhr.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
function save(path, file) {
|
|
||||||
var request = {},
|
|
||||||
reader = new FileReader(),
|
|
||||||
fileString;
|
|
||||||
|
|
||||||
reader.readAsDataURL(file);
|
|
||||||
|
|
||||||
reader.onload = function(event){
|
|
||||||
fileString = event.target.result;
|
|
||||||
opendb(function(db){
|
|
||||||
|
|
||||||
db.transaction(function(tx){
|
|
||||||
tx.executeSql("REPLACE INTO "+TABLENAME+" (path, file, type) VALUES (?,?,?)",
|
|
||||||
[path, fileString, file.type],
|
|
||||||
request.onSuccess,
|
|
||||||
request.onError);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
request.onError = function(event, err) {
|
|
||||||
console.log("failed: ", err);
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onSuccess = function(event) {
|
|
||||||
//-- Do nothing for now
|
|
||||||
//console.log("saved", path);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function getURL(path, file){
|
|
||||||
var url, blob;
|
|
||||||
|
|
||||||
if(typeof(_blobs[path]) != "undefined"){
|
|
||||||
callback(_blobs[path]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
blob = FP.core.dataURLToBlob(file); //go from data url to blob
|
|
||||||
url = _URL.createObjectURL(blob);
|
|
||||||
|
|
||||||
//-- need to revokeObjectURL previous urls, but only when cleaning cache
|
|
||||||
// this.createdURLs.forEach(function(url){
|
|
||||||
// this._URL.revokeObjectURL(url);
|
|
||||||
// });
|
|
||||||
|
|
||||||
_blobs[path] = url;
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _error(err){
|
|
||||||
if(typeof(this.failed) == "undefined"){
|
|
||||||
console.log("Error: ", err);
|
|
||||||
}else{
|
|
||||||
this.failed(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
|
||||||
"get" : get,
|
|
||||||
"preload" : preload,
|
|
||||||
"batch" : batch,
|
|
||||||
"getURL" : getURL,
|
|
||||||
"save" : save
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,156 +0,0 @@
|
||||||
var _requestFileSystem = self.requestFileSystem || self.webkitRequestFileSystem;
|
|
||||||
|
|
||||||
const DBSIZE = 5*1024*1024;
|
|
||||||
const DBTYPE = TEMPORARY;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.onmessage = function(event){
|
|
||||||
var path = event.data;
|
|
||||||
|
|
||||||
|
|
||||||
self.request(path, function(file){
|
|
||||||
self.save(path, file, function(){
|
|
||||||
self.postMessage(path);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
self.openFs = function(callback){
|
|
||||||
|
|
||||||
if(self._fs){
|
|
||||||
if(callback) callback(self._fs);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_requestFileSystem(DBTYPE, DBSIZE, function(fs){
|
|
||||||
self._fs = fs;
|
|
||||||
if(callback) callback(fs);
|
|
||||||
}, self.failure);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
self.request = function(path, callback) {
|
|
||||||
var xhr = new self.loadFile(path);
|
|
||||||
|
|
||||||
xhr.succeeded = function(file) {
|
|
||||||
if(callback) callback(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
xhr.failed = function(err){
|
|
||||||
self.postMessage("failed: " +err.toString());
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.save = function(path, file, callback) {
|
|
||||||
self.openFs(function(fs){
|
|
||||||
var base = path.split('/').slice(0,-1);
|
|
||||||
self.createDir(fs.root, base);
|
|
||||||
|
|
||||||
fs.root.getFile(path, {create: true},
|
|
||||||
function(fileEntry) {
|
|
||||||
|
|
||||||
fileEntry.createWriter(function(fileWriter) {
|
|
||||||
|
|
||||||
fileWriter.onwriteend = function(e) {
|
|
||||||
callback(e);
|
|
||||||
};
|
|
||||||
|
|
||||||
fileWriter.onerror = function(e){
|
|
||||||
self.postMessage("write error:" + self.errorHandler(err) + " path="+path);
|
|
||||||
};
|
|
||||||
|
|
||||||
fileWriter.write(file);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}, self.failure );
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
self.createDir = function(rootDirEntry, folders) {
|
|
||||||
// Throw out './' or '/' and move on to prevent something like '/foo/.//bar'.
|
|
||||||
if (folders[0] == '.' || folders[0] == '') {
|
|
||||||
folders = folders.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
rootDirEntry.getDirectory(folders[0], {create: true}, function(dirEntry) {
|
|
||||||
// Recursively add the new subfolder (if we still have another to create).
|
|
||||||
if (folders.length) {
|
|
||||||
createDir(dirEntry, folders.slice(1));
|
|
||||||
}
|
|
||||||
}, self.failure);
|
|
||||||
};
|
|
||||||
|
|
||||||
self.failure = function(err){
|
|
||||||
self.postMessage("failed: " + self.errorHandler(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.errorHandler = function(e) {
|
|
||||||
switch (e.code) {
|
|
||||||
case FileError.QUOTA_EXCEEDED_ERR:
|
|
||||||
return 'QUOTA_EXCEEDED_ERR';
|
|
||||||
break;
|
|
||||||
case FileError.NOT_FOUND_ERR:
|
|
||||||
return 'NOT_FOUND_ERR';
|
|
||||||
break;
|
|
||||||
case FileError.SECURITY_ERR:
|
|
||||||
return 'SECURITY_ERR';
|
|
||||||
break;
|
|
||||||
case FileError.INVALID_MODIFICATION_ERR:
|
|
||||||
return 'INVALID_MODIFICATION_ERR';
|
|
||||||
break;
|
|
||||||
case FileError.INVALID_STATE_ERR:
|
|
||||||
return 'INVALID_STATE_ERR';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return 'Unknown Error';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.loadFile = function(url, callback){
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
|
|
||||||
this.succeeded = function(response){
|
|
||||||
if(callback){
|
|
||||||
callback(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.failed = function(err){
|
|
||||||
console.log("Error:", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.start = function(){
|
|
||||||
var that = this;
|
|
||||||
|
|
||||||
xhr.open('GET', url, true);
|
|
||||||
xhr.responseType = 'blob';
|
|
||||||
|
|
||||||
xhr.onload = function(e) {
|
|
||||||
if (this.status == 200) {
|
|
||||||
that.succeeded(this.response);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.onerror = function(e) {
|
|
||||||
that.failed(this.status); //-- TODO: better error message
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.send();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"start": this.start,
|
|
||||||
"succeeded" : this.succeeded,
|
|
||||||
"failed" : this.failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.openFs();
|
|
||||||
|
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
importScripts('core.js');
|
|
||||||
|
|
||||||
const DBNAME = "fpjs_db";
|
|
||||||
var indexedDB = self.indexedDB || self.mozIndexedDB || self.webkitIndexedDB || self.msIndexedDB;
|
|
||||||
|
|
||||||
var _q = [];
|
|
||||||
|
|
||||||
self.onmessage = function(event){
|
|
||||||
var path = event.data;
|
|
||||||
|
|
||||||
if(self._objectStore){
|
|
||||||
self.request(path, function(file){
|
|
||||||
self.save(path, file);
|
|
||||||
self.postMessage("succeeded");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
self.opendb = function(callback){
|
|
||||||
|
|
||||||
var request = indexedDB.open(DBNAME);
|
|
||||||
|
|
||||||
request.onsuccess = function(event) {
|
|
||||||
self._db = request.result;
|
|
||||||
|
|
||||||
_db.onerror = function(event) {
|
|
||||||
self.postMessage("failed: " + event.target.errorCode);
|
|
||||||
};
|
|
||||||
|
|
||||||
self._transaction = _db.transaction(["files"], "readwrite");//.objectStore("files");
|
|
||||||
|
|
||||||
self._objectStore = self._transaction.objectStore("files");
|
|
||||||
|
|
||||||
if(callback) callback(_db);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
request.onerror = function(event) {
|
|
||||||
self.postMessage("failed: " + event.target.errorCode);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
self.request = function(path, callback) {
|
|
||||||
var xhr = new FP.core.loadFile(path);
|
|
||||||
|
|
||||||
xhr.succeeded = function(file) {
|
|
||||||
if(callback) callback(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
xhr.failed = function(err){
|
|
||||||
self.postMessage("failed: " +err);
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.save = function(path, file) {
|
|
||||||
var entry = {"path" : path, "file": file},
|
|
||||||
request;
|
|
||||||
self.postMessage("failed: before");
|
|
||||||
var transaction = _db.transaction(["files"], "readwrite");
|
|
||||||
var store = transaction.objectStore("files");
|
|
||||||
request = store.put(entry);
|
|
||||||
self.postMessage("failed: after");
|
|
||||||
request.onerror = function(event) {
|
|
||||||
self.postMessage("failed: " + event.target.errorCode);
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onsuccess = function(event) {
|
|
||||||
//-- Do nothing for now
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
self.opendb();
|
|
||||||
/*
|
|
||||||
self.opendb(function(db){
|
|
||||||
var transaction = db.transaction(["files"], "readwrite")//.objectStore("files");
|
|
||||||
|
|
||||||
transaction.oncomplete = function(event) {
|
|
||||||
self.postMessage("All done!");
|
|
||||||
};
|
|
||||||
|
|
||||||
transaction.onerror = function(event) {
|
|
||||||
self.postMessage("Error in Transaction")
|
|
||||||
};
|
|
||||||
|
|
||||||
_objectStore = transaction.objectStore("files");
|
|
||||||
});
|
|
||||||
*/
|
|
6
grunt.js
6
grunt.js
|
@ -9,13 +9,15 @@ module.exports = function(grunt) {
|
||||||
},
|
},
|
||||||
min: {
|
min: {
|
||||||
'dist/render.min.js': ['<banner>', 'fpjs/render/*.js'],
|
'dist/render.min.js': ['<banner>', 'fpjs/render/*.js'],
|
||||||
'dist/workers/loader_filesystem.js': ['<banner>', 'fpjs/render/workers/loader_filesystem.js'],
|
//'dist/workers/loader_filesystem.js': ['<banner>', 'fpjs/render/workers/loader_filesystem.js'],
|
||||||
'dist/reader.min.js': ['<banner>', 'fpjs/reader/*.js'],
|
'dist/reader.min.js': ['<banner>', 'fpjs/reader/*.js'],
|
||||||
'dist/hooks/hooks.min.js': ['<banner>', 'fpjs/hooks/*.js'],
|
'dist/hooks/hooks.min.js': ['<banner>', 'fpjs/hooks/*.js'],
|
||||||
'dist/libs/zip.js': ['fpjs/libs/zip.js'],
|
'dist/libs/zip.js': ['fpjs/libs/zip.js'],
|
||||||
'dist/libs/deflate.js': ['fpjs/libs/deflate.js'],
|
'dist/libs/deflate.js': ['fpjs/libs/deflate.js'],
|
||||||
'dist/libs/inflate.js': ['fpjs/libs/inflate.js'],
|
'dist/libs/inflate.js': ['fpjs/libs/inflate.js'],
|
||||||
'dist/libs/mime-types.js': ['fpjs/libs/mime-types.js']
|
'dist/libs/mime-types.js': ['fpjs/libs/mime-types.js'],
|
||||||
|
'dist/libs/fileStorage.min.js': ['fpjs/libs/fileStorage.min.js'],
|
||||||
|
'dist/libs/loader_filesystem.js': ['fpjs/libs/loader_filesystem.js']
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
document.onreadystatechange = function () {
|
document.onreadystatechange = function () {
|
||||||
if (document.readyState == "complete") {
|
if (document.readyState == "complete") {
|
||||||
FP.filePath = "/dist/";
|
FP.filePath = "/dist/";
|
||||||
|
fileStorage.filePath = FP.filePath + "libs/";
|
||||||
|
|
||||||
FPR.app.init();
|
FPR.app.init();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -34,6 +36,9 @@
|
||||||
<!-- Reader -->
|
<!-- Reader -->
|
||||||
<script src="dist/reader.min.js"></script>
|
<script src="dist/reader.min.js"></script>
|
||||||
|
|
||||||
|
<!-- fileStorage -->
|
||||||
|
<script src="dist/libs/fileStorage.min.js"></script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="sidebar">
|
<div id="sidebar">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue