changeset 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
files js-lib/buy3.js
diffstat 1 files changed, 52 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/js-lib/buy3.js	Mon Jul 26 20:33:17 2010 -0400
     1.2 +++ b/js-lib/buy3.js	Mon Jul 26 21:42:20 2010 -0400
     1.3 @@ -28,8 +28,15 @@
     1.4  	{"bold" : {
     1.5  	    "name" :(function (text, display){
     1.6  		return display.print(10,10,text,helvetica, 25).attr(
     1.7 -		    {"fill" : "#FFFFFF"});
     1.8 -	    })}};
     1.9 +		    {"fill" : "#0F0"});}),
    1.10 +	    "email" : (function (text, paper){
    1.11 +		return paper.print(50,50,text,helvetica_I,40).attr(
    1.12 +		    {"fill" : "red"});})
    1.13 +		
    1.14 +		
    1.15 +	    }};
    1.16 +
    1.17 +
    1.18  
    1.19      
    1.20  
    1.21 @@ -51,6 +58,26 @@
    1.22  
    1.23  
    1.24      // Initilization Functions.
    1.25 +    var card = 
    1.26 +	{name       : {text: "Robert McIntyre", ref: ""},
    1.27 +	 company    : {text: "", ref: ""},
    1.28 +	 occupation : {text: "", ref: ""},
    1.29 +	 phone      : {text: "", ref: ""},
    1.30 +	 email      : {text: "rlm@mit.edu", ref: ""},
    1.31 +	 website    : {text: "", ref: ""},
    1.32 +	 decoration : {text: "", ref: ""}};
    1.33 +
    1.34 +    var card_init = (function () {
    1.35 +	card.name.ref = display.set();
    1.36 +	card.company.ref = display.set();
    1.37 +	card.occupation.ref = display.set();
    1.38 +	card.phone.ref = display.set();
    1.39 +	card.email.ref = display.set();
    1.40 +	card.website.ref = display.set();
    1.41 +	card.decoration.ref = display.set();
    1.42 +    });
    1.43 +
    1.44 +
    1.45      var order = 
    1.46  	{color : "green",
    1.47  	 style : "bold",
    1.48 @@ -181,18 +208,6 @@
    1.49  	});
    1.50  
    1.51  
    1.52 -    var card = 
    1.53 -	{name       : {text: "Robert McIntyre", ref: ""},
    1.54 -	 company    : {text: "", ref: ""},
    1.55 -	 occupation : {text: "", ref: ""},
    1.56 -	 phone      : {text: "", ref: ""},
    1.57 -	 email      : {text: "", ref: ""},
    1.58 -	 website    : {text: "", ref: ""},
    1.59 -	 decoration : {text: "", ref: ""}};
    1.60 -
    1.61 -    var card_init = (function () {
    1.62 -	card.name.ref = display.rect(10,10,10,10,5);
    1.63 -    });
    1.64  
    1.65      var key_handling = (function (){
    1.66  	var assoc = (function (target, field) {
    1.67 @@ -209,17 +224,29 @@
    1.68  
    1.69  
    1.70      var display_text_update = (function (){
    1.71 -	var name = null;
    1.72 +	var state = {name : "nothing",
    1.73 +		     phone: "nothing",
    1.74 +		     email: "nothing"};
    1.75 +	//what an asinine function... referential transparency blah blah...
    1.76 +	var deref = (function (var_name){return var_name;});
    1.77  
    1.78 -	var check_text = (function () {                         
    1.79 -	    if (name !== card.name.text){
    1.80 -		card.name.ref.remove();
    1.81 -		card.name.ref = Cards[order.style].name(card.name.text, display);
    1.82 -		name = card.name.text;
    1.83 -	    }});
    1.84 -	return check_text;
    1.85 -	    
    1.86 -
    1.87 +	var check_text = (function (var_name) {                         
    1.88 +	    if (state[deref(var_name)] !== (card[deref(var_name)]).text){
    1.89 +		if (Cards[order.style][deref(var_name)]) {
    1.90 +		    card[deref(var_name)].ref.remove();
    1.91 +	    	    card[var_name].ref = 
    1.92 +	     		Cards[order.style][deref(var_name)](
    1.93 +			    card[deref(var_name)].text,display);
    1.94 +	     	    state[deref(var_name)] = card[deref(var_name)].text;
    1.95 +		}}});
    1.96 +	
    1.97 +	return (function (){
    1.98 +	    check_text("name");
    1.99 +	    check_text("phone");
   1.100 +	    check_text("email");
   1.101 +	    $("#debug").html(JSON.stringify(state));
   1.102 +	});
   1.103 +	
   1.104      })();
   1.105        
   1.106      
   1.107 @@ -228,7 +255,7 @@
   1.108  	color_select_update();
   1.109  	display_color_update();
   1.110  	display_text_update();
   1.111 -	$("#debug").html(JSON.stringify({name : card.name.text, email : card.email.text}));
   1.112 +//	$("#debug").html(JSON.stringify({name : card.name.text, email : card.email.text, phone : card.phone.text}));
   1.113      });
   1.114      
   1.115