Mercurial > laserkard
comparison 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 |
comparison
equal
deleted
inserted
replaced
85:da4f4f91f8aa | 86:e48424b01e5f |
---|---|
1 Buy = (function (){ | 1 Buy = (function (){ |
2 var order = | 2 var order = |
3 {color: "black", | 3 {color: "red", |
4 style: "bold", | 4 style: "bold", |
5 quantity: 30, | 5 quantity: 30, |
6 content: undefined, | 6 content: undefined, |
7 info: undefined}; | 7 info: undefined}; |
8 | 8 |
9 var display; | 9 var display; |
10 var color; | 10 var color; |
11 var style; | 11 var style; |
12 | 12 |
13 | 13 // var select_green; |
14 //var select_red; | |
15 //var select_blue; | |
16 //var select_black; | |
17 | |
18 var select_map = | |
19 {"green" : 0, | |
20 "red" : 0, | |
21 "blue" : 0, | |
22 "green" : 0}; | |
23 | |
24 var toggle_on = (function (button){ | |
25 button.scale(0.5, 0.75); | |
26 }); | |
27 | |
28 var toggle_off = (function (button){ | |
29 button.attr("fill", "black"); | |
30 }); | |
31 | |
32 var color_update = (function (){ | |
33 var color = order.color; | |
34 return (function (){ | |
35 if (order.color === color){} | |
36 else { | |
37 toggle_off(select_map[color]); | |
38 toggle_on(select_map[(order.color)]); | |
39 color = order.color;} | |
40 });})(); | |
41 | |
42 var update = (function (){ | |
43 color_update();}); | |
44 | |
14 var drawInit = (function (){ | 45 var drawInit = (function (){ |
15 display.rect(1, 1, 338, 213, 20); | 46 //color-select init |
16 color.rect(1, 1, 50, 50, 10); | 47 select_map["red"] = color.rect(1, 1, 70, 50, 10).attr("fill","red"); |
17 style.rect(1, 1, 10, 10, 5); | 48 select_map["red"].node.onclick = (function (){ |
18 | 49 order.color= "red"; update();}); |
19 display.print(40, 45, "Robert" , display.getFont('HelveticaNeue', 700), 30); | 50 //toggle_on(select_red); |
20 display.print(40, 90, "McIntyre" , display.getFont('HelveticaNeue', 800), 30); | 51 |
21 | 52 |
53 select_map["green"] = | |
54 color.rect(80, 1, 70, 50,10).attr("fill", "green"); | |
55 select_map["green"].node.onclick = | |
56 (function (){order.color = "green"; update();}); | |
57 select_map["blue"] = | |
58 color.rect(160, 1, 70, 50, 10).attr("fill", "blue"); | |
59 select_map["blue"].node.onclick = | |
60 (function (){order.color = "blue"; update();}); | |
61 | |
62 toggle_on(select_map[order.color]); | |
63 | |
64 display.rect(1, 1, 338, 213, 20); | |
65 style.rect(1, 1, 10, 10, 5); | |
66 | |
67 display.print(40, 45, "Robert" , display.getFont('HelveticaNeue', 700), 30); | |
68 display.print(40, 90, "McIntyre" , display.getFont('HelveticaNeue', 800), 30); | |
69 | |
70 | |
22 }); | 71 }); |
23 | 72 |
24 var init = (function () { | 73 var init = (function () { |
25 | 74 |
26 $("#debug").append("init called."); | 75 $("#debug").append("init called."); |
27 display = Raphael("card-display", 340 ,215); | 76 display = Raphael("card-display", 340 ,215); |
28 color = Raphael("color-select", 200, 70); | 77 color = Raphael("color-select", 300, 100); |
29 style = Raphael("style-select", 200, 70); | 78 style = Raphael("style-select", 200, 70); |
30 drawInit(); | 79 drawInit(); |
31 }); | 80 }); |
32 | 81 |
33 | 82 |
34 | 83 |
35 return {init : init | 84 return {init : init, |
36 }; | 85 update : update}; |
37 })(); | 86 })(); |
38 | 87 |
39 | 88 |
40 | 89 |
41 $(document).ready(function() { | 90 $(document).ready(function() { |