comparison js-lib/buy3.js @ 96:a0b768d3494a laserkard

created text-entry-restriction function
author Robert McIntyre <rlm@mit.edu>
date Mon, 26 Jul 2010 23:39:03 -0400
parents 5fb202915c11
children 8a3615df4c18
comparison
equal deleted inserted replaced
95:5fb202915c11 96:a0b768d3494a
51 if ($(this).val() == $(this).attr('title')) 51 if ($(this).val() == $(this).attr('title'))
52 $(this).val('').removeClass('exampleText'); 52 $(this).val('').removeClass('exampleText');
53 else if ($.trim($(this).val()) == '') 53 else if ($.trim($(this).val()) == '')
54 $(this).addClass('exampleText').val($(this).attr('title'));}); 54 $(this).addClass('exampleText').val($(this).attr('title'));});
55 55
56 //what an asinine function... referential transparency blah blah...
57 var deref = (function (var_name){return var_name;});
56 58
57 59
58 60
59 61
60 // Initilization Functions. 62 // Initilization Functions.
61 var card = 63 var card;
62 {name : {text: "Robert McIntyre", ref: ""}, 64
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 () { 65 var card_init = (function () {
71 card.name.ref = display.set(); 66
72 card.company.ref = display.set(); 67 card = {
73 card.occupation.ref = display.set(); 68 name : {text: "Robert McIntyre", ref: display.set()},
74 card.phone.ref = display.set(); 69 company : {text: "", ref: display.set()},
75 card.email.ref = display.set(); 70 occupation : {text: "", ref: display.set()},
76 card.website.ref = display.set(); 71 phone : {text: "", ref: display.set()},
77 card.decoration.ref = display.set(); 72 email : {text: "rlm@mit.edu", ref: display.set()},
73 website : {text: "", ref: display.set()},
74 decoration : {text: "", ref: display.set()}};
78 }); 75 });
79 76
80 77
81 var order = 78 var order =
82 {color : "green", 79 {color : "blue",
83 style : "bold", 80 style : "bold",
84 quantity : 30, 81 quantity : 30,
85 content : undefined, 82 content : undefined,
86 info : undefined, 83 info : undefined,
87 name : "Robert McIntyre", 84 name : "Robert McIntyre",
195 if (order.color === color){} 192 if (order.color === color){}
196 else { 193 else {
197 state_map["display"].ref.animate( 194 state_map["display"].ref.animate(
198 {"fill" : state_map[order.color].onState.fill}, 2000); 195 {"fill" : state_map[order.color].onState.fill}, 2000);
199 color = order.color;}})})(); 196 color = order.color;}})})();
200 197
201
202
203 var display_style_update = (function (){ 198 var display_style_update = (function (){
204 var style = null; 199 var style = null;
205 return (function (){ 200 return (function (){
206 if (style !== order.style){ 201 if (style !== order.style){
207 ""; }}); 202 ""; }});
208 }); 203 });
209
210
211 204
212 var key_handling = (function (){ 205 var key_handling = (function (){
213 var assoc = (function (target, field) { 206 var assoc = (function (target, field) {
214 $(target).keyup(function() { 207 $(target).keyup(function() {
215 field.text = $(target).val(); 208 field.text = $(target).val();
220 assoc('#user-company', card.company); 213 assoc('#user-company', card.company);
221 assoc('#user-occupation', card.occupation); 214 assoc('#user-occupation', card.occupation);
222 assoc('#user-website', card.website); 215 assoc('#user-website', card.website);
223 }); 216 });
224 217
218 var display_style_update = (function (){
219 var style = null;
220 return (function () {
221 if (style !== order.style){
222
223 for ( var property in card )
224 {
225 alert( property );
226 if (!Cards[order.style][(deref(property))]){
227 $("#user" + "-" + property).toggle(400);}
228 }
229
230
231 style = order.style; }
232
233 });})();
225 234
226 var display_text_update = (function (){ 235 var display_text_update = (function (){
227 var state = {name : "nothing", 236 var state = {name : "nothing",
228 phone: "nothing", 237 phone: "nothing",
229 email: "nothing"}; 238 email: "nothing",
230 //what an asinine function... referential transparency blah blah... 239 occupation: "nothing",
231 var deref = (function (var_name){return var_name;}); 240 company : "nothing",
241 website : "nothing" };
232 242
233 var check_text = (function (var_name) { 243 var check_text = (function (var_name) {
234 if (state[deref(var_name)] !== (card[deref(var_name)]).text){ 244 if (state[deref(var_name)] !== (card[deref(var_name)]).text){
235 if (Cards[order.style][deref(var_name)]) { 245 if (Cards[order.style][deref(var_name)]) {
236 card[deref(var_name)].ref.remove(); 246 card[deref(var_name)].ref.remove();
242 252
243 return (function (){ 253 return (function (){
244 check_text("name"); 254 check_text("name");
245 check_text("phone"); 255 check_text("phone");
246 check_text("email"); 256 check_text("email");
257 check_text("occupation");
258 check_text("company");
259 check_text("website");
260
247 $("#debug").html(JSON.stringify(state)); 261 $("#debug").html(JSON.stringify(state));
248 }); 262 });
249 263
250 })(); 264 })();
251 265
252
253
254 var update = (function (){ 266 var update = (function (){
255 color_select_update(); 267 color_select_update();
256 display_color_update(); 268 display_color_update();
257 display_text_update(); 269 display_text_update();
258 // $("#debug").html(JSON.stringify({name : card.name.text, email : card.email.text, phone : card.phone.text})); 270 display_style_update();
259 }); 271 });
260
261
262 272
263 // return closure over state 273 // return closure over state
264 return {init : init, 274 return {init : init,
265 update : update};})(); 275 update : update};})();
266 276