Posted By

prianto on 06/09/11


Tagged

javascript badge twitter


Versions (?)

Twitter Badge


 / Published in: JavaScript
 

  1. var badge={};badge.defaultTop=78;badge.defaultColor="#35ccff";badge.isInArray=function(str,ar){if(ar.length<1)return;for(var i=0;i<ar.length;i++){if(ar[i]==str){return true;break;}}return false;};badge.showbadge=function(){if(!window.XMLHttpRequest){return;};if(document.getElementById('twitterFollowBadge')){document.body.removeChild(document.getElementById('twitterFollowBadge'));};if(badge.top<0||badge.top>1000||isNaN(badge.top)){badge.top=badge.defaultTop;};var validColorPattern=/^#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?$/;if(!validColorPattern.test(badge.color)||(badge.color.length!=4&&badge.color.length!=7)){badge.color=badge.defaultColor;};if(badge.side!='l'){badge.side='r';};badge.tabStyleCode='position:fixed;'+'top:'+badge.top+'px;'+'width:30px;'+'height:119px;'+'z-index:8765;'+'cursor:pointer;'+'background:'+badge.color+' url('+badge.imgtwitter+');'+'background-repeat:no-repeat;';badge.aboutStyleCode='position:fixed;'+'top:'+(parseInt(badge.top)+107)+'px;'+'width:10px;'+'height:11px;'+'z-index:9876;'+'cursor:pointer;'+'background:url('+badge.imgabout+');'+'background-repeat:no-repeat;';if(badge.side=='l'){badge.tabStyleCode+='left:0; background-position:right top;';badge.aboutStyleCode+='left:0;';}else{badge.tabStyleCode+='right:0; background-position:left top;';badge.aboutStyleCode+='right:0;';};badgeMainDiv=document.createElement('div');badgeMainDiv.setAttribute('id','twitterFollowBadge');document.body.appendChild(badgeMainDiv);badgeMainDiv.innerHTML='<div title="@'+badge.account+'" id="badgeTab" style="'+badge.tabStyleCode+'"></div><div title="Tentang Twitter Badge" id="badgeAbout" style="'+badge.aboutStyleCode+'"></div>'+'<style>#badgeAbout{visibility:hidden;} #twitterFollowBadge:hover #badgeAbout{visibility:visible;}</style>';document.getElementById('badgeTab').onclick=function(){window.open('http://twitter.com/'+badge.account);};document.getElementById('badgeAbout').onclick=function(){window.open('http://prianto.tumblr.com/post/6346780591/cara-membuat-twitter-badge');}}
  2.  
  3. badge.imgtwitter = 'http://static.fotokita.net/images/twitter-ikuti-kami-60x119.png';
  4. badge.imgabout = 'http://static.fotokita.net/images/about-10x11.png';
  5. badge.account = 'fotokitanet';
  6. badge.color = '#2299cc';
  7. badge.side = 'r';
  8. badge.top = 200;
  9. badge.showbadge();

Report this snippet  

You need to login to post a comment.