Archive for December, 2007

Conversations to Remember

"Your [gas] is horrible."

"No, no it's not. It's like someone made you a peanut butter sandwich and you didn't even know you brought lunch."

Tags:

Still Waiting

For Zero Punctuation to get old. It seems like everything that really entertains me on the Internet has a short life. Hilarious for a week, funny for a month, meh after that. But I'm starting to doubt this will ever happen with Yahtzee. See for yourself:

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: