commit:bddb3452818c4bb33195452f75c5667c207474a2
author:Chip Black
committer:Chip Black
date:Sun Jan 9 00:17:45 2011 -0800
parents:fd4abb4a961a1cfe8ebe1fa0b2a0987dc2f90b35
Add bookmarklet support, clean up hashSwitch()
diff --git a/www/index.html b/www/index.html
line changes: +4/-0
index 729ff19..cd0bfc3
--- a/www/index.html
+++ b/www/index.html
@@ -105,6 +105,10 @@
 
   <p>Here, take a look at the <a href="/doc/#design">design docs</a>.</p>
 
+  <h2>I'm a social media whore and I want to share links!</h2>
+
+  <p>I've created a bookmarklet just for you: <a href="javascript:location.href='http://blerg.dominionofawesome.com/?post/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(location.href)">Blërg it!</a></p>
+
   </div>
 
   <div id="navigation">

diff --git a/www/js/blerg.js b/www/js/blerg.js
line changes: +25/-24
index bae782e..d6081eb
--- a/www/js/blerg.js
+++ b/www/js/blerg.js
@@ -8,7 +8,7 @@ var recordTemplate = new Template(
     '<div class="record">#{data}<div class="info">Posted #{date}</div></div>'
 );
 var tagRecordTemplate = new Template(
-    '<div class="record">#{data}<div class="info">Posted by <a href="\##{author}">@#{author}</a> on #{date}</div></div>'
+    '<div class="record">#{data}<div class="info">Posted by <a href="/\##{author}">@#{author}</a> on #{date}</div></div>'
 );
 
 // Page elements
@@ -77,7 +77,7 @@ LoginStatus.prototype.logout = function() {
 
 LoginStatus.prototype.update = function() {
     if (this.loggedIn) {
-        $('userlink').href = '#' + this.username;
+        $('userlink').href = '/#' + this.username;
         $('userlink').update('@' + this.username);
         $('login').hide();
         $('logout').show();
@@ -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;
 }
@@ -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') });