<?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>Brian Grinstead &#187; javascript</title>
	<atom:link href="http://www.briangrinstead.com/blog/tag/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.briangrinstead.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 11 Jan 2012 20:23:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>jQuery UI CDN Boilerplate</title>
		<link>http://www.briangrinstead.com/blog/jquery-ui-cdn-boilerplate</link>
		<comments>http://www.briangrinstead.com/blog/jquery-ui-cdn-boilerplate#comments</comments>
		<pubDate>Tue, 13 Dec 2011 22:13:21 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery-ui]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=682</guid>
		<description><![CDATA[I always forget these links, and they are surprisingly hard to find. Here is a quick markup skeleton to throw together for prototypes using jQuery UI. &#60;!doctype html&#62; &#60;head&#62; &#60;title&#62;&#60;/title&#62; &#160; &#60;script type=&#34;text/javascript&#34; src=&#34;http://code.jquery.com/jquery-1.7.1.js&#34;&#62;&#60;/script&#62; &#60;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js&#34;&#62;&#60;/script&#62; &#60;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/ui-lightness/jquery-ui.css&#34; /&#62; &#160; &#60;style type=&#34;text/css&#34;&#62; #draggable { background: orange; width: 100px; height: 100px; } &#60;/style&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>I always forget these links, and they are surprisingly hard to find.  Here is a quick markup skeleton to throw together for prototypes using jQuery UI.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!doctype html&gt;
&lt;head&gt;
  &lt;title&gt;&lt;/title&gt;
&nbsp;
  &lt;script type=&quot;text/javascript&quot; src=&quot;http://code.jquery.com/jquery-1.7.1.js&quot;&gt;&lt;/script&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js&quot;&gt;&lt;/script&gt;
  &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/ui-lightness/jquery-ui.css&quot; /&gt;
&nbsp;
  &lt;style type=&quot;text/css&quot;&gt;
    #draggable {
		background: orange;
		width: 100px;
		height: 100px;
	}
  &lt;/style&gt;
&nbsp;
  &lt;script type='text/javascript'&gt;
	$(function() {
		$(&quot;#draggable&quot;).draggable().resizable();
	});
  &lt;/script&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&lt;div id='draggable'&gt;drag!&lt;/div&gt;
&lt;/body&gt;
&nbsp;
&lt;/html&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/jquery-ui-cdn-boilerplate/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Chrome Developer Tools &#8211; monitorEvents</title>
		<link>http://www.briangrinstead.com/blog/chrome-developer-tools-monitorevents</link>
		<comments>http://www.briangrinstead.com/blog/chrome-developer-tools-monitorevents#comments</comments>
		<pubDate>Tue, 04 Oct 2011 22:34:47 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[developer tools]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=654</guid>
		<description><![CDATA[I have been playing with the Chrome Developer Tools lately. Here is a cool feature I didn&#8217;t know about. There are many times I have ran some code like this: $&#40;&#34;body&#34;&#41;.bind&#40;&#34;click mousedown&#34;, function&#40;e&#41; &#123; console.log&#40;e&#41;; &#125;&#41;; Inspect an element (see screenshot). Now that it has been inspected, there is a $0 variable available in the [...]]]></description>
			<content:encoded><![CDATA[<p>I have been playing with the Chrome Developer Tools lately.  Here is a cool feature I didn&#8217;t know about.  </p>
<p>There are many times I have ran some code like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">&quot;body&quot;</span><span style="color: #009900;color: #000000;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">&quot;click mousedown&quot;</span><span style="color: #339933;color: #000000;">,</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>e<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;color: #000000;">&#40;</span>e<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
<span style="color: #009900;color: #000000;">&#125;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span></pre></div></div>

<p>Inspect an element (see screenshot).  Now that it has been inspected, there is a $0 variable available in the console.</p>
<p><a href="http://briangrinstead.com/files/devtools-highlight-body.png"><img src="http://briangrinstead.com/files/devtools-highlight-body-1024x547.png" alt="" title="devtools-highlight-body" width="500" class="aligncenter size-large wp-image-661" /></a></p>
<p>Instead of that extra bind, you can just type this into the console:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">monitorEvents<span style="color: #009900;color: #000000;">&#40;</span>$0<span style="color: #339933;color: #000000;">,</span> <span style="color: #3366CC;color: #808080;">'mouse'</span><span style="color: #009900;color: #000000;">&#41;</span></pre></div></div>

<p><a href="http://briangrinstead.com/files/devtools-monitor-events.png"><img src="http://briangrinstead.com/files/devtools-monitor-events-1024x547.png" alt="" title="devtools-monitor-events" width="500" class="aligncenter size-large wp-image-663" /></a></p>
<p>You can also use &#8216;key&#8217; instead of &#8216;mouse&#8217; if you are tracking key events.  There are actually a number of second parameters, via the <a href='http://getfirebug.com/wiki/index.php/Command_Line_API'>Firebug command line API</a>.  Note: not all of these seem to be supported by Chrome dev tools.  Here they are:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">composition contextmenu drag focus form key load mouse mutation paint scroll text ui xul</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/chrome-developer-tools-monitorevents/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chrome Developer Tools Colorpicker Concept</title>
		<link>http://www.briangrinstead.com/blog/chrome-developer-tools-colorpicker-concept</link>
		<comments>http://www.briangrinstead.com/blog/chrome-developer-tools-colorpicker-concept#comments</comments>
		<pubDate>Mon, 03 Oct 2011 19:35:11 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[developer tools]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=630</guid>
		<description><![CDATA[I always thought it would be awesome to have a colorpicker in browser developer tools. Who wants to guess at hex colors or open up a separate program just to get a color code? Apparently I&#8217;m not the only one who thinks a colorpicker inside the developer toolbar would be nice. So, I did some [...]]]></description>
			<content:encoded><![CDATA[<p>I always thought it would be awesome to have a colorpicker in browser developer tools.  Who wants to guess at hex colors or open up a separate program just to get a color code?  Apparently I&#8217;m not the only one who <a href='http://lensco.be/2010/04/15/webkit-inspector-wish-list/'>thinks a colorpicker inside the developer toolbar would be nice</a>.</p>
<p>So, I did some reading on how to <a href='http://www.chromium.org/devtools'>contribute to developer tools</a> and integrated my <a href='http://briangrinstead.com/blog/spectrum'>spectrum colorpicker</a> into the color swatch button.</p>
<p>Check out the demo in this video:</p>
<p><object id="scPlayer"  width="840" height="505" type="application/x-shockwave-flash" data="http://content.screencast.com/users/bgrins/folders/Jing/media/4d610e8b-a472-4c87-a5ea-f3359e4c5ea9/jingswfplayer.swf" ><param name="movie" value="http://content.screencast.com/users/bgrins/folders/Jing/media/4d610e8b-a472-4c87-a5ea-f3359e4c5ea9/jingswfplayer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#FFFFFF" /><param name="flashVars" value="thumb=http://content.screencast.com/users/bgrins/folders/Jing/media/4d610e8b-a472-4c87-a5ea-f3359e4c5ea9/FirstFrame.jpg&#038;containerwidth=1680&#038;containerheight=1010&#038;content=http://content.screencast.com/users/bgrins/folders/Jing/media/4d610e8b-a472-4c87-a5ea-f3359e4c5ea9/2011-10-03_1420.swf&#038;blurover=false" /><param name="allowFullScreen" value="true" /><param name="scale" value="showall" /><param name="allowScriptAccess" value="always" /><param name="base" value="http://content.screencast.com/users/bgrins/folders/Jing/media/4d610e8b-a472-4c87-a5ea-f3359e4c5ea9/" />Unable to display content. Adobe Flash is required.</object></p>
<p>Of course, I don&#8217;t want to get rid of the swatch button (it usually rotates through color formats if you click it which can be useful), so the UI could use some work.  Still, this functionality makes picking colors a lot easier, I think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/chrome-developer-tools-colorpicker-concept/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Keep Aspect Ratio With HTML and CSS</title>
		<link>http://www.briangrinstead.com/blog/keep-aspect-ratio-with-html-and-css</link>
		<comments>http://www.briangrinstead.com/blog/keep-aspect-ratio-with-html-and-css#comments</comments>
		<pubDate>Wed, 28 Sep 2011 17:51:31 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[colorpicker]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=601</guid>
		<description><![CDATA[When working on my javascript colorpicker, one of the things I thought would be really cool is if you could resize it and have the colorpicker automatically respond to different widths. When I first made it, I had basically defined static widths with the thought that there could be different themes (small, normal, large) which [...]]]></description>
			<content:encoded><![CDATA[<p>When working on my <a href='http://bgrins.github.com/spectrum/'>javascript colorpicker</a>, one of the things I thought would be really cool is if you could resize it and have the colorpicker automatically respond to different widths.  When I first made it, I had basically <a href='https://github.com/bgrins/spectrum/commit/aa54da8f1b76a75ef165f6433441fd006a7c22c5#L0R223'>defined static widths</a> with the thought that there could be different themes (small, normal, large) which defined different widths.  </p>
<p>This turned out to be a pain, since you had to manually figure out what each width needed to be for the total size.  To complicate things further, I wanted to have a different percentage width when accessing the colorpicker via an iPhone.  I found that the hue slider was a little too small to accurately slide with the touch interface, so I wanted it to take up more of a percentage of the total width.  I&#8217;m can be lazy about calculating widths in CSS, so I went off looking for a different way to do this.</p>
<h2>Aspect Ratios</h2>
<p>Why couldn&#8217;t I just use percentage widths?  Because the left portion of the colorpicker needs to be a square &#8211; or else the gradients for saturation and value just look weird and don&#8217;t really map up 1:1.  I did some searching and found a <a href='http://ansciath.tumblr.com/post/7347495869/css-aspect-ratio'>CSS workaround to keep the aspect ratio</a> of a fluid element by ansciath.  The meat of this trick is that <a href='http://www.w3.org/TR/CSS2/box.html#propdef-margin-top'>according to the spec for margin-top</a>, a percentage refers to the <em>width</em> of the containing block, not the height.  This post got me much of the way there, but I had to include a couple of fixes for IE and ways.</p>
<p><em>The really nice part about using this technique is that it makes spectrum extremely easy to skin in your own CSS.</em>  Check out <a href='http://briangrinstead.com/colorstash'>ColorStash</a> for an example of this.  Using media queries and max-widths, I can change the width of the colorpicker as the browser resizes to get some really responsive behavior on a UI control (colorpicker) that has typically been very static.</p>
<h2>Demo</h2>
<p>See the <a href='http://jsfiddle.net/bgrins/zpWNF/embedded/result/'>demo of the aspect ratio  and media query</a>.  Try resizing your browser window to under 480px width to see the switch happen.  Here is the full <a href='http://jsfiddle.net/bgrins/zpWNF/'>source code</a> for the demo.</p>
<p>Below is a snippet showing the basic HTML/CSS needed for this technique:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class='container'&gt;
    &lt;div class='outer'&gt;
        &lt;div class='fill'&gt;&lt;/div&gt;
        &lt;div class='inner-top'&gt;
            &lt;div class='square'&gt;Always a square&lt;/div&gt;
            &lt;div class='right'&gt;% width&lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class='bottom'&gt;
        Bottom
    &lt;/div&gt;
&lt;/div&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.outer</span> <span style="color: #00AA00;color: #000000;">&#123;</span>
  <span style="color: #000000; font-weight: bold;color: #0000FF;">position</span><span style="color: #00AA00;color: #000000;">:</span><span style="color: #993333;color: #0000FF;">relative</span><span style="color: #00AA00;color: #000000;">;</span> 
  <span style="color: #000000; font-weight: bold;color: #0000FF;">width</span><span style="color: #00AA00;color: #000000;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;color: #000000;">;</span>
  <span style="color: #000000; font-weight: bold;color: #0000FF;">display</span><span style="color: #00AA00;color: #000000;">:</span>inline-<span style="color: #993333;color: #0000FF;">block</span><span style="color: #00AA00;color: #000000;">;</span>
<span style="color: #00AA00;color: #000000;">&#125;</span>
.inner-<span style="color: #000000; font-weight: bold;color: #0000FF;">top</span> <span style="color: #00AA00;color: #000000;">&#123;</span>
   <span style="color: #000000; font-weight: bold;color: #0000FF;">position</span><span style="color: #00AA00;color: #000000;">:</span><span style="color: #993333;color: #0000FF;">absolute</span><span style="color: #00AA00;color: #000000;">;</span> <span style="color: #000000; font-weight: bold;color: #0000FF;">top</span><span style="color: #00AA00;color: #000000;">:</span><span style="color: #cc66cc;color: #808080;">0</span><span style="color: #00AA00;color: #000000;">;</span> <span style="color: #000000; font-weight: bold;color: #0000FF;">left</span><span style="color: #00AA00;color: #000000;">:</span><span style="color: #cc66cc;color: #808080;">0</span><span style="color: #00AA00;color: #000000;">;</span> <span style="color: #000000; font-weight: bold;color: #0000FF;">bottom</span><span style="color: #00AA00;color: #000000;">:</span><span style="color: #cc66cc;color: #808080;">0</span><span style="color: #00AA00;color: #000000;">;</span> <span style="color: #000000; font-weight: bold;color: #0000FF;">right</span><span style="color: #00AA00;color: #000000;">:</span><span style="color: #cc66cc;color: #808080;">0</span><span style="color: #00AA00;color: #000000;">;</span>
<span style="color: #00AA00;color: #000000;">&#125;</span>
.<span style="color: #993333;color: #0000FF;">square</span> <span style="color: #00AA00;color: #000000;">&#123;</span>    
    <span style="color: #000000; font-weight: bold;color: #0000FF;">position</span><span style="color: #00AA00;color: #000000;">:</span> <span style="color: #993333;color: #0000FF;">absolute</span><span style="color: #00AA00;color: #000000;">;</span>
    <span style="color: #000000; font-weight: bold;color: #0000FF;">top</span><span style="color: #00AA00;color: #000000;">:</span><span style="color: #cc66cc;color: #808080;">0</span><span style="color: #00AA00;color: #000000;">;</span>left<span style="color: #00AA00;color: #000000;">:</span><span style="color: #cc66cc;color: #808080;">0</span><span style="color: #00AA00;color: #000000;">;</span>bottom<span style="color: #00AA00;color: #000000;">:</span><span style="color: #cc66cc;color: #808080;">0</span><span style="color: #00AA00;color: #000000;">;</span>right<span style="color: #00AA00;color: #000000;">:</span><span style="color: #933;">20%</span><span style="color: #00AA00;color: #000000;">;</span>
    <span style="color: #000000; font-weight: bold;color: #0000FF;">background</span><span style="color: #00AA00;color: #000000;">:</span>orange<span style="color: #00AA00;color: #000000;">;</span> 
<span style="color: #00AA00;color: #000000;">&#125;</span>
.<span style="color: #000000; font-weight: bold;color: #0000FF;">right</span> <span style="color: #00AA00;color: #000000;">&#123;</span>
    <span style="color: #000000; font-weight: bold;color: #0000FF;">position</span><span style="color: #00AA00;color: #000000;">:</span> <span style="color: #993333;color: #0000FF;">absolute</span><span style="color: #00AA00;color: #000000;">;</span>
    <span style="color: #000000; font-weight: bold;color: #0000FF;">top</span><span style="color: #00AA00;color: #000000;">:</span><span style="color: #cc66cc;color: #808080;">0</span><span style="color: #00AA00;color: #000000;">;</span>right<span style="color: #00AA00;color: #000000;">:</span><span style="color: #cc66cc;color: #808080;">0</span><span style="color: #00AA00;color: #000000;">;</span>bottom<span style="color: #00AA00;color: #000000;">:</span><span style="color: #cc66cc;color: #808080;">0</span><span style="color: #00AA00;color: #000000;">;</span>left<span style="color: #00AA00;color: #000000;">:</span><span style="color: #933;">83%</span><span style="color: #00AA00;color: #000000;">;</span>
    <span style="color: #000000; font-weight: bold;color: #0000FF;">background</span><span style="color: #00AA00;color: #000000;">:</span> <span style="color: #993333;color: #0000FF;">purple</span><span style="color: #00AA00;color: #000000;">;</span>
<span style="color: #00AA00;color: #000000;">&#125;</span>
<span style="color: #6666ff;">.fill</span> <span style="color: #00AA00;color: #000000;">&#123;</span> 
    <span style="color: #00AA00;color: #000000;">*</span><span style="color: #000000; font-weight: bold;color: #0000FF;">height</span><span style="color: #00AA00;color: #000000;">:</span> <span style="color: #933;">80%</span><span style="color: #00AA00;color: #000000;">;</span>
    <span style="color: #000000; font-weight: bold;color: #0000FF;">margin-top</span><span style="color: #00AA00;color: #000000;">:</span> <span style="color: #933;">80%</span><span style="color: #00AA00;color: #000000;">;</span>  <span style="color: #808080; font-style: italic;color: #008000;">/* Same as square width */</span>
<span style="color: #00AA00;color: #000000;">&#125;</span>
<span style="color: #a1a100;color: #008000;">@media (max-width: 480px) {</span>
    .<span style="color: #993333;color: #0000FF;">square</span> <span style="color: #00AA00;color: #000000;">&#123;</span> <span style="color: #000000; font-weight: bold;color: #0000FF;">right</span><span style="color: #00AA00;color: #000000;">:</span> <span style="color: #933;">51%</span><span style="color: #00AA00;color: #000000;">;</span> <span style="color: #000000; font-weight: bold;color: #0000FF;">background</span><span style="color: #00AA00;color: #000000;">:</span> <span style="color: #000000; font-weight: bold;color: #0000FF;">blue</span><span style="color: #00AA00;color: #000000;">;</span> <span style="color: #00AA00;color: #000000;">&#125;</span>
    .<span style="color: #000000; font-weight: bold;color: #0000FF;">right</span> <span style="color: #00AA00;color: #000000;">&#123;</span> <span style="color: #000000; font-weight: bold;color: #0000FF;">left</span><span style="color: #00AA00;color: #000000;">:</span> <span style="color: #933;">51%</span><span style="color: #00AA00;color: #000000;">;</span> <span style="color: #00AA00;color: #000000;">&#125;</span>
    <span style="color: #6666ff;">.fill</span> <span style="color: #00AA00;color: #000000;">&#123;</span> <span style="color: #000000; font-weight: bold;color: #0000FF;">margin-top</span><span style="color: #00AA00;color: #000000;">:</span> <span style="color: #933;">49%</span><span style="color: #00AA00;color: #000000;">;</span> <span style="color: #00AA00;color: #000000;">&#125;</span> 
<span style="color: #00AA00;color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/keep-aspect-ratio-with-html-and-css/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What I want in a JavaScript colorpicker</title>
		<link>http://www.briangrinstead.com/blog/javascript-colorpicker</link>
		<comments>http://www.briangrinstead.com/blog/javascript-colorpicker#comments</comments>
		<pubDate>Mon, 05 Sep 2011 02:21:31 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=558</guid>
		<description><![CDATA[I have been wanting to add colorpickers in a couple of projects recently, and was not happy with the options. Just search JavaScript Colorpicker and you&#8217;ll see what I mean. It got me thinking about what I wanted out of a colorpicker. No Images! It is pretty well known that you should limit the number [...]]]></description>
			<content:encoded><![CDATA[<p>I have been wanting to add colorpickers in a couple of projects recently, and was not happy with the options.  Just search <a href='http://www.google.com/search?q=javascript+colorpicker'>JavaScript Colorpicker</a> and you&#8217;ll see what I mean.  It got me thinking about what I wanted out of a colorpicker.</p>
<h2>No Images!</h2>
<p>It is pretty well known that you should limit the number of images that your web page requests for performance reasons.  Some of these, including the <a href='http://www.eyecon.ro/colorpicker/'>eyecon.ro</a> picker, which is the first that shows up when searching &#8216;jQuery colorpicker&#8217;, require a ton of images (27, in fact).  This is overkill.  Why can&#8217;t it be skinned with HTML/CSS? </p>
<h2>Reasonable defaults</h2>
<p>I found myself having to dig through the source code of various colorpickers in order to get them to act how I wanted.  Maybe my experience on this is unique, but once I wanted to actually script behavior to go along with the picker (think &#8211; a template editor for an online portfolio), it became painful quickly.</p>
<h2>Browser Support</h2>
<p>It needs to support all major browsers (even IE).  Ideally it could also support mobile devices.</p>
<h2>Drop in</h2>
<p>Didn&#8217;t want to have to download zip folders, place a bunch of images in my project and modify css files to point to the correct image path, etc.  I just want to include a single JavaScript file, and a single CSS file, and be done.</p>
<h2>Anything Like This?</h2>
<p>I did find the nifty <a href='https://github.com/DavidDurman/FlexiColorPicker'>FlexiColorPicker</a>, which accomplishes the no images goal with SVG and VML.  It seems very nice, but didn&#8217;t have some of the features I wanted (dragging around the hue slider and picker didn&#8217;t actually work).  I&#8217;m glad I found it, as I did use some of the gradients as a starting point with my CSS gradients.</p>
<h2>Spectrum &#8211; My JavaScript Colorpicker</h2>
<p>I have done a fair amount of color manipulation work while building a color scheme generator in a theme editor.  I also have made a JavaScript color micro framework for parsing and conversion, called <a href='https://github.com/bgrins/TinyColor'>TinyColor</a>.  This is designed to allow a wide range of input and output (named colors, hex, rgb, hsl, hsv).  </p>
<p>So, I decided to try my hand at this, and made the <a href="http://bgrins.github.com/spectrum/">spectrum JavaScript colorpicker</a>.</p>
<p>It works in all major browsers (tested in Safari, Chrome, Firefox, IE 7+, iOS, Opera).  It uses IE&#8217;s propriety gradient filter (with some hacks for the hue slider &#8211; see .spectrum-ie-1 through 8 in <a href='https://github.com/bgrins/spectrum/blob/master/spectrum.css'>spectrum.css</a>.  It should even work in iPhone and iPad &#8211; let me know if you have one and can double check that for me over on the demo page :).  It is still in early stages, but I would love if I could get some feedback on the UI and desired functionality.</p>
<h2>Demo</h2>
<p>Head over to the current <a href='http://bgrins.github.com/spectrum/'>project page</a> to try out the demo and see the docs.</p>
<p>It currently requires jQuery, but I have been trying to write the code to make it possible to remove that dependancy.</p>
<p><a href="http://bgrins.github.com/spectrum/"><img src="http://briangrinstead.com/files/Picture-4.png" alt="" title="Spectrum JavaScript Colorpicker" width="754" height="319" class="aligncenter size-full wp-image-565" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/javascript-colorpicker/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>bindWithDelay jQuery Plugin &#8211; Now With Throttling</title>
		<link>http://www.briangrinstead.com/blog/bindwithdelay-throttling</link>
		<comments>http://www.briangrinstead.com/blog/bindwithdelay-throttling#comments</comments>
		<pubDate>Sat, 14 May 2011 00:27:46 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bindwithdelay]]></category>
		<category><![CDATA[event binding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=522</guid>
		<description><![CDATA[I decided to add in throttling functionality to the jquery bindWithDelay plugin. This is a nice feature that didn&#8217;t require very many changes to the code (see the: diff). What is throttling? Imagine you are scrolling down a long page for 3 seconds and you have bindWithDelay running with a timeout of 1000ms. By default, [...]]]></description>
			<content:encoded><![CDATA[<p>I decided to add in throttling functionality to the <a href='http://briangrinstead.com/files/bindWithDelay/'>jquery bindWithDelay</a> plugin.  This is a nice feature that didn&#8217;t require very many changes to the code (see the: <a href='https://github.com/bgrins/bindWithDelay/commit/e23c2502458c516e24dd0b16edcde8b2f1636f3f#diff-0'>diff</a>).</p>
<h3>What is throttling?</h3>
<p>Imagine you are scrolling down a long page for 3 seconds and you have bindWithDelay running with a timeout of 1000ms. By default, your event will only fire a second after you have completely finished scrolling. If you have the optional throttling on, it will fire once per second during the scrolling &#8211; a total of 3 times instead of 1.</p>
<p>Checkout the <a href='http://briangrinstead.com/files/bindWithDelay#example'>throttling demo</a> to see what it is doing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/bindwithdelay-throttling/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordsolver.js</title>
		<link>http://www.briangrinstead.com/blog/wordsolver</link>
		<comments>http://www.briangrinstead.com/blog/wordsolver#comments</comments>
		<pubDate>Thu, 10 Feb 2011 23:56:31 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[All]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[unscramble]]></category>
		<category><![CDATA[words]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=510</guid>
		<description><![CDATA[I was playing around with unscrambling words recently, and decided to implement a solver in JavaScript. I called it wordsolver.js. Demo There is a wordsolver demo on my site. Try typing in URESMTA or something to see all the words that get unscrambled. Code All code can be found in the wordsolver repository on github. [...]]]></description>
			<content:encoded><![CDATA[<p>I was playing around with unscrambling words recently, and decided to implement a solver in JavaScript.  I called it wordsolver.js.</p>
<h3>Demo</h3>
<p>There is a <a href='http://briangrinstead.com/files/wordsolver/'>wordsolver demo</a> on my site.  Try typing in URESMTA or something to see all the words that get unscrambled.</p>
<h3>Code</h3>
<p>All code can be found in the <a href='https://github.com/bgrins/wordsolver.js'>wordsolver repository on github</a>.  In particular, <a href='https://github.com/bgrins/wordsolver.js/blob/master/wordsolver.js'>here is the file</a> that does all the heavy lifting.  It is all available under the MIT license.</p>
<h3>How does it perform?</h3>
<p>Smoother than I expected it to.  The load time for the dictionaries can be pretty slow (they are anywhere from 1.7MB to 2.6MB depending on the dictionary), but once it loads, it finds words pretty fast and tries to cache results.  <strong>Warning: it will probably crash an iPhone while trying to load the dictionary array into memory</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/wordsolver/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Safer JSONP</title>
		<link>http://www.briangrinstead.com/blog/safer-jsonp</link>
		<comments>http://www.briangrinstead.com/blog/safer-jsonp#comments</comments>
		<pubDate>Mon, 29 Nov 2010 16:47:11 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[jsonp]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=460</guid>
		<description><![CDATA[I read a nice write up on on JSON and JSONP by Angus Croll. He provided a sample implementation of a safe JSONP library. The library is concise and does the trick for a single connection, but I found it didn&#8217;t handle multiple connections. It would overwrite a single global callback, so if you had [...]]]></description>
			<content:encoded><![CDATA[<p>I read a nice write up on <a href='http://javascriptweblog.wordpress.com/2010/11/29/json-and-jsonp/'>on JSON and JSONP</a> by Angus Croll.  He provided a sample implementation of a safe JSONP library.</p>
<p>The library is concise and does the trick for a single connection, but I found it didn&#8217;t handle  multiple connections.  It would overwrite a single global callback, so if you had connections of varying speeds, you would undoubtedly get errors.  For instance, &#8220;Request 1&#8243; is very slow, and &#8220;Request 2&#8243; gets finished before it.  When &#8220;Request 1&#8243; gets finished, it uses the callback for &#8220;Request 2&#8243;.  This actually happened the first time I loaded it up and ran it.  Not good.</p>
<p>Here is a simple updated version that takes care of that particular problem.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;color: #008000;">/*
An implementation of: http://javascriptweblog.wordpress.com/2010/11/29/json-and-jsonp/
that handles multiple connections at once (don't want to replace the global callback if second
request is sent after the first, but returns before.
*/</span>
&nbsp;
<span style="color: #009900;color: #000000;">&#40;</span><span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>global<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> evalJSONP <span style="color: #339933;color: #000000;">=</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>callback<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
	<span style="color: #000066; font-weight: bold;color: #0000FF;">return</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>data<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
		<span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> validJSON <span style="color: #339933;color: #000000;">=</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">false</span><span style="color: #339933;color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;color: #0000FF;">if</span> <span style="color: #009900;color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;color: #0000FF;">typeof</span> data <span style="color: #339933;color: #000000;">==</span> <span style="color: #3366CC;color: #808080;">&quot;string&quot;</span><span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
			<span style="color: #000066; font-weight: bold;color: #0000FF;">try</span> <span style="color: #009900;color: #000000;">&#123;</span>validJSON <span style="color: #339933;color: #000000;">=</span> JSON.<span style="color: #660066;">parse</span><span style="color: #009900;color: #000000;">&#40;</span>data<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span><span style="color: #009900;color: #000000;">&#125;</span> <span style="color: #000066; font-weight: bold;color: #0000FF;">catch</span> <span style="color: #009900;color: #000000;">&#40;</span>e<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
				<span style="color: #006600; font-style: italic;color: #008000;">/*invalid JSON*/</span><span style="color: #009900;color: #000000;">&#125;</span>
		<span style="color: #009900;color: #000000;">&#125;</span> <span style="color: #000066; font-weight: bold;color: #0000FF;">else</span> <span style="color: #009900;color: #000000;">&#123;</span>
			validJSON <span style="color: #339933;color: #000000;">=</span> JSON.<span style="color: #660066;">parse</span><span style="color: #009900;color: #000000;">&#40;</span>JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;color: #000000;">&#40;</span>data<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
			window.<span style="color: #660066;">console</span> <span style="color: #339933;color: #000000;">&amp;&amp;</span> console.<span style="color: #660066;">warn</span><span style="color: #009900;color: #000000;">&#40;</span>
				<span style="color: #3366CC;color: #808080;">'response data was not a JSON string'</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
		<span style="color: #009900;color: #000000;">&#125;</span>
		<span style="color: #000066; font-weight: bold;color: #0000FF;">if</span> <span style="color: #009900;color: #000000;">&#40;</span>validJSON<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
			callback<span style="color: #009900;color: #000000;">&#40;</span>validJSON<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
		<span style="color: #009900;color: #000000;">&#125;</span> <span style="color: #000066; font-weight: bold;color: #0000FF;">else</span> <span style="color: #009900;color: #000000;">&#123;</span>
			<span style="color: #000066; font-weight: bold;color: #0000FF;">throw</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">&quot;JSONP call returned invalid or empty JSON&quot;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
		<span style="color: #009900;color: #000000;">&#125;</span>
	<span style="color: #009900;color: #000000;">&#125;</span>
<span style="color: #009900;color: #000000;">&#125;</span><span style="color: #339933;color: #000000;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> callbackCounter <span style="color: #339933;color: #000000;">=</span> <span style="color: #CC0000;color: #808080;">0</span><span style="color: #339933;color: #000000;">;</span>
global.<span style="color: #660066;">saferJSONP</span> <span style="color: #339933;color: #000000;">=</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>url<span style="color: #339933;color: #000000;">,</span> callback<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
	<span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> fn <span style="color: #339933;color: #000000;">=</span> <span style="color: #3366CC;color: #808080;">'JSONPCallback_'</span> <span style="color: #339933;color: #000000;">+</span> callbackCounter<span style="color: #339933;color: #000000;">++;</span>
	global<span style="color: #009900;color: #000000;">&#91;</span>fn<span style="color: #009900;color: #000000;">&#93;</span> <span style="color: #339933;color: #000000;">=</span> evalJSONP<span style="color: #009900;color: #000000;">&#40;</span>callback<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
	url <span style="color: #339933;color: #000000;">=</span> url.<span style="color: #660066;">replace</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">'=JSONPCallback'</span><span style="color: #339933;color: #000000;">,</span> <span style="color: #3366CC;color: #808080;">'='</span> <span style="color: #339933;color: #000000;">+</span> fn<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> scriptTag <span style="color: #339933;color: #000000;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">'SCRIPT'</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
	scriptTag.<span style="color: #660066;">src</span> <span style="color: #339933;color: #000000;">=</span> url<span style="color: #339933;color: #000000;">;</span>
	document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">'HEAD'</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #009900;color: #000000;">&#91;</span><span style="color: #CC0000;color: #808080;">0</span><span style="color: #009900;color: #000000;">&#93;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;color: #000000;">&#40;</span>scriptTag<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
<span style="color: #009900;color: #000000;">&#125;</span><span style="color: #339933;color: #000000;">;</span>
&nbsp;
<span style="color: #009900;color: #000000;">&#125;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;color: #0000FF;">this</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span></pre></div></div>

<p>To test it out:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> obamaTweets <span style="color: #339933;color: #000000;">=</span> <span style="color: #3366CC;color: #808080;">&quot;http://www.twitter.com/status/user_timeline/BARACKOBAMA.json?count=5&amp;callback=JSONPCallback&quot;</span><span style="color: #339933;color: #000000;">;</span>
saferJSONP<span style="color: #009900;color: #000000;">&#40;</span>obamaTweets<span style="color: #339933;color: #000000;">,</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>data<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>console.<span style="color: #660066;">log</span><span style="color: #009900;color: #000000;">&#40;</span>data<span style="color: #009900;color: #000000;">&#91;</span><span style="color: #CC0000;color: #808080;">0</span><span style="color: #009900;color: #000000;">&#93;</span>.<span style="color: #660066;">text</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #009900;color: #000000;">&#125;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> reddits <span style="color: #339933;color: #000000;">=</span> <span style="color: #3366CC;color: #808080;">&quot;http://www.reddit.com/.json?limit=1&amp;jsonp=JSONPCallback&quot;</span><span style="color: #339933;color: #000000;">;</span>
saferJSONP<span style="color: #009900;color: #000000;">&#40;</span>reddits <span style="color: #339933;color: #000000;">,</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>data<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>console.<span style="color: #660066;">log</span><span style="color: #009900;color: #000000;">&#40;</span>data.<span style="color: #660066;">data</span>.<span style="color: #660066;">children</span><span style="color: #009900;color: #000000;">&#91;</span><span style="color: #CC0000;color: #808080;">0</span><span style="color: #009900;color: #000000;">&#93;</span>.<span style="color: #660066;">data</span>.<span style="color: #660066;">title</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #009900;color: #000000;">&#125;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span></pre></div></div>

<p>If you are really worried about multiple global objects <code>JSONPCallback_1</code>, <code>JSONPCallback_2</code>, etc &#8211; you could store them all in an array instead.  Like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>global<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> evalJSONP <span style="color: #339933;color: #000000;">=</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>callback<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
	<span style="color: #000066; font-weight: bold;color: #0000FF;">return</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>data<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
		<span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> validJSON <span style="color: #339933;color: #000000;">=</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">false</span><span style="color: #339933;color: #000000;">;</span>
		<span style="color: #000066; font-weight: bold;color: #0000FF;">if</span> <span style="color: #009900;color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;color: #0000FF;">typeof</span> data <span style="color: #339933;color: #000000;">==</span> <span style="color: #3366CC;color: #808080;">&quot;string&quot;</span><span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
			<span style="color: #000066; font-weight: bold;color: #0000FF;">try</span> <span style="color: #009900;color: #000000;">&#123;</span>validJSON <span style="color: #339933;color: #000000;">=</span> JSON.<span style="color: #660066;">parse</span><span style="color: #009900;color: #000000;">&#40;</span>data<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span><span style="color: #009900;color: #000000;">&#125;</span> <span style="color: #000066; font-weight: bold;color: #0000FF;">catch</span> <span style="color: #009900;color: #000000;">&#40;</span>e<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
				<span style="color: #006600; font-style: italic;color: #008000;">/*invalid JSON*/</span><span style="color: #009900;color: #000000;">&#125;</span>
		<span style="color: #009900;color: #000000;">&#125;</span> <span style="color: #000066; font-weight: bold;color: #0000FF;">else</span> <span style="color: #009900;color: #000000;">&#123;</span>
			validJSON <span style="color: #339933;color: #000000;">=</span> JSON.<span style="color: #660066;">parse</span><span style="color: #009900;color: #000000;">&#40;</span>JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;color: #000000;">&#40;</span>data<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
			window.<span style="color: #660066;">console</span> <span style="color: #339933;color: #000000;">&amp;&amp;</span> console.<span style="color: #660066;">warn</span><span style="color: #009900;color: #000000;">&#40;</span>
				<span style="color: #3366CC;color: #808080;">'response data was not a JSON string'</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
		<span style="color: #009900;color: #000000;">&#125;</span>
		<span style="color: #000066; font-weight: bold;color: #0000FF;">if</span> <span style="color: #009900;color: #000000;">&#40;</span>validJSON<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
			callback<span style="color: #009900;color: #000000;">&#40;</span>validJSON<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
		<span style="color: #009900;color: #000000;">&#125;</span> <span style="color: #000066; font-weight: bold;color: #0000FF;">else</span> <span style="color: #009900;color: #000000;">&#123;</span>
			<span style="color: #000066; font-weight: bold;color: #0000FF;">throw</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">&quot;JSONP call returned invalid or empty JSON&quot;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
		<span style="color: #009900;color: #000000;">&#125;</span>
	<span style="color: #009900;color: #000000;">&#125;</span>
<span style="color: #009900;color: #000000;">&#125;</span><span style="color: #339933;color: #000000;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> callbackCounter <span style="color: #339933;color: #000000;">=</span> <span style="color: #CC0000;color: #808080;">0</span><span style="color: #339933;color: #000000;">;</span>
global.<span style="color: #660066;">JSONPCallbacks</span> <span style="color: #339933;color: #000000;">=</span> <span style="color: #009900;color: #000000;">&#91;</span><span style="color: #009900;color: #000000;">&#93;</span><span style="color: #339933;color: #000000;">;</span>
global.<span style="color: #660066;">saferJSONP</span> <span style="color: #339933;color: #000000;">=</span> <span style="color: #003366; font-weight: bold;color: #0000FF;">function</span><span style="color: #009900;color: #000000;">&#40;</span>url<span style="color: #339933;color: #000000;">,</span> callback<span style="color: #009900;color: #000000;">&#41;</span> <span style="color: #009900;color: #000000;">&#123;</span>
	<span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> count <span style="color: #339933;color: #000000;">=</span> callbackCounter<span style="color: #339933;color: #000000;">++;</span>
	global.<span style="color: #660066;">JSONPCallbacks</span><span style="color: #009900;color: #000000;">&#91;</span>count<span style="color: #009900;color: #000000;">&#93;</span> <span style="color: #339933;color: #000000;">=</span> evalJSONP<span style="color: #009900;color: #000000;">&#40;</span>callback<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
	url <span style="color: #339933;color: #000000;">=</span> url.<span style="color: #660066;">replace</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">'=JSONPCallback'</span><span style="color: #339933;color: #000000;">,</span> <span style="color: #3366CC;color: #808080;">'=JSONPCallbacks['</span> <span style="color: #339933;color: #000000;">+</span> count <span style="color: #339933;color: #000000;">+</span> <span style="color: #3366CC;color: #808080;">']'</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;color: #0000FF;">var</span> scriptTag <span style="color: #339933;color: #000000;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">'SCRIPT'</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
	scriptTag.<span style="color: #660066;">src</span> <span style="color: #339933;color: #000000;">=</span> url<span style="color: #339933;color: #000000;">;</span>
	document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">'HEAD'</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #009900;color: #000000;">&#91;</span><span style="color: #CC0000;color: #808080;">0</span><span style="color: #009900;color: #000000;">&#93;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;color: #000000;">&#40;</span>scriptTag<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
<span style="color: #009900;color: #000000;">&#125;</span><span style="color: #339933;color: #000000;">;</span>
&nbsp;
<span style="color: #009900;color: #000000;">&#125;</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #009900;color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;color: #0000FF;">this</span><span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/safer-jsonp/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Instant Sprite &#8211; CSS Sprite Generator</title>
		<link>http://www.briangrinstead.com/blog/instant-sprite</link>
		<comments>http://www.briangrinstead.com/blog/instant-sprite#comments</comments>
		<pubDate>Fri, 19 Nov 2010 13:36:08 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[css sprite]]></category>
		<category><![CDATA[css sprite generator]]></category>
		<category><![CDATA[filereader]]></category>
		<category><![CDATA[instantsprite]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=452</guid>
		<description><![CDATA[I&#8217;ve been working on a project to make generating CSS Sprites faster and easier. It is called Instant Sprite, and available at http://instantsprite.com. You can drop the images right into the browser (or open them up in a file input) and it generates the sprite in the browser, with no file uploads. You can check [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a project to make generating CSS Sprites faster and easier.  It is called Instant Sprite, and available at <a href='http://instantsprite.com'>http://instantsprite.com</a>.  You can drop the images right into the browser (or open them up in a file input) and it generates the sprite in the browser, with no file uploads.  You can check it out and use some sample images provided if you don&#8217;t have any images available. </p>
<p>Instant Sprite uses HTML Canvas and the FileReader interface to read images from your hard drive &#8211; this prevents you from having to zip up all the images before passing them off to the sprite generator.  You can also preview your changes to CSS tweaks in real time, so you don&#8217;t have to resubmit if the file match regex isn&#8217;t doing what you want.  </p>
<p>I&#8217;d like to give credit to <a href='http://www.aaronbarker.net/'>Aaron Barker</a> for helping out with a lot of feedback and UI suggestions.</p>
<p>I made it for myself so that generating sprites was easier, but put it online because I think it might be useful to others, too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/instant-sprite/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>filereader.js &#8211; A Lightweight FileReader Wrapper</title>
		<link>http://www.briangrinstead.com/blog/filereaderjs</link>
		<comments>http://www.briangrinstead.com/blog/filereaderjs#comments</comments>
		<pubDate>Sun, 14 Nov 2010 07:33:13 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[filereader]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.briangrinstead.com/blog/?p=438</guid>
		<description><![CDATA[filereader.js is lighweight wrapper for the JavaScript FileReader interface.]]></description>
			<content:encoded><![CDATA[<p>I am working on project that needs to read local files.  This relies on the FileReader interface, and I couldn&#8217;t find any JavaScript libraries to help out with common usage for this, so I made one.</p>
<p>FileReader is a JavaScript interface that allows you to read local files as binary.  This is available in <a href='http://caniuse.com/#feat=fileapi'>supported browsers</a> when a user drags and drops files into a browser window or selects files from an input with a type of file.  See the <a href='http://dev.w3.org/2006/webapi/FileAPI/#FileReader-interface'>FileReader specification</a> for more information.</p>
<p>filereader.js is a wrapper for accessing this functionality.  It can be called using:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">FileReaderJS.<span style="color: #660066;">setupInput</span><span style="color: #009900;color: #000000;">&#40;</span>fileInput<span style="color: #339933;color: #000000;">,</span> opts<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
FileReaderJS.<span style="color: #660066;">setupDrop</span><span style="color: #009900;color: #000000;">&#40;</span>dropbox<span style="color: #339933;color: #000000;">,</span> opts<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span></pre></div></div>

<p>If you use jQuery, you can access these calls with:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">&quot;#fileInput&quot;</span><span style="color: #009900;color: #000000;">&#41;</span>.<span style="color: #660066;">fileReaderJS</span><span style="color: #009900;color: #000000;">&#40;</span>opts<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span>
$<span style="color: #009900;color: #000000;">&#40;</span><span style="color: #3366CC;color: #808080;">&quot;#dropbox&quot;</span><span style="color: #009900;color: #000000;">&#41;</span>.<span style="color: #660066;">fileReaderJS</span><span style="color: #009900;color: #000000;">&#40;</span>opts<span style="color: #009900;color: #000000;">&#41;</span><span style="color: #339933;color: #000000;">;</span></pre></div></div>

<p>To see the full range of options and functionality, view the <a href='https://github.com/bgrins/filereader.js/blob/master/README'>readme</a>.</p>
<p>filereader.js is available under the MIT License.  See the full <a href="http://github.com/bgrins/filereader.js">filereader.js code</a> or the single file <a href='https://github.com/bgrins/filereader.js/raw/master/filereader.js'>raw javascript source</a> on github.</p>
<p>You can see an example project using filereader.js on Instant Sprite, a browser based <a href="http://instantsprite.com">CSS Sprite Generator</a> that I am working on.  Try dragging images onto the body, or clicking to add multiple image files to see what is possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.briangrinstead.com/blog/filereaderjs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

