diff options
-rw-r--r-- | js/index.js | 4 | ||||
-rw-r--r-- | js/read.js | 6 | ||||
-rw-r--r-- | read.html | 23 |
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); } }); @@ -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"); @@ -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' } |