Recognize links inside parentheses/brackets
[blerg.git] / www / js / blerg.js
index 83a8a88..8cb5bab 100644 (file)
@@ -401,9 +401,28 @@ function mangleRecord(record, template) {
         l = l.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
 
         // Turn HTTP URLs into links
-        l = l.replace(/(\s|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1<a href="$2">$2</a>');
+        l = l.replace(/(\s[()\[\]{}]?|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1<a href="$2">$2</a>');
 
         // Turn markdown links into links
+        var re;
+
+        // Craft a regex that finds URLs that end in the extensions specified by BlergMedia.audioExtensions.
+        re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9]\\/[^)"]*?\\.(' + BlergMedia.audioExtensions.join('|') + '))\\)', 'g');
+        l = l.replace(re, '$1<a href="$3">$2</a> <a href="$3" onclick="play_audio(); return false"><img src="/images/play.png"></a>');
+
+        // Ditto, but use the extended markdown link syntax to specify the format
+        re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\\/[^)"]*?)?)\\s+audio:(' + BlergMedia.audioExtensions.join('|') + ')\\)', 'g');
+        l = l.replace(re, '$1<a href="$3">$2</a> <a href="$3" onclick="play_audio(); return false"><img src="/images/play.png"></a>');
+
+        // Craft a regex that finds URLs that end in the extensions specified by BlergMedia.videoExtensions.
+        re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9]\\/[^)"]*?\\.(' + BlergMedia.videoExtensions.join('|') + '))\\)', 'g');
+        l = l.replace(re, '$1<a href="$3">$2</a> <a href="$3" onclick="play_video(); return false"><img src="/images/play.png"></a>');
+
+        // Ditto, but use the extended markdown link syntax to specify the format
+        re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\\/[^)"]*?)?)\\s+video:(' + BlergMedia.videoExtensions.join('|') + ')\\)', 'g');
+        l = l.replace(re, '$1<a href="$3">$2</a> <a href="$3" onclick="play_video(); return false"><img src="/images/play.png"></a>');
+
+        // Regular markdown links
         l = l.replace(/(\s|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)"]*?)?)\)/g, '$1<a href="$3">$2</a>');
 
         // Turn *foo* into italics and **foo** into bold
@@ -628,6 +647,36 @@ function signup_cancel() {
     urlSwitch();
 }
 
+function passwd() {
+    var old_password = $('passwd.old_password').value;
+    var new_password = $('passwd.new_password').value;
+
+    new Ajax.Request(baseURL + '/passwd', {
+        parameters: {
+            username: loginStatus.username,
+            password: old_password,
+            new_password: new_password
+        },
+        onSuccess: function(r) {
+            if (r.responseJSON.status == 'success') {
+                alert('Password changed');
+                passwd_cancel();
+            } else {
+                alert('Password change failed.  Your password has NOT been changed.');
+            }
+        },
+        onFailure: function(r) {
+            alert('Password change error');
+        }
+    });
+}
+
+function passwd_cancel() {
+    $('passwd').hide();
+    $('navigation').show();
+    urlSwitch();
+}
+
 function subscribe() {
     new Ajax.Request(baseURL + '/subscribe/' + currentPager.username, {
         method: 'post',
@@ -795,6 +844,10 @@ Welcome.prototype.hide = function() {
     $('welcome').hide();
 }
 
+Welcome.prototype.updateState = function() {
+    this.show();
+}
+
 function ExternalURLPost(m) {
     this.title = decodeURIComponent(m[1]).replace(']','').replace('[','');
     this.url = decodeURIComponent(m[2]);