Mit Ajax.PeriodicalUpdater nur updaten wenn Content verändert wurde
Geschrieben von ckay am 16. Juli 2009 | Abgelegt unter Tipps
Die Funktion Ajax.PeriodicalUpdater aus der Prototype-Bibliothek ist ja ansich schon eine feine Sache. Das einzige was immer störte war, dass der Inhalt auch aktualisiert wurde wenn der Content sich nicht geändert hat.
Auf der Suche nach einer Lösung habe ich dann diese nette Erweiterung für Prototype gefunden:
Ajax.PassivePeriodicalUpdater = Class.create(Ajax.Base, {
initialize: function($super, container, url, options) {
$super(options);Confessions of a Pop Performer download this.onComplete = this.options.onComplete;
this.frequency = (this.options.frequency || 2);
this.decay = (this.options.decay || 1);this.updater = { };
this.container = $(container);
this.url = url;Brainscan this.start();
Laughing Gas psp
},start: function() {
this.options.onComplete = this.updateComplete.bind(this);
this.onTimerEvent();
},Taking 5 movie stop: function() {
this.updater.options.onComplete = undefined;clearTimeout(this.timer);
(this.onComplete || Prototype.emptyFunction).apply(this, arguments);
},updateComplete: function(response) {
if (response.responseText == this.lastText) {
this.decay = this.decay * this.options.decay;
} else {
this.decay = 1;
this.container.update(response.responseText);
this.lastText = response.responseText;Blue Collar move The Bliss ipod
}
this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
},onTimerEvent: function() {
this.updater = new Ajax.Request(this.url, this.options);}
});
The World Is Not Enough ipod Quelle: hier
Keine Kommentare »

