#287 ✓duplicate
crasy

PeriodicalUpdater expansion

Reported by crasy | August 17th, 2008 @ 02:37 PM

Hi

its my first ticket soo please excuse formerrors and my english, it is terrible.

i want to reset only! the timer from the PeriodicalUpdater whithout do a new request. over stop and start does a new request will be effected.

i think it is a good function to reset the timer for anyone, too.

my solution (quick and dirty):


var PU = new Ajax.PeriodicalUpdater('foo', 'bar.php', {
    method: 'get', frequency: 10, decay: 1
  });

clearTimeout(PU.timer);
PU.timer = PU.onTimerEvent.bind(PU).delay(PU.decay * PU.frequency);

but i think this is fast implementated in the prototype source for a clean and fast solution.

e.G. (untested):


Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {
  initialize: function($super, container, url, options) {
    $super(options);
    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;

    this.start();
  },

  start: function() {
    this.options.onComplete = this.updateComplete.bind(this);
    this.onTimerEvent();
  },

  stop: function() {
    this.updater.options.onComplete = undefined;
    clearTimeout(this.timer);
    (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
  },

  resset: function() {
    clearTimeout(this.timer);
    this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
  },

  updateComplete: function(response) {
    if (this.options.decay) {
      this.decay = (response.responseText == this.lastText ?
        this.decay * this.options.decay : 1);

      this.lastText = response.responseText;
    }
    this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
  },

  onTimerEvent: function() {
    this.updater = new Ajax.Updater(this.container, this.url, this.options);
  }
});

greetz crasy aka. Kay Linzmeier

PS: thanks for your work, its a realy realy realy good framework.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Referenced by

Pages