<?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>Vance Lucas &#187; Javascript</title>
	<atom:link href="http://www.vancelucas.com/blog/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vancelucas.com</link>
	<description>Web Entrepreneur and Freelance PHP/Javascript Developer</description>
	<lastBuildDate>Thu, 17 Nov 2011 15:30:33 +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>Count the Number of Object keys/properties in Node.js</title>
		<link>http://www.vancelucas.com/blog/count-the-number-of-object-keysproperties-in-node-js/</link>
		<comments>http://www.vancelucas.com/blog/count-the-number-of-object-keysproperties-in-node-js/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 17:26:25 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[nodejs]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=768</guid>
		<description><![CDATA[When using the excellent formidable library to handle file uploads, I needed to get a count of the number of files unloaded in a multi-part form. Javascript arrays have a .length property that you can use, but objects do not. I instinctively typed: 1 files.length Which returned undefined. So if there is no length property present, an [...]]]></description>
			<content:encoded><![CDATA[<p>When using the excellent <a href="https://github.com/felixge/node-formidable">formidable</a> library to handle file uploads, I needed to get a count of the number of files unloaded in a multi-part form. Javascript arrays have a <code>.length</code> property that you can use, but objects do not. I instinctively typed:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="js" style="font-family:monospace;">files.length</pre></td></tr></table></div>

<p>Which returned <code>undefined</code>. So if there is no length property present, an easy way to count the number of keys or properties of an object in ES5-compliant javascript environments like <a href="http://nodejs.org">Node.js</a> is to use the Object prototype directly:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="js" style="font-family:monospace;">Object.keys(files).length</pre></td></tr></table></div>

<p>A little more typing, but it is fast, efficient, and most importantly: already built-in.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/count-the-number-of-object-keysproperties-in-node-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The One Character Block Comment</title>
		<link>http://www.vancelucas.com/blog/the-one-character-block-comment/</link>
		<comments>http://www.vancelucas.com/blog/the-one-character-block-comment/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 14:58:10 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[code comments]]></category>
		<category><![CDATA[comments]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=401</guid>
		<description><![CDATA[When debugging, I often find that I have to comment and un-comment a block of code several times during the process of trying to find out what&#8217;s going on. That used to mean typing and deleting comment block characters repetitively, but not anymore. Here&#8217;s a simple solution to that problem: Comment or un-comment an entire [...]]]></description>
			<content:encoded><![CDATA[<p>When debugging, I often find that I have to comment and un-comment a block of code several times during the process of trying to find out what&#8217;s going on. That used to mean typing and deleting comment block characters repetitively, but not anymore. Here&#8217;s a simple solution to that problem: Comment or un-comment an entire code block of code by typing or deleting a single character.</p>
<p>I was able to arrive at this solution by combining the one-line comment with the comment block in a way that takes advantage of the rules the different types of comments have to follow.<br />
<span id="more-401"></span></p>
<h3>The One-Line Comment</h3>
<p>One-line comment rules dictate that everything after the comment characters must be ignored for the rest of that line. They look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// My code below</span>
<span style="color: #000088;">$someVar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;blah&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;code&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$someVar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/code&gt;&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>The Block Comment</h3>
<p>Block comment rules dictate that once the beginning characters are started, everything up until the ending characters is ignored. They look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* My code below
$someVar = array(&quot;foo&quot;, &quot;bar&quot;, &quot;blah&quot;);
echo &quot;&lt;code&gt;&quot;;
print_r($someVar);
echo &quot;&lt;/code&gt;&quot;;
*/</span></pre></td></tr></table></div>

<h3>Combining The Two: The Best of Both Worlds</h3>
<p>Using both those comment style rules, we can combine the two comment styles in a way that will allow us to comment and un-comment a block of code with by adding or deleting a single character. The trick is to make both the beginning and ending lines both single-line AND block style comments, like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//* My code below</span>
<span style="color: #000088;">$someVar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;blah&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;code&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$someVar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/code&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// */</span></pre></td></tr></table></div>

<p>In the above example, you notice that the code will still run &#8211; it&#8217;s not commented out because the first line is following the rules of the single-line comment &#8211; ignoring the block comment declaration on the same line. By removing the first backslash at the beginning of the block, we can comment out the entire code block by enabling the block comment style instead of the single-line style. The last single-comment line is ignored because the block comment rules ignore everything up until the end block comment declaration at the end of the line:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* My code below
$someVar = array(&quot;foo&quot;, &quot;bar&quot;, &quot;blah&quot;);
echo &quot;&lt;code&gt;&quot;;
print_r($someVar);
echo &quot;&lt;/code&gt;&quot;;
// */</span></pre></td></tr></table></div>

<p>So a single character &#8211; a backslash at the very beginning of the block declaration can now comment or un-comment the entire block by switching the comment rules back and forth between single-line and block style. The code examples provided are in PHP, but this trick will work with any language that supports both single-line and block style comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/the-one-character-block-comment/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Get the Most From Your Google Analytics Dashboard</title>
		<link>http://www.vancelucas.com/blog/get-the-most-from-your-google-analytics-dashboard/</link>
		<comments>http://www.vancelucas.com/blog/get-the-most-from-your-google-analytics-dashboard/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 18:05:34 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[stats]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=250</guid>
		<description><![CDATA[I&#8217;m a big fan of Google Analytics.  The service is free, can go on multiple websites using just one account, and displays and processes stats beautifully.  But the one thing that&#8217;s always annoyed me about Google Analytics is the default dashboard setup when you create a new website profile. The dashboard is the place for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="https://www.google.com/analytics/"><img class="alignright size-full wp-image-256" title="Google Analytics Logo" src="http://www.vancelucas.com/wp-content/uploads/2008/11/main_logo.gif" alt="" width="182" height="35" /></a>I&#8217;m a big fan of <a href="https://www.google.com/analytics/">Google Analytics</a>.  The service is free, can go on multiple websites using just one account, and displays and processes stats beautifully.  But the one thing that&#8217;s always annoyed me about Google Analytics is the default dashboard setup when you create a new website profile.</p>
<p>The dashboard is the place for the <em>most important</em> things to be.  it should be the single place you can view to and get an overview of all the most important things about your website regarding your visitors without having to drill deeper or go through multiple pages or sub-sections.  But the default dashboard Analytics starts you off with is all wrong, and is almost never the information I really want to see.  Let&#8217;s see how we can fix this.<span id="more-250"></span></p>
<h3>The Default Dashboard</h3>
<div id="attachment_251" class="wp-caption alignnone" style="width: 510px"><a href="http://www.vancelucas.com/wp-content/uploads/2008/11/google-analyics-before.jpg"><img class="size-full wp-image-251" title="Google Analytics Default Dashboard Setup" src="http://www.vancelucas.com/wp-content/uploads/2008/11/google-analyics-before.jpg" alt="Google Analyics Default Dashboard Setup" width="500" height="403" /></a><p class="wp-caption-text">Google Analytics Default Dashboard Setup</p></div>
<p>The first thing to note here is the repetitive information.  The &#8220;Visitors Overview&#8221; widget is the first thing you want to get rid of.  The exact same information is displayed larger above &#8211; no use in repeating the same information twice in the same screen area.  To the right of that is the &#8220;Map Overlay&#8221; widget.  While this information may be neat to see, it&#8217;s not really the real information you need day to day.  That one&#8217;s leaving our dashboard too.  So that leaves the two bottom widgets &#8211; &#8220;Traffic Sources Overview&#8221; and &#8220;Content Overview&#8221;.  These both can stay, but perhaps can be arranged a bit differently.</p>
<h3>The Information You Need</h3>
<p>For most webmasters, there are essentially two important questions: &#8220;<em>How are visitors getting to my website?</em>&#8221; and &#8220;<em>What are visitors doing on my website?</em>&#8220;.  The widgets we select for our dashboard must help us quickly answer those every day questions without having to drill any deeper or take any more of our time.  We also need only the information that isn&#8217;t already present on the dashboard that we can&#8217;t edit.</p>
<h3>A More Useful Dashboard</h3>
<div id="attachment_253" class="wp-caption alignnone" style="width: 510px"><a href="http://www.vancelucas.com/wp-content/uploads/2008/11/google-analyics-after.jpg"><img class="size-full wp-image-253" title="Google Analytics Customized Dashboard" src="http://www.vancelucas.com/wp-content/uploads/2008/11/google-analyics-after.jpg" alt="Google Analytics Customized Dashboard" width="500" height="400" /></a><p class="wp-caption-text">Google Analytics Customized Dashboard</p></div>
<p>With a customized dashboard, we can now have the information we <em>really</em> need on a daily basis that help us answer our every day questions:</p>
<p><strong>How are visitors getting to my website?</strong><br />
I can clearly see here that the dominant source is Google searches, followed by direct type-ins and the typo domain that redirects to the real site.  I can also see the top search keywords that visitors used to reach my website, which is very useful for measuring <a href="http://en.wikipedia.org/wiki/Search_engine_optimization">SEO</a> effectiveness.</p>
<p>Another dashboard widget I like to have to help answer this question is the &#8220;Referring Sites&#8221; widget.  This tells me the actual websites referring visitors to me through links.  This is especially helpful if the site gets mentioned in a blog post or article so you can know about it quickly.</p>
<p>If you run any Google Adwords campaigns, there is also an Adwords section and a dashboard widget for campaign clickthroughs and conversions that may be helpful.</p>
<p><strong>What are visitors doing on my website?<br />
</strong>This question may take a bit more analysis to answer because there are many parts to this.  The &#8220;Content Overview&#8221; widget helps us spot the most popular pages and areas of the website, which helps us solve most of this question.</p>
<p>Taking the analysis further, you may want to <a href="http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&amp;answer=55515">setup conversion goals</a> and add a dashboard widget to display the number of daily goal conversions.  You can also add widgets for the entrance and exit pages, among many other things.</p>
<h3>Conclusion</h3>
<p>Most of the time for most of my websites, I have only the widgets above shown on the customized dashboard image above.  The great thing about Google Analytics is that it can be customized with any widgets you want to display.  So although the default widgets are not particularly useful on a day to day basis, they can easily be replaced with widgets containing information that is useful.</p>
<p>One more final thing about Google Anlytics is that the date range can be customized as well.  In the screenshots above, stats for the whole month are displayed.  If you have a larger website, you may want to customize the date range to a week or even a single day to get a better understanding of what&#8217;s going on most recently.  The drawback of course, as anyone that uses Google Analytics knows, is that the stats aren&#8217;t live or real-time.  There is a 24-hour delay because all the stats are compiled and processed at the end of each day.  I&#8217;m not going to complain about it because the product is free, but just remember that if you do choose to view a single day, you will have to select the previous day instead of the current one.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/get-the-most-from-your-google-analytics-dashboard/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Fixing IE7 Z-Index Issues with jQuery</title>
		<link>http://www.vancelucas.com/blog/fixing-ie7-z-index-issues-with-jquery/</link>
		<comments>http://www.vancelucas.com/blog/fixing-ie7-z-index-issues-with-jquery/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 23:45:43 +0000</pubDate>
		<dc:creator>Vance Lucas</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.vancelucas.com/?p=21</guid>
		<description><![CDATA[For some reason, Internet Explorer 7 does some pretty funky things, and has several known bugs with it&#8217;s rendering engine that drive web developers like me crazy.  While most of the known bugs occur in relatively obscure situations and go largely unnoticed, there are a few that really stick out and cause web developers to [...]]]></description>
			<content:encoded><![CDATA[<p>For some reason, Internet Explorer 7 does some pretty funky things, and has <a href="http://www.quirksmode.org/bugreports/archives/explorer_7/index.html">several known bugs</a> with it&#8217;s rendering engine that drive web developers like me crazy.  While most of the known bugs occur in relatively obscure situations and go largely unnoticed, there are a few that really stick out and cause web developers to waste many hours trying to fix them.  The way IE7 renders z-index stacking orders is one of them.</p>
<p>One way to fix many of the issues with IE7 is to dynamically reverse the default z-index stacking order of the elements on your page. This will ensure the elements higher in your HTML source will also have a higher z-index order on your page, solving most of the IE stacking issues.<span id="more-21"></span> If you&#8217;re using <a href="http://jquery.com">jQuery</a> (the best Javascript library there is), here&#8217;s the quick fix:</p>
<p><code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> zIndexNumber <span style="color: #339933;">=</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'zIndex'</span><span style="color: #339933;">,</span> zIndexNumber<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		zIndexNumber <span style="color: #339933;">-=</span> <span style="color: #CC0000;">10</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;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p></code></p>
<p>This code will start with a z-index of 1000, and decrement the z-index for each DIV element of the page by 10, giving the first DIV a z-index of 1000, the second, 990, the third 980, and so on. Notice that the selector will find all DIV elements with the code &#8220;$(&#8216;div&#8217;)&#8221;, using the same syntax as CSS selectors.  If your HTML code has different requirements, feel free to change the code or the selector to suit your needs by following jQuery&#8217;s <a href="http://docs.jquery.com/Selectors">documentation on selectors</a>.</p>
<h3>Update for MooTools (04/14/2009):</h3>
<p><a href="http://www.liamsmart.co.uk/">A generous commenter</a> has posted the code for fixing z-index issues with <a href="http://mootools.net/">MooTools</a> 1.2:</p>
<p><code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>Browser.<span style="color: #660066;">Engine</span>.<span style="color: #660066;">trident</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> zIndexNumber <span style="color: #339933;">=</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span>
	$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</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>el<span style="color: #339933;">,</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		el.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'z-index'</span><span style="color: #339933;">,</span>zIndexNumber<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		zIndexNumber <span style="color: #339933;">-=</span> <span style="color: #CC0000;">10</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: #339933;">;</span></pre></td></tr></table></div>

<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vancelucas.com/blog/fixing-ie7-z-index-issues-with-jquery/feed/</wfw:commentRss>
		<slash:comments>75</slash:comments>
		</item>
	</channel>
</rss>

