Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery plugin with methods and callback
    text
    copied!<p>I'm working on a kind of do-it-all basic framework for jQuery plugins. I'm basing the structure off of the jQuery Plugins/Authoring example found <a href="http://docs.jquery.com/Plugins/Authoring" rel="nofollow">here</a>.</p> <p>Here's a further simplified version of the structure I'm building:</p> <pre><code>(function( $ ){ var methods = { init : function( options ) { var defaults = { // place default settings for plugin here } var options = $.extend(defaults, options); return this.each(function(){ var $this = $(this), data = $this.data('PLUGINNAME'); if ( ! data ) { // do more setup stuff here } }); }, destroy : function( ) { return this.each(function(){ // do stuff to destroy any function binding }) }, update : function( content ) { return this.each(function() { //do your update stuff here }) } }; $.fn.PLUGINNAME = function( method ) { 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.PLUGINNAME' ); } }; })( jQuery ); </code></pre> <p>The piece that I'm trying to figure out now is how to add a callback function to the plugin call. I know that I'll need another parameter like this:</p> <pre><code> $.fn.PLUGINNAME = function( method, callback ) { </code></pre> <p>but I'm not sure how to go about implementing that based on what I currently have.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload