Plugins Entries

Using Low Pro for jQuery

Monday, May 12th, 2008

Recently I have been getting a real buzz out of developing with jQuery. I’ve been using the library since 2006, releasing sporadic bits of code. In April of this year, I released the third revision of my most complex plugin, jMaps, and updated several other plugins, which are available in my mercurial repository.

This was also the same month I discovered a new plugin which has dramatically changed how I develop applications with jQuery. The plugin in question is Dan Webb’s Low Pro for jQuery, a port of the plugin of the same name for Prototype.

What is Low Pro?

So what is Low Pro? It’s a plugin that provides a way of making more object-oriented JavaScript through event delegation. jQuery’s plugin architecture provides a really simple way of extending the core functionality, but there is no easy way of making macros of code that do several types of events on one element. Until now!
(more…)

Simple Effects Plugins

Tuesday, February 12th, 2008

jQuery has a nice selection of core animation effects, such as .show('speed') and .hide('speed'), .slideUp() and .slideDown(), and .fadeIn() and .fadeOut(). It even has a couple methods for toggling effects — the aptly named .toggle('speed') and .slideToggle().

All of these methods have optional speed, easing, and callback arguments — although a couple are special cases. The .show() and .hide() methods, when used without a speed, will immediately show and hide the matched set of elements with no animation. When the speed argument is included, the matched elements are shown and hidden gradually by animating their height, width, and opacity simultaneously. The .toggle() method shares its name with a method that takes two arguments that alternate being triggered. All of the other effect methods have a default speed of 400ms.
(more…)

Questions and Answers from the List

Wednesday, December 19th, 2007

I’ve been feeling guilty lately about my lack of posts to this blog. But when I looked at my profile for the jQuery Google Group and discovered that for the past six months I’ve posted an average of 100+ times each month, well, I decided to give myself a break. Since I’m sure some people who stumble upon this blog aren’t subscribed to the Google group/mailing list, here are a few (edited) questions that have appeared there recently, along with my (edited) answers. I hope some of you find them helpful.
(more…)

Managing the creative process behind a jQuery plugin

Monday, December 10th, 2007

An excellent post by Mike Alsup described a plugin development pattern that has served him quite well over time. I have used BlockUI (an Alsup creation) on several projects, and it is readily apparent that Mike knows his stuff. The one thing I have always enjoyed and appreciated most about this particular plugin, however, is the simplicity of the implementation. You could argue that this was a creative decision, having little to do with the actual development. I will not speak for Mike, but for me the degree of simplicity is indeed one of the many creative decisions that I make every time I develop a jQuery plugin. (more…)

A Plugin Development Pattern

Tuesday, October 30th, 2007

I’ve been developing jQuery plugins for quite a while now, and I’ve become rather comfortable with a particular style of plugin development for my scripts. This article is meant to share the pattern that I’ve found especially useful for plugin authoring. It assumes you already have an understanding of plugin development for jQuery; if you’re a novice plugin author, please review the jQuery Authoring Guidelines first.

There are a few requirements that I feel this pattern handles nicely:

  1. Claim only a single name in the jQuery namespace
  2. Accept an options argument to control plugin behavior
  3. Provide public access to default plugin settings
  4. Provide public access to secondary functions (as applicable)
  5. Keep private functions private
  6. Support the Metadata Plugin

I’ll cover these requirements one by one, and as we work through them we’ll build a simple plugin which highlights text.
(more…)

Namespace Your Events

Thursday, September 20th, 2007

A common pattern in jQuery plugin development is the need to undo what the plugin has done. This is usually handled through a method prefixed with “un”. Another common pattern is the use of anonymous functions for event handlers. Unbinding events is easy with jQuery but unbinding a single event handler requires the use of a named function. jQuery 1.2 now provides another option for binding and unbinding events: event namespaces.

(more…)