[jQuery] Improved jQIR?
[jQuery] Improved jQIR?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi,
I am seeking feedback on what I think may be an improvement on Sam
Collett's jQIR plugin
<a class="moz-txt-link-rfc2396E" href="http://sam.collett.googlepages.com/jQIR.html"><http://sam.collett.googlepages.com/jQIR.html></a>.
jQuery.fn.jQIR = function(format, path) {
var template = document.createElement('img');
return this.each(function() {
var obj = jQuery(this);
jQuery(template.cloneNode(true)).oneload(function() {
obj.empty().append(this) }).attr({src:path + obj.id() + '.' + format,
alt:obj.text() });
});
};
The reasons I think it may be an improvement are:
<ul>
<li>It detects if the browser supports images before doing the
replacement. (This is a feature in ppk's version
<a class="moz-txt-link-rfc2396E" href="http://www.quirksmode.org/dom/fir.html"><http://www.quirksmode.org/dom/fir.html></a>)</li>
<li>It makes sure the actual image will load before doing the
replacement. (Not in ppk's version)</li>
<li>It moves the image creation out of the loop and uses cloneNode in
the loop (Since ppk did it this way, I assume it might be more
efficient).</li>
<li>The DOM manipulation is more jQuery centric.</li>
</ul>
I have only tested this with Firefox 1.5 and IE 6. ppk warned that IE
on Windows does
<em>not</em> fire the <code>onload</code> event of cached images. I
did not notice any problems when returning to pages via the back button
with IE.
I am also wondering if I am using <code>oneload </code>correctly and
if it does any good. I used it because I don't think I need the
function bound after the initial load. Is this correct? Also, are
there any performance benefits to using <code>oneload</code> instead
of <code>load</code>? Are there any traps to avoid when deciding
between <code>load</code> and <code>oneload</code>?
Thanks in advance,
Faust
</body>
</html>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/