<?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>Fit to Page</title>
	<atom:link href="http://fittopage.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://fittopage.org</link>
	<description></description>
	<lastBuildDate>Thu, 03 Jun 2010 07:12:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>En and Em dashes in KDE</title>
		<link>http://fittopage.org/2010/06/03/en-and-em-dashes-in-kde/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=en-and-em-dashes-in-kde</link>
		<comments>http://fittopage.org/2010/06/03/en-and-em-dashes-in-kde/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 07:12:42 +0000</pubDate>
		<dc:creator>nelson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fittopage.org/?p=100</guid>
		<description><![CDATA[I&#8217;m a bit of typography geek, so hunting down in KCharSelect for en dash (–) or em dash (—) feels like a lot of trouble. No more! Alt Gr + -(hyphen) = en dash Alt Gr + Shift + -(hyphen) &#8230; <a href="http://fittopage.org/2010/06/03/en-and-em-dashes-in-kde/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a bit of typography geek, so hunting down in <a href="http://utils.kde.org/projects/kcharselect/">KCharSelect</a> for <a href="http://cutewriting.blogspot.com/2008/06/en-dash-em-dash-and-hyphen.html">en dash (–) or em dash (—)</a> feels like a lot of trouble. No more!</p>
<p><code>Alt Gr + -</code>(hyphen) = en dash<br />
<code>Alt Gr + Shift + -</code>(hyphen) = em dash</p>
<p>Not sure if the same happens in Gnome; let me know if it works for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://fittopage.org/2010/06/03/en-and-em-dashes-in-kde/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tabs, done right</title>
		<link>http://fittopage.org/2010/05/30/tabs-done-right/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tabs-done-right</link>
		<comments>http://fittopage.org/2010/05/30/tabs-done-right/#comments</comments>
		<pubDate>Sun, 30 May 2010 18:52:23 +0000</pubDate>
		<dc:creator>nelson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fittopage.org/?p=81</guid>
		<description><![CDATA[There are a lot of JavaScript-driven tab widgets around the web. All of the major JS libraries provide a tabs widget, and this is such a common user interface pattern that the ARIA specification includes several roles (tab, tablist, tabpanel) &#8230; <a href="http://fittopage.org/2010/05/30/tabs-done-right/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There are a lot of JavaScript-driven tab widgets <a href="http://www.google.com/search?q=+javascript+tabs">around the web</a>. All of the major JS libraries provide a tabs widget, and this is such a common user interface pattern that the ARIA specification includes several roles (<a href="http://www.w3.org/TR/2009/WD-wai-aria-20091215/roles#tab">tab</a>, <a href="http://www.w3.org/TR/2009/WD-wai-aria-20091215/roles#tablist">tablist</a>, <a href="http://www.w3.org/TR/2009/WD-wai-aria-20091215/roles#tabpanel">tabpanel</a>) to allow accessible description of the widget. This is a good thing, but there is a problem. <span id="more-81"></span>All of these implementations (including <a href="http://test.cita.illinois.edu/aria/tabpanel/tabpanel1.php">the ARIA example</a>) use the following type of markup to define tab widgets:</p>
<pre>&lt;div class=&quot;tabs&quot;&gt;
    &lt;ul&gt;
        &lt;li&gt;&lt;a href=&quot;#panel1&quot;&gt;Tab 1&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#panel2&quot;&gt;Tab 2&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#panel3&quot;&gt;Tab 3&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
    &lt;div id=&quot;panel1&quot;&gt;
        &lt;!-- panel content --&gt;
    &lt;/div&gt;
    &lt;div id=&quot;panel2&quot;&gt;
        &lt;!-- panel content --&gt;
    &lt;/div&gt;
    &lt;div id=&quot;panel3&quot;&gt;
        &lt;!-- panel content --&gt;
     &lt;/div&gt;
&lt;/div&gt;</pre>
<p>What&#039;s wrong with that? Well, the semantics are a bit off. Granted, it&#039;s not the worse example of content structure, but it&#039;s not very user friendly either: you have a list of links to content (the tabs), followed by several essentially unstructured content snippets (the panels). The tabs usually hold a meaningful title for the respective panel content, which makes sense visually since the tab and the content are rendered closely together and with visual clues indicating their relatedness once the JavaScript kicks in.</p>
<p>However, the tabs are not usually marked up as content headers (say, &lt;h*&gt;) since that would not create a meaningful content outline (all the headers would grouped together).&nbsp;&nbsp;Also, if you wanted to use the same markup to provide different rendering depending on context you&#039;d be in a bit of trouble. Here are just a couple of examples where you might want to do this:</p>
<ul>
<li>When printing the document tabs are obviously meaningless, so we&#039;d want to output all panel sections with the correct title above each one.</li>
<li>On a touch-screen smartphone we&#039;d want to use an accordion widget instead of tabs.</li>
<li>A screen reader could avoid the whole tabbed interface nastyness</li>
</ul>
<p>The essential problem is the disassociation between title and content: the markup has been written to suit a specific UI widget. It is possible to work around this by adding the title to each panel and selectively hiding/showing it depending on context, but that is not an elegant solution.</p>
<h3>Doing it right</h3>
<p>That is all very interesting, you say, but where is the elegant solution, then? Coming right up. We start with some simple, semantic markup:</p>
<pre>&lt;h3&gt;One&lt;/h3&gt;
&lt;p&gt;Lorem ipsum dolor sit amet.&lt;/p&gt;
&lt;p&gt;Proin posuere, velit non facilisis rutrum.&lt;/p&gt;

&lt;h3&gt;Two&lt;/h3&gt;
&lt;p&gt;Quisque tempor ligula risus.&lt;/p&gt;

&lt;h3&gt;Three&lt;/h3&gt;
&lt;p&gt;Suspendisse a orci turpis.&lt;/p&gt;</pre>
<p>And we add some scaffolding (note the <strong>selected</strong> class to highlight the selected tab):</p>
<pre>&lt;div class=&quot;tabWidget&quot;&gt;
    &lt;div class=&quot;tabWidget&quot;&gt;
	&lt;div class=&quot;tabPanel&quot;&gt;
		&lt;h3 class=&quot;tab&quot;&gt;One&lt;/h3&gt;
		&lt;div class=&quot;panel&quot;&gt;
			&lt;div class=&quot;panel-inner&quot;&gt;
				&lt;p&gt;Lorem ipsum dolor sit amet.&lt;/p&gt;
				&lt;p&gt;Proin posuere, velit non facilisis rutrum.&lt;/p&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/div&gt;
	&lt;div class=&quot;tabPanel selected&quot;&gt;
		&lt;h3 class=&quot;tab&quot;&gt;Two&lt;/h3&gt;
		&lt;div class=&quot;panel&quot;&gt;
			&lt;div class=&quot;panel-inner&quot;&gt;
				&lt;p&gt;Quisque tempor ligula risus.&lt;/p&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/div&gt;
	&lt;div class=&quot;tabPanel&quot;&gt;
		&lt;h3 class=&quot;tab&quot;&gt;Three&lt;/h3&gt;
		&lt;div class=&quot;panel&quot;&gt;
			&lt;div class=&quot;panel-inner&quot;&gt;
				&lt;p&gt;Suspendisse a orci turpis.&lt;/p&gt;
			&lt;/div&gt;
		&lt;/div&gt;
	&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
</pre>
<p>Note that I am using &lt;div&gt;s simply to keep the original semantics. You can use whatever elements make sense &#8212; there is an example using a list on <a href="http://jsfiddle.net/V9GZK/">the demo page</a>. Here is the CSS:</p>
<pre>.tabWidget {
    overflow: hidden;
}

.tabWidget .tabPanel {
    display: block;
}

.tabWidget .tab {
    float: left;
    /* change rules below for your desired visual effect */
    cursor: pointer;
    border: 2px solid #000;
    margin-right: 5px;
    padding: 2px 8px;
}

.tabWidget .panel {
    display: none;
    float: right;
    margin-left: -100%;
    margin-top: 1.7em;  /* adjust as needed */
    width: 100%;
}

.tabWidget .panel-inner {
    /* change rules below for your desired visual effect */
    border: 2px solid #000;
    padding: 10px;
}

.tabWidget .selected .tab {
    /* change rules below for your desired visual effect */
    background-color: #000;
    color: #FFF;
}

.tabWidget .selected .panel {
    display: block;
}</pre>
<p>The magic happens in the rules <strong>float: right</strong>, <strong>margin-left: -100%</strong>, and <strong>width: 100%</strong>, applied to the <strong>.panel</strong> &lt;div&gt;. These rules remove the panels from the <em>horizontal</em> flow of the document (since their width is cancelled by their negative margin), but leave their vertical dimension intact, allowing them to push down the bottom of the tab widget. A gotcha is that the <strong>.panel</strong> &lt;div&gt;s must be pushed down <em>by the correct amount</em> so that they line up with the bottom of the tabs (i.e. adjust the <strong>margin-top: 1.7em</strong> rule to suit your design). This also means that multi-line tabs are probably difficult to achieve (I haven&#039;t tried them; let me know if you have ideas). The purpose of the <strong>.panel-inner</strong> &lt;div&gt; is to allow for borders and/or padding to be added to the panel content without interfering with the <strong>width: 100%</strong> rule applied to <strong>.panel</strong> &lt;div&gt;. If you need neither, these can be removed. All we need now is some JavaScript to handle the tab switching. Here&#039;s an example using JQuery:</p>
<pre>$.fn.tabsDoneRight = function(options) {

    return this.each(function(index, el) {

        $(el).find(&quot;.tab&quot;).each(function(tabIndex, tabEl) {

            $(tabEl).click(function() {

                $(el).find(&quot;.selected&quot;).removeClass(&quot;selected&quot;);
                $(this).parents(&quot;.tabPanel&quot;).addClass(&quot;selected&quot;);

                return false;
            });

            $(tabEl).attr(&quot;tabindex&quot;, 0).keypress(function(ev) {

                if (ev.keyCode == 13) $(this).click();
            });
        });

        if (!$(el).find(&quot;.tabPanel:has(.selected)&quot;).length) {

            $(el).find(&quot;.tabPanel&quot;).first().click();
        }
    });
};

$(function() {

    $(&quot;.tabWidget&quot;).tabsDoneRight();
});</pre>
<h3>More accessible</h3>
<p>We&#039;re adding onclick behaviour to elements that don&#039;t have a default interaction (the &lt;h3&gt; tabs) so keyboard navigation won&#039;t automatically be added by the browser. We must make the tabs focusable by the tab key (<a href="http://snook.ca/archives/accessibility_and_usability/elements_focusable_with_tabindex">setting the <strong>tabindex</strong> attribute</a>), and triggering the click event handler when the <strong>enter</strong> key is pressed (see the <strong>keypress</strong> event handler in the code above). What if JavaScript is disabled? The <strong>display: none</strong> rule will keep all non-selected tab panels inaccessible, so I recommend a little trick: display all panels by default, and trigger the hiding if JS is enabled. Let&#039;s change the CSS:</p>
<pre>.tabWidget {
    overflow: hidden;
}

.tabWidget .tabPanel {
    display: block;
}

.tabWidget .tab {
    clear: both;
    float: left;
    /* change rules below for your desired visual effect */
    cursor: pointer;
    border: 2px solid #000;
    margin-right: 5px;
    padding: 2px 8px;
}

.js .tabWidget .tab {
    clear: none;
}

.tabWidget .panel {
    clear: right;
    display: block;
    float: right;
    margin-left: -100%;
    margin-top: 1.7em;  /* adjust as needed */
    width: 100%;
}

.js .tabWidget .panel {
    display: none;
    clear: none;
}

.tabWidget .panel-inner {
    /* change rules below for your desired visual effect */
    border: 2px solid #000;
    padding: 10px;
}

.tabWidget .selected .tab {
    /* change rules below for your desired visual effect */
    background-color: #000;
    color: #FFF;
}

.js .tabWidget .selected .panel {
    display: block;
}</pre>
<p>To trigger the correct CSS for JS-enabled pages, add this code as far up in the &lt;body&gt; as possible:</p>
<pre>&lt;script type=&quot;text/javascript&quot;&gt;
document.body.className += &quot; js&quot;;
&lt;/script&gt;</pre>
<h3>Putting it all together</h3>
<p>With the above markup it should now be relatively straightforward to create alternative styling for <a href="http://www.alistapart.com/articles/return-of-the-mobile-stylesheet">mobile</a> and <a href="http://www.alistapart.com/articles/goingtoprint/">print</a> mediums. Even better, making use of <a href="http://www.alistapart.com/articles/responsive-web-design/">CSS media queries</a> you can decide to change the appearance and behaviour of the widget based, for instance, on the available viewport space. This solution has been tested in IE6, IE7, IE8, FF3.6, Opera 10, Chrome 6. It also seems to work in mobile browsers (Nokia and Sony Ericsson), although you will need to make the tabs either links or buttons (maybe via the <a href="http://api.jquery.com/wrap/">JQuery wrap()</a> function?) since the onclick event doesn&#039;t seem to trigger on non-link elements on those browsers..</p>
]]></content:encoded>
			<wfw:commentRss>http://fittopage.org/2010/05/30/tabs-done-right/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Why I want to beat Java with a stick</title>
		<link>http://fittopage.org/2010/03/27/why-i-want-to-beat-java-with-a-stick/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=why-i-want-to-beat-java-with-a-stick</link>
		<comments>http://fittopage.org/2010/03/27/why-i-want-to-beat-java-with-a-stick/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 13:36:47 +0000</pubDate>
		<dc:creator>nelson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fittopage.org/?p=78</guid>
		<description><![CDATA[int x = 100; Stuff.doStuff(x); The method doStuff(String) in the type Stuff is not applicable for the arguments (int) int x = 100; Stuff.doStuff(x.toString()); Cannot invoke toString() on the primitive type int int x = 100; Stuff.doStuff((String)x); Cannot cast from &#8230; <a href="http://fittopage.org/2010/03/27/why-i-want-to-beat-java-with-a-stick/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><code>int x = 100;<br />
Stuff.doStuff(x);<br />
</code></p>
<blockquote><p>The method doStuff(String) in the type Stuff is not applicable for the arguments (int)</p></blockquote>
<p><code>int x = 100;<br />
Stuff.doStuff(x.toString());</code></p>
<blockquote><p>Cannot invoke toString() on the primitive type int</p></blockquote>
<p><code>int x = 100;<br />
Stuff.doStuff((String)x);</code></p>
<blockquote><p>Cannot cast from int to String</p></blockquote>
<p><code>int x = 100;<br />
Stuff.doStuff(new Integer(x).toString());   // OMGWTFGRRRBBQ!!!</code></p>
<blockquote><p>BUILD SUCCESSFUL</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://fittopage.org/2010/03/27/why-i-want-to-beat-java-with-a-stick/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>htmlspecialchars() for JavaScript</title>
		<link>http://fittopage.org/2010/02/25/htmlspecialchars-for-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=htmlspecialchars-for-javascript</link>
		<comments>http://fittopage.org/2010/02/25/htmlspecialchars-for-javascript/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 12:24:55 +0000</pubDate>
		<dc:creator>nelson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fittopage.org/?p=71</guid>
		<description><![CDATA[Creating markup with JavaScript for fun and profit is easy due to innerHTML. However, it would be nice to be able to escape output that is not trusted or known. Most references online point to encodeURI or encodeURIComponent, which will &#8230; <a href="http://fittopage.org/2010/02/25/htmlspecialchars-for-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Creating markup with JavaScript for fun and profit is easy due to innerHTML. However, it would be nice to be able to escape output that is not trusted or known. Most references online point to <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/encodeURI">encodeURI</a> or <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/encodeURIComponent">encodeURIComponent</a>, which will kind-of work; however those functions are intended for URI escaping, which has different rules.</p>
<p>So, here&#8217;s a quick solution that works pretty much like the similarly-named PHP function, <a href="http://php.net/manual/en/function.htmlspecialchars.php">htmlspecialchars</a>:</p>
<pre>function htmlspecialchars(str) {

    if (str === undefined) return "";
&nbsp;
    return str.replace(/[&lt;&gt;"&amp;]/g, function(match){
        return (match == "&lt;") ? "&amp;lt;" :
               (match == "&gt;") ? "&amp;gt;" :
               (match == '"') ? "&amp;quot;" :
               (match == "&amp;") ? "&amp;amp;" : "";
    });
}</pre>
<p>What&#8217;s missing? The &#8220;quote_style&#8221; parameter which allows deciding what will happen with single quotes (&#8216;). If your markup is sane and under control, there should be no need for it &#8212; if it isn&#8217;t, it&#8217;s not hard to change the above function.</p>
]]></content:encoded>
			<wfw:commentRss>http://fittopage.org/2010/02/25/htmlspecialchars-for-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making YUI ButtonGroups behave</title>
		<link>http://fittopage.org/2010/02/17/making-yui-buttongroups-behave/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=making-yui-buttongroups-behave</link>
		<comments>http://fittopage.org/2010/02/17/making-yui-buttongroups-behave/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 11:50:30 +0000</pubDate>
		<dc:creator>nelson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fittopage.org/?p=67</guid>
		<description><![CDATA[I like YUI Buttons. Amongst other niceties they allow you to have reliable cross-browser, cross platform custom-rendered form widgets like checkboxes and radio buttons &#8212; while keeping all the accessibility concerns in check. One of the functionalities it has is &#8230; <a href="http://fittopage.org/2010/02/17/making-yui-buttongroups-behave/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I like <a href="http://developer.yahoo.com/yui/button/">YUI Buttons</a>. Amongst other niceties they allow you to have reliable cross-browser, cross platform custom-rendered form widgets like checkboxes and radio buttons &#8212; while keeping all the accessibility concerns in check. One of the functionalities it has is to create &#8220;ButtonGroups&#8221;, i.e. a bunch of button controls that behave as a traditional radio-button group. All nice and good, except that it has one obnoxious behaviour: it forces all your radio buttons inside a common container &#8212; which might not be what you had in mind. I like my radio buttons where I put them, thank you&#8230;</p>
<p>So, quick fix coming up:</p>
<pre style="padding-left: 30px">var radioGroup = new YAHOO.widget.ButtonGroup({ container: aDivSomewhereItDoesntMatterWhere });
var radioButtons = anArrayOfPlainNormalRadioButtons;

for (var i = 0, len = radioButtons.length; i &lt; len; ++i) {

    var nodeIndex = getNodeIndex(radioButtons[i]),
        parentNode = radioButtons[i].parentNode,
        radioButton = new YAHOO.widget.Button(radioButtons[i]);

    // This will put the button somewhere silly
    radioGroup.addButton(radioButton);

    // Move the button back where it was
    parentNode.insertBefore(radioButton.get("element"), parentNode.childNodes[nodeIndex]);
}</pre>
<p>So, it&#8217;s more verbose than just using the simple &#8220;<strong>new YAHOO.widget.ButtonGroup(radioButtonContainer)</strong>&#8221; syntax that does everything for you &#8212; if you are willing to have the radio buttons where YUI put them. Also&#8230; what&#8217;s that &#8220;<strong>getNodeIndex()</strong>&#8221; function?, I hear you ask. Just a simple utility off my toolbox; it gets the index of a node within all the nodes with the same parent:</p>
<pre style="padding-left: 30px">var nodeIndex = function(element) {
    for (var index = 0, el = element; el = el.previousSibling; ++index);
    return index;
}</pre>
<p>Hope that&#8217;s helpful&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://fittopage.org/2010/02/17/making-yui-buttongroups-behave/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting the category ID in WordPress</title>
		<link>http://fittopage.org/2010/02/04/getting-the-category-id-in-wordpress/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-the-category-id-in-wordpress</link>
		<comments>http://fittopage.org/2010/02/04/getting-the-category-id-in-wordpress/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 08:42:40 +0000</pubDate>
		<dc:creator>nelson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fittopage.org/?p=63</guid>
		<description><![CDATA[There is quite a bit of documentation in the WordPress site about categories, specifically how to retrieve data about them. Unfortunately all the available methods seem to focus on getting category data from a post, but it&#8217;s nearly impossible to &#8230; <a href="http://fittopage.org/2010/02/04/getting-the-category-id-in-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There is quite a bit of documentation in the WordPress site about categories, specifically how to retrieve data about them. Unfortunately all the available methods seem to focus on getting category data from a post, but it&#8217;s nearly impossible to figure out the category you are looking at when viewing the category page itself (i.e. the special &#8220;archive page&#8221; that lists all posts in a category).</p>
<p>The function <a href="http://codex.wordpress.org/Function_Reference/is_category">is_category()</a> falls short, since it only indicates whether or not the current page is <em>a</em> category page, but not which one. And <a href="http://codex.wordpress.org/Function_Reference/get_cat_ID">get_cat_id()</a>, <a href="http://codex.wordpress.org/Function_Reference/get_category">get_category()</a>, <a href="http://codex.wordpress.org/Function_Reference/get_the_category">get_the_category()</a>, and the half-dozen other &#8220;obviously&#8221;-named functions either require that you already know something about the category or provide information about a post.</p>
<p>So, the solution?</p>
<pre>if (is_category()) {
   $categoryId = $GLOBALS["cat"];
}</pre>
<p>Yes, it&#8217;s a global variable&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://fittopage.org/2010/02/04/getting-the-category-id-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making sprites</title>
		<link>http://fittopage.org/2009/12/23/making-sprites/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=making-sprites</link>
		<comments>http://fittopage.org/2009/12/23/making-sprites/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 15:08:58 +0000</pubDate>
		<dc:creator>nelson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fittopage.org/?p=37</guid>
		<description><![CDATA[So you have a website that uses dozens of little images to make the interface more attractive. Maybe there&#8217;s a toolbar or menu, where each item or button has its own icon. It looks great, but it&#8217;s a pain to &#8230; <a href="http://fittopage.org/2009/12/23/making-sprites/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So you have a website that uses dozens of little images to make the interface more attractive. Maybe there&#8217;s a toolbar or menu, where each item or button has its own icon. It looks great, but it&#8217;s a pain to load &#8211; each image is a small file and the browser frantically struggles to manage the 20 or 30 requests for all the graphical nicety. The interface feels sluggish. Users get bored and leave. Civilisational collapse soon ensues.</p>
<p>Fortunately, you know how to fix the problem with the use of the great technique of <a href="http://www.alistapart.com/articles/sprites">CSS Sprites</a>. If you don&#8217;t, you should. Click the link and learn about it; I will assume that you know what CSS sprites are from here on&#8230;  Yes, CSS sprites are great, but they are a <em>pain</em> to create manually. Not only you need to stitch the images together but also there will be lots of CSS rules to position the background image correctly. Automation comes to the rescue in the form of the <strong>montage</strong> command (part of the fantastic <a href="http://www.imagemagick.org">ImageMagick</a> collection of image-manipulation software goodness) and some quick script hacking&#8230;</p>
<h3>Creating the sprite</h3>
<p>This little tip will create a sprite off a directory of image files with identical size (in this case, 16×16 icons), each one named something sensible. The objective is to get one image file and a bunch of CSS rules built automatically.  First, ensure that you have ImageMagick. In Ubuntu this command will do the trick:</p>
<pre>sudo apt-get install imagemagick</pre>
<p>There are also downloadable distributions for <a href="http://www.imagemagick.org/script/binary-releases.php#windows">Windows</a> and <a href="http://www.imagemagick.org/script/binary-releases.php#macosx">Mac</a>. Once you&#8217;re ready, open a command prompt and go to the folder where your images live, and run this command:</p>
<pre>montage *.png -alpha on -background "#ffffff00" -tile x1 -geometry 16x16 ../sprites.png</pre>
<p>This will create a file, <strong>sprites.png</strong>, in the parent folder (in Windows, make sure that you type &#8220;..sprites.png&#8221; as the last parameter – notice the backslash), with all the images tiled side-by-side. If you require the images to be tiled top-to-bottom substitute <strong>-tile x1</strong> with <strong>-tile 1x</strong>. And if your images are a different size than 16×16, specify that in the <strong>-geometry</strong> parameter. And if your source images are not PNGs, replace &#8220;*.png&#8221; as appropriate.  I recommend that you open the sprites.png file in your editor of choice and perform any conversions or optimisations as you see fit. Don&#8217;t forget to apply <a href="http://optipng.sourceforge.net/">OptiPNG</a> if you use PNG as your final format (why wouldn&#8217;t you?) to get a really small final file size. Your sprites file will look a bit like this (icons off the excellent <a href="http://www.famfamfam.com/lab/icons/silk/">Silk Icon</a>s set):</p>
<p><a href="http://fittopage.org/wp-content/uploads/2009/12/icons16mime.png"><img class="alignnone size-full wp-image-56" src="http://fittopage.org/wp-content/uploads/2009/12/icons16mime.png" alt="Example of icons in sprite file" width="448" height="16" /></a></p>
<p>That takes care of the sprite image. Now for the CSS rules.</p>
<h3>Auto-generating CSS rules</h3>
<p>We&#8217;ll be defining a couple of base rules that apply to all elements (note the references to 16px, the size of the icons; adjust as necessary):</p>
<pre>
.i16:before, .i16 span {
    content: "";
    background-image: url("sprites.png");
    background-repeat: no-repeat;
    padding: 0 0 0 16px;
    margin: 0 0.25em 0 0;
    *zoom: 1;  /* For IE 6 and 7 */
}

.i16block {
    display: block;
    margin: 0 0 0 16px;
    padding: 0 0 0 0.25em;
    position: relative;
    *zoom: 1;  /* For IE 6 and 7 */
}

.i16block span {
    background-image: url("sprites.png");
    background-repeat: no-repeat;
    height: 16px;
    left: -16px;
    min-height: 1em;
    position: absolute;
    top: 0.115em;
    width: 16px;
}</pre>
<p>And one more rule per image, which provides the correct background position. The objective is to be able to use classes like this (﻿in this case, to obtain the PDF icon):</p>
<pre>&lt;a class="<strong><span style="color: #993300">i16 i16pdf</span></strong>" href="example.pdf"&gt;PDF link&lt;/a&gt;</pre>
<p>Or, for links that might span multiple lines and require nice text alignment (or for IE6 support) we need an extra element:</p>
<pre>&lt;a class="<strong><span style="color: #993300">i16block i16pdf</span></strong>" href="example.pdf"&gt;<strong>&lt;span&gt;&lt;/span&gt;</strong>PDF link&lt;/a&gt;</pre>
<p>First, we need to get a list of files in the directory. Each file will produce a rule, and it is important that the contents of the directory haven&#8217;t changed since the sprite was created (this is why we placed the sprite in the parent directory). So, drop to the command line and, in Linux, run this:</p>
<pre>ls -1 *.png &gt; filelist.txt</pre>
<p>Or, in Windows:</p>
<pre>dir /b *.png &gt; filelist.txt</pre>
<p>Now we only need a quick script to output a bunch of CSS rules. This can be done with your favourite programming language, but here is an example in <span style="color: #000000"><a href="http://www.python.org/download/">Python</a>:</span></p>
<pre>rules = ""
f = open('filelist.txt', 'r')
x = 0
for name in f:
    rules = rules + ".i16Mime" + name[0].capitalize() + name[1:] + ":before"
    rules = rules + ", .i16Mime" +  name[0].capitalize() + name[1:]"
    rules = rules + " span {n    background-position: -" + str(x) + "px 50%;n}nn"
    x = x + 16
f.close()
f = open('rules.css', 'w')
f.write(rules)
f.close()</pre>
<p>The above code can be saved as a Python script file (say, &#8220;myscript.py&#8221;) in the same directory as the images, and run from the command-line like so:</p>
<pre>python myscript.py</pre>
<p>This will generate a new CSS file, &#8220;rules.css&#8221;, with all the correct rules for all the icons. It should be pretty easy to rewrite the above in your language of choice (PHP, Ruby, Assembler&#8230;)   Simple apply to your links the appropriate &#8220;<strong>i16 i16<em>type</em></strong>&#8221; class names and you should be good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://fittopage.org/2009/12/23/making-sprites/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Too big to work?</title>
		<link>http://fittopage.org/2009/11/29/too-big-to-work/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=too-big-to-work</link>
		<comments>http://fittopage.org/2009/11/29/too-big-to-work/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 11:06:19 +0000</pubDate>
		<dc:creator>nelson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fittopage.org/?p=34</guid>
		<description><![CDATA[Without trying to dismiss the complexity of the problem, how hard can it be to implement an Europe-wide train booking system? BBC: &#8220;Euro train booking system shelved&#8221; Is IT still such a headache that these systems are too hard/expensive to &#8230; <a href="http://fittopage.org/2009/11/29/too-big-to-work/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Without trying to dismiss the complexity of the problem, how hard can it be to implement an Europe-wide train booking system?</p>
<p>BBC: &#8220;<a href="http://news.bbc.co.uk/2/hi/business/8382508.stm">Euro train booking system shelved</a>&#8221;</p>
<p>Is IT still such a headache that these systems are too hard/expensive to implement? I say make the routing, timetable, and booking information freely available and I&#8217;ll have a go at making it work&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://fittopage.org/2009/11/29/too-big-to-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing for outline CSS support with jQuery</title>
		<link>http://fittopage.org/2009/11/27/testing-for-outline-css-support-with-jquery/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=testing-for-outline-css-support-with-jquery</link>
		<comments>http://fittopage.org/2009/11/27/testing-for-outline-css-support-with-jquery/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 12:19:10 +0000</pubDate>
		<dc:creator>nelson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fittopage.org/?p=31</guid>
		<description><![CDATA[In the good spirit of testing capabilities rather than browser versions, I needed a way to find out whether or not a browser supports setting the values of the &#8220;outline&#8221; property via CSS. IE6 and 7 don&#8217;t support it, everything &#8230; <a href="http://fittopage.org/2009/11/27/testing-for-outline-css-support-with-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the good spirit of testing capabilities rather than browser versions, I needed a way to find out whether or not a browser supports setting the values of the &#8220;outline&#8221; property via CSS. IE6 and 7 don&#8217;t support it, everything else seems to. So I just quickly extended the <a href="http://docs.jquery.com/Utilities/jQuery.support">jQuery.support</a> functionality like so:</p>
<pre>$.support.outlineCss = function() {
    var $el = $("&lt;div&gt;&lt;/div&gt;").css("outline", "1px solid black"),
        outlineStyle = $el.appendTo(document.body).css("outline-style");
    $el.remove();
    return outlineStyle == "solid";
}();</pre>
<p>Simply test if <strong>$.support.outlineCss</strong> is true and you&#8217;re good to go&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://fittopage.org/2009/11/27/testing-for-outline-css-support-with-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Moving to WordPress</title>
		<link>http://fittopage.org/2009/11/08/moving-to-wordpress/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=moving-to-wordpress</link>
		<comments>http://fittopage.org/2009/11/08/moving-to-wordpress/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 13:12:56 +0000</pubDate>
		<dc:creator>nelson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://fittopage.org/?p=28</guid>
		<description><![CDATA[I've moved my site to WordPress from the previous home-baked mismatch of Zend Framework and Serendipity. I had fun with the previous solution, but this is a more sane arrangement. <a href="http://fittopage.org/2009/11/08/moving-to-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been planing this for a while, but I&#8217;ve finally gone ahead and done it. I ditched my previous site, which was built as an amalgamation of <a href="http://www.s9y.org/">Serendipity</a> (S9Y) and <a href="framework.zend.com">Zend Framework</a> (ZF) and moved to <a href="http://wordpress.org">WordPress</a>.</p>
<p>Why? Mostly because the previous setup still required quite a bit of work for me to be happy with it: it looked OK for a visitor, but integrating S9Y into an MVC framework like Zend was somewhat nightmarish, and the admin interface was quite cumbersome even for simple things like adding a post. So I&#8217;m setting up a vanilla WordPress installation (apologies about the design; I&#8217;m working on it!) which will hopefuly translate into more interesting content and less hassle for me!</p>
<p>I initially set up a ZF site to try and get some more experience with the framework itself, and I am very glad I did. It was a completely overkill application of the technology but I feel I can now use ZF for quite more complex applications: it is very capable and powerful while avoiding the typical &#8220;application server&#8221; setup that seems so common with larger frameworks. I especially liked the way you can cherry-pick which parts of the framework are of interest, including whether or not the whole MVC stack gets used. For simpler applications something like <a href="http://cakephp.org/">Cake PHP</a> might still be a faster and simpler way to do things, and I&#8217;ll keep to plain-no-frills-PHP for really simple things like prototyping.</p>
<p>As for S9Y, it was a bit of a disappointment. I was looking for a blogging engine that could be plugged into my ZF setup, but since there seem to be none that are happy to do that kind of &#8220;blog backend&#8221; role only, I settled for something that seemed easy to hack into submission. S9Y does bring its own kitchen sink as well, but it seemed easy to hack. However, two things let it down: convoluted, poorly-documented code, and the templating system.</p>
<p>I won&#8217;t say much about the code quality, except that it was at first sight simple but in fact quite messy once you tried to wok out interactions between different parts. The lack of documentation was the really frustrating part, though. So far WordPress seems much better documented and understandable.</p>
<p>The templating system of S9Y is <a href="http://www.smarty.net">Smarty</a>. There&#8217;s nothing wrong with Smarty itself; I guess my problem is with templating systems in general. I know these have their usefulness in some development environments, and of course it is essential to separate as much logic as possible from your markup. However, I don&#8217;t think templating systems are a great solution: many times the behaviour of a template is itself complex, and a custom-syntax, crippled language like Smarty is a hindrance.</p>
<p>So there you have the reasons for moving on. Both ZF and S9Y had its fun moments but that setup wasn&#8217;t really suitable for this tiny site. Getting rid of the not-invented-here syndrome is also a good thing. In the coming days/weeks I hope to put together a nicer design (I promise I&#8217;ll go easy on the orange&#8230;) and I now also have fewer excuses to create content more often. So overall I think this was the right decision!</p>
]]></content:encoded>
			<wfw:commentRss>http://fittopage.org/2009/11/08/moving-to-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

