rlm@92: // Cards = (function (){ rlm@92: rlm@92: rlm@92: // (function (info paper){ rlm@92: // info.name rlm@92: // info.occupation rlm@92: // info.email rlm@92: // info.phone rlm@92: rlm@92: rlm@92: rlm@92: rlm@92: rlm@92: rlm@92: // }); rlm@92: rlm@92: rlm@92: rlm@92: rlm@85: Buy = (function (){ rlm@92: // Utility Functinos rlm@90: rlm@92: var switchText = (function (){ rlm@92: if ($(this).val() == $(this).attr('title')) rlm@92: $(this).val('').removeClass('exampleText'); rlm@92: else if ($.trim($(this).val()) == '') rlm@92: $(this).addClass('exampleText').val($(this).attr('title'));}); rlm@90: rlm@92: rlm@92: rlm@92: rlm@92: rlm@92: // Initilization Functions. rlm@85: var order = rlm@92: {color : "green", rlm@92: style : "bold", rlm@92: quantity : 30, rlm@92: content : undefined, rlm@92: info : undefined, rlm@92: name : "Robert McIntyre", rlm@92: occupation : "AI Researcher", rlm@92: phone : "617.821.9129", rlm@92: email : "rlm@mit.edu", rlm@92: website : "www.rlmcintyre.com", rlm@92: company : "LaserKard LLC." rlm@92: }; rlm@85: rlm@85: var display; rlm@85: var color; rlm@85: var style; rlm@90: rlm@91: var state_map = { rlm@91: green : {ref : null, rlm@91: offState : {"fill" : "#030", "scale": 1} , rlm@91: onState : {"fill" : "#0F0", "scale": 1}}, rlm@91: red : {ref : null, rlm@91: offState: {"fill" : "#300", "scale" : 1}, rlm@91: onState : {"fill" : "#F00" ,"scale" : 1}}, rlm@91: blue : {ref : null, rlm@91: offState : {"fill" : "#003", "scale": 1}, rlm@91: onState : {"fill" : "#00F", "scale": 1}, rlm@91: ref : null}, rlm@91: black : {offState : null, onState : null, ref : null}, rlm@91: display : {ref : null, state : {"fill" : "black"}}}; rlm@90: rlm@90: var color_select_init = (function (){ rlm@90: state_map["red"].ref = rlm@92: color.rect(160, 1, 70, 50, 10).attr(state_map["red"].offState); rlm@90: state_map["red"].ref.node.onclick = rlm@90: (function (){order.color= "red"; update();}); rlm@90: state_map["green"].ref = rlm@92: color.rect(1, 1, 70, 50, 10).attr(state_map["green"].offState); rlm@90: state_map["green"].ref.node.onclick = rlm@90: (function (){order.color= "green"; update();}); rlm@90: state_map["blue"].ref = rlm@92: color.rect(80, 1, 70, 50, 10).attr(state_map["blue"].offState); rlm@90: state_map["blue"].ref.node.onclick = rlm@90: (function (){order.color= "blue"; update();}); rlm@90: rlm@90: toggle_on(state_map[order.color]); rlm@90: }); rlm@86: rlm@90: var display_init = (function (){ rlm@90: state_map["display"].ref = rlm@90: display.rect(1, 1, 338, 213, 20).attr(state_map["display"].state); rlm@90: }); rlm@92: rlm@92: var text_entry_init = (function (){ rlm@92: $('input[type=text][title!=""]').each(function() { rlm@92: if ($.trim($(this).val()) == ''){ rlm@92: $(this).val($(this).attr('title'));} rlm@92: if ($(this).val() == $(this).attr('title')){ rlm@92: $(this).addClass('exampleText');} rlm@92: }).focus(switchText).blur(switchText); rlm@92: rlm@92: $('form').submit(function() { rlm@92: $(this).find('input[type=text][title!=""]').each(function() { rlm@92: if ($(this).val() == $(this).attr('title')){ rlm@92: $(this).val('');}})})}); rlm@92: rlm@92: rlm@92: rlm@92: rlm@92: rlm@90: rlm@90: var init = (function () { rlm@90: display = Raphael("card-display", 340 ,215); rlm@90: color = Raphael("color-select", 300, 100); rlm@90: style = Raphael("style-select", 200, 70); rlm@90: color_select_init(); rlm@90: display_init(); rlm@92: card_init(); rlm@92: text_entry_init(); rlm@92: key_handling(); rlm@92: rlm@90: }); rlm@90: rlm@90: rlm@90: //Update Functions rlm@86: rlm@86: var toggle_on = (function (button){ rlm@90: button.ref.animate(button.onState, 2000); rlm@86: }); rlm@86: rlm@86: var toggle_off = (function (button){ rlm@90: button.ref.animate(button.offState, 2000); rlm@86: }); rlm@86: rlm@90: var color_select_update = (function (){ rlm@86: var color = order.color; rlm@86: return (function (){ rlm@86: if (order.color === color){} rlm@86: else { rlm@90: toggle_off(state_map[color]); rlm@90: toggle_on(state_map[(order.color)]); rlm@86: color = order.color;} rlm@86: });})(); rlm@86: rlm@92: var display_color_update = (function (){ rlm@90: var color = state_map.display.state.fill rlm@90: rlm@90: return (function (){ rlm@90: if (order.color === color){} rlm@90: else { rlm@91: state_map["display"].ref.animate( rlm@91: {"fill" : state_map[order.color].onState.fill}, 2000); rlm@90: color = order.color;}})})(); rlm@90: rlm@92: rlm@92: rlm@92: var display_style_update = (function (){ rlm@92: var style = null; rlm@92: return (function (){ rlm@92: if (style !== order.style){ rlm@92: ""; }}); rlm@92: }); rlm@92: rlm@92: rlm@92: var card = rlm@92: {name : {text: "Robert McIntyre", ref: ""}, rlm@92: company : {text: "", ref: ""}, rlm@92: occupation : {text: "", ref: ""}, rlm@92: phone : {text: "", ref: ""}, rlm@92: email : {text: "", ref: ""}, rlm@92: website : {text: "", ref: ""}, rlm@92: decoration : {text: "", ref: ""}}; rlm@92: rlm@92: var card_init = (function () { rlm@92: card.name.ref = display.rect(10,10,10,10,5); rlm@92: }); rlm@92: rlm@92: var key_handling = (function (){ rlm@92: var assoc = (function (target, field) { rlm@92: $(target).keyup(function() { rlm@92: field.text = $(target).val(); rlm@92: update();})}); rlm@92: assoc('#user-name', card.name); rlm@92: assoc('#user-phone', card.phone); rlm@92: assoc('#user-email', card.email); rlm@92: assoc('#user-company', card.company); rlm@92: assoc('#user-occupation', card.occupation); rlm@92: assoc('#user-website', card.website); rlm@92: rlm@92: rlm@92: }); rlm@92: rlm@92: rlm@92: rlm@92: var display_text_update = (function (){ rlm@92: var name = null; rlm@92: rlm@92: return (function () { rlm@92: rlm@92: if (name !== card.name.text){ rlm@93: rlm@92: card.name.ref.remove(); rlm@92: card.name.ref = rlm@92: display.print(10,10,card.name.text, rlm@92: display.getFont('HelveticaNeue',700), 25).attr( rlm@92: {"fill" : "#FFFFFF"}); rlm@92: rlm@92: //card.name.ref.animate({"fill" : Raphael.getColor()} ,1000); rlm@92: name = card.name.text; rlm@92: }}); rlm@92: rlm@92: rlm@92: })(); rlm@92: rlm@92: rlm@92: rlm@86: var update = (function (){ rlm@90: color_select_update(); rlm@92: display_color_update(); rlm@92: display_text_update(); rlm@92: $("#debug").html(JSON.stringify({name : card.name.text, email : card.email.text})); rlm@90: }); rlm@86: rlm@85: rlm@85: rlm@90: // return closure over state rlm@86: return {init : init, rlm@90: update : update};})(); rlm@85: rlm@85: rlm@92: rlm@92: rlm@92: rlm@92: rlm@92: rlm@92: rlm@92: rlm@85: $(document).ready(function() { rlm@90: Buy.init(); rlm@90: Buy.update(); rlm@85: });