forked from kylefox/Typekit-Tweaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtt.min.js
1 lines (1 loc) · 3.66 KB
/
tt.min.js
1
(function(){$.log=function(a){if(console&&typeof console.log==="function"){console.log("TT: "+a)}};window.tt={VERSION:0.1,DEFAULTS:{"line-height":"1.50em","font-size":"16px",color:"#444444",background:"#FFFFFF","letter-spacing":"0px"},LOREM:"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",ADJUST_LIGHTNESS:0.2};tt.Color={parseRGB:function(c){c=c.replace("#","");var e,d,a;if(c.length===3){e=c[0]+c[0];d=c[1]+c[1];a=c[2]+c[2]}else{if(c.length===6){e=c.substring(0,2);d=c.substring(2,4);a=c.substring(4,6)}else{e=d=a=0}}return{r:Math.round(parseInt(e,16)),g:Math.round(parseInt(d,16)),b:Math.round(parseInt(a,16))}},rgbToHex:function(a){var b=function(d){var c=Math.round(d).toString(16);if(c.length===1){c="0"+c}return c};return("#"+b(a.r)+b(a.g)+b(a.b)).toUpperCase()},adjustLightness:function(a,b){var c=function(e){var d=(e*b>255)?255:(e*b);return(b<1)?Math.floor(d):Math.ceil(d)};return{r:c(a.r),g:c(a.g),b:c(a.b)}}};tt.Tweaker=function(g){var n=this,i=$(g),f,j,m;function b(o){m.filter('[name="font-size"]').val(i.css("font-size"))}function c(o){return'<div class="widget"><label for="tt-'+o+'">'+o.replace("-"," ")+'</label><input type="text" name="'+o+'" id="tt-'+o+'" /></div>'}function h(o){n.refresh()}function e(p,r){var o=tt.Color.parseRGB(p.val());if(o.r===0&&o.g===0&&o.b===0&&r){o={r:1,g:1,b:1}}var q=tt.Color.adjustLightness(o,r?1+tt.ADJUST_LIGHTNESS:1-tt.ADJUST_LIGHTNESS),s=tt.Color.rgbToHex(q);p.val(s)}function a(p,s){var r=p.attr("name");if(r==="color"||r==="background"){e(p,s)}else{var o=p.val().replace(".","").replace(/-?\d+/,"")||"px",u=(o==="px"?1:0.05),t=Number(p.val().slice(0,-2)),q=Number(s?t+=u:t-=u);if(isNaN(q)){q=0}else{if(q<=0&&r!=="letter-spacing"){q=0}}if(o==="em"){q=q.toFixed(2)}p.val(q+o)}}function l(){var o,p=$.cookie("-tt-css");k();d();if(p){try{o=JSON.parse(p)}catch(q){$.log(q);o=tt.DEFAULTS}}else{o=tt.DEFAULTS}n.load(o)}function k(){var o=[];o.push('<div id="tt-tb">');o.push('<div class="lorem widget"><a href="#lorem" title="Insert sample text">L</a></div>');o.push(c("font-size"));o.push(c("line-height"));o.push(c("letter-spacing"));o.push(c("color"));o.push(c("background"));o.push('<div class="chk widget">');o.push('<p><input id="tt-smoothing" name="-webkit-font-smoothing" value="antialiased:subpixel-antialiased" type="checkbox" /><label for="tt-smoothing" title="Use antialiasing instead of subpixel-antialiasing (WebKit only)">Antialias</label></p>');o.push('<a href="http://kylefox.ca/typekit-tweaker/" title="Typekit Tweaker, Version '+window.tt.VERSION+'">About</a>');o.push("</div>");o.push("</div>");j=$(o.join(""));m=j.find('input[type="text"]');i.before(j)}function d(){j.find('a[href="#lorem"]').click(function(){var o=$.trim($("#aside .font-creator-bio .description").text());i.val(o||tt.LOREM);return false});m.keydown(function(o){if(o.keyCode===$.ui.keyCode.UP||o.keyCode===$.ui.keyCode.DOWN){o.preventDefault();a($(this),o.keyCode===$.ui.keyCode.UP)}n.refresh()}).change(h).keyup(h);j.find('input[type="checkbox"]').click(h);$(".variation-switch").change(h);$(".font-size-slider").bind("slide",b)}this.load=function(o){f=o;$.each(f,function(p,q){j.find('[name="'+p+'"]').val(q)});this.refresh()};this.refresh=function(){var o={};m.each(function(p,q){o[this.name]=this.value});j.find('input[type="checkbox"]').each(function(p,q){o[this.name]=this.value.split(":")[this.checked?0:1]});i.css(o);$.cookie("-tt-css",JSON.stringify(o))};l();$.log("Loaded!");$("#tt-font-size").select()}})();