comparison js-lib/buy3.js @ 95:5fb202915c11 laserkard

created card template multifunction
author Robert McIntyre <rlm@mit.edu>
date Mon, 26 Jul 2010 21:42:20 -0400
parents 0f19af92260e
children a0b768d3494a
comparison
equal deleted inserted replaced
94:0f19af92260e 95:5fb202915c11
26 26
27 var Cards = 27 var Cards =
28 {"bold" : { 28 {"bold" : {
29 "name" :(function (text, display){ 29 "name" :(function (text, display){
30 return display.print(10,10,text,helvetica, 25).attr( 30 return display.print(10,10,text,helvetica, 25).attr(
31 {"fill" : "#FFFFFF"}); 31 {"fill" : "#0F0"});}),
32 })}}; 32 "email" : (function (text, paper){
33 return paper.print(50,50,text,helvetica_I,40).attr(
34 {"fill" : "red"});})
35
36
37 }};
38
39
33 40
34 41
35 42
36 43
37 // Utility Functinos 44 // Utility Functinos
49 56
50 57
51 58
52 59
53 // Initilization Functions. 60 // Initilization Functions.
61 var card =
62 {name : {text: "Robert McIntyre", ref: ""},
63 company : {text: "", ref: ""},
64 occupation : {text: "", ref: ""},
65 phone : {text: "", ref: ""},
66 email : {text: "rlm@mit.edu", ref: ""},
67 website : {text: "", ref: ""},
68 decoration : {text: "", ref: ""}};
69
70 var card_init = (function () {
71 card.name.ref = display.set();
72 card.company.ref = display.set();
73 card.occupation.ref = display.set();
74 card.phone.ref = display.set();
75 card.email.ref = display.set();
76 card.website.ref = display.set();
77 card.decoration.ref = display.set();
78 });
79
80
54 var order = 81 var order =
55 {color : "green", 82 {color : "green",
56 style : "bold", 83 style : "bold",
57 quantity : 30, 84 quantity : 30,
58 content : undefined, 85 content : undefined,
179 if (style !== order.style){ 206 if (style !== order.style){
180 ""; }}); 207 ""; }});
181 }); 208 });
182 209
183 210
184 var card =
185 {name : {text: "Robert McIntyre", ref: ""},
186 company : {text: "", ref: ""},
187 occupation : {text: "", ref: ""},
188 phone : {text: "", ref: ""},
189 email : {text: "", ref: ""},
190 website : {text: "", ref: ""},
191 decoration : {text: "", ref: ""}};
192
193 var card_init = (function () {
194 card.name.ref = display.rect(10,10,10,10,5);
195 });
196 211
197 var key_handling = (function (){ 212 var key_handling = (function (){
198 var assoc = (function (target, field) { 213 var assoc = (function (target, field) {
199 $(target).keyup(function() { 214 $(target).keyup(function() {
200 field.text = $(target).val(); 215 field.text = $(target).val();
207 assoc('#user-website', card.website); 222 assoc('#user-website', card.website);
208 }); 223 });
209 224
210 225
211 var display_text_update = (function (){ 226 var display_text_update = (function (){
212 var name = null; 227 var state = {name : "nothing",
213 228 phone: "nothing",
214 var check_text = (function () { 229 email: "nothing"};
215 if (name !== card.name.text){ 230 //what an asinine function... referential transparency blah blah...
216 card.name.ref.remove(); 231 var deref = (function (var_name){return var_name;});
217 card.name.ref = Cards[order.style].name(card.name.text, display); 232
218 name = card.name.text; 233 var check_text = (function (var_name) {
219 }}); 234 if (state[deref(var_name)] !== (card[deref(var_name)]).text){
220 return check_text; 235 if (Cards[order.style][deref(var_name)]) {
221 236 card[deref(var_name)].ref.remove();
222 237 card[var_name].ref =
238 Cards[order.style][deref(var_name)](
239 card[deref(var_name)].text,display);
240 state[deref(var_name)] = card[deref(var_name)].text;
241 }}});
242
243 return (function (){
244 check_text("name");
245 check_text("phone");
246 check_text("email");
247 $("#debug").html(JSON.stringify(state));
248 });
249
223 })(); 250 })();
224 251
225 252
226 253
227 var update = (function (){ 254 var update = (function (){
228 color_select_update(); 255 color_select_update();
229 display_color_update(); 256 display_color_update();
230 display_text_update(); 257 display_text_update();
231 $("#debug").html(JSON.stringify({name : card.name.text, email : card.email.text})); 258 // $("#debug").html(JSON.stringify({name : card.name.text, email : card.email.text, phone : card.phone.text}));
232 }); 259 });
233 260
234 261
235 262
236 // return closure over state 263 // return closure over state