annotate buy2.js @ 106:5b0753c6f34d laserkard tip

updated to newest compojure and a simpler syntax
author Robert McIntyre <rlm@mit.edu>
date Mon, 27 Sep 2010 20:22:58 -0400
parents e0dadfad3dc4
children
rev   line source
rlm@83 1 //expects: Raphael.js, jQuery.js
rlm@83 2
rlm@79 3
rlm@82 4 var Buy =
rlm@82 5 /* main LaserKard function. Deals with updating the order.
rlm@82 6 expects the following:
rlm@82 7
rlm@83 8 class:
rlm@82 9 select-green
rlm@82 10 select-red
rlm@82 11 select-blue
rlm@82 12 select-black
rlm@82 13
rlm@83 14 id:
rlm@82 15 card-display
rlm@82 16 color-select
rlm@83 17 pokedex
rlm@82 18 */
rlm@82 19
rlm@80 20 (function (){
rlm@80 21
rlm@80 22 var order =
rlm@80 23 {color: "black",
rlm@80 24 style: "bold",
rlm@81 25 quantity: 30,
rlm@82 26 content: undefined,
rlm@82 27 info: undefined};
rlm@83 28
rlm@83 29 var display =
rlm@83 30 {green: "buy-images/display-green.png",
rlm@83 31 red: "buy-images/display-red.png",
rlm@83 32 blue: "buy-images/display-blue.png",
rlm@83 33 black: "buy-images/display-black.png"};
rlm@81 34
rlm@80 35 var raphe = undefined;
rlm@80 36
rlm@80 37 var init = (function () {
rlm@81 38 raphe = Raphael("card-display", 337 ,212);
rlm@81 39 $(".select-green").click(function() {order.color="green";update();});
rlm@81 40 $(".select-red").click(function() {order.color="red";update();});
rlm@81 41 $(".select-blue").click(function() {order.color="blue";update();});
rlm@81 42 $(".select-black").click(function() {order.color="black";update();});
rlm@82 43 });
rlm@80 44
rlm@82 45 var drawRect = (function (){raphe.rect(0,0,337,212);});
rlm@83 46
rlm@83 47 var update_style = (function (){
rlm@83 48 var info = undefined;
rlm@83 49 return (function () {
rlm@83 50 if (order.info === info){}
rlm@83 51 else {
rlm@83 52 info = order.info;
rlm@83 53 $("#pokedex").html(order.info);
rlm@83 54 }});})();
rlm@83 55
rlm@83 56 var update_pokedex = (function (){
rlm@83 57 var info = undefined;
rlm@83 58 return (function () {
rlm@83 59 if (order.info === info){}
rlm@83 60 else {
rlm@83 61 info = order.info;
rlm@83 62 $("#pokedex").html(order.info);
rlm@83 63 }});})();
rlm@80 64
rlm@81 65 var update_color = (function (){
rlm@81 66 var color = undefined;
rlm@81 67 return (function () {
rlm@83 68 if (order.color === color){}
rlm@82 69 else {
rlm@82 70 color = order.color;
rlm@83 71 $("#debug").append("color change");
rlm@83 72 $("#card-display > img").attr("src", display[(order.color)]);
rlm@82 73 $(".selected").removeClass("selected");
rlm@82 74 $(".select-"+order.color).addClass("selected");
rlm@82 75 }});})();
rlm@82 76
rlm@81 77 var update_info = (function (){});
rlm@83 78
rlm@81 79 var update = (function (){
rlm@83 80 update_style();
rlm@83 81 update_pokedex();
rlm@83 82 update_color();
rlm@83 83
rlm@83 84 update_info();
rlm@83 85 });
rlm@81 86
rlm@80 87 return {init : init,
rlm@81 88 draw : drawRect,
rlm@81 89 update : update
rlm@81 90 };
rlm@80 91 })();
rlm@80 92
rlm@80 93
rlm@80 94
rlm@80 95 $(document).ready(function() {
rlm@80 96 Buy.init();
rlm@80 97 Buy.draw();
rlm@81 98 $("#radio1").buttonset();
rlm@80 99
rlm@80 100
rlm@80 101 });
rlm@80 102