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