<?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>Chris Upjohn</title>
	<atom:link href="http://www.chrisupjohn.me/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisupjohn.me</link>
	<description>Personal Blog &#38; Portfolio</description>
	<lastBuildDate>Sat, 17 Nov 2012 16:01:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Dumb Ways To Die by Metro Trains</title>
		<link>http://www.chrisupjohn.me/blog/dumb-ways-to-die-by-metro-trains/</link>
		<comments>http://www.chrisupjohn.me/blog/dumb-ways-to-die-by-metro-trains/#comments</comments>
		<pubDate>Sat, 17 Nov 2012 16:01:39 +0000</pubDate>
		<dc:creator>Chris Upjohn</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[YouTube]]></category>
		<category><![CDATA[die]]></category>
		<category><![CDATA[dumb]]></category>
		<category><![CDATA[metro trains]]></category>

		<guid isPermaLink="false">http://www.chrisupjohn.me/?p=705</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<p><iframe src="https://www.youtube.com/embed/IJNR2EpS0jw" frameborder="0" width="600" height="338"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisupjohn.me/blog/dumb-ways-to-die-by-metro-trains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter announces the next major API update</title>
		<link>http://www.chrisupjohn.me/blog/twitter-announces-the-next-major-api-update/</link>
		<comments>http://www.chrisupjohn.me/blog/twitter-announces-the-next-major-api-update/#comments</comments>
		<pubDate>Fri, 17 Aug 2012 04:23:57 +0000</pubDate>
		<dc:creator>Chris Upjohn</dc:creator>
				<category><![CDATA[Social Networking]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.chrisupjohn.me/?p=683</guid>
		<description><![CDATA[So this is going to be a very quick insight into what Twitter are doing in their next ...]]></description>
				<content:encoded><![CDATA[<p>So this is going to be a very quick insight into what Twitter are doing in their next update of the public API, so to get straight into it here are some key points:</p>
<ol>
<li>All calls to the API must now use the oAuth authentication as all areas of the API will be on lock down</li>
<li>Desktop based clients that make use of the API will be restricted to 100, 000 unless they receive special permission to continue making API connections</li>
<li>The display guidelines have changed so any developer making a clone of what the tweet view looks like needs to follow the guide now</li>
</ol>
<p>So that&#8217;s just a very brief overview but the one I really got interested about was the API limit for desktop clients, for a long time now they have given us the freedom of seamlessly going between the website and viewing tweets directly on our desktop by removing a lot of the crud that we didn&#8217;t need to see so we got the best experience possible. This has worked for millions of users for a long time but now Twitter want&#8217;s to restrict the amount of calls a single application can make to their API regardless of which platform you use the app on, for us as the consumer of the product(s) we might think it doesn&#8217;t affect us but you would be wrong.<span id="more-683"></span></p>
<p>Twitter is going to throttle apps so only about <span style="text-decoration: underline;">200, 000</span> users will be able to use their favourite app on their iDevice, Android, tablet, desktop etc&#8230; See the below for how this is going to work:</p>
<ul>
<li>If an existing application already has 100, 000+ users they will be allowed to continue growing until they reach 200% or 200, 000 users</li>
<li>If a new or existing application has less then 100, 000 users but reach that limit they will need to request from Twitter directly in order to allow extra users to use the app</li>
<li>If an application hits 200, 000 users then we are all screwed as I can only see Twitter saying no more or asking for a monthly fee to continue allowing extra connections but who know what will happen</li>
</ul>
<p>So that&#8217;s pretty much my rant for what will I think make Twitter an unpopular site to visit now that <a href="http://www.app.net" target="_blank">app.net</a> has been launched, I say stay tuned into their blogged as I dislike visiting browser based websites if they have an easily accessible application that I can use on my iPhone and Macbook Pro.</p>
<p>See the full overhaul article here: <a href="https://dev.twitter.com/blog/changes-coming-to-twitter-api">https://dev.twitter.com/blog/changes-coming-to-twitter-api</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisupjohn.me/blog/twitter-announces-the-next-major-api-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Call of Duty: Black Ops 2 MP Trailer</title>
		<link>http://www.chrisupjohn.me/blog/call-of-duty-black-ops-2-mp-trailer/</link>
		<comments>http://www.chrisupjohn.me/blog/call-of-duty-black-ops-2-mp-trailer/#comments</comments>
		<pubDate>Fri, 10 Aug 2012 15:14:09 +0000</pubDate>
		<dc:creator>Chris Upjohn</dc:creator>
				<category><![CDATA[Black Ops]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[black ops]]></category>
		<category><![CDATA[cod]]></category>

		<guid isPermaLink="false">http://www.chrisupjohn.me/?p=680</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<p><iframe src="https://www.youtube.com/embed/Dre21lBu2zU" frameborder="0" width="600" height="338"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisupjohn.me/blog/call-of-duty-black-ops-2-mp-trailer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery 1.8.0 is here</title>
		<link>http://www.chrisupjohn.me/blog/jquery-1-8-0-is-here/</link>
		<comments>http://www.chrisupjohn.me/blog/jquery-1-8-0-is-here/#comments</comments>
		<pubDate>Thu, 09 Aug 2012 23:38:41 +0000</pubDate>
		<dc:creator>Chris Upjohn</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Updates]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[updates]]></category>

		<guid isPermaLink="false">http://www.chrisupjohn.me/?p=678</guid>
		<description><![CDATA[Its always a great morning when you find out a fantastic library such as jQuery has been updated ...]]></description>
				<content:encoded><![CDATA[<p>Its always a great morning when you find out a fantastic library such as jQuery has been updated to a new version with more benefits and much better performance overall, it offers a lot of handy improvements to help all of us as developers including a re-architected version of the Sizzle engine which drives the most powerful JavaScript selector engine I personally have ever used.</p>
<p>Other features include vendor prefixed properties so no longer do we have to do things like:</p>
<pre class="brush: jscript; title: ; notranslate">$('element').css({
    '-webkit-transform' : 'rotate(90deg)',
    '-moz-transform'    : 'rotate(90deg)',
    '-ms-transform'     : 'rotate(90deg)',
    '-o-transform'      : 'rotate(90deg)',
    'transform'         : 'rotate(90deg)'
});</pre>
<p>Now all we need to do is this:</p>
<pre class="brush: jscript; title: ; notranslate">$('element').css('transform', 'rotate(90deg)');</pre>
<p>I think this feature alone will make my life easier since now I won&#8217;t need to contend with un-needed overhead that otherwise slowed down performance, for a full list of changes, fixes and new features see the following url.</p>
<p><a href="http://blog.jquery.com/2012/08/09/jquery-1-8-released/">http://blog.jquery.com/2012/08/09/jquery-1-8-released/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisupjohn.me/blog/jquery-1-8-0-is-here/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My initial thoughts about SASS</title>
		<link>http://www.chrisupjohn.me/blog/my-initial-thoughts-about-sass/</link>
		<comments>http://www.chrisupjohn.me/blog/my-initial-thoughts-about-sass/#comments</comments>
		<pubDate>Sat, 21 Jul 2012 17:15:58 +0000</pubDate>
		<dc:creator>Chris Upjohn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[sass]]></category>

		<guid isPermaLink="false">http://www.chrisupjohn.me/?p=671</guid>
		<description><![CDATA[I like many others are always looking towards new ways to improve our workflow habit&#8217;s so we can ...]]></description>
				<content:encoded><![CDATA[<p>I like many others are always looking towards new ways to improve our workflow habit&#8217;s so we can cut down on our development time making our day-to-day job much more enjoyable for us and keeps our clients happy, one new technology that has been a big hit for pretty much the last two years now is preprocessors for CSS which can be explained by the following quote by Wikipedia.</p>
<blockquote><p>In <a title="Computer science" href="http://en.wikipedia.org/wiki/Computer_science">computer science</a>, a <strong>preprocessor</strong> is a <a title="Computer program" href="http://en.wikipedia.org/wiki/Computer_program">program</a> that processes its input data to produce output that is used as input to another program. The output is said to be a <strong>preprocessed</strong> form of the input data, which is often used by some subsequent programs like <a title="Compiler" href="http://en.wikipedia.org/wiki/Compiler">compilers</a>.</p></blockquote>
<p>We can take advantage of these preprocessors by making simple and advanced maths that normally we couldn&#8217;t if we used a plain old <strong><code>.css</code></strong> file, because of these advantages we can also extend the abilities the compilers can manage allowing for the most efficient style sheet a developer could ever hope for.</p>
<p><span id="more-671"></span></p>
<p>To jump straight into it i would have to say on a personal level SASS along with Compass are 2 of the most powerful technologies i have ever used for my development, I say this with high confidence as for the last 6 months i have been using LESS which like SASS allows for a simple way of writing your CSS in a way which improves your workflow. If you were to compare SASS and LESS that might look the same at first glance but as you go through what seems like endless layers you will find SASS to be the most powerful preprocessor currently available to developers even without Compass.</p>
<p>See the following for some of the features which i have already used that have made my life easier thus far:</p>
<ul>
<li>Mixins</li>
<li>Variables</li>
<li>Functions</li>
<li>Better imports</li>
<li>Includes</li>
<li>Interpolation for variables</li>
<li>For, while and foreach loops</li>
</ul>
<p>I know that LESS supports some of these features as well and if your project only requires things such as mixins and variables then that would be fine for small projects but from a long term perspective <strong>SASS + Compass</strong> will suit any project, see the following which are some basic CSS examples using SASS and Compass together.</p>
<pre class="brush: css; title: ; notranslate">#container {
    background-color: red;
    padding: 10px;

    h1 &amp; {
        color: red;
    }
}</pre>
<p>This would generate the following output:</p>
<pre class="brush: css; title: ; notranslate">#container {
    background-color: red;
    padding: 10px;
}

#container h1 {
    color: red;
}</pre>
<p>To explain how you actually get this result you first need to understand what the ampersand means when we write something like <code>h1 &amp;</code>, in SASS we can use the following syntax two ways as it means two different things based on where you put the ampersand. The above example shows we define a h1 selector and declare the ampersand which in this case inherits the parent selector we nested the h1 in, if you have followed along so far you have worked out that <code>#container</code> is the magic parent in the example.</p>
<p>See the below which explains the second way you can use the ampersand:</p>
<pre class="brush: css; title: ; notranslate">a {
    color: red;
    text-decoration: none;

    &amp;:hover {
        text-decoration: underline;
    }
}</pre>
<p>And the result will be:</p>
<pre class="brush: css; title: ; notranslate">a {
    color: red;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}</pre>
<p>Looking at both examples now there isn&#8217;t any different apart from the way the syntax works, when we use the ampersand before a pseudo selector/element it SASS automatically knows to inherit the parent before it where as if we define the ampersand part way down the nested selector it inherit the parent selector allowing us to create much short selectors in our SASS and SCSS files. Now that you have a grasp on this really cool feature I&#8217;ll show you a couple of more of my favourites which are interpolated variables and for loops.</p>
<pre class="brush: css; title: ; notranslate">@for $i from 1 to 3 {
    $size: $i * 10;

    .font-size-#{$size} {
        font-size: #{$size}px;
    }
}</pre>
<p>Now before you jump the gun and say this will result in 3 selectors you would be wrong, when we use <em>&#8220;to&#8221;</em> in SASS it looks at the first parameter we give it and the second parameter and only loops between them which will only result in 2 selectors. See the below:</p>
<pre class="brush: css; title: ; notranslate">.font-size-10 {
    font-size: 10px;
}

.font-size-20 {
    font-size: 20px;
}</pre>
<p>If you want 3 selectors to be output in your CSS then instead of <em>&#8220;to&#8221;</em> we can use <em>&#8220;through&#8221;</em> which goes from 1 through 3 but takes one extra step to get the third selector we would expect, moving on though lets talk about interpolated variables which if your new to you wouldn&#8217;t have noticed in the last example even though they we&#8217;re looking straight at you. Basically what they are is escaped variables that a prefixed or suffixed string can be used with in order to achieve dynamic values allowing for more maintainable CSS.</p>
<p>A simple way to remember what an interpolated variable is would be to break in down into it&#8217;s key elements:</p>
<ul>
<li>The pound or hash (<em>this is a dollar sign in PHP</em>)</li>
<li>followed by an opening curly brace</li>
<li>then followed by the variable</li>
<li>and finally closed with a closing curly brace</li>
</ul>
<p>This is exactly the same way you write the syntax in PHP except the <em>&#8220;pound/hash&#8221;</em> becomes a <em>&#8220;$&#8221;</em> dollar sign but it works exactly the same way, now that you have found out some of the reasons why I am already in love with SASS but i recommend you take it for a spin yourself as you will be surprised by how quickly you pick it up.</p>
<p>Hopefully i didn&#8217;t rant too much having not written an article in so long but i do hope you found it useful enough to convert yourself to SASS, i will write an article soon about using Compass along side SASS as it offers great benefits in it&#8217;s own right.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisupjohn.me/blog/my-initial-thoughts-about-sass/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Halo 4 Reveal</title>
		<link>http://www.chrisupjohn.me/blog/halo-4-reveal/</link>
		<comments>http://www.chrisupjohn.me/blog/halo-4-reveal/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 09:17:49 +0000</pubDate>
		<dc:creator>Chris Upjohn</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Halo]]></category>
		<category><![CDATA[343]]></category>
		<category><![CDATA[halo]]></category>

		<guid isPermaLink="false">http://www.chrisupjohn.me/?p=663</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<p><iframe src="http://www.youtube.com/embed/xS5hWOoXwjc" frameborder="0" width="600" height="335"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisupjohn.me/blog/halo-4-reveal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LESS CSS: Quick Tip &#8211; 1</title>
		<link>http://www.chrisupjohn.me/blog/less-css-quick-tip-1/</link>
		<comments>http://www.chrisupjohn.me/blog/less-css-quick-tip-1/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 09:51:28 +0000</pubDate>
		<dc:creator>Chris Upjohn</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[less]]></category>
		<category><![CDATA[namespace]]></category>

		<guid isPermaLink="false">http://www.chrisupjohn.me/?p=644</guid>
		<description><![CDATA[I&#8217;m now starting to get a little deeper into the LESS CSS language and i thought i would ...]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m now starting to get a little deeper into the LESS CSS language and i thought i would challenge myself early on, basically i wanted to create a namespace that contained functions i could reference for things such as box-shadow and border-radius. The problem i found instantly is that while setting static vars is great and all it&#8217;s not ideal for dynamic values that you may want to use in a non standard order, to overcome the problem i did a little reading on the <a href="http://lesscss.org" target="_blank">LESS CSS</a> website and found i could reference <code>@arguments</code> to retrieve all the values given in the function and then use <code>~','</code> to escape the comma so i could then for instance create multiple box shadows without the need to call the namespace again and again.</p>
<p>So to start off with i simply created the namespace and the function with an empty argument reference so that it didn&#8217;t expect any specific value pattern which would cause parsing errors, next i simply set the vendor prefixed properties for box-shadow and passed <code>@arguments</code> as the value:<span id="more-644"></span></p>
<pre class="brush: css; title: ; notranslate">#myNamespace {
    .box-shadow () {
        box-shadow:         @arguments;
        -moz-box-shadow:    @arguments;
        -webkit-box-shadow: @arguments;
    }
}</pre>
<p>The next thing i did was simply call the namespace and function like you would normally do with LESS but instead of passing a specific set of arguments i gave it 3 sets of arguments that were comma seperated:</p>
<pre class="brush: css; title: ; notranslate">div {
    #myNamespace &gt; .box-shadow(
        5px, 5px, 0, 6px, rgba(0,0,0, .5), ~',',
        7px, 7px, 0, 8px, rgba(51,51,51, .4), ~',',
        inset, 0, 0, 3px, rgba(0,0,0, .4)
    );
}</pre>
<p>So there you have it, a simple way to create multiple box shadows using one function inside a custom namespace using the LESS CSS language.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisupjohn.me/blog/less-css-quick-tip-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple getElementsByClassName emulation &#8211; Part 2</title>
		<link>http://www.chrisupjohn.me/blog/simple-getelementsbyclassname-emulation-part-2/</link>
		<comments>http://www.chrisupjohn.me/blog/simple-getelementsbyclassname-emulation-part-2/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 11:10:12 +0000</pubDate>
		<dc:creator>Chris Upjohn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.chrisupjohn.me/?p=639</guid>
		<description><![CDATA[So in the first part of this small snippet/tutorial i gave you a general concept of targeting classes ...]]></description>
				<content:encoded><![CDATA[<p>So in the first part of this small snippet/tutorial i gave you a general concept of targeting classes in a cross browser environment without the need to use a library such as jQuery, in this second and last part i will show you the last few modifications needed to allow for element specific selections and multiple class selections with just a couple of changes. Basically the main two changes in this final part will focus on the wildcard selector and the regular expression in which are the key declarations we need otherwise the prototype won&#8217;t work as expected or at all, the first change will need to make is changing <code>document</code> to <code>this</code>:</p>
<pre class="brush: jscript; title: ; notranslate">var ele = document.getElementsByTagName('*')</pre>
<p style="text-align: center;">↓↓↓↓↓↓↓↓↓↓</p>
<pre class="brush: jscript; title: ; notranslate">var ele = this.getElementsByTagName('*')</pre>
<p>Next we need to change the regular expression so it looks for multiple classes within the given argument, to accomplish this we simply use the <code><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/split" target="_blank">split</a></code> and <code><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/join" target="_blank">join</a></code> methods like below:</p>
<pre class="brush: jscript; title: ; notranslate">reg = new RegExp(c, 'i')</pre>
<p style="text-align: center;">↓↓↓↓↓↓↓↓↓↓</p>
<pre class="brush: jscript; title: ; notranslate">reg = new RegExp('(' + c.split(' ').join('|') + ')', 'i')</pre>
<p><span id="more-639"></span></p>
<pre></pre>
<p>As you can see we first split the string by searching for any spaces and if any are found we then split the string again using a specific pipe separator which allows us to create a word separated expression which is pretty much the most simple way to accomplish this, apart from that you should be able to use the final code below in any browser that doesn&#8217;t have native support for <code>getElementsByClassName</code>.</p>
<pre class="brush: jscript; title: ; notranslate">if (typeof document.getElementsByClassName === 'undefined') {
    // If the current browser doesn't support the built in class method lets
    // create our own to emulate it
    Object.prototype.getElementsByClassName = function(c) {
        // Collect all the elements in the DOM
        var ele = this.getElementsByTagName('*'),
            tmp = [],
            reg = new RegExp('(' + c.split(' ').join('|') + ')', 'i');

        for (var i = 0; i &lt; ele.length; i++) {
            // Cache the current element to prevent memory leaks
            var e = ele[i];

            if (typeof e.className !== 'undefined' &amp;&amp; e.className.match(reg)) {
                // To improve performance when appending a new array item use the length
                // to increment the current index
                tmp[tmp.length] = e;
            }
        }

        return tmp;
    };
}</pre>
<p>I hope you enjoyed this simple snippet/tutorial as i hope to produce more soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisupjohn.me/blog/simple-getelementsbyclassname-emulation-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple getElementsByClassName emulation &#8211; Part 1</title>
		<link>http://www.chrisupjohn.me/blog/simple-getelementsbyclassname-emulation/</link>
		<comments>http://www.chrisupjohn.me/blog/simple-getelementsbyclassname-emulation/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 13:50:01 +0000</pubDate>
		<dc:creator>Chris Upjohn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.chrisupjohn.me/?p=627</guid>
		<description><![CDATA[I&#8217;m sure this has been posted before on the web but i felt like writing my own version ...]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m sure this has been posted before on the web but i felt like writing my own version anyway, if you notice performance tweaks as such or anything else simply leave a comment below and I&#8217;ll alter the code.</p>
<p>Basically these days classes are the best way for managing any website as you can assign them to elements and specifically select those elements in the CSS just by associating it with the class name, JS is also a great tool for manipulating these elements as it allows us to select a whole group of them at once without the need to manually go through and find the elements. This is all good and well when it comes to use libraries such as <a href="http://www.jquery.com" target="_blank">jQuery</a> but when you only need to write a small amount of JS you would need something more simple.</p>
<p>In modern browsers the <code>document.getElementsByClassName</code> method is available to use but in IE8 and below the story isn&#8217;t the same, to accomplish the exact same result in all browsers we simply need to emulate the method as a protoype of the <code>Object</code> object.</p>
<pre class="brush: jscript; title: ; notranslate">Object.prototype.getElementsByClassName = function(c) {}</pre>
<p>Now we can just create this really simple prototype and not think twice about how it runs in moderns browsers but if we want to avoid using extra processing power we can wrap it in an <code>IF</code> statement and check to see if the method exists within the <code>document</code> object.</p>
<pre class="brush: jscript; title: ; notranslate">if (typeof document.getElementsByClassName === 'undefined') {
    Object.prototype.getElementsByClassName = function(c) {}
}</pre>
<p><span id="more-627"></span><br />
Now you can see we have solved the processing issue by simply checking if the method exists and only bind the prototype when its needed, next what we need to do is select all the elements from the DOM which we can do by using <code>document.getElementsByTagName('*')</code> which has been standard in all browsers since IE5 so no need to worry about browser compatibility.</p>
<pre class="brush: jscript; title: ; notranslate">if (typeof document.getElementsByClassName === 'undefined') {
    // If the current browser doesn't support the built in class method lets
    // create our own to emulate it
    Object.prototype.getElementsByClassName = function(c) {
        // Collect all the elements in the DOM
        var ele = document.getElementsByTagName('*'),
            tmp = [],
            reg = new RegExp(c, 'i');
    };
}</pre>
<p>You can see i have specified some other variables but ill get to those in a second, basically we have just told the browser we can to grab every element currently in the DOM no matter what it is. The other two variables you see are for storage and performance, when we iterate through the elements we are going to cache the object for each matched element to avoid memory leaks ask it can happen. The reason we are setting the regular expression outside of the loop is because we don&#8217;t want to waste precious resources we could be using elsewhere by declaring the same variable over and over again in the loop, this goes for any other variable that can play a role in a loop that only needs to be declared once.</p>
<p>Now what we need to do is build the loop that we scan each element in the page and check the class name if the attribute <code>class</code> exists and append the element object to the tmp array:</p>
<pre class="brush: jscript; title: ; notranslate">if (typeof document.getElementsByClassName === 'undefined') {
    // If the current browser doesn't support the built in class method lets
    // create our own to emulate it
    Object.prototype.getElementsByClassName = function(c) {
        // Collect all the elements in the DOM
        var ele = document.getElementsByTagName('*'),
            tmp = [],
            reg = new RegExp(c, 'i');

        for (var i = 0; i &amp;lt; ele.length; i++) {
            // Cache the current element to prevent memory leaks
            var e = ele[i];

            if (typeof e.className !== 'undefined' &amp;&amp; e.className.match(reg)) {
                // To improve performance when appending a new array item use the length
                // to increment the current index
                tmp[tmp.length] = e;
            }
        }

        return tmp;
    };
}</pre>
<p>Nothing to it right? Alright maybe if your new to JS it might be confusing so let me break it down, first we store the current element object as it improves performance we calling it multiple times within a loop. Next we check if the attribute or in this class element property <code>className</code> exists and if it does match it against the regular expression we setup earlier, next we store the element object in the tmp array but you will notice we use tmp.length which is a better way for performance as your not requesting the browser to determine the next interation of the loop. Once all that is done we simply return the array and from there we can use our normal JS declarations to request the elements with a class name of foo for example.</p>
<pre class="brush: jscript; title: ; notranslate">var foo = document.getElementsByClassName('foo'),
    bar = document.getElementsByClassName('bar');

alert('Foo: ' + foo.length + '\nBar: ' + bar.length);

var a = document.getElementsByClassName('item');
alert('Items: ' + a.length);</pre>
<p>So now that we have everything together you can play around with the code at Tinkerbin using the following link <a href="http://tinkerbin.com/tnHWOnTr" target="_blank">http://tinkerbin.com/tnHWOnTr</a>, i hope you have enjoyed reading this as i thought it may help at least one developer in need.</p>
<p><div class="alert green"><strong>NOTE:</strong> The above examples only targets the document object and single class selectors, i will make another post soon about how to target child elements in the DOM and multiple classes.</div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisupjohn.me/blog/simple-getelementsbyclassname-emulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Maps Going Shopping</title>
		<link>http://www.chrisupjohn.me/blog/google-maps-going-shopping/</link>
		<comments>http://www.chrisupjohn.me/blog/google-maps-going-shopping/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 04:09:35 +0000</pubDate>
		<dc:creator>Chris Upjohn</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Maps]]></category>

		<guid isPermaLink="false">http://www.chrisupjohn.me/?p=617</guid>
		<description><![CDATA[Think the title is confusing?? Well it should be confusing as Google is planning to walk through shopping ...]]></description>
				<content:encoded><![CDATA[<p><em>Think the title is confusing??</em></p>
<p>Well it should be confusing as Google is planning to walk through shopping centers all over the globe so you can see stores in your browser and on your mobile device before you even leave your home, when you think about it the idea is great but i see 1 fatal flaw in the plan that may make many people feel uneasy about when the pictures reach the internet. As everyone should know Google doesn&#8217;t ask your permission when the Google Maps images reach the internet which has been fine up until now because they have only captured people outdoors, when it comes down to it though do you really want your face on Google Maps publicly exposed while you walk around or shop in a store?</p>
<p>I know i sure don&#8217;t without my permission first as it&#8217;s wrong that a company as big as Google can take pictures and put them on the web without our permission but when we do it we face copyright laws and such, i personally don&#8217;t want my face publicly facing the world as you never know who&#8217;s looking at the map and what they might do with it. <span id="more-617"></span>In today&#8217;s day and age you never know who might be using the service for reasons other then finding the correct way to there destination and such, i know this won&#8217;t deter Google in any way, shape or form but i feel like we the public have a say in what should be allowed to be uploaded to the web and what should <strong>NOT</strong> be!</p>
<p>Some people may disagree but there is a main reason why countries have individual privacy laws which protects us from companies like Google doing such a thing but apparently like i said before they are exempt from these laws and free to do what they want when they want, I&#8217;m not smart enough to start a global poll or enough but simply spreading the word around should be enough to grab the attention of the Google developers that we should have a say before this extended service goes live in Google Maps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisupjohn.me/blog/google-maps-going-shopping/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using xcache
Database Caching using xcache
Object Caching 1140/1324 objects using xcache
Content Delivery Network via Amazon Web Services: CloudFront: cf.chrisupjohn.com

 Served from: www.chrisupjohn.me @ 2013-05-18 22:09:04 by W3 Total Cache -->