X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjs%2Fblerg.js;h=737d84cefc2759b2060469a237219d311b60c71d;hb=f13f6cbe98cab2e170fb714047cd794fbd39e228;hp=bae782ed96bbed815679760c1ae24e6e8d367e3a;hpb=54789cc8538714fc3622646721f6f2ecceae94ac;p=blerg.git
diff --git a/www/js/blerg.js b/www/js/blerg.js
index bae782e..737d84c 100644
--- a/www/js/blerg.js
+++ b/www/js/blerg.js
@@ -8,7 +8,7 @@ var recordTemplate = new Template(
'
'
);
var tagRecordTemplate = new Template(
- ''
+ ''
);
// Page elements
@@ -39,7 +39,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,20 +64,20 @@ 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";
}
LoginStatus.prototype.update = function() {
if (this.loggedIn) {
- $('userlink').href = '#' + this.username;
+ $('userlink').href = '/#' + this.username;
$('userlink').update('@' + this.username);
$('login').hide();
$('logout').show();
@@ -192,7 +192,7 @@ function User(username) {
this.itemCount = parseInt(j.record_count);
this.displayItems();
}
- }.bind(this),
+ }.bind(this)
});
}
User.prototype = new Pager();
@@ -202,7 +202,7 @@ User.prototype.show = function() {
$$('[name=section]').each(function(v) { v.update(' @' + this.username) }.bind(this));
$('welcome').hide();
items.show();
- $('reflink').href = '#ref/' + this.username;
+ $('reflink').href = '/#ref/' + this.username;
$('rss').show();
$('rsslink').href = '/rss/' + this.username;
}
@@ -349,7 +349,7 @@ function signup() {
new Ajax.Request(baseURL + '/create', {
parameters: {
username: username,
- password: password,
+ password: password
},
onSuccess: function(r) {
$('signup').hide();
@@ -399,29 +399,30 @@ function resizePostContent() {
}
function hashSwitch() {
- var m = location.hash.match(/^#((ref|tag)\/)?(\w+)(:(\d+))?/);
- if (m) {
- if (m[1]) {
- currentPager = new Tag(m[2], m[3]);
- currentPager.show();
- } else {
- if (!currentPager || currentPager.username != m[3])
- currentPager = new User(m[3]);
- currentPager.show();
- loginStatus.update();
-
- if (m[5]) {
- var r = parseInt(m[5]);
- currentPager.showRecord = r;
- if (currentPager.recordCache[r]) {
- currentPager.displayItems();
- } else {
- currentPager.loadItems((r >= 49 ? r - 49 : 0), r);
- }
+ var m;
+ if (m = location.search.match(/^\?post\/([^/]+)\/(.+)/)) {
+ $('post').show();
+ $('post.content').value = '[' + decodeURIComponent(m[1]).replace(']','').replace('[','') + '](' + decodeURIComponent(m[2]) + ')';
+ } else if (m = location.hash.match(/^#(ref|tag)\/(\w+)$/)) {
+ currentPager = new Tag(m[1], m[2]);
+ currentPager.show();
+ } else if (m = location.hash.match(/^#(\w+)(:(\d+))?$/)) {
+ if (!currentPager || currentPager.username != m[1])
+ currentPager = new User(m[1]);
+ currentPager.show();
+ loginStatus.update();
+
+ if (m[3]) {
+ var r = parseInt(m[3]);
+ currentPager.showRecord = r;
+ if (currentPager.recordCache[r]) {
+ currentPager.displayItems();
} else {
- currentPager.pageStart = currentPager.itemCount - 1;
- currentPager.loadItems();
+ currentPager.loadItems((r >= 49 ? r - 49 : 0), r);
}
+ } else {
+ currentPager.pageStart = currentPager.itemCount - 1;
+ currentPager.loadItems();
}
} else {
$$('[name=section]').each(function(v) { v.update('Welcome') });
@@ -458,4 +459,7 @@ function init() {
event.stop();
}
});
+ $('post.content').addEventListener('keyup', function(event) {
+ event.stopPropagation();
+ }, true);
}