If you already have a jQuery* plugin that uses the functions we implement, your code should be fairly easy to port over. For the most part, you will just need to change the reference in the IIFE (Immediately Invoked Function Expression) from "jQuery" to "jq".
First, this document will illustrate the basic structure for creating a plugin, then demonstrate how to create a utility plugin. Finally this page will share how to create a plugin that acts upon elements in a bucket.
The first step to createing a plugin is creating an IIFE (Immediately Invoked Function Expression) and extend the $.fn object. For example:
1
2
3
4
5
|
( function ($){ $.fn.myPlugin= function (){ }; })(af) |
The code above creates a simple function that can then be accessed using the object returned by the $().myPlugin() function. There are a few tips to remember when operating inside the plugin.
Next, here is an example of how to make a utility plugin that does not act on objects.