first_page

Over 800 Lines of jQuery Later…

Buy this Book at Amazon.com!I am not being sarcastic: with jQuery you do write less and do more. The ‘over 800 lines’ is less than what is needed for my YUI 2.x JavaScript base. Apart from the brilliant syntax, much of this reduction is due to the plug-in culture of jQuery. I’m sure jQuery veterans would ask, why would need even 800 lines? These are the generalities that I’m for:

  • $.rx.client extension functions to define how I organize the Client and define conventional ways of producing jQuery-UI-based alert and confirm messages. One format for alerts and one for confirmations is shared by the entire Client application. There is also a cute little helper function, $.rx.client.setKeydownTrigger() which wires keydown triggers of other events—usually click events. Respect goes out to Nadia Alramli for showing me how this is done in jQuery via StackOverflow.com.
  • $.rx.ajax extension functions to define how I attach an event to an AJAX call. The options object literal (a jQuery convention) can be configured to support a confirmation before an AJAX call. I sacrificed the terseness of the post() and get() methods for this flexibility. One notable convention is the conventional invocation of $.rx.client.displayBuilder.build() when the AJAX complete event fires. This conventional build() function uses the super-power of jQuery to—you guessed it—query the elements returned from the AJAX call to attach events and format.
  • $.rx.dateTime is not doing much right now. It has one extension function I use it to append the current time to date values from the Datepicker.
  • $.rx.validation extension functions of my legacy <form/> validation code that has been maintained for over a decade. This old stuff is still useful even in view of the Validation plugin by Jörn Zaefferer.One very important thing I’ve learned about jQuery is that it is wrapper over DOM elements. Concealing DOM elements is not a design goal. You can have your old DOM elements back with $(selector).get(n) or $(selector)[n]. This means that my old code can still work.

Another important bit is the jQuery.extend() function. It took me way too long to see its importance in “name-spacing”:$.extend({rx:{}}); //$.rx

$.extend($.rx, {client:{}}); //$.rx.client I use the term extension function for jQuery procedures that are not chaining the jQuery object. You don’t need a selector query to get these helpers. The term extension method refers to procedures in the jQuery chain.

rasx()