Archive for category Code

On Starting a Project

Starting a project is one of those moments of sheer pleasure for developers, the clean sheet. While you're laying foundations on web apps, you often need some way of interacting with the plumbing. Old friends may remember "Peterson Style", named for an ex-coworker who would roll 16 pixel Times New Roman black on white up 'til the last second he could get away with it. After a few years of working with world-class visual designers and usability folks, it pained me to do that. The first thing I usually do is create a tiny stylesheet that adds some padding to the page and changes the font to something less grating. Along the way I'll play with potential interactive bits for the interface, which is one of the ways I got involved in the usability and interactivity discussions at work in the first place. Now that I'm off on my own, this gets a little more challenging. When I'd spent years with a team, people had no problem telling me to remove some overly rococo bit of JavaScript widgetry, but when you don't each other, it's a trickier conversation. Plus people assume you have some emotional investment in what you put on the page; only the most autistic are going to roll right over something someone spent time on (and the most autistic are all other developers, not ui people). But if the choices are fait accompli or accept the average, my inner Catholic schoolboy will go with the fancy Latin everytime.

Clone Table Rows with Form Elements in a .NET Style

Using jQuery to coax .NET into cloning table rows with properly numbered id/ name attributes:

  1.  
  2. var MyNamespace = {
  3. init: function()
  4. {
  5. // attach row clone to passenger table
  6. $("table#tblPassengers tr:last :input").change(function() {MyNamespace.cloneRow("tblPassengers")});
  7.  
  8. // attach row clone to contacts table
  9. $("table#tblContacts tr:last :input").change(function() {MyNamespace.cloneRow("tblContacts")});
  10. },
  11.  
  12. cloneRow: function(sTableId)
  13. {
  14. var oRow = $("table#{0} tr:last :input".format(sTableId));
  15. oRow.unbind("change");
  16.  
  17. var oNewRow = $("table#{0} tr:last".format(sTableId)).clone();
  18.  
  19. $(":input", oNewRow).each(
  20. function ()
  21. {
  22. MyNamespace.cloneInput($(this));
  23. }
  24. );
  25.  
  26. $("table#{0}".format(sTableId)).append(oNewRow);
  27. $("table#{0} tr:last :input".format(sTableId)).change(function() {Flights.cloneRow(sTableId)});
  28. },
  29.  
  30. cloneInput: function(oInput)
  31. {
  32. oInput.val("");
  33. var oRegex = new RegExp(/[^"]ctl(\d+)/g);
  34.  
  35. var sId = oInput.attr("id");
  36. oRegex.exec(sId);
  37. var iIdCount = parseInt(RegExp.$1[1]);
  38. var sFind = "ctl" + MyNamespace.padIntegerString(iIdCount, 2);
  39. var sReplace = "ctl" + MyNamespace.padIntegerString(++iIdCount, 2);
  40. oInput.attr("id", sId.replace(sFind, sReplace));
  41. oInput.attr("name", oInput.attr("name").replace(sFind, sReplace));
  42. },
  43.  
  44. padIntegerString: function(iInt, iNumberOfCharacters)
  45. {
  46. var sTest = iInt + "";
  47. if (sTest.length >= iNumberOfCharacters)
  48. {
  49. return sTest;
  50. }
  51. var sPad = "";
  52. for (var i = 0; i < iNumberOfCharacters - 1; i++)
  53. {
  54. sPad += "0";
  55. }
  56. return sPad + iInt;
  57. },
  58. };
  59.  

Tags:

Rails 2.0 Released

2.0.1, actually. Now I just need an excuse to use it somewhere.

Tags:

Me and .NET

We get along so well:

Try Catch Drop

Tags: