From c588ae44cc54c7b7bf1d0d421676f94f9c3a2203 Mon Sep 17 00:00:00 2001 From: jeena Date: Wed, 21 Aug 2013 16:57:08 +0200 Subject: [PATCH] offline features --- css/screen.css | 5 ++++- js/App.js | 11 ++++++----- js/TinyTinyRSS.js | 44 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/css/screen.css b/css/screen.css index d7b37b9..f7dd9a0 100644 --- a/css/screen.css +++ b/css/screen.css @@ -1,5 +1,6 @@ img { max-width: 100%; + height: auto; } #full header *, #full2 header * { @@ -31,4 +32,6 @@ img { } .smallogo { text-align: center; margin: 0; padding: 0; } -.smallogo img { width: 50%; } \ No newline at end of file +.smallogo img { width: 50%; } + +.count { font-size: 0.8em; padding-top: 0.6em; padding-right: 0.2em; text-shadow: 0 0 2px black; } \ No newline at end of file diff --git a/js/App.js b/js/App.js index 0ff0f95..e3e7705 100644 --- a/js/App.js +++ b/js/App.js @@ -14,7 +14,7 @@ function App() { $("#full").bind("taphold", this.setCurrentUnread.bind(this)); $(".back").on("vclick", this.setCurrentRead.bind(this)); - $(".count").button(); + //$(".count").button(); var _this = this; var aop = function(event, ui) { setTimeout(function() { $("#popup").popup("close") }, 2000) }; @@ -67,7 +67,7 @@ App.prototype.populateList = function() { ul.listview("refresh"); - //$(".count").html(this.unread_articles.length + " / " + this.unread_articles.length); + $(".count").html(this.unread_articles.length + " / " + this.unread_articles.length); //$(".count").button("refresh"); }; @@ -84,7 +84,7 @@ App.prototype.updateList = function() { //$("#list ul").listview("refresh"); - //$(".count").html(unread + " / " + this.unread_articles.length); + $(".count").html(unread + " / " + this.unread_articles.length); //$(".count").button("refresh"); }; @@ -142,7 +142,7 @@ App.prototype.setCurrentRead = function() { article.unread = false; this.updateList(); var _this = this; - setTimeout(function() { this.ttrss.setArticleRead(article.id); }, 500); + setTimeout(function() { _this.ttrss.setArticleRead(article.id); },100); } article.set_unread = false; @@ -152,9 +152,10 @@ App.prototype.setCurrentUnread = function() { var article = this.unread_articles[this.currentIndex]; article.unread = true; article.set_unread = true; - this.ttrss.setArticleUnread(article.id); this.updateList(); $("#popup").popup("open"); + var _this = this; + setTimeout(function() { _this.ttrss.setArticleUnread(article.id); }, 100); }; App.prototype.goToList = function() { diff --git a/js/TinyTinyRSS.js b/js/TinyTinyRSS.js index 20c24c2..da66460 100644 --- a/js/TinyTinyRSS.js +++ b/js/TinyTinyRSS.js @@ -2,8 +2,34 @@ function TinyTinyRSS(app, server_url, session_id) { this.app = app; this.server_url = server_url; this.session_id = session_id; + + window.addEventListener("offline", this.onoffline.bind(this)); + window.addEventListener("online", this.ononline.bind(this)); } +TinyTinyRSS.prototype.onoffline = function() { + // Do nothing +}; + +TinyTinyRSS.prototype.ononline = function() { + var read_articles = localStorage.read_articles; + if (typeof read_articles !== "undefined") { + read_articles = JSON.parse(localStorage.read_articles); + this.setArticleRead(read_articles.join(","), function() { + debug(read_articles) + localStorage.read_articles = null; + }); + } + + var unread_articles = localStorage.unread_articles; + if (unread_articles) { + unread_articles = JSON.parse(unread_articles); + this.setArticleUnread(unread_articles.join(","), function() { + localStorage.unread_articles(); + }); + } +}; + TinyTinyRSS.prototype.doOperation = function(operation, new_options, callback) { if(!navigator.onLine) { callback(null); @@ -58,7 +84,14 @@ TinyTinyRSS.prototype.setArticleRead = function(article_id) { field: 2 }; - this.doOperation("updateArticle", options); + if (navigator.onLine) this.doOperation("updateArticle", options); + else { + var read_articles = localStorage.read_articles; + if(typeof read_articles !== "undefined") read_articles = JSON.parse(read_articles); + else read_articles = []; + read_articles.push(article_id); + localStorage.read_articles = JSON.stringify(read_articles); + } }; TinyTinyRSS.prototype.setArticleUnread = function(article_id) { @@ -68,7 +101,14 @@ TinyTinyRSS.prototype.setArticleUnread = function(article_id) { field: 2 }; - this.doOperation("updateArticle", options); + if (navigator.onLine) this.doOperation("updateArticle", options); + else { + var unread_articles = localStorage.unread_articles; + if (typeof unread_articles !== "undefined") unread_articles = JSON.parse(unread_articles); + else unread_articles = []; + unread_articles.push(article_id); + localStorage.unread_articles = JSON.stringify(unread_articles); + } }; TinyTinyRSS.prototype.logOut = function() {