<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/css/rss20.xsl" type="text/xsl"?>
<rss xmlns:pheedo="http://www.pheedo.com/namespace/pheedo" 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/">
	<channel>
		<title>SitePoint &#187; JavaScript &amp; CSS</title>
		<atom:link href="http://www.sitepoint.com/blogs/category/dhtml-css/feed/" rel="self" type="application/rss+xml"/>
		<link>http://www.sitepoint.com/blogs</link>
		<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
		<pubDate>Sat, 04 Jul 2009 09:08:11 +0000</pubDate>
		<generator>http://wordpress.org/?v=2.7.1</generator>
		<language>en</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
		<item>
			<title>Announcing Updates to our Popular Add-ons for Firefox 3.5</title>
			<link>http://www.pheedcontent.com/click.phdo?i=bd3772d4ca679775202e49ef8533d8fc</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/07/02/announcing-updates-to-our-popular-add-ons-for-firefox-35/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/07/02/announcing-updates-to-our-popular-add-ons-for-firefox-35/#comments</comments>
			<pubDate>Thu, 02 Jul 2009 01:26:12 +0000</pubDate>
			<dc:creator>brothercake</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<category><![CDATA[Web Tech]]></category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=11824</guid>
			<description><![CDATA[If you've recently installed Firefox 3.5 you're probably itching to get hold of updates to our popular developer add-ons, Dust-Me Selectors, and CodeBurner for Firebug. And here they are &#8212; hot off the press!<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=bd3772d4ca679775202e49ef8533d8fc&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=bd3772d4ca679775202e49ef8533d8fc&p=1"/></a>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/07/firefox-refreshed.jpg" alt="The Refreshed Firefox Logo" width="200" height="200" class="size-full wp-image-11937 imgright" />
<p>
With the recent release of Firefox 3.5, we&#8217;re very pleased to announce the release of updates to our useful developer tools: <a href="http://www.sitepoint.com/dustmeselectors/">Dust-Me Selectors</a>, and <a href="http://tools.sitepoint.com/codeburner/">CodeBurner for Firebug</a>.
</p>
<p>
Dust-Me Selectors is a standalone extension that finds unused <abbr title="Cascading Style Sheets">CSS</abbr> selectors, and is particularly useful for updating legacy sites, allowing you to throw away all those redundant rules without worrying that something, somewhere might be using them.
</p>
<p>
CodeBurner for Firebug, as its name suggests, is an extension to the popular developer tool, <a href="http://getfirebug.com/">Firebug</a>, and extends it with searchable reference material for <abbr title="HyperText Markup Language">HTML</abbr> and <abbr title="Cascading Style Sheets">CSS</abbr>.
</p>
<p>
We&#8217;ve been beavering away behind the scenes on updates to both these extensions, waiting for the final version of Firefox 3.5 &#8212; and now that it&#8217;s been released, here they are!
</p>
<div id="adz" class="vertical"></div><p>
Dust-Me Selectors in particular benefits from this browser update &#8212; thanks to improvements in Firefox&#8217;s JavaScript engine, it now performs significantly faster, with a typical &quot;find&#8230;&quot; operation around 50% quicker than in Firefox 3.0!
</p>
<p>
But that&#8217;s not nearly all! Both new versions also bring a host of improvements and new features:
</p>
<h4>New features in Dust-Me Selectors Version 2.2:</h4>
<ul>
<li>new tabbed preferences dialog that&#8217;s neater and more user-friendly</li>
<li>added a new spidering preference &quot;don&#8217;t spider external sites&quot;, which resricts the spider to pages on the same domain as the sitemap</li>
<li>bugfixes to make &quot;find&#8230;&quot; and &quot;spider&#8230;&quot; keyboard triggers more reliable cross-platform</li>
<li>improved error handling throughout</li>
<li>removed two unecessary preferences to streamline the spidering logic: &quot;ignore www difference&quot; and &quot;ignore fragment identifiers&quot; in URLs, both of which are now enabled all the time</li>
</ul>
<h4>New features in CodeBurner for Firebug 1.2:</h4>
<ul>
<li>improved search algorithm gives better results</li>
<li>special search now includes &quot;other attributes that are valid for this element&quot; as well as those which are actually defined for it</li>
<li>code examples for CSS properties now include direct links to <a href='http://reference.sitepoint.com/css/demos'>live examples</a> online</li>
<li>the original search term is now indicated in search results</li>
<li>slightly modified license clarifies the distinction between &quot;use&quot; and &quot;redistribution&quot;</li>
</ul>
<p>
Both of these updates have been uploaded to the <a href="https://addons.mozilla.org/">Mozilla Add-ons site</a>, however since all submissions are reviewed manually, it may be a day or so before they become available from there, or through the automatic updates channel. So if you can&#8217;t wait that long, you can grab them straight away from SitePoint:
</p>
<ul>
<li><a href="http://www.sitepoint.com/dustmeselectors/"><strong>Dust-Me Selectors v2.2</strong></a></li>
<li><a href="http://tools.sitepoint.com/codeburner/"><strong>CodeBurner for Firebug v1.2</strong></a></li>
</ul>
<p>
As always, we welcome your comments and feedback on both of these extensions &#8212; and if you&#8217;ve any ideas for features you&#8217;d like to see, please don&#8217;t hesitate to let us know!</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=136&amp;did=adz&amp;adtype=vertical" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=bd3772d4ca679775202e49ef8533d8fc&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=bd3772d4ca679775202e49ef8533d8fc&p=1"/></a>
]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/07/02/announcing-updates-to-our-popular-add-ons-for-firefox-35/feed/</wfw:commentRss>
		</item>
		<item>
			<title>Truthy and Falsy: When All is Not Equal in JavaScript</title>
			<link>http://www.pheedcontent.com/click.phdo?i=cafcbf18300ab86cc071303bb3bef447</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/07/01/javascript-truthy-falsy/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/07/01/javascript-truthy-falsy/#comments</comments>
			<pubDate>Tue, 30 Jun 2009 15:13:30 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=11126</guid>
			<description><![CDATA[Anything in JavaScript can be considered to be either truthy or falsy. Craig provides a useful guide explaining what they are and the bizarre rules that apply when they're compared.<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=cafcbf18300ab86cc071303bb3bef447&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=cafcbf18300ab86cc071303bb3bef447&p=1"/></a>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/06/095-js-truthy-falsy.png" alt="JavaScript-truthy-falsy" title="JavaScript-truthy-falsy" width="220" height="220" class="imgright" />Like most computer languages, JavaScript supports Boolean data types; values which can be set to true or false. In addition, everything in JavaScript has an inherent Boolean value, generally known as either <em>truthy</em> or <em>falsy</em>. Handling truthy and falsy values can be a little quirky, especially when comparing variables. Understanding some of the more bizarre rules can help when debugging complex client-side applications.</p>
<h2>Truthy and Falsy Values</h2>
<p>The following values are always falsy:</p>
<ul>
<li><strong>false</strong></li>
<li><strong>0</strong> (zero)</li>
<li><strong>&quot;&quot;</strong> (empty string)</li>
<li><strong>null</strong></li>
<li><strong>undefined</strong></li>
<li><strong>NaN</strong> (a special Number value meaning Not-a-Number!)</li>
</ul>
<div id="adz" class="horizontal"></div><p>All other values are truthy, including &quot;0&quot; (zero in quotes), &quot;false&quot; (false in quotes), empty functions, empty arrays, and empty objects.</p>
<pre><code class="javascript">
var a = !!(0); // variable is set to false
var b = !!("0"); // true
</code></pre>
<h2>Comparing Falsy Values</h2>
<p>Falsy values follow some slightly odd comparison rules which can lead to errors in program logic.</p>
<p>The falsy values <strong>false</strong>, <strong>0</strong> (zero), and <strong>&quot;&quot;</strong> (empty string) are all equivalent and can be compared against each other:</p>
<pre><code class="javascript">
var c = (false == 0); // true
var d = (false == ""); // true
var e = (0 == ""); // true
</code></pre>
<p>The falsy values <strong>null</strong> and <strong>undefined</strong> are not equivalent to anything except themselves:</p>
<pre><code class="javascript">
var f = (null == false); // false
var g = (null == null); // true
var h = (undefined == undefined); // true
var i = (undefined == null); // true
</code></pre>
<p>Finally, the falsy value <strong>NaN</strong> is not equivalent to anything &#8212; including NaN!</p>
<pre><code class="javascript">
var j = (NaN == null); // false
var k = (NaN == NaN); // false
</code></pre>
<p>You should also be aware that <code>typeof(NaN)</code> returns &quot;number&quot;. Fortunately, the core JavaScript function <code>isNaN()</code> can be used to evaluate whether a value is NaN or not.</p>
<p><strong>If in doubt&#8230;</strong><br />
Use strict equal (===) and strict not equal (!==) in situations where truthy or falsy values could lead to logic errors. These operators ensure that the objects are compared by type and by value.</p>
<pre><code class="javascript">
var l = (false == 0); // true
var m = (false === 0); // false
</code></pre>
<p>Has truthy or falsy logic ever caused you grief in JavaScript code?</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=137&amp;did=adz&amp;adtype=horizontal" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=cafcbf18300ab86cc071303bb3bef447&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=cafcbf18300ab86cc071303bb3bef447&p=1"/></a>
]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/07/01/javascript-truthy-falsy/feed/</wfw:commentRss>
		</item>
		<item>
			<title>Write Better CSS with Less</title>
			<link>http://www.pheedcontent.com/click.phdo?i=497b14a60f2ab9ebf4188be698b598bf</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/06/30/write-better-css-with-less/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/06/30/write-better-css-with-less/#comments</comments>
			<pubDate>Tue, 30 Jun 2009 07:30:24 +0000</pubDate>
			<dc:creator>raena</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=11726</guid>
			<description><![CDATA[I have a confession: I think parts of CSS suck. It's repetitive, tedious, and ... well, kind of dumb. Less promises to make writing CSS a little smarter!<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=497b14a60f2ab9ebf4188be698b598bf&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=497b14a60f2ab9ebf4188be698b598bf&p=1"/></a>
]]></description>
			<content:encoded><![CDATA[<p><img class="imgright size-full wp-image-11728" title="Less" src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/06/picture-120.png" alt="Less" width="168" height="82" /> <strong>I have a confession: I think parts of CSS <em>suck. </em>It&#8217;s repetitive, tedious, and &#8230; well, kind of dumb. </strong></p>
<p>I for one find it quite counter-intuitive to specify descendants&#8217; styles like this:</p>
<pre><code>#banner { color: white; background: black; }
#banner a { color: yellow; }
#banner p { margin: 0; }
#banner ...
#banner ...
#banner ...</code></pre>
<p>&#8230; and on, and on, and on. Instead, this makes way more sense to me:</p>
<pre><code>#banner {
  color: white;
  background: black;
    a { color: yellow; }
    p { margin: 0em; }
    ...
}</code></pre>
<p>And how about variables? They&#8217;d be cool:</p>
<pre><code>@logo = #457301;

h3 { color: @logo; }
#sale { border: 1px solid @logo; }
.alert { background: @logo; }</code></pre>
<p>Are you with me? Well, <a href="http://lesscss.org/">Less</a> promises to make these daydreams and more a happy reality. You&#8217;d write a style sheet using the Less syntax, which is exceptionally easy to pick up &#8212; it&#8217;s just CSS with some added CSS-like extras. You then use the Less Ruby gem to convert it into regular CSS &#8212; run it on the command line, or incorporate it into an app.</p>
<p>Less permits you to use variables and nested selectors, as seen above, but also offers a way to include classes within classes, and some simple math operators. Sweet! Let&#8217;s put Less through its paces and see how it copes with a simpler style sheet.</p>
<p>Let&#8217;s say I&#8217;m making a style sheet for a reasonably common grid structure, like so:</p>
<p align="center"><img src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/06/less-grid.jpg" border="0" alt="Grid: three at the top, four in the centre, six at the bottom" align="middle" /></p>
<div id="adz" class="vertical"></div><p>Usually, I&#8217;d decide on a width for the entire page (let&#8217;s say 960 pixels &#8212; it&#8217;s a <a href="http://960.gs">popular</a> size) and construct various widths based on that, perhaps indeed using a grid system from a framework. I&#8217;d like the topmost boxes to occupy one third of the width of the container, the second set of boxes one quarter, and the footer boxes one sixth, so I&#8217;ll divide accordingly using my handy calculator. I have a particular favorite green, which I&#8217;d like to use as a heading color for some boxes, a border color for the secondary headings, and as a background for the footer. There&#8217;s an item that looks kind of like the footer, but with a different font. Oh, and I&#8217;d like to add some basic font specifications to each of the sections &#8212; the text should become smaller the further you go down. All groovy:</p>
<pre><code>#container {
  width: 960px;
}
.box {
  float: left;
}
#main .box {
  width: 320px;
}
#main .box h3 {
  background: #450;
}
#secondary {
  font-size: 90%;
}
#secondary .box {
  width: 240px;
  border-bottom: 1px solid #450;
}
#footer {
  font-size: 80%;
}
#footer, #super {
  background: #450;
  color: #fff;
}
#footer .box {
  width: 160px;
}
#super {
  font-family: cursive;
}</code></pre>
<p>All groovy, that is, until I decide I&#8217;d like to change the width of the container. Now I have to go back and edit the widths of <code>container</code> and each of the descendent boxes on <code>main</code>, <code>secondary</code>, and <code>footer</code>. Then, I decide I&#8217;d like to use purple instead of green, so I then have to change the color of the main boxes&#8217; headings, the secondary boxes&#8217; borders, <em>and</em> the footer boxes&#8217; backgrounds. Annoying!</p>
<p>Let&#8217;s imagine that I used Less for this task instead. First, of course, I&#8217;ll need to install Less, which is a quick job on the command line:</p>
<pre><code>sudo gem install less</code></pre>
<p>Now I&#8217;ll open a new text file and start writing Less. I&#8217;ll specify a<br />
base width in a variable, <code>@base</code>:</p>
<pre><code>@base: 960px;</code></pre>
<p>And my favorite color:</p>
<pre><code>@pretty: #450;</code></pre>
<p>I&#8217;ll then use the <code>@base</code> variable to specify the widths of the main, secondary, and footer boxes as a fraction of that overall width. To define each of the <code>box</code> children of each section, I&#8217;ll use nested selectors to define how I want the <code>box</code> children of each section to appear. The <code>@pretty</code> variable is used wherever I need to specify that color. Here is the rest of my Less file:</p>
<pre><code>#container {
  width: @base;
}
.box {
  float: left;
}

#main {
  .box {
    width: @base / 3;
      h3 {
        color: @pretty;
      }
  }
}

#secondary {
  font-size: 90%;
  .box {
    width: @base / 4;
    border-bottom: 1px solid @pretty;
  }
}

#footer {
  font-size: 80%;
  background: @pretty;
  color: #fff;
  .box {
    width: @base / 6;
  }
}</code></pre>
<p>Since <code>super</code> looks just like <code>footer</code>, but with a different font, I&#8217;ll use Less&#8217;s class inclusion technique (they call it a mixin) to tell it to include these declarations too:</p>
<pre><code>#super {
  #footer;
  font-family: cursive;
}</code></pre>
<p>I&#8217;ll cook up a CSS file using this simple statement on the command line:</p>
<pre><code>lessc mystylesheet.less</code></pre>
<p>Out pops a style sheet with much the same content as the one I made in the usual fashion above, with the exception of my <code>footer</code> and <code>super</code> declarations. Rather than being grouped, the common declarations are repeated:</p>
<pre><code>#footer {
  font-size: 80%;
  background: #450;
  color: #fff;
}
#super {
  font-size: 80%;
  background: #450;
  color: #fff;
  font-family: cursive;
}</code></pre>
<p>More on that small annoyance later.</p>
<p>Now, since Less created much the same style sheet, you might be wondering where I&#8217;m going with this. Well, here&#8217;s where we come to the part where it&#8217;s time to change my mind about the width and color, and this is where Less really comes into its own. This time, I only need to change <em>two lines</em> in my style sheet. First up, let&#8217;s adjust the value of the base variable, like this:</p>
<pre><code>@base: 720px;</code></pre>
<p>Now, let&#8217;s change the green to purple:</p>
<pre><code>@pretty: #619;</code></pre>
<p>Now, I can leave the rest of the declarations alone and generate a new CSS file. The boxes&#8217; width recalculations and color replacements are done for me:</p>
<pre><code>#container {
  width: 720px;
}
.box {
  float: left;
}
#main .box {
  width: 240px;
}
#main .box h3 {
  color: #619;
}
#secondary {
  font-size: 90%;
}
#secondary .box {
  border-bottom: 1px solid #619;
  width: 180px;
}
#footer {
  font-size: 80%;
  background: #619;
  color: #fff;
}
#footer .box {
  width: 120px;
}

#super {
  font-size: 80%;
  background: #619;
  color: #fff;
  font-family: cursive;
}</code></pre>
<p>Of course, this is a very simple example. In the real world, a complex grid-based template could contain dozens of declarations based on a single figure; a color scheme could revolve around two or three basic shades. Using Less, we can treat these base definitions as true variables, and spend less time maintaining them.</p>
<p>Less&#8217;s inclusion method could be tidier if it was clever enough to group the common elements of the mixed-in declarations. On the other hand, I kind of like the way it comes out here &#8212; I like to organize my style sheet into sections according to purpose:</p>
<pre><code>/* heading styles */
...
/* main content styles */
...
/* footer styles */
...</code></pre>
<p>If there&#8217;s a style I like the look of in the heading area, and I want an item in my footer to resemble it, I&#8217;d prefer to avoid storing that footer item in my headings section. If you want to be clever and use grouped selectors, you&#8217;ll have to put both those styles somewhere. The convenience of the feature outweighs this small nuisance for me, and of course using mixins is absolutely optional.</p>
<p>I love it when clever folk come up with great ways to save time on CSS, and I can see I&#8217;ll be making good use of this nifty tool in future. You can <a href="http://lesscss.org">check out Less at its web site.</a></p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=136&amp;did=adz&amp;adtype=vertical" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=497b14a60f2ab9ebf4188be698b598bf&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=497b14a60f2ab9ebf4188be698b598bf&p=1"/></a>
]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/06/30/write-better-css-with-less/feed/</wfw:commentRss>
		</item>
		<item>
			<title>Implementing Event Latency in JavaScript</title>
			<link>http://www.pheedcontent.com/click.phdo?i=dfbd5c8dd96d7de1531cd8e7a1e1a1f9</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/06/18/javascript-event-latency/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/06/18/javascript-event-latency/#comments</comments>
			<pubDate>Wed, 17 Jun 2009 21:31:52 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<category>events</category>
			<category>JavaScript</category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=9856</guid>
			<description><![CDATA[Craig provides some useful JavaScript code to slow down event handling in your client-side web application.<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=dfbd5c8dd96d7de1531cd8e7a1e1a1f9&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=dfbd5c8dd96d7de1531cd8e7a1e1a1f9&p=1"/></a>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/05/078-javascript-latancy.jpg" alt="JavaScript event latancy" title="JavaScript event latancy" width="250" height="250" class="imgright" />Handling browser events in JavaScript is probably the most time-consuming, frustrating, and misunderstood aspects of client-side programming. Libraries such as <a href="http://jquery.com/">jQuery</a> make it easier, but it&#8217;s still useful to have a little knowledge of what&#8217;s going on beneath the surface.</p>
<p>In this article, we will implement event latency, i.e. the response to an event will occur a little time after it fired. This is often useful in situations such as creating drop-down menus. So let&#8217;s start with a little HTML and CSS code (it&#8217;s kept brief for the purpose of this example, hence no DOCTYPE)&#8230;</p>
<pre><code class="html">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Latency test&lt;/title&gt;

&lt;style type="text/css"&gt;
#element1
{
	width: 20em;
	margin: 20px;
	background-color: #dff;
	border: 2px solid #00d;
}

#para1
{
	text-align: center;
	padding: 10px;
	margin: 30px;
	background-color: #ccc;
	border: 1px solid #000;
}
&lt;/style&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;div id="element1"&gt;
	&lt;p id="para1"&gt;Hover over me...&lt;/p&gt;
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>This just produces a box similar to the following&#8230;</p>
<p><img src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/05/078-javascript-latancy-box.png" alt="Box image" title="Box image" width="324" height="106" class="imgcenter fullsize" /></p>
<div id="adz" class="horizontal"></div><p>Now we&#8217;ll add a little JavaScript just before the closing <code>body</code> tag&#8230;</p>
<pre><code class="javascript">
&lt;script type="text/javascript"&gt;

window.onload = function() {

	// get nodes
	var element1 = document.getElementById("element1");
	var para1 = document.getElementById("para1");

	// define events
	if (element1 &amp;&amp; para1) {
		element1.onmouseover = Handler;
		element1.onmouseout = Handler;
	}

	// event handler
	function Handler(e) {
		e = (e ? e : window.event);
		var on = (e.type == "mouseover");
		Highlight(on);
		return false;
	}

	// highlight or dim element (pass true|false)
	function Highlight(on) {
		para1.firstChild.nodeValue = (on ? "over" : "out");
		element1.style.backgroundColor = (on ? "#ffd" : "#dff");
		if (!on) alert("moved out");
	}

};

&lt;/script&gt;
</code></pre>
<p>This adds a couple of (DOM0) events that fire when the cursor moves over or out of the light-blue element1 <code>div</code>. An event Handler function is called to sort out IE inconsistencies and discover whether a mouse over or out event was fired. The Highlight function is passed true (mouse over) or false (mouse out) and it changes the paragraph text and background color accordingly. Finally, if the mouse is moved out, an alert box is shown.</p>
<p>The script works, however, when we move the mouse into the grey paragraph box the &#8220;moved out&#8221; alert appears. This occurs because the browser fires two events - a mouseout for element1 and a mouseover for para1. Although we did not delegate an event handler for para1, browsers implement a technique known as <a href="http://www.quirksmode.org/js/events_order.html">bubbling</a> and events will propagate through all element1&#8217;s descendants.</p>
<p>In this example, we only care if the last event fired was a mouseout that was not immediately followed by a mouseover. We can therefore fix the problem in our Handler() function with a little event latency:</p>
<pre><code class="javascript">
	var timer;
	function Handler(e) {
		e = (e ? e : window.event);
		var on = (e.type == "mouseover");
		if (timer) clearTimeout(timer);
		timer = setTimeout( function() { Highlight(on); }, 300);
		return false;
	}
</code></pre>
<p>When an event occurs, we clear any existing timeout. A new timeout is then created which calls the Highlight function after 300 milliseconds (Highlight(on) is contained in a function so the value of &#8216;on&#8217; is retained by the closure). This process makes it impossible for Highlight() to be executed any more frequently than every 300 milliseconds. When it is called, only the most recent value of &#8216;on&#8217; is available.</p>
<p>Reload the page and you will notice that there is a short delay before any event animation occurs. In addition, the alert will only appear when you move outside of the blue #element1 box.</p>
<p>I hope you find the technique useful in other JavaScript projects.</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=137&amp;did=adz&amp;adtype=horizontal" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=dfbd5c8dd96d7de1531cd8e7a1e1a1f9&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=dfbd5c8dd96d7de1531cd8e7a1e1a1f9&p=1"/></a>
]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/06/18/javascript-event-latency/feed/</wfw:commentRss>
		</item>
		<item>
			<title>Opera Unite Seeks to Decentralize the Web</title>
			<link>http://www.pheedcontent.com/click.phdo?i=3a111d2f74ae79a782e400e966a14be0</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/06/16/opera-unite-seeks-to-decentralize-the-web/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/06/16/opera-unite-seeks-to-decentralize-the-web/#comments</comments>
			<pubDate>Tue, 16 Jun 2009 13:22:45 +0000</pubDate>
			<dc:creator>Akash Mehta</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<category><![CDATA[News & Trends]]></category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=11030</guid>
			<description><![CDATA[Opera Unite is an innovative move by the Norwegian based company to turn your browser into a peer-to-peer sharing platform. Akash gives us the low-down.<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=3a111d2f74ae79a782e400e966a14be0&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=3a111d2f74ae79a782e400e966a14be0&p=1"/></a>
]]></description>
			<content:encoded><![CDATA[<p><img class="imgright" src="http://www.sitepointstatic.com/blogs/wp-content/uploads/2009/06/opera-unite.jpg" alt="Opera Unite" title="opera-unite" width="220" height="220" class="size-full wp-image-11039" />Opera Software has just released the latest beta of Opera 10, along with <a href="http://unite.opera.com/">a micro site</a> showcasing the new (alpha) Opera Unite technology that seeks to enable peer-to-peer networking for browser-based applications. In a <a href="http://labs.opera.com/news/2009/06/16/">detailed blog post</a> regarding the release, Opera Software product analyst Lawrence Eng explains how Opera 10 can turn any computer or device into a server, enabling applications running on the platform to communicate directly with another web user (presumably also running Opera 10).</p>
<p>With Opera Unite, developers will create applications &#8212; or Opera Unite Services &#8212; which run in the end-user&#8217;s browser, connect directly to other computers, and share data. Sample scenarios outlined by Eng include media sharing, instant communication, and anything in a &#8220;class of social software on the web.&#8221; The end goal suggested in Eng&#8217;s announcement includes restoring power to end-users to communicate with each other, using their own infrastructure (personal computers, residential internet connections etc.).</p>
<p>In <a href="http://dev.opera.com/articles/view/an-introduction-to-opera-unite/">an article on Dev.Opera</a>, Chris Mills explains how to get up and running with the latest Opera Unite build. Mills offers a fairly concise description for Opera Unite &#8212; &#8220;a collaborative technology that uses a compact server inside [Opera] to share data and services.&#8221;</p>
<p>As Google, Yahoo! and Microsoft seek to create centralized platforms and capture mindshare, Opera Unite aims to steer the web away from a centrally-managed architecture run by &#8220;computers with more power than the rest&#8221; (servers). Opera believes that a new set of opportunities exists where servers are not required and applications can communicate directly with peer systems. Should Opera succeed, this would strike at the heart of user-driven content sites, many of which rely on users sharing media with a select group of friends for traffic. Interestingly, Opera Unite seems to make no attempt to challenge fundamentally centralised systems, such as search engines, nor does it attempt to replace online communities that thrive on sharing content to a general audience (YouTube, anyone?).</p>
<div id="adz" class="horizontal"></div><p>A quick run through of Opera Unite is promising &#8212; a wizard in the Opera 10 beta (available under the Tools menu) takes the user through the process of creating an account, and helpfully offers to attempt to configure UPnP (no port forwarding instructions in sight &#8212; the system is clearly optimized for as little configuration as possible). Once set up, the Opera Unite sidebar appears, and a list of default services is available.</p>
<p>Enabling the file sharing application, for example, adds a File Sharing entry to a list of available services on a public URL (generally http://(computer name).(Opera username).operaunite.com). This public URL represents a landing page of sorts for the user, and Opera suggests this is served from the end-user&#8217;s machine, although the hostname of the public URL resolves to an Opera server. Additionally, while any browser can be used to browse available content, it appears that Opera Unite is required to actually access content, e.g. download shared files.</p>
<p>The initial release feels extremely stable, although Opera emphasizes that the Unite technology is still in alpha, and there will undoubtedly be challenges with complex networking environments (NAT, no UPnP etc.) for which the technology is yet to be battle-tested. Builds are available for Windows, Linux and Mac OS X.</p>
<p><em><a href="http://labs.opera.com/news/2009/06/16/">Download Opera Unite</a> and let us know what you think.</em></p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=137&amp;did=adz&amp;adtype=horizontal" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=3a111d2f74ae79a782e400e966a14be0&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=3a111d2f74ae79a782e400e966a14be0&p=1"/></a>
]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/06/16/opera-unite-seeks-to-decentralize-the-web/feed/</wfw:commentRss>
		</item>
		<item>
			<title>First Look: Object Oriented CSS</title>
			<link>http://www.pheedcontent.com/click.phdo?i=a1f63c783c48c8e1c60c4cbec606216f</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/06/16/first-look-object-oriented-css/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/06/16/first-look-object-oriented-css/#comments</comments>
			<pubDate>Tue, 16 Jun 2009 05:16:35 +0000</pubDate>
			<dc:creator>Kevin Yank</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=10974</guid>
			<description><![CDATA[Nicole Sullivan's Object Oriented CSS aims to make your styles easier to maintain and extend, with a performance boost to boot. Kevin's been using this methodology in a recent project. Are the benefits worth the extra discipline, or is CSS complicated enough already?<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=a1f63c783c48c8e1c60c4cbec606216f&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=a1f63c783c48c8e1c60c4cbec606216f&p=1"/></a>
]]></description>
			<content:encoded><![CDATA[<p><strong>In October, I&#8217;ll speak at <a href="http://south09.webdirections.org/">Web Directions South 2009</a> in Sydney about <a href="http://south09.webdirections.org/program/development#css-frameworks">CSS Frameworks</a>. One of the main questions I will answer in my talk is whether or not you should use a CSS Framework in any given project. Since the alternative is writing your own CSS styles from scratch, I&#8217;m researching some of the latest thinking on hand-coded CSS.</strong></p>
<p><a href="http://wiki.github.com/stubbornella/oocss"><img src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/06/object-oriented-css.jpg" alt="Object Oriented CSS for high performance web applications and sites" border="0" width="250" height="187" class="imgright" /></a></p>
<p>One prominent voice in this arena is <a href="http://www.stubbornella.org/">Nicole Sullivan</a>, who has developed a methodology called <a href="http://wiki.github.com/stubbornella/oocss">Object Oriented CSS</a> (OOCSS). She outlined this approach to writing CSS at Web Directions North 2009, and the 48-minute <a href="http://www.stubbornella.org/content/2009/03/23/object-oriented-css-video-on-ydn/">video is available</a>.</p>
<p>Sullivan is a talented and engaging presenter, but I found the video a lot to take in all at once. Since watching it, I have applied the principles of OOCSS to an internal project here at SitePoint, and I feel like I have a better grasp on what it&#8217;s all about.</p>
<div id="adz" class="vertical"></div><h2>A Change of Perspective</h2>
<p>Just another framework? Think bigger: &#8220;OOCSS isn&#8217;t really a framework &#8230; but a way of writing scalable, sane, maintainable CSS,&#8221; <a href="http://wiki.github.com/stubbornella/oocss/faq#yui">writes Sullivan</a>. Sullivan uses and recommends a grid framework like <a href="http://developer.yahoo.com/yui/grids/">Yahoo!&#8217;s YUI Grids</a>, but you&#8217;re free to write your layout styles from scratch using OOCSS principles if that&#8217;s your thing. But OOCSS applies equally to the work you do after you have implemented your site&#8217;s layout, as you design the blocks and content that slot <em>into</em> your layout.</p>
<p>Most web designers tend to write CSS code so that it requires as little extra markup (whether <code>&lt;div&gt;</code> or <code>&lt;span&gt;</code> tags or <code>class</code> attributes) as possible. Fundamentally, adopting OOCSS is making a mental shift towards easy maintenance and reuse of your styles, <strong>even if it means writing extra HTML markup.</strong></p>
<p>OOCSS methodologies help you to look beyond your immediate design goals and organize your code so that adding new site content that reuses the same styles in the future becomes trivial. With OOCSS, adding a new type of page to your site should mean that there&#8217;s no need to create additional CSS styles or selectors. New page types should be able to reuse existing CSS styles as much as possible.</p>
<p>When designing a site with OOCSS, you must break your design into reusable components, which OOCSS calls <em>objects</em>. Each component is a fixed HTML structure, to which you apply a set of CSS rules that control its layout (in OOCSS parlance, the <em>structure</em>), and another set of CSS rules that control its appearance (the <em>skin</em>). That component can then contain arbitrary HTML content: paragraphs, lists, tables, and so on, all of which is styled independently of the container in which it appears.</p>
<p>This last point is crucial. Under OOCSS you must avoid what Sullivan calls &#8220;location-based selectors&#8221; &#8212; that is, styles that affect content differently, depending on the part of your site in which it appears. If you want, say, a list to look different in a particular part of your site, you should add a <code>class</code> attribute to it and apply the styles based on that attribute. This ensures that the list can be lifted out and reused elsewhere on the site, with its style remaining intact.</p>
<h2>An Example in Code</h2>
<p>Let&#8217;s say every page of your site had a sidebar, the code for which looked like this:</p>
<pre><code class="css">&lt;div class="sidebar"&gt;
  …sidebar content…
&lt;/div&gt;</code></pre>
<p>Now, let&#8217;s say you had a set of pages where you wanted this sidebar styled a little differently &#8212; say with a different background color to highlight a sale on certain products. You would probably also want to make changes to some other elements of those pages because of this sale, too.</p>
<p>Traditionally, your approach to this might be to add a class to your page&#8217;s <code>&lt;body&gt;</code> tag:</p>
<pre><code class="html">&lt;body class="onsale"&gt;</code></pre>
<p>&#8220;Brilliant!&#8221;, you would think. &#8220;Now I can make all my style adjustments for this sale without making any further changes to my HTML code!&#8221; Then you would set about writing a bunch of style rules like this one:</p>
<pre><code class="css">body.onsale .sidebar {
  background-color: #FFA500;
}</code></pre>
<p>The approach recommended by Object Oriented CSS is quite different. Instead of a single class applied to the <code>body</code> of your page, you would create a new class for each type of element that you wanted to change for the sale. Here&#8217;s what the sale style for the sidebar might look like:</p>
<pre><code class="css">.onsalesidebar {
  /* extends .sidebar */
  background-color: #FFA500;
}</code></pre>
<p>This class is said to <em>extend</em> the existing class that describes the standard style for the element. You then apply it <em>in addition to</em> the existing (base) class:</p>
<pre><code class="html">&lt;div class="sidebar onsalesidebar"&gt;
  …sidebar content…
&lt;/div&gt;</code></pre>
<p>Now, a content editor can confidently copy and paste this sidebar code into another page of your site, or even a brand new page, and know that it will be displayed with the same styles applied. The same principles apply to the styling of the content within this sidebar.</p>
<p>The guidelines for OOCSS actually recommend a considerably more complex HTML structure for reusable components like this, which enable more intricate styles to be applied to them &#8212; including rounded corners and border effects &#8212; but this simple example effectively demonstrates the fundamental principles behind OOCSS.</p>
<h2>What&#8217;s the Point?</h2>
<p>Sullivan works at Yahoo, where her primary focus is on improving web site performance. Aside from the copy-and-paste reusability of styled HTML content and component blocks, OOCSS claims to offer significant benefits in performance.</p>
<p>By prioritizing the reuse of CSS styles across your site, OOCSS results in considerably smaller CSS files, but slightly larger HTML files. This trade-off is desirable because the size of your CSS files directly influences the amount of time that the browser displays a blank page while your site loads. Smaller CSS means less time spent looking at a blank page. Once your CSS has loaded, your site&#8217;s HTML content is displayed progressively as it loads. The result of this trade-off, then, is greater <em>perceived</em> performance, even if the total load time is slightly longer.</p>
<p>Furthermore, by avoiding location-based selectors, you reduce the amount of work that the browser has to do to determine the actual appearance of any given element on the page. Especially on mobile browsers, but even on the desktop, this can produce significant performance gains.</p>
<h2>Is It Worth It?</h2>
<p>If you&#8217;re lucky enough to be the only front-end developer working on a project, you might like to take the OOCSS principles for a spin. Where the reusability benefits of OOCSS really shine, however, is when working in a team environment.</p>
<p>Senior front-end designers can define the reusable structures for the site. Visual designers can apply attractive CSS skins to those structures. Content editors can write the content that slots into those structures with confidence, knowing that only the styles they expect will be applied to the content they write.</p>
<p>Coaxing an entire team to jump aboard the OOCSS bandwagon can be a significant undertaking, however, and that&#8217;s the point I&#8217;m at here at SitePoint. Having applied OOCSS principles to a little project on my own, I now have to decide if it&#8217;s worth bringing this to the SitePoint design team.</p>
<p>What do you think? Are the benefits of OOCSS worth the extra discipline required to adopt it, or is CSS complicated enough already?</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=136&amp;did=adz&amp;adtype=vertical" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=a1f63c783c48c8e1c60c4cbec606216f&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=a1f63c783c48c8e1c60c4cbec606216f&p=1"/></a>
]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/06/16/first-look-object-oriented-css/feed/</wfw:commentRss>
		</item>
		<item>
			<title>Why Blocking Ad Blockers Will Fail</title>
			<link>http://www.pheedcontent.com/click.phdo?i=63228778c3ff574f7de6c8cbf42401f3</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/06/11/blocking-ad-blockers-will-fail/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/06/11/blocking-ad-blockers-will-fail/#comments</comments>
			<pubDate>Wed, 10 Jun 2009 18:10:58 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=10097</guid>
			<description><![CDATA[Craig's previous article provided a method to hide premium content from people using advert blockers. However, today he highlights why your attempts to block the blockers could reduce revenues and harm your business.<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=63228778c3ff574f7de6c8cbf42401f3&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=63228778c3ff574f7de6c8cbf42401f3&p=1"/></a>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/05/083-block-blockers2.png" alt="Blocking blockers will fail" title="Blocking blockers will fail" width="197" height="197" class="imgright" />My previous post, <a href="http://www.sitepoint.com/blogs/2009/06/10/block-ad-blockers">How to Block the Advert Blockers</a> provides a technique that exploits URL regular expression matching. The method hides your premium content from users who are using advert-blocking technology.</p>
<p>The solution might please some site owners and publishers. Unfortunately, there are several reasons why blocking the blockers is futile, self-defeating, and could lead to <em>less</em> advert revenue.</p>
<p><strong>1. You won&#8217;t stop every ad blocker</strong><br />
The code provided will work for some ad blockers some of the time, but it certainly will not stop every one. No single technique will ever be suitable in all situations. Will the cost and effort required to implement multiple solutions ever be recouped?</p>
<p><strong>2. Accessibility problems</strong><br />
Your page will fail for anyone who has JavaScript disabled. It may also fail for those using alternative devices such as screen readers. That might be acceptable to you &#8212; those users are not viewing your adverts either. However, it is also likely to affect a proportion of your regular visitors. Be prepared for complaints and additional support costs.</p>
<div id="adz" class="vertical"></div><p><strong>3. It&#8217;s easy to beat</strong><br />
Anyone with modest technical skills can prevent your block. The majority of Adblock users are technically literate: all are Firefox users who install browser add-ons, many will understand how the blocker works, and some will edit their own regular expressions.</p>
<p>Your content can be revealed by changing the Adblock rules, viewing the source code, disabling CSS, using an alternative stylesheet, or modifying the code using Firebug or the Web Developer Toolbar.</p>
<p><strong>4. Your revenue may not be affected&#8230;</strong><br />
They majority of advert revenue is raised when a visitor clicks an advert. AdBlock users are far less likely to click adverts even if they are <em>forced</em> to view them. Will blocking the blockers really increase your advertising revenue?</p>
<p><strong>5. &#8230;or it could go down</strong><br />
Blocking your premium content simply makes it unavailable to a proportion of users. Will that concern them or will they go elsewhere? These visitors are your customers: making it difficult for them could harm your business.</p>
<p>We have already established that visitors using ad blockers are likely to be technically literate. These are the very people who might have blogs, use online bookmarking, or participate in social networking. Will they link to your content if you&#8217;re making it more difficult to view? How would that affect your link building and viral marketing effort?</p>
<p>The web is not the same as print and you cannot force a user to view a page the way you intended. Anyone can block adverts, images, CSS, JavaScript, Java, Flash, ActiveX, or modify any aspect of your page to their own personal preference.</p>
<p>If you write articles to make money and are convinced advert blockers affect your revenue, there is a simple solution: start charging for content. Why publish content under the pretense that it&#8217;s free/sponsored, then complain about a proportion of users who fail to click ads? What is really at fault &#8212; the ad blockers or the business model?</p>
<p>Ultimately, I suspect advert blockers have a negligible monetary effect on the majority of web sites. If revenue is down, perhaps there are more obvious problems to address first?</p>
<p>See also: </p>
<ul>
<li><a href="http://www.sitepoint.com/blogs/2009/06/10/block-ad-blockers">How to Block the Advert Blockers</a></li>
<li><a href="http://www.sitepoint.com/blogs/2009/05/27/file-naming-important/">Why File Naming is More Important Than You Think</a></li>
</ul>
<p>Do you use an advert blocker? Are they the scourge of the internet? Are you convinced they have a negative effect on your advertising revenues?</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=136&amp;did=adz&amp;adtype=vertical" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=63228778c3ff574f7de6c8cbf42401f3&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=63228778c3ff574f7de6c8cbf42401f3&p=1"/></a>
]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/06/11/blocking-ad-blockers-will-fail/feed/</wfw:commentRss>
		</item>
		<item>
			<title>How to Block the Advert Blockers</title>
			<link>http://www.pheedcontent.com/click.phdo?i=e9e60167ccdd82ffa3845056a97af042</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/06/10/block-ad-blockers/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/06/10/block-ad-blockers/#comments</comments>
			<pubDate>Tue, 09 Jun 2009 17:55:50 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=10086</guid>
			<description><![CDATA[It may not be possible to detect ad blockers, but you can get around them. In the first of a two-part article, Craig provides a simple technique to block the blockers - but should you use it?<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=e9e60167ccdd82ffa3845056a97af042&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=e9e60167ccdd82ffa3845056a97af042&p=1"/></a>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/05/082-block-blockers.png" alt="block advert blockers" title="block advert blockers" width="197" height="197" class="imgright" />I recently wrote an article about <a href="http://www.sitepoint.com/blogs/2009/05/27/file-naming-important/">why it&#8217;s important to choose file names that are not inadvertently blocked by ad blockers</a>. The comments revealed that advert-blocking technology annoyed many site owners. Why should they produce premium content if they can not receive revenue in return?</p>
<p>Detecting for the presence of advert blockers is not possible. Different implementation technologies are used and they are not necessarily embedded in the browser. Ad blockers also work in different ways: some use a long list of advertiser domains whilst others use regular expressions to suppress matching URLs.</p>
<p>Regular expression matching is used by one of the most popular blockers, <a href="http://adblockplus.org/">Firefox&#8217;s Adblock Plus add-on</a>. However, we can exploit URL checking using a technique that prevents Adblock users viewing your content unless they disable the add-on.</p>
<p>Your HTML page should follow this example:</p>
<pre><code class="html">
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"&gt;
&lt;title&gt;Advert Blocker blocking&lt;/title&gt;
&lt;meta http-equiv="content-language" content="en"&gt;&lt;meta name="language" content="en"&gt;

&lt;style type="text/css"&gt;
#content { display: none; }

#blockermessage
{
	font-weight: bold;
	text-align: center;
	padding: 4px;
	color: #fff;
	background-color: #c00;
}
&lt;/style&gt;

&lt;script type="text/javascript" src="/banner-advert.js"&gt;&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;

	&lt;div id="content"&gt;
		&lt;h1&gt;Main content&lt;/h1&gt;
		&lt;p&gt;This will be hidden to people using advert blockers.&lt;/p&gt;
	&lt;/div&gt;

	&lt;div id="blockermessage"&gt;
		&lt;p&gt;Please switch of your advert blocker and enable JavaScript to view this page.&lt;/p&gt;
	&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>Explanation:</p>
<ul>
<li>The main content should be contained within an outer element, such as <code>&lt;div id="content"&gt;</code>.</li>
<li>You should provide an alternative message for people using an advert blocker, as shown in <code>&lt;div id="blockermessage"&gt;</code>.</li>
<li>It is important that the first two CSS rules on the page style these elements. Since external CSS file can be blocked, I would recommend embedding it directly in the HTML. The #content rule must be set to <code>display: none</code>, whilst the #blockermessage rule can be styled big, bold or in any way you choose.</li>
<li>Finally, an external JavaScript file is included. This should be given a file/folder name that will trigger ad-blocking rules, e.g. banner-advert.js.</li>
</ul>
<p>The code for banner-advert.js:</p>
<pre><code class="javascript">
// reveal content to those not using an advert blocker
if (document.styleSheets &amp;&amp; document.styleSheets.length > 0) {
	var ss = document.styleSheets[0];
	var bRule = (ss.cssRules ? ss.cssRules : ss.rules);
	if (bRule.length > 1) {
		bRule[0].style.display = "block";
		bRule[1].style.display = "none";
	}
}
</code></pre>
<p>It works in the following way:</p>
<div id="adz" class="vertical"></div><ol>
<li>As the page is loaded, the main content is switched off for everyone and only the #blockermessage is shown.</li>
<li>For most people, the banner-advert.js code is executed immediately. This alters the embedded styles so #content becomes visible and #blockermessage is hidden. It occurs before the main content is displayed so users should not see any difference.</li>
<li>AdBlock will spot banner-advert.js and refuse to load it. The styles are not modified so the main content remains hidden.</li>
</ol>
<p>That should please many premium content site owners. But &#8212; hold back &#8212; <strong>I strongly recommend you do not implement this on your web site!</strong> There are a number of technical issues and blocking the blockers is futile &#8230; see <a href="http://www.sitepoint.com/blogs/2009/06/11/blocking-ad-blockers-will-fail/">Why Blocking Ad Blockers Will Fail</a>.</p>
<p>See also: <a href="http://www.sitepoint.com/blogs/2009/05/27/file-naming-important/">Why File Naming is More Important Than You Think</a>.</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=136&amp;did=adz&amp;adtype=vertical" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=e9e60167ccdd82ffa3845056a97af042&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=e9e60167ccdd82ffa3845056a97af042&p=1"/></a>
]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/06/10/block-ad-blockers/feed/</wfw:commentRss>
		</item>
		<item>
			<title>The Two Ways of Sizing Absolute Elements in CSS</title>
			<link>http://www.pheedcontent.com/click.phdo?i=fddc24e646e6c4985aea6128306927ef</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/06/02/css-sizing-absolute-position/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/06/02/css-sizing-absolute-position/#comments</comments>
			<pubDate>Mon, 01 Jun 2009 18:38:54 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<category>CSS</category>
			<category>JavaScript</category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=9703</guid>
			<description><![CDATA[Most developers have used left, right, top and bottom properties with an absolutely-positioned element. But did you know that all four properties can be set at the same time?<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=fddc24e646e6c4985aea6128306927ef&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=fddc24e646e6c4985aea6128306927ef&p=1"/></a>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/05/071-absolute-sizing.jpg" alt="Absolute Sizing" title="Absolute Sizing" width="220" height="220" class="imgright" />Anyone who has used CSS for a while will know about the merits of absolute and relative positioning. To recap:</p>
<p><strong><code>position: relative</code></strong> allows an element to be shifted from its original position either horizontally (using <code>left</code> or <code>right</code>) or vertically (using <code>top</code> or <code>bottom</code>).</p>
<p><strong><code>position: absolute</code></strong> allows an element to be positioned with respect to a containing block using <code>left</code>, <code>right</code>, <code>top</code> or <code>bottom</code> (the containing block is the nearest ancestor node with a position of relative, absolute or fixed).</p>
<p>Positioning nodes is therefore straightforward, e.g.</p>
<div id="adz" class="horizontal"></div><p><strong>HTML:</strong></p>
<pre><code class="html">
&lt;div id="outer"&gt;
	&lt;div id="inner"&gt;&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p><strong>CSS:</strong></p>
<pre><code class="css">
#outer
{
	position: relative;
	width: 200px;
	height: 200px;
	margin: 20px auto;
	border: 2px solid #c00;
}

#inner
{
	position: absolute;
	left: 50px;
	top: 50px;
	width: 96px;
	height: 96px;
	background-color: #ddc;
	border: 2px solid #00c;
}
</code></pre>
<p><em>(The actual width and height of the inner block will be 100px owing to the addition of the border).</em></p>
<p>The following boxes are rendered in every modern browser (including IE6):</p>
<div id="outer" style="position: relative; width: 200px; height: 200px; margin: 20px auto; border: 2px solid #c00;">
<div id="inner" style=" position: absolute; left: 50px; top: 50px; width: 96px; height: 96px; background-color: #ddc; border: 2px solid #00c;">&nbsp;</div>
</p></div>
<p>Less well known is that you can apply all the <code>left</code>, <code>right</code>, <code>top</code> and <code>bottom</code> properties at the <strong>same</strong> time. The following CSS will render the inner element  identically:</p>
<pre><code class="css">
#inner
{
	position: absolute;
	left: 50px;
	right: 50px;
	top: 50px;
	bottom: 50px;
	background-color: #ddc;
	border: 2px solid #00c;
}
</code></pre>
<p>The width and height of the inner box will remain 100px, but we do not need to need to explicitly set the dimensions.</p>
<p>This could be useful when:</p>
<ul>
<li>the spacing around the element is more critical than the width or height. You can also use negative <code>left</code>, <code>right</code>, <code>top</code> and/or <code>bottom</code> properties to make the inner box larger than its outer parent.</li>
<li>you have multiple inner elements with differing borders and padding but need consistent outer spacing. This method allows you to create a single style for all those elements.</li>
</ul>
<p>JavaScript animations can also benefit since it can be easier and quicker to resize an element if you do not need to calculate the resulting width and height, e.g.</p>
<pre><code class="javascript">
// expands and contracts the inner box
window.onload = function() {

	var inner = document.getElementById("inner");
	var offset = 100, dir = -1;
	setInterval(function() {
		inner.style.left = inner.style.right = inner.style.top = inner.style.bottom = offset+"px";
		offset += dir;
		if (offset == 0 || offset == 100) dir = -dir;
	}, 10);
	
}
</code></pre>
<p><strong>A note about browser compatibility:</strong> this technique works in all the main browsers, <em>except</em> IE6 which only understands explicit widths and heights. There&#8217;s a surprise!</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=137&amp;did=adz&amp;adtype=horizontal" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=fddc24e646e6c4985aea6128306927ef&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=fddc24e646e6c4985aea6128306927ef&p=1"/></a>
]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/06/02/css-sizing-absolute-position/feed/</wfw:commentRss>
		</item>
		<item>
			<title>How to Override Inline CSS Styles</title>
			<link>http://www.pheedcontent.com/click.phdo?i=99e518240057034c667a7f5fbbdff791</link>
			<pheedo:origLink>http://www.sitepoint.com/blogs/2009/05/27/override-inline-css/</pheedo:origLink>
			<comments>http://www.sitepoint.com/blogs/2009/05/27/override-inline-css/#comments</comments>
			<pubDate>Tue, 26 May 2009 16:07:38 +0000</pubDate>
			<dc:creator>Craig Buckler</dc:creator>
			<category><![CDATA[JavaScript & CSS]]></category>
			<category>css</category>
			<category>styles</category>
			<guid isPermaLink="false">http://www.sitepoint.com/blogs/?p=9835</guid>
			<description><![CDATA[Inline CSS can be applied to any HTML element using the style attribute and it is generally treated as the most important definition. However, there is a way to override inline CSS from an external stylesheet.<br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=99e518240057034c667a7f5fbbdff791&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=99e518240057034c667a7f5fbbdff791&p=1"/></a>
]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.sitepoint.com/blogs/wp-content/uploads/2009/05/075-override-inline-css.jpg" alt="Override inline CSS" title="Override inline CSS" width="260" height="260" class="imgright" />One of the most powerful features of CSS is the cascading. Knowing how a browser chooses and applies your styles is invaluable knowledge. Novices can find it especially confusing given that style use is influenced by the method used to include the CSS, the order of the rules, how the selectors are specified, and special declarations such as <code>!important</code>.</p>
<p>Inline styles are those defined in the HTML itself, e.g.</p>
<pre><code class="html">
&lt;p&gt;This is an 
&lt;strong style="color: red;"&gt;inline style that should be blue&lt;/strong&gt;
.&lt;/p&gt;
</code></pre>
<p>Inline styles have the highest priority of all CSS. In general, I would recommend you avoid using them and place your CSS declarations in external files. However, you may not have that luxury if you are working on a legacy system or do not have direct access to the HTML code.</p>
<p>Fortunately, there <strong>is</strong> a way to override inline styles from an external stylesheet:</p>
<div id="adz" class="horizontal"></div><pre><code class="css">
strong[style] { color: blue !important; }
</code></pre>
<p>This will force the text in the <code>strong</code> tag to become blue in the example above. The method appears to work in all major browser, including:</p>
<ul>
<li>Internet Explorer 8.0</li>
<li>Mozilla Firefox 2 and 3</li>
<li>Opera 9</li>
<li>Apple Safari, and</li>
<li>Google Chrome</li>
</ul>
<p>Internet Explorer 6 and 7 are the notable exceptions. However, this technique is not something you should use on a day-to-day basis. Keep your CSS clean and only override inline styles when there is absolutely no alternative.</p>
<script src="http://ads.aws.sitepoint.com/adjs.php?region=137&amp;did=adz&amp;adtype=horizontal" type="text/javascript"></script><br clear="both" style="clear: both;"/>
<br clear="both" style="clear: both;"/>
<a href="http://ads.pheedo.com/click.phdo?s=99e518240057034c667a7f5fbbdff791&p=1"><img alt="" style="border: 0;" border="0" src="http://ads.pheedo.com/img.phdo?s=99e518240057034c667a7f5fbbdff791&p=1"/></a>
]]></content:encoded>
			<wfw:commentRss>http://www.sitepoint.com/blogs/2009/05/27/override-inline-css/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
<!-- Dynamic Page Served (once) in 1.360 seconds -->