<?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 jquery)</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>Sorting of lists in jQuery</title>
    <link>http://blog.dynom.nl/archives/Sorting-of-lists-in-jQuery_20091006_49.html</link>
            <category>Javascript</category>
    
    <comments>http://blog.dynom.nl/archives/Sorting-of-lists-in-jQuery_20091006_49.html#comments</comments>
    <wfw:comment>http://blog.dynom.nl/wfwcomment.php?cid=49</wfw:comment>

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

    <author>nospam@example.com (Mark van der Velden)</author>
    <content:encoded>
    &lt;p&gt;A while back I posted a simple sorting algorithm for number sorting, but it doesn&#039;t really do the trick for regular strings (e.g. anchors). But since I needed one recently I wrote another small and very simple sorting solution. &lt;/p&gt;&lt;p&gt;For a working example, see: &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/dynom.nl/jquery/listsort.php&#039;);&quot;  href=&quot;http://dynom.nl/jquery/listsort.php&quot; mce_href=&quot;http://dynom.nl/jquery/listsort.php&quot;&gt;http://dynom.nl/jquery/listsort.php&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;List&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; Sort : &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;listSelector&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: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; sortedElements, left, right;&lt;br /&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;// If we have any list items to sort on&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;if&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;listSelector + &lt;span style=&quot;color: #3366CC;&quot;&gt;&#039; li&#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;length&lt;/span&gt; &amp;gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;0&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; &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;// Remove the items from the DOM&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; sortedElements = $&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;listSelector + &lt;span style=&quot;color: #3366CC;&quot;&gt;&#039; li&#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;remove&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;&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: #009900; font-style: italic;&quot;&gt;// Sort, using a custom sorting and compare by anchor contents&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; sortedElements.&lt;span style=&quot;color: #006600;&quot;&gt;sort&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;a, b&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; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; left = $&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;a&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;children&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;a&#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;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; &amp;#160; &amp;#160; &amp;#160; &amp;#160; right = $&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;b&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;children&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;a&#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;br /&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; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;left &amp;gt; right&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; &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: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;1&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; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;right &amp;lt; left&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; &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: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; -&lt;span style=&quot;color: #CC0000;&quot;&gt;1&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; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;else&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; &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: #000066; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;0&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; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&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;#125;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&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: #009900; font-style: italic;&quot;&gt;// Place the items back on the DOM&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;listSelector&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;sortedElements&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;#125;&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;/div&gt;&lt;/p&gt;&lt;p&gt;Again, the source should be self explanatory&lt;/p&gt;&lt;p&gt;&amp;#160;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Tue, 06 Oct 2009 13:00:00 +0200</pubDate>
    <guid isPermaLink="false">http://blog.dynom.nl/archives/guid_20091006_49.html</guid>
    <category>anchor</category>
<category>filter</category>
<category>javascript</category>
<category>jquery</category>
<category>link</category>
<category>list</category>
<category>sort</category>
<category>ul</category>

</item>
<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>jQuery simple unordered list filter</title>
    <link>http://blog.dynom.nl/archives/jQuery-simple-unordered-list-filter_20090624_39.html</link>
            <category>Javascript</category>
    
    <comments>http://blog.dynom.nl/archives/jQuery-simple-unordered-list-filter_20090624_39.html#comments</comments>
    <wfw:comment>http://blog.dynom.nl/wfwcomment.php?cid=39</wfw:comment>

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

    <author>nospam@example.com (Mark van der Velden)</author>
    <content:encoded>
    &lt;p&gt;I needed a simple filter system on a unordered list. The goal is to filter &#039;realtime&#039; based on what a user is typing. I came up with the following, if you have any suggestions and/or performance tips feel free to drop a line!&lt;/p&gt;
&lt;h2&gt;The HTML:&lt;/h2&gt;&lt;p&gt;The blog software is messing with the HTML, for a working example with ungarbled code. Look at the bottom of this post.&lt;/p&gt;&lt;p&gt;
&lt;div style=&quot;text-align: left&quot;&gt;&amp;lt;/p&amp;gt;&amp;lt;div&amp;gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;lt;input name=&amp;quot;filter&amp;quot; id=&amp;quot;search_filter&amp;quot; type=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&amp;lt;div id=&amp;quot;titles&amp;quot;&amp;gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;lt;ul&amp;gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;http://blog.dynom.nl/path/to/item/1&amp;quot;&amp;gt;Item 1&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;http://blog.dynom.nl/path/to/item/2&amp;quot;&amp;gt;Item 2&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;http://blog.dynom.nl/path/to/item/3&amp;quot;&amp;gt;Item 3&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;lt;/ul&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&amp;#160;&lt;/p&gt;
&lt;h2&gt;The Javascript&lt;/h2&gt;&lt;p&gt;&lt;div class=&quot;javascript&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; My = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&amp;#160; &amp;#160; &amp;#160;&lt;br /&gt;My.&lt;span style=&quot;color: #006600;&quot;&gt;List&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; Filter : &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;inputSelector, listSelector&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; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// Sanity check&amp;#160; &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: #003366; font-weight: bold;&quot;&gt;var&lt;/span&gt; inp, rgx = &lt;span style=&quot;color: #003366; font-weight: bold;&quot;&gt;new&lt;/span&gt; RegExp&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;, titles = $&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;listSelector&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, keys;&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;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;titles.&lt;span style=&quot;color: #006600;&quot;&gt;length&lt;/span&gt; === &lt;span style=&quot;color: #CC0000;&quot;&gt;0&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; &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; &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; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #009900; font-style: italic;&quot;&gt;// The list with keys to skip (esc, arrows, return, etc)&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;// 8 is backspace, you might want to remove that for better usability&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; keys = &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt; &lt;span style=&quot;color: #CC0000;&quot;&gt;13&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;27&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;32&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;37&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;38&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;39&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;40&lt;/span&gt;, &lt;span style=&quot;color: #CC0000;&quot;&gt;8&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&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;// binding keyup to the unordered list&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;inputSelector&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;keyup&#039;&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;e&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; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;jQuery.&lt;span style=&quot;color: #006600;&quot;&gt;inArray&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;e.&lt;span style=&quot;color: #006600;&quot;&gt;keyCode&lt;/span&gt;, keys&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;gt;= &lt;span style=&quot;color: #CC0000;&quot;&gt;0&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; &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; &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;#125;&lt;/span&gt;&lt;br /&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: #009900; font-style: italic;&quot;&gt;// Building the regex from our user input, &#039;inp&#039; should be escaped&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; inp = $&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;attr&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;value&#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; &amp;#160; &amp;#160; &amp;#160; &amp;#160; rgx.&lt;span style=&quot;color: #006600;&quot;&gt;compile&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;inp, &lt;span style=&quot;color: #3366CC;&quot;&gt;&#039;im&#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; &amp;#160; &amp;#160; &amp;#160; &amp;#160; titles.&lt;span style=&quot;color: #006600;&quot;&gt;each&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;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &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: #000066; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;rgx.&lt;span style=&quot;color: #006600;&quot;&gt;source&lt;/span&gt; !== &lt;span style=&quot;color: #3366CC;&quot;&gt;&#039;&#039;&lt;/span&gt; &amp;amp;&amp;amp; !rgx.&lt;span style=&quot;color: #006600;&quot;&gt;test&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: #66cc66;&quot;&gt;&amp;#41;&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; &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;&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;parent&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;li&#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;hide&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;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &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;#125;&lt;/span&gt; &lt;span style=&quot;color: #000066; font-weight: bold;&quot;&gt;else&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; &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;&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;parent&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;li&#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;show&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;;&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; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&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;#125;&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;#125;&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;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;&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;List&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;Filter&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;input#search_filter&#039;&lt;/span&gt;, &lt;span style=&quot;color: #3366CC;&quot;&gt;&#039;#titles&amp;gt;ul&amp;gt;li&amp;gt;a&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&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;h2&gt;Working example&lt;/h2&gt;&lt;p&gt;Visit &lt;a onclick=&quot;javascript: pageTracker._trackPageview(&#039;/extlink/dynom.nl/jquery/list.php&#039;);&quot;  href=&quot;http://dynom.nl/jquery/list.php&quot; title=&quot;Working example&quot; mce_href=&quot;http://dynom.nl/jquery/list.php&quot;&gt;http://dynom.nl/jquery/list.php&lt;/a&gt; for a working example. &lt;br /&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Wed, 24 Jun 2009 15:50:21 +0200</pubDate>
    <guid isPermaLink="false">http://blog.dynom.nl/archives/guid_20090624_39.html</guid>
    <category>each</category>
<category>filter</category>
<category>inarray</category>
<category>javascript</category>
<category>jquery</category>
<category>list</category>
<category>parent</category>
<category>regexp</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>