<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Recent Posts in 'Dealing with multiple image load events' | Pragmatic Forums</title>
    <link>https://forums.pragprog.com/forums/45/topics/312</link>
    <language>en-us</language>
    <ttl>60</ttl>
    <description></description>
    <item>
      <title>Dealing with multiple image load events posted by Christophe Porteneuve @ Wed, 12 Mar 2008 08:13:27 -0000</title>
      <description>&lt;p&gt;No I mean not using inject, or anything that relies on &lt;code&gt;innerHTML&lt;/code&gt;, but building the actual &lt;span class="caps"&gt;DOM&lt;/span&gt; nodes, which you have many options for:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;code&gt;new Element(&#8230;)&lt;/code&gt; lets you easily create a &lt;span class="caps"&gt;DOM&lt;/span&gt; element, complete with attributes and contents, and returns the &lt;span class="caps"&gt;DOM&lt;/span&gt; node for it: you can then script it.&lt;/li&gt;
		&lt;li&gt;If you need to quickly build a complex &lt;span class="caps"&gt;DOM&lt;/span&gt; fragment, you may favor Scripty&amp;#8217;s &lt;code&gt;Builder&lt;/code&gt; capability over &lt;code&gt;new Element&lt;/code&gt;, as it may well turn out less verbose, especially if you enable its shortcut syntaxes.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;The book explains both, read it up! :-)&lt;/p&gt;</description>
      <pubDate>Wed, 12 Mar 2008 08:13:27 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:45:312:2433</guid>
      <author>Christophe Porteneuve</author>
      <link>https://forums.pragprog.com/forums/45/topics/312</link>
    </item>
    <item>
      <title>Dealing with multiple image load events posted by Adam Beguelin @ Wed, 12 Mar 2008 01:25:43 -0000</title>
      <description>&lt;p&gt;thanks for the quick response.&lt;/p&gt;


	&lt;p&gt;what&amp;#8217;s the difference between &lt;span class="caps"&gt;HTML&lt;/span&gt; injection and &lt;span class="caps"&gt;DOM&lt;/span&gt; injection?  do you mean using inject()?  Isn&amp;#8217;t it &lt;span class="caps"&gt;DOM&lt;/span&gt; injection since I&amp;#8217;m doing $(elt).insert?&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m using the Truveo &lt;span class="caps"&gt;API&lt;/span&gt; to get a list of videos and then putting the images into a div.  Here&amp;#8217;s the line that does the Element.insert:&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;TVS&lt;/span&gt;.VideoSet.Video.each(function(vid){$(&amp;#8216;imageContainer&amp;#8217;).insert(tpl.evaluate(vid))})&lt;/p&gt;


	&lt;p&gt;The each loop iterates up to 50 times.  But I want to go back and fill the array (calling Truveo again)  and then add the resulting images in the next round, after all the images have loaded from the current round.&lt;/p&gt;


	&lt;p&gt;You can see one version of this experiment here: &lt;br /&gt;&lt;a href="http://khido.com/ov/oevurt.html"&gt;http://khido.com/ov/oevurt.html&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;I was also hoping to just keep around the last N images, sliding in new ones in some animated way.  I&amp;#8217;ve added a unique id (again from the Truveo result set) so I could build a hash of the existing images, and then just remove ones that aren&amp;#8217;t in the new result set.&lt;/p&gt;


	&lt;p&gt;I don&amp;#8217;t have control of the server since I&amp;#8217;m using the Truveo &lt;span class="caps"&gt;API&lt;/span&gt;.  I suppose I could use my web server to get the data from Truveo and then update the page that way.  Maybe for version 2 of this exercise.  But for now I&amp;#8217;m using this as an exercise to learn Prototype using your excellent book. :-)&lt;/p&gt;</description>
      <pubDate>Wed, 12 Mar 2008 01:25:43 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:45:312:2432</guid>
      <author>Adam Beguelin</author>
      <link>https://forums.pragprog.com/forums/45/topics/312</link>
    </item>
    <item>
      <title>Dealing with multiple image load events posted by Christophe Porteneuve @ Tue, 11 Mar 2008 22:07:33 -0000</title>
      <description>&lt;p&gt;Hey Adam,&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;AFAIK&lt;/span&gt;, the &lt;code&gt;load&lt;/code&gt; event indeed does not bubble, so event delegation wouldn&amp;#8217;t be your ticket.  You could switch from &lt;span class="caps"&gt;HTML&lt;/span&gt; injection to &lt;span class="caps"&gt;DOM&lt;/span&gt; injection, and use nodes as soon as you add them to the &lt;span class="caps"&gt;DOM&lt;/span&gt;?&lt;/p&gt;


	&lt;p&gt;From a higher standpoint, I fear for your page&amp;#8217;s performance when I hear you&amp;#8217;re creating up to 1,000 images in JS, client-side, using Templates.  Can&amp;#8217;t you offload that to the server?  Or at least use chunks, not just a one-image-at-a-time approach&#8230;&lt;/p&gt;


	&lt;p&gt;&amp;#8216;HTH&lt;/p&gt;</description>
      <pubDate>Tue, 11 Mar 2008 22:07:33 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:45:312:2427</guid>
      <author>Christophe Porteneuve</author>
      <link>https://forums.pragprog.com/forums/45/topics/312</link>
    </item>
    <item>
      <title>Dealing with multiple image load events posted by Adam Beguelin @ Tue, 11 Mar 2008 11:36:57 -0000</title>
      <description>&lt;p&gt;I have some code that creates uses a Template to create a bunch of img links.  After the images load, I want the code to then manipulate the &lt;span class="caps"&gt;DOM&lt;/span&gt; and add more img links.&lt;/p&gt;


	&lt;p&gt;Is there some way to use Element.observe in order to know when all the images have loaded?  I tried observing &amp;#8216;load&amp;#8217; on the div that contains the images, but that didn&amp;#8217;t work.  There are a bunch of images (up to 1,000) so I don&amp;#8217;t want to use Element.observe() on each image.&lt;/p&gt;


	&lt;p&gt;Element.observe(window, &amp;#8216;load&amp;#8217;, ...) seems to work once, but not after a second set of images are loaded.&lt;/p&gt;


	&lt;p&gt;Suggestions?&lt;/p&gt;</description>
      <pubDate>Tue, 11 Mar 2008 11:36:57 -0000</pubDate>
      <guid isPermaLink="false">forums.pragprog.com:45:312:2420</guid>
      <author>Adam Beguelin</author>
      <link>https://forums.pragprog.com/forums/45/topics/312</link>
    </item>
  </channel>
</rss>
