-
Notifications
You must be signed in to change notification settings - Fork 11
/
typebutter.jquery.min.js
7 lines (7 loc) · 1.83 KB
/
typebutter.jquery.min.js
1
2
3
4
5
6
7
/*
* TYPEBUTTER v1.3
* 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(e){var t;e.fn.typeButterReset=function(){t=null};e.fn.typeButterExtend=function(n){t=e.extend(n,t)};e.fn.typeButter=function(n){var r=this,s=e.extend({"default-spacing":"0em",elementName:"kern"},n);recurseThroughNodes=function(n,r){e(r).contents().each(function(){var r,o=e(this),u=n.css("text-transform").toLowerCase()=="uppercase"?o.text().toUpperCase():o.text(),a=[""];if(this.nodeType==3){var f=String(n.css("fontWeight")).toLowerCase(),l=n.css("fontStyle").toLowerCase(),c=n.css("font-family").toLowerCase();var h=new Array("normal","bold","bolder","lighter","100","200","300","400","500","600","700","800","900"),p=new Array("normal","italic","oblique");c=c.split(",");c=c[0].replace(/[^\w\s]/gi,"").replace(/ /g,"-");if(!e.inArray(f,h)||f=="400")f="normal";if(!e.inArray(l,p))l="normal";if(f=="700")f="bold";if(t[c]!=undefined&&t[c][f+"-"+l]!=undefined){for(i=0;i<u.length;i++){if(t[c][f+"-"+l][u.substring(i,i+2)]!=undefined){var d=t[c][f+"-"+l][u.substring(i,i+2)],v=parseInt(n.css("letter-spacing"));d=v*.064+parseFloat(d)+parseFloat(s["default-spacing"])+"em";a.push("<"+s.elementName+' style="letter-spacing:'+d+'">'+u.substring(i,i+1)+"</"+s.elementName+">")}else{a.push(u.substring(i,i+1))}}e(n).append(a.join(""))}else{e(n).append(o);console.log("library not found for "+c)}}else{r=e(this).clone().empty().appendTo(n);recurseThroughNodes(r,this)}})};return r.each(function(t,n){var i=e(this),o=i.clone();i.empty();i.css("letter-spacing",s["default-spacing"]);recurseThroughNodes(i,o);if(r.length==t+1&&typeof s.callback=="function"){s.callback()}})}})(jQuery)