src/js/utils.js
branchtweet-widget
changeset 285 b7aa28af2c10
parent 256 8e1181b855bd
child 297 ed4a459c9290
--- a/src/js/utils.js	Mon Nov 21 10:17:54 2011 +0100
+++ b/src/js/utils.js	Mon Nov 21 10:51:22 2011 +0100
@@ -47,7 +47,18 @@
   var seconds = parseFloat(Math.abs(secs % 60).toFixed(0));
   
   return {"hours" : hours, "minutes" : minutes, "seconds" : seconds};
-}
+};
+
+/* format a tweet - replaces @name by a link to the profile, #hashtag, etc. */
+IriSP.formatTweet = function(tweet) {
+  var rNickname = /@(\w+)/; // matches a @handle
+  var rHashtag = /#(\w+)/;  // matches a hashtag
+  var i1 = tweet.replace(rNickname, "<a href='http://twitter.com/$1'>@$1</a>");
+  var i2 = i1.replace(rHashtag, "<a href='http://twitter.com/search?q=%23$1'>#$1</a>");
+  
+  return i2;
+};
+
 /* for ie compatibility
 if (Object.prototype.__defineGetter__&&!Object.defineProperty) {
    Object.defineProperty=function(obj,prop,desc) {