view 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 source
1 Buy = (function (){
2 var order =
3 {color: "red",
4 style: "bold",
5 quantity: 30,
6 content: undefined,
7 info: undefined};
9 var display;
10 var color;
11 var style;
13 // var select_green;
14 //var select_red;
15 //var select_blue;
16 //var select_black;
18 var select_map =
19 {"green" : 0,
20 "red" : 0,
21 "blue" : 0,
22 "green" : 0};
24 var toggle_on = (function (button){
25 button.scale(0.5, 0.75);
26 });
28 var toggle_off = (function (button){
29 button.attr("fill", "black");
30 });
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 });})();
42 var update = (function (){
43 color_update();});
45 var drawInit = (function (){
46 //color-select init
47 select_map["red"] = color.rect(1, 1, 70, 50, 10).attr("fill","red");
48 select_map["red"].node.onclick = (function (){
49 order.color= "red"; update();});
50 //toggle_on(select_red);
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();});
62 toggle_on(select_map[order.color]);
64 display.rect(1, 1, 338, 213, 20);
65 style.rect(1, 1, 10, 10, 5);
67 display.print(40, 45, "Robert" , display.getFont('HelveticaNeue', 700), 30);
68 display.print(40, 90, "McIntyre" , display.getFont('HelveticaNeue', 800), 30);
71 });
73 var init = (function () {
75 $("#debug").append("init called.");
76 display = Raphael("card-display", 340 ,215);
77 color = Raphael("color-select", 300, 100);
78 style = Raphael("style-select", 200, 70);
79 drawInit();
80 });
84 return {init : init,
85 update : update};
86 })();
90 $(document).ready(function() {
91 Buy.init();
96 });