# HG changeset patch # User Robert McIntyre # Date 1280313399 14400 # Node ID 52297178e0ebce3176d4e7cd7a931e6a5824d9ba # Parent 8ed3394e6b73a16d162e0704dfed3b165f1e4c19 implemented automatic text resize diff -r 8ed3394e6b73 -r 52297178e0eb js-lib/buy3.js --- a/js-lib/buy3.js Tue Jul 27 22:23:13 2010 -0400 +++ b/js-lib/buy3.js Wed Jul 28 06:36:39 2010 -0400 @@ -1,3 +1,17 @@ +//WHY do I have to write this myself!? +Object.prototype.keys = function () +{ + var keys = []; + for(i in this) if (this.hasOwnProperty(i)) + { + keys.push(i); + } + return keys; +} + + + + Buy = (function (){ @@ -10,26 +24,64 @@ var draw_card = (function (paper){ - var helvetica = paper.getFont('HelveticaNeue', 700); - var helveticaI = paper.getFont('HelveticaNeue', 800); - var h = paper.height; - var w = paper.width; + var helvetica = paper.getFont('HelveticaNeue', 700); + var helveticaI = paper.getFont('HelveticaNeue', 800); + var h = paper.height; + var w = paper.width; + var default_color = "#AAAAAA"; - var standard = (function (text, x, y, pt, font){ - if (!font) {font = helvetica;} + // var clamp = (function (target args){ + // x = args.x || null; + // y = args.y || null; + + // if (x) { + // if (target.getBBox().width > display.width * x){ + // target.scale( + // } + // } + + // if (y) + + // }); + + var standard = (function (args){ + var pt = args.pt || 20; + var x = args.x || 0; + var y = args.y || 0; + var x_max = args.x_max || null; + var y_max = args.y_max || null; + var font = args.font || helvetica; + var text = args.text || ""; var scale_x = 0.00030*h*pt/20; var scale_y = 0.00025*w*pt/20; - return paper.print(h*x, w*y,text, font).scale( - scale_x,scale_y,h*x,w*y);}); + + + + target = paper.print(h*x, w*y,text, font).scale( + scale_x,scale_y,h*x,w*y).attr({"fill": default_color}); + + if (x_max){ + var width = target.getBBox().width; + var max_width = paper.width*x_max; + if (width > max_width){ + var x_mod = max_width/width; + target.scale(scale_x*x_mod,scale_y,0,0); + } + } + return target; + }); + + + + var bold = { "name" :(function (text){ - return standard(text, 0.2,0.1,20).attr({"fill" : "red"});}), + return standard({x_max : 0.5, "text": text, x: 0.2, y: 0.1, pt: 20});}), "email" : (function (text){ - return standard(text, 0.2,0.4,20,helveticaI).attr( - {"fill" : "red"});})}; + return standard({"text": text, x: 0.2, y: 0.4,pt: 20,font: helveticaI});})}; - + return { "bold" : bold }; @@ -134,7 +186,7 @@ var display_init = (function (){ state_map["display"].ref = - display.rect(1, 1 , display.width - 1, display.height - 2, 20).attr( + display.rect(1, 1 , display.width - 1, display.height - 2, 15).attr( state_map["display"].state); }); @@ -178,12 +230,12 @@ var init = (function () { - display = Raphael("card-display", 340 ,215); + display = Raphael("card-display", 360 ,230); color = Raphael("color-select", 300, 100); - style.bold = Raphael("bold", 170, 107); + style.bold = Raphael("bold", display.width/2, display.height/2); - style.classic = Raphael("classic", 170 , 107); + style.classic = Raphael("classic", display.width/2 , display.width/2); helvetica = display.getFont('HelveticaNeue', 700); helvetica_I = display.getFont('HelveticaNeue', 800); diff -r 8ed3394e6b73 -r 52297178e0eb kill-comments --- a/kill-comments Tue Jul 27 22:23:13 2010 -0400 +++ b/kill-comments Wed Jul 28 06:36:39 2010 -0400 @@ -1,13 +1,29 @@ -#!/usr/bin/env python +#!/usr/bin/python import subprocess import sys +import os target_file = sys.argv[1] -command = "emacs -batch " + \ +command = "emacs -batch -l ~/.emacs-batch " + \ target_file + \ - " --eval '(kill-comment (point-min) (point-max) nil)' -f save-buffer" + " --eval '(kill-comment (count-lines (point-min) (point-max)))'" + \ + " -f save-buffer" -print command -subprocess.call(command, shell=True) +#to load a custom .emacs script (for more syntax support), +#use -l in the above command + +#print command + +fnull = open(os.devnull, 'w') +subprocess.call(command, shell = True, stdout = fnull, stderr = fnull) +fnull.close() + + + + + + + + diff -r 8ed3394e6b73 -r 52297178e0eb temp342423/buy3.css --- a/temp342423/buy3.css Tue Jul 27 22:23:13 2010 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -div#debug { - position: absolute; - top:5%; - right:10%; - width: 450px; - border-color:#DD7777; - border-width:2px; - background-color:#bf3f9b; - font: bold 15px "helvetica","arial", "sans-serif"; - color: white; - height: 200px; - display : none; -} - -div#text-entry { - position : absolute; - top : 15%; - left : 25%; - width : 150px; -} - -.hidden { - display : none; -} - -input.exampleText { - color: #aaa; -} diff -r 8ed3394e6b73 -r 52297178e0eb temp342423/buy3.js --- a/temp342423/buy3.js Tue Jul 27 22:23:13 2010 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,310 +0,0 @@ - -Buy = (function (){ - - - - var magic_font_ratio = 318; - var mfg = magic_font_ratio; - - - - var draw_card = (function (paper){ - - var helvetica = paper.getFont('HelveticaNeue', 700); - var helveticaI = paper.getFont('HelveticaNeue', 800); - var h = paper.height; - var w = paper.width; - - var standard = (function (text, x, y, pt, font){ - if (!font) {font = helvetica;} - var scale_x = 0.00030*h*pt/20; - var scale_y = 0.00025*w*pt/20; - return paper.print(h*x, w*y,text, font).scale( - scale_x,scale_y,h*x,w*y);}); - - var bold = { - "name" :(function (text){ - return standard(text, 0.2,0.1,20).attr({"fill" : "red"});}), - "email" : (function (text){ - return standard(text, 0.2,0.4,20,helveticaI).attr( - {"fill" : "red"});})}; - - - return { - "bold" : bold - }; - - }); - - - - - - - - - - - - - - - - var switchText = (function (){ - if ($(this).val() == $(this).attr('title')) - $(this).val('').removeClass('exampleText'); - else if ($.trim($(this).val()) == '') - $(this).addClass('exampleText').val($(this).attr('title'));}); - - - var deref = (function (var_name){return var_name;}); - - - - - - var card; - - var card_init = (function () { - - card = { - name : {text: "Robert McIntyre", ref: display.set()}, - company : {text: "", ref: display.set()}, - occupation : {text: "", ref: display.set()}, - phone : {text: "", ref: display.set()}, - email : {text: "rlm@mit.edu", ref: display.set()}, - website : {text: "", ref: display.set()}, - decoration : {text: "", ref: display.set()}}; - }); - - - var order = - {color : "blue", - style : "bold", - quantity : 30, - content : undefined, - info : undefined, - name : "Robert McIntyre", - occupation : "AI Researcher", - phone : "617.821.9129", - email : "rlm@mit.edu", - website : "www.rlmcintyre.com", - company : "LaserKard LLC." - }; - - var display; - var color; - var style = {}; - var helvetica; - var helvetica_I; - - var state_map = { - bold : null, - classic : null, - - green : {ref : null, - offState : {"fill" : "#030", "scale": 1} , - onState : {"fill" : "#0F0", "scale": 1}}, - red : {ref : null, - offState: {"fill" : "#300", "scale" : 1}, - onState : {"fill" : "#F00" ,"scale" : 1}}, - blue : {ref : null, - offState : {"fill" : "#003", "scale": 1}, - onState : {"fill" : "#00F", "scale": 1}, - ref : null}, - black : {offState : null, onState : null, ref : null}, - display : {ref : null, state : {"fill" : "black"}}}; - - var color_select_init = (function (){ - state_map["red"].ref = - color.rect(160, 1, 70, 50, 10).attr(state_map["red"].offState); - state_map["red"].ref.node.onclick = - (function (){order.color= "red"; update();}); - state_map["green"].ref = - color.rect(1, 1, 70, 50, 10).attr(state_map["green"].offState); - state_map["green"].ref.node.onclick = - (function (){order.color= "green"; update();}); - state_map["blue"].ref = - color.rect(80, 1, 70, 50, 10).attr(state_map["blue"].offState); - state_map["blue"].ref.node.onclick = - (function (){order.color= "blue"; update();}); - - toggle_on(state_map[order.color]); - }); - - var display_init = (function (){ - state_map["display"].ref = - display.rect(1, 1 , display.width - 1, display.height - 2, 20).attr( - state_map["display"].state); - }); - - var text_entry_init = (function (){ - $('input[type=text][title!=""]').each(function() { - if ($.trim($(this).val()) == ''){ - $(this).val($(this).attr('title'));} - if ($(this).val() == $(this).attr('title')){ - $(this).addClass('exampleText');} - }).focus(switchText).blur(switchText); - - $('form').submit(function() { - $(this).find('input[type=text][title!=""]').each(function() { - if ($(this).val() == $(this).attr('title')){ - $(this).val('');}})})}); - - var style_text = { - phone : "617.821.9129", - email : "rlm@mit.edu", - website : "www.rlmcintyre.com", - name : "Robert McIntyre", - company : "LaserKard LLC.", - occupation : "AI Researcher"} - - - var style_init = (function (){ - var draw = draw_card(style.bold); - draw.bold.name(style_text.name); - style.bold.rect(1, 1 ,style.bold.width - 1, style.bold.height - 2, 10); - draw.bold.email(style_text.email); - - - - - - - - }); - - - - - var init = (function () { - display = Raphael("card-display", 340 ,215); - color = Raphael("color-select", 300, 100); - - style.bold = Raphael("bold", 170, 107); - - style.classic = Raphael("classic", 170 , 107); - - helvetica = display.getFont('HelveticaNeue', 700); - helvetica_I = display.getFont('HelveticaNeue', 800); - color_select_init(); - display_init(); - card_init(); - text_entry_init(); - key_handling(); - style_init(); - update(); - }); - - - - - var toggle_on = (function (button){ - button.ref.animate(button.onState, 2000); - }); - - var toggle_off = (function (button){ - button.ref.animate(button.offState, 2000); - }); - - var color_select_update = (function (){ - var color = order.color; - return (function (){ - if (order.color === color){} - else { - toggle_off(state_map[color]); - toggle_on(state_map[(order.color)]); - color = order.color;} - });})(); - - var display_color_update = (function (){ - var color = state_map.display.state.fill - - return (function (){ - if (order.color === color){} - else { - state_map["display"].ref.animate( - {"fill" : state_map[order.color].onState.fill}, 2000); - color = order.color;}})})(); - - var display_style_update = (function (){ - var style = null; - return (function (){ - if (style !== order.style){ - ""; }}); - }); - - var key_handling = (function (){ - var assoc = (function (target, field) { - $(target).keyup(function() { - field.text = $(target).val(); - update();})}); - assoc('#user-name', card.name); - assoc('#user-phone', card.phone); - assoc('#user-email', card.email); - assoc('#user-company', card.company); - assoc('#user-occupation', card.occupation); - assoc('#user-website', card.website); - }); - - var display_style_update = (function (){ - var style = null; - - return (function () { - var draw = draw_card(display); - if (style !== order.style){ - for ( var property in card ){ - if (!draw[order.style][(deref(property))]){ - $("#user" + "-" + property).toggle(400);}} - style = order.style;} - });})(); - - var display_text_update = (function (){ - var state = {name : "nothing", - phone: "nothing", - email: "nothing", - occupation: "nothing", - company : "nothing", - website : "nothing" }; - - var check_text = (function (var_name) { - var draw = draw_card(display); - if (state[deref(var_name)] !== (card[deref(var_name)]).text){ - if (draw[order.style][deref(var_name)]) { - card[deref(var_name)].ref.remove(); - card[var_name].ref = - draw[order.style][deref(var_name)]( - card[deref(var_name)].text,display); - state[deref(var_name)] = card[deref(var_name)].text; - }}}); - - return (function (){ - check_text("name"); - check_text("phone"); - check_text("email"); - check_text("occupation"); - check_text("company"); - check_text("website"); - - $("#debug").html(JSON.stringify(state)); - }); - - })(); - - var update = (function (){ - color_select_update(); - display_color_update(); - display_text_update(); - display_style_update(); - }); - - - return {init : init, - update : update};})(); - - - -$(document).ready(function() { - Buy.init(); - Buy.update(); - }); diff -r 8ed3394e6b73 -r 52297178e0eb temp342423/kill-comments --- a/temp342423/kill-comments Tue Jul 27 22:23:13 2010 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -#!/usr/bin/python - -import subprocess -import sys -import os - -target_file = sys.argv[1] - -command = "emacs -batch -l ~/.emacs-bash " + \ - target_file + \ - " --eval '(kill-comment (count-lines (point-min) (point-max)))'" - -#to load a custom .emacs script (for more syntax support), -#use -l in the above command - -#print command - -fnull = open(os.devnull, 'w') -result = subprocess.call(command, shell = True, stdout = fnull, stderr = fnull) -fnull.close() - - - - - - - - diff -r 8ed3394e6b73 -r 52297178e0eb temp342423/server.clj --- a/temp342423/server.clj Tue Jul 27 22:23:13 2010 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -(ns laserkard.server - (:use (compojure.http request servlet session routes) - (compojure.server jetty) - (compojure control) - (laserkard buy-temp faq) - -)) - -(defroutes example - (GET "/index.clj" [] "

hello, connie, good to meet you

") - (GET "/buy-temp.clj" [] (buy-gen)) - (GET "/faq.clj" [] (faq)) -) - - - -(defserver laserkard-server - {:port 9000 :host "localhost"} - "/*" (servlet example)) - - - ;adasdas - -;asdas - - -