troubleshooting Question

jquery plugin: call to method within plugin

Avatar of Victor Kimura
Victor KimuraFlag for Canada asked on
jQueryAJAXJavaScript
5 Comments1 Solution420 ViewsLast Modified:
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 );

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');
});

All the alerts are working except display2().

thanks,
Victor
ASKER CERTIFIED SOLUTION
Jon Norman
Information Systems Manager
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros