# HG changeset patch # User Robert McIntyre # Date 1280194940 14400 # Node ID 5fb202915c11c3c2906241e21a69fa07478a0bec # Parent 0f19af92260ecd72e8d8d9b65f53aa14a9d9999d created card template multifunction diff -r 0f19af92260e -r 5fb202915c11 js-lib/buy3.js --- a/js-lib/buy3.js Mon Jul 26 20:33:17 2010 -0400 +++ b/js-lib/buy3.js Mon Jul 26 21:42:20 2010 -0400 @@ -28,8 +28,15 @@ {"bold" : { "name" :(function (text, display){ return display.print(10,10,text,helvetica, 25).attr( - {"fill" : "#FFFFFF"}); - })}}; + {"fill" : "#0F0"});}), + "email" : (function (text, paper){ + return paper.print(50,50,text,helvetica_I,40).attr( + {"fill" : "red"});}) + + + }}; + + @@ -51,6 +58,26 @@ // Initilization Functions. + var card = + {name : {text: "Robert McIntyre", ref: ""}, + company : {text: "", ref: ""}, + occupation : {text: "", ref: ""}, + phone : {text: "", ref: ""}, + email : {text: "rlm@mit.edu", ref: ""}, + website : {text: "", ref: ""}, + decoration : {text: "", ref: ""}}; + + var card_init = (function () { + card.name.ref = display.set(); + card.company.ref = display.set(); + card.occupation.ref = display.set(); + card.phone.ref = display.set(); + card.email.ref = display.set(); + card.website.ref = display.set(); + card.decoration.ref = display.set(); + }); + + var order = {color : "green", style : "bold", @@ -181,18 +208,6 @@ }); - var card = - {name : {text: "Robert McIntyre", ref: ""}, - company : {text: "", ref: ""}, - occupation : {text: "", ref: ""}, - phone : {text: "", ref: ""}, - email : {text: "", ref: ""}, - website : {text: "", ref: ""}, - decoration : {text: "", ref: ""}}; - - var card_init = (function () { - card.name.ref = display.rect(10,10,10,10,5); - }); var key_handling = (function (){ var assoc = (function (target, field) { @@ -209,17 +224,29 @@ var display_text_update = (function (){ - var name = null; + var state = {name : "nothing", + phone: "nothing", + email: "nothing"}; + //what an asinine function... referential transparency blah blah... + var deref = (function (var_name){return var_name;}); - var check_text = (function () { - if (name !== card.name.text){ - card.name.ref.remove(); - card.name.ref = Cards[order.style].name(card.name.text, display); - name = card.name.text; - }}); - return check_text; - - + var check_text = (function (var_name) { + if (state[deref(var_name)] !== (card[deref(var_name)]).text){ + if (Cards[order.style][deref(var_name)]) { + card[deref(var_name)].ref.remove(); + card[var_name].ref = + Cards[order.style][deref(var_name)]( + card[deref(var_name)].text,display); + state[deref(var_name)] = card[deref(var_name)].text; + }}}); + + return (function (){ + check_text("name"); + check_text("phone"); + check_text("email"); + $("#debug").html(JSON.stringify(state)); + }); + })(); @@ -228,7 +255,7 @@ color_select_update(); display_color_update(); display_text_update(); - $("#debug").html(JSON.stringify({name : card.name.text, email : card.email.text})); +// $("#debug").html(JSON.stringify({name : card.name.text, email : card.email.text, phone : card.phone.text})); });