Weil ich "bind" grad selbst mal wieder brauchte und weils meiner Meinung nach "schöner" Javascript-Code ist:
PHP-Code:
(function (window, $, L, undefined) {
/**
* @namespace Limubo.Progressbar
*/
L.Progressbar = new Class({
Implements: Options,
options : {
value : 1,
el : null
},
initialize : function (options) {
if (options !== undefined) {
this.setOptions(options);
}
if (this.options.el === null) {
this.options.el = $(".progressbar")
}
/**
* @var {number}
*/
this.counter = this.options.value;
this.options.el.progressbar({
value: this.counter
});
},
run : function () {
var el = this.options.el,
prev = el.prev();
if ( el.length < 1 ) {
return;
}
if ( prev.length > 0 && prev.hasClass('progressbar_text') ) {
prev.fadeIn();
}
(function () {
this.counter += 1;
if (this.counter > 100) {
this.counter = 1;
}
el.progressbar('value', this.counter);
window.setTimeout(
arguments.callee.bind(this),
40
);
}).bind(this)();
}
});
})(window, jQuery, Limubo);
Anstatt den jquery fn namespace zu erweitern, benutz ich für widgets eigentlich immer eine jqueryui- Abstraktion - in dem Fall die ui-Progressbar direkt. Angesteuert wird das ganze dann über eine Instanz einer Mootools-JS-Klasse. Events aus dem ui-Widget kannst du dann über Objekt-Methoden bedienen und du hast mMn. ein sauberes Interface (in dem Fall hört das Ding auf keine events, da es beim Fileupload instanziert wird). Von Mootools brauchste hier eigentlich nur die Klassenbibliotheken im Mootools build-Tool anzuwählen.
Wirklich cool ist die anonyme Funktion in run, deren Scope der Objektscope bleibt und die sich selbst nach dem Ausführen ihres Inhalts wieder startet.
Grüße
Basti