X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjs%2Fblerg.js;h=9f92594ba51b22777d5855bf0390d4854d0bb3b9;hb=f4bf2d2efc566e9f165b97bda72cd5a27e0d2b19;hp=d6081eb7859e4ed8f42e31b8b8dbf880a0451e0b;hpb=bddb3452818c4bb33195452f75c5667c207474a2;p=blerg.git diff --git a/www/js/blerg.js b/www/js/blerg.js index d6081eb..9f92594 100644 --- a/www/js/blerg.js +++ b/www/js/blerg.js @@ -8,7 +8,10 @@ var recordTemplate = new Template( '
#{data}
Posted #{date}
' ); var tagRecordTemplate = new Template( - '
#{data}
Posted by @#{author} on #{date}
' + '
#{data}
Posted by @#{author} on #{date}
' +); +var latestRecordsTemplate = new Template( + '
@#{author} #{data}
' ); // Page elements @@ -39,7 +42,7 @@ LoginStatus.prototype.login = function(username, password) { new Ajax.Request(baseURL + '/login', { parameters: { username: username, - password: password, + password: password }, onSuccess: function(r) { var j = r.responseText.evalJSON(); @@ -64,13 +67,13 @@ LoginStatus.prototype.login = function(username, password) { LoginStatus.prototype.logout = function() { new Ajax.Request(baseURL + '/logout', { parameters: { - username: this.username, + username: this.username }, onSuccess: function(r) { this.loggedIn = false; document.cookie = "auth=; expires=1-Jan-1970 00:00:00 GMT"; this.update(); - }.bind(this), + }.bind(this) }); document.cookie = "username=; expires=1-Jan-1970 00:00:00 GMT"; } @@ -79,6 +82,7 @@ LoginStatus.prototype.update = function() { if (this.loggedIn) { $('userlink').href = '/#' + this.username; $('userlink').update('@' + this.username); + $('reflink').href = '/#ref/' + this.username; $('login').hide(); $('logout').show(); } else { @@ -91,7 +95,7 @@ LoginStatus.prototype.update = function() { LoginStatus.prototype.post = function(msg) { if (!this.loggedIn) { alert("You are not logged in!"); - exit(0); + return; } new Ajax.Request(baseURL + '/put', { @@ -104,7 +108,7 @@ LoginStatus.prototype.post = function(msg) { if (j && j.status == 'success') { $('post.content').value = ''; if (location.hash != '#' + this.username) { - location.hash = this.username; + location.href = '/#' + this.username; hashSwitch(); } else { currentPager.itemCount++; @@ -184,6 +188,28 @@ function User(username) { this.initPager(); this.username = username; + $$('[name=user.obsesslink]').each(Element.hide); + $$('[name=user.unobsesslink]').each(Element.hide); + + if (loginStatus.loggedIn) { + new Ajax.Request(baseURL + '/feedinfo/' + username, { + method: 'post', + parameters: { + username: loginStatus.username + }, + onSuccess: function(r) { + var json = r.responseText.evalJSON(); + if (json.subscribed) { + $$('[name=user.obsesslink]').each(Element.hide); + $$('[name=user.unobsesslink]').each(Element.show); + } else { + $$('[name=user.obsesslink]').each(Element.show); + $$('[name=user.unobsesslink]').each(Element.hide); + } + } + }); + } + new Ajax.Request(baseURL + '/info/' + username, { method: 'get', onSuccess: function(r) { @@ -192,7 +218,7 @@ function User(username) { this.itemCount = parseInt(j.record_count); this.displayItems(); } - }.bind(this), + }.bind(this) }); } User.prototype = new Pager(); @@ -202,9 +228,12 @@ User.prototype.show = function() { $$('[name=section]').each(function(v) { v.update(' @' + this.username) }.bind(this)); $('welcome').hide(); items.show(); - $('reflink').href = '/#ref/' + this.username; $('rss').show(); $('rsslink').href = '/rss/' + this.username; + $$('[name=user.reflink]').each(function(e) { + e.href = '/#ref/' + this.username; + }.bind(this)); + $('usercontrols').show(); } User.prototype.loadItems = function(from, to) { @@ -243,22 +272,82 @@ User.prototype.loadItems = function(from, to) { function mangleRecord(record, template) { record.recInt = parseInt(record.record); - // Sanitize HTML input - record.data = record.data.replace('&', '&').replace('<', '<').replace('>', '>'); + var lines = record.data.split(/\r?\n/); + if (lines[lines.length - 1] == '') + lines.pop(); + + var out = ['

']; + var endpush = null; + var listMode = false; + lines.each(function(l) { + if (l == '') { + if (out[out.length - 1] == '
') { + out[out.length - 1] = '

'; + } + if (out[out.length - 1] == '') { + out.push(''); + out.push('

'); + listMode = false; + } + return; + } - // Turn HTTP URLs into links - record.data = record.data.replace(/(\s|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/(\S*[^.!,;?()\s])?)?)/g, '$1$2'); + if (l[0] == '>') { + var pi = out.lastIndexOf('

'); + if (pi != -1) { + out[pi] = '

'; + l = l.replace(/^>\s*/, ''); + } + } + if (l[0] == '*') { + if (!listMode) { + var pi = out.lastIndexOf('

'); + out[pi] = '