Add italic/bold markdown syntax
[blerg.git] / www / js / blerg.js
index d6081eb..2ee3467 100644 (file)
@@ -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,13 +64,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";
 }
@@ -192,7 +192,7 @@ function User(username) {
                 this.itemCount = parseInt(j.record_count);
                 this.displayItems();
             }
-        }.bind(this),
+        }.bind(this)
     });
 }
 User.prototype = new Pager();
@@ -252,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<a href="$3">$2</a>');
 
+    // Turn *foo* into italics and **foo** into bold
+    record.data = record.data.replace(/(\s)\*\*([^*]+)\*\*(\s)/, '$1<b>$2</b>$3');
+    record.data = record.data.replace(/(\s)\*([^*]+)\*(\s)/, '$1<i>$2</i>$3');
+
     // Turn refs and tags into links
     record.data = record.data.replace(/(\s|^)#(\w+)/g, '$1<a href="#tag/$2">#$2</a>');
     record.data = record.data.replace(/(\s|^)@(\w+)/g, '$1<a href="#$2">@$2</a>');
@@ -349,7 +353,7 @@ function signup() {
     new Ajax.Request(baseURL + '/create', {
         parameters: {
             username: username,
-            password: password,
+            password: password
         },
         onSuccess: function(r) {
             $('signup').hide();
@@ -459,4 +463,7 @@ function init() {
             event.stop();
         }
     });
+    $('post.content').addEventListener('keyup', function(event) {
+        event.stopPropagation();
+    }, true);
 }