We help IT Professionals succeed at work.
Get Started

jquery plugin: call to method within plugin

Victor Kimura
on
419 Views
Last Modified: 2012-07-12
Hi,

I have this plugin:

(function( $ ){

    var methods = {
        init : function( options ) {
            var settings = $.extend( {
                'location' : 'top',
                'background-color' : 'blue'
            }, options);

            alert ( settings.location );
        },
        show : function( ) {
            // IS
        },
        hide : function( ) {
            // GOOD
        },
        update : function( content ) {
            // !!!
        },
        display : function ( test1, test2 ) {
            var test1 = test1;
            alert ( "test1: " + test1 + "\ntest2: " + test2 );
            self.display2( test2 );
        },
        display2 : function ( test3 ) {
            alert ( "test3: " + test3 );
        }
    };

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

Open in new window


There is this method display() that is calling the other method display2() but display2 is never executed. How can I make it work?

I have the following in my as my init.js:
$(document).ready(function() {

// calls the init method
    $('div').tooltip();

// calls the init method
    $('div').tooltip({
        'location' : 'left'
    });

    $().tooltip('display', 'John', '316');
});

Open in new window


All the alerts are working except display2().

thanks,
Victor
Comment
Watch Question
Information Systems Manager
CERTIFIED EXPERT
Top Expert 2012
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE