Mercurial > laserkard
view js-lib/buy3.js @ 87:81deee1fc85b laserkard
got pure raphael color selector working
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 26 Jul 2010 02:20:29 -0400 |
parents | e48424b01e5f |
children | 08f93d043ed2 |
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 : {offAttr : 0, onAttr : 0, ref : 0},20 red : {offAttr : 0, onAttr : 0, ref : 0},21 blue : {offAttr : 0, onAttr : 0, ref : 0},22 green : {offAttr : 0, onAttr : 0, ref : 0}};24 var toggle_on = (function (button){25 button.ref.animate(button.onAttr, 500);26 });28 var toggle_off = (function (button){29 button.ref.animate(button.offAttr, 500);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 init47 select_map["red"].onAttr = {"fill" : "#F00"};48 select_map["red"].offAttr = {"fill" : "#300"};49 select_map["red"].ref =50 color.rect(1, 1, 70, 50, 10).attr(select_map["red"].offAttr);51 select_map["red"].ref.node.onclick =52 (function (){order.color= "red"; update();});54 select_map["green"].onAttr = {"fill" : "#0F0"};55 select_map["green"].offAttr = {"fill" : "#030"};56 select_map["green"].ref =57 color.rect(80, 1, 70, 50, 10).attr(select_map["green"].offAttr);58 select_map["green"].ref.node.onclick =59 (function (){order.color= "green"; update();});61 select_map["blue"].onAttr = {"fill" : "#00F"};62 select_map["blue"].offAttr = {"fill" : "#003"};63 select_map["blue"].ref =64 color.rect(160, 1, 70, 50, 10).attr(select_map["blue"].offAttr);65 select_map["blue"].ref.node.onclick =66 (function (){order.color= "blue"; update();});69 toggle_on(select_map[order.color]);71 display.rect(1, 1, 338, 213, 20);72 style.rect(1, 1, 10, 10, 5);74 display.print(40, 45, "Robert" , display.getFont('HelveticaNeue', 700), 30);75 display.print(40, 90, "McIntyre" , display.getFont('HelveticaNeue', 800), 30);78 });80 var init = (function () {82 $("#debug").append("init called.");83 display = Raphael("card-display", 340 ,215);84 color = Raphael("color-select", 300, 100);85 style = Raphael("style-select", 200, 70);86 drawInit();87 });91 return {init : init,92 update : update};93 })();97 $(document).ready(function() {98 Buy.init();103 });