javascript - jQuery - this.option becomes undefined in load function -


i'm trying alter plugin little bit, here's prototype function, i've marked lines i've added.

ok, problem happens inside img-load function i've added. i've surrounded old code 1 assure script waits until image has loaded. problem is, "this" inside load-function not connected 1 outside. i've tried giving load function parameter apparently it's not working or i'm doing wrong.

do know easy way sort-of inherit "this"? don't know else do.

plugin.prototype._fade = function(number) {   var $element, currentslide, next, slidescontrol, value,     _this = this;   $element = $(this.element);   this.data = $.data(this);   if (!this.data.animating && number !== this.data.current + 1) {     $.data(this, "animating", true);     currentslide = this.data.current;     if (number) {       number = number - 1;       value = number > currentslide ? 1 : -1;       next = number;     } else {       value = this.data.direction === "next" ? 1 : -1;       next = currentslide + value;     }     if (next === -1) {       next = this.data.total - 1;     }     if (next === this.data.total) {       next = 0;     }      this._setactive(next);     slidescontrol = $(".slidesjs-control", $element);        var nxtimg = $(slidescontrol.children(":eq(" + next + ")")).find("img:eq(0)"); // added     if ( nxtimg.attr("longdesc") !== undefined ) {  // added       nxtimg.attr("src", nxtimg.attr("longdesc")); // added       nxtimg.removeattr("longdesc"); // added     } // added       nxtimg.load(function(){ // added       slidescontrol.children(":eq(" + next + ")").css({         display: "block",         left: 0,         zindex: 0       });       this.options.callback.start(currentslide + 1);       if (this.options.effect.fade.crossfade) {         return slidescontrol.children(":eq(" + this.data.current + ")").stop().fadeout(this.options.effect.fade.speed, (function() {           slidescontrol.children(":eq(" + next + ")").css({             zindex: 10           });           $.data(_this, "animating", false);           $.data(_this, "current", next);           return _this.options.callback.complete(next + 1);         }));       } else {         slidescontrol.children(":eq(" + next + ")").css({           display: "none"         });         return slidescontrol.children(":eq(" + currentslide + ")").stop().fadeout(this.options.effect.fade.speed, (function() {           slidescontrol.children(":eq(" + next + ")").stop().fadein(_this.options.effect.fade.speed).css({             zindex: 10           });           $.data(_this, "animating", false);           $.data(_this, "current", next);           return _this.options.callback.complete(next + 1);         }));       }     }); // added      } }; 

you're capturing in closure variable "_this". isn't working?


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -