On Wed, Dec 27, 2006 at 11:25:20AM -0800, Michael Geary wrote:
> "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.
yep, it's for use with multiple elements,
so that global attr()-stuff doesn't cut it.
but fear not, Choan's helper function did it for me:
$(this)[0].ontimer = setTimeoutH( function( mysrc, body, x, y ) { on( mysrc,
body, x, y ) },
this.tSettings.ondelay,
$(this).attr('id'),
$(this).attr('ttbody'),
event.pageX + this.tSettings.xoffset,
event.pageY + this.tSettings.yoffset
);
yes, it's still a helper function, but at least a
generic one. :) and this way it works in all browsers.
regards, moe
--
Death before dishonor. But neither before breakfast.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/