<?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>ADM Blog &#187; Java Script</title> <atom:link href="http://blog.another-d-mention.ro/category/programming/java-script/feed/" rel="self" type="application/rss+xml" /><link>http://blog.another-d-mention.ro</link> <description>No matter how you see things, reality changes when you reach understanding</description> <lastBuildDate>Fri, 22 Jul 2011 06:56:49 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1</generator> <item><title>Read data directly from base64 without decoding</title><link>http://blog.another-d-mention.ro/programming/java-script/read-data-directly-from-base64-without-decoding/</link> <comments>http://blog.another-d-mention.ro/programming/java-script/read-data-directly-from-base64-without-decoding/#comments</comments> <pubDate>Fri, 01 Jul 2011 13:06:55 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[base64]]></category> <category><![CDATA[decode]]></category> <category><![CDATA[javascript]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=855</guid> <description><![CDATA[So here's the catch. You have a binary input you want to mess with in your browser for whatever reason. First problem you encounter is when you load the file. In IE you will have trouble reading a binary string because it uses null terminated strings, and your file will end at the first 0x00 [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/' rel='bookmark' title='Permanent Link: jQuery.quickEach'>jQuery.quickEach</a></li></ol>]]></description> <content:encoded><![CDATA[<p>So here's the catch. You have a binary input you want to mess with in your browser for whatever reason. First problem you encounter is when you load the file. In IE you will have trouble reading a binary string because it uses null terminated strings, and your file will end at the first 0x00 byte found. If you manage to overcome that but trust me it is very CPU intensive. See the source of <a
href="http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/">Read/Load files from ZIP in Javascript</a> post. You will have to create a vbScript that will convert the received AJAX response into an array with decimal values for each byte in the file. Depending on your file size, it will take accordingly (10+ seconds * file KB). For every other browser it works just fine with plain strings.</p><p>Okay, one other potential issue may come if you need to receive the data into a JSON string or XML or whatever beside a plain binary file. Then you have to use BASE64 encoding and decode your data into a variable but must keep in mind the first issue with the null characters. My solution to this problem is to create a method to read directly from the BASE64 encoded string at arbitrary locations without decoding the entire thing.</p><p>Here's an example of a binary file:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">Offset<span style="color: #009900;">&#40;</span>h<span style="color: #009900;">&#41;</span>00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
&nbsp;
00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F     ...............
00000010 <span style="color: #CC0000;">19</span> <span style="color: #CC0000;">84</span> <span style="color: #CC0000;">74</span> <span style="color: #CC0000;">68</span> <span style="color: #CC0000;">69</span> <span style="color: #CC0000;">73</span> <span style="color: #CC0000;">20</span> <span style="color: #CC0000;">69</span> <span style="color: #CC0000;">73</span> <span style="color: #CC0000;">20</span> <span style="color: #CC0000;">61</span> <span style="color: #CC0000;">20</span> <span style="color: #CC0000;">74</span> <span style="color: #CC0000;">65</span> <span style="color: #CC0000;">73</span> <span style="color: #CC0000;">74</span>     ..<span style="color: #000066; font-weight: bold;">this</span> <span style="color: #000066; font-weight: bold;">is</span> a test</pre></div></div><p>You have 32 bytes in this file, with BASE64 encoding you get a 46 chars length string:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">   AAECAwQFBgcICQoLDA0ODxmEdGhpcyBpcyBhIHRlc3Q<span style="color: #339933;">=</span></pre></div></div><p>A usage example:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">    <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Base64Native<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;AAECAwQFBgcICQoLDA0ODxmEdGhpcyBpcyBhIHRlc3Q=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 32;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">readBoolean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs false; - reads a byte and casts it to a boolean value</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">readByte</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 1;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">readWord</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 515; - reads a 16 bit number</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">readInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 67438087; - reads a 32 bit number</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">seek</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">28</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// moves the pointer to byte 28 (0x1C)</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">readString</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">bytesAvailable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 'test'; reads a string from position 28 to the end of the file</span></pre></div></div><p>And here's the class</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Base64Native <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> keyStr <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=&quot;</span><span style="color: #339933;">,</span>
        length <span style="color: #339933;">=</span> data.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">length</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/=/g</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        ptr <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> keyIdx<span style="color: #009900;">&#40;</span>idx<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> keyStr.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span>idx<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>length <span style="color: #339933;">-</span> ptr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">throw</span> Error<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'End of stream!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
        <span style="color: #003366; font-weight: bold;">var</span> blockIndex <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>ptr <span style="color: #339933;">/</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> subIndex <span style="color: #339933;">=</span> ptr<span style="color: #339933;">++</span> <span style="color: #339933;">%</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> ptrChr <span style="color: #339933;">=</span> blockIndex <span style="color: #339933;">+</span> subIndex<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #339933;">!</span>subIndex <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>keyIdx<span style="color: #009900;">&#40;</span>ptrChr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>keyIdx<span style="color: #009900;">&#40;</span>ptrChr <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> subIndex <span style="color: #339933;">===</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">&amp;&amp;</span>
               <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>keyIdx<span style="color: #009900;">&#40;</span>ptrChr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #CC0000;">15</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>keyIdx<span style="color: #009900;">&#40;</span>ptrChr <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;&gt;</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>keyIdx<span style="color: #009900;">&#40;</span>ptrChr<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span>  <span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span>  keyIdx<span style="color: #009900;">&#40;</span>ptrChr <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009966; font-style: italic;">/* Returns the available bytes left in the file to read */</span>
        bytesAvailable <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> length <span style="color: #339933;">-</span> ptr<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Reads and returns a 8 bit number and increments the position of the index accordingly */</span>
        readByte <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Reads and returns a 32 bit number and increments the position of the index accordingly */</span>
        readInt <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #CC0000;">24</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #CC0000;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #CC0000;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Reads 1 byte and returns the boolean value of it and increments the position of the index accordingly */</span>
        readBoolean <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> Boolean<span style="color: #009900;">&#40;</span>readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Reads and returns a 16 bit number and increments the position of the index accordingly */</span>
        readWord <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #CC0000;">8</span> <span style="color: #339933;">|</span> readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Reads and returns a string of length 'len' and increments the position of the index accordingly */</span>
        readString <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #006600; font-style: italic;">/*String*/</span>len<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                data <span style="color: #339933;">+=</span> String.<span style="color: #660066;">fromCharCode</span><span style="color: #009900;">&#40;</span>readByte<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">return</span> data<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Moves the index into the file at location newpos */</span>
        seek <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>newpos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            ptr <span style="color: #339933;">=</span> newpos<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* Returns the position of the index in the file */</span>
        position <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> ptr<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #009966; font-style: italic;">/* The length of the data */</span>
        length <span style="color: #339933;">:</span> length
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div> </pre><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/' rel='bookmark' title='Permanent Link: jQuery.quickEach'>jQuery.quickEach</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/java-script/read-data-directly-from-base64-without-decoding/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>jQuery.quickEach</title><link>http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/</link> <comments>http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/#comments</comments> <pubDate>Wed, 04 May 2011 09:13:08 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[plugin]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=847</guid> <description><![CDATA[With jQuery, when you need to iterate all elements with a specific class for example, you use the each() method and inside the callback function you must convert the DOM element you receive as this to a jQuery object in order to access it's jQuery specific methods: $(this) This is not such a big issue [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/on-typing-complete-jquery-plugin/' rel='bookmark' title='Permanent Link: On typing finished jQuery plugin'>On typing finished jQuery plugin</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/' rel='bookmark' title='Permanent Link: Parse XML in JavaScript with jQuery'>Parse XML in JavaScript with jQuery</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li></ol>]]></description> <content:encoded><![CDATA[<p>With jQuery, when you need to iterate all elements with a specific class for example, you use the <code>each()</code> method and inside the callback function you must convert the DOM element you receive as <code>this</code> to a jQuery object in order to access it's jQuery specific methods: <code>$(this)</code><br
/> This is not such a big issue but if you have a lot of items and/or do this often, then times ads up. It would be a blast to have the <code>this</code> object directly as a jQuery instance. So here's a $ little plugin that does exactly that</p><p>Source website:<br
/> <a
href="http://jsperf.com/jquery-each-vs-quickeach" target="_blank">http://jsperf.com/jquery-each-vs-quickeach</a></p><p>The code:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">quickEach</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> jq <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>
       el<span style="color: #339933;">,</span> len <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span>i <span style="color: #339933;">&lt;</span> len <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>el <span style="color: #339933;">=</span> jq<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> c.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>jq<span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> el<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">delete</span> jq<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">throw</span> e<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #000066; font-weight: bold;">delete</span> jq<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>If you run the test on that page, on most browsers you'll see that quickEach() is about 80% faster than native each()</pre><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/on-typing-complete-jquery-plugin/' rel='bookmark' title='Permanent Link: On typing finished jQuery plugin'>On typing finished jQuery plugin</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/' rel='bookmark' title='Permanent Link: Parse XML in JavaScript with jQuery'>Parse XML in JavaScript with jQuery</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>For Javascript devs</title><link>http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/</link> <comments>http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/#comments</comments> <pubDate>Wed, 30 Mar 2011 08:08:18 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[html]]></category> <category><![CDATA[htmtag]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[querytag]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=846</guid> <description><![CDATA[If you write Javascript apps you may want to dynamically add some HTML here and there and having HTML strings that need concatenation with different variables is bad and ugly at the same time. So here is a little nugget you might find useful. 1 2 3 4 5 // standard style x = '&#60;div [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li><li><a
href='http://blog.another-d-mention.ro/programming/communicate-betwen-c-and-an-embeded-flash-application/' rel='bookmark' title='Permanent Link: Communicate betwen C# and an embeded Flash application'>Communicate betwen C# and an embeded Flash application</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol>]]></description> <content:encoded><![CDATA[<p>If you write Javascript apps you may want to dynamically add some HTML here and there and having HTML strings that need concatenation with different variables is bad and ugly at the same time. So here is a little nugget you might find useful.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">    <span style="color: #006600; font-style: italic;">// standard style</span>
    x <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;div class=&quot;'</span> <span style="color: #339933;">+</span> classnames <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; rel=&quot;'</span> <span style="color: #339933;">+</span> somevar <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; id=&quot;'</span> <span style="color: #339933;">+</span> othervar <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span> content <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// html tag style</span>
    x <span style="color: #339933;">=</span> htmlTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">:</span>classname<span style="color: #339933;">,</span> rel<span style="color: #339933;">:</span>somevar<span style="color: #339933;">,</span> id<span style="color: #339933;">:</span>othervar<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><h3>Usage</h3><p> <code>htmlTag(tagName [, attributes [, content]])</code><br
/> or<br
/> <code>htmlTag(tagName [, content [, attributes]])</code></p><p>The function can be called with one, two or three arguments. Beside the first one which is the name of the tag (string), the other two are optional and can be placed in whatever order you like.<br
/> For <strong>img</strong> tags, the content argument is set as <i>src</i> attribute or as <i>value</i> attribute for <strong>input</strong> tags if the attributes argument doesn't specify otherwise</p><p><i>attributes</i> argument must be an object with key:value pairs and will be expanded as attributes of the tag<br
/> <i>content</i> argument is a string or number</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">    <span style="color: #003366; font-weight: bold;">var</span> classname <span style="color: #339933;">=</span> <span style="color: #3366CC;">'test'</span><span style="color: #339933;">,</span> somevar <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> id <span style="color: #339933;">=</span> <span style="color: #3366CC;">'mydiv'</span><span style="color: #339933;">,</span> content <span style="color: #339933;">=</span> <span style="color: #3366CC;">'hello'</span><span style="color: #339933;">;</span>
&nbsp;
    htmlTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">:</span>classname<span style="color: #339933;">,</span> rel<span style="color: #339933;">:</span>somevar<span style="color: #339933;">,</span> id<span style="color: #339933;">:</span>othervar<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    htmlTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> content<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">:</span>classname<span style="color: #339933;">,</span> rel<span style="color: #339933;">:</span>somevar<span style="color: #339933;">,</span> id<span style="color: #339933;">:</span>othervar<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// will both return &lt;div class='test' rel='2' id='mydiv'&gt;hello&lt;/div&gt;</span>
&nbsp;
    htmlTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span>
    <span style="color: #006600; font-style: italic;">// &lt;img src='hello' /&gt;</span>
    htmlTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>src<span style="color: #339933;">:</span><span style="color: #3366CC;">'myImage.jpg'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span>
    <span style="color: #006600; font-style: italic;">// &lt;img src='myImage.jpg' /&gt; content is discarded and attributes src is used as source</span>
&nbsp;
    htmlTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>type<span style="color: #339933;">:</span><span style="color: #3366CC;">'text'</span><span style="color: #339933;">,</span> <span style="color: #000066;">name</span><span style="color: #339933;">:</span>id<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span>
    <span style="color: #006600; font-style: italic;">// &lt;input type=&quot;text&quot; name=&quot;mydiv&quot; value=&quot;hello&quot; /&gt;</span></pre></td></tr></table></div><h3>The code</h3><p></p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> htmlTag<span style="color: #009900;">&#40;</span>type<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> r<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&lt; &quot;</span><span style="color: #339933;">+</span>type<span style="color: #339933;">,</span>o<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>v<span style="color: #339933;">=</span><span style="color: #3366CC;">''</span><span style="color: #339933;">,</span>x<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>a<span style="color: #339933;">=</span>arguments<span style="color: #339933;">;</span>
    a.<span style="color: #660066;">length</span><span style="color: #339933;">==</span><span style="color: #CC0000;">3</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">typeof</span> a<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'object'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>o<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span><span style="color: #339933;">-</span>~<span style="color: #339933;">!</span>x<span style="color: #009900;">&#93;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>v<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span><span style="color: #339933;">-</span>~x<span style="color: #009900;">&#93;</span><span style="color: #339933;">||</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span>a.<span style="color: #660066;">length</span><span style="color: #339933;">==</span><span style="color: #CC0000;">2</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> a<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'object'</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>o<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>v<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">||</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> o<span style="color: #009900;">&#41;</span>r<span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;='&quot;</span><span style="color: #339933;">+</span>o<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#40;</span>type<span style="color: #339933;">==</span><span style="color: #3366CC;">'img'</span><span style="color: #339933;">||</span>type<span style="color: #339933;">==</span><span style="color: #3366CC;">'br'</span><span style="color: #339933;">||</span>type<span style="color: #339933;">==</span><span style="color: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>o.<span style="color: #660066;">src</span><span style="color: #339933;">&amp;&amp;</span>v<span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>type<span style="color: #339933;">==</span><span style="color: #3366CC;">'img'</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>r<span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot; src='&quot;</span><span style="color: #339933;">+</span>v<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;' /&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>type<span style="color: #339933;">==</span><span style="color: #3366CC;">'input'</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>r<span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot; value='&quot;</span><span style="color: #339933;">+</span>v<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;' /&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>r<span style="color: #339933;">+=</span><span style="color: #3366CC;">' /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>r<span style="color: #339933;">+=</span><span style="color: #3366CC;">&quot;&gt;&quot;</span><span style="color: #339933;">+</span>v<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt; &quot;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #339933;">+</span>type<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> r<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> queryTag<span style="color: #009900;">&#40;</span>type<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span>htmlTag.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>queryTag function just wraps the newly created html in a jQuery object so you can have something like this</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">     $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#menu&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>
             queryTag<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'menuItem'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Click me'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'clicked'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
             <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#41;</span></pre></td></tr></table></div><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li><li><a
href='http://blog.another-d-mention.ro/programming/communicate-betwen-c-and-an-embeded-flash-application/' rel='bookmark' title='Permanent Link: Communicate betwen C# and an embeded Flash application'>Communicate betwen C# and an embeded Flash application</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Read/Load files from ZIP in JavaScript</title><link>http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/</link> <comments>http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/#comments</comments> <pubDate>Fri, 01 Oct 2010 10:40:05 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[chrome]]></category> <category><![CDATA[firefox]]></category> <category><![CDATA[ie]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[load]]></category> <category><![CDATA[opera]]></category> <category><![CDATA[parse]]></category> <category><![CDATA[read]]></category> <category><![CDATA[safari]]></category> <category><![CDATA[zip]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=837</guid> <description><![CDATA[At work we do a lot of JavaScript applications that have little to no HTML files (beside the index), everything is generated by JavaScript and we have tons of .js files that load at runtime and to reduce the size we have to minify them and that is really hard to debug and watch in [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/read-data-directly-from-base64-without-decoding/' rel='bookmark' title='Permanent Link: Read data directly from base64 without decoding'>Read data directly from base64 without decoding</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol>]]></description> <content:encoded><![CDATA[<p>At work we do a lot of JavaScript applications that have little to no HTML files (beside the index), everything is generated by JavaScript and we have tons of .js files that load at runtime and to reduce the size we have to minify them and that is really hard to debug and watch in the browser if something goes wrong. So I've made this JavaScript class that comes to help. What can you do is Zip up all your assets (js, images, css) and use ZipLoader class to read the zip and unpack your resources whenever you need them. It's small (10KB), easy to use and quite fast considering the extraction is made by JavaScript.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">   <span style="color: #006600; font-style: italic;">// loads and caches the zip file</span>
   <span style="color: #003366; font-weight: bold;">var</span> loader <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ZipLoader<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'files.zip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// creates a style node in the document header and appends the style</span>
   loader.<span style="color: #660066;">LoadCSS</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'files.zip://style.css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// creates a script node in the document header and appends the script</span>
   loader.<span style="color: #660066;">loadScript</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'files.zip://jquery.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// returns the file content</span>
   <span style="color: #003366; font-weight: bold;">var</span> someFileYouNeed <span style="color: #339933;">=</span> loader.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;files.zip://myFile.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// returns the base64 encoded image usable as img source</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#logo&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span> loader.<span style="color: #660066;">loadImage</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'files.zip://images/logo.png'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>The level of compression using zip surpasses the js and css minification in all the ways possible. For example, My current application has 79 files (js, and few css) and they all sum up to 924KB in size. Zipping all those 96 files using Ultra compression level gives me 1 file of 126 KB => 1 server request. That's something.</p><p>The best performance is made Opera (strangely), then Firefox, Crome, Safari and last IE (no surprise here, I was expecting it before I even started).</p><p><del
datetime="2010-10-04T10:42:19+00:00">It's a V 1.0 that still needs some work and it doesn't work in IE because that stupid browser overrides the mime type and at first null character in the reading of the zip, the content ends. I will fix this eventually <img
src='http://blog.another-d-mention.ro/wp-includes/images/smilies/icon_smile.gif' alt="icon smile Read/Load files from ZIP in JavaScript" class='wp-smiley' title="Read/Load files from ZIP in JavaScript" /> </del> I will also include this as a <a
href="http://code.google.com/p/adm-jclass/">jClass</a> library soon.</p><p><strong>Update:</strong> Fixed it so it works in IE as well. There is a performance issue still. Will fix that too.</p><p>Till then, <a
href="http://another-d-mention.ro/apps/download.php?app=archive">HERE</a> are the sources and a demo.</p><p>The zip in the demo is made using <a
href="http://www.7-zip.org/">7Zip</a> with Ultra Compression level.</p><p>Happy codding.</p><p><a
class="FlattrButton" style="display:none;" href="http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/"></a><br
/> <noscript><a
href="http://flattr.com/thing/183347/ReadLoad-files-from-ZIP-in-JavaScript" target="_blank"><br
/> <img
src="http://api.flattr.com/button/flattr-badge-large.png" alt="flattr badge large Read/Load files from ZIP in JavaScript" title="Flattr this" border="0" /></a></noscript></p><p><script type="text/javascript">google_ad_client = "ca-pub-3771432957882119";
/* InsidePost */
google_ad_slot = "9112434755";
google_ad_width = 468;
google_ad_height = 60;</script><br
/> <script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/' rel='bookmark' title='Permanent Link: Open and Save files to Desktop without going to Server'>Open and Save files to Desktop without going to Server</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/read-data-directly-from-base64-without-decoding/' rel='bookmark' title='Permanent Link: Read data directly from base64 without decoding'>Read data directly from base64 without decoding</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/feed/</wfw:commentRss> <slash:comments>50</slash:comments> </item> <item><title>Parse XML in JavaScript with jQuery</title><link>http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/</link> <comments>http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/#comments</comments> <pubDate>Tue, 28 Sep 2010 10:40:42 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[parse]]></category> <category><![CDATA[xml]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=836</guid> <description><![CDATA[Yes, you can do it with XMLDOM and all the other ways out there, but why not use the power of jQuery ? Like so: 1 2 3 4 5 6 7 &#60;root&#62; &#60;items&#62; &#60;item name=&#34;first&#34; id=&#34;1&#34;&#62;Content 1&#60;/item&#62; &#60;item name=&#34;second&#34; id=&#34;2&#34;&#62;Content 2&#60;/item&#62; &#60;/items&#62; &#60;other atribute=&#34;true&#34; /&#62; &#60;/root&#62; 1 2 3 4 var xml = '&#60;root [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/' rel='bookmark' title='Permanent Link: jQuery.quickEach'>jQuery.quickEach</a></li><li><a
href='http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/' rel='bookmark' title='Permanent Link: Read/Load files from ZIP in JavaScript'>Read/Load files from ZIP in JavaScript</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li></ol>]]></description> <content:encoded><![CDATA[<p>Yes, you can do it with XMLDOM and all the other ways out there, but why not use the power of jQuery ?<br
/> Like so:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td
class="code"><pre class="xml" style="font-family:monospace;">   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;first&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Content 1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;second&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Content 2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/items<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;other</span> <span style="color: #000066;">atribute</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">   <span style="color: #003366; font-weight: bold;">var</span> xml <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;root ......'</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// and now you can use jquery selectors to get what you want</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;item[name=second]&quot;</span><span style="color: #339933;">,</span> obj<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 2</span></pre></td></tr></table></div><p></root></pre><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/' rel='bookmark' title='Permanent Link: jQuery.quickEach'>jQuery.quickEach</a></li><li><a
href='http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/' rel='bookmark' title='Permanent Link: Read/Load files from ZIP in JavaScript'>Read/Load files from ZIP in JavaScript</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</title><link>http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/</link> <comments>http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/#comments</comments> <pubDate>Mon, 06 Sep 2010 11:29:28 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[class]]></category> <category><![CDATA[extend]]></category> <category><![CDATA[interface]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jclass]]></category> <category><![CDATA[oop]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=834</guid> <description><![CDATA[I just finished working on a JavaScript 'framework' that will allow you to write highly object-oriented code in your browser. Using jClass you can easily define namespaces, create and extend class, define and implement interfaces, define public/private/static methods, override and overload them, have getters and setters, and so on. The syntax for writing code using [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li><li><a
href='http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/' rel='bookmark' title='Permanent Link: Read/Load files from ZIP in JavaScript'>Read/Load files from ZIP in JavaScript</a></li><li><a
href='http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/' rel='bookmark' title='Permanent Link: How to clone (duplicate) an object in ActionScript 3'>How to clone (duplicate) an object in ActionScript 3</a></li></ol>]]></description> <content:encoded><![CDATA[<p>I just finished working on a JavaScript 'framework' that will allow you to write highly object-oriented code in your browser.<br
/> Using jClass you can easily define namespaces, create and extend class, define and implement interfaces, define public/private/static methods, override and overload them, have getters and setters, and so on.</p><p>The syntax for writing code using jClass looks something like this</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">include<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;some.other.files&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;my.namespace&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    MyClass <span style="color: #339933;">:</span> jClass.<span style="color: #003366; font-weight: bold;">extends</span><span style="color: #009900;">&#40;</span>BaseClass<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">implements</span><span style="color: #009900;">&#40;</span>SomeInterf<span style="color: #339933;">,</span> SomeOtherInterf<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        constructor <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         ....
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">private</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
          ....
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">public</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
          ....
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        static <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
          ....
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    OtherClass <span style="color: #339933;">:</span> jClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
       ......
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div><p>I'm also working on some useful libraries that you can use with jClass.<br
/> Usage examples, documentation and downloads are all available on Google Code right <a
href="http://code.google.com/p/adm-jclass/"><strong>HERE</strong></a></p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/' rel='bookmark' title='Permanent Link: Serialize JavaScript object to JSON'>Serialize JavaScript object to JSON</a></li><li><a
href='http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/' rel='bookmark' title='Permanent Link: Read/Load files from ZIP in JavaScript'>Read/Load files from ZIP in JavaScript</a></li><li><a
href='http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/' rel='bookmark' title='Permanent Link: How to clone (duplicate) an object in ActionScript 3'>How to clone (duplicate) an object in ActionScript 3</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>On typing finished jQuery plugin</title><link>http://blog.another-d-mention.ro/programming/java-script/on-typing-complete-jquery-plugin/</link> <comments>http://blog.another-d-mention.ro/programming/java-script/on-typing-complete-jquery-plugin/#comments</comments> <pubDate>Wed, 11 Aug 2010 08:06:01 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[event]]></category> <category><![CDATA[form]]></category> <category><![CDATA[input]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[plugin]]></category> <category><![CDATA[type]]></category> <category><![CDATA[validation]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=832</guid> <description><![CDATA[If you are developing a form and you require certain validations; check if username is available or not for example - the way to do that is to listen for the change/focusout DOM events. You can also check it on every keypress but if the validation does some expensive checking in the background that is [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/' rel='bookmark' title='Permanent Link: jQuery.quickEach'>jQuery.quickEach</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/' rel='bookmark' title='Permanent Link: Parse XML in JavaScript with jQuery'>Parse XML in JavaScript with jQuery</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li></ol>]]></description> <content:encoded><![CDATA[<p>If you are developing a form and you require certain validations; check if username is available or not for example - the way to do that is to listen for the change/focusout DOM events. You can also check it on every keypress but if the validation does some expensive checking in the background that is out of the question. So here is a really small jQuery plugin that does tell you when a user finished typing inside a text box. The way it does it is to compute the speed the user is typing with and when a delay longer than twice the speed average occurs, the event is triggered and your validation function is called. Simple enough.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">onTypeFinished</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>func<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #003366; font-weight: bold;">var</span> T <span style="color: #339933;">=</span> undefined<span style="color: #339933;">,</span> S <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> D <span style="color: #339933;">=</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span>
     $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;keypress&quot;</span><span style="color: #339933;">,</span> onKeyPress<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;focusout&quot;</span><span style="color: #339933;">,</span> onTimeOut<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">function</span> onKeyPress<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        clearTimeout<span style="color: #009900;">&#40;</span>T<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>S <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> S <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> D <span style="color: #339933;">=</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span> T <span style="color: #339933;">=</span> setTimeout<span style="color: #009900;">&#40;</span>onTimeOut<span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
        <span style="color: #003366; font-weight: bold;">var</span> t <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        D <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>D <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>t <span style="color: #339933;">-</span> S<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span> S <span style="color: #339933;">=</span> t<span style="color: #339933;">;</span> T <span style="color: #339933;">=</span> setTimeout<span style="color: #009900;">&#40;</span>onTimeOut<span style="color: #339933;">,</span> D <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">function</span> onTimeOut<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
           func.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> S <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>The way to use it:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[name='username']&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">onTypeFinished</span><span style="color: #009900;">&#40;</span>myValidationFunction<span style="color: #009900;">&#41;</span></pre></td></tr></table></div><p>And here is a small demo:<br
/> <iframe
src="http://cache.another-d-mention.ro/stuff/jquery/jquerytest.html" border="0" width="100%" height="100"></iframe></p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/jquery-quickeach/' rel='bookmark' title='Permanent Link: jQuery.quickEach'>jQuery.quickEach</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/parse-xml-in-javascript-with-jquery/' rel='bookmark' title='Permanent Link: Parse XML in JavaScript with jQuery'>Parse XML in JavaScript with jQuery</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/java-script/on-typing-complete-jquery-plugin/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Check if user visited certain websites</title><link>http://blog.another-d-mention.ro/programming/check-if-user-visited-certain-websites/</link> <comments>http://blog.another-d-mention.ro/programming/check-if-user-visited-certain-websites/#comments</comments> <pubDate>Tue, 11 May 2010 13:21:53 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[browser]]></category> <category><![CDATA[history]]></category> <category><![CDATA[javascript]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=819</guid> <description><![CDATA[Today I found a website called http://www.stayinvisible.com/ that uses a really clever technique to peak in your browser history. They can't see everything of course but they can see whatever they are interested in and that is a list of web-proxy websites. So how are they doing it ? First, they have a list of [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/on-typing-complete-jquery-plugin/' rel='bookmark' title='Permanent Link: On typing finished jQuery plugin'>On typing finished jQuery plugin</a></li><li><a
href='http://blog.another-d-mention.ro/misc/firefox-and-user-agent-switcher/' rel='bookmark' title='Permanent Link: Firefox and User Agent Switcher'>Firefox and User Agent Switcher</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol>]]></description> <content:encoded><![CDATA[<p>Today I found a website called http://www.stayinvisible.com/ that uses a really clever technique to peak in your browser history. They can't see everything of course but they can see whatever they are interested in and that is a list of web-proxy websites.</p><p><strong>So how are they doing it ? </strong></p><p>First, they have a list of websites they are interested in, like i said, a list of web-proxies.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> sites <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;hidemyass.com&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;http://www.hidemyass.com&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;http://forum.hidemyass.com&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;freeproxy.ca&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;http://www.freeproxy.ca&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;proxy4free.com&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;http://www.proxy4free.com&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    ....
    ....
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>Second, they create a temporary IFRAME where they write a simple 2 lines CSS that does the magic</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
</pre></td><td
class="code"><pre class="css" style="font-family:monospace;">a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">&#125;</span>
a<span style="color: #00AA00;">:</span> visited <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#F00</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div><p>... and in the body they append all the links from the <string>sites list.</p><p>The browser renders the links, and all the sites that appear in your history will use the "<strong>a:visited</strong>" CSS class. The others use the normal "<strong>a</strong>" class that has a display:none property and will be hidden.</p><p>What's left to do is iterate all the links from the frame and check if they are visible or not to know which of them are in your history and which of them aren't. Pretty simple eh ?</p><p>So here's the class:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> bHistory <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> sites <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;hidemyass.com&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;http://www.hidemyass.com&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;http://forum.hidemyass.com&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;freeproxy.ca&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;http://www.freeproxy.ca&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;proxy.org&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;http://www.proxy.org&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;http://www.proxy.org/cgi_proxies.shtml&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;http://www.proxy.org/forum/index.html&quot;</span><span style="color: #009900;">&#93;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> visited <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">function</span> getStyle<span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span> scopeDoc<span style="color: #339933;">,</span>styleProp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">currentStyle</span><span style="color: #009900;">&#41;</span> <span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> el.<span style="color: #660066;">currentStyle</span><span style="color: #009900;">&#91;</span>styleProp<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">getComputedStyle</span><span style="color: #009900;">&#41;</span> <span style="color: #003366; font-weight: bold;">var</span> y <span style="color: #339933;">=</span> scopeDoc.<span style="color: #660066;">defaultView</span>.<span style="color: #660066;">getComputedStyle</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getPropertyValue</span><span style="color: #009900;">&#40;</span>styleProp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> y<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #003366; font-weight: bold;">function</span> remove<span style="color: #009900;">&#40;</span> el <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    el.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span> el <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #003366; font-weight: bold;">function</span> createIframe<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> iframe <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;iframe&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    iframe.<span style="color: #660066;">style</span>.<span style="color: #660066;">position</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;absolute&quot;</span><span style="color: #339933;">;</span>
    iframe.<span style="color: #660066;">style</span>.<span style="color: #660066;">visibility</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;hidden&quot;</span><span style="color: #339933;">;</span>
    document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>iframe<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>iframe.<span style="color: #660066;">contentDocument</span><span style="color: #009900;">&#41;</span> iframe.<span style="color: #660066;">doc</span> <span style="color: #339933;">=</span> iframe.<span style="color: #660066;">contentDocument</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>iframe.<span style="color: #660066;">contentWindow</span><span style="color: #009900;">&#41;</span> iframe.<span style="color: #660066;">doc</span> <span style="color: #339933;">=</span> iframe.<span style="color: #660066;">contentWindow</span>.<span style="color: #660066;">document</span><span style="color: #339933;">;</span>
    iframe.<span style="color: #660066;">doc</span>.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	iframe.<span style="color: #660066;">doc</span>.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;style&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	iframe.<span style="color: #660066;">doc</span>.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a{color: #000000; display:none;}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	iframe.<span style="color: #660066;">doc</span>.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a:visited {color: #FF0000; display:inline;}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	iframe.<span style="color: #660066;">doc</span>.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;/style&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    iframe.<span style="color: #660066;">doc</span>.<span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> iframe<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #003366; font-weight: bold;">var</span> iframe <span style="color: #339933;">=</span> createIframe<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">function</span> embedLinkInIframe<span style="color: #009900;">&#40;</span> href<span style="color: #339933;">,</span> text <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> iframe.<span style="color: #660066;">doc</span>.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    a.<span style="color: #660066;">href</span> <span style="color: #339933;">=</span> href<span style="color: #339933;">;</span>
    a.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> site<span style="color: #339933;">;</span>
    iframe.<span style="color: #660066;">doc</span>.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span> a <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> site <span style="color: #000066; font-weight: bold;">in</span> sites <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> urls <span style="color: #339933;">=</span> sites<span style="color: #009900;">&#91;</span>site<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>urls .<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      embedLinkInIframe<span style="color: #009900;">&#40;</span> urls<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> site <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> urls<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/www\./</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> sansWWW <span style="color: #339933;">=</span> urls<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/www\./</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        embedLinkInIframe<span style="color: #009900;">&#40;</span> sansWWW<span style="color: #339933;">,</span> site <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> httpLen <span style="color: #339933;">=</span> urls<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;//&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> withWWW <span style="color: #339933;">=</span> urls<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> httpLen <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;www.&quot;</span> <span style="color: #339933;">+</span> urls<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span> httpLen <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        embedLinkInIframe<span style="color: #009900;">&#40;</span> withWWW<span style="color: #339933;">,</span> site <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #003366; font-weight: bold;">var</span> links <span style="color: #339933;">=</span> iframe.<span style="color: #660066;">doc</span>.<span style="color: #660066;">body</span>.<span style="color: #660066;">childNodes</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>links.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> displayValue <span style="color: #339933;">=</span> getStyle<span style="color: #009900;">&#40;</span>links<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> iframe.<span style="color: #660066;">doc</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;display&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> didVisit <span style="color: #339933;">=</span> displayValue <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;none&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> didVisit <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      visited<span style="color: #009900;">&#91;</span> links<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  remove<span style="color: #009900;">&#40;</span> iframe <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> usedSites <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> site <span style="color: #000066; font-weight: bold;">in</span> visited <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    usedSites.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> site <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">return</span> usedSites<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>To use it:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">   <span style="color: #003366; font-weight: bold;">var</span> visited <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> bHistory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>visited<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// an array with visited websites from the defined list</span></pre></td></tr></table></div><p>All credits go to the smart man who did this. Cheers!</urls></pre><p></string></p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/java-script/on-typing-complete-jquery-plugin/' rel='bookmark' title='Permanent Link: On typing finished jQuery plugin'>On typing finished jQuery plugin</a></li><li><a
href='http://blog.another-d-mention.ro/misc/firefox-and-user-agent-switcher/' rel='bookmark' title='Permanent Link: Firefox and User Agent Switcher'>Firefox and User Agent Switcher</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/check-if-user-visited-certain-websites/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Open and Save files to Desktop without going to Server</title><link>http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/</link> <comments>http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/#comments</comments> <pubDate>Wed, 05 May 2010 13:21:01 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Java Script]]></category> <category><![CDATA[externalinterface]]></category> <category><![CDATA[filereference]]></category> <category><![CDATA[flash]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[open]]></category> <category><![CDATA[save]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=817</guid> <description><![CDATA[Few days ago I was working on a jQuery based tool to QA the JavaScript functionality of a website and I was in need of a method to save and load my scripts to Desktop. In most cases this require a server script where you send the content and it will serve it to download [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/' rel='bookmark' title='Permanent Link: Read/Load files from ZIP in JavaScript'>Read/Load files from ZIP in JavaScript</a></li><li><a
href='http://blog.another-d-mention.ro/programming/right-click-and-custom-context-menu-in-flash-flex/' rel='bookmark' title='Permanent Link: Right click and custom context menu in Flash/Flex'>Right click and custom context menu in Flash/Flex</a></li><li><a
href='http://blog.another-d-mention.ro/programming/use-any-font-with-cufon/' rel='bookmark' title='Permanent Link: Use any Font with Cufon'>Use any Font with Cufon</a></li></ol>]]></description> <content:encoded><![CDATA[<p>Few days ago I was working on a jQuery based tool to QA the JavaScript functionality of a website and I was in need of a method to save and load my scripts to Desktop.<br
/> In most cases this require a server script where you send the content and it will serve it to download and same for loading it. But a colleague suggested a better solution: to use the FileReference class.<br
/> First step was to create a simple flash with the required functionality and send/retrieve data with ExternalInterface. Failed miserably. Why ? Because it seems Flash will not allow you to open a File Dialog from script only. You literally have to click a button from the movie interface to be able to do that. If you knew that good for you, I didn't.</p><p>So, I've created another flash movie, where you pass the open and save image and callback and it will insert the flash with the specified images in place and look just like any other buttons.</p><p>Here's a small demonstration (other buttons beside open and save are just for show):<br
/> <iframe
src="http://blog.another-d-mention.ro/stuff/FileDialogs/index.html" with="400" height="170" frameborder="0" style="overflow:hidden"></iframe><br
/> So what do you need to set it up ?</p><p>First, you have to include the <strong>FileDialogs.js</strong> in your document (or just paste the code inside it into your own script).</p><p>Second, you need your JavaScript callbacks.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> openCallback<span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'text'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> input<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> saveCallback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000066; font-weight: bold;">return</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'text'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p><strong>openCallback()</strong> will be called once the user will select a file from the desktop and pass it's content as a parameter<br
/> <strong>saveCallback()</strong> will be called when the user clicks save, before the dialog to choose a file name opens, and it must return the content you want to save to disk</p><p>Third, you must setup the whole thing.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// call this function on the onload event so the placeHolder element gets created</span>
<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #000066;">onLoad</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Create a config object</span>
    <span style="color: #003366; font-weight: bold;">var</span> config <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> FileDialogsConfig<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// width of the entire flash movie (buttons width + padding)</span>
    config.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">45</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// height of the movie</span>
    config.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">16</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// padding between buttons</span>
    config.<span style="color: #660066;">padding</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// open dialog button image and javascript callback function</span>
    config.<span style="color: #000066;">open</span>.<span style="color: #660066;">image</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;open.png&quot;</span><span style="color: #339933;">;</span>
    config.<span style="color: #000066;">open</span>.<span style="color: #660066;">handler</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;openCallback&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// save dialog button image and javascript callback function</span>
    config.<span style="color: #660066;">save</span>.<span style="color: #660066;">image</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;save.png&quot;</span><span style="color: #339933;">;</span>
    config.<span style="color: #660066;">save</span>.<span style="color: #660066;">handler</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;saveCallback&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// create the movie inside an element with the given id and configuration</span>
    <span style="color: #003366; font-weight: bold;">new</span> FileDialogs<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;placeHolder&quot;</span><span style="color: #339933;">,</span> config<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p><strong>Note:</strong> Handler callbacks in the config must be declared as String and not reference. IE will freak out and I don't want to fix it.</p><p>You can have only one button (open or save) if you chose so. Just don't set the other one.</p><p>That's about it. The placeHolder can be any container element. The script will set it's style size based on the configuration, the movie will have transparent background so don't worry about that, and it will set it's float property to left so you can add other stuff after it. But all those things are easy to configure if you mess a bit with the FileDialogs.js file.</p><p>Cheers!</p><p><a
href="http://cache.another-d-mention.ro/stuff/FileDialogs/FileDialogs.zip">Download Source and Demo</a></p><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/read-load-files-from-zip-in-javascript/' rel='bookmark' title='Permanent Link: Read/Load files from ZIP in JavaScript'>Read/Load files from ZIP in JavaScript</a></li><li><a
href='http://blog.another-d-mention.ro/programming/right-click-and-custom-context-menu-in-flash-flex/' rel='bookmark' title='Permanent Link: Right click and custom context menu in Flash/Flex'>Right click and custom context menu in Flash/Flex</a></li><li><a
href='http://blog.another-d-mention.ro/programming/use-any-font-with-cufon/' rel='bookmark' title='Permanent Link: Use any Font with Cufon'>Use any Font with Cufon</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/java-script/open-and-save-files-to-desktop-without-going-to-server/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>Serialize JavaScript object to JSON</title><link>http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/</link> <comments>http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/#comments</comments> <pubDate>Wed, 28 Apr 2010 11:57:51 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[Flex / ActionScript]]></category> <category><![CDATA[Java Script]]></category> <category><![CDATA[deserialize]]></category> <category><![CDATA[flash]]></category> <category><![CDATA[flex]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[json]]></category> <category><![CDATA[object]]></category> <category><![CDATA[serialize]]></category> <guid
isPermaLink="false">http://blog.another-d-mention.ro/?p=816</guid> <description><![CDATA[Recently, on a project I was working, I needed a function to serialize a JavaScript object and all I could find online were scripts and jquery plugins for serializing a html form. Then, I found this, a script that takes advantage of the .toSource() method available in Gecko-based browsers and for the rest of them [...]
Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/' rel='bookmark' title='Permanent Link: How to clone (duplicate) an object in ActionScript 3'>How to clone (duplicate) an object in ActionScript 3</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol>]]></description> <content:encoded><![CDATA[<p>Recently, on a project I was working, I needed a function to serialize a JavaScript object and all I could find online were scripts and jquery plugins for serializing a html form. Then, I found <a
href="http://blog.stchur.com/2007/04/06/serializing-objects-in-javascript/" target="_blank">this</a>, a script that takes advantage of the <i>.toSource()</i> method available in Gecko-based browsers and for the rest of them plain old recursion. But it does the trick as expected and I'm pretty sure someone else might need it.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> serialize<span style="color: #009900;">&#40;</span>_obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_obj <span style="color: #339933;">!=</span> undefined <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">typeof</span> _obj.<span style="color: #660066;">toSource</span> <span style="color: #339933;">!==</span> <span style="color: #3366CC;">'undefined'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">typeof</span> _obj.<span style="color: #660066;">callee</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">return</span> _obj.<span style="color: #660066;">toSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> _obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'number'</span><span style="color: #339933;">:</span>
      <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'boolean'</span><span style="color: #339933;">:</span>
      <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'function'</span><span style="color: #339933;">:</span>
         <span style="color: #000066; font-weight: bold;">return</span> _obj<span style="color: #339933;">;</span>
         <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'string'</span><span style="color: #339933;">:</span>
          <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'&quot;'</span> <span style="color: #339933;">+</span> _obj.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&quot;/mg</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;'</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'object'</span><span style="color: #339933;">:</span>
          <span style="color: #003366; font-weight: bold;">var</span> str<span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_obj.<span style="color: #660066;">constructor</span> <span style="color: #339933;">===</span> Array <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">typeof</span> _obj.<span style="color: #660066;">callee</span> <span style="color: #339933;">!==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
              str <span style="color: #339933;">=</span> <span style="color: #3366CC;">'['</span><span style="color: #339933;">;</span>
              <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">,</span> len <span style="color: #339933;">=</span> _obj.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
              <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> str <span style="color: #339933;">+=</span> Utils.<span style="color: #660066;">serialize</span><span style="color: #009900;">&#40;</span>_obj<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">','</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
              str <span style="color: #339933;">+=</span> Utils.<span style="color: #660066;">serialize</span><span style="color: #009900;">&#40;</span>_obj<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">']'</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
              str <span style="color: #339933;">=</span> <span style="color: #3366CC;">'{'</span><span style="color: #339933;">;</span>
              <span style="color: #003366; font-weight: bold;">var</span> key<span style="color: #339933;">;</span>
              <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>key <span style="color: #000066; font-weight: bold;">in</span> _obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> str <span style="color: #339933;">+=</span> key <span style="color: #339933;">+</span> <span style="color: #3366CC;">':'</span> <span style="color: #339933;">+</span> Utils.<span style="color: #660066;">serialize</span><span style="color: #009900;">&#40;</span>_obj<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">','</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
              str <span style="color: #339933;">=</span> str.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\,$/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'}'</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
          <span style="color: #000066; font-weight: bold;">return</span> str<span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
          <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'&quot;&quot;'</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>To deserialize it, just use <i>eval()</i>.</p><p>Also, if you need the same thing for your Flash/Flex Actionscript3 project, here is a class for that as well -> <a
href="http://blog.another-d-mention.ro/stuff/Serializer.as" target="_blank">Click Me</a>.</p><p>Cheers! </pre><p>Related posts:<ol><li><a
href='http://blog.another-d-mention.ro/programming/how-to-clone-duplicate-an-object-in-actionscript-3/' rel='bookmark' title='Permanent Link: How to clone (duplicate) an object in ActionScript 3'>How to clone (duplicate) an object in ActionScript 3</a></li><li><a
href='http://blog.another-d-mention.ro/programming/java-script/for-javascript-devs/' rel='bookmark' title='Permanent Link: For Javascript devs'>For Javascript devs</a></li><li><a
href='http://blog.another-d-mention.ro/programming/javascript-object-oriented-programming-oop-jclass/' rel='bookmark' title='Permanent Link: JavaScript Object-Oriented Programming (OOP) &#8211; jClass'>JavaScript Object-Oriented Programming (OOP) &#8211; jClass</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://blog.another-d-mention.ro/programming/flex-actionscript/serialize-javascript-object-to-json/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
