Created
May 30, 2010 01:14
-
-
Save orangkucing/418681 to your computer and use it in GitHub Desktop.
Example @anywhere
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Example usage of @Anywhere by Twitter | |
Description: This is a demo doing both (1) and (2) in ANY webpage. | |
(1) change any plain text "@username" to a linked text with hovercard. | |
(2) change any link <a href="http://twitter.com/username..."... to a hovercard. | |
[Note: @Anywhere enables you to do (1) trivially but (2) might be tricky.] | |
Install: First you'd better read the document http://dev.twitter.com/anywhere | |
and get an Application Key as instructed. Next replace the following | |
XXXXXXXXXXXXXXXXXXXXX with your Application Key. Then, copy and paste | |
all of this code to your HTML. And your webpage now have hovercards. | |
--> | |
<!-- this part is going to anywhere in the header part. --> | |
<script src="http://platform.twitter.com/anywhere.js?id=XXXXXXXXXXXXXXXXXXXXX&v=1" type="text/javascript"></script> | |
<!-- this part is going to anywhere in the body part. --> | |
<script type="text/javascript"> | |
twttr.anywhere(function (T) { | |
T("a[href^=\"http://twitter.com/\"]").hovercards({ | |
username: function (node) { | |
var m; | |
for(;;) { | |
if (node.href) { | |
m = node.href.split("/"); | |
if (m[2] == "twitter.com") | |
return m[3] || undefined; | |
} | |
node = node.parentNode || node.parent; // for IE | |
} | |
} | |
}); | |
}); | |
if (window.addEventListener) | |
window.addEventListener("load", function(){twttr.anywhere(function(T){T.linkifyUsers();});}, false); | |
else if (window.attachEvent) | |
window.attachEvent("onload", function(){twttr.anywhere(function(T){T.linkifyUsers();});}); // for IE | |
</script> | |
<!-- end @Anywhere --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment