var $renderKey = {}; (function () { "use strict"; // Some predefined sizes for our caps var sizes = { cap: 54, padding: 2, margin: 6, spacing: 1 }; sizes.capsize = function(size) { return (size*sizes.cap) - (2*sizes.spacing); }; // Lighten a color by the specified amount function lightenColor(color,mod) { var c = $color.sRGB8(color.r,color.g,color.b).Lab(); c.l = Math.min(100,c.l*mod); return c.sRGB8(); } $renderKey.getKeyRotationStyles = function(key) { if(key.rotation_angle == 0) { return ""; } var angle = key.rotation_angle.toString() + "deg"; var origin = (sizes.capsize(key.rotation_x) + sizes.margin).toString() + "px " + (sizes.capsize(key.rotation_y) + sizes.margin).toString() + "px"; return "transform: rotate("+angle+"); -ms-transform: rotate("+angle+"); -webkit-transform: rotate("+angle+"); " + "transform-origin: "+origin+"; -ms-transform-origin: "+origin+"; -webkit-transform-origin: "+origin+";"; }; // Given a key, generate the HTML needed to render it var noRenderText = [0,2,1,3,0,4,2,3]; $renderKey.html = function(key, $sanitize) { var html = ""; var capwidth = sizes.capsize(key.width), capwidth2 = sizes.capsize(key.width2); var capheight = sizes.capsize(key.height), capheight2 = sizes.capsize(key.height2); var capx = sizes.capsize(key.x) + sizes.margin, capx2 = sizes.capsize(key.x+key.x2)+sizes.margin; var capy = sizes.capsize(key.y) + sizes.margin, capy2 = sizes.capsize(key.y+key.y2)+sizes.margin; var jShaped = (capwidth2 !== capwidth) || (capheight2 !== capheight) || (capx2 !== capx) || (capy2 !== capy); var darkColor = key.color; var lightColor = lightenColor($color.hex(key.color), 1.2).hex(); var innerPadding = (2*sizes.margin) + (2*sizes.padding); var borderStyle = "keyborder", bgStyle = "keybg"; key.centerx = key.align&1 ? true : false; key.centery = key.align&2 ? true : false; key.centerf = key.align&4 ? true : false; if(key.ghost) { borderStyle += " ghosted"; bgStyle += " ghosted"; } // The border html += "
\n" .format( capwidth, capheight, capx, capy, darkColor, borderStyle ); if(jShaped) { html += "\n" .format( capwidth2, capheight2, capx2, capy2, darkColor, borderStyle ); } // The key edges html += "\n" .format( capwidth, capheight, capx+1, capy+1, darkColor, bgStyle ); if(jShaped) { html += "\n" .format( capwidth2, capheight2, capx2+1, capy2+1, darkColor, bgStyle ); } if(!key.ghost) { // The top of the cap html += "\n" .format( capwidth-innerPadding, capheight-innerPadding, capx+sizes.margin, capy+(sizes.margin/2), lightColor, sizes.padding ); if(jShaped && !key.stepped) { html += "\n" .format( capwidth2-innerPadding, capheight2-innerPadding, capx2+sizes.margin, capy2+(sizes.margin/2), lightColor, sizes.padding ); } var maxWidth = capwidth-(2*sizes.margin); var maxHeight = capheight-(2*sizes.margin); if(jShaped && !key.stepped) { maxWidth = Math.max(capwidth,capwidth2)-(2*sizes.margin); maxHeight = Math.max(capheight,capheight2)-(2*sizes.margin); html += "