<?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>Lapegna.com &#187; Web Development</title>
	<atom:link href="http://www.lapegna.com/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lapegna.com</link>
	<description>Thoughts + Ideas + Code from a mobile game dev</description>
	<lastBuildDate>Wed, 02 Nov 2011 13:36:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Seting up a Virtual Host in Apache 2.2</title>
		<link>http://www.lapegna.com/2010/07/seting-up-a-virtual-host-in-apache-2-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=seting-up-a-virtual-host-in-apache-2-2</link>
		<comments>http://www.lapegna.com/2010/07/seting-up-a-virtual-host-in-apache-2-2/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 18:35:24 +0000</pubDate>
		<dc:creator>joey</dc:creator>
				<category><![CDATA[Geeky]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.lapegna.com/?p=47</guid>
		<description><![CDATA[The following steps will help you setup a virtual domain on apache 2.2 on Windows. Steps are very similar for OS X, only the location of the files will change. In these steps I&#8217;ve used cowabunga.localhost as a test. The .localhost TLD is reserved for testing, so you can be guaranteed it won&#8217;t interfere with [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.lapegna.com%2F2010%2F07%2Fseting-up-a-virtual-host-in-apache-2-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.lapegna.com%2F2010%2F07%2Fseting-up-a-virtual-host-in-apache-2-2%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>The following steps will help you setup a virtual domain on apache 2.2 on Windows. Steps are very similar for OS X, only the location of the files will change.</p>
<p>In these steps I&#8217;ve used cowabunga.localhost as a test. The .localhost <acronym title="Top-Level-Domain">TLD is reserved</acronym> for testing, so you can be guaranteed it won&#8217;t interfere with any real websites. This is the best practice to follow, if you create a virtual host of cowabunga.com, you will not be able to reach the real version of that site.</p>
<ol>
<li>Edit httpd.conf</li>
<li>Uncomment the line Include conf/extra/httpd-vhosts.conf. Right after # Virtual hosts</li>
<li>Add the following above # Virtual hosts (replace C:\www with the path to your web root). Close and save it when done.</li>
</ol>
<pre>&lt;Directory "C:/www"&gt;
 Order Deny,Allow
 Allow from all
&lt;/Directory&gt; 
</pre>
<ol>
<li>We&#8217;ll setup the follow virtual host site.
<ol>
<li>cowabunga (C:\www\cowabunga). We&#8217;ll access this in the browser as cowabunga.localhost.</li>
</ol>
</li>
<li>Edit httpd-vhosts.conf (located in apache root/conf/etc/)</li>
<li>Add the following to the bottom of httpd-vhosts.conf. Close and save it when done.</li>
</ol>
<pre>&lt;VirtualHost *:80&gt;
DocumentRoot "C:/www/cowabunga"
ServerName cowagunga.localhost
&lt;/VirtualHost&gt;

&lt;VirtualHost *:80&gt;
DocumentRoot "C:/www/"
ServerName localhost
&lt;/VirtualHost&gt;
</pre>
<ol>
<li>That&#8217;s it for apache configuration. It&#8217;s now ready to host the virtual domain. We just need to tell Windows to go to our virtual host, rather than looking up the DNS.</li>
<li>Edit your <a href="http://en.wikipedia.org/wiki/Hosts_(file)">&#8220;hosts&#8221;</a> file. Available in one of the following places
<ol>
<li>Windows 95, 98, ME: Windows directory</li>
<li>NT, 2000, XP, 2003, Vista, 7: Windows folder\system32\drivers\etc\</li>
<li>Mac OS X, iOS: /private/etc/hosts or /etc/hosts</li>
</ol>
</li>
<li>Add the following line to the end of hosts. Close and save it when done.</li>
</ol>
<pre>127.0.0.1    burgess.localhost
127.0.0.1    localhost
</pre>
<ol>
<li>Restart apache from the GUI or the command prompt using:</li>
</ol>
<pre>apache -w -n "Apache" -k restart</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lapegna.com/2010/07/seting-up-a-virtual-host-in-apache-2-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Animated scroll to internal links in JavaScript</title>
		<link>http://www.lapegna.com/2010/07/animated-scroll-to-internal-links-in-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=animated-scroll-to-internal-links-in-javascript</link>
		<comments>http://www.lapegna.com/2010/07/animated-scroll-to-internal-links-in-javascript/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 19:34:03 +0000</pubDate>
		<dc:creator>joey</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.lapegna.com/?p=42</guid>
		<description><![CDATA[Usually, I&#8217;m a big fan of UI libraries like jQuery and YUI. Don&#8217;t really like to re-invent the wheel. This is a function that&#8217;s quite easy to do in either of those libraries. Unfortunately, I&#8217;m working on a project right now with very strict guidelines on it&#8217;s code, so it turns out I am unable [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.lapegna.com%2F2010%2F07%2Fanimated-scroll-to-internal-links-in-javascript%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.lapegna.com%2F2010%2F07%2Fanimated-scroll-to-internal-links-in-javascript%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Usually, I&#8217;m a big fan of UI libraries like jQuery and YUI. Don&#8217;t really like to re-invent the wheel. This is a function that&#8217;s quite easy to do in either of those libraries.</p>
<p>Unfortunately, I&#8217;m working on a project right now with very strict guidelines on it&#8217;s code, so it turns out I am unable to use any JavaScript UI Libraries. So, I set forth on putting this together.</p>
<p>There were a few resources I used that came in handy to create this, and I&#8217;ve given credit to those folk at the end of this post.</p>
<h2>Part one: setInternalLinks</h2>
<p>Run this function on page load. I use Simon Willison&#8217;s <a href="http://simonwillison.net/2004/May/26/addLoadEvent/" target="_blank">addLoadEvent</a> to do this. It will search for all internal links on your page, and add a click listener to the animation function scrollToYOffset.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
* setInternalLinks
* Searches the page for any internal links and converts them to animated automatic scrolls
*/</span>
<span style="color: #003366; font-weight: bold;">function</span> setInternalLinks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// grab all anchor links on the page</span>
	<span style="color: #003366; font-weight: bold;">var</span> anchors <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> anchors.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> anchors<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">href</span> <span style="color: #339933;">&amp;&amp;</span> a.<span style="color: #660066;">href</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span>  <span style="color: #006600; font-style: italic;">// href has #</span>
		   <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">pathname</span> <span style="color: #339933;">==</span> location.<span style="color: #660066;">pathname</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/'</span> <span style="color: #339933;">+</span> a.<span style="color: #660066;">pathname</span> <span style="color: #339933;">==</span> location.<span style="color: #660066;">pathname</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// path name of url is same as current</span>
		   <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">search</span> <span style="color: #339933;">==</span> location.<span style="color: #660066;">search</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// query string of url is same as current</span>
			<span style="color: #003366; font-weight: bold;">var</span> aName <span style="color: #339933;">=</span> a.<span style="color: #660066;">href</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> a.<span style="color: #660066;">href</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			a.<span style="color: #660066;">onclick</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// checks if the caller event e exists and grabs the target (mozilla + webkit). Grabs the IE equivalent if not.</span>
				<span style="color: #003366; font-weight: bold;">var</span> target <span style="color: #339933;">=</span> e <span style="color: #339933;">?</span> e.<span style="color: #660066;">target</span> <span style="color: #339933;">:</span> event.<span style="color: #660066;">srcElement</span><span style="color: #339933;">;</span>
				<span style="color: #006600; font-style: italic;">// the anchor name</span>
				<span style="color: #003366; font-weight: bold;">var</span> anchorName <span style="color: #339933;">=</span> target.<span style="color: #660066;">hash</span><span style="color: #339933;">;</span>
				<span style="color: #006600; font-style: italic;">// cut out the hash mark</span>
				anchorName <span style="color: #339933;">=</span> anchorName.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> anchorName.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #006600; font-style: italic;">// grab all the anchors on the page again</span>
				anchors <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> j <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> anchors.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>anchors<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">==</span> anchorName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #006600; font-style: italic;">// found the right anchor. scroll to it!</span>
						scrollToYOffset<span style="color: #009900;">&#40;</span>anchors<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">offsetTop</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Part two: scrollToYOffset</h2>
<p>The method below is called by an onclick handler added by the setInternalLinks method. It&#8217;s a time-based animation with sinusoidal easing. Smooth and quick.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
* scrollToOffset
*
* @param yOffset	The vertical offset to scroll to
*/</span>
<span style="color: #003366; font-weight: bold;">function</span> scrollToYOffset<span style="color: #009900;">&#40;</span>iTargetY<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// if the target is negative set it to 0</span>
	iTargetY <span style="color: #339933;">=</span> iTargetY <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">?</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">:</span> iTargetY<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> frameInterval <span style="color: #339933;">=</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 20 milliseconds per frame</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> totalTime <span style="color: #339933;">=</span> <span style="color: #CC0000;">750</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">// current scroll position: checks if window.pageYOffset exists (webkit + mozilla). If not, set's it to the IE equivalent</span>
	<span style="color: #003366; font-weight: bold;">var</span> startY <span style="color: #339933;">=</span> window.<span style="color: #660066;">pageYOffset</span> <span style="color: #339933;">?</span> window.<span style="color: #660066;">pageYOffset</span> <span style="color: #339933;">:</span> window.<span style="color: #660066;">document</span>.<span style="color: #660066;">body</span>.<span style="color: #660066;">scrollTop</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> d <span style="color: #339933;">=</span> iTargetY <span style="color: #339933;">-</span> startY<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// total distance to scroll</span>
	<span style="color: #003366; font-weight: bold;">var</span> freq <span style="color: #339933;">=</span> Math.<span style="color: #660066;">PI</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span> <span style="color: #339933;">*</span> totalTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// frequency</span>
	<span style="color: #003366; font-weight: bold;">var</span> startTime <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> tmr <span style="color: #339933;">=</span> setInterval<span style="color: #009900;">&#40;</span>
		<span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">// check the time that has passed from the last frame</span>
			<span style="color: #003366; font-weight: bold;">var</span> elapsedTime <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> startTime<span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>elapsedTime <span style="color: #339933;">&lt;</span> totalTime<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// are we there yet?</span>
				<span style="color: #003366; font-weight: bold;">var</span> f <span style="color: #339933;">=</span> Math.<span style="color: #660066;">abs</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">sin</span><span style="color: #009900;">&#40;</span>elapsedTime <span style="color: #339933;">*</span> freq<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				window.<span style="color: #660066;">scrollTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>f<span style="color: #339933;">*</span>d<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> startY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				clearInterval<span style="color: #009900;">&#40;</span>tmr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				window.<span style="color: #660066;">scrollTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> iTargetY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #339933;">,</span> frameInterval<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Above code has been tested in Firefox 3.6.6, Safari 5 and IE 7.</p>
<p>Credit for some help: <a href="http://articles.sitepoint.com/article/scroll-smoothly-javascript" target="_blank">Sitepoint: Make Internal Links Scroll Smothly with JavaScript</a> and <a href="http://cross-browser.com/x/examples/animation_tech.php" target="_blank">Cross-Browser.com: Animation Techniques</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lapegna.com/2010/07/animated-scroll-to-internal-links-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

