<?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>Derek Punsalan - 5THIRTYONE &#187; code</title> <atom:link href="http://5thirtyone.com/archives/tag/code/feed" rel="self" type="application/rss+xml" /><link>http://5thirtyone.com</link> <description>A personal site by Derek Punsalan sharing personal interests with technology, WordPress, design, and general geekery.</description> <lastBuildDate>Wed, 28 Jul 2010 19:35:03 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0</generator> <atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/> <item><title>CSS + jQuery: Highlight important keywords inside text</title><link>http://5thirtyone.com/archives/2206</link> <comments>http://5thirtyone.com/archives/2206#comments</comments> <pubDate>Tue, 22 Dec 2009 22:47:20 +0000</pubDate> <dc:creator>Derek</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[code]]></category> <category><![CDATA[css]]></category> <category><![CDATA[define]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[sample]]></category><guid
isPermaLink="false">http://5thirtyone.com/?p=2206</guid> <description><![CDATA[A few days ago while working on a new UI component I had to come up with a solution to highlight identified keywords (using named entity recognition) inside of a chunk of user generated text. While the idea was fairly simple, the challenge was creating a solution which would work [relatively] well for all modern [...]]]></description> <content:encoded><![CDATA[<p
align="center"><a
href="http://5thirtyone.com/sandbox/samples/fadefocus/"><img
src="http://5thirtyone.com/wp-content/uploads/2009/12/sample-screenshot.png" alt="CSS+jQuery Sample Screenshot" /></a></p><p>A few days ago while working on a new UI component I had to come up with a solution to highlight identified keywords (using <a
href="http://en.wikipedia.org/wiki/Named_entity_recognition">named entity recognition</a>) inside of a chunk of user generated text. While the idea was fairly simple, the challenge was creating a solution which would work [relatively] well for <em>all</em> modern browsers including IE7, IE8, Firefox, Safari, and Chrome.</p><p
align="center"><a
class="demo-button" href="http://5thirtyone.com/sandbox/samples/fadefocus/" title="View Demo">View Demo</a></p><h3>Background</h3><p>The easiest solution to highlight keywords inside of a chunk of text would be to swap font colors, maybe even change the &quot;highlighted&quot; background color and type weight for added emphasis. However, the easiest solution is not always the best solution. Relying on font color and weight alone is not enough.</p><ul><li><strong>Images</strong> &#8211; Photos are full of color, bold, and attractive. Ignore these while toggling the text color of de-emphasized / emphasized content and a visitors eyes will still wander.</li><li><strong>Dynamic</strong> &#8211; Content may be user generated. Assuming basic HTML like &lt;em&gt;, &lt;strong&gt;, &lt;a&gt;, etc are supported, original styles should remain untouched.</li></ul><p>The better solution would be to create a &quot;mask&quot; overlaying the source content while using a spotlight-esque effect to highlight keywords. The overlay method is a safer option which reduces the likelihood of overriding any user generated content [styles].</p><h3>Example HTML</h3><p>This demo is a simplified version of the original code &#8211; shared as an example for fading the source content and highlighting important keywords within. Originally planned for use where classes are dynamically generated and wrapped around identified keywords, I have manually inserted classes for the purpose of this demo. The basic example HTML is below (text sampled from the <a
href="http://en.wikipedia.org/wiki/Avatar">Avatar Wikipedia</a> entry):</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td
class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrapper&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;entity-results&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;d1&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Summary<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;d2&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Avatar<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;d3&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Formats<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>Avatar (2009 film)<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;entity-source&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/avatar.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Avatar poster&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Avatar, also known as James Cameron's Avatar, is an American 3-D science fiction epic film written and directed by <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://en.wikipedia.org/wiki/James_Cameron&quot;</span>&gt;</span>James Cameron<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>, and was released on December 16, 2009 by 20th Century Fox. The film is co-produced by <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://en.wikipedia.org/wiki/Lightstorm_Entertainment&quot;</span>&gt;</span>Lightstorm Entertainment<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>, and <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;d1&quot;</span>&gt;</span>focuses on an epic conflict on Pandora<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>, an inhabited Earth-sized moon of Polyphemus, one of three fictional gas giants orbiting <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://en.wikipedia.org/wiki/Alpha_Centauri_A&quot;</span>&gt;</span>Alpha Centauri A<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>. On Pandora, human colonists and the sentient humanoid indigenous inhabitants of Pandora, the Na'vi, engage in a war over the planet's resources and the latter's continued existence. The film's title refers to <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;d2&quot;</span>&gt;</span>an avatar, a representation of a real person in a virtual world<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;d3&quot;</span>&gt;</span>The film was released in 2D and 3D formats<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>, along with an IMAX 3D release in selected theaters. The film is being touted as a breakthrough in terms of filmmaking technology, for its development of 3D viewing and stereoscopic filmmaking with cameras that were specially designed for the film's production.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Read the rest of the <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://en.wikipedia.org/wiki/Avatar_(2009_film)&quot;</span>&gt;</span>original Wikipedia page about Avatar<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mask&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div><p><code>.entity-results</code> is a sample list corresponding to select text inside of the <code>.entity-source</code> wrapper. Each <code>&lt;li&gt;&lt;a&gt;&lt;/li&gt;</code> has a matching keyword phrase wrapped in the same class. Ideally these are dynamically included in the document. The &quot;mask&quot; is included inline as an empty <code>&lt;div&gt;</code> which can also be inserted using JavaScript.</p><h3>Minimal CSS requirement</h3><p>Using a few lines of CSS, overlay a mask above the content. The <code>&lt;span&gt;</code> around the keywords to highlight is crucial in order to pull the text out above the mask.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td
class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.entity-source</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.entity-source</span> span<span style="color: #6666ff;">.show</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.entity-source</span> <span style="color: #6666ff;">.mask</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.entity-source</span> span <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.entity-source</span> span<span style="color: #6666ff;">.show</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ffc</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div><h3>Example jQuery</h3><p>The example uses jQuery to handle the opacity changes and toggle of active / inactive states for detected keywords.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td
class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// mask source</span>
    <span style="color: #003366; font-weight: bold;">var</span> maskSource <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.mask'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.entity-results'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        maskSource.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>opacity<span style="color: #339933;">:</span><span style="color: #CC0000;">0.7</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'750'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        maskSource.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'1000'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// match hover</span>
    <span style="color: #003366; font-weight: bold;">var</span> sample1 <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span.d1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> sample2 <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span.d2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> sample3 <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span.d3'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.d1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        sample1.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'show'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        sample1.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'show'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.d2'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        sample2.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'show'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        sample2.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'show'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.d3'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        sample3.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'show'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        sample3.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'show'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>When your mouse cursor hovers over a keyword in the right sidebar, the mask is set to display block with opacity handled by the jQuery <a
href="http://docs.jquery.com/Effects/animate">.animate()</a> effect. View the demo below or <a
href="http://5thirtyone.com/sandbox/samples/fadefocus/all.zip">download the source</a>.</p><p
align="center"><a
class="demo-button" href="http://5thirtyone.com/sandbox/samples/fadefocus/" title="View Demo">View Demo</a></p><div
id="wherego_related"><h3>Readers Also Read</h3><ul><li><a
href="http://5thirtyone.com/archives/1110" rel="bookmark" class="wherego_title">Create a WordPress reader &quot;explore&quot; block to promote content</a></li><li><a
href="http://5thirtyone.com/archives/774" rel="bookmark" class="wherego_title">How-to style WordPress author comments</a></li><li><a
href="http://5thirtyone.com/archives/2212" rel="bookmark" class="wherego_title">BHEESTIE Bag saves me $200: iPhone 1 vs. Heavy rain 0</a></li><li><a
href="http://5thirtyone.com/archives/2049" rel="bookmark" class="wherego_title">Backblaze: Secure unlimited automatic backups for $5</a></li><li><a
href="http://5thirtyone.com/archives/788" rel="bookmark" class="wherego_title">Preventing content from &quot;shifting&quot; for Adblockers</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://5thirtyone.com/archives/2206/feed</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Create a WordPress reader &quot;explore&quot; block to promote content</title><link>http://5thirtyone.com/archives/1110</link> <comments>http://5thirtyone.com/archives/1110#comments</comments> <pubDate>Mon, 20 Oct 2008 05:55:12 +0000</pubDate> <dc:creator>Derek</dc:creator> <category><![CDATA[WordPress]]></category> <category><![CDATA[code]]></category> <category><![CDATA[explore]]></category> <category><![CDATA[Tutorial]]></category><guid
isPermaLink="false">http://5thirtyone.com/?p=1110</guid> <description><![CDATA[Congrats. You have your own WordPress blog. Each passing day results in a handful of new unique readers. As your site continues to grow, convincing visitors to explore your site beyond your most recent posts becomes more of a challenge. Additionally, getting visitors &#8211; who happen upon older posts via search engines &#8211; to visit [...]]]></description> <content:encoded><![CDATA[<p>Congrats. You have your own <a
href="http://www.wordpress.org" title="WordPress - Blog Tool and Publishing Platform">WordPress</a> blog. Each passing day results in a handful of new unique readers. As your site continues to grow, convincing visitors to explore your site beyond your most recent posts becomes more of a challenge. Additionally, getting visitors &#8211; who happen upon older posts via search engines &#8211; to visit newer content is no small feat either. You can imagine the challenge of convincing both reader types to check out the rest of the content between your oldest and most recent posts.</p><p>Without going into detail concerning elements that your site should have, let&#8217;s look at one element that all blogs can leverage for increased page views. How do you get readers to explore content beyond their current view? By including a simple block element that introduces content before / after the current post, or articles deep within the archives. What is this simple block element comprised of?</p><ul><li>Previous post &#8211; reverse chronological (if one exists)</li><li>Next post &#8211; chronological (if one exists)</li><li>Posts sharing the same categories</li><li>Posts with similar tags</li></ul><p>If you browse the WordPress codex, or explore the individual files inside the default theme each installation includes, you&#8217;ll notice all of the required functions needed to create a simple &quot;explore&quot; &#8211; similar to what I have implemented on 5thirtyone.com. It really is just a matter of collection the functions, adding a little semantic markup, and styling to taste. The functions necessary are:</p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">&lt;?php</span> previous_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%link'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p><a
href="http://codex.wordpress.org/Template_Tags/previous_post_link">Codex:</a> <em>Used on single post permalink pages, this template tag displays a link to the previous post which exists in chronological order from the current post.</em></p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">&lt;?php</span> next_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%link'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p><a
href="http://codex.wordpress.org/Template_Tags/next_post_link">Codex:</a> <em>Used on single post permalink pages, this template tag displays a link to the next post which exists in chronological order from the current post.</em></p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p><a
href="http://codex.wordpress.org/Template_Tags/the_category">Codex:</a> <em>Displays a link to the category or categories a post belongs to. This tag must be used within The Loop.</em></p><div
class="wp_syntax"><div
class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_tags<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p><a
href="http://codex.wordpress.org/Template_Tags/the_tags">Codex:</a> <em>First available with WordPress Version 2.3, this template tag displays a link to the tag or tags a post belongs to. If no tags are associated with the current entry, the associated category is displayed instead. This tag should be used within The Loop.</em></p><h3>Put it all together</h3><p>Four simple functions placed together create an invaluable resource for readers to explore your archived content from various slices.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;ul class=&quot;exploreThese&quot;&gt;
		&lt;li&gt;Previous: <span style="color: #000000; font-weight: bold;">&lt;?php</span> previous_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%link'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #666666; font-style: italic;">/* if next post exists */</span> next_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;li&gt;Next: %link&lt;/li&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;li&gt;Category: <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;
		&lt;li&gt;Tag: <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_tags<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/li&gt;
	&lt;/ul&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div><p>The markup above generates an unstyled unordered list which when rendered provides:</p><p
align="center"><img
src="http://5thirtyone.com/wp-content/uploads/2008/10/explore-unstyled.gif" alt="Unstyled explore links" /></p><ul><li>Line 1 &amp; 8: Standard <a
href="http://codex.wordpress.org/The_Loop_in_Action">WordPress loop</a> &#8211; required if you are re-using this code outside of the standard loop in single.php.</li><li>Line 3: Title (link) of a previous post.</li><li>Line 4: Title (link) of the next post. If there are no newer posts, the entire line is ignored. Thanks <a
href="http://www.cavemonkey50.com">Ronald</a>.</li><li>Line 5: Renders assigned categories (comma separated). Links to an archive page for posts sharing the same category.</li><li>Line 6: Renders assigned tags (comma separated). Each tag links to an archive page for posts sharing the same tags.</li></ul><p>Drop the block of code somewhere inside single.php so that WordPress knows to generate the proper links. Note that if you do plan on inserting the code outside of the standard loop, lines 1 &amp; 8 are required.</p><h3>Expand on the explore block</h3><p>Looking for more options to offer your readers? Check out some of these functions and plugins to add to the explore block: <a
href="http://codex.wordpress.org/Template_Tags/wp_dropdown_categories#Examples">wp_dropdown_categories</a>, <a
href="http://codex.wordpress.org/Template_Tags/wp_get_archives#Examples">wp_get_archives</a>, <a
href="http://codex.wordpress.org/Template_Tags/wp_tag_cloud#Examples">wp_tag_cloud</a>, <a
href="http://fairyfish.net/2007/09/12/wordpress-23-related-posts-plugin/">Related Posts</a>, or <a
href="http://wordpress.org/extend/plugins/random-redirect/">Random Redirect</a>. Hopefully there is enough to expand on the idea of the reader explore block on your own. Feel free to drop any questions in the comments. [<a
href="http://digg.com/software/The_WordPress_reader_explore_block_for_promoting_content">Digg this</a>]</p><div
id="wherego_related"><h3>Readers Also Read</h3><ul><li><a
href="http://5thirtyone.com/archives/1089" rel="bookmark" class="wherego_title">Some apps &amp; games stay on my iPhone out of guilt</a></li><li><a
href="http://5thirtyone.com/archives/1083" rel="bookmark" class="wherego_title">10 step guide for improving a vanilla WordPress install</a></li><li><a
href="http://5thirtyone.com/archives/875" rel="bookmark" class="wherego_title">WordPress Custom Fields; laying text over your lead graphic</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://5thirtyone.com/archives/1110/feed</wfw:commentRss> <slash:comments>15</slash:comments> </item> <item><title>Preventing content from &quot;shifting&quot; for Adblockers</title><link>http://5thirtyone.com/archives/788</link> <comments>http://5thirtyone.com/archives/788#comments</comments> <pubDate>Wed, 14 Mar 2007 07:57:20 +0000</pubDate> <dc:creator>Derek</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[adblock]]></category> <category><![CDATA[code]]></category> <category><![CDATA[css]]></category> <category><![CDATA[design]]></category> <category><![CDATA[xhtml]]></category><guid
isPermaLink="false">http://5thirtyone.com/archives/788</guid> <description><![CDATA[Anyone who inserts contextual advertisements into their pages &#8211; like Google Adsense &#8211; are aware of the fact that some readers block advertisements. Oftentimes, methods for removing advertisements from view alter the structure of a page, in turn, changing the layout. For some websites or blogs, this does not pose a problem. For websites created [...]]]></description> <content:encoded><![CDATA[<p
align="center"><img
src="/wp-content/uploads/2007/03/adsense_blocked.gif" alt="Consistent page with or without ads" /></p><p>Anyone who inserts contextual advertisements into their pages &#8211; like Google Adsense &#8211; are  aware of the fact that some readers <em>block advertisements</em>. Oftentimes, methods for removing advertisements from view alter the structure of a page, in turn, changing the layout. For some websites or blogs, this does not pose a problem. For websites created to present both content and advertisements in harmony, removing ad elements may have a negative impact on a pages layout.</p><h3>Ultimately, the author controls layout</h3><p>Contrary to what some readers [would like to] believe, the author <em>ultimately</em> controls how content is displayed on a site. The author also reserves the right to present advertisements [hopefully, in a tasteful manner]. The argument for both sides of the fence is lengthy and one which this post does not address. What we will address is the use of simple HTML/CSS to designate advertisement elements. Areas of a page which do not collapse are disappear from view using rudimentary adblocking tools like <a
href="https://addons.mozilla.org/firefox/10/">Firefox&#8217;s Adblock extension</a>.</p><h3>Prevent the adblock &quot;shift&quot;</h3><p>When users remove standard advertisement scripts from view, the ad element collapses moving surrounding elements. In order to control the layout of a page from shifting, I wrap the ad <code>script</code> with a <code>div</code> which I then apply a fixed width &amp; height to using CSS. I also add a &quot;title&quot; to the <code>div</code> to let readers with adblocking enabled know what is missing.</p><p
align="center"><img
src="/wp-content/uploads/2007/03/adsense_bordered.jpg" alt="1px bordered Adsense block" /></p><p>The corresponding HTML for a 468&#215;60 text link Google Banner might look like:</p><p><code>&lt;div id=&quot;adsense_468&quot;&gt;<br
/> &lt;p id=&quot;adtitle&quot;&gt;Advertisement&lt;/p&gt;<br
/> &lt;center&gt;...INSERT ADSENSE CODE...&lt;/center&gt;<br
/> &lt;/div&gt;</code></p><p>With a few lines of CSS, add a fixed width &amp; height to the <code>#adsense_468</code>. Similar to the advertisement presentation for the Grid Focus, we&#8217;ll also add a 1px border and use <code>position: absolute;</code> to move the title to the top right corner.</p><p><code>#adsense_468 { width: 495px; height: 70px; border: 1px solid #BBB; padding-top: 5px; position: relative; }<br
/> #adsense_468 #adtitle { font-size: 11px; position: absolute; display: block; background: #FFF; padding:0 3px; top: -8px; right: 12px; }</code></p><p>The question now is, <em>who out there is adblocking?</em> Come clean! <img
src='http://5thirtyone.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><h3>Take Care of your Hosting Issues</h3><p>Worried that you are paying to much for <a
href="http://www.fortunecity.com/">your hosting</a>? Get the best <a
href="http://www.hosting-website.us/">website hosting</a> available. They can also take care of your <a
href="http://www.hosting-website.us/domain-registration.html">domain registration needs</a>, making it easier than ever to <a
href="http://www.west.asu.edu/IT/start/web_tools/resources.htm">host a site</a> without breaking the bank.</p><div
id="wherego_related"><h3>Readers Also Read</h3><ul></ul></div>]]></content:encoded> <wfw:commentRss>http://5thirtyone.com/archives/788/feed</wfw:commentRss> <slash:comments>28</slash:comments> </item> <item><title>5 HTML bits you may not know</title><link>http://5thirtyone.com/archives/588</link> <comments>http://5thirtyone.com/archives/588#comments</comments> <pubDate>Wed, 16 Aug 2006 09:41:43 +0000</pubDate> <dc:creator>Derek</dc:creator> <category><![CDATA[Tutorial]]></category> <category><![CDATA[code]]></category> <category><![CDATA[html]]></category><guid
isPermaLink="false">http://5thirtyone.com/archives/588</guid> <description><![CDATA[How come [some] these 5 HTML elements are not more widely known? This is a list of HTML elements I&#8217;ve found to be very poorly represented in most markup on the web today. Many of these elements offer more semantic value than actual functionality, but with the rising popularity of CSS driven design where HTML [...]]]></description> <content:encoded><![CDATA[<p>How come [some] these <a
href="http://www.seomoz.org/blogdetail.php?ID=1282" title="5 HTML elements you might now know" rel="external">5 HTML elements</a> are not more widely known?</p><blockquote><p>This is a list of HTML elements I&#8217;ve found to be very poorly represented in most markup on the web today. Many of these elements offer more semantic value than actual functionality, but with the rising popularity of CSS driven design where HTML elements are used for what they were actually intended for, I felt shining a little light on them was appropriate.</p></blockquote><p><em>[W]here HTML elements are used for what they were actually intended for</em>. Ouch. You got me. I&#8217;ve been guilty of using a definition list here or there for *cough* non-definition list elements.</p><p>Anyhow, check out the &lt;address&gt; tag which can be styled with a wee bit &#8216;o CSS.</p><p><code>&lt;address&gt;<br
/> 5thirtyone.com<br
/> &lt;br /&gt;<br
/> 1234 Pine St.<br
/> &lt;br /&gt;<br
/> Seattle, WA<br
/> &lt;br /&gt;<br
/> Phone: (123) 456-7890<br
/> &lt;/address&gt;</code></p><p>Check out the remaining <a
href="http://www.seomoz.org/blogdetail.php?ID=1282" title="5 HTML elements you might now know" rel="external">elements</a>. Don&#8217;t be coy, admit anything that is altogether new to you.</p><div
id="wherego_related"></div>]]></content:encoded> <wfw:commentRss>http://5thirtyone.com/archives/588/feed</wfw:commentRss> <slash:comments>5</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 13/23 queries in 0.031 seconds using disk

Served from: 5thirtyone.com @ 2010-07-30 05:11:57 -->