hCardme
- Author(s): George Ornbo
- Source Code: Github
Compatibility
- IE 6+
- Safari 2+
- Firefox 2+
- Opera 8+
- Camino 1+
License
hCardme is free for personal and commercial use.
hCardme is licensed under a Open Source Initiative - BSD License license. I encourage others to fork the code and enhance it.
Installation
hCard me is a web based demonstration of how JavaScript can be used to fetch contact details using Microformats. To test it out simply open the file index.html file in a browser, ensuring you are connected to the internet.
Name
hCardme
Synopsis
hCardme fetches contact details from public HTML pages using jQuery
Description
hCardme uses YQL to query microformat enabled HTML pages and return JSON. This JSON is then consumed and written to the DOM. Here’s the JavaScript that does the work.
$(document).ready(function() {
$("form#mf-url-form").submit(function() {
$(this).attr("value","");
$('form#vcard :input.text').val("");
var url = escape($("#mf-url").val());
$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20microformats%20where%20url%3D'"+url+"'&format=json&callback=?",
function(data){
$(data.query.results.result.feed.adjunct).each(function(adjunct){
if(this.id == "com.yahoo.page.uf.hcard"){
// Check for no results
// Parse items
$(this.item.type.item).each(function(){
switch(this.rel)
{
case "vcard:org":
$("input#vcard-org").attr("value",this.type.meta.content);
break;
case "vcard:adr":
$(this.type.meta).each(function(meta) {
switch(this.property)
{
case "vcard:street-address":
$("input#vcard-street-address").attr("value",this.content);
break;
case "vcard:postal-code":
$("input#vcard-postal-code").attr("value",this.content);
break;
case "vcard:locality":
$("input#vcard-locality").attr("value",this.content);
break;
case "vcard:region":
$("input#vcard-region").attr("value",this.content);
break;
case "vcard:country-name":
$("input#vcard-country-name").attr("value",this.content);
break;
}
});
break;
case "vcard:org":
$("input#vcard-org").attr("value",this.type.meta.content);
break;
}
});
// Parse meta items
$(this.item.type.meta).each(function(){
switch(this.property)
{
case "vcard:fn":
$("input#vcard-fn").attr("value",this.content);
break;
case "vcard:tel":
$("input#vcard-tel").attr("value",this.content);
break;
case "vcard:email":
$("input#vcard-email").attr("value",this.content);
break;
case "vcard:title":
$("input#vcard-title").attr("value",this.content);
break;
}
});
}
});
});
return false;
});
$("ul li a").click(function () {
$("input#mf-url").attr("value",$(this).attr("href"));
return false;
});
});
See also
You can open a ticket over at Lighthouse. As this is free software the response time can vary.
# | Ticket | Milestone | Created at | Updated at | Status |
---|
Donations
Most of my software is free but I still need to eat and keep the wife happy.
If you use any software commercially please consider giving a donation.
Comments
blog comments powered by Disqus