X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjs%2Fblerg.js;h=2415483ee2a9b90a8ee24d4a4e52e979642f8c4e;hb=972dcb8706dcedaf0460e23cc816f5eb1bbf7e96;hp=bae782ed96bbed815679760c1ae24e6e8d367e3a;hpb=54789cc8538714fc3622646721f6f2ecceae94ac;p=blerg.git diff --git a/www/js/blerg.js b/www/js/blerg.js index bae782e..2415483 100644 --- a/www/js/blerg.js +++ b/www/js/blerg.js @@ -8,7 +8,7 @@ var recordTemplate = new Template( '
").replace(/\r?\n/g, "
");
@@ -349,11 +353,11 @@ function signup() {
new Ajax.Request(baseURL + '/create', {
parameters: {
username: username,
- password: password,
+ password: password
},
onSuccess: function(r) {
$('signup').hide();
- location.hash = username;
+ location.href = '/#' + username;
hashSwitch();
loginStatus.login(username, password);
@@ -398,30 +402,57 @@ function resizePostContent() {
}, 150);
}
+function loadNewThings() {
+ new Ajax.Request(baseURL + '/newtags.json', {
+ onSuccess: function(r) {
+ $('newtags').update();
+ r.responseText.evalJSON().each(function(v) {
+ var a = new Element('a', {href: '/#tag/' + v});
+ a.insert('#' + v);
+ $('newtags').insert(a);
+ $('newtags').insert(new Element('br'));
+ });
+ }
+ });
+
+ new Ajax.Request(baseURL + '/newusers.json', {
+ onSuccess: function(r) {
+ $('newusers').update();
+ r.responseText.evalJSON().each(function(v) {
+ var a = new Element('a', {href: '/#' + v});
+ a.insert('@' + v);
+ $('newusers').insert(a);
+ $('newusers').insert(new Element('br'));
+ });
+ }
+ });
+}
+
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(/^#([A-Za-z0-9_-]+)(:(\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') });
@@ -432,6 +463,7 @@ function hashSwitch() {
$('older_link').hide();
$('welcome').show();
$('rss').hide();
+ loadNewThings();
}
}
@@ -458,4 +490,7 @@ function init() {
event.stop();
}
});
+ $('post.content').addEventListener('keyup', function(event) {
+ event.stopPropagation();
+ }, true);
}