<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DaveOnCode &#187; jquery</title>
	<atom:link href="http://www.daveoncode.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daveoncode.com</link>
	<description>Objective C, iOS and more programming stuff</description>
	<lastBuildDate>Mon, 19 Dec 2011 12:11:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CSS tip: if you can&#8217;t remove the evil, you can imprison it!</title>
		<link>http://www.daveoncode.com/2008/11/21/css-tip-if-you-cant-remove-the-evil-you-can-imprison-it/</link>
		<comments>http://www.daveoncode.com/2008/11/21/css-tip-if-you-cant-remove-the-evil-you-can-imprison-it/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 15:13:59 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[browser incopatibility]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery plugin]]></category>
		<category><![CDATA[positioning]]></category>

		<guid isPermaLink="false">http://daveoncode.wordpress.com/?p=57</guid>
		<description><![CDATA[Yesterday a colleague asked me to help her in debugging a crazy behavior of internet explorer 6 (all the others browsers worked fine!), which caused the wrong display of the boxes inside the page. The bug was caused by the rendering of a jQuery powered div, ie one of those things like: $("#myDivID").doMagic({...}); In somehow [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.daveoncode.com/2008/11/21/css-tip-if-you-cant-remove-the-evil-you-can-imprison-it/' addthis:title='CSS tip: if you can&#8217;t remove the evil, you can imprison it! ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-60" style="margin: 0pt 10px 10px 0pt;" title="prison" src="http://www.daveoncode.com/wp-content/uploads/2008/11/prison1.gif" alt="prison" />Yesterday a colleague asked me to help her in debugging a crazy behavior of internet explorer 6 (all the others browsers worked fine!), which caused the wrong display of the boxes inside the page. The bug was caused by the rendering of a jQuery powered div, ie one of those things like:</p>
<pre>$("#myDivID").doMagic({...});</pre>
<p>In somehow the jQuery&#8217;s function used, annoyed ie6 due to the CSS styles that it applied to the div. After a couple of minutes of debugging, I realized that we should have needed to spend a full day or more to fix the problem at the root (due to the complexity of the page content). So I decided to isolate the problem by using the CSS positioning technique. Fundamentally <span class="__mozilla-findbar-search" style="background-color:yellow;color:black;display:inline;font-size:inherit;padding:0;">I</span> put the div (&#8220;#myDivID&#8221;) into another div with relative position and set the first with an absolute position, in this way:</p>
<pre>&lt;div style="position: relative; width: Npx; height: Npx;"&gt;
    &lt;div id="myDivID" style="position: absolute; top: 0; left: 0;"&gt;&lt;/div&gt;
&lt;/div&gt;</pre>
<p>With this expedient &#8220;myDivID&#8221; is now &#8220;trapped&#8221; into the parent div and it can&#8217;t influence the others page elements.</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.daveoncode.com/2008/11/21/css-tip-if-you-cant-remove-the-evil-you-can-imprison-it/' addthis:title='CSS tip: if you can&#8217;t remove the evil, you can imprison it! ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2008/11/21/css-tip-if-you-cant-remove-the-evil-you-can-imprison-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handle multiple ajax calls in a fixed incremental order</title>
		<link>http://www.daveoncode.com/2008/11/10/handle-multiple-ajax-calls-in-a-fixed-incremental-order/</link>
		<comments>http://www.daveoncode.com/2008/11/10/handle-multiple-ajax-calls-in-a-fixed-incremental-order/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 16:11:46 +0000</pubDate>
		<dc:creator>Davide Zanotti</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://daveoncode.wordpress.com/?p=6</guid>
		<description><![CDATA[In a project which I&#8217;m working on, I&#8217;ve realized a Javascript object (I&#8217;ve called it MediaBrowser), which displays images and flv videos into a box (a dynamic div rendered at runtime). The data used by this object is contained into multiple XML files, which are loaded by ajax (potentially it can loads infinite files passed [...]<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.daveoncode.com/2008/11/10/handle-multiple-ajax-calls-in-a-fixed-incremental-order/' addthis:title='Handle multiple ajax calls in a fixed incremental order ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>In a project which I&#8217;m working on, I&#8217;ve realized a Javascript object (I&#8217;ve called it MediaBrowser), which displays images and flv videos into a box (a dynamic div rendered at runtime). The data used by this object is contained into multiple XML files, which are loaded by ajax (potentially it can loads infinite files passed as array of urls). The problem was: ajax is by definition asynchronous, so each time I load the page with my cool MediaBrowser, the order in which the objects (images and videos) are processed and displayed varies based on the order in which responses to the ajax calls are returned. IE: if I call file_1.xml, file_2.xml and file_3.xml, which contain respectively:</p>
<p><span id="more-6"></span></p>
<ul>
<li>file_A, file_B, file_C</li>
<li>file_D, file_E</li>
<li>file_F</li>
</ul>
<p>I can get the following display order:</p>
<ol>
<li>file_A</li>
<li>file_B</li>
<li>file_C</li>
<li>file_D</li>
<li>file_E</li>
<li>file_F</li>
</ol>
<p>which is what I want, but more probably I will get a similar order:</p>
<ol>
<li>file_D</li>
<li>file_E</li>
<li>file_A</li>
<li>file_B</li>
<li>file_C</li>
<li>file_F</li>
</ol>
<p>because the ajax responses are returned (due to the case) in this order: file_2.xml, file_1.xml and file_3.xml. This is not acceptable, specially due to a project requirement which force the reload of the page each time the user select any of the object displayed in order to see its details.</p>
<p>So, I&#8217;ve realized a sort of &#8220;priority tail&#8221; by adding an extra XML node, called &lt;priority&gt; to the XML document returned from the ajax call. This has been possible by using the parameter <em><strong>dataFilter</strong></em> provided by jQuery&#8217;s $.ajax() method, which accepts a function callback to apply an extra data-processing operation.</p>
<p>This is a piece of code:</p>
<pre>$.ajax({
  type: "GET",
  url: XMLUrl,
  dataType: "xml",
  cache: this.cacheAjax,
  success: this._storeData,
  error: this._storeError,
  dataFilter: function(data) {

    var root, newNode, newNodeValue;

    root = data.getElementsByTagName('pics')[0];
    newNode = data.createElement("priority");
    newNodeValue = data.createTextNode(priority);
    newNode.appendChild(newNodeValue);
    root.appendChild(newNode);

    return data;

  }
});</pre>
<p>The <em><strong>priority</strong></em> variable is passed as a parameter to a method (this._startAjaxRequest()) that wraps the jQuery code ($.ajax()). In this way I can store the data retrieved (basically i put the XML documents into an array) from the ajax calls randomly (based on the responses order) and then I can sort the store (by using the <em><strong>priority</strong></em> value) and display the objects always in the same order.</p>
<p>This is a piece of code of <em><strong>this._storeData()</strong></em> that shows how the data is stored for further processing operations:</p>
<pre>this._storeData = function(xhr) {

  var XMLDoc = xhr.documentElement;

  // adds the XML document to the MediaBrowser's dataStore
  instance.dataStore.push({
	doc: XMLDoc,
	priority: XMLDoc.getElementsByTagName("priority")[0].firstChild.nodeValue
  });
...</pre>
<p>&#8230;and this is the method which sorts the data into array:</p>
<pre>this._sortDataStore = function() {
  instance.dataStore.sort(
    function(a, b) {
      return a.priority - b.priority;
    }
  );
}</pre>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://www.daveoncode.com/2008/11/10/handle-multiple-ajax-calls-in-a-fixed-incremental-order/' addthis:title='Handle multiple ajax calls in a fixed incremental order ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.daveoncode.com/2008/11/10/handle-multiple-ajax-calls-in-a-fixed-incremental-order/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

