jQuery Plugin Boilerplate



You are currently browsing comments. If you would like to return to the full story, you can read the full entry here: “jQuery Plugin Boilerplate”.

36 thoughts on “jQuery Plugin Boilerplate

  1. Roger padilla

    Well, now I see the way you suggests to use the plugin do reuse the first created instance; anyway that is ugly, IMHO.

    $(document).ready(function() {

    // attach the plugin to an element
    $(‘#element’).pluginName({‘foo’: ‘bar’});

    // call a public method
    $(‘#element’).data(‘pluginName’).foo_public_method();

    // get the value of a property
    $(‘#element’).data(‘pluginName’).settings.foo;

    });

    And again, IMHO, the best skeleton for a jQuery plugin is (based on performance, usability and legibility):
    http://docs.jquery.com/Plugins/Authoring

  2. Simone

    Hi Stefan!
    You did an amazing work!!!

    Your code is a “must have” for everyone want to develop a jQuery Plugin!

    Thank you!!!

    Bye,
    Simone.

  3. Simone

    Well, I think you could move var methods = {}; and var helpers = {}; outside the $.fn.pluginName = function(method) {}; declaration.

    @Roger: I think that jQuery Plugin Authoring is a good template but has the problem of no consistency for settings variable.
    Another solution could be insert settings inside plugin data.

Comments are closed.