Ruby on Rails 3.1 standardizes on JQuery…

Rails 3.1 sounds very promising indeed. From the article on InfoWorld it looks like they made some major enhancements to performance and most interesting is the default JavaScript library is now JQuery. JQuery is clearly all over the place these days. Being the default library in Rails, WordPress, and Drupal make it almost ubiquitous in the world of open source web development.

Another change: The default JavaScript library for Ruby on Rails has been switched to jQuery. Users can easily change from the previous default library, Prototype, through a single command. Developers shouldn’t notice any difference, and going forward, Ruby on Rails will be able to harness the work being done on this popular library.

Is Eclipse fading away into the abyss?

As I read the Eclipse responses to the 2011 survey one thing that really stood out was the activity (or lack there of) in the number of respondents. The US continues to be second or third in the past two years with regards to number of respondents (maybe we are just lazy). I also would have thought, from a site which claims over a million hits per month that there would have been more than 624 people taking the survey. The survey count dropped from 1696 respondents in 2010 to just 624 in 2011 – I don’t think that’s a good thing for an open source community.

We believe a reason for the lower number of respondents is that some popular developer news sites in Germany and France had previously promoted the survey but did not promote the survey this year. This is evident by the decreased participation rate
in Germany (26% in 2010 vs 18% in 2011) and France (15% in 2010 vs 7% in 2011).

This year, the playing field seem to be leveled between Germany, France, and the United States with regards to survey respondents. But, as stated, the lack of promotion may be the cause. The US was at 16.8%, Germany reigns at 18.1% and France took a beating with only 6.9% of the respondents and India gained some ground to 5.6% – up 1.6% from last year.

Based on geographical area, Europe represented 58.9% of the respondents, North America 21.6%, and Asia 14.3%.

I also found it interesting that JQuery continues to win the popularity vote amongst developers for RIA frameworks:

Click to make larger

 

And a real shocker is the number of developers choosing Windows over the other platforms this year:

Special Effects and Dojo

If you want a slick looking site you need to master FX. There is no better way to have great FX then to use the different features in a JavaScript library like Dojo. We will start with the basic functions in the Effects area. Interestingly, both jQuery and Dojo do a good job in this space and are very similar in both API’s and supported behaviors.

If you are a CSS junky then you need to look at dojo.animate() and jquery.animate(). These methods can animate any CSS property, so the possibilities are infinite.

In Dojo, for the most control you can check out the dojo.anim() page for the different properties:

Parameter Type Description
node DOMNode|String Can be a DOM node or the id of a node (as string) to animate CSS properties on.
properties Object
duration Integer The number of milliseconds over which the animation should run. Defaults to the global animation default duration (350ms).
easing Function An easing function over which to calculate acceleration and deceleration of the animation through its duration. A default easing algorithm is provided, but you may plug in any you wish. A large selection of easing algorithms are available in dojo.fx.easing.
onEnd Function A function to be called when the animation finishes running.
delay Integer The number of milliseconds to delay beginning the animation by. The default is 0.

Mixing the duration, delay and easing properties gives you a high level of control for the animation behavior. You can also create some pretty cool effects by making DIV’s and other DOM elements have a full transparency level and then fade them in when needed. I have mixed using the Ajax techniques to go and get new DOM contents and slowly fade them in for instance. You can then override the onEnd method to provide your own function when the animation is complete. This is very useful when you need to create a full transition effect or chain animations together to create a seamless animation among multiple effects.

Over the past few versions it looks like most of the new stuff is being added to the dojo.fx package. Things like slideTo, wipeOut, wipeIn, and Toggler are all part of the FX package. These are more basic functions similar to what is provided in jQuery, which we will talk about next.

jQuery is almost identical in FX support – the methods and signatures are almost identical. You can look at the reference of $.animate(). I actually like the jQuery API a little better because you can provide a step function to change the animation during the animation. So for instance, you could have an animation that starts off fast then eases slowly to finish – very cool.

Lastly, you can also use the higher level calls for basic animation like dojo.fadeIn(), dojo.fadeOut(), or the jQuery equivalents: $.fadeIn(), $.fadeOut(). jQuery also has some other high level cool methods like $.fadeTo() and $.fadeToggle() that could come in handy.

In the end, I think jQuery excels in more higher level functions and for the most part people will probably use them versus trying to figure out all of the various ways animate() can be called. I have personally used $.hide() and $.show() a lot because they are just so simple to call and because they support the callback function it makes it very easy to chain effects together. If you want to check out all the high level effects support in jQuery check out the effects page. I really don’t like how Dojo has some functions in base dojo and others in dojo.fx, they should deprecate the dojo.XXX transition calls and just stick with dojo.fx for consistency.

http://api.jquery.com/category/effects/

Connect with Dojo

Dojo.connect() is a very powerful function. It not only allows you to connect to various DOM and user events but it also lets you connect to other JavaScript methods and custom events. You can read about connecting to custom objects and functions in the online help here.

The most common use case for dojo.connect() is probably attaching to things like buttons or DIV clicking but you should consider using the Dojo event system for more than just user interface based events. It’s a good way to create a decoupled event system for disparate components.You can learn about creating such an event system by reading the documentation on dojo.connectPublisher(). It shows how you can publish events on a specific topic.

Many times you don’t even need the dojo.connect() for UI based events because you can do that inline using the regular JavaScript way, like this:

<img
    id="btn_pin"
    style="float: right;cursor: pointer;"
    title="Un-pin Attachment"
    src="icons/pinned-down.png"
    onClick="togglePin();">
</img>

But, let’s say each page has a specific button bar action or menu action like “New”. Each page could connect its own handler to that button based on the context. So you would leave the HTML onClick() attribute blank and use dojo.connect() to handle the click event for that page:

function conectToolbar(){
  dojo.connect(dojo.byId("btn_pin"),"onclick",createNewDocument);
}

The third parameter is simply a JavaScript method in the current context.

Now, how does this stand up to jQuery? Once, again, I think Dojo offers more flexibility in this space because it essentially supports a custom event model where the traditional jQuery approach uses bind.  jquery.bind() or more commonly, $.bind(), let’s you attach to all of the common DOM events for an element. So using the powerful selector API you can attach to any DOM related event (link):

$('#foo').bind('click', function() {
  alert('User clicked on "foo."');
});

This tells jQuery to bind to the element with the id of “foo” and attach to the “click” event.  In the above sample an inline function is used but you could have specified any JavaScript function in the current context. You can learn more about the different events supported in the help. jQuery does in fact support custom event types so you could simply generate your own event names and use the trigger() method to publish the event to any listeners. This basically allows you to achieve a generic pub sub without using additional plugins. This is described really well on another blog, check it out here. From what I can tell however, there is no built in way for jQuery to do this and the referenced article talks about the plugin Peter Higgins wrote for general pub/sub. What I really like about the article is how the author actually performed tests to see how fast the jQuery custom event method performs to the general pub/sub plugin. Check out his results, they clearly show using jQuery DOM events for custom events is way slower than using the pub/sub mechanism.

So what is next? I guess one thing would be to test this same level of performance testing using Dojo pub/sub versus the connect method. I checked the Dojo source and it looks like Dojo.connect does not use the Dojo.publish/subscribe libraries under the covers so it may result in the same poor performance results as jQuery. That might just be another blog post!

Another excellent article to read is the one on DeveloperWorks by Mike Wilcox – Conquer event-driven design using dojo.connect.

2011 Focus

2010 is gone, here comes 2011!

Professionally:

This is going to be a fun and challenging year for me.  I have several areas of interest that I will be focusing on in 2011, the first and foremost is web 2.0 patterns (as is Matt) and techniques, and to follow, getting them to work seamlessly in the Eclipse and Lotus Notes client, ie. project Vulcan.  So you will continue to see various web-client integration patterns using things like Open Social API’s, Dojo, and more. The challenge will be mixing web and Eclipse based technology in a seamless and re-usable manner.  Many have already seen the attachment viewer, which was my first stab prototype at the concepts.

On the personal-professional side (ie. my hobby), I am still diving on WordPress, JQuery, MySQL, and PHP.  I always “play” in other areas that are either opposite or compliment my job at IBM.  This gives me a slightly different take in technical debates.  I always fall back to Sun Tzu – “know your enemy” – well, that’s probably extreme but I am sure someone I work with would call JQuery the enemy!  I also plan on reviewing a few books this year so I am looking for suggestions in that space.

Personally:

Lot’s of stuff going on at the home front.  With Kim and the girls fully moved in, the house is finally starting to settle; but that doesn’t mean its not somewhat chaotic on a daily basis.  With four kids in sports and with me coaching one of them it gets a bit ugly but its fun.

Book Review: Learning jQuery 1.3

This book (Learning jQuery 1.3) took me a little longer to get through, it wasn’t for the lack of interest or anything like that, it was because I was compelled to go through the samples because they were so great!  I really loved this book and I recommend it to anyone looking at jQuery.  I really love JQuery, it is simple, elegant and extremely powerful.  It is clear the creators of jQuery knew exactly what they were creating with this amazing library and community.  Since I have read the book I have been playing with plug-ins and reading the community forums.  The samples are excellent and extremely easy to follow.  Even if you are new to JavaScript this book walks you through all of it and even gives you tips for JavaScript best practices throughout the book.  While the samples are really good, what is even better is the Appendix – it has an excellent series of appendix.  There is an appendix for Tools for each of the browsers, JavaScript Closures, and a quick reference for the library.

Lastly, anyone interested in learning or getting started with jQuery I would highly recommend this great book.  I know I will use this as a reference for quite some time.

You can also preview Chapter 4 prior to buying this book.