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