I essentially have the same goal as in this question:
Calling a jQuery plugin without specifying any elements
However I am looking for the minimal edit to add a method to the “conclusion” built up in the jQuery plugin guide…which culminates in a jQuery “data” based tooltip plugin:
http://docs.jquery.com/Plugins/Authoring
I’m looking for the turnkey “right” way to add a method (the sort that finds its place in the list with reposition, show, hide, and update) for something that could be called with no elements. My case is I want to add a debug mode method you can call like:
$.tooltip('debug', true);
Like the author of the question I cite, I can get this working just fine with a parallel to:
$().tooltip('debug', true);
But the supplied answer wasn’t cast in terms of the full-on .data-based tooltip plugin structure. So I can’t quite figure out where to inject the offered advice of using .extend. Can anyone suggest the minimal edit to get the desired effect?
After looking at this a bit, I think the simplest modification to do is just to inject the extend call right after the
$.fn.tooltip = function(method) { ... }and make it a synonym, like this:That seems to do the trick…and in the plugin’s methods you just test to see if
thisis equal tojQuery(or$) to see if it’s actually being called on “nothing”.