<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>D-talk (Entries tagged as ajax)</title>
    <link>http://blog.dynom.nl/</link>
    <description>The little things that pop into mind</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.2-beta4 - http://www.s9y.org/</generator>
    
    

<item>
    <title>Click many, call once with jQuery</title>
    <link>http://blog.dynom.nl/archives/Click-many,-call-once-with-jQuery_20091006_48.html</link>
            <category>Javascript</category>
    
    <comments>http://blog.dynom.nl/archives/Click-many,-call-once-with-jQuery_20091006_48.html#comments</comments>
    <wfw:comment>http://blog.dynom.nl/wfwcomment.php?cid=48</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://blog.dynom.nl/rss.php?version=2.0&amp;type=comments&amp;cid=48</wfw:commentRss>
    

    <author>nospam@example.com (Mark van der Velden)</author>
    <content:encoded>
    &lt;p&gt;Recently I wanted to improve they way some anchors where handled in my recent project, it works a bit like adding and removing items to/from a list. But it was possible to trick the interface by quickly clicking multiple times on a link before the AJAX request was finished, while the back-end handled this without any problems, the interface for the visitor couldn&#039;t. And since I&#039;m a neat freak and I had a few minutes to spare, I came up with the following.&lt;/p&gt;&lt;p&gt;A working example: &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/dynom.nl/jquery/clickmanycallonce.html&#039;);&quot;  href=&quot;http://dynom.nl/jquery/clickmanycallonce.html&quot; mce_href=&quot;http://dynom.nl/jquery/clickmanycallonce.html&quot;&gt;http://dynom.nl/jquery/clickmanycallonce.html&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;
&lt;div class=&quot;javascript&quot; style=&quot;text-align: left&quot;&gt;My.&lt;span style=&quot;color: #006600;&quot;&gt;items&lt;/span&gt; = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; init : &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// Bind the real item only once, and the dummy item permanently&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// This way the *real* item is only called once, regardless of the amount of clicks&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// And the link remains clickable but doesn&#039;t trigger the browser to follow it.&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; $&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;&#039;ul&amp;gt;li&amp;gt;a.item&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;one&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;&#039;click&#039;&lt;/span&gt;, My.&lt;span style=&quot;color: #006600;&quot;&gt;items&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;real_action&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;&#039;click&#039;&lt;/span&gt;, My.&lt;span style=&quot;color: #006600;&quot;&gt;items&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;dummy_action&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;,&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; dummy_action : &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; $&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt; $&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; + &lt;span style=&quot;color: #3366CC;&quot;&gt;&#039;.&#039;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;false&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;,&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; real_action : &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;/* Fancy AJAX call, that shouldn&#039;t be executed more then once for every click */&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; $&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;&#039;div#frame&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;$&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #3366CC;&quot;&gt;&#039;div#frame&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; + &lt;span style=&quot;color: #3366CC;&quot;&gt;&quot;&amp;lt;br&amp;gt;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;Calling &#039;real_action&#039; for anchor: &quot;&lt;/span&gt; + $&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;false&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// When the DOM is ready&lt;/span&gt;&lt;br /&gt;$&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;document&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;ready&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// Attach the filter to our input and list&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; My.&lt;span style=&quot;color: #006600;&quot;&gt;items&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;init&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;/div&gt;

&lt;/p&gt;&lt;p&gt;While the code is fairly self explanatory and quite simple here the steps in a bit more detail:&lt;/p&gt;&lt;ol&gt;
  &lt;li&gt; Unobtrusively binding, as soon as the DOM is ready. &lt;/li&gt;
  &lt;li&gt; Binding the real action handler on &#039;click&#039; action with jQuery&#039;s  &#039;one()&#039; event handler &lt;/li&gt;
  &lt;li&gt; Binding the dummy action handler on &#039;click&#039; action with the &#039;bind()&#039; event handler &lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;This situation is probably only favorable if the item you click is removed from the DOM (or has actions re-bound after the call) else it might not be what you want.&lt;/p&gt; 
    </content:encoded>

    <pubDate>Tue, 06 Oct 2009 12:28:00 +0200</pubDate>
    <guid isPermaLink="false">http://blog.dynom.nl/archives/guid_20091006_48.html</guid>
    <category>ajax</category>
<category>ignoring double click</category>
<category>javascript</category>
<category>jquery</category>

</item>
<item>
    <title>Javascript unordened list sorting</title>
    <link>http://blog.dynom.nl/archives/Javascript-unordened-list-sorting_20090511_36.html</link>
            <category>Javascript</category>
    
    <comments>http://blog.dynom.nl/archives/Javascript-unordened-list-sorting_20090511_36.html#comments</comments>
    <wfw:comment>http://blog.dynom.nl/wfwcomment.php?cid=36</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://blog.dynom.nl/rss.php?version=2.0&amp;type=comments&amp;cid=36</wfw:commentRss>
    

    <author>nospam@example.com (Mark van der Velden)</author>
    <content:encoded>
    &lt;p&gt;I spent some time figuring out a way to sort unordened lists, when dynamically (AJAX) adding/removing items. I had some problems with the typical &#039;10 being greater then 1, but lesser then 2&#039;, so I took a simple bubblesort algorithm and tweaked it with the string length. It&#039;s probably not the fastest or most elegant way of doing it, but it works like a charm. If you have any improvement points, don&#039;t be shy and drop a line. &lt;/p&gt;&lt;p&gt;&amp;#160;&lt;/p&gt;&lt;p&gt;&lt;b&gt;The algorithm:&lt;/b&gt;&lt;br /&gt;
This is the search algorithm I used, (which I found &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/www.merlyn.demon.co.uk/js-order.htm&#039;);&quot;  href=&quot;http://www.merlyn.demon.co.uk/js-order.htm&quot; mce_href=&quot;http://www.merlyn.demon.co.uk/js-order.htm&quot;&gt;here&lt;/a&gt;) and I simply added the difference in string length to the equation to make sure that &#039;10&#039; is greater then &#039;1&#039;, causing human-natural sorting.&lt;/p&gt;&lt;p&gt;
&lt;div class=&quot;javascript&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// Search algorithm, if lesser then 0 it&#039;s smaller then the current item.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// If it&#039;s greater then 0, it&#039;s &amp;quot;larger&amp;quot; then the current item.&lt;/span&gt;&lt;br /&gt;cmpr =&amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;newItem &amp;gt; curListItem&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; - &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;curListItem &amp;gt; newItem&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; +&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;newItem.&lt;span style=&quot;color: #006600;&quot;&gt;length&lt;/span&gt; - curListItem.&lt;span style=&quot;color: #006600;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;b&gt;Before:&lt;/b&gt; Title 1, Title 10, Title 13, Title 2, Title 3, Title 4&lt;br /&gt;
&lt;b&gt;After:&lt;/b&gt; Title 1, Title 2, Title 3, Title 4, Title 10, Title 13
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;Read on to see a implementation example...&lt;/p&gt; &lt;br /&gt;&lt;a href=&quot;http://blog.dynom.nl/archives/Javascript-unordened-list-sorting_20090511_36.html#extended&quot;&gt;Continue reading &quot;Javascript unordened list sorting&quot;&lt;/a&gt;
    </content:encoded>

    <pubDate>Mon, 11 May 2009 15:19:35 +0200</pubDate>
    <guid isPermaLink="false">http://blog.dynom.nl/archives/guid_20090511_36.html</guid>
    <category>ajax</category>
<category>bubble sort</category>
<category>javascript</category>
<category>jquery</category>
<category>li</category>
<category>natural sort</category>
<category>ul</category>
<category>unordened list</category>

</item>

</channel>
</rss>