Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 50db24a658
Fetching contributors…

Cannot retrieve contributors at this time

100 lines (73 sloc) 13.025 kb
<!DOCTYPE html> <html> <head> <title>file.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="file.html"> file.js </a> <a class="source" href="icon.html"> icon.js </a> <a class="source" href="icons.html"> icons.js </a> <a class="source" href="page.html"> page.js </a> <a class="source" href="stitches.html"> stitches.js </a> <a class="source" href="tmpl.html"> tmpl.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> file.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <h2>Stitches.File</h2>
<p><a href="http://draeton.github.com/stitches">http://draeton.github.com/stitches</a></p>
<p>Copyright 2011, Matthew Cobbs
Licensed under the MIT license.</p> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*global jQuery, Stitches */</span>
<span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nb">window</span><span class="p">,</span> <span class="nx">Stitches</span><span class="p">,</span> <span class="nx">$</span><span class="p">)</span> <span class="p">{</span>
<span class="s2">&quot;use strict&quot;</span><span class="p">;</span>
</pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h2>Stitches.File namespace</h2>
<p>Holds all File procesing methods</p> </td> <td class="code"> <div class="highlight"><pre>
<span class="nx">Stitches</span><span class="p">.</span><span class="nx">File</span> <span class="o">=</span> <span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="cm">/* shortcut */</span>
<span class="kd">var</span> <span class="nx">S</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">Stitches</span><span class="p">;</span>
<span class="cm">/* track files to read */</span>
<span class="kd">var</span> <span class="nx">readQueue</span> <span class="o">=</span> <span class="p">[];</span>
<span class="k">return</span> <span class="p">{</span>
</pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <h3>queueFiles</h3>
<p>Loops through <code>files</code>; adds an image to the <code>readQueue</code></p>
<pre><code>@param {FileList} files From a drop event
</code></pre> </td> <td class="code"> <div class="highlight"><pre>
<span class="nx">queueFiles</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">files</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">$</span><span class="p">.</span><span class="nx">each</span><span class="p">(</span><span class="nx">files</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="sr">/jpeg|png|gif/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">file</span><span class="p">.</span><span class="nx">type</span><span class="p">))</span> <span class="p">{</span>
<span class="nx">readQueue</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">file</span><span class="p">);</span>
<span class="nx">S</span><span class="p">.</span><span class="nx">pub</span><span class="p">(</span><span class="s2">&quot;file.queue.done&quot;</span><span class="p">,</span> <span class="nx">file</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">});</span>
<span class="p">},</span>
</pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <h3>queueIcons</h3>
<p>Read in a file from the <code>readQueue</code>. Starts up a new <code>FileReader</code>
to read in the image as data and create a new <code>Icon</code></p> </td> <td class="code"> <div class="highlight"><pre>
<span class="nx">queueIcons</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">file</span><span class="p">,</span> <span class="nx">reader</span><span class="p">;</span>
<span class="nx">file</span> <span class="o">=</span> <span class="nx">readQueue</span><span class="p">.</span><span class="nx">shift</span><span class="p">();</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">file</span><span class="p">)</span> <span class="p">{</span>
<span class="k">try</span> <span class="p">{</span>
<span class="nx">reader</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">FileReader</span><span class="p">();</span>
<span class="nx">reader</span><span class="p">.</span><span class="nx">onloadend</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
<span class="cm">/* create an icon and add to the icon queue */</span>
<span class="kd">var</span> <span class="nx">icon</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">S</span><span class="p">.</span><span class="nx">Icon</span><span class="p">(</span><span class="nx">file</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span> <span class="nx">e</span><span class="p">.</span><span class="nx">target</span><span class="p">.</span><span class="nx">result</span><span class="p">);</span>
<span class="nx">S</span><span class="p">.</span><span class="nx">iconQueue</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">icon</span><span class="p">);</span>
<span class="cm">/* notify */</span>
<span class="nx">S</span><span class="p">.</span><span class="nx">pub</span><span class="p">(</span><span class="s2">&quot;file.icon.done&quot;</span><span class="p">,</span> <span class="nx">icon</span><span class="p">);</span>
<span class="p">};</span>
<span class="nx">reader</span><span class="p">.</span><span class="nx">readAsDataURL</span><span class="p">(</span><span class="nx">file</span><span class="p">);</span>
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">S</span><span class="p">.</span><span class="nx">pub</span><span class="p">(</span><span class="s2">&quot;page.error&quot;</span><span class="p">,</span> <span class="nx">e</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">},</span>
</pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <h3>unqueueIcon</h3>
<p>Removes an icon from the queue</p>
<pre><code>@param {Icon} icon
</code></pre> </td> <td class="code"> <div class="highlight"><pre>
<span class="nx">unqueueIcon</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">icon</span><span class="p">)</span> <span class="p">{</span>
<span class="cm">/* remove the icon from the queue */</span>
<span class="nx">S</span><span class="p">.</span><span class="nx">iconQueue</span> <span class="o">=</span> <span class="nx">$</span><span class="p">.</span><span class="nx">grep</span><span class="p">(</span><span class="nx">S</span><span class="p">.</span><span class="nx">iconQueue</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">item</span><span class="p">)</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">item</span> <span class="o">!==</span> <span class="nx">icon</span><span class="p">;</span>
<span class="p">});</span>
<span class="nx">S</span><span class="p">.</span><span class="nx">Icon</span><span class="p">.</span><span class="nx">clearNameCache</span><span class="p">(</span><span class="nx">icon</span><span class="p">.</span><span class="nx">name</span><span class="p">);</span>
<span class="cm">/* notify */</span>
<span class="nx">S</span><span class="p">.</span><span class="nx">pub</span><span class="p">(</span><span class="s2">&quot;file.remove.done&quot;</span><span class="p">,</span> <span class="nx">icon</span><span class="p">);</span>
<span class="p">},</span>
</pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h3>unqueueAllIcons</h3>
<p>Clear all icons from the queue</p> </td> <td class="code"> <div class="highlight"><pre>
<span class="nx">unqueueAllIcons</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
<span class="nx">$</span><span class="p">.</span><span class="nx">each</span><span class="p">(</span><span class="nx">S</span><span class="p">.</span><span class="nx">iconQueue</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="nx">icon</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">S</span><span class="p">.</span><span class="nx">File</span><span class="p">.</span><span class="nx">unqueueIcon</span><span class="p">(</span><span class="nx">icon</span><span class="p">);</span>
<span class="p">});</span>
<span class="nx">S</span><span class="p">.</span><span class="nx">Icon</span><span class="p">.</span><span class="nx">clearNameCache</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">};</span>
<span class="p">})();</span>
<span class="p">})(</span><span class="nb">window</span><span class="p">,</span> <span class="nx">Stitches</span><span class="p">,</span> <span class="nx">jQuery</span><span class="p">);</span>
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
Jump to Line
Something went wrong with that request. Please try again.