rlm@92
|
1 // Cards = (function (){
|
rlm@92
|
2
|
rlm@92
|
3
|
rlm@92
|
4 // (function (info paper){
|
rlm@92
|
5 // info.name
|
rlm@92
|
6 // info.occupation
|
rlm@92
|
7 // info.email
|
rlm@92
|
8 // info.phone
|
rlm@92
|
9
|
rlm@92
|
10
|
rlm@92
|
11
|
rlm@92
|
12
|
rlm@92
|
13
|
rlm@92
|
14
|
rlm@92
|
15 // });
|
rlm@92
|
16
|
rlm@92
|
17
|
rlm@92
|
18
|
rlm@94
|
19
|
rlm@94
|
20
|
rlm@94
|
21
|
rlm@92
|
22
|
rlm@85
|
23 Buy = (function (){
|
rlm@94
|
24
|
rlm@94
|
25 //Cards drawing functions:
|
rlm@94
|
26
|
rlm@94
|
27 var Cards =
|
rlm@94
|
28 {"bold" : {
|
rlm@94
|
29 "name" :(function (text, display){
|
rlm@94
|
30 return display.print(10,10,text,helvetica, 25).attr(
|
rlm@95
|
31 {"fill" : "#0F0"});}),
|
rlm@95
|
32 "email" : (function (text, paper){
|
rlm@95
|
33 return paper.print(50,50,text,helvetica_I,40).attr(
|
rlm@95
|
34 {"fill" : "red"});})
|
rlm@95
|
35
|
rlm@95
|
36
|
rlm@95
|
37 }};
|
rlm@95
|
38
|
rlm@95
|
39
|
rlm@94
|
40
|
rlm@94
|
41
|
rlm@94
|
42
|
rlm@94
|
43
|
rlm@92
|
44 // Utility Functinos
|
rlm@90
|
45
|
rlm@94
|
46
|
rlm@94
|
47
|
rlm@94
|
48
|
rlm@94
|
49
|
rlm@92
|
50 var switchText = (function (){
|
rlm@92
|
51 if ($(this).val() == $(this).attr('title'))
|
rlm@92
|
52 $(this).val('').removeClass('exampleText');
|
rlm@92
|
53 else if ($.trim($(this).val()) == '')
|
rlm@92
|
54 $(this).addClass('exampleText').val($(this).attr('title'));});
|
rlm@90
|
55
|
rlm@92
|
56
|
rlm@92
|
57
|
rlm@92
|
58
|
rlm@92
|
59
|
rlm@92
|
60 // Initilization Functions.
|
rlm@95
|
61 var card =
|
rlm@95
|
62 {name : {text: "Robert McIntyre", ref: ""},
|
rlm@95
|
63 company : {text: "", ref: ""},
|
rlm@95
|
64 occupation : {text: "", ref: ""},
|
rlm@95
|
65 phone : {text: "", ref: ""},
|
rlm@95
|
66 email : {text: "rlm@mit.edu", ref: ""},
|
rlm@95
|
67 website : {text: "", ref: ""},
|
rlm@95
|
68 decoration : {text: "", ref: ""}};
|
rlm@95
|
69
|
rlm@95
|
70 var card_init = (function () {
|
rlm@95
|
71 card.name.ref = display.set();
|
rlm@95
|
72 card.company.ref = display.set();
|
rlm@95
|
73 card.occupation.ref = display.set();
|
rlm@95
|
74 card.phone.ref = display.set();
|
rlm@95
|
75 card.email.ref = display.set();
|
rlm@95
|
76 card.website.ref = display.set();
|
rlm@95
|
77 card.decoration.ref = display.set();
|
rlm@95
|
78 });
|
rlm@95
|
79
|
rlm@95
|
80
|
rlm@85
|
81 var order =
|
rlm@92
|
82 {color : "green",
|
rlm@92
|
83 style : "bold",
|
rlm@92
|
84 quantity : 30,
|
rlm@92
|
85 content : undefined,
|
rlm@92
|
86 info : undefined,
|
rlm@92
|
87 name : "Robert McIntyre",
|
rlm@92
|
88 occupation : "AI Researcher",
|
rlm@92
|
89 phone : "617.821.9129",
|
rlm@92
|
90 email : "rlm@mit.edu",
|
rlm@92
|
91 website : "www.rlmcintyre.com",
|
rlm@92
|
92 company : "LaserKard LLC."
|
rlm@92
|
93 };
|
rlm@85
|
94
|
rlm@85
|
95 var display;
|
rlm@85
|
96 var color;
|
rlm@85
|
97 var style;
|
rlm@94
|
98 var helvetica;
|
rlm@94
|
99 var helvetica_I;
|
rlm@90
|
100
|
rlm@91
|
101 var state_map = {
|
rlm@91
|
102 green : {ref : null,
|
rlm@91
|
103 offState : {"fill" : "#030", "scale": 1} ,
|
rlm@91
|
104 onState : {"fill" : "#0F0", "scale": 1}},
|
rlm@91
|
105 red : {ref : null,
|
rlm@91
|
106 offState: {"fill" : "#300", "scale" : 1},
|
rlm@91
|
107 onState : {"fill" : "#F00" ,"scale" : 1}},
|
rlm@91
|
108 blue : {ref : null,
|
rlm@91
|
109 offState : {"fill" : "#003", "scale": 1},
|
rlm@91
|
110 onState : {"fill" : "#00F", "scale": 1},
|
rlm@91
|
111 ref : null},
|
rlm@91
|
112 black : {offState : null, onState : null, ref : null},
|
rlm@91
|
113 display : {ref : null, state : {"fill" : "black"}}};
|
rlm@90
|
114
|
rlm@90
|
115 var color_select_init = (function (){
|
rlm@90
|
116 state_map["red"].ref =
|
rlm@92
|
117 color.rect(160, 1, 70, 50, 10).attr(state_map["red"].offState);
|
rlm@90
|
118 state_map["red"].ref.node.onclick =
|
rlm@90
|
119 (function (){order.color= "red"; update();});
|
rlm@90
|
120 state_map["green"].ref =
|
rlm@92
|
121 color.rect(1, 1, 70, 50, 10).attr(state_map["green"].offState);
|
rlm@90
|
122 state_map["green"].ref.node.onclick =
|
rlm@90
|
123 (function (){order.color= "green"; update();});
|
rlm@90
|
124 state_map["blue"].ref =
|
rlm@92
|
125 color.rect(80, 1, 70, 50, 10).attr(state_map["blue"].offState);
|
rlm@90
|
126 state_map["blue"].ref.node.onclick =
|
rlm@90
|
127 (function (){order.color= "blue"; update();});
|
rlm@90
|
128
|
rlm@90
|
129 toggle_on(state_map[order.color]);
|
rlm@90
|
130 });
|
rlm@86
|
131
|
rlm@90
|
132 var display_init = (function (){
|
rlm@90
|
133 state_map["display"].ref =
|
rlm@90
|
134 display.rect(1, 1, 338, 213, 20).attr(state_map["display"].state);
|
rlm@90
|
135 });
|
rlm@92
|
136
|
rlm@92
|
137 var text_entry_init = (function (){
|
rlm@92
|
138 $('input[type=text][title!=""]').each(function() {
|
rlm@92
|
139 if ($.trim($(this).val()) == ''){
|
rlm@92
|
140 $(this).val($(this).attr('title'));}
|
rlm@92
|
141 if ($(this).val() == $(this).attr('title')){
|
rlm@92
|
142 $(this).addClass('exampleText');}
|
rlm@92
|
143 }).focus(switchText).blur(switchText);
|
rlm@92
|
144
|
rlm@92
|
145 $('form').submit(function() {
|
rlm@92
|
146 $(this).find('input[type=text][title!=""]').each(function() {
|
rlm@92
|
147 if ($(this).val() == $(this).attr('title')){
|
rlm@92
|
148 $(this).val('');}})})});
|
rlm@92
|
149
|
rlm@92
|
150
|
rlm@92
|
151
|
rlm@92
|
152
|
rlm@92
|
153
|
rlm@90
|
154
|
rlm@90
|
155 var init = (function () {
|
rlm@90
|
156 display = Raphael("card-display", 340 ,215);
|
rlm@90
|
157 color = Raphael("color-select", 300, 100);
|
rlm@90
|
158 style = Raphael("style-select", 200, 70);
|
rlm@94
|
159 helvetica = display.getFont('HelveticaNeue', 700);
|
rlm@94
|
160 helvetica_I = display.getFont('HelveticaNeue', 800);
|
rlm@94
|
161
|
rlm@90
|
162 color_select_init();
|
rlm@90
|
163 display_init();
|
rlm@92
|
164 card_init();
|
rlm@92
|
165 text_entry_init();
|
rlm@92
|
166 key_handling();
|
rlm@94
|
167 update();
|
rlm@90
|
168 });
|
rlm@90
|
169
|
rlm@90
|
170
|
rlm@90
|
171 //Update Functions
|
rlm@86
|
172
|
rlm@86
|
173 var toggle_on = (function (button){
|
rlm@90
|
174 button.ref.animate(button.onState, 2000);
|
rlm@86
|
175 });
|
rlm@86
|
176
|
rlm@86
|
177 var toggle_off = (function (button){
|
rlm@90
|
178 button.ref.animate(button.offState, 2000);
|
rlm@86
|
179 });
|
rlm@86
|
180
|
rlm@90
|
181 var color_select_update = (function (){
|
rlm@86
|
182 var color = order.color;
|
rlm@86
|
183 return (function (){
|
rlm@86
|
184 if (order.color === color){}
|
rlm@86
|
185 else {
|
rlm@90
|
186 toggle_off(state_map[color]);
|
rlm@90
|
187 toggle_on(state_map[(order.color)]);
|
rlm@86
|
188 color = order.color;}
|
rlm@86
|
189 });})();
|
rlm@86
|
190
|
rlm@92
|
191 var display_color_update = (function (){
|
rlm@90
|
192 var color = state_map.display.state.fill
|
rlm@90
|
193
|
rlm@90
|
194 return (function (){
|
rlm@90
|
195 if (order.color === color){}
|
rlm@90
|
196 else {
|
rlm@91
|
197 state_map["display"].ref.animate(
|
rlm@91
|
198 {"fill" : state_map[order.color].onState.fill}, 2000);
|
rlm@90
|
199 color = order.color;}})})();
|
rlm@90
|
200
|
rlm@92
|
201
|
rlm@92
|
202
|
rlm@92
|
203 var display_style_update = (function (){
|
rlm@92
|
204 var style = null;
|
rlm@92
|
205 return (function (){
|
rlm@92
|
206 if (style !== order.style){
|
rlm@92
|
207 ""; }});
|
rlm@92
|
208 });
|
rlm@92
|
209
|
rlm@92
|
210
|
rlm@92
|
211
|
rlm@92
|
212 var key_handling = (function (){
|
rlm@92
|
213 var assoc = (function (target, field) {
|
rlm@92
|
214 $(target).keyup(function() {
|
rlm@92
|
215 field.text = $(target).val();
|
rlm@92
|
216 update();})});
|
rlm@92
|
217 assoc('#user-name', card.name);
|
rlm@92
|
218 assoc('#user-phone', card.phone);
|
rlm@92
|
219 assoc('#user-email', card.email);
|
rlm@92
|
220 assoc('#user-company', card.company);
|
rlm@92
|
221 assoc('#user-occupation', card.occupation);
|
rlm@92
|
222 assoc('#user-website', card.website);
|
rlm@94
|
223 });
|
rlm@92
|
224
|
rlm@92
|
225
|
rlm@92
|
226 var display_text_update = (function (){
|
rlm@95
|
227 var state = {name : "nothing",
|
rlm@95
|
228 phone: "nothing",
|
rlm@95
|
229 email: "nothing"};
|
rlm@95
|
230 //what an asinine function... referential transparency blah blah...
|
rlm@95
|
231 var deref = (function (var_name){return var_name;});
|
rlm@92
|
232
|
rlm@95
|
233 var check_text = (function (var_name) {
|
rlm@95
|
234 if (state[deref(var_name)] !== (card[deref(var_name)]).text){
|
rlm@95
|
235 if (Cards[order.style][deref(var_name)]) {
|
rlm@95
|
236 card[deref(var_name)].ref.remove();
|
rlm@95
|
237 card[var_name].ref =
|
rlm@95
|
238 Cards[order.style][deref(var_name)](
|
rlm@95
|
239 card[deref(var_name)].text,display);
|
rlm@95
|
240 state[deref(var_name)] = card[deref(var_name)].text;
|
rlm@95
|
241 }}});
|
rlm@95
|
242
|
rlm@95
|
243 return (function (){
|
rlm@95
|
244 check_text("name");
|
rlm@95
|
245 check_text("phone");
|
rlm@95
|
246 check_text("email");
|
rlm@95
|
247 $("#debug").html(JSON.stringify(state));
|
rlm@95
|
248 });
|
rlm@95
|
249
|
rlm@92
|
250 })();
|
rlm@92
|
251
|
rlm@92
|
252
|
rlm@92
|
253
|
rlm@86
|
254 var update = (function (){
|
rlm@90
|
255 color_select_update();
|
rlm@92
|
256 display_color_update();
|
rlm@92
|
257 display_text_update();
|
rlm@95
|
258 // $("#debug").html(JSON.stringify({name : card.name.text, email : card.email.text, phone : card.phone.text}));
|
rlm@90
|
259 });
|
rlm@86
|
260
|
rlm@85
|
261
|
rlm@85
|
262
|
rlm@90
|
263 // return closure over state
|
rlm@86
|
264 return {init : init,
|
rlm@90
|
265 update : update};})();
|
rlm@85
|
266
|
rlm@85
|
267
|
rlm@92
|
268
|
rlm@92
|
269
|
rlm@92
|
270
|
rlm@92
|
271
|
rlm@92
|
272
|
rlm@92
|
273
|
rlm@92
|
274
|
rlm@85
|
275 $(document).ready(function() {
|
rlm@90
|
276 Buy.init();
|
rlm@90
|
277 Buy.update();
|
rlm@85
|
278 });
|