views:

31

answers:

2

This is my plugin

(function($){
    $.fn.editor = function(options){
        var defaults = {},
        settings = $.extend({},defaults, options);
        this.each(function(){
            function save(){
                alert('voila'); 
            }
        });
    }
})(jQuery);

I want to call function save from outside the plugin. How can I do it ?

A: 

for example something like this?:

call method

var save = function () {

   var self = this; // this is a element of each

};

(function($){
    $.fn.editor = function(options){
        var defaults = {},
        settings = $.extend({},defaults, options);
        this.each(function(){
           save.call(this) // you can include parameters 
        });
    }
})(jQuery);
andres descalzo
My intention is to keep function save inside the plugin, and call it from outside
runrunforest
A: 

iOh I found a way. it works best for me.

(function($){
    $.fn.editor = function(options){
        var defaults = {},
        settings = $.extend({},defaults, options);
        this.each(function(){
            function save(){
                alert('voila'); 
            }
            $.fn.editor.externalSave= function() {
                save();
            }
        });

    }
})(jQuery);

call

$(function(){
    $('div').editor();
    $.fn.editor.externalSave();
});
runrunforest