<?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>Ambition Lab &#187; Web Dev</title>
	<atom:link href="http://www.ambitionlab.com/web-dev/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ambitionlab.com</link>
	<description>Rajeev Singh</description>
	<lastBuildDate>Tue, 25 May 2010 21:28:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Find &amp; Delete a Specified Value From an Array in JavaScript</title>
		<link>http://www.ambitionlab.com/how-to-find-delete-a-specified-value-from-an-array-in-javascript-2010-04-21</link>
		<comments>http://www.ambitionlab.com/how-to-find-delete-a-specified-value-from-an-array-in-javascript-2010-04-21#comments</comments>
		<pubDate>Wed, 21 Apr 2010 13:00:35 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=251</guid>
		<description><![CDATA[You would think that this would be part of JavaScript&#8217;s core functionality, but&#8230; no. It&#8217;s delete function leaves a value of &#8220;undefined&#8221; in place of the original. Using splice is the solution, but first you have to know the index of the element. These two simple functions make easy work of the task.
Object-oriented folk may [...]]]></description>
			<content:encoded><![CDATA[<p>You would think that this would be part of JavaScript&#8217;s core functionality, but&#8230; no. It&#8217;s <strong>delete</strong> function leaves a value of &#8220;undefined&#8221; in place of the original. Using<strong> splice</strong> is the solution, but first you have to know the index of the element. These two simple functions make easy work of the task.</p>
<p>Object-oriented folk may want to enclose these functions within an extended array object (or extend the Array object, if that&#8217;s your style):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> getArrayIndex <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>array<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> array.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>array<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> i<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> deleteArrayItem <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>array<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> index <span style="color: #339933;">=</span> getArrayIndex<span style="color: #009900;">&#40;</span>array<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>index <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>        
        <span style="color: #000066; font-weight: bold;">return</span> array.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span>index<span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> array<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Using Array.indexOf might seem logical, but it&#8217;s mildly cross-browser problematic at the moment. Rather than using the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/indexOf">common Array.indexOf workaround</a>, I&#8217;m using a custom function because it&#8217;s less code and can be tweaked to suit any unique needs I might have.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/how-to-find-delete-a-specified-value-from-an-array-in-javascript-2010-04-21/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Typeface.js :hover workaround</title>
		<link>http://www.ambitionlab.com/typeface-js-hover-workaround-2010-04-19</link>
		<comments>http://www.ambitionlab.com/typeface-js-hover-workaround-2010-04-19#comments</comments>
		<pubDate>Mon, 19 Apr 2010 13:00:01 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=243</guid>
		<description><![CDATA[A while ago I wrote a sIFR vs Typeface.js article, and ever since then I&#8217;ve seen hits to my site from people searching for a :hover workaround for Typeface. Here&#8217;s a limited solution. It&#8217;s using jQuery, but you could easily adapt this method to use another library (or none at all). I&#8217;ll admit this isn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I wrote a <a href="http://www.ambitionlab.com/sifr-vs-typeface-js-the-verdict-2010-01-08">sIFR vs Typeface.js article</a>, and ever since then I&#8217;ve seen hits to my site from people searching for a :hover workaround for Typeface. Here&#8217;s a limited solution. It&#8217;s using jQuery, but you could easily adapt this method to use another library (or none at all). I&#8217;ll admit this isn&#8217;t the most eloquent solution in the world, but this proved to be functional, so I thought I&#8217;d share.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> typefacehover <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>                            
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.typeface-js&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//Get all the classes for an element. </span>
    <span style="color: #003366; font-weight: bold;">var</span> elementStyles <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    elementStyles <span style="color: #339933;">=</span> elementStyles.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//Run through them and check for a :hover color property.</span>
    <span style="color: #003366; font-weight: bold;">var</span> hoverColor<span style="color: #339933;">;</span>                                
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> elementStyles<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>                                        
      <span style="color: #003366; font-weight: bold;">var</span> temp <span style="color: #339933;">=</span> getCSSColor<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.'</span><span style="color: #339933;">+</span>elementStyles<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">':hover'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                           
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>temp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        hoverColor <span style="color: #339933;">=</span> temp<span style="color: #339933;">;</span>                                        
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>hoverColor<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">//Duplicate the element, create a new hover version of the element (hidden) and add a container to each one so that we can distinguish between the two.</span>
      <span style="color: #003366; font-weight: bold;">var</span> hoverElement <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;div class=&quot;typeface-js-hover&quot; style=&quot;color:'</span><span style="color: #339933;">+</span>hoverColor<span style="color: #339933;">+</span><span style="color: #3366CC;">';display:none&quot;&gt;'</span><span style="color: #339933;">+</span>element<span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
      element <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;div class=&quot;typeface-js-nohover&quot;&gt;'</span><span style="color: #339933;">+</span>element<span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> newElement <span style="color: #339933;">=</span> element <span style="color: #339933;">+</span> hoverElement<span style="color: #339933;">;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>newElement<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">//Add the event listener. You could do fade transitions here if you wanted to be fancy.</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.typeface-js-nohover&quot;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.typeface-js-hover&quot;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.typeface-js-nohover&quot;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.typeface-js-hover&quot;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #006600; font-style: italic;">//Kudos: http://www.mail-archive.com/jquery-dev@googlegroups.com/msg03390.html</span>
<span style="color: #003366; font-weight: bold;">var</span> getCSSColor <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>selector<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>                            
  <span style="color: #003366; font-weight: bold;">var</span> re <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'(^|,)<span style="color: #000099; font-weight: bold;">\\</span>s*'</span><span style="color: #339933;">+</span>selector.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\\</span>s*(,|$)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> color<span style="color: #339933;">;</span>                            
  $.<span style="color: #660066;">each</span> <span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">makeArray</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">styleSheets</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">each</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cssRules</span> <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">rules</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>    
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>re.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">selectorText</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>                                        
        color <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span><span style="color: #339933;">;</span>                                        
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">return</span> color<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I hope to find the time to develop a more robust solution in the future. Let me know if this was helpful!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/typeface-js-hover-workaround-2010-04-19/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>sIFR vs Typeface.js: The Verdict</title>
		<link>http://www.ambitionlab.com/sifr-vs-typeface-js-the-verdict-2010-01-08</link>
		<comments>http://www.ambitionlab.com/sifr-vs-typeface-js-the-verdict-2010-01-08#comments</comments>
		<pubDate>Fri, 08 Jan 2010 20:44:45 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=215</guid>
		<description><![CDATA[[Update: If you're looking for the typeface.js :hover workaround, it's here]
Months ago, in my mission to find a good solution for using fancy fonts on the web, I had a choice between sIFR and typeface.js. sIFR uses Flash to render text, and typeface uses the &#60;canvas&#62; element (or VML in IE). Other than the difference [...]]]></description>
			<content:encoded><![CDATA[<p><strong>[Update: If you're looking for the typeface.js :hover workaround, it's <a href="http://www.ambitionlab.com/typeface-js-hover-workaround-2010-04-19">here</a>]</strong></p>
<p>Months ago, in my mission to find a good solution for using fancy fonts on the web, I had a choice between <a href="http://wiki.novemberborn.net/sifr/">sIFR</a> and <a href="http://typeface.neocracy.org/">typeface.js</a>. sIFR uses Flash to render text, and typeface uses the &lt;canvas&gt; element (or VML in IE). Other than the difference in implementation, however, their feature-set looked about the same, at least for my simple purposes: they were both javascript driven, both allowed text to be selected, and they both looked damn good.</p>
<p>But typeface.js had one crippling debilitation. It didn&#8217;t have :hover support. <em>Weak.</em> So I went with sIFR.</p>
<p>First, I found sIFR&#8217;s configuration to be a pain. <em>Well, that&#8217;s OK. I only have to learn the setup once, then I can copy+paste my code. </em></p>
<p>Then I found that it had z-index issues in IE, particularly when using them as links and tying the :hover directive together with an image change. <em>Annoying, but it&#8217;s flash based and IE is always a pain. Fine.</em></p>
<p>Then I noticed that my jQuery animations (slide effects) were slowed down when sIFR elements were included in the animated element. <em>Hmmm.</em></p>
<p>Then I started using <span style="text-decoration: underline;">a lot</span> of sIFR elements on one page&#8230; significant loading delay. <em>Hrmph.</em></p>
<p>Then it came to my attention that every once in a while the sIFR elements would fail to load altogether in IE on those sIFR-heavy pages. <em>Uh&#8230;. sIFR, we&#8217;re through. This just isn&#8217;t going to work out. It&#8217;s not me, it&#8217;s you. It was great while it lasted (wait, no.. not really). Ciao.</em></p>
<p>And then I said hello to typeface.js. Configuration? <em>Piece of cake.</em> Speed? <em>Fast!</em> Reliability? <em>Hasn&#8217;t failed me yet.</em> Z-index issues? <em>None.</em> Lack of :hover support?</p>
<p>I can live with that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/sifr-vs-typeface-js-the-verdict-2010-01-08/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to check if a file exists using JQuery</title>
		<link>http://www.ambitionlab.com/how-to-check-if-a-file-exists-using-jquery-2010-01-06</link>
		<comments>http://www.ambitionlab.com/how-to-check-if-a-file-exists-using-jquery-2010-01-06#comments</comments>
		<pubDate>Wed, 06 Jan 2010 20:54:11 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>
		<category><![CDATA[code snippet]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=205</guid>
		<description><![CDATA[The best way to do this is with an AJAX HEAD request. HEAD requests only ask for and return the header from the destination file, so they&#8217;re much faster than POST or GET requests. Perfect for a simple file check.
It&#8217;s also worth noting that a HEAD request also returns the content length and last modified [...]]]></description>
			<content:encoded><![CDATA[<p>The best way to do this is with an AJAX HEAD request. HEAD requests only ask for and return the header from the destination file, so they&#8217;re much faster than POST or GET requests. Perfect for a simple file check.</p>
<p>It&#8217;s also worth noting that a HEAD request also returns the content length and last modified date, and that jQuery has an &#8220;ifModified&#8221; option for the .ajax function that returns a boolean value.</p>
<p>Quick code snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    url<span style="color: #339933;">:</span><span style="color: #3366CC;">'http://www.example.com/somefile.ext'</span><span style="color: #339933;">,</span>
    type<span style="color: #339933;">:</span><span style="color: #3366CC;">'HEAD'</span><span style="color: #339933;">,</span>
    error<span style="color: #339933;">:</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">//do something depressing</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    success<span style="color: #339933;">:</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">//do something cheerful :)</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Couldn&#8217;t be easier!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/how-to-check-if-a-file-exists-using-jquery-2010-01-06/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Clean, Tidy and Flexible Function Variables</title>
		<link>http://www.ambitionlab.com/clean-tidy-and-flexible-function-variables-2009-12-14</link>
		<comments>http://www.ambitionlab.com/clean-tidy-and-flexible-function-variables-2009-12-14#comments</comments>
		<pubDate>Mon, 14 Dec 2009 13:00:12 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=187</guid>
		<description><![CDATA[The thing about functions is&#8230; they grow. They start off small and cute and useful, but over time you start to notice their little shortcomings, so you make them bigger, better, and more flexible. Unfortunately, if you&#8217;re using PHP&#8217;s default method of passing functions, which is based on the sequence the functions are given (i.e. [...]]]></description>
			<content:encoded><![CDATA[<p>The thing about functions is&#8230; they grow. They start off small and cute and useful, but over time you start to notice their little shortcomings, so you make them bigger, better, and more flexible. Unfortunately, if you&#8217;re using PHP&#8217;s default method of passing functions, which is based on the sequence the functions are given (i.e. <strong>function </strong>example<span style="color: #339966;">(</span><span style="color: #ff9900;">$variable1</span>, <span style="color: #ff9900;">$variable2</span>, <span style="color: #ff9900;">$etc</span><span style="color: #339966;">)</span>) , things can get a little messy. The more variables a function can handle, the harder it is to remember the sequence they have to follow. Not to mention PHP 5 doesn&#8217;t facilitate a way to skip variables. For example, this doesn&#8217;t work: example<span style="color: #339966;">(</span><span style="color: #ff9900;">$variable1</span>, , <span style="color: #ff9900;">$variable3</span>, <span style="color: #ff9900;">$etc</span><span style="color: #339966;">)</span>.</p>
<p>The solution is to pass your variables on in an array. Here&#8217;s the template that I use whenever I code a new function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> example<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$variable1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variable1'</span><span style="color: #009900;">&#93;</span>? <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variable1'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And this is how you pass variables on to your function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'variable1'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'value'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'variable2'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'variable3'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$etc</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
example<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And what&#8217;s more, if you have an existing function that you want to convert to taking an array, but don&#8217;t want to change all of your existing function calls, you can do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> example<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$variable2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$variable3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$variable1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variable1'</span><span style="color: #009900;">&#93;</span>? <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variable1'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$variable2</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variable2'</span><span style="color: #009900;">&#93;</span>? <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'variable2'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$variable1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Clean, tidy, and easy as pie. <img src='http://www.ambitionlab.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/clean-tidy-and-flexible-function-variables-2009-12-14/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code your own permalinks</title>
		<link>http://www.ambitionlab.com/code-your-own-permalinks-2009-12-09</link>
		<comments>http://www.ambitionlab.com/code-your-own-permalinks-2009-12-09#comments</comments>
		<pubDate>Thu, 10 Dec 2009 02:42:53 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=173</guid>
		<description><![CDATA[Ever wondered how a CMS like WordPress creates those pretty URLs that resemble directory structures on the fly?Ever wondered if you could do the same thing with your own website or web app? Well you can, and it&#8217;s ridiculously simple.
Step 1: You need to edit your .htaccess file to incorporate some mod rewrite rules. This [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wondered how a CMS like WordPress creates those pretty URLs that resemble directory structures on the fly?Ever wondered if you could do the same thing with your own website or web app? Well you can, and it&#8217;s ridiculously simple.</p>
<p>Step 1: You need to edit your .htaccess file to incorporate some mod rewrite rules. This is the code that we&#8217;re going to use (the same code that WordPress uses):</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteBase</span> /
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} !-f
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} !-d
<span style="color: #00007f;">RewriteRule</span> . /yourcode.php [L]</pre></div></div>

<p>What this does is capture the &#8220;filenames&#8221; (really just a URI string that comes after your site root), and pass them on in an array to the file of your choice, &#8220;yourcode.php&#8221; in this case. It does all this without changing the URL on the user&#8217;s end. So now all we have to do is pick up those variables in our PHP code. We&#8217;ll do that with this code in yourcode.php :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$vars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$uri</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So now we&#8217;ve captured the elements of the permalink in our array $vars, starting with the second array object, $vars[1]. The first array object, $vars[0] will return as blank. So let&#8217;s suppose the user is trying to go to this address:</p>
<p>http://www.yoursite.com/someuser/profile</p>
<p>$vars[1] will be &#8220;someuser&#8221;. $vars[2] will be &#8220;profile&#8221;. We can then use that information like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vars</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vars</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&#8230; and then use those variables to determine what data we output to the browser.</p>
<p>Easy as pie. <img src='http://www.ambitionlab.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/code-your-own-permalinks-2009-12-09/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>News Bulletin: The Internet Says Hello to Typography</title>
		<link>http://www.ambitionlab.com/news-bulletin-the-internet-says-hello-to-typography-2009-05-26</link>
		<comments>http://www.ambitionlab.com/news-bulletin-the-internet-says-hello-to-typography-2009-05-26#comments</comments>
		<pubDate>Tue, 26 May 2009 20:20:34 +0000</pubDate>
		<dc:creator>Raj</dc:creator>
				<category><![CDATA[Web Dev]]></category>
		<category><![CDATA[font-face]]></category>
		<category><![CDATA[typography]]></category>

		<guid isPermaLink="false">http://www.ambitionlab.com/?p=5</guid>
		<description><![CDATA[Will it be love at first sight or a bitter, bitter marriage with no possibility of divorce?
Pandora’s little black box is about to be opened. Soon, very soon, most common browsers will support the @font-face CSS directive. Web designers will have at their disposal any TrueType or OpenType font that legally allows for web embedding. [...]]]></description>
			<content:encoded><![CDATA[<p style="font-family: BergamoStd;font-style:italic">Will it be love at first sight or a bitter, bitter marriage with no possibility of divorce?</p>
<p style="font-family: graublauweb">Pandora’s little black box is about to be opened. Soon, very soon, most common browsers will support the @font-face CSS directive. Web designers will have at their disposal any TrueType or OpenType font that legally allows for web embedding. What does that mean to you? Well, brace yourself for a web full of <span style="font-family: abduction, georgia">unreadable</span>, <span style="font-family: girlsare, georgia;">kooky</span> typefaces, <span style="font-family: baronkuffner, georgia;">messy grunge fonts</span>, and lots and <span style="font-family: notethis, georgia;">lots</span> of <span style="font-family: notethis, georgia;"> imitation handwriting</span>.</p>
<p>And that&#8217;s not all. Designers will want to use commercial fonts that are meticulously designed with readability and balance in mind. Unfortunately, because the directive requires that the font file be downloaded by the client machine (and therefore accessible to anyone on the web), the use of said fonts will constitute a legal violation. <span style="font-family: nevis, georgia">So the fonts we hate will be given free reign while the fonts we love will remain private treasures.</span></p>
<p>That having been said, there is a bright side. I have a few predictions: Reputed foundries will release free, limited web-versions of their commercial fonts. The prolific use of hideous typefaces will only make the good ones shine a little brighter.  Web designers will be forced to learn more than a handful of fonts. Typography&#8217;s value will be clearer, and interest and appreciation of it will rise.</p>
<p>OK, want a taste of what it will look like? This post is an experiment—it uses @font-face—so all you have to do is load it in a browser with @font-face support (see link below for more info) and you can behold the wonder that is font embedding. My apologies if this post is a poorly executed example and hard to read (welcome to the future, friend). I only wanted to experiment and learn, which leads me to my next point.</p>
<p>I have two potential concerns for the practical use of @font-face:</p>
<p><strong>One.</strong> While testing @font-face on this page, I noticed that some fonts just didn&#8217;t work. On top of that, fonts that worked in Firefox 3.5b didn&#8217;t work in Opera 10a. If anyone knows what&#8217;s going on here, please enlighten me. I realize that I&#8217;m working with alpha &amp; beta versions of those browsers, so maybe this is an issue that will work itself out in due time.</p>
<p><strong>Two.</strong> As usual, IE somehow manages to be both ahead of and behind the curve. While IE has supported @font-face since IE 4 (yeah, seriously!), they only support a font format called EOT (Embedded Open Type) that they created and no one uses. Naturally, being Microsoft, they decided to make the font conversion process a huge pain, which might just explain why no one uses it (hmmm&#8230;). IE&#8217;s lack of support for TrueType or OpenType is very troubling and can&#8217;t be ignored, but no one is going to torture themselves by using IE&#8217;s conversion tool unless the process is more streamlined. Solution: As usual, the rest of the world waits for IE to catch up.</p>
<p>All concerns and nay-saying aside, I really am very optimistic about the future of typography on the web. If you&#8217;re a web designer or developer, take some time to play around with @font-face! Here are a few links to get you started:</p>
<p>My hat goes off to <a href="http://webfonts.info/wiki/index.php?title=Main_Page">Webfonts.info</a> for being an extremely useful resource. Be sure to check out their <a href="http://www.webfonts.info/wiki/index.php?title=Commercial_foundries_which_allow_%40font-face_embedding">list of commercial foundries which allow @font-face embedding</a>. I expect that list to grow very quickly in the near future.</p>
<p><a href="http://webfonts.info/wiki/index.php?title=%40font-face_browser_support">A nice summary of supported browsers &amp; browser versions</a></p>
<p><a href="http://www.webfonts.info/wiki/index.php?title=Fonts_available_for_%40font-face_embedding">A list of fonts available for @font-face embedding</a></p>
<p><a href="http://jontangerine.com">Jon Tan</a> has a detailed article on <a href="http://jontangerine.com/log/2008/10/font-face-in-ie-making-web-fonts-work">how to make @font-face work in IE</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ambitionlab.com/news-bulletin-the-internet-says-hello-to-typography-2009-05-26/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
