Posted by & filed under Code, Finds.

I have decided to start creating some plug-ins again. I have created some before in the past and the biggest one that I did was a custom tooltip. I have started on a new one that will validate your forms. I have not done much but I will find it useful and I am sure someone else out there will do to as I will be releasing them on here.

I will also start to work on my tooltip plug-in and I will release that one to. I want to create a gallery plug-in but that will just be a simple one.

So what is a jQuery plug-in? It is basically a function that allows you to write less code and do more. There are many of these plug-ins about that allow you to do lots with very little code because it has already been written. There are plug-ins for creating galleries from a list of images to creating a modal window.

Here is a template for creating your plug-ins. This is what I to create mine as well.

//You need an anonymous function to wrap around your function to avoid conflict
(function($){

    //Attach this new method to jQuery
     $.fn.extend({
         //This is where you write your plug-ins name
         pluginname: function() {

            //Iterate over the current set of matched elements
            return this.each(function() {
                //code to be inserted here
            });
        }
    });
//pass jQuery to the function,
//So that we will able to use any valid JavaScript variable name
//to replace "$" SIGN. But, we’ll stick to $ (I like dollar sign: ) )       
})(jQuery);

This is from http://www.queness.com/post/112/a-really-simple-jquery-plugin-tutorial

Leave a Reply

  • (will not be published)