"this" doesn't work like a local variable. Inside a nested function, "this"
is not the same as in the outer function. That's what is messing things up.
If I understand your code, you can write it more simply like this:
(function($) {
$.fn.Tooltip = function(settings) {
var $all = this;
settings = $.extend($.extend({}, arguments.callee.defaults),
settings || {});
$all.filter('[EMAIL PROTECTED]').bind( settings.event, onmouseover );
return this;
function onmouseover( event ) {
//...
setTimeout(
function() {
on( $all.attr('id'), $all.attr('ttbody'),
event.pageX + settings.xoffset,
event.pageY + settings.yoffset
);
}, settings.ondelay );
//...
}
function on( mysrcid, body, x, y ) {
// do stuff...
}
};
})(jQuery);
But now that it's simple enough for me to understand, one question comes to
mind: Do you use this plugin only with a single element, e.g.
$('#foo').Tooltip(), or can it use multiple elements, e.g.
$('.foo').Tooltip()? The two attr() calls inside the setTimeout don't look
right for multple elements.
-Mike
> well, i need to pass some arguments to doStuff() that seem to
> be out of scope when it fires.
>
> to clarify, below is the relevant snippet of my real code
> with your variant applied:
>
> ----snip
>
> (function($) {
> $.fn.Tooltip = function(settings) {
> settings = $.extend($.extend({}, arguments.callee.defaults),
settings || {});
>
> $(this).filter('[EMAIL PROTECTED]')
> .each(function() {
> this.tSettings = settings;
> })
> .bind( settings.event, onmouseover );
> return this;
> };
>
> //...
>
> function onmouseover( event ) {
> //...
> //
> // firebug throws "this.tSettings has no properties" on the
next line
> // (when the timeout fires)
> //
> setTimeout(
> function() {
> on( $(this).attr('id'),
> $(this).attr('ttbody'),
> event.pageX +
> this.tSettings.xoffset,event.pageY + this.tSettings.yoffset
> );
> }, this.tSettings.ondelay );
> //...
> }
>
> function on( mysrcid, body, x, y ) {
> // do stuff...
> }
>
> //...
>
> })(jQuery);
>
> ----snap
>
> as you may have guessed i'm tampering with the tooltip plugin
> and am probably missing something obvious...
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/