changeset 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
files js-lib/buy3.js
diffstat 1 files changed, 40 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/js-lib/buy3.js	Mon Jul 26 21:42:20 2010 -0400
     1.2 +++ b/js-lib/buy3.js	Mon Jul 26 23:39:03 2010 -0400
     1.3 @@ -53,33 +53,30 @@
     1.4  	else if ($.trim($(this).val()) == '')
     1.5  	    $(this).addClass('exampleText').val($(this).attr('title'));});
     1.6  
     1.7 +    //what an asinine function... referential transparency blah blah...
     1.8 +    var deref = (function (var_name){return var_name;});
     1.9  
    1.10  
    1.11  
    1.12  
    1.13      // Initilization Functions.
    1.14 -    var card = 
    1.15 -	{name       : {text: "Robert McIntyre", ref: ""},
    1.16 -	 company    : {text: "", ref: ""},
    1.17 -	 occupation : {text: "", ref: ""},
    1.18 -	 phone      : {text: "", ref: ""},
    1.19 -	 email      : {text: "rlm@mit.edu", ref: ""},
    1.20 -	 website    : {text: "", ref: ""},
    1.21 -	 decoration : {text: "", ref: ""}};
    1.22 -
    1.23 +    var card;
    1.24 +	
    1.25      var card_init = (function () {
    1.26 -	card.name.ref = display.set();
    1.27 -	card.company.ref = display.set();
    1.28 -	card.occupation.ref = display.set();
    1.29 -	card.phone.ref = display.set();
    1.30 -	card.email.ref = display.set();
    1.31 -	card.website.ref = display.set();
    1.32 -	card.decoration.ref = display.set();
    1.33 +	
    1.34 +	card = {
    1.35 +	    name       : {text: "Robert McIntyre", ref: display.set()},
    1.36 +	    company    : {text: "", ref: display.set()},
    1.37 +	    occupation : {text: "", ref: display.set()},
    1.38 +	    phone      : {text: "", ref: display.set()},
    1.39 +	    email      : {text: "rlm@mit.edu", ref: display.set()},
    1.40 +	    website    : {text: "", ref: display.set()},
    1.41 +	    decoration : {text: "", ref: display.set()}};
    1.42      });
    1.43  
    1.44  
    1.45      var order = 
    1.46 -	{color : "green",
    1.47 +	{color : "blue",
    1.48  	 style : "bold",
    1.49  	 quantity : 30,
    1.50  	 content : undefined,
    1.51 @@ -197,9 +194,7 @@
    1.52      		state_map["display"].ref.animate(
    1.53  		    {"fill" : state_map[order.color].onState.fill}, 2000);
    1.54      		color = order.color;}})})();
    1.55 -
    1.56      
    1.57 -
    1.58      var display_style_update = (function (){
    1.59  	var style = null;
    1.60  	return (function (){
    1.61 @@ -207,8 +202,6 @@
    1.62  		""; }});
    1.63  	});
    1.64  
    1.65 -
    1.66 -
    1.67      var key_handling = (function (){
    1.68  	var assoc = (function (target, field) {
    1.69  	    $(target).keyup(function() {
    1.70 @@ -222,13 +215,30 @@
    1.71  	assoc('#user-website', card.website);
    1.72      });
    1.73  
    1.74 +    var display_style_update = (function (){
    1.75 +	var style = null;
    1.76 +	return (function () {
    1.77 +	    if (style !== order.style){
    1.78 +		
    1.79 +		for ( var property in card )
    1.80 +		{
    1.81 +		    alert( property );
    1.82 +		    if (!Cards[order.style][(deref(property))]){
    1.83 +			$("#user" + "-" + property).toggle(400);}
    1.84 +		}
    1.85 +		
    1.86 +		
    1.87 +		style = order.style;	    }
    1.88 +	
    1.89 +	});})();
    1.90  
    1.91      var display_text_update = (function (){
    1.92  	var state = {name : "nothing",
    1.93  		     phone: "nothing",
    1.94 -		     email: "nothing"};
    1.95 -	//what an asinine function... referential transparency blah blah...
    1.96 -	var deref = (function (var_name){return var_name;});
    1.97 +		     email: "nothing",
    1.98 +		     occupation: "nothing",
    1.99 +		     company : "nothing",
   1.100 +		     website : "nothing" };
   1.101  
   1.102  	var check_text = (function (var_name) {                         
   1.103  	    if (state[deref(var_name)] !== (card[deref(var_name)]).text){
   1.104 @@ -244,22 +254,22 @@
   1.105  	    check_text("name");
   1.106  	    check_text("phone");
   1.107  	    check_text("email");
   1.108 +	    check_text("occupation");
   1.109 +	    check_text("company");
   1.110 +	    check_text("website");
   1.111 +	    
   1.112  	    $("#debug").html(JSON.stringify(state));
   1.113  	});
   1.114 -	
   1.115 +    
   1.116      })();
   1.117        
   1.118 -    
   1.119 -
   1.120      var update = (function (){
   1.121  	color_select_update();
   1.122  	display_color_update();
   1.123  	display_text_update();
   1.124 -//	$("#debug").html(JSON.stringify({name : card.name.text, email : card.email.text, phone : card.phone.text}));
   1.125 +	display_style_update();
   1.126      });
   1.127      
   1.128 -    
   1.129 -    
   1.130      // return closure over state
   1.131      return {init : init,
   1.132  	    update : update};})();