ColdFusion 8.0.1 Released With New Features! | Home | Parameterized XPath Expressions in .NET

Filed under Quick Tips on April 9, 2008 by Javier Julio

JQuery Plugins: Callbacks and Now Triggers

Recently, I helped a developer with the JQuery TableSorter plugin where he needed to run some code whenever the TableSorter finished sorting. The plugin didn't provide any callbacks in its configuration which seemed odd, as this is normal practice with any JQuery plugin.

After digging through the plugin source code, I noticed it was using JQuery's "trigger" method which dispatched a built-in or custom event. From there, the solution was simple. When initializing theTableSorter plugin, we used the "bind" method to listen for any event bubbled up from within the plugin. In this case, we listened for the "SortEnd" event. An example can be seen below:

$("table.sortable")
	.tablesorter()
	.bind("sortEnd", function(){
		// fired when sorting has finished
	});

I had used the "trigger" method in an earlier project but never seen it used before with a JQuery plugin. We can expect to see two standards now on how to tap into a plugin event-- one using callbacks, and the other using events. If you run into a plugin that doesn't give the option to pass in a callback, be on the look out for a custom event trigger!

Post a Comment Digg Del.icio.us

Trackback Pings (TrackBack URL for this entry)

http://www.arc90.com/cgi-bin/mt4/mt-tb.cgi/118.

Post a Comment:

ColdFusion 8.0.1 Released With New Features! | Main | Parameterized XPath Expressions in .NET