<?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>subCHILD</title>
	<atom:link href="http://www.subchild.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.subchild.com</link>
	<description>Memoirs of a DOM Scriptah: JavaScript, CSS, HTML and other findings and tutorials</description>
	<lastBuildDate>Mon, 12 Nov 2012 19:43:05 +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>Slideshowify Gets a Project Homepage, Demos, Documentation</title>
		<link>http://www.subchild.com/2012/11/12/slideshowify-gets-project-homepage-more-demos-documentation/</link>
		<comments>http://www.subchild.com/2012/11/12/slideshowify-gets-project-homepage-more-demos-documentation/#comments</comments>
		<pubDate>Mon, 12 Nov 2012 16:43:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[photo gallery]]></category>

		<guid isPermaLink="false">http://www.subchild.com/?p=288</guid>
		<description><![CDATA[After just sitting there collecting dust for a while, Slideshowify is back and better than ever. New updates include CSS3 support (provided via @rstacruz&#8216;s excellent jquery.transit.js plugin), animation as well as zooming in both directions and better browser support &#8211; it works and looks great on tablets and other touch devices. In addition, the project [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://subchild.com/slideshowify" target="_blank"><img style="border: 0; float: left; margin: 0 20px 20px 0;" src="http://www.subchild.com/blog/wp-content/uploads/2012/11/slideshowify.png" alt="" /></a>After just sitting there collecting dust for a while, Slideshowify is back and better than ever.</p>
<p>New updates include CSS3 support (provided via <a href="http://twitter.com/rstacruz" target="_blank">@rstacruz</a>&#8216;s excellent jquery.transit.js plugin), animation as well as zooming in both directions and better browser support &#8211; it works and looks great on tablets and other touch devices.</p>
<p>In addition, the project now has a legitimate project homepage which provides documentation and a couple of live demos. </p>
<p>Check it out now at: <a href="http://subchild.com/slideshowify" target="_blank">http://subchild.com/slideshowify</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.subchild.com/2012/11/12/slideshowify-gets-project-homepage-more-demos-documentation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>iStockutils.com &#8211; Built with Flask and Now Live</title>
		<link>http://www.subchild.com/2012/01/07/istockutils-com-built-with-flask-and-now-live/</link>
		<comments>http://www.subchild.com/2012/01/07/istockutils-com-built-with-flask-and-now-live/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 22:44:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.subchild.com/?p=271</guid>
		<description><![CDATA[I recently set out to learn Python, specifically on the Flask (+Werkzeug/Jinja2) microframework, and did so through developing a tool for iStocphoto.com contributors. The result is iStockutils.com, and the code is available for viewing/forking on GitHub. I still have much more to learn, but though this exercise I&#8217;ve become a big fan of Python and, [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float:left; margin:0 20px 20px 0" src="http://www.subchild.com/blog/wp-content/uploads/2012/01/istockutils.com_-300x180.png" alt="" title="istockutils.com" width="300" height="180" class="alignnone size-medium wp-image-272" /> I recently set out to learn Python, specifically on the <a href="http://flask.pocoo.org/">Flask</a> (+Werkzeug/Jinja2) microframework, and did so through developing a tool for <a href="http://www.istockphoto.com">iStocphoto.com</a> contributors. The result is <a href="http://www.istockutils.com">iStockutils.com</a>, and the code is available for viewing/forking on <a href="http://github.com/subchild/iStockUtils">GitHub</a>.</p>
<p>I still have much more to learn, but though this exercise I&#8217;ve become a big fan of Python and, after working with lots of different templating engines over the years, really like the format and flexibility of Jinja2. Kudos to Armin Ronacher for his fantastic work on all of this.</p>
<p>No kudos though to the iStockphoto folks who haven&#8217;t even responded to my request for access to their API. This means that all of the data is currently scraped from the HTML. Nasty.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subchild.com/2012/01/07/istockutils-com-built-with-flask-and-now-live/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Processing XML with jQuery &#8211; An IBM devWorks Tutorial</title>
		<link>http://www.subchild.com/2011/02/09/developerworks-tutorial-processing-xml-with-jquery/</link>
		<comments>http://www.subchild.com/2011/02/09/developerworks-tutorial-processing-xml-with-jquery/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 18:52:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.subchild.com/?p=260</guid>
		<description><![CDATA[My tutorial on processing XML with jQuery in the browser is now live on IBM&#8217;s developerWorks website. Check it out at: http://www.ibm.com/developerworks/xml/tutorials/x-processxmljquerytut/index.html Most JavaScript and jQuery ninjas needn&#8217;t read past the title for the gist, but hopefully there&#8217;s something new for everyone. Either way, your comments are welcome.]]></description>
			<content:encoded><![CDATA[<p><img src="/blog/wp-content/uploads/2011/02/ibm_dW1.png" class="alignleft" style="margin:0 20px 20px 0; border-bottom:3px solid black"/> My tutorial on processing XML with jQuery in the browser is now live on IBM&#8217;s developerWorks website. Check it out at: <br/><br />
<a href="http://www.ibm.com/developerworks/xml/tutorials/x-processxmljquerytut/index.html">http://www.ibm.com/developerworks/xml/tutorials/x-processxmljquerytut/index.html</a><br/><br />
Most JavaScript and jQuery ninjas needn&#8217;t read past the title for the gist, but hopefully there&#8217;s something new for everyone. Either way, your comments are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subchild.com/2011/02/09/developerworks-tutorial-processing-xml-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Featured Posts</title>
		<link>http://www.subchild.com/2010/12/14/test/</link>
		<comments>http://www.subchild.com/2010/12/14/test/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 20:58:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.subchild.com/?p=244</guid>
		<description><![CDATA[Thanks for stopping by. While you&#8217;re here, you might as well check out the LiveXMLEditor, Slideshowify, JS and CSS Bundler, among other things. Enjoy.]]></description>
			<content:encoded><![CDATA[<p>Thanks for stopping by. While you&#8217;re here, you might as well check out the <a href="http://www.subchild.com/liveXmlEdit/" target="_blank">LiveXMLEditor</a>, <a href="http://subchild.com/slideshowify">Slideshowify</a>, <a href="http://www.subchild.com/2008/08/07/simple-javascript-and-css-file-bundler/">JS and CSS Bundler</a>, among other things. Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subchild.com/2010/12/14/test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Amazon CloudFront &#8211; PHP Invalidator</title>
		<link>http://www.subchild.com/2010/09/17/amazon-cloudfront-php-invalidator/</link>
		<comments>http://www.subchild.com/2010/09/17/amazon-cloudfront-php-invalidator/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 17:05:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[AWS]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[CloudFront]]></category>

		<guid isPermaLink="false">http://www.subchild.com/?p=176</guid>
		<description><![CDATA[Amazon recently (finally!) added support for invalidation to CloudFront.  Frankly, without this feature the service was pretty useless to me since updating (or deleting) the cached resource would mean that the actual operation would take up to 24 hours to be reflected on the CDN.  But all is well now as the invalidation API available [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-182" style="margin:0 25px 0 0;" title="cloudfrontlogo" src="/blog/wp-content/uploads/2010/09/cloudfrontlogo.gif" alt="cloudfrontlogo" width="195" height="122" />Amazon recently (finally!) added support for invalidation to CloudFront.  Frankly, without this feature the service was pretty useless to me since updating (or deleting) the cached resource would mean that the actual operation would take up to 24 hours to be reflected on the CDN.  But all is well now as the invalidation API available and is, as expected, very responsive.  (Based on initial tests, invalidations take a few minutes to process.)</p>
<p>What was missing though is a PHP API for easily creating and processing invalidation requests, so I put one together, largely inspired by the existing S3 and CloudFront PHP kits.</p>
<p><br style="clear:both;" /><br />
To invalidate an object, just create an instance of CloudFront and call invalidate() it. Like so:</p>
<pre>
<pre class="brush: php; title: ;">
$cf = new CloudFront($keyId, $secretKey, $distributionId);

// invalidate single object
$cf-&gt;invalidate(&quot;/path/to/object&quot;);

// invalidate many objects with single (batch) request
$cf-&gt;invalidate(array(&quot;/path/to/first&quot;,&quot;/path/to/second&quot;));

// enable debugging (response output) by passing true as the second argument
$cf-&gt;invalidate(array(&quot;/path/to/first&quot;,&quot;/path/to/second&quot;), true);</pre>
</pre>
<p><strong>Check out the source on GitHub:</strong> <a href="http://github.com/subchild/CloudFront-PHP-Invalidator">http://github.com/subchild/CloudFront-PHP-Invalidator</a></p>
<p>A couple of things to keep in mind. CloudFront supports very few concurrent invalidation requests so make batch requests as much as possible.  If you absolutely need to up this limit, go to <a href="http://aws.amazon.com/cloudfront-request/">http://aws.amazon.com/cloudfront-request/</a> and submit such a request. Also, keep in mind that updating a resource on CloudFront means that you&#8217;ll need to update it on S3 first, then invalidate the CloudFront copy only after the S3 has actually been updated, not when you make the request.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subchild.com/2010/09/17/amazon-cloudfront-php-invalidator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Live XML Editor: Version 1.5</title>
		<link>http://www.subchild.com/2010/08/26/live-xml-editor-version-1-5/</link>
		<comments>http://www.subchild.com/2010/08/26/live-xml-editor-version-1-5/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 15:31:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[LiveXmlEdit]]></category>

		<guid isPermaLink="false">http://www.subchild.com/?p=166</guid>
		<description><![CDATA[I recently had a chance to make a few updates to the Live XML Editor and address some user requests. Version 1.5 is now done and out.  Among the updates are: - jQuery 1.4 support. Since the editor relies heavily on DOM rendering and events, this update makes the app snappier. - Comment node display [...]]]></description>
			<content:encoded><![CDATA[<div style="margin:15px 15px 15px 0"><img title="liveXmlEdit_screenshot" src="/blog/wp-content/uploads/2010/08/liveXmlEdit_screenshot.gif" alt="liveXmlEdit_screenshot" width="500" height="416" /></div>
<p>I recently had a chance to make a few updates to the Live XML Editor and address some user requests. Version 1.5 is now done and out.  Among the updates are:</p>
<p>- <strong>jQuery 1.4 support</strong>. Since the editor relies heavily on DOM rendering and events, this update makes the app snappier.</p>
<p>- <strong>Comment node display and editing</strong>. This was requested by a user and I was surprised that I hadn&#8217;t thought of it. Creating comments isn&#8217;t supported yet, but its on the to-do list.</p>
<p>- Various <strong>bug fixes</strong>, tweaks and <strong>optimizations</strong>.</p>
<p>- Added (MIT) <strong>license</strong>.</p>
<p><strong>Check it out:</strong> <a href="http://www.subchild.com/liveXmlEdit" target="_blank">http://www.subchild.com/liveXmlEdit</a>.  <strong>Code is also on GitHub:</strong> <a href="http://github.com/subchild/liveXmlEdit/" target="_blank">http://github.com/subchild/liveXmlEdit/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.subchild.com/2010/08/26/live-xml-editor-version-1-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make an Object loggable()</title>
		<link>http://www.subchild.com/2010/08/23/make-an-object-loggable/</link>
		<comments>http://www.subchild.com/2010/08/23/make-an-object-loggable/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 21:47:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[Firebug]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://www.subchild.com/?p=152</guid>
		<description><![CDATA[loggable() is a simple little function for safely making a JavaScript object (console) loggable. (Name was inspired by @furf&#8216;s jquery.bindable.js.) /** * Loggable adds a log method to the passed object. * @param obj {Object} Object which will get a new log() method * @param objName {String} Optional parameter for displaying a string before each [...]]]></description>
			<content:encoded><![CDATA[<p>loggable() is a simple little function for safely making a JavaScript object (console) loggable. (Name was inspired by <a href="http://www.twitter.com/furf" target="_blank">@furf</a>&#8216;s <a href="http://github.com/furf/jquery-bindable">jquery.bindable.js</a>.)</p>
<pre>
<pre class="brush: jscript; title: ;">
/**
 * Loggable adds a log method to the passed object.
 * @param obj       {Object}  Object which will get a new log() method
 * @param objName   {String}  Optional parameter for displaying a string before each log output
 * @param debugMode {boolean} Optional switch for disabling logging
 */
function loggable(obj /* , objName, debugMode */){
	var objName   = arguments[1] || &quot;&quot;,
		debugMode = (typeof arguments[2]!==&quot;undefined&quot;) ? arguments[2] : true,
		prefix    = objName ? objName + &quot;: &quot; : &quot;&quot;;
	obj.log = (function(prefix){
		return function(){
			if (debugMode &amp;&amp; typeof console!==&quot;undefined&quot;){
				if (arguments.length){
					arguments[0] = prefix + arguments[0];
				}
				console.log.apply(null, arguments);
			}
		}
	})(prefix);
	return obj;
};
</pre>
</pre>
<p>So if you have an object like:</p>
<pre class="plain">
var obj = {
  name     : "Alex",
  getName : function(){ return "Alex" },
  setName : function(name){
    obj.name = name;
    obj.log("name was set to", name);
  }
}

<strong>loggable(obj, "Obj");</strong>
</pre>
<p>Then, executing:</p>
<pre class="plain">
obj.setName("Balthazar");
</pre>
<p>Will log this in your console (Firebug or otherwise):</p>
<pre class="plain">
Obj: name was set to Balthazar.
</pre>
<p>Here it is on GitHub: <a href="http://gist.github.com/547926">http://gist.github.com/547926</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.subchild.com/2010/08/23/make-an-object-loggable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slideshowify: Ken Burns Slideshow Effect as a jQuery Plugin</title>
		<link>http://www.subchild.com/2010/06/10/ken-burns-effect-as-a-jquery-plugin-slideshowify/</link>
		<comments>http://www.subchild.com/2010/06/10/ken-burns-effect-as-a-jquery-plugin-slideshowify/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 01:02:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[photo gallery]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[slideshow]]></category>

		<guid isPermaLink="false">http://www.subchild.com/2010/06/10/ken-burns-effect-as-a-jquery-plugin-slideshowify/</guid>
		<description><![CDATA[Slideshowify is a jQuery plugin for creating a slideshow of images that will fill the screen with a (cropped) image, then pan across to reveal the rest of it. This is commonly referred to as the Ken Burns Effect and is often seen in documentaries. A nice version is of it can be seen in [...]]]></description>
			<content:encoded><![CDATA[<p>Slideshowify is a jQuery plugin for creating a slideshow of images that will fill the screen with a (cropped) image, then pan across to reveal the rest of it.  This is commonly referred to as the <a href="http://en.wikipedia.org/wiki/Ken_Burns_Effect" target=_"blank">Ken Burns Effect</a> and is often seen in documentaries.  A nice version is of it can be seen in that Mac screensaver.</p>
<p>Anyhow, here&#8217;s a stab at such a thing. Some future enhancements are obvious (pan direction, zooming, transition options, etc.) and anticipate finding the time to add that stuff shortly.</p>
<p>For now, check out the code on <a href="http://www.github.com/subchild/jquery.slideshowify.js" target="_blank">github.com</a> and <strong>see a demo</strong> at <a href="http://www.subchild.com/slideshowify">www.subchild.com/slideshowify</a></p>
<p>To use it, include jQuery, jquery.slideshowify.js, then feed slideshowify a selector that matches some images.  For example:</p>
<pre class="plain">
$("img").slideshowify();
</pre>
<p>Alternatively, you could load data from an external feed and call $.slideshowify() with configuration options:</p>
<pre class="plain">
$.slideshowify({
 	dataUrl   : "http://www.gallerama.com/services/gallery/get.php?gid=2107&#038;versions[]=9",
	dataType  : "jsonp",
	randomize : true,
 	filterFn  : function(imgs){
 		var fixedImgs = [];
 		$.each(imgs, function(i, img){
 			fixedImgs.push(img.versions["9"]);
 		});
 		return fixedImgs;
 	},
	afterFadeIn : function(imgData){},
	beforeFadeOut : function(imgData){}
 });
</pre>
<p>Most of the params here are passed directly to jQuery&#8217;s $.ajax() method. Some are used to reformat the data (slideshowify() expects an array of objects of this format: {src:&#8221;domain.com/path/to/image.jpg&#8221;, w:&#8221;600&#8243;, h:&#8221;400&#8243;}), others are hooks or speed (fade, delay) options.</p>
<p>Proper documentation will be provided.  Most likely.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subchild.com/2010/06/10/ken-burns-effect-as-a-jquery-plugin-slideshowify/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic CSS Loading with jQuery 1.4: Cross-Browser Problem Solved</title>
		<link>http://www.subchild.com/2010/05/20/cross-browser-problem-with-dynamic-css-loading-with-jquery-1-4-solved/</link>
		<comments>http://www.subchild.com/2010/05/20/cross-browser-problem-with-dynamic-css-loading-with-jquery-1-4-solved/#comments</comments>
		<pubDate>Thu, 20 May 2010 21:59:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.subchild.com/?p=131</guid>
		<description><![CDATA[Loading an external CSS stylesheet with jQuery is cake.  But in version 1.4 it stopped working in IE. Specifically, doing this doesn&#8217;t work: $('&#60;link href="/path/to/stylesheet.css" rel="stylesheet" type="text/css" /&#62;').appendTo("head"); After investigating and Googling this a bit, I discovered that this technique does work: var $link = $('&#60;link/&#62;').appendTo("head"); $link.attr({ href : "/path/to/stylesheet.css", rel  : "stylesheet", type : [...]]]></description>
			<content:encoded><![CDATA[<p>Loading an external CSS stylesheet with jQuery is cake.  But in version 1.4 it stopped working in IE. Specifically, doing this doesn&#8217;t work:</p>
<pre class="plain">$('&lt;link href="/path/to/stylesheet.css" rel="stylesheet" type="text/css" /&gt;').appendTo("head");</pre>
<p>After investigating and Googling this a bit, I discovered that this technique does work:</p>
<pre class="plain">var $link = $('&lt;link/&gt;').appendTo("head");
$link.attr({
	href : "/path/to/stylesheet.css",
	rel  : "stylesheet",
	type : "text/css"
});</pre>
<p>However, this doesn&#8217;t work in Opera (only the latest version tested).</p>
<p>The solution is perhaps to simple to bother writing up, but here it is anyway:</p>
<pre class="plain">
$('&lt;link href="/path/to/stylesheet.css" rel="stylesheet" type="text/css" /&gt;').appendTo("head");
$link.attr({
	href : "/path/to/stylesheet.css",
	rel  : "stylesheet",
	type : "text/css"
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.subchild.com/2010/05/20/cross-browser-problem-with-dynamic-css-loading-with-jquery-1-4-solved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorting a JSON Array by Property</title>
		<link>http://www.subchild.com/2010/03/31/sorting-a-json-array-by-property/</link>
		<comments>http://www.subchild.com/2010/03/31/sorting-a-json-array-by-property/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 21:11:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://www.subchild.com/?p=112</guid>
		<description><![CDATA[Sorting arrays of JSON objects is a task that I occasionally come across. Here&#8217;s a little utility I&#8217;ve been using for a while that does the trick. /** * Sorts an array of json objects by some common property, or sub-property. * @param {array} objArray * @param {array&#124;string} prop Dot-delimited string or array of (sub)properties [...]]]></description>
			<content:encoded><![CDATA[<p>Sorting arrays of JSON objects is a task that I occasionally come across. Here&#8217;s a little utility I&#8217;ve been using for a while that does the trick.</p>
<pre>
<pre class="brush: jscript; title: ;">
/**
 * Sorts an array of json objects by some common property, or sub-property.
 * @param {array} objArray
 * @param {array|string} prop Dot-delimited string or array of (sub)properties
 */
function sortJsonArrayByProp(objArray, prop){
	if (arguments.length&lt;2){
		throw new Error(&quot;sortJsonArrayByProp requires 2 arguments&quot;);
	}
	if (objArray &amp;amp;&amp;amp; objArray.constructor===Array){
		var propPath = (prop.constructor===Array) ? prop : prop.split(&quot;.&quot;);
		objArray.sort(function(a,b){
			for (var p in propPath){
				if (a[propPath[p]] &amp;amp;&amp;amp; b[propPath[p]]){
					a = a[propPath[p]];
					b = b[propPath[p]];
				}
			}
			// convert numeric strings to integers
			a = a.match(/^\d+$/) ? +a : a;
			b = b.match(/^\d+$/) ? +b : b;
			return ( (a &lt; b) ? -1 : ((a &gt; b) ? 1 : 0) );
		});
	}
}
</pre>
</pre>
<p>Here&#8217;s a simple example:</p>
<pre class="plain">var arr = [
	{name:"Zack", friends:{count:50}},
	{name:"Alex", friends:{count:80}},
	{name:"Mike", friends:{count:30}}
];
sortJsonArrayByProp(arr, "name");
sortJsonArrayByProp(arr, "friends.count");
sortJsonArrayByProp(arr, ["friends","count"]);</pre>
<p>[Update] This function now converts strings made up entirely of digits into integers for (presumably) more accurate comparisons, and therefore, sorting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.subchild.com/2010/03/31/sorting-a-json-array-by-property/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
