Hi all,

I'm developing functionality for an application using jQuery plugins.
Our organization has a compelling need to allow for these plugins to
be extended without touching the original code. I.e., let's say I have
a plugin that looks like this:

$.fn.somePlugin = function(callerSettings) {
    // statement #1
    $(this).click(function(e) {
        doStuff();
    });

    // statement #2
    $(this).hover(function(e) {
        doSomeMoreStuff();
    }, function(e) {
        doStillMoreStuff();
    });
}

I'd like to allow users of this plugin to 1) add functionality and 2)
change existing functionality without rewriting the entire plugin. Is
it possible for users to modify the plugin without modifying the
original code, so that the plugin becomes, in effect (note that only
statement #1 and #3 have changed, #2 is untouched):

$.fn.somePlugin = function(callerSettings) {
    // statement #1
    $(this).click(function(e) {
        doStuff();
        doCustomStuff();
        doSomeMoreCustomStuff();
    });

    // statement #2
    $(this).hover(function(e) {
        doSomeMoreStuff();
    }, function(e) {
        doStillMoreStuff();
    });

    // statement #3
    $(this).focus(function(e) {
        doStillMoreCustomStuff();
    });
}

I would have a souce file called jquery.somePlugin.js and then maybe
another one called jquery.somePluginOverride.js that would contain the
extensions to the original.

Thanks in advance for your help.

--Bill

Reply via email to