Book Image

jQuery Plugin Development Beginner's Guide

By : Giulio Bai
Book Image

jQuery Plugin Development Beginner's Guide

By: Giulio Bai

Overview of this book

<p>jQuery is the most famous JavaScript library. If you use jQuery a lot, it can be a good idea to start packaging your code into plugins. A jQuery plugin is simply a way to put your code into a package, which makes it easier to maintain your code and use across different projects. While basic scripting is relatively straightforward, writing plugins can leave people scratching their heads.<br /><br />With this exhaustive guide in hand, you can start building your own plugins in a matter of minutes! This book takes you beyond the basics of jQuery and enables you to take full advantage of jQuery's powerful plugin architecture to deliver highly interactive content to your website viewers.<br /><br />This book contains all the information you need to successfully author your very own jQuery plugin with a particular focus on the practical aspect of design and development. <br /><br />This book will also cover some details of real life plugins and explain their functioning to gain a better understanding of the overall concept of plugin development and jQuery plugin architecture.<br /><br />Different topics regarding plugin development are discussed, and you will learn how to develop many types of add-ons, ranging from media plugins (such as slideshows, video and audio controls, and so on) to various utilities (image pre-loading, handling cookies) and use and applications of jQuery effects and animations (sliding, fading, combined animations) to eventually demonstrate how all of these plugins can be merged and give birth to a new, more complex, and multipurpose script that comes in handy in a lot of situations.</p>
Table of Contents (20 chapters)
jQuery 1.4 Plugin Development
Credits
About the Author
About the Reviewers
Preface

jQuery plugin development checklist


Some basic key points to remember are as follows:

  • jQuery documentation is your best friend. Always go back to the documentation pages when in trouble or in need of information. Reading it thoroughly wouldn't hurt, either.

  • It might sound stupid, but always remember to link to the jquery.js file (containing the jQuery library) or, no matter what, we might spend hours looking for some error that justifies the script not running or working properly.

  • Always prefer the document-ready statement to any other non-jQuery functions to check whether the page has already loaded or not. Enough said.

  • This can never be stressed enough: plugins based on methods are completely different to plugins based on functions.

    • Method plugins extend the jQuery.fn object.

    • Function plugins extend the jQuery object directly.

    • Method plugins do support chainability.

    • Function plugins do not support chainability.

    • Method plugins should always return the jQuery object (this, in the code), to allow for chainability.

    Also refer back to Chapters 2 and 3 for more details.

As a plus, Keith Wood has written a very useful article about the plugin framework that he makes use of when developing plugins, which you may find interesting.

The article, which can be found at http://keith-wood.name/pluginFramework.html, is an extremely detailed dissertation covering all a developer needs to know about the jQuery plugin structure. It deals with singletons, event binding, settings, and destroy functionalities. It is a must-read for all jQuery plugin developers out there.