-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathvcard.compressed.js
7 lines (6 loc) · 3.88 KB
/
vcard.compressed.js
1
2
3
4
5
6
7
// ____________
// | | A Javascript parser for vCards
// | vCard.js | Created by Mattt Thompson, 2008
// | | Released under the MIT License
// ̅̅̅̅̅̅̅̅̅̅̅̅
if(!Array.prototype.forEach){Array.prototype.forEach=function(g,h){h=h||this;for(var e=0,f=this.length;e<f;e++){g.call(h,this[e],e,this)}}}if(typeof Prototype!="undefined"||!Array.prototype.map){Array.prototype.map=function(i,j){j=j||this;var h=[];for(var f=0,g=this.length;f<g;f++){h.push(i.call(j,this[f],f,this))}return h}}if(typeof Prototype!="undefined"||!Array.prototype.filter){Array.prototype.filter=function(i,j){j=j||this;var h=[];for(var f=0,g=this.length;f<g;f++){if(i.call(j,this[f],f,this)){h.push(this[f])}}return h}}["forEach","map","filter","slice","concat"].forEach(function(b){if(!Array[b]){Array[b]=function(a){return this.prototype[b].apply(a,Array.prototype.slice.call(arguments,1))}}});Date.ISO8601PartMap={Year:1,Month:3,Date:5,Hours:7,Minutes:8,Seconds:9};Date.matchISO8601=function(b){return b.match(/^(\d{4})(-?(\d{2}))?(-?(\d{2}))?(T(\d{2}):?(\d{2})(:?(\d{2}))?)?(Z?(([+\-])(\d{2}):?(\d{2})))?$/)};Date.parseISO8601=function(j){var g=this.matchISO8601(j);if(g){var h=new Date,l,k=0;for(var i in this.ISO8601PartMap){if(part=g[this.ISO8601PartMap[i]]){h["set"+i]((i=="Month")?parseInt(part)-1:parseInt(part))}else{h["set"+i]((i=="Date")?1:0)}}if(g[11]){k=(parseInt(g[14])*60)+parseInt(g[15]);k*=((parseInt[13]=="-")?1:-1)}k-=h.getTimezoneOffset();h.setTime(h.getTime()+(k*60*1000));return h}};vCard={initialize:function(b){var a={};this.parse(b,a);a.prototype=vCard.Base;return vCard.extend(a,vCard.SingletonMethods)},parse:function(d,a){var c={simple:/^(version|fn|title|org)\:(.+)$/i,complex:/^([^\:\;]+);([^\:]+)\:(.+)$/,key:/item\d{1,2}\./,properties:/((type=)?(.+);?)+/};var b=d.split("\n");for(n in b){line=b[n];if(c.simple.test(line)){results=line.match(c.simple);key=results[1].toLowerCase();value=results[2];a[key]=value}else{if(c.complex.test(line)){results=line.match(c.complex);key=results[1].replace(c.key,"").toLowerCase();properties=results[2].split(";");properties=Array.filter(properties,function(e){return !e.match(/[a-z]+=[a-z]+/)});properties=Array.map(properties,function(e){return e.replace(/type=/g,"")});type=properties.pop()||"default";type=type.toLowerCase();value=results[3];value=/;/.test(value)?[value.split(";")]:value;a[key]=a[key]||{};a[key][type]=a[key][type]||[];a[key][type]=a[key][type].concat(value)}}}},SingletonMethods:{to_html:function(){var a='<div class="vcard">';if(this.photo){a+='<img class="photo" src="data:image/png;base64,'+this.photo.base64[0]+'" />'}a+='<span class="fn">'+this.fn+"</span>";if(this.title){a+='<span class="title">'+this.title+"</span>"}if(this.org){a+='<span class="org">'+this.org+"</span>"}a+="<hr/>";for(type in this.adr){for(n in this.adr[type]){value=this.adr[type][n];a+='<address class="adr">';a+='<span class="type">'+type+"</span>";a+='<div class="content">';adr_fields=["post-office-box","extended-address","street-address","locality","region","postal-code","country-name"];for(field in adr_fields){if(value[field]){a+='<span class="'+adr_fields[field]+'">';a+=value[field];a+="</span>"}}a+="</div>";a+="</address>"}}for(type in this.tel){for(n in this.tel[type]){value=this.tel[type][n];a+='<span class="tel">';a+='<span class="type">'+type+"</span>";a+='<span class="value">'+value+"</span>";a+="</span>"}}for(type in this.email){for(n in this.email[type]){value=this.email[type][n];a+='<span class="email">';a+='<span class="type">'+type+"</span>";a+='<a class="value" href="mailto:'+value+'">'+value+"</a>";a+="</span>"}}for(type in this.url){for(n in this.url[type]){value=this.url[type][n];a+='<span class="url">';a+='<span class="type">'+type+"</span>";a+='<a class="value" href="'+value+'">'+value+"</a>";a+="</span>"}}a+="</div>";a=a.replace(/\\n/g,"<br/>");return a}},extend:function(a,b){for(var c in b){a[c]=b[c]}return a},Base:{}};