jqueryplugin1

by oterox

HTML

<div class="a">aaa</div>
<div class="b">bbb</div>

JavaScript

(function( $ ){

  var methods = {
    init : function( options ) { 
      alert(options.startIndex);
    },
    show : function( ) {
      // IS
    },
    hide : function( ) { 
    
    },
    slideTo : function ( position ) {
          this.html(position);
    },
    update : function( content ) { 
      // !!! 
    }
  };

  $.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 );


$('.a').tooltip('slideTo',4); 
$('.b').tooltip('slideTo',4); 
// calls the init method
$('div').tooltip({
  startIndex : '5'
});