Mercurial > laserkard
diff js-lib/buy3.js @ 86:e48424b01e5f laserkard
more functional goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 26 Jul 2010 01:24:29 -0400 |
parents | da4f4f91f8aa |
children | 81deee1fc85b |
line wrap: on
line diff
1.1 --- a/js-lib/buy3.js Sun Jul 25 22:36:16 2010 -0400 1.2 +++ b/js-lib/buy3.js Mon Jul 26 01:24:29 2010 -0400 1.3 @@ -1,39 +1,88 @@ 1.4 Buy = (function (){ 1.5 var order = 1.6 - {color: "black", 1.7 - style: "bold", 1.8 - quantity: 30, 1.9 - content: undefined, 1.10 - info: undefined}; 1.11 + {color: "red", 1.12 + style: "bold", 1.13 + quantity: 30, 1.14 + content: undefined, 1.15 + info: undefined}; 1.16 1.17 var display; 1.18 var color; 1.19 var style; 1.20 1.21 - 1.22 + // var select_green; 1.23 + //var select_red; 1.24 + //var select_blue; 1.25 + //var select_black; 1.26 + 1.27 + var select_map = 1.28 + {"green" : 0, 1.29 + "red" : 0, 1.30 + "blue" : 0, 1.31 + "green" : 0}; 1.32 + 1.33 + var toggle_on = (function (button){ 1.34 + button.scale(0.5, 0.75); 1.35 + }); 1.36 + 1.37 + var toggle_off = (function (button){ 1.38 + button.attr("fill", "black"); 1.39 + }); 1.40 + 1.41 + var color_update = (function (){ 1.42 + var color = order.color; 1.43 + return (function (){ 1.44 + if (order.color === color){} 1.45 + else { 1.46 + toggle_off(select_map[color]); 1.47 + toggle_on(select_map[(order.color)]); 1.48 + color = order.color;} 1.49 + });})(); 1.50 + 1.51 + var update = (function (){ 1.52 + color_update();}); 1.53 + 1.54 var drawInit = (function (){ 1.55 - display.rect(1, 1, 338, 213, 20); 1.56 - color.rect(1, 1, 50, 50, 10); 1.57 - style.rect(1, 1, 10, 10, 5); 1.58 - 1.59 - display.print(40, 45, "Robert" , display.getFont('HelveticaNeue', 700), 30); 1.60 - display.print(40, 90, "McIntyre" , display.getFont('HelveticaNeue', 800), 30); 1.61 - 1.62 + //color-select init 1.63 + select_map["red"] = color.rect(1, 1, 70, 50, 10).attr("fill","red"); 1.64 + select_map["red"].node.onclick = (function (){ 1.65 + order.color= "red"; update();}); 1.66 + //toggle_on(select_red); 1.67 + 1.68 + 1.69 + select_map["green"] = 1.70 + color.rect(80, 1, 70, 50,10).attr("fill", "green"); 1.71 + select_map["green"].node.onclick = 1.72 + (function (){order.color = "green"; update();}); 1.73 + select_map["blue"] = 1.74 + color.rect(160, 1, 70, 50, 10).attr("fill", "blue"); 1.75 + select_map["blue"].node.onclick = 1.76 + (function (){order.color = "blue"; update();}); 1.77 + 1.78 + toggle_on(select_map[order.color]); 1.79 + 1.80 + display.rect(1, 1, 338, 213, 20); 1.81 + style.rect(1, 1, 10, 10, 5); 1.82 + 1.83 + display.print(40, 45, "Robert" , display.getFont('HelveticaNeue', 700), 30); 1.84 + display.print(40, 90, "McIntyre" , display.getFont('HelveticaNeue', 800), 30); 1.85 + 1.86 + 1.87 }); 1.88 1.89 var init = (function () { 1.90 1.91 $("#debug").append("init called."); 1.92 display = Raphael("card-display", 340 ,215); 1.93 - color = Raphael("color-select", 200, 70); 1.94 + color = Raphael("color-select", 300, 100); 1.95 style = Raphael("style-select", 200, 70); 1.96 drawInit(); 1.97 }); 1.98 1.99 1.100 1.101 - return {init : init 1.102 - }; 1.103 + return {init : init, 1.104 + update : update}; 1.105 })(); 1.106 1.107