0

I am having trouble calling a jQuery plugin off the jQuery object itself. So rather than calling $(selector).myPlugin() I want to call $.myPlugin instead. For some reason it tells me that the function is undefined.

Here's my code:

(function ($) {

    var _current = null;

    var methods = {
        init: function (options) {
            _current = $('.rfgQuestionsWrapper').filter(function () {
                return $(this).css('display') != 'none';
            }).first();
            console.log(_current);
            $('.gaugeTitle').click(function (e) {
                var rfgCode = $(this).parent().find('.gaugeWrapper').attr('id');
                console.log(rfgCode);
                showByCode(rfgCode);
                return false;
            });
        },
        showByCode: function (rfgCode) {
            var target = $.utilities.filterById('.rfgQuestionsWrapper', rfgCode);
            console.log(target);
            _current.hide();
            target.show();
        }
    };

    $.fn.navigationManager = 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.tooltip');
        }
    };

})(jQuery);

I must be doing something wrong because this is the first time I call a plugin this way... Any suggestions?

Kassem
  • 8,116
  • 17
  • 75
  • 116

1 Answers1

1

Look at that question: in jQuery what is the difference between $.myFunction and $.fn.myFunction?

Basically instead of $.fn.navigationManager = function(){} you write $.navigationManager = function(){}.

Community
  • 1
  • 1
Andy
  • 29,707
  • 9
  • 41
  • 58
  • One more question though... is there a recommended way to call the `showByCode` method from within the `init` method? – Kassem Jun 04 '12 at 12:58