forked from hudsonfoo/typebutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typebutter.jquery.min.js
7 lines (7 loc) · 1.6 KB
/
typebutter.jquery.min.js
1
2
3
4
5
6
7
/*
* TYPEBUTTER v1.0
* Developed by David Hudson (@_davidhudson)
* Website design and default font kerning by Joel Richardson (@richardson_joel)
* This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License: http://creativecommons.org/licenses/by-sa/3.0/
*/
(function(a){var b;a.fn.typeButterReset=function(){b=null};a.fn.typeButterExtend=function(c){b=a.extend(c,b)};a.fn.typeButter=function(c){var d=a.extend({"default-spacing":"0em"},c);recurseThroughNodes=function(c,e){a(e).contents().each(function(){var e,f=a(this),g=f.text(),h=[""];if(this.nodeType==3){var j=c.css("fontWeight").toLowerCase(),k=c.css("fontStyle").toLowerCase(),l=c.css("font-family").toLowerCase();var m=new Array("normal","bold","bolder","lighter","100","200","300","400","500","600","700","800","900"),n=new Array("normal","italic","oblique");l=l.split(",");l=l[0].replace(/[^\w\s]/gi,"").replace(/ /g,"-");if(!a.inArray(j,m)||j=="400")j="normal";if(!a.inArray(k,n))k="normal";if(j=="700")j="bold";if(b[l]!=undefined&&b[l][j+"-"+k]!=undefined){for(i=0;i<g.length;i++){if(b[l][j+"-"+k][g.substring(i,i+2)]!=undefined){var o=b[l][j+"-"+k][g.substring(i,i+2)];o=parseFloat(o)+parseFloat(d["default-spacing"])+"em";h.push('<kern style="letter-spacing:'+o+'">'+g.substring(i,i+1)+"</kern>")}else{h.push(g.substring(i,i+1))}}a(c).append(h.join(""))}else{a(c).append(f);console.log("library not found for "+l)}}else{e=a(this).clone().empty().appendTo(c);recurseThroughNodes(e,this)}})};return this.each(function(){var b=a(this),c=b.clone();b.empty();b.css("letter-spacing",d["default-spacing"]);recurseThroughNodes(b,c)})}})(jQuery)