summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2017-02-27 09:40:08 +0300
committerAndrew Dolgov <[email protected]>2017-02-27 09:40:08 +0300
commit17f826cd1d1fdaa7212a568c371273f702f77b7c (patch)
tree8f624c67d529b289abf16badedb348d263e84f3c
parentbc720234f59d39119c9486ff88f248bacd3140c3 (diff)
store basic settings in indexed db
-rw-r--r--js/index.js4
-rw-r--r--js/read.js6
-rw-r--r--read.html23
3 files changed, 20 insertions, 13 deletions
diff --git a/js/index.js b/js/index.js
index 336232f..b314cc0 100644
--- a/js/index.js
+++ b/js/index.js
@@ -1,12 +1,12 @@
function cache_refresh() {
if ('serviceWorker' in navigator) {
- localforage.getItem("epube-cache.timestamp").then(function(stamp) {
+ localforage.getItem("epube.cache-timestamp").then(function(stamp) {
var ts = parseInt(new Date().getTime()/1000);
if (!stamp || ts - stamp > 3600) {
console.log('asking worker to refresh cache');
navigator.serviceWorker.controller.postMessage("refresh-cache");
- localforage.setItem("epube-cache.timestamp", ts);
+ localforage.setItem("epube.cache-timestamp", ts);
}
});
diff --git a/js/read.js b/js/read.js
index fed73f7..e7e4e4f 100644
--- a/js/read.js
+++ b/js/read.js
@@ -66,7 +66,7 @@ function lmargin(incr) {
var cur = parseInt(window.book.settings.styles.lineHeight.replace("%", ""));
var size = cur + incr;
- localStorage["epube:lineHeight"] = size;
+ localforage.setItem("epube.lineHeight", size);
window.book.setStyle("lineHeight", size + "%");
@@ -75,7 +75,7 @@ function lmargin(incr) {
function apply_font(elem) {
var font = elem[elem.selectedIndex].value;
- localStorage["epube:fontFamily"] = font;
+ localforage.setItem("epube.fontFamily", font);
window.book.setStyle("fontFamily", font);
@@ -84,7 +84,7 @@ function zoom(incr) {
var cur = parseInt(window.book.settings.styles.fontSize.replace("px", ""));
var size = cur + incr;
- localStorage["epube:fontSize"] = size;
+ localforage.setItem("epube.fontSize", size);
window.book.setStyle("fontSize", size + "px");
diff --git a/read.html b/read.html
index 500743d..fa4553e 100644
--- a/read.html
+++ b/read.html
@@ -278,14 +278,21 @@
restore: false,
});
- var settings = {
- fontSize: localStorage['epube:fontSize'] ? localStorage['epube:fontSize'] : '16px',
- fontFamily: localStorage['epube:fontFamily'] ? localStorage['epube:fontFamily'] : 'Georgia',
- lineHeight: localStorage['epube:lineHeight'] ? localStorage['epube:lineHeight'] : '140%' };
-
- book.setStyle("fontSize", settings.fontSize + "px");
- book.setStyle("fontFamily", settings.fontFamily);
- book.setStyle("lineHeight", settings.lineHeight + "%");
+ Promise.all([
+ localforage.getItem("epube.fontSize"),
+ localforage.getItem("epube.fontFamily"),
+ localforage.getItem("epube.lineHeight")
+ ]).then(function(res) {
+ var fontSize = res[0] ? res[0] + "px" : "16px";
+ var fontFamily = res[1] ? res[1] : "Georgia";
+ var lineHeight = res[2] ? res[2] + "%" : "140%";
+
+ book.setStyle("fontSize", fontSize);
+ book.setStyle("fontFamily", fontFamily);
+ book.setStyle("lineHeight", lineHeight);
+
+ });
+
//styles: { fontSize: '24px', lineHeight: '130%', fontFamily: 'Georgia' }