X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjs%2Fblerg.js;h=2ee3467dcef8e2dc933364688cc9b4fc7b8a6436;hb=0a73588293307fc51c995bda6f98e082a61df89c;hp=7bb5fe24788262f65a82eacdec390165f0de6fa8;hpb=6ce5fb7ab6e31f76e57639e4d04e32af33e77ee6;p=blerg.git
diff --git a/www/js/blerg.js b/www/js/blerg.js
index 7bb5fe2..2ee3467 100644
--- a/www/js/blerg.js
+++ b/www/js/blerg.js
@@ -1,10 +1,14 @@
+/* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a
+ * BSD-style license. Please see the COPYING file for details.
+ */
+
// Config
var baseURL = '';
var recordTemplate = new Template(
'
'
);
var tagRecordTemplate = new Template(
- ''
+ ''
);
// Page elements
@@ -35,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();
@@ -60,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();
@@ -188,7 +192,7 @@ function User(username) {
this.itemCount = parseInt(j.record_count);
this.displayItems();
}
- }.bind(this),
+ }.bind(this)
});
}
User.prototype = new Pager();
@@ -198,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;
}
@@ -248,6 +252,10 @@ function mangleRecord(record, template) {
// Turn markdown links into links
record.data = record.data.replace(/(\s|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)]*?)?)\)/, '$1$2');
+ // Turn *foo* into italics and **foo** into bold
+ record.data = record.data.replace(/(\s)\*\*([^*]+)\*\*(\s)/, '$1$2$3');
+ record.data = record.data.replace(/(\s)\*([^*]+)\*(\s)/, '$1$2$3');
+
// Turn refs and tags into links
record.data = record.data.replace(/(\s|^)#(\w+)/g, '$1#$2');
record.data = record.data.replace(/(\s|^)@(\w+)/g, '$1@$2');
@@ -345,7 +353,7 @@ function signup() {
new Ajax.Request(baseURL + '/create', {
parameters: {
username: username,
- password: password,
+ password: password
},
onSuccess: function(r) {
$('signup').hide();
@@ -395,29 +403,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') });
@@ -454,4 +463,7 @@ function init() {
event.stop();
}
});
+ $('post.content').addEventListener('keyup', function(event) {
+ event.stopPropagation();
+ }, true);
}