<?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>www.hackification.com &#187; JavaScript</title>
	<atom:link href="http://www.hackification.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hackification.com</link>
	<description></description>
	<lastBuildDate>Sat, 05 Jun 2010 11:16:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Weekly Links &#8211; node.js, Processors, Microsoft, and more</title>
		<link>http://www.hackification.com/2010/02/07/weekly-links/</link>
		<comments>http://www.hackification.com/2010/02/07/weekly-links/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 12:24:33 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[node.js]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=422</guid>
		<description><![CDATA[Since I&#8217;m having trouble producing full-length articles at the moment, I thought I&#8217;d try a different track to at least get some value out of my blog hosting costs. I&#8217;ll try to post a handful of links that have caught my attention each week. Comet with node.js and V8 http://amix.dk/blog/post/19484 A presentation (slideshow, no audio [...]]]></description>
			<content:encoded><![CDATA[<p>Since I&#8217;m having trouble producing full-length articles at the moment, I thought I&#8217;d try a different track to at least get <em>some </em>value out of my blog hosting costs. I&#8217;ll try to post a handful of links that have caught my attention each week.</p>
<p><span id="more-424"></span></p>
<h3>Comet with node.js and V8</h3>
<p><a href="http://amix.dk/blog/post/19484" target="_blank">http://amix.dk/blog/post/19484</a></p>
<p>A presentation (slideshow, no audio or video) on node.js, a JavaScript web-server running on Google&#8217;s V8 engine. Very interesting concept &#8211; using an event-based system vastly simplifies the code needed to serve data. There&#8217;s plenty of discussion about node.js on the interwebs at the moment &#8211; hopefully it will grow and become more than just a curiosity.</p>
<h3>Gallery  of Processor Cache Effects</h3>
<p><a href="http://igoro.com/archive/gallery-of-processor-cache-effects/" target="_blank">http://igoro.com/archive/gallery-of-processor-cache-effects/</a></p>
<p>Interesting blog post about the effects that processor caches may have on performance. Examples are in C#, but really apply to any language.</p>
<h3>Microsoft’s Creative Destruction</h3>
<p><a href="http://www.nytimes.com/2010/02/04/opinion/04brass.html?pagewanted=1&amp;ref=opinion" target="_blank">http://www.nytimes.com/2010/02/04/opinion/04brass.html?pagewanted=1&amp;ref=opinion</a></p>
<p>Opinion piece from the NYTimes regarding Microsoft&#8217;s recent lack of innovation (at least, in the area of shiny gadgets). Written by an ex-vice-president of Microsoft.</p>
<h3>How Many Passes?</h3>
<p><a href="http://blogs.msdn.com/ericlippert/archive/2010/02/04/how-many-passes.aspx" target="_blank">http://blogs.msdn.com/ericlippert/archive/2010/02/04/how-many-passes.aspx</a></p>
<p>Summary article from Eric Lippert describing the differences between the C# compiler and a &#8220;traditional&#8221; compiler, and listing the various passes made over the symbol tree.</p>
<h3>A Deadlock Holiday</h3>
<p><a href="http://www.theregister.co.uk/2009/12/10/verity_stob/" target="_blank">http://www.theregister.co.uk/2009/12/10/verity_stob/</a></p>
<p>Very funny tongue-in-cheek article about the current state of parallel / multicore coding techniques, from Verity Stob of The Register.</p>
<h3>A Maturity Model for Source Control</h3>
<p><a href="http://lucas-ward.blogspot.com/2010/02/maturity-model-for-source-control-scmm.html" target="_blank">http://lucas-ward.blogspot.com/2010/02/maturity-model-for-source-control-scmm.html</a></p>
<p>Semi-opinion piece assigning levels to types of source-control systems &#8211; from &#8220;No SCM&#8221; through &#8220;Clunky&#8221; to &#8220;Speedy,  Invisible, and Highly Capable&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2010/02/07/weekly-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resizing Single-Image-Rollovers Using jQuery</title>
		<link>http://www.hackification.com/2009/09/02/resizing-single-image-rollovers-using-jquery/</link>
		<comments>http://www.hackification.com/2009/09/02/resizing-single-image-rollovers-using-jquery/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 14:28:00 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[rollovers]]></category>
		<category><![CDATA[sprites]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=252</guid>
		<description><![CDATA[In this article I describe how to create shaped buttons in HTML/CSS that size to their content, have roll-over state, and require only a single image, using jQuery. I&#8217;m sure most web developers know about image rollovers (using separate images for normal and &#8220;hover&#8221; states of anchors). Hopefully also the use of &#8220;CSS Sprites&#8221; is [...]]]></description>
			<content:encoded><![CDATA[<p>In this article I describe how to create shaped buttons in HTML/CSS that size to their content, have roll-over state, and require only a single image, using jQuery.</p>
<p><span id="more-252"></span></p>
<p>I&#8217;m sure most web developers know about image rollovers (using separate images for normal and &#8220;hover&#8221; states of anchors). Hopefully also the use of &#8220;<a href="http://www.alistapart.com/articles/sprites" target="_blank">CSS Sprites</a>&#8221; is becoming better known &#8211; combining the normal and rollover images into a single physical image file to speed up load times and reduce flicker. I won&#8217;t cover those techniques here.</p>
<p>However, if you want the anchor or button to size to its contents, it&#8217;s more difficult to make use of these techniques. Here&#8217;s one way.</p>
<p><img class="aligncenter size-full wp-image-258" title="Sizing Rollovers" src="http://www.hackification.com/wp-content/uploads/2009/09/SizingRollovers.png" alt="Sizing Rollovers" width="414" height="127" /></p>
<p style="text-align: center;"><em>(The final result &#8211; <a href="http://www.hackification.com/jquery-examples/sizing-rollovers/sizing-rollovers.htm" target="_blank">view demo</a>).</em></p>
<p><strong>Start With Markup</strong></p>
<p>Before diving into fancy techniques, get the markup down as you would like it, if you didn&#8217;t have to style anything.</p>
<pre>&lt;a href="..." class="rollover"&gt;Button Text&lt;/a&gt;</pre>
<p>Ideally we want the markup to be clean and not compromised by styling requirements.</p>
<p><strong>Handle Degradation Gracefully</strong></p>
<p>My technique is going to make use of JavaScript, so let&#8217;s handle the case where the user has it disabled for some reason. Here&#8217;s some very basic CSS to give the button a simple style:</p>
<pre>a.rollover
{
  background-color: #00f;
  border: solid 1px #000;
  color: #fff;
  font-weight: bold;
  padding: 4px;
  text-decoration: none;
}

a.rollover:hover
{
  background-color: #008;
}</pre>
<p><strong>Add Styling Naively</strong></p>
<p>Next, I&#8217;m going to add some rollover styling &#8211; but in a way that isn&#8217;t complete. Firstly I created a simple rollover image, but made it very wide &#8211; it needs to be at least as wide as the widest button is ever going to be:</p>
<p><img class="aligncenter size-full wp-image-256" title="Button Rollover" src="http://www.hackification.com/wp-content/uploads/2009/09/buttons.png" alt="Button Rollover" width="657" height="123" /></p>
<p>I&#8217;m going to define my rollover styling against a class selector of &#8220;extra&#8221; &#8211; you&#8217;ll see where that comes from in a moment.</p>
<pre>a.rollover.extra
{
  background: url(buttons.png) repeat-x left 0;
  border: none;
  height: 27px;
  padding: 23px 40px 10px 40px;
  position: relative;
}

a.rollover.extra:hover
{
  background-position: left -57px;
}</pre>
<p>Note that we&#8217;ve had to undo some of the styles applied previously, such as border.</p>
<p>We&#8217;re kind of getting there, but our buttons won&#8217;t look correct on the right-hand-side.</p>
<p><strong>Use JavaScript To Add Styling Markup</strong></p>
<p>To fix the right-hand end-caps, we need to modify our markup. However, I really don&#8217;t want to have to do that on my pages &#8211; afterall, I might change my mind about the site styling.</p>
<p>Here I recommend using JavaScript to tweak at runtime the markup to what we need. I&#8217;m going to use jQuery for this:</p>
<pre>$(function() {
  $('.rollover')
    .addClass('extra')
    .append('&lt;div class="cap"&gt;&lt;/div&gt;');
});</pre>
<p>Basically, when the pad is ready, I find all elements with class &#8220;rollover&#8221;, add another class (&#8220;extra&#8221;), and append into the rollover button an empty span element which has a class of &#8220;cap&#8221;.</p>
<p>That class &#8220;extra&#8221; triggers the image rollovers. The &#8220;cap&#8221; span can be styled as follows:</p>
<pre>a.rollover.extra .cap
{
  background: url(buttons.png) no-repeat right 0;
  height: 100%;
  position: absolute;
  right: 0;
  top: 0;
  width: 40px;
}

a.rollover.extra:hover .cap
{
  background-position: right -57px;
}</pre>
<p>And voila!</p>
<blockquote><p><a href="http://www.hackification.com/jquery-examples/sizing-rollovers/sizing-rollovers.htm" target="_blank">If you&#8217;d like to see this technique in action, please view the demo</a>.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2009/09/02/resizing-single-image-rollovers-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My JavaScript Code Organization Journey (So Far)</title>
		<link>http://www.hackification.com/2009/03/01/my-javascript-code-organization-journey-so-far/</link>
		<comments>http://www.hackification.com/2009/03/01/my-javascript-code-organization-journey-so-far/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 19:09:37 +0000</pubDate>
		<dc:creator>Stu Smith</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[namespaces]]></category>
		<category><![CDATA[private]]></category>
		<category><![CDATA[public]]></category>

		<guid isPermaLink="false">http://www.hackification.com/?p=83</guid>
		<description><![CDATA[If you&#8217;ve been reading this blog, you&#8217;ll know that I&#8217;ve been doing more and more JavaScript coding recently. One aspect that&#8217;s very different to C# coding is that there&#8217;s no explicit notion of &#8216;public&#8217; or &#8216;private&#8217; methods. This article explains my own journey towards implementing these concepts in JavaScript. Stage One: No Access Control, Massive [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been reading this blog, you&#8217;ll know that I&#8217;ve been doing more and more JavaScript coding recently. One aspect that&#8217;s very different to C# coding is that there&#8217;s no explicit notion of &#8216;public&#8217; or &#8216;private&#8217; methods. This article explains my own journey towards implementing these concepts in JavaScript.</p>
<p><span id="more-83"></span></p>
<p><strong>Stage One: No Access Control, Massive Pollution</strong></p>
<p>My first JavaScript files looked a lot like this:</p>
<pre>function myPrivateMethod()
{
  ...
}

function myPublicMethod()
{
  ...
  myPrivateMethod();
  ...
}
</pre>
<p>My functions were just dumped straight into the global context, &#8220;polluting&#8221; it, and there was no kind of access control &#8211; all methods could be called from anywhere.</p>
<p><strong>Stage Two: Coding-Convention Access Control, Minimal Pollution</strong></p>
<p>My next strategy for defining function was to create a single object in the global scope, then add functions as properties of that object. I still hadn&#8217;t figured out access control, other than by using a naming convention:</p>
<pre>if (typeof MyNamespace == 'undefined') {
  MyNamespace = {};
}

MyNamespace._privateMethod = function() {
  ...
}

MyNamespace.publicMethod = function() {
  ...
  MyNamespace._privateMethod();
  ...
}
</pre>
<p>While this is better than before, it&#8217;s still not true access control.</p>
<p><strong>Stage Three: Access Control, Plus Namespaces<br />
</strong></p>
<p>The latest way I&#8217;ve <a href="http://www.dustindiaz.com/javascript-private-public-privileged/" target="_blank">discovered</a> for arranging code gives namespaces and true access control.</p>
<pre>var MyNamespace = window.MyNamespace || {};

MyNamespace.MyModule = function() {

  var privateMethod = function() {
    ...
  };

  return {

    publicMethod : function() {
      ...
      privateMethod();
      ...
    }

  };
}();
</pre>
<p>I&#8217;d seen examples like the above back when I first started coding JavaScript, but I don&#8217;t like cargo-cult-copy-paste code: if I don&#8217;t understand code, I don&#8217;t use it. It&#8217;s taken me this long to understand every line in the above. Now that I do, I can start to refactor my existing code where necessary to use this pattern.</p>
<p>The interesting points in the above code example are:</p>
<ul>
<li>The first line is a much more compact way of determining whether the single global variables is defined already (for example from another code file), and if it&#8217;s not, creating it.</li>
<li>The &#8216;module&#8217; property is assigned from the immediate invocation of an anonymous function. This anonymous function returns an object whose properties are the functions we want to make public.</li>
<li>The private functions are created as inner functions of the outer anonymous function. The public functions retains access to these private functions via the magic of closures.</li>
</ul>
<p>It continually amazes me how the JavaScript langauge manages to allow a developer so many features (in this article I&#8217;ve covered public/private and namespaces), without needing to include them as first-class keywords in the langauge.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hackification.com/2009/03/01/my-javascript-code-organization-journey-so-far/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
