X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjs%2Fblerg.js;h=83a8a88683f523c3554b05f72e5a49a8fab816af;hb=756f2f096cf6a6f7126e053846c1b87b089e30ce;hp=d0135b8abda05ff5591979b11c02b0253946704e;hpb=36bef82c002dfa65064635cb8d3fae3660a6cde2;p=blerg.git diff --git a/www/js/blerg.js b/www/js/blerg.js index d0135b8..83a8a88 100644 --- a/www/js/blerg.js +++ b/www/js/blerg.js @@ -5,13 +5,13 @@ // Config var baseURL = ''; var recordTemplate = new Template( - '
#{data}
Posted #{date}. [permalink] [reply]
' + '
#{data}
Posted #{date}. [permalink] [reply]
' ); var tagRecordTemplate = new Template( - '
#{data}
Posted by @#{author} on #{date}. [permalink] [reply]
' + '
#{data}
Posted by @#{author} on #{date}. [permalink] [reply]
' ); var latestRecordsTemplate = new Template( - '
@#{author} #{data}
' + '
@#{author} #{data}
' ); // Page elements @@ -31,6 +31,8 @@ function LoginStatus() { if (cookies.auth && cookies.username) { this.loggedIn = true; this.username = cookies.username; + this.requestFeedStatus(); + this.feedStatusUpdateInterval = setInterval(this.requestFeedStatus.bind(this), 900000); } else { this.loggedIn = false; this.username = null; @@ -51,6 +53,8 @@ LoginStatus.prototype.login = function(username, password) { this.username = username; document.cookie = "username=" + username; $('login.password').value = ''; + this.requestFeedStatus(); + this.feedStatusUpdateInterval = setInterval(this.requestFeedStatus.bind(this), 900000); this.update(); } else { alert("Could not log in"); @@ -73,6 +77,7 @@ LoginStatus.prototype.logout = function() { this.loggedIn = false; document.cookie = "auth=; expires=1-Jan-1970 00:00:00 GMT"; this.update(); + clearInterval(this.feedStatusUpdateInterval); }.bind(this) }); document.cookie = "username=; expires=1-Jan-1970 00:00:00 GMT"; @@ -80,9 +85,9 @@ LoginStatus.prototype.logout = function() { LoginStatus.prototype.update = function() { if (this.loggedIn) { - $('userlink').href = '/#' + this.username; + $('userlink').href = baseURL + '/#' + this.username; $('userlink').update('@' + this.username); - $('reflink').href = '/#/ref/' + this.username; + $('reflink').href = baseURL + '/#/ref/' + this.username; $('login').hide(); $('logout').show(); } else { @@ -123,6 +128,19 @@ LoginStatus.prototype.post = function(msg) { }); } +LoginStatus.prototype.requestFeedStatus = function() { + new Ajax.Request('/feedinfo', { + parameters: { username: this.username }, + onSuccess: function(r) { + var j = r.responseText.evalJSON(); + if (j['new'] > 0) { + $('newFeedMessages').update('(' + j['new'] + ' new)'); + } else { + $('newFeedMessages').update(''); + } + } + }); +} // Base object for paged data function Pager() { @@ -180,14 +198,14 @@ Pager.prototype.displayItems = function() { } if (this.pageStart < this.itemCount - 1) { - $('newer_link').href = '/#' + this.baseFrag + '/p' + (this.pageStart + this.itemsPerPage); + $('newer_link').href = baseURL + '/#' + this.baseFrag + '/p' + (this.pageStart + this.itemsPerPage); $('newer_link').show(); } else { $('newer_link').hide(); } if (this.pageStart >= 10) { - $('older_link').href = '/#' + this.baseFrag + '/p' + (this.pageStart - this.itemsPerPage); + $('older_link').href = baseURL + '/#' + this.baseFrag + '/p' + (this.pageStart - this.itemsPerPage); $('older_link').show(); } else { $('older_link').hide(); @@ -253,13 +271,13 @@ User.prototype.show = function() { $('rss').show(); $('rsslink').href = '/rss/' + this.username; $$('[name=user.reflink]').each(function(e) { - e.href = '/#/ref/' + this.username; + e.href = baseURL + '/#/ref/' + this.username; }.bind(this)); $('usercontrols').show(); - if (this.permalink && this.pageStart) { + if (this.permalink && this.pageStart >= 0) { this.showRecord(this.pageStart); - } else if (this.pageStart) { + } else if (this.pageStart >= 0) { this.showPageAt(this.pageStart); } else { this.reload(); @@ -311,6 +329,9 @@ User.prototype.reload = function() { } User.prototype.loadItems = function(from, to, continuation) { + if (to < 0) + return; + var url; if (from != undefined && to != undefined) { url = baseURL + '/get/' + this.username + '/' + from + '-' + to; @@ -537,6 +558,7 @@ function Feed(m) { if (!this.pageStart) this.pageStart = response.length - 1; this.itemCount = response.length; + loginStatus.requestFeedStatus(); } this.displayItems(); }.bind(this), @@ -719,12 +741,13 @@ function stopTicker() { function loadLatest() { new Ajax.Request(baseURL + '/latest.json', { + method: 'GET', onSuccess: function(r) { var j = r.responseText.evalJSON(); $('latest-tags').update(); j.tags.each(function(v) { - var a = new Element('a', {href: '/#/tag/' + v}); + var a = new Element('a', {href: baseURL + '/#/tag/' + v}); a.insert('#' + v); a.onclick = "return qlink()"; a.className = 'ref';