October 10th, 2006

JHeartbeat and JTicker

Filed under: Cool Coding, JQuery, JavaScript — jasonlevine @ 9:00 pm

Recently, I’ve been doing more and more development with JQuery. For those who haven’t heard of it, JQuery is a JavaScript library that makes some previously time consuming and difficult tasks very easy. The way that it is built, you can even develop plugins to extend JQuery’s functionality. And that’s just what I did:

JHeartbeat will allow a web page to periodically poll a server. This polling can be used to keep the user’s session alive or to download updated information.

JTicker will turn an RSS feed into a scrolling news ticker.

Try them out and let me know what you think.

12 Comments »

  1. Comment by gavinmroy — October 26, 2006 @ 5:57 pm

    Hey, I’ve been developing an app with jHeartbeat (thanks for the cool plugin btw). I was wondering if you planned on releasing it under a license (MIT for example like jQuery). I’m concerned about distributing it in my app without knowing what the license could/would be. Thanks again for a cool plugin.

  2. Comment by jasonlevine — November 6, 2006 @ 11:41 am

    jHeartbeat is free to use for any commercial or non-commercial project. I just ask that I be credited somewhere. Doesn’t need to be in huge, bold letters or anything. Just make some small mention of jHeartbeat and my site where ever you feel it is appropriate.

    You are right that I should come up with a more formal license, though. I’m looking at the MIT license right now and that looks pretty good. In fact, consider jHeartbeat and my other JQuery plugins/scripts to be “unofficially” covered by the MIT license. (By “unofficially”, I mean that they are under that license now but I probably won’t get to update the documentation for a bit.)

  3. Comment by ray — December 1, 2006 @ 3:19 pm

    Hi Jason,

    Good work with jHeartbeat!

    My question:
    ———–
    You mention that:
    “…can use the callback function to manipulate this (returned) data, if needed..”.

    Being new to jQuery, could you show a simple “hello world” example for the callback function?

    Suggestion:
    suppose we’d like to multiply times 2,
    the number returned in the DIV by “heartbeat.asp”?
    What would the actual samnple code be?

    Thanks, Jason!
    ray

  4. Comment by jasonlevine — December 28, 2006 @ 8:42 am

    ray,

    The JHeartbeat page has the generic code. However, a simple “Hello World” application might look like this:

    	$(document).ready(function() {
    		$.jheartbeat.set({
    			url: "heartbeat.asp",
    			delay: 3000
    		}, function () {
    			alert("Hello World!");
    		});
    	});
    

    A function that might take the number returned and multiply it by 2 would look something like this:

    	$(document).ready(function() {
    		$.jheartbeat.set({
    			url: "heartbeat.asp",
    			delay: 3000
    		}, function () {
    			alert(parseInt($("#HeartBeatDIV").html())*2);
    		});
    	});
    

    I hope this helps.

  5. Comment by bleen18 — January 29, 2007 @ 3:28 pm

    jHeartbeat is great, but how do you make it stop beating? I’m using ti to check the status of a slooow script. Once the script is complete though, I want the page to stop checking.

    Thanks!

  6. Comment by bleen18 — January 29, 2007 @ 5:33 pm

    Regarding my last comment .. I figured it out and thought I’d share:
    clearTimeout($.jheartbeat.timeoutobj.id);

    With that though, another question: in the “set” function, shouldn’t the first few lines be:
    if (this.timeoutobj.id > -1) {
    clearTimeout(this.timeoutobj.id);
    // note the ‘.id’
    }

  7. Comment by howie — February 9, 2007 @ 6:20 am

    Is it possible there’s a memory leak in JHeartbeat? I’ve been playing with it for the last couple of days, on something that fetches JSON updates every few seconds from our monitoring system, and uses that to update a UL with entries.

    It works nicely now, but I left it running overnight, and came back to a 1GB firefox! Since then, I’ve ripped out ALL of my code, leaving just an empty every-2-seconds heartbeat, and left it going in IE, and I can still watch the memory usage grow every tick…

    This is my first go at this kind of stuff, so I’m prepared to believe it’s me. Is there any more scientific instrumentation for looking at this stuff?

  8. Comment by erica — April 12, 2007 @ 11:06 am

    I downloaded http://www.jasons-toolbox.com/JTicker/JTicker_With_JQuery.zip, but JTicker doesn’t seem to be working when I view index.html on my machine- neither with your xml file or with my own. All I see fading in and out is “JTicker 0.5 Beta.” Any ideas? This is exactly what I want to implement on my site and I want it to work soooo bad! Also, if you can answer that question, is there any way to display more than one item at a time? So, for instance, four headlines - fade out - the next four headlines - etc.

  9. Comment by peter — April 22, 2007 @ 1:51 am

    I would like to suggest a change to jHeartbeat
    IE caches, and I saw how you send various HTTP/HTML headers to stop the caching. I would like to suggest adding a counter instead,
    which would force IE to request the result from the server and not make anything time dependent:

    In the changes, show below, I have added a counter.
    If the user has already supplied a url with a parameters, then the extra parameter starts with a & instead of a ?.

    options: {

    url: “heartbeat_default.asp”,

    counter: 0,
    delay: 10000

    },

    beat: function() {

    var c = this.options.url.search(/\?/) == -1 ? ‘?’ : ‘&’ ;
    var newUrl = this.options.url + c + “counter=” + this.options.counter++ ;
    $(”#HeartBeatDIV”).load(newUrl);

    this.timeoutobj.id = setTimeout(”$.jheartbeat.beat();”, this.options.delay);

    this.beatfunction();

  10. Comment by peter — May 20, 2007 @ 6:25 am

    The memory leak as pointed out in comment 7 is really problematic. Is there any way of fixing it?

    Thanks

    Peter

  11. Comment by jasonlevine — July 24, 2007 @ 6:45 am

    howie, It’s possible that there’s a memory leak in there somewhere. When I get some time, I need to update this plugin for the latest version of JQuery.

  12. Comment by eshu — November 12, 2007 @ 5:51 am

    thx for a nice plugins…

    i have one question regarding JTicker

    is it possible to extend somehow support for other character encodings..
    for example im using Windows-1250 and can not get some special character..
    i know that that is an issue…
    its pitty that half of the world can not use that nice technology ;-(

    thx

    mario

RSS feed for comments on this post. TrackBack URI

Leave a comment

Page generated in: 0.280 seconds.
Powered by: WordPress 2.5