Tuesday, March 8, 2011

Smartupdater v. 3.1 beta is released.

see live example and docs at:  http://www.eslinstructor.net/smartupdater3/


Published on jQuery Plugins portal: http://plugins.jquery.com/project/smartupdater


New Features for ver 3.1:
  • smart Stop:  depend on element's size, current layout and visibility client automatically stops and restarts polling
  • self clean-up:  automatically clears all related timeouts/intervals on element remove/empty event.
New Features for ver 3.0:
  • Switch polling URL dynamically
  • Switch callback function dynamically
  • Remotely select callback function
  • HTTP cache (304 Not Modified)
  • Feedback to server
Improved Feature:
  • Remotely set polling timeout.
Deprecated Feature:
  • multiplies time interval each time when data not changed.

12 comments:

  1. Is there any way to run an arbitrary function when the ajax call fails? For example, when my user session times out, the server returns a status 401. I would like to have my own function for redirecting the user or showing a message. Not just stop the polling.

    ReplyDelete
  2. Sure :)
    If you create only one instance of Smartupdater or if you create multiple instances, but process errors identically, you can simply add your code to or call your error handler function from "error:" section of smartupdater's ajax,

    error: function(xhr, textStatus, errorThrown) {
    if ( ++es.failedRequests < es.maxFailedRequests ) {
    . . .
    } else {
    . . . elem.smartupdaterStatus.state = 'OFF';

    //
    // add your error handling code code here,
    //
    alert(textStatus);

    //
    // or call external function
    //

    yourErrHandling(xhr, textStatus, errorThrown);

    }
    }

    If error processing logic depends on element Smartupdater attached to, it's also not a big deal, but I'm too lazy to type it now :) Let me know if you need it and I'll show you how to do such kind of error handling.

    ReplyDelete
  3. I see, thank you :)

    However it would be a bit cleaner if there was some event to hook into instead. I don't like changing the source files for external components.

    ReplyDelete
  4. Well, maybe I'll add callbacks for error, complete, beforeSend events in the next release. Not sure yet. Originally I wanted to keep this plugin as simple as possible. But it getting more complex now and people still load ver. 2.xx better then 3.0, though this one is cleaner and much more advanced.

    ReplyDelete
  5. Hello!

    Very nice plugin. I have made a couple of changes to source code. Basically, I needed to be able to poll server forever so I added :
    if ( (++es.failedRequests < es.maxFailedRequests ) || (es.maxFailedRequests < 0)) { ...}

    Also,I added function to force plugin to replace item with same content:
    jQuery.fn.smartupdaterForceRestart = function () {
    /*ignore previous content and force restart*/
    return this.each(function () {
    this.settings.stopFlag = false;
    clearTimeout(this.settings.h);
    this.settings.failedRequests = 0;
    this.settings.etag = "0";
    this.settings.lastModified = "0";
    this.settings.prevContent = "";
    this.settings.fnStart();
    });
    };

    note line : this.settings.prevContent = ""; which will replace content even if same content is received.
    This is needed if I have some content which must be replaced even if the content seems to be the same.

    Thank you for your plugin!

    ReplyDelete
  6. Hi Hermenegildo,
    thank you for using my plugin.

    1. Regarding "failedRequests": you don't need to modify source, just set it to something very big, say to Number.MAX_VALUE, which on my computer is 1.7976931348623157e+308 :)

    2. Regarding "smartupdaterForceRestart()" function: I would simply add this line:
    this.settings.prevContent = "";
    to the existing "smartupdaterRestart()" function rather then create a new one. Maybe I'll do it in the next release. Thank you for this idea :)

    ReplyDelete
  7. Thank you for your response.

    At first I did just what you suggest, but have made these modifications because:

    1. -1 is visually easier to identify as a number which indicates that plugin will never stop polling

    2. when I just added that line to "smartupdaterRestart()" function I lost ability to restart with old content, a feature I find very usefull, especially when I have linked values, conditional refreshes and such.


    Best regards,

    ReplyDelete
  8. would like to see smartupdater on github so i can work always with the newest version and can also host it on github for my projects

    ReplyDelete
  9. Hey Anonymous,

    here is link to github

    https://github.com/vkiryukhin/Smartupdater

    Good luck with your projects!

    ReplyDelete
  10. Hello Vadimk,
    Two issues I'd love to add to this very nice plugin,
    1)-Configuration option for autostart true/false as you suggested on github,

    2)-Autostop on specific response text, if the resonse text contains a pre configured value, then stop the updater and optionally call a precongigured url once to cleanUp or tell something else on the server we are finished.

    Thank you again

    ReplyDelete
  11. Hi,
    This was really helpful. However, I'm not an AJAX programmer, so I made a very silly gotcha that took me a while to correct. I was using
    http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js
    and was getting xhr undefined errors.
    switching to 1.4.4 fixed this problem. If anyone else is as stupid as me, this might help them.

    ReplyDelete