views:

10

answers:

1

I made this jQuery plugin called removable when you click the objects button it slides up and should trigger a custom event like onDone.

Here's what I did (The codeing format is based on jQuery's http://docs.jquery.com/Plugins/Authoring):

init: function(){
    return this.each(function(){
        $('a', this).click(function(){
            $(this).parent().slideUp(function(){

                    // Somehow trigger the onDone method

            })
        });
    })
},
onDone: function(){
    // Default action
},

and this is what I've done when calling the plugin

   $('li').removable({
        onDone: function(){
          // Overwrite default action
        },
    })

How can this be done?

A: 

If all you need is to call it at the end of the animation, just pass it as the second argument to slideUp or even just call it with $(foo).MyPlugin.onDone() inside the callback function.

otherwise look at trigger and bind jQuery functions - you can use any string you want for those event types so you can trigger and bind a MyPluginDone event

EDIT: based on comments you want something simpler -

As it states in the article you quoted, the best way to provide override-able defaults to options is to have your plugin accept an options object, then to get the combined defaults+overrides you do:

var combinedOpts = $.extend({},defaults,overrides);

and get all the values to use from there...

tobyodavies
My objective is to overwrite the default "onDone" behaviour when calling my plugin. So each object using the plugin can have some custom actions when somthing happens.
Siavash M
edited to account for what i now think you mean...
tobyodavies