[jQuery] Re: creating own callback

2007-12-21 Thread Eric Teubert

> jQuery.extend({
>preloadImage: function(imagePath,callback) {
>  var image = new Image();
>  if(jQuery.isFunction(callback)) image.onload = callback;
>  image.src = "gfx/"+imagePath;
>}
>
> });

Looks good, I'll give it a try.

Thanks a lot!

Eric


[jQuery] Re: creating own callback

2007-12-21 Thread Erik Beeson
I doubt that will work. There need not be anything particularly "jQueryish"
about preloading images, but if you want to stick it under $, maybe
something like:

jQuery.extend({
   preloadImage: function(imagePath,callback) {
 var image = new Image();
 if(jQuery.isFunction(callback)) image.onload = callback;
 image.src = "gfx/"+imagePath;
   }
});

--Erik


On 12/21/07, Jake McGraw <[EMAIL PROTECTED]> wrote:
>
> I'm sure there's a more sophisticated way of doing this, but functions can
> be passed around like any other variable type in JavaScript, so:
>
> jQuery.extend({
>preloadImage: function(imagePath,callback) {
>  jQuery("").attr("src", "gfx/"+imagePath);
>  callback();
>}
> });
>
> Should do the trick.
>
> - jake
>
> On Dec 21, 2007 3:11 PM, Eric Teubert < [EMAIL PROTECTED]> wrote:
>
> >
> > Hi,
> >
> > I spend some time in browsing through the documentation but I didn't
> > find anything about creating own functions with callback-
> > functionality. How do I do this?
> >
> > What I want to do:
> > Write a function that preloads an image and returns a callback when
> > the image is loaded. It looks like
> >
> > jQuery.extend({
> >preloadImage: function(imagePath) {
> >jQuery("").attr("src", "gfx/"+imagePath);
> >}
> > });
> >
> > $.preloadImage("example.gif ");
> >
> > But how have I to edit the first part when I want the second to look
> > like the following?
> >
> > $.preloadImage("example.gif", function() { alert("Preloading
> > finished"); });
> >
> > Thanks!
> >
>
>


[jQuery] Re: creating own callback

2007-12-21 Thread Jake McGraw
I'm sure there's a more sophisticated way of doing this, but functions can
be passed around like any other variable type in JavaScript, so:

jQuery.extend({
   preloadImage: function(imagePath,callback) {
 jQuery("").attr("src", "gfx/"+imagePath);
 callback();
   }
});

Should do the trick.

- jake

On Dec 21, 2007 3:11 PM, Eric Teubert <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I spend some time in browsing through the documentation but I didn't
> find anything about creating own functions with callback-
> functionality. How do I do this?
>
> What I want to do:
> Write a function that preloads an image and returns a callback when
> the image is loaded. It looks like
>
> jQuery.extend({
>preloadImage: function(imagePath) {
>jQuery("").attr("src", "gfx/"+imagePath);
>}
> });
>
> $.preloadImage("example.gif");
>
> But how have I to edit the first part when I want the second to look
> like the following?
>
> $.preloadImage("example.gif", function() { alert("Preloading
> finished"); });
>
> Thanks!
>