I defined my plugin base on http://docs.jquery.com/Plugins/Authoring
(function( $ ){
var methods = {
init : function( options ) { },
show : function( options ) { },
hide : function( ) { },
update : function( content ) {
// How to call the show method inside the update method
// I tried these but it does not work
// Error: not a function
this.show();
var arguments = { param: param };
var method = 'show';
// Error: options is undefined
methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
}
};
$.fn.tooltip = function( method ) {
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
}
};
})( jQuery );
How to call the show method inside the update method?
EDIT:
The show
method references this
. Using methods.show(options)
or methods['show'](Array.prototype.slice.call( arguments, 1 ));
works to call the show
method but then the reference to this
seems to be wrong because I got a this.find(...) is not a function
error.
The show
method:
show: function(options) {
alert("Options: " + options);
alert("Options Type: " + options.interactionType);
var typeCapitalized = capitalize(options.interactionType);
var errorList = this.find('#report' + typeCapitalized);
errorList.html('');
},
var methods = {
init : function( options ) { },
show : function( options ) { },
hide : function( ) { },
update : function( options ) {
methods.show.call(this, options);
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With