Chapter 9. Extending widgets with the widget factory
This chapter covers
- Building on top of the jQuery UI widgets
- Using and creating extension points
- Extending datepicker
We’ve spent the greater part of this book looking at myriad things you can do with the jQuery UI widgets. But although the jQuery UI widgets handle the most common development use cases, real-life applications often have specific—often crazy—requirements. To give a few concrete examples: the jQuery UI team has had feature requests asking for accordions that store their open panel in a cookie, draggables that have a Cancel button, and autocompletes within autocompletes. (I’m not sure what those last two even mean, but someone asked for them.)
Widgets can’t solve every niche problem that developers have, so to allow for highly customized solutions to these unique issues, the widget factory allows you to extend existing widgets. The ability to extend widgets lets you add, remove, or tweak the behavior of an existing widget without reinventing the wheel. Because of the customizability it provides, the widget factory’s extensions mechanism is—in my opinion—the single most powerful feature in jQuery UI.
In this chapter, we’ll look at how to create widget extensions, then we’ll build a few examples to see what they make possible. We’ll look at datepicker specifically, as it’s the only jQuery UI widget that doesn’t use the widget factory yet and requires tricky workarounds.
Let’s dig in.