Permalink
Browse files

Reminified script

  • Loading branch information...
1 parent 2f08444 commit c4909a18c45201ec61fb2266b7228804a634eae9 @ggPeti ggPeti committed Sep 7, 2013
Showing with 1 addition and 1 deletion.
  1. +1 −1 tinycon.min.js
View
2 tinycon.min.js
@@ -5,4 +5,4 @@
MIT Licensed
@version 0.5
*/
-(function(){var Tinycon={};var currentFavicon=null;var originalFavicon=null;var originalTitle=document.title;var faviconImage=null;var canvas=null;var options={};var defaults={width:7,height:9,font:'10px arial',colour:'#ffffff',background:'#F03D25',fallback:true,abbreviate:true};var ua=(function(){var agent=navigator.userAgent.toLowerCase();return function(browser){return agent.indexOf(browser)!==-1}}());var browser={ie:ua('msie'),chrome:ua('chrome'),webkit:ua('chrome')||ua('safari'),safari:ua('safari')&&!ua('chrome'),mozilla:ua('mozilla')&&!ua('chrome')&&!ua('safari')};var getFaviconTag=function(){var links=document.getElementsByTagName('link');for(var i=0,len=links.length;i<len;i++){if((links[i].getAttribute('rel')||'').match(/\bicon\b/)){return links[i]}}return false};var removeFaviconTag=function(){var links=document.getElementsByTagName('link');var head=document.getElementsByTagName('head')[0];for(var i=0,len=links.length;i<len;i++){var exists=(typeof(links[i])!=='undefined');if(exists&&(links[i].getAttribute('rel')||'').match(/\bicon\b/)){head.removeChild(links[i])}}};var getCurrentFavicon=function(){if(!originalFavicon||!currentFavicon){var tag=getFaviconTag();originalFavicon=currentFavicon=tag?tag.getAttribute('href'):'/favicon.ico'}return currentFavicon};var getCanvas=function(){if(!canvas){canvas=document.createElement("canvas");canvas.width=16;canvas.height=16}return canvas};var setFaviconTag=function(url){removeFaviconTag();var link=document.createElement('link');link.type='image/x-icon';link.rel='icon';link.href=url;document.getElementsByTagName('head')[0].appendChild(link)};var log=function(message){if(window.console)window.console.log(message)};var drawFavicon=function(label,colour){if(!getCanvas().getContext||browser.ie||browser.safari||options.fallback==='force'){return updateTitle(label)}var context=getCanvas().getContext("2d");var colour=colour||'#000000';var src=getCurrentFavicon();faviconImage=new Image();faviconImage.onload=function(){context.clearRect(0,0,16,16);context.drawImage(faviconImage,0,0,faviconImage.width,faviconImage.height,0,0,16,16);if((label+'').length>0)drawBubble(context,label,colour);refreshFavicon()};if(!src.match(/^data/)){faviconImage.crossOrigin='anonymous'}faviconImage.src=src};var updateTitle=function(label){if(options.fallback){if((label+'').length>0){document.title='('+label+') '+originalTitle}else{document.title=originalTitle}}};var drawBubble=function(context,label,colour){if(typeof label=='number'&&label>99&&options.abbreviate){label=abbreviateNumber(label)}var len=(label+'').length-1;var width=options.width+(6*len);var w=16-width;var h=16-options.height;context.font=(browser.webkit?'bold ':'')+options.font;context.fillStyle=options.background;context.strokeStyle=options.background;context.lineWidth=1;context.fillRect(w,h,width-1,options.height);context.beginPath();context.moveTo(w-0.5,h+1);context.lineTo(w-0.5,15);context.stroke();context.beginPath();context.moveTo(15.5,h+1);context.lineTo(15.5,15);context.stroke();context.beginPath();context.strokeStyle="rgba(0,0,0,0.3)";context.moveTo(w,16);context.lineTo(15,16);context.stroke();context.fillStyle=options.colour;context.textAlign="right";context.textBaseline="top";context.fillText(label,15,browser.mozilla?7:6)};var refreshFavicon=function(){if(!getCanvas().getContext)return;setFaviconTag(getCanvas().toDataURL())};var abbreviateNumber=function(label){var metricPrefixes=[['G',1000000000],['M',1000000],['k',1000]];for(var i=0;i<metricPrefixes.length;++i){if(label>=metricPrefixes[i][1]){label=round(label/metricPrefixes[i][1])+metricPrefixes[i][0];break}}return label};var round=function(value,precision){var number=new Number(value);return number.toFixed(precision)};Tinycon.setOptions=function(custom){options={};for(var key in defaults){options[key]=custom.hasOwnProperty(key)?custom[key]:defaults[key]}return this};Tinycon.setImage=function(url){currentFavicon=url;refreshFavicon();return this};Tinycon.setBubble=function(label,colour){label=label||'';drawFavicon(label,colour);return this};Tinycon.reset=function(){setFaviconTag(originalFavicon)};Tinycon.setOptions(defaults);window.Tinycon=Tinycon})();
+(function(){var e={};var t=null;var n=null;var r=document.title;var i=null;var s=null;var o={};var u=window.devicePixelRatio||1;var a=16*u;var f={width:7,height:9,font:10*u+"px arial",colour:"#ffffff",background:"#F03D25",fallback:true,abbreviate:true};var l=function(){var e=navigator.userAgent.toLowerCase();return function(t){return e.indexOf(t)!==-1}}();var c={ie:l("msie"),chrome:l("chrome"),webkit:l("chrome")||l("safari"),safari:l("safari")&&!l("chrome"),mozilla:l("mozilla")&&!l("chrome")&&!l("safari")};var h=function(){var e=document.getElementsByTagName("link");for(var t=0,n=e.length;t<n;t++){if((e[t].getAttribute("rel")||"").match(/\bicon\b/)){return e[t]}}return false};var p=function(){var e=document.getElementsByTagName("link");var t=document.getElementsByTagName("head")[0];for(var n=0,r=e.length;n<r;n++){var i=typeof e[n]!=="undefined";if(i&&(e[n].getAttribute("rel")||"").match(/\bicon\b/)){t.removeChild(e[n])}}};var d=function(){if(!n||!t){var e=h();n=t=e?e.getAttribute("href"):"/favicon.ico"}return t};var v=function(){if(!s){s=document.createElement("canvas");s.width=a;s.height=a}return s};var m=function(e){p();var t=document.createElement("link");t.type="image/x-icon";t.rel="icon";t.href=e;document.getElementsByTagName("head")[0].appendChild(t)};var g=function(e){if(window.console)window.console.log(e)};var y=function(e,t){if(!v().getContext||c.ie||c.safari||o.fallback==="force"){return b(e)}var n=v().getContext("2d");var t=t||"#000000";var r=d();var s=c.mozilla?16:a;i=new Image;i.onload=function(){n.clearRect(0,0,a,a);n.drawImage(i,0,0,s,s,0,0,a,a);if((e+"").length>0)w(n,e,t);E()};if(!r.match(/^data/)){i.crossOrigin="anonymous"}i.src=r};var b=function(e){if(o.fallback){if((e+"").length>0){document.title="("+e+") "+r}else{document.title=r}}};var w=function(e,t,n){if(typeof t=="number"&&t>99&&o.abbreviate){t=S(t)}var r=(t+"").length-1;var i=o.width*u+6*u*r,s=o.height*u;var f=a-s,l=a-i-u,h=16*u,p=16*u,d=2*u;e.font=(c.webkit?"bold ":"")+o.font;e.fillStyle=o.background;e.strokeStyle=o.background;e.lineWidth=u;e.beginPath();e.moveTo(l+d,f);e.quadraticCurveTo(l,f,l,f+d);e.lineTo(l,h-d);e.quadraticCurveTo(l,h,l+d,h);e.lineTo(p-d,h);e.quadraticCurveTo(p,h,p,h-d);e.lineTo(p,f+d);e.quadraticCurveTo(p,f,p-d,f);e.closePath();e.fill();e.beginPath();e.strokeStyle="rgba(0,0,0,0.3)";e.moveTo(l+d/2,h);e.lineTo(p-d/2,h);e.stroke();e.fillStyle=o.colour;e.textAlign="right";e.textBaseline="top";e.fillText(t,u===2?29:15,c.mozilla?7*u:6*u)};var E=function(){if(!v().getContext)return;m(v().toDataURL())};var S=function(e){var t=[["G",1e9],["M",1e6],["k",1e3]];for(var n=0;n<t.length;++n){if(e>=t[n][1]){e=x(e/t[n][1])+t[n][0];break}}return e};var x=function(e,t){var n=new Number(e);return n.toFixed(t)};e.setOptions=function(e){o={};for(var t in f){o[t]=e.hasOwnProperty(t)?e[t]:f[t]}return this};e.setImage=function(e){t=e;E();return this};e.setBubble=function(e,t){e=e||"";y(e,t);return this};e.reset=function(){m(n)};e.setOptions(f);window.Tinycon=e})()

0 comments on commit c4909a1

Please sign in to comment.