function App() { this.login = new Login(this); this.currentIndex = -1; var color = localStorage.color; if(!color) color = "red"; this.setColor(color); var _this = this; jester($("#full")).flick(function(touches, direction) { if(direction == "left") _this.showNext(); else _this.showPrevious(); }); window.onhashchange = function(e) { // do not reload page e.preventDefault(); e.stopPropagation(); var url = window.location.hash; if(url == "#list") { _this.changeToPage("#list"); } else if(url == "#reload") { _this.reload(); } else if(url == "#settings") { _this.changeToPage("#settings"); } else if(url.indexOf("#color-") == 0) { var color = url.replace("#color-", ""); _this.setColor(color); } else if(url.indexOf("#full-") == 0) { var i = parseInt(url.replace("#full-", ""), 10); _this.showFull(_this.unread_articles[i]); } else if(url == "#unread") { _this.setCurrentUnread(); } else if(url == "#logout") { _this.logout(); } else if(url == "#reset-info") { alert("Info bubbles will be shown again.") $$(".info").forEach(function(o) { o.removeClass("hidden"); }); } // this is here so you can tap on a button more then once // and it will still call onhashchange window.location.hash = "#"; } // FIXME move that code somewhere else $(".info.swipe").ontouchend = function(e) { localStorage.info_swipe = true; $(".info.swipe").addClass("hidden"); }; if(localStorage.info_swipe) { $(".info.swipe").addClass("hidden"); } var request = window.navigator.mozApps.getSelf(); request.onsuccess = function() { $("#version").innerHTML = request.result.manifest.version; } }; App.prototype.authenticate = function() { }; App.prototype.after_login = function() { this.changeToPage("#list"); this.ttrss = new TinyTinyRSS(this, localStorage.server_url, localStorage.session_id); this.reload(); }; App.prototype.logout = function() { this.ttrss.logOut(); this.unread_articles = []; this.populateList(); this.login.log_out(); }; App.prototype.changeToPage = function(page) { // FIXME var active = $(".active"); if(active.id == "list") { this.saveScrollTop = document.body.scrollTop; } if(page == "#list") { document.body.scrollTop = this.saveScrollTop; } else { window.scroll(0,0); } active.removeClass("active"); $(page).addClass("active"); }; App.prototype.setColor = function(color) { localStorage.color = color; document.body.className = ""; document.body.addClass(color); this.updatePieChart(); }; App.prototype.reload = function() { this.unread_articles = []; this.ttrss.getUnreadFeeds(this.gotUnreadFeeds.bind(this)); }; App.prototype.gotUnreadFeeds = function(new_articles) { if(new_articles == null) { // on error load the saved unread articles. var old_articles = localStorage.unread_articles; if(old_articles) { this.unread_articles = JSON.parse(old_articles); } this.populateList(); } else { this.unread_articles = this.unread_articles.concat(new_articles); if(new_articles.length > 0) { this.ttrss.getUnreadFeeds(this.gotUnreadFeeds.bind(this), this.unread_articles.length); } else { localStorage.unread_articles = JSON.stringify(this.unread_articles); this.populateList(); } } }; App.prototype.populateList = function() { var html_str = ""; for (var i = 0; i < this.unread_articles.length; i++) { var article = this.unread_articles[i]; html_str += "
"; html_str += "" + article.feed_title + ""; html_str += "
"; html_str += "" + article.excerpt + "
"; html_str += "