<?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>Helephant.com</title>
	<atom:link href="http://helephant.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://helephant.com</link>
	<description></description>
	<lastBuildDate>Sun, 03 Aug 2014 12:17:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.15</generator>
	<item>
		<title>Visual Studio and Resharper .gitignore file</title>
		<link>http://helephant.com/2013/04/16/visual-studio-and-resharper-gitignore-file/</link>
		<comments>http://helephant.com/2013/04/16/visual-studio-and-resharper-gitignore-file/#comments</comments>
		<pubDate>Tue, 16 Apr 2013 12:58:22 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Source control]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2938</guid>
		<description><![CDATA[My .gitignore file for C# Resharper, Visual Studio projects. It lists any files that should not get added to the repository.
]]></description>
				<content:encoded><![CDATA[<p>This is my <a href="http://git-scm.com/docs/gitignore">.gitignore</a> file for C# Visual Studio projects which use the Resharper plugin. It will also work perfectly fine for projects that don&#8217;t use Resharper. </p>
<p>The .gitignore file tells git which files should not be committed to the repository when you add a directory. It is useful for files that get generated by the build, your tools or the IDE. It&#8217;s also great for per-user configuration that shouldn&#8217;t get checked in. </p>
<pre class="command-line">
# visual studio
obj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
*.sln.cache
*.suo
*.user
*.vspscc
*.vssscc
*.cache
*.bak
*.log
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# tools
_ReSharper.*
*.resharper.user
_TeamCity*

# operating system
thumbs.db
*.DS_Store
Desktop.ini
</pre>
<p>Github host a heap of <a href="https://github.com/github/gitignore/blob/master/VisualStudio.gitignore">.gitignore files</a> for different types of projects including one for <a href="https://github.com/github/gitignore/blob/master/VisualStudio.gitignore">Visual Studio</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2013/04/16/visual-studio-and-resharper-gitignore-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git command cheat sheet</title>
		<link>http://helephant.com/2013/04/14/git-command-cheat-sheet/</link>
		<comments>http://helephant.com/2013/04/14/git-command-cheat-sheet/#comments</comments>
		<pubDate>Sun, 14 Apr 2013 12:49:48 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Source control]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2902</guid>
		<description><![CDATA[A git source control cheat sheet with the basic commands I need to be productive. ]]></description>
				<content:encoded><![CDATA[<p><img src="http://helephant.com/wp-content/uploads/2013/04/gitlogo.svg" class="alignright">Git is the perfect source control for my home projects. It is free, works on mac, linux and windows, makes it easy to share code through <a href="https://github.com/helephant">github</a> and takes me out of my Microsoft technology comfort zone. </p>
<p>Unfortunately I have used it so sporadically that it&#8217;s been hard for me to make the basic git commands automatic! Here are the basic commands I need to be productive. </p>
<h2>Basics</h2>
<p>Adding all changed files in the current directory to the commit:</p>
<pre class="command-line">
git add .
</pre>
<p>Adding any deleted files in the current directory to the commit:</p>
<pre class="command-line">
git add -u .
</pre>
<p>Seeing which files are waiting to be committed:</p>
<pre class="command-line">
git status
</pre>
<p>Committing the currently staged files to a repository:</p>
<pre class="command-line">
git commit -m "a very well explained commit message"
</pre>
<p>Pushing my changes to another repository:</p>
<pre class="command-line">
git push origin master
</pre>
<p>Get changes from another repository and apply on top of the existing changes:</p>
<pre class="command-line">
git pull origin master
</pre>
<p>Get changes from another repository, but rewind history, apply the changes and then apply the new changes on top. This makes the history more straight forward: </p>
<pre class="command-line">
git pull --rebase origin master
</pre>
<h2>Setting up a new repository</h2>
<p>Creating a new repository in the current directory:</p>
<pre class="command-line">
git init .
</pre>
<h2>Working with remote repositories</h2>
<p>Adding a new remote repository:</p>
<pre class="command-line">
git remote add origin git@github.com:helephant/SeriesLink.git
</pre>
<p>Seeing a list of all remote repositories:</p>
<pre class="command-line">
git remote -v
</pre>
<p>Updating the URL for a remote repository:</p>
<pre class="command-line">
git remote set-url origin git@github.com:helephant/SeriesLink.git
</pre>
<p>Cloning an existing repository:</p>
<pre class="command-line">
git clone git@github.com:helephant/SeriesLink.git
</pre>
<h2>Committing files</h2>
<p>Discard current changes &#8211; rollback the file in the working directory to the latest committed version:</p>
<pre class="command-line">
git checkout myfile.cs
</pre>
<p>Unstage changes &#8211; keep the changes in the working directory, but roll the version of the file in the staging index back to the last committed version: </p>
<pre class="command-line">
git reset HEAD myfile.cs
</pre>
<p>Commit all changed files &#8211; does the add and commit in a single step. Will only commit files that are already in the repository. New, untracked files will not be commited:</p>
<pre class="command-line">
git commit --all -m "a very well explained commit message"
</pre>
<p>Ammending the last commit (because you&#8217;ve forgotten files or messed up the commit message):</p>
<pre class="command-line">
git commit --ammend
</pre>
<p>Seeing differences between your working directory and the staging index:</p>
<pre class="command-line">
git diff -w
</pre>
<p>Seeing differences between your working directory and the last commit:</p>
<pre class="command-line">
git diff -w HEAD
</pre>
<h2>History</h2>
<p>Viewing the history of a file:</p>
<pre class="command-line">
git log src/series-link.php
</pre>
<p>View the complete history of a file that has been renamed:</p>
<pre class="command-line">
git log --follow src/series-link.php
</pre>
<p>View the summary of the last 3 commits: </p>
<pre class="command-line">
git log -n 3 --format=oneline HEAD
</pre>
<p>Search through the history of a file for a term:</p>
<pre class="command-line">
git log -S command-line --format=oneline style.css
</pre>
<p>Search through versions of a file for changes that involve the search term: </p>
<pre class="command-line">
git diff -S "latest-post" master~2 master~4 style.css
</pre>
<p>Viewing more details about the last commit:</p>
<pre class="command-line">
git show
</pre>
<p>Viewing more details about a particular commit:</p>
<pre class="command-line">
git show 9d35508c249f1e7060c54165fe0767c01f598359
</pre>
<p>Seeing differences between two commits for a file:</p>
<pre class="command-line">
git diff afb13de89c3 eb72e0b5182  -- style.css
</pre>
<h2>Rolling back a file</h2>
<p>Rolling back a file to the last commited version (just replaces the file with the last commited version).</p>
<pre class="command-line">
git checkout myfile.cs
</pre>
<p>Unstage changes &#8211; keep the changes in the working directory, but roll the version of the file in the staging index back to the last committed version: </p>
<pre class="command-line">
git reset HEAD myfile.cs
</pre>
<h2>Branching</h2>
<p>Create a new branch from the latest commit:</p>
<pre class="command-line">
git branch new-feature-prototype
</pre>
<p>Create a new branch and switch to it straight away:</p>
<pre class="command-line">
git checkout -b new-feature-prototype
</pre>
<p>List all branches:</p>
<pre class="command-line">
git branch
</pre>
<p>Switch between branches:</p>
<pre class="command-line">
git checkout new-feature-prototype
</pre>
<p>Switch between branches and merge any pending changes in your working directory:</p>
<pre class="command-line">
git checkout -m new-feature-prototype
</pre>
<p>View a file in another branch:</p>
<pre class="command-line">
git show master:style.css
</pre>
<p>Delete a branch that you&#8217;re finished with:</p>
<pre class="command-line">
git branch -d  new-feature-prototype
</pre>
<h2>Merging</h2>
<p>Merging changes from a branch into the current branch:</p>
<pre class="command-line">
git merge -m new-feature-prototype
</pre>
<p>Generate a commit graph to graphically see branch history: </p>
<pre class="command-line">
 git log --graph --format=oneline --abbrev-commit
</pre>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2013/04/14/git-command-cheat-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS3 flexbox examples</title>
		<link>http://helephant.com/2013/03/29/css3-flexbox-examples/</link>
		<comments>http://helephant.com/2013/03/29/css3-flexbox-examples/#comments</comments>
		<pubDate>Fri, 29 Mar 2013 22:15:52 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2802</guid>
		<description><![CDATA[Here are some examples of common layouts that can be easily created using flexbox, a future way to layout HTML elements in CSS3. ]]></description>
				<content:encoded><![CDATA[<p><a href="http://helephant.com/2013/03/23/css3-flexbox-layout/">Flexbox layout</a> is a new way of laying out items in CSS3 where items are laid out in a direction, flexing to take up the available space. It is designed to make stretchy, flexible layouts simple. Quite complex layouts can be built up by nesting flexbox containers. </p>
<p>For more information on how flexbox works, check out <a href="http://helephant.com/2013/03/23/css3-flexbox-layout/">using the CSS3 flexbox layout</a>. </p>
<p>CSS has always been pretty great for applying formatting styles like backgrounds, fonts, colours and borders to HTML elements. I think it&#8217;s been pretty weak at putting all of these items together in a page layout, forcing front end developers to create fragile code based mostly on clever floating tricks.</p>
<p>I think when flexbox is available cross browser, it is going to revolutionise the way we do CSS layout because it is simpler and more robust than similar layouts built on floats. It also makes it easy to do things that are pretty much impossible with current CSS like aligning boxes horizontally and vertically without knowing the exact proportions of the entire layout ahead of time. </p>
<p>The best thing is that it&#8217;s not the only new option for doing page layout in CSS. Other tools like the CSS grid layout module will work better for some types of layouts, giving front end developers lots of new options for creating pages. </p>
<p>Here are some simple examples of reasons to demonstrate why web developers should be excited by flexbox. </p>
<h2 id="three-column-layout">Creating a three column layout</h2>
<p>Flexbox will make common layouts like the three column layout really simple to implement. </p>
<p>Here&#8217;s an example where the content div is 60% wide and the navigation divs use the flex property to be sized according the space left in the container:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;div class=&quot;container&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;nav class=&quot;nav left&quot;&gt;&#8230;&lt;/nav&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;section class=&quot;main&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;/section&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;nav class=&quot;nav right&quot;&gt;&#8230;&lt;/nav&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
</ol>
</div>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re1">.container</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">display</span><span class="sy0">:</span> flex<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex-flow<span class="sy0">:</span> row<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">.main</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3"><span class="nu0">60</span>%</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">.left</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex<span class="sy0">:</span> <span class="nu0">1</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">.right</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex<span class="sy0">:</span> <span class="nu0">2</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><img src="http://helephant.com/wp-content/uploads/2013/03/three-column-layout.png"></p>
<p>See the <a href="http://helephant.com/wp-content/uploads/2013/03/three-column-layout.html">complete example</a>.</p>
<h2 id="multi-line">Laying out a form with multi-line flex containers</h2>
<p>Flexbox supports wrapping flex items onto multiple lines. This can be switched on by adding &#8220;wrap&#8221; to the flex-flow property. Flex items that do not fit in the remaining space of the flex container will then be wrapped to the next line inside the container. </p>
<p>You could use a multi-line flexbox to lay out a really simple form:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;form&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;label for=&quot;name&quot;&gt;Name:&lt;/label&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;input id=&quot;name&quot; type=&quot;text&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;label for=&quot;email&quot;&gt;Email:&lt;/label&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;input id=&quot;email&quot; type=&quot;email&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &#8230;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/form&gt;</div>
</li>
</ol>
</div>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1">form<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">display</span><span class="sy0">:</span> flex<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex-flow<span class="sy0">:</span> row wrap<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">408px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">label <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">display</span><span class="sy0">:</span> <span class="kw2">block</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">150px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">input, textarea <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">250px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">margin-bottom</span><span class="sy0">:</span> <span class="re3">7px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><img src="http://helephant.com/wp-content/uploads/2013/03/form.png" alt="using flexbox to layout a form over multiple lines"></p>
<p>See <a href="http://helephant.com/wp-content/uploads/2013/03/form.html">complete example</a>.</p>
<h2 id="nested-containers">Displaying a results grid with nested flex containers</h2>
<p>It&#8217;s possible to nest flex containers to create fairly sophisticated grid layouts. </p>
<p>It&#8217;s quite difficult to create a grid of boxes using CSS2.1 if the size of the content isn&#8217;t known ahead of time because some boxes might end up taller than others. One way to do it is to set a max-height that&#8217;s big enough to accomodate all items, which ends up looking slightly strange if none of the items in the row have overly tall content. </p>
<p>Flexbox layouts solve this problem for you. The height of the lines can be automatically worked out based on the content in the boxes if you don&#8217;t set an explicit height on the flex container or flex items. </p>
<p>Here&#8217;s an example of a grid of search results. The outer container has a row flex-flow and the inner containers have a column flow. The height of the flex containers is worked out based on size of the content:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;div class=&quot;latest-items&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;div class=&quot;latest-item&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;img src=&quot;img/news.jpg&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;h2&gt;Article title&lt;/h2&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;div class=&quot;summary&quot;&gt;&#8230;&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;div class=&quot;latest-item&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;img src=&quot;img/logo.png&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;h2&gt;Article title&lt;/h2&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;div class=&quot;summary&quot;&gt;&#8230;&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &#8230;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
</ol>
</div>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re1">.latest-items</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">display</span><span class="sy0">:</span> flex<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex-flow<span class="sy0">:</span> row wrap<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">650px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">.latest-item</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">display</span><span class="sy0">:</span> flex<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex-flow<span class="sy0">:</span> column<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">padding</span><span class="sy0">:</span> <span class="re3">14px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">255px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><img src="http://helephant.com/wp-content/uploads/2013/03/latest-items-alignment.png" alt="the nested flex containers automatically line up in a grid" /></p>
<p>See <a href="http://helephant.com/wp-content/uploads/2013/03/latest-items.html">complete example</a>.</p>
<h2 id="flex-box-alignment">Centering an element on the page</h2>
<p>Flexbox layout has alignment options that give a lot of control over how flex items are positioned in the flex container. </p>
<p>These can be used to do horizontal and vertical positioning that isn&#8217;t possible with CSS2.1. For example, you could use the <a href="https://developer.mozilla.org/en-US/docs/CSS/justify-content">justify-content</a> and <a href="https://developer.mozilla.org/en-US/docs/CSS/align-content">align-content</a> properties to center a single item in the middle of the page:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;body&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;div class=&quot;content&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;p&gt;It is extremely difficult&#8230;&lt;/p&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/body&gt;</div>
</li>
</ol>
</div>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1">body <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">display</span><span class="sy0">:</span> flex<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex-flow<span class="sy0">:</span> column<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; align-items<span class="sy0">:</span> <span class="kw2">center</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; justify-<span class="kw1">content</span><span class="sy0">:</span> <span class="kw2">center</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3"><span class="nu0">100</span>%</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3"><span class="nu0">100</span>%</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">.content</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">display</span><span class="sy0">:</span> flex<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex-flow<span class="sy0">:</span> column<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; justify-<span class="kw1">content</span><span class="sy0">:</span> <span class="kw2">center</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">text-align</span><span class="sy0">:</span> <span class="kw2">center</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">250px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">250px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><img src="http://helephant.com/wp-content/uploads/2013/03/vertical-centering.png" alt="justify-content and align-items can be used to do vertical and horizontal box alignment not possible in CSS2.1" /></p>
<p>See <a href="http://helephant.com/wp-content/uploads/2013/03/vertical-centering.html">complete example</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2013/03/29/css3-flexbox-examples/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using the CSS3 flexbox layout</title>
		<link>http://helephant.com/2013/03/23/css3-flexbox-layout/</link>
		<comments>http://helephant.com/2013/03/23/css3-flexbox-layout/#comments</comments>
		<pubDate>Sat, 23 Mar 2013 22:14:10 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2669</guid>
		<description><![CDATA[The CSS flexbox is a future CSS3 layout module that aims to make CSS page layout much simpler.  It makes it easy to create flexible, stretchy layouts.]]></description>
				<content:encoded><![CDATA[<p>The <a href="http://www.w3.org/TR/css3-flexbox/">flexbox layout</a> is a new CSS3 module for page layout. It can lay out items in a direction (left-to-right or top-to-bottom) with the items stretching to take up the available space. Quite complicated layouts can be built up by nesting flex containers.</p>
<p>Flexbox makes it simple to create stretchy layouts that can be dropped into a space and be easily resized when the layout is displayed on a smaller screen.  It is designed to make common layout patterns like the three column layout very simple to implement. </p>
<p>Take a look at some <a href="http://helephant.com/2013/03/29/css3-flexbox-examples/">examples</a> of the kind of things flexbox is good at. </p>
<h2>Flex containers and flex items</h2>
<p>A flexbox layout is made up of a flex container and flex items inside the container. </p>
<p>A flex container is a HTML element with its <code>display</code> property set to <code>flex</code>. Any item inside a flex container is automatically a flex item.</p>
<p>Here&#8217;s an example of a three column layout. The outer container div is the flex container and the left, main and right divs are flex items:<br />
<img src="http://helephant.com/wp-content/uploads/2013/03/flex-container-and-items.png" alt="the container div is a flex container and the left, main and right divs are flex items" /></p>
<p>The code for setting up a really simple flex container with no items would look like this:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;div class=&quot;container&quot;&gt;&lt;/div&gt;</div>
</li>
</ol>
</div>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re1">.container</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">display</span><span class="sy0">:</span> flex<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<h2>Flex-flow</h2>
<p>Flex containers have a <code>flex-flow</code> CSS property which determines how the flex items will be laid out. A flex container with flex-flow set to row will be laid out from left to right:<br />
<img src="http://helephant.com/wp-content/uploads/2013/03/flex-flow-row.png" alt="flex-flow: row makes the contents go from left to right" /></p>
<p>One with flex-flow set to column will be laid out from top to bottom:<br />
<img src="http://helephant.com/wp-content/uploads/2013/03/flex-flow-column.png" alt="flex-flow: column makes the contents go from top to bottom" /></p>
<p>Here&#8217;s how you&#8217;d set the flex container to lay out its flex items in a row:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re1">.container</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">display</span><span class="sy0">:</span> flex<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex-flow<span class="sy0">:</span> row<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>A flex container can either have all of its items on a single line or it can support multiple lines. This is determined by whether the <code>flex-flow</code> is told to wrap or not. If the container supports wrap, an item which does not fit on the current line will be wrapped to the next line:<br />
<img src="http://helephant.com/wp-content/uploads/2013/03/multiple-line-wrap.png" alt="multiple line wrapping"></p>
<p>Here&#8217;s how we&#8217;d make the flex container wrap:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re1">.container</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">display</span><span class="sy0">:</span> flex<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex-flow<span class="sy0">:</span> row wrap<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<h2>Flex items</h2>
<p>The elements inside the flex containers are automatically turned into flex items. No extra CSS configuration is needed. The only thing you will need to do is set their dimensions. </p>
<p>If the flex container has its flex-flow set to row, the flex items will need to have their width set. Their height will automatically be set to the height of the flex container:<br />
<img src="http://helephant.com/wp-content/uploads/2013/03/flex-flow-dimensions-row.png"></p>
<p>If the flex container has its flex-flow set to column, the flex items will need to have their height set. Their width will be automatically set to the width of the flex container:<br />
<img src="http://helephant.com/wp-content/uploads/2013/03/flex-flow-dimensions-column.png"></p>
<p>Use the width or height property to give your flex item a size that is independent of the other flex items. For example if we give the content div a width of 600px, it will be 600px wide no matter if there is one, two or a hundred other flex items in the container.</p>
<p>Use the flex property if you want your flex items to be sized according to the space left in the flex container. For example we can tell the browser that the left and right columns should take up any remaining space in the flex container after the content element has been sized. </p>
<p>The value of the flex property is proportional. If the left navigation is set to one and right navigation is set to two, the remaining space should be divided up so the right column is twice as wide as the left:<br />
<img src="http://helephant.com/wp-content/uploads/2013/03/flex-item-width.png"></p>
<p>Here&#8217;s some sample CSS to set widths on some flex items that use a mixture of independent and proportional widths:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re1">.main</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">600px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">.left</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex<span class="sy0">:</span> <span class="nu0">1</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">.right</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex<span class="sy0">:</span> <span class="nu0">2</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<h2>Complete example</h2>
<p>Here&#8217;s a really simple flexbox example that creates a classic three column page layout. The content div is 60% wide and the navigation divs use the flex property to be sized according the space left in the container:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;div class=&quot;container&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;nav class=&quot;nav left&quot;&gt;&#8230;&lt;/nav&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;section class=&quot;main&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;/section&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;nav class=&quot;nav right&quot;&gt;&#8230;&lt;/nav&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
</ol>
</div>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re1">.container</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">display</span><span class="sy0">:</span> flex<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex-flow<span class="sy0">:</span> row<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">.main</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3"><span class="nu0">60</span>%</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">.left</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex<span class="sy0">:</span> <span class="nu0">1</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">.right</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; flex<span class="sy0">:</span> <span class="nu0">2</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><img src="http://helephant.com/wp-content/uploads/2013/03/three-column-layout.png"></p>
<p>See the <a href="http://helephant.com/wp-content/uploads/2013/03/three-column-layout.html">complete example</a>.</p>
<h2>Browser support</h2>
<p>At time of writing, in 2012, <a href="http://caniuse.com/#feat=flexbox">browser support</a> for the finalized (<a href="http://css-tricks.com/old-flexbox-and-new-flexbox/">or maybe just latest</a>) syntax is not very good. These examples work in Opera and webkit (because I included the prefixes). </p>
<p>I haven&#8217;t included browser specific prefixes in my in-article examples to make them easier to understand. For the widest browser support in March 2013, you&#8217;ll need prefixes targetting for webkit and IE. You might also want to consider adding support for <a href="http://css-tricks.com/using-flexbox/">earlier version of the syntaxes</a>. I personally think it&#8217;s better to hold off using flexbox until the final syntax gets wide enough support. </p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2013/03/23/css3-flexbox-layout/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using CSS3 multi-column layouts to split a list into columns</title>
		<link>http://helephant.com/2013/03/17/using-css3-multi-column-layouts-to-split-a-list-into-columns/</link>
		<comments>http://helephant.com/2013/03/17/using-css3-multi-column-layouts-to-split-a-list-into-columns/#comments</comments>
		<pubDate>Sat, 16 Mar 2013 23:17:16 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2643</guid>
		<description><![CDATA[How to use the new CSS multi-column layout feature to split a list across multiple columns. ]]></description>
				<content:encoded><![CDATA[<p>At least once a year I&#8217;m given a design mock that contains a list that has been split into columns. I&#8217;ve always wondered if it&#8217;s possible to do it using the <a href="https://developer.mozilla.org/en-US/docs/CSS/Using_CSS_multi-column_layouts">CSS3 column layout module</a> and it turns out that it&#8217;s easy! Just use the column-count CSS property on the &lt;ul&gt; to specify how many columns you want and the browser does it all for you:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;ul style=&quot;column-count: 5;&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;li&gt;item 1&lt;/li&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;..
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;li&gt;item 100&lt;/li&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/ul&gt;</div>
</li>
</ol>
</div>
<p>If you&#8217;re more worried about the width of the columns, you can specify a minimum column-width instead and the browser will work out how many columns it should display:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;ul style=&quot;column-width: 250px;&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;li&gt;item 1&lt;/li&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;..
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;li&gt;item 100&lt;/li&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/ul&gt;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2013/03/css3-columns.html">See example</a>.</p>
<h2>Why&#8217;s this exciting?</h2>
<p>Once the browser support is there, this will be much simpler and less fragile than using methods like floats. This is telling the browser what you want, rather than how to do it. There won&#8217;t be issues with items of different heights getting caught on the bottom of longer elements. There will be no overflow issues. It won&#8217;t affect the flow of the rest of the document. </p>
<p>Controlling this purely through style makes responsive design easy, just set up different column rules for different displays or use the column-width to let the browser make the decision itself. </p>
<p>You also end up with an element that will easily go into any space of the structure of the page. This is great even if you&#8217;re not interested in responsive design because it makes it easy to tweak the structure without having to change the elements that contain the contents inside. </p>
<h2>Browser support</h2>
<p><a href="http://caniuse.com/#feat=multicolumn">Browser support</a> is good in the latest version of all browsers but still (in March 2012) prefixed. It&#8217;s only supported in IE10+. Backwards compatibility is good, if you don&#8217;t mind falling back to the content rendered without the columns. There is at least one <a href="http://www.csscripting.com/css-multi-column/">polyfill</a>.</p>
<p>Right now there are some issues with bullets. I noticed in Chrome, the &lt;li&gt; <a href="https://bugs.webkit.org/show_bug.cgi?id=23053">loses its bullet</a> when you split the &lt;ul&gt; across multiple columns. IE10 shows bullets only in the first column.</p>
<p>You can work around this by moving the bullet inside the li using <code><a href="https://developer.mozilla.org/en-US/docs/CSS/list-style-position">list-style-position</a>: inside</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2013/03/17/using-css3-multi-column-layouts-to-split-a-list-into-columns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Are you a developer who likes to learn new things?</title>
		<link>http://helephant.com/2012/08/31/are-you-a-developer-who-likes-to-learn-new-things/</link>
		<comments>http://helephant.com/2012/08/31/are-you-a-developer-who-likes-to-learn-new-things/#comments</comments>
		<pubDate>Fri, 31 Aug 2012 15:37:06 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2616</guid>
		<description><![CDATA[Totaljobs is hiring .NET developers and senior .NET developers. Central London. Agile teams. C#, TDD, MVC, twice weekly releases.]]></description>
				<content:encoded><![CDATA[<p>Totaljobs (the company where I work) are looking for .NET developers and senior .NET developers. If you&#8217;re interested or know someone who might be, please <a href="mailto:helen@helephant.com">let me know</a> and I can pass on a CV (and any github account, stackoverflow account or technical blog..) or you can apply online through our website for the <a href="http://www.totaljobs.com/JobSearch/JobDetails.aspx?JobId=54335699">developer</a> or <a href="http://www.totaljobs.com/JobSearch/JobDetails.aspx?JobId=54225870">senior developer</a> role. </p>
<h2>Who are we?</h2>
<p>Totaljobs is based in central London and runs seven online job boards which between them carry over 200,000 jobs, and attract over 5 million jobseekers every month. </p>
<h2>Who we are looking for?</h2>
<p>We are looking for smart people who can learn quickly and have a drive to get things done. You should care about writing quality code and solving problems, and be always trying to get a little bit better at what you do. You don&#8217;t need to have experience in every technology we use, this is a great opportunity to learn new things and to grow your career. Totaljobs is a place where good people are recognised and promoted.</p>
<h2>Technology we use</h2>
<p>All new projects use the ASP.NET MVC framework and are test driven. </p>
<p>Our technology stack is constantly evolving but these are some of the technologies you would be working with:</p>
<ul>
<li>NHibernate and structure map</li>
<li>NUnit, Web driver and Moq</li>
<li>TFS, MSBuild and NuGet</li>
<li>JQuery, Web fonts, responsive CSS and SASS</li>
<li>MSMQ, windows services, 3rd party APIs</li>
<li>RhinoETL</li>
<li>SQL Server 2012, spatial searching, peer to peer replication, data cube analysis</li>
<li>AWS, IIS7.5 in a load balanced environment</li>
</ul>
<p>We are constantly trying to be better at what we do. This year&#8217;s goal has been to move from a large jobseeker site codebase to small, self contained projects that are easy to work on independently and quick to build, test and deploy. </p>
<h2>We practice agile development</h2>
<p>We have found scrum works really well for us and have six teams that use a mixture of scrum and kanban, depending on what works best for the team. Each team is encouraged to adapt their process, so they each have their own unique personality. </p>
<p>All developers are as cross functional as possible and work on everything from CSS down to the database. Teams constantly work on different parts of the codebase rather than own particular areas of functionality, so each project is an opportunity to learn new things. </p>
<p>We follow XP practices such as user stories, pair programming, continuous integration and TDD. Our releases, testing and test environments are automated so we can release often. There is a big focus on breaking projects up iteratively and getting value out to customers as soon as possible. </p>
<h2>Perks</h2>
<p>Work with people who are passionate about development. Our office is filled with books about technology and people who enjoy coding so much they will do it outside of office hours. There is no shortage of people to have interesting technical discussions with or to ask for help if you need it. We have regular brown bag sessions where team members do a presentation about something that they&#8217;re passionate about. </p>
<p>The office has a relaxed atmosphere and a nice, social feel. Teams regularly go for team lunches and we have Friday afternoon office drinks. We have a casual dress code and lots of great office toys. </p>
<h2>Sound interesting?</h2>
<p>If you&#8217;d like more information, feel free to <a href="mailto:helen@helephant.com">email me</a> and I can answer any questions you have. If this sounds like the kind of place you&#8217;d like to work, please send me your CV (and any github account, stackoverflow account or technical blog..) or go apply on our website for the <a href="http://www.totaljobs.com/JobSearch/JobDetails.aspx?JobId=54335699">developer</a> or <a href="http://www.totaljobs.com/JobSearch/JobDetails.aspx?JobId=54225870">senior developer</a> role. </p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2012/08/31/are-you-a-developer-who-likes-to-learn-new-things/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web debugging on windows</title>
		<link>http://helephant.com/2012/07/24/web-debugging-on-windows/</link>
		<comments>http://helephant.com/2012/07/24/web-debugging-on-windows/#comments</comments>
		<pubDate>Tue, 24 Jul 2012 11:00:45 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[IIS7]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[iis7]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2588</guid>
		<description><![CDATA[some tools and techniques that make it much easier to debug what your wayward application is doing. ]]></description>
				<content:encoded><![CDATA[<p><img src="http://helephant.com/wp-content/uploads/2012/07/bugs-ants-300x234.jpg" alt="" title="bugs-ants" width="300" height="234" class="alignright" /> Web development has come a long way since the days when Response.Write() and alert() were the only ways to find out why your application was misbehaving. Here are some of my favourite tools and techniques for understanding what&#8217;s really going on. </p>
<h2>Debugging inside IIS</h2>
<p><a href="/2012/07/18/debugging-the-iis7-integrated-pipeline-with-failed-request-tracing/">Failed request tracing</a> &#8211; a handy IIS7 feature for debugging what&#8217;s happening when there are problems with modules or handlers in the IIS pipeline.</p>
<p><a href="/2012/07/23/debugging-iis7-requests-with-windows-event-tracing/">Debugging IIS7 with Windows events tracing</a> &#8211; detailed information about what has happened to a broken request that fails before or after it gets to an IIS7 application pool. </p>
<h2>When things go wrong on the client</h2>
<p><a href="/2012/07/11/simulating-network-latency-with-fiddler/">Simulating network latency with fiddler</a> &#8211; How to use the Fiddler proxy to simulate HTTP response latency to test how your website works over a slow connection.</p>
<p><a href="/2008/08/07/ietester-test-ie55-to-ie8-on-the-same-computer/">IE tester</a> &#8211; for cross browser testing across all versions of IE. </p>
<p><a href="/2006/06/28/new-link-for-ie-drip-memory-leak-detector/">IE drip</a> &#8211; finding javascript memory leaks. Tracks how much memory IE is using and shows DOM elements that can&#8217;t be disposed. An old tool which isn&#8217;t very pretty looking, but super handy if you need to debug memory leaks. </p>
<p><a href="/2007/05/12/diy-javascript-stack-trace/">DIY javascript stack trace</a> &#8211; creating yourself a stack trace if you can&#8217;t run javascript debugging tools for some reason. </p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2012/07/24/web-debugging-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging IIS7 requests with windows event tracing</title>
		<link>http://helephant.com/2012/07/23/debugging-iis7-requests-with-windows-event-tracing/</link>
		<comments>http://helephant.com/2012/07/23/debugging-iis7-requests-with-windows-event-tracing/#comments</comments>
		<pubDate>Mon, 23 Jul 2012 11:00:57 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[IIS7]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[application pool]]></category>
		<category><![CDATA[application request routing]]></category>
		<category><![CDATA[arr]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[etw]]></category>
		<category><![CDATA[ETW tracing]]></category>
		<category><![CDATA[http.sys]]></category>
		<category><![CDATA[http.sys logging]]></category>
		<category><![CDATA[httptrace]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[logman]]></category>
		<category><![CDATA[windows event tracing]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2565</guid>
		<description><![CDATA[The windows event tracing can give detailed information about what has happened to a broken request that fails before or after it gets to the IIS7 pipeline. ]]></description>
				<content:encoded><![CDATA[<p>Previously I wrote about <a href="http://helephant.com/2012/07/18/debugging-the-iis7-integrated-pipeline-with-failed-request-tracing/">debugging the integrated pipeline with failed request tracing</a> but I&#8217;ve also run into problems that occur either too early or too late in IIS to be captured by failed request tracing. These are usually problems that involve the connection between <a href="http://learn.iis.net/page.aspx/101/introduction-to-iis-architecture/">HTTP.sys and the IIS7 application pools</a> (and in my case have been all related to <a href="http://www.iis.net/download/ApplicationRequestRouting">application request routing</a>). </p>
<p>For these types of problems, <a href="http://msdn.microsoft.com/en-us/library/bb968803.aspx">windows event tracing</a> can show where the request has gone wrong. This is the built-in operating system event tracing that supplies messages to the windows event viewer, turning on logging that is usually off by default.  </p>
<h2>Using windows event tracing</h2>
<p>You turn on the HTTP.sys logging using the <a href="https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/nt_command_logman.mspx?mfr=true">logman start</a> command. Then you need to do whatever is needed to generate some request for it to log. </p>
<pre class="command-line">
c:\> logman start httptrace -p Microsoft-Windows-HttpService 0xFFFF -o trace-output.etl -ets
The command completed successfully.
</pre>
<p>After you have finished making requests, you need to turn off the logger. This will create a binary file with all the output, which you can translate into XML (or CSV).</p>
<pre  class="command-line">
c:\> logman stop httptrace -ets
The command completed successfully.

c:\> tracerpt.exe trace-output.etl -of XML -o trace-output.xml

Input
----------------
File(s):
     trace-output.etl

100.00%

Output
----------------
DumpFile:           trace-output.xml

The command completed successfully.
</pre>
<p>After you have finished there will be a trace-output.etl and trace-output.xml file in the current directory. </p>
<h2>Understanding the output</h2>
<p>The file that gets generated is not particularly pretty to look at, but contains lots of information about what happened to your request. I usually search for the path that I entered or the port that my request came in on (if it&#8217;s not 80) to skip straight to the right place in the file.</p>
<p>About the third thing that happens is the incoming request is assigned a connectionId. This makes it very convenient to find all the events that happen to your request afterwards because they all contain the connectionId.</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;Event</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://schemas.microsoft.com/win/2004/08/events/event&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;System<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/System<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;EventData<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;RequestId&quot;</span><span class="re2">&gt;</span></span>0xF500000080000024<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;ConnectionId&quot;</span><span class="re2">&gt;</span></span>0xF500000060000023<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;ConnectionObj&quot;</span><span class="re2">&gt;</span></span>0xFFFFFA80019BE870<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/EventData<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;RenderingInfo</span> <span class="re0">Culture</span>=<span class="st0">&quot;en-GB&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Task<span class="re2">&gt;</span></span></span>HTTP Connection Trace Task <span class="sc3"><span class="re1">&lt;/Task<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Message<span class="re2">&gt;</span></span></span>Connection ID (0xF500000060000023) assigned to connection </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; and request (request ID 0xF500000080000024) will be parsed. <span class="sc3"><span class="re1">&lt;/Message<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/RenderingInfo<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/Event<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p>If you are having problems getting your requests to arrive at an IIS7 application pool, here&#8217;s an example of a message logged when the request is passed off to an IIS application pool:</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;Event</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://schemas.microsoft.com/win/2004/08/events/event&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;EventData<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;RequestObj&quot;</span><span class="re2">&gt;</span></span>0xFFFFFA80023AB550<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;RequestId&quot;</span><span class="re2">&gt;</span></span>0xF500000080000024<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;SiteId&quot;</span><span class="re2">&gt;</span></span> &nbsp; &nbsp; &nbsp; 2<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;RequestQueueName&quot;</span><span class="re2">&gt;</span></span>FailedRequestTracingDemo<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;Url&quot;</span><span class="re2">&gt;</span></span>http://localhost:8082/<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;Status&quot;</span><span class="re2">&gt;</span></span> &nbsp; &nbsp; &nbsp; 0<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/EventData<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;RenderingInfo</span> <span class="re0">Culture</span>=<span class="st0">&quot;en-GB&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Level<span class="re2">&gt;</span></span></span>Information <span class="sc3"><span class="re1">&lt;/Level<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Opcode<span class="re2">&gt;</span></span></span>Deliver <span class="sc3"><span class="re1">&lt;/Opcode<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Message<span class="re2">&gt;</span></span></span>Delivered request to server application (request pointer 0xFFFFFA80023AB550, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; request ID 0xF500000080000024, site ID 2) from request queue FailedRequestTracingDemo </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for URI http://localhost:8082/ with status 0. <span class="sc3"><span class="re1">&lt;/Message<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Channel<span class="re2">&gt;</span></span></span>HTTP Service Channel <span class="sc3"><span class="re1">&lt;/Channel<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Provider<span class="re2">&gt;</span></span></span>Microsoft-Windows-HttpService <span class="sc3"><span class="re1">&lt;/Provider<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/RenderingInfo<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/Event<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p>If your request is going wrong after the app pool has finished with it (and you can tell this by turning on <a href="http://helephant.com/2012/07/18/debugging-the-iis7-integrated-pipeline-with-failed-request-tracing/">failed request tracing</a>), look for a message like this which says that the response was generated successfully and gives some information about what was sent back to the client:</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;Event</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://schemas.microsoft.com/win/2004/08/events/event&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;EventData<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;RequestId&quot;</span><span class="re2">&gt;</span></span>0xF500000080000024<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/EventData<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;RenderingInfo</span> <span class="re0">Culture</span>=<span class="st0">&quot;en-GB&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Level<span class="re2">&gt;</span></span></span>Information <span class="sc3"><span class="re1">&lt;/Level<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Opcode<span class="re2">&gt;</span></span></span>FastRespLast <span class="sc3"><span class="re1">&lt;/Opcode<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Message<span class="re2">&gt;</span></span></span>Server application passed the last response (corresponding to request ID </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0xF500000080000024). <span class="sc3"><span class="re1">&lt;/Message<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Channel<span class="re2">&gt;</span></span></span>HTTP Service Channel <span class="sc3"><span class="re1">&lt;/Channel<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;Provider<span class="re2">&gt;</span></span></span>Microsoft-Windows-HttpService <span class="sc3"><span class="re1">&lt;/Provider<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/RenderingInfo<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/Event<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;Event</span> <span class="re0">xmlns</span>=<span class="st0">&quot;http://schemas.microsoft.com/win/2004/08/events/event&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;&#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sc3"><span class="re1">&lt;EventData<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;RequestId&quot;</span><span class="re2">&gt;</span></span>0xF500000080000025<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;ConnectionId&quot;</span><span class="re2">&gt;</span></span>0xF500000060000023<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;StatusCode&quot;</span><span class="re2">&gt;</span></span>304<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;Verb&quot;</span><span class="re2">&gt;</span></span>GET<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;HeaderLength&quot;</span><span class="re2">&gt;</span></span>4294965376<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;EntityChunkCount&quot;</span><span class="re2">&gt;</span></span>0<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Data</span> <span class="re0">Name</span>=<span class="st0">&quot;CachePolicy&quot;</span><span class="re2">&gt;</span></span> &nbsp; &nbsp; &nbsp; 0<span class="sc3"><span class="re1">&lt;/Data<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sc3"><span class="re1">&lt;/EventData<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sc3"><span class="re1">&lt;RenderingInfo</span> <span class="re0">Culture</span>=<span class="st0">&quot;en-GB&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Level<span class="re2">&gt;</span></span></span>Information <span class="sc3"><span class="re1">&lt;/Level<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Opcode<span class="re2">&gt;</span></span></span>FastResp <span class="sc3"><span class="re1">&lt;/Opcode<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Task<span class="re2">&gt;</span></span></span>HTTP Request Trace Task <span class="sc3"><span class="re1">&lt;/Task<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;Message<span class="re2">&gt;</span></span></span>Server application passed response (request ID 0xF500000080000025, connection </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ID 0xF500000060000023, method GET, header length 4294965376, number of entity </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chunks 0, cache policy 0) with status code 304. <span class="sc3"><span class="re1">&lt;/Message<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sc3"><span class="re1">&lt;/RenderingInfo<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/Event<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p>Hopefully this is something that most developers will never need to know because you have to be doing something a bit strange to mess things up at this level, but I&#8217;ve found it&#8217;s a pretty useful tool to have in my IIS7 debugging toolkit. It&#8217;s also appeals to my nerdy nature to be able to take a peek under the covers and see what IIS is actually doing when it processes my request. </p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2012/07/23/debugging-iis7-requests-with-windows-event-tracing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging the IIS7 integrated pipeline with failed request tracing</title>
		<link>http://helephant.com/2012/07/18/debugging-the-iis7-integrated-pipeline-with-failed-request-tracing/</link>
		<comments>http://helephant.com/2012/07/18/debugging-the-iis7-integrated-pipeline-with-failed-request-tracing/#comments</comments>
		<pubDate>Wed, 18 Jul 2012 11:00:11 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[IIS7]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[debugging tools]]></category>
		<category><![CDATA[failed request tracing]]></category>
		<category><![CDATA[frt]]></category>
		<category><![CDATA[handler]]></category>
		<category><![CDATA[http handler]]></category>
		<category><![CDATA[http module]]></category>
		<category><![CDATA[iis]]></category>
		<category><![CDATA[iis7]]></category>
		<category><![CDATA[iis7.5]]></category>
		<category><![CDATA[integrated pipeline]]></category>
		<category><![CDATA[module]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2532</guid>
		<description><![CDATA[Failed request tracing is a handy IIS7 feature for debugging what's happening when there are problems with modules or handlers in the IIS pipeline.]]></description>
				<content:encoded><![CDATA[<p>I spent a fair amount of time in 2011 helping to move websites from IIS6 to IIS7 at work and was delighted to find out that IIS7 has some really nice tools you can use to peer into the matrix when things go wrong. </p>
<p>The one I found most useful was <a href="http://learn.iis.net/page.aspx/266/troubleshooting-failed-requests-using-tracing-in-iis/">failed request tracing</a>, a tool designed to show what has happened inside the <a href="http://learn.iis.net/page.aspx/243/aspnet-integration-with-iis/">integrated pipeline</a> for a particular request. It logs every event that fires so you can trace the journey of a request and diagnose problems with HTTP modules or HTTP handlers. </p>
<p>The featured is called failed request tracing, but don&#8217;t worry, it can trace any request. </p>
<h2>Using failed request tracing</h2>
<p>Failed request tracing comes with IIS7 but is an optional module that is not installed by default. You can switch it on through the windows component dialog. If its installed you&#8217;ll see a failed request tracing rules item in the IIS manager under the website.<br />
<img src="http://helephant.com/wp-content/uploads/2012/07/failed-request-tracing-windows-components.png"></p>
<p>Failed request tracing is switched on at the site level in IIS manager. It needs to be turned on in two places. You need to enable it for the site and then set up one or more request filters.<br />
<img src="http://helephant.com/wp-content/uploads/2012/07/enabling-failed-request-tracing.png"></p>
<p>The IIS manager stores the changes in the site&#8217;s web.config file in the system.webserver section, so you can also make them directly there. If you do use the IIS manager to configure failed request tracing, make sure you don&#8217;t accidentally check in the changes. </p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;system</span>.webServer<span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;tracing<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;traceFailedRequests<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;add</span> <span class="re0">path</span>=<span class="st0">&quot;*&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;traceAreas<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;add</span> <span class="re0">provider</span>=<span class="st0">&quot;ASPNET&quot;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">areas</span>=<span class="st0">&quot;Infrastructure,Module,Page,AppServices&quot;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">verbosity</span>=<span class="st0">&quot;Verbose&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/traceAreas<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;failureDefinitions</span> <span class="re0">statusCodes</span>=<span class="st0">&quot;200&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/add<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/traceFailedRequests<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/tracing<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/system</span>.webServer<span class="re2">&gt;</span></span></div>
</li>
</ol>
</div>
<p>Once you have everything set up, you just run your pages and the logs are written to <code>c:\inetpub\logs\FailedReqLogFiles</code>. They are XML with an XSLT that makes them pretty. I found they only really worked in IE. </p>
<p>Once you are done, there&#8217;s no problem manually deleting the files you don&#8217;t want any more. Just be careful to either delete the whole directory or to leave the XSLT because failed request tracing won&#8217;t regenerate the XSLT unless the directory isn&#8217;t there any more. If you don&#8217;t delete the files, they will eventually be overwritten when IIS hits the limit on the number of files to generate. </p>
<h2>Reading the logs</h2>
<p>The problem with failed request tracing is that the amount of data it captures feels a bit overwhelming, but there are a few views I&#8217;ve found really helpful.</p>
<p>Sometimes the summary view has all the information you need to know. It will tell you who the request was authenticated by, how long it took, what the status code was and which app pool it ran under.<br />
<img src="http://helephant.com/wp-content/uploads/2012/07/frt-summary.png"></p>
<p>If one of your modules is acting strangely or isn&#8217;t kicking in, the module notifications gives a fairly succinct story of which events fired for which modules in which order. If you need more detail, check out the complete request trace.<br />
<img src="http://helephant.com/wp-content/uploads/2012/07/frt-module-order.png"></p>
<p>If your request isn&#8217;t being served properly, you might want to know which handler picked it up. The complete request trace in the request details tab shows which handlers were rejected and which ones were tried in the MapRequestHandler phase of the pipline.<br />
<img src="http://helephant.com/wp-content/uploads/2012/07/frt-handler.png"></p>
<p>If your request is slow, the performance view lists the slowest steps at the top so you can quickly figure out which module is to blame.<br />
<img src="http://helephant.com/wp-content/uploads/2012/07/frt-performance-view.png"></p>
<h2>Makes the IIS7 integrated pipeline less of a black box</h2>
<p>Failed request tracing is an awesomely useful tool. It would have been much harder to figure out what was going wrong in our code designed to run in a classic app pool if we didn&#8217;t have this. </p>
<p>It helped us figure out that the <a href="http://stackoverflow.com/questions/1046092/iis-7-static-file-compression-problem">Sitecore module was corrupting static files</a> once they&#8217;d been gziped by looking at what order the modules inside the pipeline fired in. We found it helpful to confirm that performance problems were outside the application by seeing how long the pipeline took to run. It also helped us figure out we needed to turn on <a href="http://www.iis.net/ConfigReference/system.webServer/modules#005">runAllManagedModulesForAllRequests</a> to get postback working for extension free Sitecore urls because we could see the modules just weren&#8217;t firing. </p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2012/07/18/debugging-the-iis7-integrated-pipeline-with-failed-request-tracing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Javascript function declarations vs function operators</title>
		<link>http://helephant.com/2012/07/14/javascript-function-declaration-vs-expression/</link>
		<comments>http://helephant.com/2012/07/14/javascript-function-declaration-vs-expression/#comments</comments>
		<pubDate>Sat, 14 Jul 2012 18:13:52 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[function declaration]]></category>
		<category><![CDATA[function operator]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[functions]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2381</guid>
		<description><![CDATA[A look at the differences between the javascript function declaration and the function operator syntax.]]></description>
				<content:encoded><![CDATA[<p><img src="http://www.helephant.com/wp-content/uploads/2012/07/IMG_2889.jpg" class="alignright" alt="Use the force luke"> There are quite a few different ways to create a new function in javascript, but the two most common are using a <a href="https://developer.mozilla.org/en/JavaScript/Reference/Statements/function">function declaration</a> or using the <a href="https://developer.mozilla.org/en/JavaScript/Reference/Operators/function">function operator</a>.</p>
<p>This function is created using a function declaration:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Stay on target, stay on target&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>This function is created using the function operator: </p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> destroyDeathStar = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Stay on target, stay on target&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>The biggest difference between using a function declaration or a function operator is when the function is created. Functions made with a function declaration are moved to the top of the code and created before the rest of the function is run. Functions made with the function operator are created at runtime where they are in the javascript code. </p>
<h2 id="function-declarations">Function declarations</h2>
<p>Function declarations are the javascript 101 way to create a new function:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Stay on target, stay on target&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>When you use a function declaration, the function object will be created as the javascript is parsed, before the code is run. This is why you can call a function created with the function statement before it is declared:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Stay on target, stay on target&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>This works because the javascript interpreter does something called <a href="http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting">hoisting</a> when it is loading a new program or creating a new function object. It looks for any function declarations in the current scope and moves them to the beginning of the code. This is why you can call a function created by a function declaration before it is declared in the code. </p>
<p>So if you wrote some code that looks like this:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Stay on target, stay on target&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>It would end up being executed like this:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> destroyDeathStar = <span class="kw2">function</span> destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Stay on target, stay on target&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>The function declaration syntax also automatically adds the new <a href="/2008/08/19/functions-are-first-class-objects-in-javascript/">function object</a> to the current scope. It creates a variable with the same name as the function which points to the newly created function object. </p>
<p>Because of this, all functions created with the function declaration must be given a name. They can not be <a href="/2008/08/23/javascript-anonymous-functions/">anonymous functions</a>. If the function did not have a name, it would not be possible to add it to the current scope and you would not be able to call it. </p>
<h2 id="the-function-operator">The function operator</h2>
<p>If you&#8217;ve done any work with <a href="http://jquery.com">jquery</a>, you&#8217;ve probably seen a function declared with the function operator:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> destroyDeathStar = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Stay on target, stay on target!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> </div>
</li>
<li class="li1">
<div class="de1">destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>The biggest difference between a function operator and a function declaration is when the function is created. Function operators aren&#8217;t affected by hoisting so they are evaluated where they occur in the source code as the code is run.</p>
<p>This is very useful because function creation can be affected by the surrounding logic. For example, if you put a function declaration into an if statement, it would get hoisted out of the if statement into the beginning of the scope. If you use a function operator no hoisting will happen so the function creation will stay inside the if statement:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> destroyDeathStar;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span>pilot == <span class="st0">&quot;Luke Skywalker&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; destroyDeathStar = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;May the force be with you&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">else</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; destroyDeathStar = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Gold Five to Red leader, lost Tiree, lost Dutch&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">// result will depend on the value of pilot when the code is run</span></div>
</li>
</ol>
</div>
<p>According to the javascript spec it&#8217;s not actually legal javascript to put a function declaration inside an if block. All the browsers let you do it, but they deal with it in different ways. Annoyingly, it will work the way you expect it to in Firefox because they have yet another type of function creation called the <a href="https://developer.mozilla.org/en/JavaScript/Reference/Statements/function">function statement</a> but it will hoist the function out of the if statement in all other browsers. </p>
<p>The other result of not being affected by hoisting is that functions created by the function operator aren&#8217;t automatically added into the current scope as a variable. Instead the function operator returns the new function object and it is up to the code to do something with it. </p>
<p>The usual thing is to assign the return value from the function operator to a variable that you can use to invoke it:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="co1">// same name as the function that you can use to invoke it</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Stay on target, stay on target&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// this example of using the function operator stores the new function</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// in a variable called destroyDeathStar2</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> destroyDeathStar2 = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Stay on target, stay on target!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> </div>
</li>
<li class="li1">
<div class="de1">destroyDeathStar2<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>If you don&#8217;t do anything with the return value from the function operator, there is no way to invoke the function. It is perfectly valid javascript to do that, but doesn&#8217;t really have much point:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Stay on target, stay on target!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> </div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// no way to invoke the function</span></div>
</li>
</ol>
</div>
<p>Since functions created with the function operator aren&#8217;t automatically added to the scope, they don&#8217;t have to have a name. They can be <a href="/2008/08/javascript-anonymous-functions/">anonymous</a>. Functions created with the function operator are usually created as anonymous functions since there isn&#8217;t much benefit giving the function a name since it&#8217;s not automatically added to scope:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> destroyDeathStar = <span class="kw2">function</span> <span class="coMULTI">/* no name here &#8211; so is anonymous */</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Stay on target, stay on target!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// destroyDeathStar is a variable containing a reference to the function, not the function&#39;s name </span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// read about anonymous functions if you&#39;d like to know more</span></div>
</li>
<li class="li1">
<div class="de1">destroyDeathStar<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<h2 id="function-operator-is-an-expression">The function operator is useful because it&#8217;s an expression</h2>
<p>The function operator is a lot more flexible than a function declaration because it can be used wherever it is valid to use an expression. </p>
<p>You can use the function operator to declare a function when you are creating an object:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> jabbaTheHut = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;laugh : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;ho ho ho ho&quot;</span><span class="br0">&#41;</span>; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">jabbaTheHut.<span class="me1">laugh</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>When you are creating a list:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> toDoToday = <span class="br0">&#91;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Aren&#39;t you a little short for a storm trooper?&quot;</span><span class="br0">&#41;</span> <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Boring conversation anyway&quot;</span><span class="br0">&#41;</span> <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> x=<span class="nu0">0</span>; x<span class="sy0">&lt;</span>toDoToday.<span class="me1">length</span>; x++<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;toDoToday<span class="br0">&#91;</span>x<span class="br0">&#93;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>To declare a function as a parameter when calling another function:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="co1">// function statement</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> itIsATrap<span class="br0">&#40;</span>theTrap<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;theTrap<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// function operator</span></div>
</li>
<li class="li1">
<div class="de1">itIsATrap<span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Many Bothans died to bring us this information&quot;</span><span class="br0">&#41;</span>; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>This can be very convenient if you are creating single use functions like object methods or event handlers. The anonymous function syntax is more concise than declaring a function and then doing something with it as two separate steps. In JQuery code (and other similar libraries) this is used all the time:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;page has loaded.&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>You can also use the function operator it inside an if condition to actually control whether a function is created or not using programming logic:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> chooseSide;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span>skywalker == <span class="st0">&quot;Luke Skywalker&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; chooseSide = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;jedi&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">else</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; chooseSide = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;sith&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>chooseSide<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Or inside any type of loop:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> x=<span class="nu0">0</span>; x<span class="sy0">&lt;</span>=<span class="nu0">900</span>; x++<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> myFunction = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;When &quot;</span> + x + <span class="st0">&quot; years old you reach, look as good you will not.&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; myFunction<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<h2 id="which-to-use">That&#8217;s nice, but which should I use?</h2>
<p>If you need to create a function inside an if statement or a loop, always use a function operator. The function declaration will not have the effect that you intended because it will be hoisted to the top of the code (unless you and all the people who will ever use your script are using Firefox because then it will become a <a href="https://developer.mozilla.org/en/JavaScript/Reference/Statements/function">function statement</a>). Function declarations that are in if statements or loops will never consistently do what you expect cross browser. </p>
<p>If you are going to declare a function and use it only once and straight away, the function operator syntax is more concise than the function declaration. It is ideal for things like single line JQuery event handlers that toggle some CSS class. </p>
<p>Building up objects with methods is pretty much the same. Using the function operator to directly assign the method to the object means not having to go looking for the implementation. If you&#8217;re worried about performance, use the <a href="http://helephant.com/2009/01/javascript-object-prototype/">object prototype</a> to declare the method only once for all the objects you create. </p>
<p>If you&#8217;re working in the global scope (writing javascript that is not inside a function), particularly if you are working on code that will be used by other people, you will want to avoid creating lots of variables that might conflict with other code. The function operator can be used with patterns such as <a href="http://www.dustindiaz.com/namespace-your-javascript/">namespacing</a> to keep your code&#8217;s footprint as light as possible. </p>
<p>For any other functions that will be used a number of times, function declaration or function operator is a matter of personal preference. The function declaration is more concise and looks more like how you&#8217;d create a function in most other languages. If you&#8217;re using the function operator everywhere else and you want to make sure no one makes the mistake of putting a function declaration inside a conditional statement or a loop, then it might be worth considering mandating the function operator in your coding standards. </p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2012/07/14/javascript-function-declaration-vs-expression/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simulating network latency with Fiddler</title>
		<link>http://helephant.com/2012/07/11/simulating-network-latency-with-fiddler/</link>
		<comments>http://helephant.com/2012/07/11/simulating-network-latency-with-fiddler/#comments</comments>
		<pubDate>Wed, 11 Jul 2012 21:24:38 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2469</guid>
		<description><![CDATA[How to use the Fiddler proxy to simulate HTTP response latency to test how your website works over a slow connection. ]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.fiddler2.com/fiddler2/">Fiddler</a> is one of my favourite web development debugging tools on Windows because it makes it easy to watch what&#8217;s happening in your website at the HTTP level. It is an easy to use proxy that can capture all of the HTTP traffic between your machine and the server and show it to you in its raw glory. </p>
<p>One of the really tricky things you can do with it is simulate network latency. This is possible because Fiddler has an autoresponder feature that can create a canned response to a request to a url. </p>
<p>To set one up, Fiddler has an autoresponder tab. You need to tick the &#8220;Enable automatic responses&#8221;, &#8220;Unmatched requests pass through&#8221; and &#8220;Enable latency&#8221; checkboxes to turn it on and to start meddling with requests. </p>
<p>The easiest way to create a new autoresponder is to load your webpage up in a browser and get fiddler to capture the traffic. Then you can drag the request that you want to simulate network latency on into the autoresponder window. Make sure that you&#8217;re capturing responses with a 200 HTTP code and not ones that return a 304 &#8220;load from cache&#8221; response. </p>
<p>Then right click on the autoresponder, choose &#8220;set latency&#8221; and enter in how long you&#8217;d like the request to take in milliseconds. To verify that it has worked, use the network tab in Firebug to watch your page download.  </p>
<p><img src="/wp-content/uploads/2012/07/fiddler-latency.png" ></p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2012/07/11/simulating-network-latency-with-fiddler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tell me a story</title>
		<link>http://helephant.com/2012/04/14/tell-me-a-story/</link>
		<comments>http://helephant.com/2012/04/14/tell-me-a-story/#comments</comments>
		<pubDate>Sat, 14 Apr 2012 21:54:59 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2418</guid>
		<description><![CDATA[A little rant against the evils of services like four square that put your story-empty tweets into my twitter stream. ]]></description>
				<content:encoded><![CDATA[<p><img src="http://helephant.com/wp-content/uploads/2012/04/fail-whale.png" class="alignright" />I find the automated messages from services like four square that my friends post to twitter a little sad because they tell me there is a story, but they don&#8217;t tell me what the story is. </p>
<p>@friend is at St Pancras. Are they catching a train or trying the champagne bar? </p>
<p>@friend is watching Doctor Who with everyone else in the UK. What did they think of the story? Do they think I should watch it? Did they like Matt Smith&#8217;s latest headwear? </p>
<p>@friend just watched a video on youtube. Was it a thought provoking demo of some technology or a cat on a Roomba? </p>
<p>I like social media (twitter in particular) because I get to hear the little stories that I share with the people in my every day life, but don&#8217;t get to hear from the people I don&#8217;t see every day. I love knowing that my friend from America is besotted with some super hero from a cartoon, that my friend from Australia is on her way to the beach or that my front-end coder friend is enjoying his new contract. With so many friends in so many different places it&#8217;s a little way to be part of their lives. Little stories that only matter because I care about them. </p>
<p>Stories spark the imagination and start conversations. Stories can tease or make me laugh. Stories make me want to click on links or see the picture. Facts without stories are empty and unsatisfying. </p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2012/04/14/tell-me-a-story/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Places to get good developer videos</title>
		<link>http://helephant.com/2012/01/21/places-to-get-good-developer-videos/</link>
		<comments>http://helephant.com/2012/01/21/places-to-get-good-developer-videos/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 19:21:29 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[professional development]]></category>
		<category><![CDATA[totaljobs group]]></category>
		<category><![CDATA[videos]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2328</guid>
		<description><![CDATA[A list of places to find videos about being a better developer. These are mostly about all the stuff I care about for work: writing good code, .NET technology and web dev. ]]></description>
				<content:encoded><![CDATA[<p><img src="http://helephant.com/wp-content/uploads/2012/01/DPP_0106.jpg" class="alignright"/> Part of the awesome that is <a href="http://www.totaljobsgroup.com/">where I work</a> is an hour a week where developers can get together and chat about what we&#8217;ve been up to with the idea of spreading ideas around the different teams. One of the regular things we do is watch a video about a new technology, pattern or practice that we&#8217;d like to know more about. Right now I run the testing and automation stream and have found it a bit of a pain to always have something new to talk about, so I&#8217;ve put together a list of interesting places to find developer videos. </p>
<p>This is just a starting point, hopefully I&#8217;ll keep updating it as I actually try out the videos and find more places to get good content.</p>
<h2>Programming</h2>
<p><a href="http://www.cleancoders.com/">Clean coders</a> has videos about writing maintainable code that are all less than an hour, fast moving, well edited and full of funny. You do have to pay for the videos, but they&#8217;re pretty cheap and have clear information about showing them to groups (around $1US/person). I find it impossible not to like Uncle Bob. It&#8217;s like being taught how to code well by your slightly embarrassing dad. </p>
<p><a href="http://www.infoq.com/">infoq</a> has presentations about pretty much everything going on in mainstream development. </p>
<h2>.NET</h2>
<p><a href="http://tekpub.com/">Tekpub</a> have videos about a heap of different technologies, including quite a good selection on <a href="http://tekpub.com/channels/microsoft">.NET</a>. The videos tend to be under an hour and they get some pretty impressive experts (like Jon Skeet) to help present them. They&#8217;re kind of pricey ($18-$25) because you have to buy the videos as a series and they don&#8217;t have cheaper streaming prices for large groups, though they were willing to give us quite a generous discount. </p>
<p>I am a huge fan of the <a href="http://www.dotnetrocks.com/">.NET rocks</a> podcast but had never tried out their <a href="http://www.dnrtv.com/default.aspx">DNR TV</a> videos. They have videos on just about everything, though they tend to be an introduction rather than going into a lot of depth like the tekpub ones do. They&#8217;re free (hurrah!). </p>
<p>There&#8217;s a series of nhibernate videos called <a href="http://www.summerofnhibernate.com/">summer of nhibernate</a>. They&#8217;re free but over an hour each. I&#8217;ve watched the first one and it&#8217;s a pretty good introduction to nhibernate. </p>
<p><a href="http://dimecasts.net/">Dimecasts</a> has 10 minute videos about almost anything you can think about in .NET. It seems like a nice way to start a discussion about something. </p>
<p><a href="http://channel9.msdn.com/">Channel 9</a> on the MSDN have a vast library of videos which are mostly about Microsoft technology. There are hundreds of videos about .NET. </p>
<p><a href="http://skillsmatter.com/go/open-source-dot-net">Skills Matter</a> is a London based company that runs a lot of interesting sessions about all sorts of different technologies (including lots of open source stuff). They have recorded quite a lot of them and put them on their site to watch for free.  </p>
<h2>Web dev</h2>
<p><a href="http://yuilibrary.com/theater/">YUI theatre</a> has lots of videos about using YUI and some generally interesting web development ones as well. </p>
<p><a href="http://www.stubbornella.org/content/category/general/geek/css/">Nicole Sullivan</a> has some recordings of her conference talks. She talks about how to write maintainable CSS and we have found that using her ideas have made our CSS way better. </p>
<p>Videos from the <a href="http://channel9.msdn.com/Events/MIX">MIX conference</a> on some pretty neat new web technology. The 2011 lot have a lot of stuff about HTML5. They tend to be pretty good quality presentations since they&#8217;re for a conference. </p>
<h2>Technology and inspiration</h2>
<p>I like the <a href="http://www.ted.com/">TED</a> videos as an excuse to dream. ASP.NET developers probably don&#8217;t need to know about <a href="http://www.ted.com/talks/bilal_bomani_plant_fuels_that_could_power_a_jet.html">bio-fuels</a>, but it&#8217;s nice to feel inspired. :) </p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2012/01/21/places-to-get-good-developer-videos/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The HTML5 audio tag</title>
		<link>http://helephant.com/2011/12/29/the-html5-audio-tag/</link>
		<comments>http://helephant.com/2011/12/29/the-html5-audio-tag/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 17:00:43 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[html5]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2160</guid>
		<description><![CDATA[Now the new HTML5 audio element has pretty decent browser support it is starting to be a pretty compelling alternative to using Flash. ]]></description>
				<content:encoded><![CDATA[<p><img src="http://helephant.com/wp-content/uploads/2012/01/audio-tag.jpg" class="alignright" /><br />
The new HTML5 &lt;audio&gt; tag provides a pretty easy way to embed audio into a webpage without needing to use flash:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;audio controls&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;source src=&quot;/my-podcast.mp3&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;source src=&quot;/my-podcast.ogg&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/audio&gt;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#browser-support">Browser support</a> for the tag itself is pretty decent, but you&#8217;ll need to <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#supporting-different-browsers">create a mp3 and ogg version of your audio</a> if you want it to play in all browsers. You can also provide a <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#fallback">fallback</a> for older browsers. </p>
<p>The <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#built-in-controls">built-in browser UI</a> is pretty consistent and looks decent enough, but if you need something special it&#8217;s very easy to <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#controlling-audio-with-javascript">use javascript to control the &lt;audio&gt; element</a>.</p>
<h2 id="audio-tag">The audio tag</h2>
<p>A simple &lt;audio&gt; tag (<a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#supporting-different-browsers">that doesn&#8217;t worry about cross browser compatibility</a>) looks like this:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;audio src=&quot;/my-podcast.mp3&quot; controls preload=&quot;none&quot; /&gt;</div>
</li>
</ol>
</div>
<p><strong>src</strong> &#8211; the url of the audio to play. In reality, if you want your audio to work in as <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#supporting-different-browsers">many browsers as possible</a>, you will need to set the media files in the &lt;source&gt; tags to provide both .mpg and .ogg versions of the content. </p>
<p><strong>controls</strong> &#8211; if this attribute is present (even if it is set to false), the browser will render an <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#built-in-controls">element to control your audio</a>. If you set this to false, no element will be rendered and you will need to <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#controlling-audio-with-javascript">use javascript to control your video</a>.</p>
<p>Here are the default controls in Chrome:<br />
<img src="http://helephant.com/wp-content/uploads/2011/12/audio-chrome.png"/></p>
<p><strong>preload</strong> (none, metadata, auto) &#8211; whether the browser should start downloading the audio as soon as the page loads. If the audio is the whole point of the page it&#8217;s on, it might make sense to do it. If not, you can tell the browser to save the bandwidth. Of course having preload turned on will affect your bandwidth costs as much as it will affect your users. </p>
<p>Setting preload to none tells the browser not to preload at all. Metadata suggest that the browser just download enough of the file to find out things like dimensions, running length and size. Auto lets the browser know that it can do whatever it thinks will be best for the user, which might include preloading the whole file. </p>
<p>Sadly if you use this right now, setting preload=&#8221;none&#8221; causes issues in IE9. It will add the audio element to the page, but won&#8217;t display any controls for it. </p>
<p>For more information checked out the <a href="https://developer.mozilla.org/en/HTML/Element/audio">Mozilla</a> or <a href="http://msdn.microsoft.com/en-us/library/ff975061(v=vs.85).aspx">MSDN</a> references. There are a heap of extra properties that are useful for <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#controlling-audio-with-javascript">interacting with audio element through javascript</a>. </p>
<h2 id="supporting-different-browsers">Different browsers need different formats</h2>
<p>While <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#browser-support">support for the tag itself is pretty solid across browsers</a>, there (predictably) isn&#8217;t one audio format that all browsers support: </p>
<table class="compatibility-table">
<tr>
<th></th>
<td>IE</td>
<td>Firefox</td>
<td>Chrome</td>
<td>Safari</td>
<td>Opera</td>
</tr>
<tr>
<th>mp3</th>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<th>ogg</th>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<th>wav</th>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
</table>
<p>So to make an &lt;audio&gt; element that will work in all browsers, you&#8217;ll need to provide your file in at least two formats. I&#8217;ve found .ogg and .mp3 work pretty well. You can use the &lt;sources&gt; tag to provide a link to the audio file in both formats. The browsers will just look through all the sources provided and choose the one it thinks is best:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;audio controls&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;&lt;source src=&quot;/my-podcast.mp3&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;&lt;source src=&quot;/my-podcast.ogg&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/audio&gt;</div>
</li>
</ol>
</div>
<p>This might be a good reason to keep using flash for developers who are less concerned about supporting open standards and don&#8217;t need to support mobile browsers. Encoding the audio in two formats definitely adds a little overhead to my podcast workflow. </p>
<h2 id="fallback">Providing a fall back for older browsers</h2>
<p>Older browsers don&#8217;t understand the &lt;audio&gt; tag so you can provide a fallback just by adding extra HTML inside the &lt;audio&gt; tag. Browsers that support &lt;audio&gt; will just ignore the fallback content, while browsers that don&#8217;t support &lt;audio&gt; will ignore the audio tag. </p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;audio controls&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;&lt;source src=&quot;/my-podcast.mp3&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;&lt;source src=&quot;/my-podcast.ogg&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;&lt;a href=&quot;/my-podcast.mp3&quot;&gt;download my podcast&lt;/a&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/audio&gt;</div>
</li>
</ol>
</div>
<p>One option is to use a Flash player as a fallback. Since Flash will play on pretty much any browsers except the iPhone, the only advantage of using the &lt;audio&gt; tag as with a Flash player fallback (apart from the warm glow of supporting open standards) is your audio will also play in iPhone Safari. </p>
<h2 id="built-in-controls">Audio controls in the different browsers</h2>
<p>If you decide to use the built in browser controls, the UI between browsers is pretty similar and fine for just including a simple audio file in your site.</p>
<p>Firefox:<br />
<img src="http://helephant.com/wp-content/uploads/2011/12/audio-firefox.png"/></p>
<p>Chrome:<br />
<img src="http://helephant.com/wp-content/uploads/2011/12/audio-chrome.png"/></p>
<p>Safari:<br />
<img src="http://helephant.com/wp-content/uploads/2011/12/audio-safari.png"/></p>
<p>Internet explorer:<br />
<img src="http://helephant.com/wp-content/uploads/2011/12/audio-ie.png"/></p>
<p>iPhone Safari:<br />
<img src="http://helephant.com/wp-content/uploads/2011/12/audio-iphone.png" /></p>
<p>To use the built in browser controls, just add the controls attribute to the &lt;audio&gt; tag:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;audio src=&quot;/my-podcast.mp3&quot; controls /&gt;</div>
</li>
</ol>
</div>
<h2 id="controlling-audio-with-javascript">Building custom controls using javascript</h2>
<p>If you don&#8217;t fancy the built in browser controls, it&#8217;s easy enough to control the <a href="https://developer.mozilla.org/en/DOM/HTMLAudioElement">audio tag using javascript</a>:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> audio = <span class="kw2">new</span> Audio<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span>audio.<span class="me1">canPlayType</span><span class="br0">&#40;</span><span class="st0">&quot;audio/mp3&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;audio.<span class="me1">src</span> = <span class="st0">&quot;/my-podcast.mp3&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span>audio.<span class="me1">canPlayType</span><span class="br0">&#40;</span><span class="st0">&quot;audio/ogg&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;audio.<span class="me1">src</span> = <span class="st0">&quot;/my-podcast.ogg&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">audio.<span class="me1">play</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2011/01/audio-javascript.html">Complete example</a></p>
<p>For more advanced audio manipulation, check out the experimental <a href="https://wiki.mozilla.org/Audio_Data_API">Audio data API</a>. </p>
<h2 id="browser-support">Browser support</h2>
<p>Once you get the <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#supporting-different-browsers">audio formats right</a>, desktop browsers have <a href="http://caniuse.com/#feat=audio">pretty good support</a> for the audio tag. Even IE 9+ supports it! </p>
<table class="compatibility-table">
<tr>
<th>Browser</th>
<th>Supported since version</th>
<th>Formats</th>
<th>Details</th>
</tr>
<tr>
<td>IE</td>
<td>9.0</td>
<td>AAC or .mp3</td>
<td><a href="http://msdn.microsoft.com/en-us/library/ff975061(v=vs.85).aspx">MSDN</a></td>
</tr>
<tr>
<td>Firefox</td>
<td>3.5</td>
<td>.ogg, .wav</td>
<td><a href="https://developer.mozilla.org/En/HTML/Element/Audio#Compatibility">MDN</a></tr>
<tr>
<td>Chrome</td>
<td>3</td>
<td>.mp3, .ogg</td>
<td></td>
</tr>
<tr>
<td>Safari</td>
<td>4</td>
<td>Any audio supported by Quicktime<br/> (m4a, .m4b, .m4p, .mp3, .aiff, .au, .sd2, .wav, .snd, .amr)</td>
<td><a href="http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariHTMLRef/Articles/HTMLTags.html#//apple_ref/doc/uid/30001262-audio">Safari docs</td>
</tr>
<tr>
<td>Opera</td>
<td>9.5</td>
<td>.ogg, .wav</td>
<td></td>
</tr>
</table>
<p>Mobile browser have pretty good support too: </p>
<table class="compatibility-table">
<tr>
<th>Browser</th>
<th>Supported since version</th>
</tr>
<tr>
<td>iOS Safari</td>
<td>4</td>
</tr>
<tr>
<td>Opera mobile</td>
<td>10</td>
</tr>
<tr>
<td>Opera mini</td>
<td>no support (Dec 2011)</td>
</tr>
<tr>
<td>Android</td>
<td>2.3</td>
</tr>
<tr>
<td>Blackberry</td>
<td><a href="http://devblog.blackberry.com/2010/08/blackberry-html5/">6</a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2011/12/29/the-html5-audio-tag/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The developer book club</title>
		<link>http://helephant.com/2011/04/24/the-developer-book-club/</link>
		<comments>http://helephant.com/2011/04/24/the-developer-book-club/#comments</comments>
		<pubDate>Sun, 24 Apr 2011 19:13:45 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[feature]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1971</guid>
		<description><![CDATA[I've started a new podcast called the developer book club where I interview someone interesting about what books have influenced and inspired them. ]]></description>
				<content:encoded><![CDATA[<p><img src="http://helephant.com/wp-content/uploads/2011/04/development-books-300x225.jpg" alt="" title="development books" width="300" height="225" class="alignright size-medium wp-image-2017" />I&#8217;ve just started a new website called <a href="http://developerbookclub.net/">the developer book club</a>. </p>
<p>It&#8217;s the same sort of setup as <a href="http://www.bbc.co.uk/programmes/b006qnmr">desert island discs</a>: I find someone interesting to interview and they tell me about three books that have influenced them as a developer. </p>
<p>I&#8217;ve just posted my first podcast where I interview a very nice developer called <a href="http://developerbookclub.net/dan-wagner-hall/">Dan Wagner-Hall</a> who agreed to be my first victim. </p>
<p>(book picture taken by <a href="http://www.flickr.com/photos/anantablamichhane/2091903760/">Ananta Bhadra Lamichhane</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2011/04/24/the-developer-book-club/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Come work for TotalJobs</title>
		<link>http://helephant.com/2011/02/21/come-work-for-totaljobs/</link>
		<comments>http://helephant.com/2011/02/21/come-work-for-totaljobs/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 13:35:52 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scrum]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1938</guid>
		<description><![CDATA[We are currently looking for passionate C# developers to come join our team. ]]></description>
				<content:encoded><![CDATA[<p><img src="http://helephant.com/wp-content/uploads/2011/02/tjg-logo.png" alt="" title="tjg-logo" width="110" height="100" class="alignright size-full wp-image-2032" />We need some <a href="http://www.totaljobs.com/JobSearch/JobDetails.aspx?JobId=49810373">new mid level ASP.NET developers</a> at <a href="http://www.totaljobsgroup.com/">Total Jobs Group</a> to join our team based in central London. Be part of one of our seven small scrum teams and work on everything from CSS and HTML through to the database, from idea through to release. </p>
<p>TJG runs seven job boards. <a href="http://www.totaljobs.com">Total Jobs</a> is the most popular one and the other five are all industry boards like <a href="http://www.cwjobs.co.uk/">CW Jobs</a> for IT. Pretty much all development is for either the websites or the web based tools that support them.</p>
<p>For more detailed information about the job and the exact skills we&#8217;re after, check out the <a href="http://www.totaljobs.com/JobSearch/JobDetails.aspx?JobId=49810373">job spec</a>. </p>
<h2>Why would you want to work with us?</h2>
<p>Our department is serious about continuous improvement so we’re constantly looking for new ways to do development better. In the past six months the development team have been going on TDD training and teams are starting to do it as part of their every day work. Some of the teams have been trying MVP patterns on areas of the code that already use web forms. New areas of the code have been using the MVC framework. We keep improving the way we use clientside technologies, particularly CSS and javascript. Lots of teams choose to pair program. Last year there was a big project to automate more of our release process.</p>
<p>Each team gets flexibility to try new things. Our team has tried experimenting with different sprint lengths, kanban style work in progress limits, tracking stories through TFS, <a href="http://helephant.com/2010/10/lego-scrum-board-avatars/">lego people on our scrum board</a> and tracking technical debt on the ceiling. Other teams are automating their acceptance testing with Selenium and trying TDD. Each team is encouraged to figure out what works for them.</p>
<p>We’re encouraged to share ideas around the department. We have our own internal user group where a couple of times a month someone talks about something they&#8217;re passionate about. Today&#8217;s session was about how one guy hooked up RFID readers to the scrum board to track story status and to automatically kick off builds. The really cool thing is the department supports it by giving us a lunch budget. We also do community of practice sessions where we all bring some code and talk about something neat we&#8217;ve been doing. Some of the groups have been reading books like Working Effectively with Legacy Code and Clean Code.</p>
<p>The office has a really nice atmosphere. The people are friendly. We have a casual dress code. People put effort into making work a fun place to be. Last week we had a build it in a day Friday where the whole team (not just developers) had a day to work on anything company related that interested them. We have team outings a couple of times a year. The development team are going bowling on Friday. People go out for team lunches and Friday drinks. People bring cakes and donuts in to celebrate things a couple of times a week. Our scrum master is a great cook and brought in homemade lemon drizzle cake today.</p>
<p>People notice when you do a good job and its recognised. Every other week there&#8217;s a presentation where the management tell everyone about something great that someone has done. Last year there were toys and lego for teams that did something special. You can see Star Wars lego all over the office now. Before that we competed for a silver cup full of sweets. They also awarded a scrum team of the year award where one of the teams got a prize to spend on a meal out together.</p>
<p>TotalJobs is part of a bigger company called Reed Elsevier so the benefits are pretty good. My absolute favourite is that we get 29 days holiday a year with the option to buy or sell three during the year. We also get two charity days. Last year our team spent the day doing gardening for some lovely elderly people in Sutton. The year before we did gardening and painting for a kids playground.</p>
<h2>Joel test</h2>
<p>Do you use source control? &#8211; TFS<br />
Can you make a build in one step? &#8211; Yes<br />
Do you make daily builds? &#8211; Yes, we build when we check in. Working towards continuous integration.<br />
Do you have a bug database? &#8211; Our scrum team track bugs on the board on red cards.<br />
Do you fix bugs before writing new code? &#8211; yes<br />
Do you have an up-to-date schedule? &#8211; yes<br />
Do you have a spec? &#8211; We write user stories with acceptance criteria.<br />
Do programmers have quiet working conditions? &#8211; No we work open plan and everyone sits with the people they&#8217;re working on<br />
Do you use the best tools money can buy? &#8211; We use VS2010 (mostly), Resharper, nUnit, computers with dual monitors, MSDN licenses<br />
Do you have testers? &#8211; yup. Vinny is a bug finding machine.<br />
Do new candidates write code during their interview? &#8211; depends who interviews you<br />
Do you do hallway usability testing? &#8211; we do weekly demos to get feedback from the people we build the software for. We have designers and usability people who come up with the best way to implement user interfaces. </p>
<h2>Your job isn&#8217;t as great as this?</h2>
<p>Interested? Then <a href="mailto:helen@helephant.com">email me your CV</a> and I&#8217;ll pass it on or <a href="http://www.totaljobs.com/JobSearch/JobDetails.aspx?JobId=49810373">apply through the website</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2011/02/21/come-work-for-totaljobs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maintainable CSS presentation slides</title>
		<link>http://helephant.com/2011/01/31/ddd9-slides/</link>
		<comments>http://helephant.com/2011/01/31/ddd9-slides/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 21:06:00 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[My presentations]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1934</guid>
		<description><![CDATA[A talk that I gave at the Developer, Developer, Developer day in Reading in 2011 about my experiences trying to make CSS easier to maintain. Contains slides and sample downloads. ]]></description>
				<content:encoded><![CDATA[<p>I gave a talk at <a href="http://www.developerdeveloperdeveloper.com/ddd9/">developer, developer, developer day</a> on Saturday about maintainable CSS so here are my <a href="http://helephant.com/wp-content/uploads/2011/01/css-is-code.zip">slides</a>. :)</p>
<p>The <a href="http://vimeo.com/19595618">video of the presentation</a> is up on Vimeo:<br />
<iframe src="http://player.vimeo.com/video/19595618?badge=0" width="500" height="375" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> </p>
<p>Feel free to use these slides if you&#8217;d like to give a similar presentation. Feel free to give it as is, as a starting point or ideas for your own presentation. I&#8217;d love it if you could link back to me, but this is all about getting people talking about writing maintainable CSS rather than anything else. </p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2011/01/31/ddd9-slides/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lego scrum board avatars</title>
		<link>http://helephant.com/2010/10/09/lego-scrum-board-avatars/</link>
		<comments>http://helephant.com/2010/10/09/lego-scrum-board-avatars/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 21:16:36 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Scrum]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1885</guid>
		<description><![CDATA[How we made our scrum board a little more fun by combining the geek loves of Lego and magnets. ]]></description>
				<content:encoded><![CDATA[<p>We&#8217;re having a bit of a Lego theme in our office at the moment with teams being given lego sets as prizes for doing good work. With all this Lego in the office, when I was chatting to another another developer about the scrum board we almost inevitably came up with the idea of using magnetic Lego people as team avatars. </p>
<p>Once we&#8217;d come up with the idea, I had to do it. So I shopped around on the internet for all the bits I needed, came into work with a creepy bag of Lego heads and we swapped our <a href="http://www.simpsonsmovie.com/main.html">Simpsons</a> avatars with new ones made out of lego. </p>
<p>Here are the avatars we came up with:<br />
<img src="http://helephant.com/wp-content/uploads/2010/10/helen.png"> <img src="http://helephant.com/wp-content/uploads/2010/10/mike.png"> <img src="http://helephant.com/wp-content/uploads/2010/10/justin.png"> <img src="http://helephant.com/wp-content/uploads/2010/10/dave.png"> <img src="http://helephant.com/wp-content/uploads/2010/10/vinny.png"> <img src="http://helephant.com/wp-content/uploads/2010/10/lauren.png"> <img src="http://helephant.com/wp-content/uploads/2010/10/jen.png"></p>
<h2>What you need to make your own scrum board Lego peeps</h2>
<ul>
<li>You can get a big bag of Lego magnets from <a href="http://www.amazon.com/gp/product/B002U2YG7E?ie=UTF8&#038;tag=helephantcom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B002U2YG7E">Amazon.com</a> or <a href="http://www.amazon.co.uk/gp/product/B0039YZ6TO?ie=UTF8&#038;tag=helensadvenin-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=B0039YZ6TO">Amazon.co.uk</a> for a couple of pounds.</li>
<li>You can buy lego heads, bodies, hair and accessories on <a href="http://www.bricklink.com/browseTree.asp?itemType=M">bricklink</a>. You don&#8217;t have to buy whole people, you can just buy the bits that you think your team might like. I got enough for my team for about £30. You can find female lego people if you hunt around.</li>
<li>A team of developers who aren&#8217;t too grown up to play Lego.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2010/10/09/lego-scrum-board-avatars/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Javascript method context</title>
		<link>http://helephant.com/2009/11/29/javascript-method-context/</link>
		<comments>http://helephant.com/2009/11/29/javascript-method-context/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 18:26:59 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[context]]></category>
		<category><![CDATA[firstclassfunctions]]></category>
		<category><![CDATA[javascriptobjects]]></category>
		<category><![CDATA[oo]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1646</guid>
		<description><![CDATA[In languages like C# and Java you never really need to give a thought to the <code>this</code> operator. In javascript things are a little more complicated due to functions being first class objects. ]]></description>
				<content:encoded><![CDATA[<p>In the <a href="http://helephant.com/2008/09/constructor-functions/">previous examples</a> you might have noticed that we use <code><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/this_Operator">this</a></code> to get a reference to the object that a function belongs to while we&#8217;re inside the function. The value of the <code>this</code> operator is the context of the method:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Pet<span class="br0">&#40;</span><span class="kw3">name</span>, species, hello<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw3">name</span> = <span class="kw3">name</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">species</span> = species;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">hello</span> = hello;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">sayHello</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hello</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Pet<span class="br0">&#40;</span><span class="st0">&quot;Rufus&quot;</span>, <span class="st0">&quot;cat&quot;</span>, <span class="st0">&quot;miaow&quot;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>If you&#8217;re familiar with languages like C# or Java, chances are you&#8217;ve never really thought too much about <code>this</code> because its value always references the object that the method belongs to (the rufus object in the previous example). This is usually the case in javascript too but there are some situations where it won&#8217;t refer back to the object that you&#8217;re expecting. </p>
<h2>Functions are first class objects</h2>
<p>The difference between way the <code>this</code> operator works in C# and javascript is a side effect of <a href="http://helephant.com/2008/08/functions-are-first-class-objects-in-javascript/">functions being first class objects</a> in javascript. Functions are just another type of variable that can be passed around the application.</p>
<p>The methods in a javascript object are only methods because you chose to store a function inside one of the object&#8217;s properties. There is nothing in the language that always binds the method to the object. If you wanted to, you could use the same function in a number of different objects:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> sayHello = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot; says hello&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">name</span>: <span class="st0">&quot;Rufus&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">sayHello</span> = sayHello;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> sabby = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">name</span>: <span class="st0">&quot;Sabby&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">sabby.<span class="me1">sayHello</span> = sayHello;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// invoke sayHello from the objects</span></div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">sayHello</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">sabby.<span class="me1">sayHello</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/10/context-object.html">Complete example</a></p>
<p>Notice that the context of the sayHello() function (the thing that <code>this</code> references) is different depending on which object invoked it. In this example the two different objects were pretty much the same but the sayHello() function could be used by completely different objects as long as they provide the right information. </p>
<p>This design decouples the function from the context that uses it. You can plug any context into the function and it will still work. This is one of the reasons that having functions as first class objects is such a powerful feature. </p>
<h2>Default context</h2>
<p>Every time you call a function it has a context even if it is not explicitly provided. If no context is explicitly provided when the function is called, the default context will be used instead. In the browser the default context is the window object. This means that if you call a function without invoking it through an object, <code>this</code> will be set to the window. </p>
<p>To see this in action lets try calling sayHello() without invoking it from an object:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> sayHello = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">if</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot; says hello&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">else</span> &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span> + <span class="st0">&quot; can&#39;t say hello because name property was not set&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// invoke sayHello from the global context</span></div>
</li>
<li class="li1">
<div class="de1">sayHello<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/10/context-default.html">Complete example</a></p>
<p>Javascript is happy to run the function without calling it through an object. It just sets the context to the default context, the window object. The window object doesn&#8217;t have a name property so instead of alerting &#8220;someone says hello&#8221;, instead it alerts the error message about the object not having a name property. </p>
<p>The way I imagine it is calling sayHello() is really calling window.sayHello(). You just don&#8217;t need to explicitly use the window object to invoke it because the window object is the default context. The same thing happens if you set a variable without declaring it first using the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statements/var">var statement</a>. Instead of creating a new variable that&#8217;s only available in the current scope, it actually creates a new property on the window object:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">flibble = <span class="st0">&quot;xyz&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>window.<span class="me1">flibble</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/11/context-default-context-property.html">Complete example</a></p>
<p>Check out <a href="http://www.jibbering.com/faq/faq_notes/closures.html#clExCon">this article</a> if you want to find out more about what happens when a Javascript function is called. It&#8217;s a really interesting write up that goes into lots of detail. </p>
<h2 id="objects-context-and-event-handlers">Objects, context and event handlers</h2>
<p>In the previous examples, we have explicitly called the sayHello() method ourselves. This doesn&#8217;t happen for functions that are used for event handlers. We wire them up and then they are invoked automatically when the event occurs. </p>
<p>This can be a problem for functions that actually are methods of objects. The logic that invokes the event handler doesn&#8217;t know anything about the object the method belongs to so it can&#8217;t be invoked in the right context. </p>
<p>Instead the context of the method is set to the element that caused the event. If it was a button click event, it will be set to the HTML button element that was clicked. It it is an onload event, it will be set to the element that was loaded. The exception to this rule is IE where the context will always be set to the default window context. </p>
<p>Here&#8217;s an example where the hello function of a rufus object is used for the onclick event of our button:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">name</span> : <span class="st0">&quot;Rufus&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; species: <span class="st0">&quot;cat&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; hello : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot; says miaow&quot;</span><span class="br0">&#41;</span>; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">&quot;button&quot;</span><span class="br0">&#41;</span>.<span class="me1">onclick</span> = rufus.<span class="me1">hello</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/10/context-event-handler.html">Complete example</a></p>
<p>If you&#8217;d never tried this before, you&#8217;d probably expect the <code>this</code> operator to still be set to the rufus object when the button is clicked so the output would be &#8220;Rufus says miaow&#8221;. Instead the <code>this</code> operator is set to the button that triggered the event. The button&#8217;s name property is set to &#8220;button&#8221; so the output is &#8220;button says miaow&#8221; (which is just silly, buttons don&#8217;t miaow).</p>
<h2>Changing the context using Function.apply() and Function.call()</h2>
<p>In cases like the event handler problem, you might want to invoke a method in an explicit context. Javascript functions support two methods that you can use to do this called <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/apply">Function.apply</a> and <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/call">Function.call</a>. </p>
<p>Both methods are pretty much the same. You can use them both to invoke a method, supply the context and a list of parameters. The only difference between the two are the way the parameters are passed in. Function.apply() accepts the parameters for the function as an array while Function.call() accepts them as individual parameters:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> sayHello = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot; says hello&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span> + <span class="st0">&quot; can&#39;t say hello because name property was not set&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">name</span>: <span class="st0">&quot;Rufus&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">sayHello.<span class="me1">call</span><span class="br0">&#40;</span>rufus<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">sayHello.<span class="me1">apply</span><span class="br0">&#40;</span>rufus<span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/10/context-call-apply.html">Complete example</a></p>
<h2>Using Function.call() to solve the event handler problem</h2>
<p>Remember the problem with <a href="#objects-context-and-event-handlers">using a method from an object as an event handler</a>? When the event is fired, the context of the event handler is set to the HTML element that triggered the event. Then when you access the <code>this</code> operator you get a reference to the HTML element rather than the object that you might have expected. </p>
<p>It&#8217;s possible to use Function.call() (or Function.apply() if you want) to invoke the event handler in the right context. The plan: create a custom function that wires up the event handler and knows what the context of the function should be when the event is run:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> addEvent<span class="br0">&#40;</span>element, eventName, handler, context<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> wrapper = handler;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>context<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// create an anonymous function </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// that uses a closure to access the context parameter</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// and then uses Function.call() to invoke the real event handler</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; wrapper = <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handler.<span class="me1">call</span><span class="br0">&#40;</span>context, e<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>element.<span class="me1">addEventListener</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; element.<span class="me1">addEventListener</span><span class="br0">&#40;</span>eventName, wrapper, <span class="kw2">false</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span>element.<span class="me1">attachEvent</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; element.<span class="me1">attachEvent</span><span class="br0">&#40;</span><span class="st0">&quot;on&quot;</span> + eventName, wrapper<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw3">name</span> : <span class="st0">&quot;Rufus&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;species: <span class="st0">&quot;cat&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;hello : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot; says miaow&quot;</span><span class="br0">&#41;</span>; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">addEvent<span class="br0">&#40;</span>document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">&quot;button&quot;</span><span class="br0">&#41;</span>, <span class="st0">&quot;click&quot;</span>, rufus.<span class="me1">hello</span>, rufus<span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/11/context-event-handler-apply.html">Complete example</a></p>
<p>This works because javascript has a feature called <a href="http://helephant.com/2008/08/javascript-anonymous-functions/">anonymous functions</a> that you can use to create a new function at runtime. The addEvent function uses this to create a new wrapper function that calls the event handler using Function.call(). The wrapper function is passed to addEventListener() instead of the event handler that was passed in as a parameter. </p>
<p>The wrapper function can access the context object when the event fires because of another javascript language feature called <a href="http://helephant.com/2008/10/javascript-closures/">closures</a>. When you create a function inside another function, closures mean that the inner function automatically has access to the local variables of the outer function (addEvent) when the inner function (wrapper) is called. This works even if the inner function is called after the outer function has finished running. </p>
<p>This is how the wrapper function can get hold of addEvent&#8217;s context and handler parameters when the anonymous function is run. </p>
<p>Mostly if you&#8217;re using a javascript framework, you don&#8217;t need to worry too much about this. The framework will look after it for you, usually in a way similar to this. For example, if you&#8217;re an ASP.NET ajax programmer, this is exactly what happens when you use Function.createDelegate() to register an event handler inside an component. </p>
<h2>What&#8217;s next?</h2>
<p>Sometimes you need to find out things about an object&#8217;s capabilities. The next article talks about finding out what type of object you have and what it can do. </p>
<p>This article is part of a set of related posts about <a href="/2008/08/how-javascript-objects-work/">How javascript objects work</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/11/29/javascript-method-context/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CSS3 Multiple background images</title>
		<link>http://helephant.com/2009/11/23/css3-multiple-background-images/</link>
		<comments>http://helephant.com/2009/11/23/css3-multiple-background-images/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 12:11:13 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[bleedingedgeofweb]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[multiplebackgrounds]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1694</guid>
		<description><![CDATA[How to use the CSS3 multiple background syntax to create complex, scalable and beautiful backgrounds for HTML elements. ]]></description>
				<content:encoded><![CDATA[<p>Multiple background images is a <a href="http://www.w3.org/TR/css3-background/">CSS3 feature</a> that makes it possible to create complex, scalable and beautiful webpages with light-weight, semantic HTML markup. </p>
<p>Multiple background images can make CSS and HTML simpler:</p>
<ul>
<li>It removes the need for elements just for styling. For example CSS sliding doors can be done with a single HTML element.</li>
<li>It makes it easy to create stretchy page elements that can be easily resized or dropped into different sized places in a website.</li>
<li>It empowers designers to be more daring because it&#8217;s easier to create CSS for complex designs</li>
</ul>
<p>This has <a href="http://caniuse.com/#feat=multibackgrounds">good browser support</a>. All the recent versions of Webkit, Firefox and Opera support it. It also works in IE9 or newer. </p>
<h2>Using multiple background images</h2>
<p>CSS3 supports more than one background image listed in the background CSS property. The syntax is otherwise is exactly the same as declaring a single background:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bottom.png&quot;</span><span class="br0">&#41;</span> <span class="kw2">repeat-x</span> <span class="kw1">bottom</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-image.png&quot;</span><span class="br0">&#41;</span> <span class="kw2">no-repeat</span> <span class="kw1">bottom</span> <span class="kw1">right</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bg.png&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/11/multiple-background-images.html">Complete example</a></p>
<p>The browser applies the images top to bottom, so the first one you declare will overlap any of the others. All the CSS background attributes are supported. </p>
<p>You could also list out each of the background attributes separately: </p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">background-image</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bottom.png&quot;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-image.png&quot;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bg.png&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">background-repeat</span><span class="sy0">:</span> <span class="kw2">repeat-x</span>, <span class="kw2">no-repeat</span>, <span class="kw2">repeat</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">background-position</span><span class="sy0">:</span> <span class="kw1">bottom</span>, <span class="kw1">bottom</span> <span class="kw1">right</span>, <span class="kw1">top</span> <span class="kw1">right</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<h2>Backwards compatibility</h2>
<p>Multiple background images degrade quite nicely in older browsers. You can supply a single background image before you declare the multiple background images and the browsers with support will show the multiple background images while the other browsers will just show the single one: </p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="coMULTI">/* you can put in a single background for browsers that don&#39;t support it */</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bg.png&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/* example using background short hand property */</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bottom.png&quot;</span><span class="br0">&#41;</span> <span class="kw2">repeat-x</span> <span class="kw1">bottom</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-image.png&quot;</span><span class="br0">&#41;</span> <span class="kw2">no-repeat</span> <span class="kw1">bottom</span> <span class="kw1">right</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bg.png&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/11/23/css3-multiple-background-images/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>IE6 absolute positioning in parent with odd width</title>
		<link>http://helephant.com/2009/09/07/ie6-absolute-positioning-in-parent-with-odd-width/</link>
		<comments>http://helephant.com/2009/09/07/ie6-absolute-positioning-in-parent-with-odd-width/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 06:00:52 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Browser quirks]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[absolute positioning]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[positioning]]></category>
		<category><![CDATA[right]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1666</guid>
		<description><![CDATA[A small browser quirk for IE6 where absolute positioning with the CSS right property is one pixel out when the parent container has an odd number of pixels.]]></description>
				<content:encoded><![CDATA[<p>One of the guys I work with found an interesting browser issue this week. He was using absolute positioning to position an element to the right of a box which was an odd number of pixels across. He noticed that in IE6 the child element was one pixel away from where it was in other browsers.</p>
<p><strong>In IE6</strong><strong><br />
<img src="http://www.helephant.com/wp-content/uploads/2009/09/relative-position-ie61.png" alt=""/></p>
<p></strong><strong>In IE7</strong><br />
<img src="http://www.helephant.com/wp-content/uploads/2009/09/relative-position-ie71.png" alt=""/></p>
<h2>Simple test case</h2>
<p>Here&#8217;s a simple example of the HTML:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;div id=&quot;container&quot;&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;div id=&quot;inside&quot;&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;/div&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
</ol>
</div>
<p>Here&#8217;s a simple example of the CSS:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re0">#container</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">position</span><span class="sy0">:</span> <span class="kw2">relative</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">301px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">200px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> pink<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">#inside</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">position</span><span class="sy0">:</span> <span class="kw2">absolute</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">20px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">20px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">right</span><span class="sy0">:</span> <span class="re3">0px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; _right<span class="sy0">:</span> &#8211;<span class="re3">1px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="kw2">yellow</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><a href="http://www.helephant.com/wp-content/uploads/2009/09/relative-position1.html">Complete example</a></p>
<h2>Workaround</h2>
<p>If you can&#8217;t use an even number of pixels for the width of the parent box, just to use the underscore IE6 hack to provide an adjusted right value just for IE6 that all the other browsers will ignore:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re0">#inside</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">position</span><span class="sy0">:</span> <span class="kw2">absolute</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">20px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">20px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">right</span><span class="sy0">:</span> <span class="re3">0px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; _right<span class="sy0">:</span> &#8211;<span class="re3">1px</span><span class="sy0">;</span> <span class="coMULTI">/* for IE6 */</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="kw2">yellow</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/09/07/ie6-absolute-positioning-in-parent-with-odd-width/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building javascript minification into MSBuild scripts</title>
		<link>http://helephant.com/2009/08/29/building-minification-into-msbuild-scripts/</link>
		<comments>http://helephant.com/2009/08/29/building-minification-into-msbuild-scripts/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 12:51:43 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[jsmin]]></category>
		<category><![CDATA[minification]]></category>
		<category><![CDATA[msbuild]]></category>
		<category><![CDATA[packer]]></category>
		<category><![CDATA[yui]]></category>
		<category><![CDATA[yui compressor]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1586</guid>
		<description><![CDATA[How to use a tool called Packer.NET to build javascript minification into a MSBuild script.]]></description>
				<content:encoded><![CDATA[<p>A while back when I had a play with javascript minification to speed up the download of a site I was working on I found a tool called <a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/">Packer.NET</a> that&#8217;s a ready made to work with MSBuild.</p>
<h2>Which algorithm to use?</h2>
<p>The minification tool supports <a href="http://www.crockford.com/javascript/jsmin.html">JSMin</a> and <a href="http://dean.edwards.name/packer/">Packer</a>.</p>
<p>JSMin just strips out the parts of the file that the browser won&#8217;t need like extra whitespace and comments. You can run JSMin over CSS and javascript.</p>
<p>Packer does the same sort of minification as JSMin but also has options to reduce variable names to single characters and to <a href="http://en.wikipedia.org/wiki/Base_62">base-62 encode</a> everything. Packer tends to give very small file sizes when you use the base-62 option but there&#8217;s a performance hit in the browser when it gets unpacked.  Packer will only run on javascript.</p>
<p>One thing is keep in mind is whether or not you&#8217;re using gzip compression. JSMin with gzip compression tends to give files that are almost the same as Packer but without the clientside performance hit of unpacking them. Gzip tends not to make as much of a difference to files minified with the base-62 encoding option.</p>
<p>A good way to find out which will be best is to run your particular script through the <a href="http://compressorrater.thruhere.net/">compressor comparison tool</a>.</p>
<h2>Using the tool</h2>
<p>Packer.NET comes as a single dll so you don&#8217;t need to install any command line programs to use it. I put the assembly into source control on our system so anyone who wanted to run the build script wouldn&#8217;t need to install it manually.</p>
<p>Here&#8217;s an example target that uses JSMin to minify all CSS files and all javascript files (except library files that are already minified). This example simply replaces the existing files:</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;import</span> <span class="re0">Project</span>=<span class="st0">&quot;$(MSBuildExtensionsPath)\SmallSharpTools.Packer\MSBuild.Packer.Targets&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;target</span> <span class="re0">Name</span>=<span class="st0">&quot;Minify&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="coMULTI">&lt;!&#8211; minify javascript and CSS &#8211;&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;itemgroup<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;javascript</span> <span class="re0">Include</span>=<span class="st0">&quot;$(SolutionRoot)\**\*.js&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Exclude</span>=<span class="st0">&quot;$(SolutionRoot)\**\*pack.js;&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;stylesheet</span> <span class="re0">Include</span>=<span class="st0">&quot;$(SolutionRoot)\**\*.css&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/itemgroup<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="coMULTI">&lt;!&#8211; http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki &nbsp;&#8211;&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;message</span> <span class="re0">Text</span>=<span class="st0">&#39;Minifying javascript: %(Javascript.FullPath) &#8230; &#39;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;packer</span> <span class="re0">OutputFileName</span>=<span class="st0">&quot;%(Javascript.FullPath)&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Mode</span>=<span class="st0">&quot;JSMin&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">InputFiles</span>=<span class="st0">&quot;%(Javascript.FullPath)&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Verbose</span>=<span class="st0">&quot;true&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Condition</span>=<span class="st0">&quot;Exists(%(Javascript.FullPath))&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;message</span> <span class="re0">Text</span>=<span class="st0">&#39;Minifying css: %(Stylesheet.FullPath) &#8230; &#39;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;packer</span> <span class="re0">OutputFileName</span>=<span class="st0">&quot;%(Stylesheet.FullPath)&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Mode</span>=<span class="st0">&quot;CSSMin&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">InputFiles</span>=<span class="st0">&quot;%(Stylesheet.FullPath)&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Verbose</span>=<span class="st0">&quot;true&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Condition</span>=<span class="st0">&quot;Exists(%(Stylesheet.FullPath))&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/target<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p>There&#8217;s <a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki">documentation</a> with more examples and details on the different options that the task supports.</p>
<h2>What about YUI compressor?</h2>
<p><a href="http://developer.yahoo.com/yui/compressor/">YUI compressor</a> is another good option for minifying javascript and CSS. There&#8217;s also <a href="http://www.coderjournal.com/2008/05/how-to-create-a-yui-compressor-msbuild-task/">an example MSBuild task</a> for that.</p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/08/29/building-minification-into-msbuild-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why I don&#039;t like reset stylesheets</title>
		<link>http://helephant.com/2009/08/23/why-i-dont-like-reset-stylesheet/</link>
		<comments>http://helephant.com/2009/08/23/why-i-dont-like-reset-stylesheet/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 17:37:25 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[reset stylesheet]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1598</guid>
		<description><![CDATA[I don't much like reset stylesheets. They make extra work when creating CSS and are an extra request for the browser to make to build a page.]]></description>
				<content:encoded><![CDATA[<p>Sometimes it&#8217;s hard to tell the difference between an idea that&#8217;s bad an idea that&#8217;s just different. Reset stylesheets have been one of those ideas for me but after working on a couple of different sites that use them I&#8217;ve decided I personally don&#8217;t like them.</p>
<p>The idea of a reset stylesheet is to strip the default style out of a webpage before you start to apply your design. This gives a predictable base for you to start with and removes browser inconsistencies with the default styles. There are a number of different reset stylesheet options. The most popular ones are from <a href="http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/">Eric Myer</a> and <a href="http://developer.yahoo.com/yui/reset/">YUI</a>.</p>
<p>Sounds like a great idea in theory. Slight browser inconsistencies (particularly with <a href="http://www.clagnut.com/blog/1287/">margins and padding</a>) are a pain to remember and can really mess up a design if you don&#8217;t test in multiple browsers.</p>
<h2>Why set the styles and then set them again?</h2>
<p>The big problem I have with it is how redundant it can be. The way I&#8217;ve seen reset stylesheets implemented is you include a reset stylesheet to reset everything to empty (including things like removing bold text from the &lt;strong&gt; tag) and then you create another stylesheet where you set all the styles that you want in the page.</p>
<p>It feels pretty redundant to have to set styles like bold text on the &lt;strong&gt; tag or numbered bullets on the ordered list. Most of the defaults make a lot of sense and most of them are pretty consistent between browsers.</p>
<p>It also feels kind of redundant to have the browser have to download and apply the reset styles and then download and apply the real styles. I haven&#8217;t actually ever seen a reset hurt the rendering time of a webpage but I have worked on a few sites where the number of requests that the browser was making became a problem and having the reset stylesheet as a separate request didn&#8217;t help.</p>
<h2>Why make me learn what the base styles are again?</h2>
<p>The other thing I don&#8217;t like about it is that the browser no longer acts the way I&#8217;d expect. I&#8217;ve got years of experience with how browsers render things and usually can picture in my head what a style should do to a page. Adding a reset stylesheet means that it&#8217;s not as intuitive any more.</p>
<h2>A better solution?</h2>
<p>I think a better solution would be using a stylesheet like <a href="http://developer.yahoo.com/yui/base/">YUI base</a> that makes browser defaults the same across different browsers as a starting point for your own stylesheet and then adding your own styles for the particular site. I don&#8217;t think I&#8217;d even bother setting a default style and then overriding, I think I&#8217;d prefer to just set the style once.</p>
<p>I think using something like the YUI base as a starting point is a great idea, but I think if I was going down this path I&#8217;d want to customize it as a I worked to make my own version to use on other sites.</p>
<h2>A tool I don&#8217;t like, but something worth thinking about</h2>
<p><a href="http://meyerweb.com/eric/thoughts/2008/04/17/crafting-ourselves/">Eric Myer&#8217;s response</a> to <a href="http://snook.ca/archives/html_and_css/no_css_reset/">people</a> <a href="http://meiert.com/en/blog/20080419/reset-style-sheets-are-bad/">questioning</a> whether reset stylesheets were a good idea or not was pretty much, use them if you find them useful and or don&#8217;t otherwise. I just wanted to put my hand up as not personally liking them (since they seem to be every at the moment) in the hope of making other people question them too.</p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/08/23/why-i-dont-like-reset-stylesheet/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Javascript prototype chaining</title>
		<link>http://helephant.com/2009/08/17/javascript-prototype-chaining/</link>
		<comments>http://helephant.com/2009/08/17/javascript-prototype-chaining/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 09:28:59 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[oo]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[prototypechain]]></category>
		<category><![CDATA[prototypechaining]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1252</guid>
		<description><![CDATA[Prototype chaining is used to build new types of objects based on existing ones. It has a very similar job to inheritance in a class based language.]]></description>
				<content:encoded><![CDATA[<p>Prototype chaining is used to build new types of objects based on existing ones. It has a very similar job to inheritance in a class based language.</p>
<p><a href="http://helephant.com/2008/09/constructor-functions/">Constructor functions</a> have a property called <a href="http://helephant.com/2009/01/javascript-object-prototype/">prototype</a>. Adding properties and methods to the prototype property will automatically add the method or property to all objects created by the constructor function.</p>
<p>Prototype chaining is an extension of this idea. The prototype property is just a regular javascript object so it&#8217;s possible to create a function&#8217;s prototype using another constructor function. When you do this, all of the properties and methods from the constructor function&#8217;s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function that builds objects that are an extended version of an existing one.</p>
<p>For a simple example, imagine that you have a Pet constructor to make pet objects. Now you want to make Cat that is pretty much like a Pet but has a few differences.</p>
<p>Here&#8217;s the Pet constructor function from the <a href="/2009/01/javascript-object-prototype/">prototype example</a>:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Pet<span class="br0">&#40;</span><span class="kw3">name</span>, species, hello<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw3">name</span> = <span class="kw3">name</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">species</span> = species;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">hello</span> = hello;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Pet.<span class="me1">prototype</span> = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; sayHello : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hello</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>We can give the cat all the properties of the Pet by setting it&#8217;s prototype to be a new pet object:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Cat<span class="br0">&#40;</span><span class="kw3">name</span>, hello, breed, whiskerLength<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw3">name</span> = <span class="kw3">name</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">species</span> = species;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">hello</span> = hello;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">breed</span> = breed;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">whiskerLength</span> = whiskerLength;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Cat.<span class="me1">prototype</span> = <span class="kw2">new</span> Pet<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Cat<span class="br0">&#40;</span><span class="st0">&quot;rufus&quot;</span>, <span class="st0">&quot;miaow&quot;</span>, <span class="st0">&quot;Maine Coon&quot;</span>, <span class="nu0">7</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">sayHello</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>This is not really any different to creating the prototype using object literal syntax. The only big difference is that instead of manually adding the methods to the object literal, the Pet&#8217;s prototype does most that work for us.</p>
<p>We can still extend the Cat objects by adding extra methods to the prototype. Any methods added to the cat prototype will only be available to objects created by the Cat constructor. Objects created by the Pet constructor will still only have the methods added directly to Pet:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">Cat.<span class="me1">prototype</span>.<span class="me1">catNap</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot;: zzzzz&#8230;&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">catNap</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>We can override any methods that came from the Pet constructor just by creating a new version of the function and assigning it to the Cat prototype. This will give cats different behaviour to the other pets:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">Cat.<span class="me1">prototype</span>.<span class="me1">sayHello</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hello</span> + <span class="st0">&quot; from a cat..&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">sayHello</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://www.helephant.com/wp-content/uploads/2009/08/prototype-chaining1.html">Complete example</a></p>
<h2>Function resolution</h2>
<p>The most important thing to understand when using prototype chaining is how the method resolution works. Method resolution is what happens when you call a method or property on an object. It&#8217;s how javascript figures out what method or property should really be called.</p>
<p>First javascript checks the object itself for the method. This is important because it means you can override any method from the prototype on any object. If we call rufus.avoidPhoto() in the following example, javascript will call the avoidPhoto() function that has been assigned directly to rufus:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Cat<span class="br0">&#40;</span><span class="st0">&quot;rufus&quot;</span>, <span class="st0">&quot;miaow&quot;</span>, <span class="st0">&quot;Maine Coon&quot;</span>, <span class="nu0">7</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">avoidPhoto</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Talk to my agent. &quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">avoidPhoto</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>If the object doesn&#8217;t have the method set directly on it, javascript then looks for a Constructor function that created the object. Javascript checks the constructor&#8217;s prototype property for the method. If we call rufus.catNap(), javascript will find the method on Cat.prototype and use it:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">Cat.<span class="me1">prototype</span>.<span class="me1">catNap</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot;: zzzzz&#8230;&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Cat<span class="br0">&#40;</span><span class="st0">&quot;rufus&quot;</span>, <span class="st0">&quot;miaow&quot;</span>, <span class="st0">&quot;Maine Coon&quot;</span>, <span class="nu0">7</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">catNap</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>If the constructor function&#8217;s prototype doesn&#8217;t have the method defined, javascript looks at what constructor function was used to create the prototype property and does the same thing again. It will keep walking the prototype chain until it finds a function that matches. If rufus.eat() is called in the following example, javascript will walk up the prototype chain until it gets to the Pet constructor&#8217;s prototype object and then use Pet&#8217;s eat() method:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">Pet.<span class="me1">prototype</span> = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="me1">eat</span> : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;nom! nom! nom!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Cat.<span class="me1">prototype</span> = <span class="kw2">new</span> Pet<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">..</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Cat<span class="br0">&#40;</span><span class="st0">&quot;rufus&quot;</span>, <span class="st0">&quot;miaow&quot;</span>, <span class="st0">&quot;Maine Coon&quot;</span>, <span class="nu0">7</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">eat</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>All objects ultimately have the Object constructor at the end of their prototype chain. This means any methods or properties added to the Object property are automatically available to all objects. Javascript libraries often use this to extend the javascript API.</p>
<p>In the previous example, if we called rufus.toString(), javascript would check the rufus object, then the Cat object, then the Pet object. The Pet object&#8217;s prototype was created with the Object constructor (using the object literal shortcut) so javascript would then find the toString() method  on the Object&#8217;s prototype.</p>
<h2>Walking the prototype chain</h2>
<p>In theory it&#8217;s possible to walk the prototype chain using an object&#8217;s constructor property. Each object has a property called constructor that holds a reference to the constructor method that created it. The constructor&#8217;s prototype property is just a regular object, so it also has a constructor property that points to the next constructor function in the chain:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Cat<span class="br0">&#40;</span><span class="st0">&quot;Rufus&quot;</span>, <span class="st0">&quot;miaow&quot;</span>, <span class="st0">&quot;maine coon&quot;</span>, <span class="nu0">12</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>rufus.<span class="me1">constructor</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>rufus.<span class="me1">constructor</span>.<span class="me1">prototype</span>.<span class="me1">constructor</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://www.helephant.com/wp-content/uploads/2009/08/prototype-chaining-constructor-broken1.html">Complete example</a></p>
<p>In theory the first alert statement will show the Cat constructor and the second will show the Pet constructor. In practise they both show the Pet constructor. This makes sense when you think about the prototype chaining behaviour. When you create the Cat&#8217;s prototype object, it&#8217;s constructor property will get set to Pet because it was created by the Pet constructor. When you look at the constructor property of the rufus object, rufus doesn&#8217;t have a value set explicitly on it so it looks for it on the Cat&#8217;s prototype object where it is set to Pet.</p>
<p>To fix the problem, you just need to set the constructor property explicitly on the  object itself when you create it:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Cat<span class="br0">&#40;</span><span class="kw3">name</span>, hello, breed, whiskerLength<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Pet.<span class="me1">call</span><span class="br0">&#40;</span><span class="kw1">this</span>, <span class="kw3">name</span>, <span class="st0">&quot;cat&quot;</span>, hello<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">breed</span> = breed;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">whiskerLength</span> = whiskerLength;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// needed because otherwise it will inherit the constructor</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// from pet</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">constructor</span> = Cat;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><a href="http://www.helephant.com/wp-content/uploads/2009/08/prototype-chaining-constructor1.html">Complete example</a></p>
<p>In mozilla based browsers each object exposes another property called <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object/proto">__proto__</a> that gives you access to the way that the browser tracks the prototype chaining. The __proto__ property is a reference to the prototype property of an object&#8217;s constructor from the object itself:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>rufus.__proto__ == Cat.<span class="me1">prototype</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>rufus.__proto__.__proto__ == Pet.<span class="me1">prototype</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://www.helephant.com/wp-content/uploads/2009/08/prototype-chaining-proto1.html">Complete example</a></p>
<p>This property is not supported across all browsers, so it&#8217;s not very useful when writing code but it can be very useful when debugging because it lets you take a peak at what the browser is actually doing.</p>
<p>If you come from a class based language you might be tempted to use the prototype chain to figure out what type an object is. The properties and methods of a javascript object can be modified after the object is created, so knowing about the constructor is no guarantee that the object will conform to a particular interface. You may choose to make your code work this way by convention but it&#8217;s important to remember that it is not enforced by the language itself.</p>
<p>I think it&#8217;s also worth considering that this is not really the javascript way of doing things. In javascript you don&#8217;t get static types, instead you use duck typing to ask an object what it can do. It&#8217;s important to use javascript&#8217;s strengths as a dynamic language with features like <a href="http://helephant.com/2008/08/functions-are-first-class-objects-in-javascript/">first class functions</a>, <a href="http://helephant.com/2008/10/javascript-closures/">closures</a> and <a href="http://helephant.com/2008/08/javascript-anonymous-functions/">anonymous functions</a> to write concise and modular code rather than trying to make it act like a different type of language.</p>
<h2>What&#8217;s next?</h2>
<p>In languages like C# and Java you never really need to give a thought to the this operator. In javascript things are a little more complicated due to functions being first class objects. The next article talks about <a href="http://helephant.com/2009/11/javascript-method-context/">javascript method context</a>.</p>
<p>This article is part of a set of related posts about <a href="/2008/08/how-javascript-objects-work/">How javascript objects work</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/08/17/javascript-prototype-chaining/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SVG images as CSS backgrounds</title>
		<link>http://helephant.com/2009/08/12/svg-images-as-css-backgrounds/</link>
		<comments>http://helephant.com/2009/08/12/svg-images-as-css-backgrounds/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 12:00:28 +0000</pubDate>
		<dc:creator><![CDATA[Helen Emerson]]></dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[background-image]]></category>
		<category><![CDATA[background-size]]></category>
		<category><![CDATA[bleedingedgeofweb]]></category>
		<category><![CDATA[contain]]></category>
		<category><![CDATA[cover]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[eps]]></category>
		<category><![CDATA[inkscape]]></category>
		<category><![CDATA[rounded corners]]></category>
		<category><![CDATA[svg]]></category>
		<category><![CDATA[vector]]></category>
		<category><![CDATA[viewbox]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1506</guid>
		<description><![CDATA[SVG images are an interesting options for CSS backgrounds because they're small to download, easy to create and have many powerful features that aren't possible using CSS3 alone.]]></description>
				<content:encoded><![CDATA[<p>One neat use of SVG images is to use them as CSS backgrounds. SVG images are small to download, easy to create and have many powerful features that aren&#8217;t possible using CSS3 alone, so they are an interesting option when creating complex scalable background images for HTML elements. </p>
<p>They now have <a href="http://caniuse.com/#feat=svg-css">pretty good browser support</a>. Using SVG as background images is supported by all the recent version of the desktop browsers and IE9+. </p>
<p>SVG are great option to:</p>
<ul>
<li>Use the same image in containers with varying width and height. They are a much better solution than downloading multiple sliding door images or using sprites.</li>
<li>Support multiple resolutions for responsive design, zoom or printing.</li>
<li>Change the styling of the images using CSS &#8211; the styling can even live in your main stylesheet.</li>
<li>Dynamically generate images with a server side language since it is a text format that is fast and easy to generate.</li>
<li>Need a large image with a small file size because unlike a raster image, a vector image&#8217;s file size only gets larger as the image becomes more complicated, not as the width and height increase.</li>
<li>Create a complicated background that uses advanced SVG features not supported by CSS3.</li>
</ul>
<h2>Using SVG images in CSS</h2>
<p>Using a SVG is exactly the same as using a regular image:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1">a <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">background-image</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="re4">svg-css-background<span class="re1">.svg</span></span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><img src="http://www.helephant.com/wp-content/uploads/2009/08/svg-tabs1.png" alt="tabs with SVG as background image"/><br />
<a href="http://helephant.com/wp-content/uploads/2009/08/svg-css-background.html">See complete example</a></p>
<h2>Background-sizing</h2>
<p>There is a new CSS3 property called <a href="https://developer.mozilla.org/en-US/docs/CSS/background-size">background-size</a> that adjusts how the background image is displayed on the HTML element. The background-size property can take width and height values, or the contains or cover keywords. </p>
<p>Contains means that the background will be sized so the whole image will be displayed. If the aspect ratio of the image isn&#8217;t the same as the aspect ratio of the element, the image will either tile or empty space will be displayed. </p>
<p>Cover means that the background will be sized so the whole HTML element is covered. If the aspect ratio of the image isn&#8217;t the same as the element, some of the image will be cropped. </p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1">a <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">background-image</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="re4">svg-css-background<span class="re1">.svg</span></span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; background-<span class="kw1">size</span><span class="sy0">:</span> cover<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<h2>Creating SVG images that will fit any container</h2>
<p>If the SVG image has width and height or viewbox (aspect ratio) information in it, the browser will respect the image&#8217;s aspect ratio:</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;svg</span> <span class="re0">xmlns:dc</span>=<span class="st0">&quot;http://purl.org/dc/elements/1.1/&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">xmlns:svg</span>=<span class="st0">&quot;http://www.w3.org/2000/svg&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">xmlns</span>=<span class="st0">&quot;http://www.w3.org/2000/svg&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">xmlns:xlink</span>=<span class="st0">&quot;http://www.w3.org/1999/xlink&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">width</span>=<span class="st0">&quot;200&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">height</span>=<span class="st0">&quot;50&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">viewBox</span>=<span class="st0">&quot;0 0 200 50&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/svg<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p>To make an image that will be scaled fit into any space without worrying about aspect ratio, set the width and the height to 100%:</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;svg</span> <span class="re0">xmlns:dc</span>=<span class="st0">&quot;http://purl.org/dc/elements/1.1/&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">xmlns:svg</span>=<span class="st0">&quot;http://www.w3.org/2000/svg&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">xmlns</span>=<span class="st0">&quot;http://www.w3.org/2000/svg&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">xmlns:xlink</span>=<span class="st0">&quot;http://www.w3.org/1999/xlink&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">width</span>=<span class="st0">&quot;100%&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">height</span>=<span class="st0">&quot;100%&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/svg<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p>This is particularly useful for making reusable, stretchy, resizable backgrounds for things like tabs, buttons and content boxes. </p>
<p>Mozilla have some <a href="https://developer.mozilla.org/en-US/docs/CSS/Scaling_of_SVG_backgrounds">detailed information</a> about how Firefox figures out how to display your image.</p>
<h2>Issues with scaling</h2>
<p>Right now in 2013 Firefox has some <a href="http://dbushell.com/2012/03/11/svg-all-fun-and-games/">issues scaling up SVG images</a>. </p>
<p>This is because they create a bitmap of the image from the SVG and don&#8217;t redrawing it in certain situations where you want it bigger than its original size like when you set the image size using the CSS background-size property or when you use the browser to zoom into the image.<br />
<img src="http://helephant.com/wp-content/uploads/2009/08/svg-css-anti-aliasing-issue.png" /> </p>
<p>The way to work around this is to set the width and height of the image inside the SVG larger than you actually need it so it won&#8217;t lose detail when zoomed. The disadvantage is it will take up more memory, which could be a particular issue on mobile devices. </p>
<p>There are also similar issues with <a href="http://benfrain.com/svg-backgrounds-dont-zoom-correctly-in-internet-explorer-10/">IE10</a>.</p>
<h2>Creating the SVG image</h2>
<p>SVG images are just text so you can create them in any text editor. There are also heaps of <a href="http://en.wikipedia.org/wiki/Svg#Software_and_support_in_applications">tools to that create SVG images</a>. <a href="http://www.inkscape.org/">Inkscape</a> is quite a nice open source tool to use or if you have Adobe software, you could use Illustrator.</p>
<p>The SVG file that your tool creates might not be particularly optimised, so you can run it through an <a href="http://petercollingridge.appspot.com/svg_optimiser">optimiser</a> if file size is important to you.</p>
<p>If you  have EPS files that you want to convert to SVG, it&#8217;s possible to get Inkspace to import EPS directly, but you need to get a library called <a href="http://pages.cs.wisc.edu/~ghost/">Ghostscript</a> working. Another way is to convert the EPS file to PDF and then import that. On a Mac this can be done by opening the EPS file up in Preview and then saving as a PDF. </p>
]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/08/12/svg-images-as-css-backgrounds/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
