<?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>Kilian Valkhof &#187; Javascript</title>
	<atom:link href="http://kilianvalkhof.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://kilianvalkhof.com</link>
	<description></description>
	<lastBuildDate>Mon, 23 Aug 2010 08:00:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>The case of the disappearing favicon</title>
		<link>http://kilianvalkhof.com/2010/javascript/the-case-of-the-disappearing-favicon/</link>
		<comments>http://kilianvalkhof.com/2010/javascript/the-case-of-the-disappearing-favicon/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 08:00:37 +0000</pubDate>
		<dc:creator>Kilian Valkhof</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kilianvalkhof.com/?p=772</guid>
		<description><![CDATA[<blockquote><p>Luckily, there is an easy fix: Just reset the favicon</p></blockquote><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2010/javascript/the-case-of-the-disappearing-favicon/">The case of the disappearing favicon</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Firefox has an annoying bug: If you set the <code>window.location.hash</code>, your favicon disappears. <em>Very</em> annoying. <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=519028">The bug</a> has been open and confirmed for a long time, and Firefox 3.0 all the way to 3.6 are affected. But it hasn&#8217;t been fixed yet, so here&#8217;s how to fix it yourself.<span id="more-772"></span></p>
<p>I encountered this bug while building <a href="http://lystener.com">Lystener</a>. I change the location hash there quite often, and each time I did, the favicon would disappear. Finding the root cause took me quite a while, and apart from the bug report I could not find any page describing why this happens and what to do about it. So I figured that I&#8217;d write a quick post about it to make it Google-able at least.</p>
<p>Luckily, there is an easy fix: Just reset the favicon after changing the <code>window.location.hash</code>. Here&#8217;s a jQuery function that does just that:</p>
<pre></code>function setFavicon() {
  var link = $('link[type=image/x-icon]').remove().attr("href");
  $('&lt;link href="'+ link +'" rel="shortcut icon" type="image/x-icon" /&gt;').appendTo('head');
}</code></pre>
<p>It&#8217;s fairly straightforward: We find the current <code>&lt;link&gt;</code> referencing the favicon, remove it, and then, making use of jQuery&#8217;s standard of functions returning themselves, get the href attribute of the just-deleted link. Then we simply set that as the <code>href</code> in a newly created <code>link</code> element, and add that to the head. </p>
<p>Just execute that function each time you change the <code>window.location.hash</code>, and you&#8217;re all set!</p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://kilianvalkhof.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2010/javascript/the-case-of-the-disappearing-favicon/">The case of the disappearing favicon</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kilianvalkhof.com/2010/javascript/the-case-of-the-disappearing-favicon/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to build a fast, simple list filter with jQuery</title>
		<link>http://kilianvalkhof.com/2010/javascript/how-to-build-a-fast-simple-list-filter-with-jquery/</link>
		<comments>http://kilianvalkhof.com/2010/javascript/how-to-build-a-fast-simple-list-filter-with-jquery/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 08:00:03 +0000</pubDate>
		<dc:creator>Kilian Valkhof</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kilianvalkhof.com/?p=613</guid>
		<description><![CDATA[<blockquote><p>jQuery has a way to check for matched elements easily: the <code>:contains()</code> selector.</p></blockquote><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2010/javascript/how-to-build-a-fast-simple-list-filter-with-jquery/">How to build a fast, simple list filter with jQuery</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Sometimes you want users of your web-app to quickly filter a list down. For example, a web-app I&#8217;m currently working on features a page listing two dozen countries, and I want users to find the country they are looking for as fast as possible. This article shows you how little code is needed to add this in a fast, progressively-enhanced way using jQuery.<span id="more-613"></span></p>
<h3>Demo</h3>
<p>If you&#8217;re the impatient type, I&#8217;ve set up a simple demo: <a href="http://kilianvalkhof.com/uploads/listfilter/">A simple list filter with jQuery</a>.</p>
<h3>The HTML</h3>
<p>The basic HTML you need for this is simple: just a header and a simple unordered list. They both have id&#8217;s so we can easily and uniquely find them:</p>
<pre><code>&lt;h1 id="header"&gt;List of countries&lt;/h1&gt;

&lt;ul id="list"&gt;
  &lt;li&gt;&lt;a href="/australia"&gt;Australia&lt;/a&gt;&#038;lt/li&gt;
  &lt;li&gt;&lt;a href="/austria"&gt;Austria&lt;/a&gt;&#038;lt/li&gt;
  &lt;li&gt;&lt;a href="/belgium"&gt;Belgium&lt;/a&gt;&#038;lt/li&gt;
  &hellip;
&lt;ul&gt;</code></pre>
<p>With the HTML ready, here is what the filter function needs to do:</p>
<ol>
<li>Add an input to the header</li>
<li>Set up events to check when someone is typing in the input</li>
<li>Check the value of the input, and compare it to the countries in the list</li>
<li>Hide the non-matching ones, while showing the matching ones</li>
</ol>
<h3>Step 1: add an input to the header</h3>
<p>We&#8217;ll start with a simple function, we&#8217;ll call it listFilter:</p>
<pre><code>function listFilter(header, list) {
  &hellip;
}</code></pre>
<p>As you see, the function takes two arguments. We&#8217;ll use jQuery to select the aforementioned header and list and give them as arguments to our function. Next, we need to create a form with an input in it, and append it to the header:</p>
<pre><code>function listFilter(header, list) {
  // create and add the filter form to the header
  var form = $("&lt;form&gt;").attr({"class":"filterform","action":"#"}),
      input = $("&lt;input&gt;").attr({"class":"filterinput","type":"text"});

  $(form).append(input).appendTo(header);
  &hellip;
}</code></pre>
<p>Using $(&#8220;&lt;form&gt;&#8221;) (with brackets) we can create new elements, and by inserting the input into the form using <code>append()</code>, and then using the <code>appendTo()</code> function to add the form (with the input in it) to the header, we easily add it into the page. For easy of use I&#8217;ve given both the form and the input classes, so you can style them easily.</p>
<p>That&#8217;s step one done, but it doesn&#8217;t do anything yet, for that we need to&hellip;</p>
<h3>Step 2: set up events</h2>
<p>To check for text in the input, we can use the <code>change</code> event. This fires every time the value of the input has changed, but only when you exit the input. However, this doesn&#8217;t work with a letter-for-letter filter. For that, we need to watch the <code>keyup</code> event a well. We use <code>keyup</code> instead of <code>keydown</code> because it fires after you pressed the key, and so the value of the input then includes the just-typed letter. With <code>keydown</code>, the event gets fired before the letter is added, so JavaScript can&#8217;t pick it up in the value of the input.</p>
<p>While using two events, there is no need to do double work. When we receive a <code>keyup</code> event, we just fire a <code>change</code> event:</p>
<pre><code>function listFilter(header, list) {
  &hellip;
  $(input).change( function () {
    &hellip;
  }).keyup( function () {
    // fire the above change event after every letter
    $(this).change();
  });
  &hellip;
}</code></pre>
<p>We&#8217;re now all set to start with the actual checking!</p>
<h3>Step 3: compare the values</h3>
<p>jQuery has a way to check for matched elements easily: the <code><a href="http://api.jquery.com/contains-selector/">:contains()</a></code> selector. Using this, you can very easily select all element containing the text between the parenthesis:</p>
<pre><code>function listFilter(header, list) {
  &hellip;
  $(input).change( function () {
    var filter = $(this).val(); // get the value of the input, which we filter on
    $(list).find("a:contains(" + filter + ")").parent().slideDown();
  });
  &hellip;
}</code></pre>
<p>The code above works like this: in the list, which is the <code>&lt;ul&gt;</code> element. it finds all the shows all the <code>&lt;a&gt;</code> elements that contain the value in the input. It then selects the parents of those <code>&lt;a&gt;</code> elements, the <code>&lt;li&gt;</code>&#8216;s. Those li&#8217;s then get shown. However, since we filter the list, we need to also hide all the li&#8217;s that <em>do not contain</em> that value. For this, jQuery offers the <code>:not()</code> selector, and we can just wrap that around the <code>:contains()</code> selector, like so:</p>
<pre><code>function listFilter(header, list) {
  &hellip;
  $(input).change( function () {
    var filter = $(this).val(); // get the value of the input, which we filter on
    $(list).find("a:not(:contains(" + filter + "))").parent().slideUp();
    $(list).find("a:contains(" + filter + ")").parent().slideDown();
  });
  &hellip;
}</code></pre>
<p>There, now with each keystroke, we check the list for matching elements, and hide the ones that don&#8217;t match. Easy-peasy.</p>
<p>But wait. What happens when you clear the input? Then $(this).val(); will be empty, and nothing matches with empty. So all list items will be hidden, the exact opposite of what we want. This can be remedied by just checking if $(this).val(); has any value, and if not, just showing everything:</p>
<pre><code>function listFilter(header, list) {
  &hellip;
  $(input).change( function () {
    var filter = $(this).val();
    if (filter) {
      $(list).find("a:not(:contains(" + filter + "))").parent().slideUp();
      $(list).find("a:contains(" + filter + ")").parent().slideDown();
    } else {
      $(list).find("li").slideDown();
    }
  });
  &hellip;
}</code></pre>
<p>Typing in letters now filters down the list, and removing them all shows the entire, now unfiltered, list again. Is that all we need? Well, It would be, except that <code>:contains()</code> is <em>case-sensitive</em>. so if you filter with &#8220;austria&#8221;, you won&#8217;t find Austria!</p>
<h3>Building a case-insensitive :contains()</h3>
<p>jQuery allows you to add your own selector expressions, and we can use that to build our own contains filter that&#8217;s a bit more sensible:</p>
<pre></code>jQuery.expr[':'].Contains = function(a,i,m){
    return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
};</code></pre>
<p>This adds a <code>:Contains()</code> (<em>note the uppercase</em>) option to your selectors that does the same as <code>:contains()</code>, but it first converts all text to uppercase, and then compares them. So once we add this to your JavaScript, all we have to do in our listFilter function is replace <code>:contains()</code> with <code>Contains()</code> and we have a fast, simple, progressively-enhanced way to filter down a large list!</p>
<h3>Demo</h3>
<p>If you want to browse through the entire, documented code, and see it in action, check out the example page: <a href="http://kilianvalkhof.com/uploads/listfilter/">A simple list filter with jQuery</a>.</p>
<p>Please let me know in the comments what you would use this for, and please let me know your remarks and questions!</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.14';
var flattr_uid = '28694';
var flattr_url = 'http://kilianvalkhof.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Kilian Valkhof';
var flattr_dsc = '';
</script>
<script src="https://api.flattr.com/js/0.5.0/load.js?mode=auto" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://kilianvalkhof.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2010/javascript/how-to-build-a-fast-simple-list-filter-with-jquery/">How to build a fast, simple list filter with jQuery</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kilianvalkhof.com/2010/javascript/how-to-build-a-fast-simple-list-filter-with-jquery/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Grafico: Javascript charting library</title>
		<link>http://kilianvalkhof.com/2010/design/grafico-javascript-charting-library/</link>
		<comments>http://kilianvalkhof.com/2010/design/grafico-javascript-charting-library/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 04:00:30 +0000</pubDate>
		<dc:creator>Kilian Valkhof</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kilianvalkhof.com/?p=541</guid>
		<description><![CDATA[<blockquote><p>There are a lot of bad charts out there, and Grafico will do it's best to prevent you from adding charts onto that pile. ;)</p></blockquote><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2010/design/grafico-javascript-charting-library/">Grafico: Javascript charting library</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Grafico is a javascript charting library built with Raphaël and Prototype.js. The library provides a wide array of graphs and stays with the guidelines laid out by Stephen Few and Edward Tufte. <strong>Grafico provides pretty charts that effectively communicate their information.</strong><span id="more-541"></span></p>
<h2>Graphs</h2>
<p>This means you get awesome graphs such as <em>stacked area charts</em> and <em>sparklines</em>, but no pie charts or bar charts with every bar a different color. There are a lot of bad charts out there, and Grafico will do it&#8217;s best to prevent you from adding charts onto that pile. ;)</p>
<p><img src="http://grafico.kilianvalkhof.com/grafico-example.png" alt="" /><br />
<strong><a href="http://grafico.kilianvalkhof.com">Website</a></strong>, <strong><a href="http://grafico.kilianvalkhof.com/documentation/">Documentation</a></strong> (might be slow on some browsers due to all the examples)</p>
<div style="float:right;margin-left:2em;">
Available graphs:</p>
<ul>
<li><a href="http://grafico.kilianvalkhof.com/documentation/index.html#line">Line graphs</a></li>
<li><a href="http://grafico.kilianvalkhof.com/documentation/index.html#area">Area graphs</a></li>
<li><a href="http://grafico.kilianvalkhof.com/documentation/index.html#stack">Stacked area graphs</a></li>
<li><a href="http://grafico.kilianvalkhof.com/documentation/index.html#stream">Stream graphs</a></li>
<li><a href="http://grafico.kilianvalkhof.com/documentation/index.html#bar">Bar graphs</a></li>
<li><a href="http://grafico.kilianvalkhof.com/documentation/index.html#horizontalbar">Horizontal bar graphs</a></li>
<li><a href="http://grafico.kilianvalkhof.com/documentation/index.html#sparkline">Sparklines</a></li>
<li><a href="http://grafico.kilianvalkhof.com/documentation/index.html#sparkbar">Sparkbars</a></li>
<li><a href="http://grafico.kilianvalkhof.com/documentation/index.html#sparkarea">Sparkareas</a></li>
</ul>
</div>
<p>Grafico requires <a href="http://raphaeljs.com">Raphaël</a> 1.0+ and <a href="http://prototypejs.org">Prototype.js</a> 1.6+</p>
<p>Each graph type has numerous API options to customize it&#8217;s look and behavior. Many examples of this can be found in the <a href="http://grafico.kilianvalkhof.com/documentation/">documentation</a>. Some highlights: pop-up hovers, meanlines and watermarks. Minified, Grafico is about 30kb and available under the MIT license.</p>
<p>Grafico is also available on <a href="http://github.com/kilian/grafico">Github</a> and includes a minification script made by <a href="http://wakoopa.com/menno">Menno</a> using the Google Closure Compiler.</p>
<h3 style="clear:both">History</h3>
<p>In april 2009 I started working on new visualizations for <a href="http://wakoopa.com">Wakoopa</a>. I had set it my target to provide unique and interesting graphs. One thing that particularly inspired me was the <a href="http://www.neoformix.com/2008/StreamGraph.html">stream graph</a>, but the <a href="http://www.neoformix.com/2008/StreamGraph.html">math behind</a> it scared the crap out of me. I decided to focus on stacked area graphs instead.</p>
<p>After doing extensive research on the available JavaScript charting libraries, and being slightly disappointed by most, <a href="http://alexyoung.org/2009/01/21/ico-svg-graphs-with-prototype-and-raphael/">Ico by Alex Young</a> was the most promising. In the (almost ) year I worked on it, the graphs, code and API changed considerably. To avoid confusion I decided to rename my version to Grafico. </p>
<h3>Todo</h3>
<p>As always, there are points of improvement. The major one is speed. Grafico is very speedy on modern browsers, but of course IE lags behind. When building graphs, drawing pop-up hovers for all data points takes too much time and I have yet to find a way to improve this. The project lives on <a href="http://github.com/kilian/grafico">Github</a>, so if you have improvements, fork away and I&#8217;ll gladly pull them!</p>
<h2>Update! (16 Feb 2010)</h2>
<p><a href="http://janpaulposma.nl">Jan Paul Posma</a> wrote the code to implement the aforementioned stream graphs into Grafico. Which is <em>awesome</em>. I have updated the links in this article accordingly.</p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://kilianvalkhof.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2010/design/grafico-javascript-charting-library/">Grafico: Javascript charting library</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kilianvalkhof.com/2010/design/grafico-javascript-charting-library/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>The state of selectable text-replacement</title>
		<link>http://kilianvalkhof.com/2009/javascript/the-state-of-selectable-text-replacement/</link>
		<comments>http://kilianvalkhof.com/2009/javascript/the-state-of-selectable-text-replacement/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 04:00:53 +0000</pubDate>
		<dc:creator>Kilian Valkhof</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kilianvalkhof.com/?p=468</guid>
		<description><![CDATA[<blockquote><p>You shouldn’t have to compromise the design or the user's experience to have selectable text.</p></blockquote><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2009/javascript/the-state-of-selectable-text-replacement/">The state of selectable text-replacement</a></p>
]]></description>
			<content:encoded><![CDATA[<p>In &#8220;<a href="http://kilianvalkhof.com/2009/javascript/Cuf&oacute;n-vs-typefacejs-which-one-is-better/">Cufón vs. Typeface.js, which one is better?</a>&#8220;, I declared that the first one to support selectable text wins. We&#8217;re a couple of months further now and both <em>Typeselect</em> and <em>Typeface.js 0.13</em> appeared, adding support for selectable text. What is the state of selectable text-replacement?<span id="more-468"></span></p>
<h3>Typeselect</h3>
<p>Let&#8217;s take a look at the new kid on the block. <a href="http://typeselect.org">Typeselect</a> is based on version 0.12 of Typeface.js, and defines it&#8217;s goal boldly in a custom, text-selectable font on it&#8217;s homepage:</p>
<p><strong>You shouldn’t have to compromise the design or the user&#8217;s experience to have selectable text.</strong></p>
<p>Amen!</p>
<p>Typeselect acts as a layer above Typeface.js. You should take this as literal as possible, since the way Typeselect works is by adding transparent text on top of your replaced text. Script-wise, added to Typeface.js are <a href="http://jquery.com">jQuery 1.3.2</a> and their own js file, typeselect.js that takes care of the actual selection of text.</p>
<h3>Including Typeselect in your website</h3>
<pre><code>&lt;head&gt;
&hellip;
  &lt;script type="text/javascript" src="js/typeface-custom.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="fonts/nilland_regular.typeface.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/jquery-1.3.2.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/typeselect.js"&gt;&lt;/script&gt;
&hellip;
&lt;/head&gt;</code></pre>
<p>While it takes two more javascript files when compared to Typeface.js and Cuf&oacute;n, chances are that you already use jQuery and you can always choose to combine multiple javascript files. When we move on though, actually changing the font is pretty easy. By adding the class <code>select</code> to the elements you want to replace, and adding your typeface.js converted font to the css, the font will be replaced!</p>
<pre><code>&lt;div class="myclass <strong>select</strong>"&gt;
&hellip;
h1,  h2 {
  font-family:nilland, Georgia, Serif;
  font-style:italic;
}</code></pre>
<h3>Future?</h3>
<p>It seems that Typeselect aims to be a layer above typeface.js and Cuf&oacute;n to provide selectable text for both. Apart from that, better rendering of the fonts is on the <a href="http://www.typeselect.org/usage">roadmap</a> as well as a host of other things. Only&hellip; Typeface.js currently has it&#8217;s own, very similar, implementation of selectable text built right in. Actually, as far as I can see, it&#8217;s identical. So without Cuf&oacute;n support, I&#8217;m not sure if Typeselect is the best choice you can make.</p>
<h3>Typeface.js</h3>
<p>Typeface.js added text selection in version 0.13 in the same way as Typeselect: selectable text is implemented by overlaying real, transparent text on top of the rendered text. Pretty smart! AS you can see on <a href="http://typeface.neocracy.org/examples.html">Typeface.js&#8217; download page</a>, it works <em>really</em> well.</p>
<p>However, by doing this, performance goes down a bit. Not enough to really notice it, but if you want to disable it, there&#8217;s an <del>app</del> option for that. By adding the following to your &lt;head&gt; in a script element, selecting text gets disabled:</p>
<pre><code>_typeface_js.configure({ disableSelection: true })</code></pre>
<h3>Cuf&oacute;n?</h3>
<p>So, where does that leave Cuf&oacute;n? Well, text selection is <a href="http://github.com/sorccu/cufon/issues#issue/7">planned</a> in version 1.2. Right now Cuf&oacute;n is at version 1.08, so we&#8217;ll have to wait a little longer.</p>
<h3>Conclusion</h3>
<p>For now, <a href="http://typeface.neocracy.org">Typeface.js</a> is pretty much the best way to use good looking fonts while also allowing selectable text, cross-browser. However, with some work, @font-face can be made working in Firefox 3.5, Safari 3.1+, Opera 9+, Internet explorer 4+ and Chrome 0.3+. So, basically every browser. However, it is <a href="http://snook.ca/archives/html_and_css/becoming-a-font-embedding-master">a lot</a> of <a href="http://paulirish.com/2009/bulletproof-font-face-implementation-syntax/">work</a> compared to using Typeface.js, Cuf&oacute;n or Typeselect. </p>
<p>Personally I think that in most browsers, using the javascript replacement results in better looking text, and it&#8217;s definitely easier to implement. In terms of forward compatibility, @font-face is a better choice. It&#8217;s up to you!</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.14';
var flattr_uid = '28694';
var flattr_url = 'http://kilianvalkhof.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Kilian Valkhof';
var flattr_dsc = '';
</script>
<script src="https://api.flattr.com/js/0.5.0/load.js?mode=auto" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://kilianvalkhof.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2009/javascript/the-state-of-selectable-text-replacement/">The state of selectable text-replacement</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kilianvalkhof.com/2009/javascript/the-state-of-selectable-text-replacement/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>gridBuilder.js, background grid generator in canvas</title>
		<link>http://kilianvalkhof.com/2009/design/gridbuilder-js-background-grid-generator-in-canvas/</link>
		<comments>http://kilianvalkhof.com/2009/design/gridbuilder-js-background-grid-generator-in-canvas/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 04:00:15 +0000</pubDate>
		<dc:creator>Kilian Valkhof</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kilianvalkhof.com/?p=451</guid>
		<description><![CDATA[<blockquote><p>In order to correctly draw a 1px wide line, <em>on</em> a single pixel, you actually need to position it 0.5 pixel further.</p></blockquote><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2009/design/gridbuilder-js-background-grid-generator-in-canvas/">gridBuilder.js, background grid generator in canvas</a></p>
]]></description>
			<content:encoded><![CDATA[<p>GridBuilder.js is a jQuery plugin that uses canvas to generate a grid background for arbitrary elements. Because it generates the grid via javascript and canvas, it&#8217;s much more flexible than using an image background.<span id="more-451"></span></p>
<h3>Canvas</h3>
<p>&hellip;is pretty easy. There are good guides available, not the least the one from Dive into HTML5, <a href="http://diveintohtml5.org/canvas.html">Let’s Call It A Draw(ing Surface)</a>. You need them, because there are a couple of gotcha&#8217;s. For example, to get different colored lines, you need to explicitly start new paths (but you don&#8217;t have to explicitly end them, just draw them on the canvas before starting another line). Once you get the way this works, it&#8217;s pretty much straightforward from there.</p>
<p>Another example is that in canvas, pixels are seen as small squares (yes, really.) When you draw a line from a pixel, it actually draws the line centered in the top-left corner of the pixel. When it renders, that means that the line gets blurred because it&#8217;s actually drawn on two pixels. This means that in order to correctly draw a 1px wide line, <em>on</em> a single pixel, you actually need to position it 0.5 pixel further. (so it&#8217;s in the &#8216;middle&#8217; of the pixel). It turns out, that sort of fails in Firefox (but not in Safari) because of a rounding error. If I used +0.5, Some lines just wouldn&#8217;t appear! However, if you just <strong>subtract 0.5</strong>, then everything works as expected.</p>
<h2><a href="http://gridbuilder.kilianvalkhof.com/">Download and demo</a></h2>
<p>The whole project is hosted at github as well: <a href="http://github.com/Kilian/gridBuilder.js">gridBuilder.js on Github</a>. gridBuilder.js is 4kb unpacked, uses jQuery and works in <strong>real browsers</strong>*. It&#8217;s dual licensed under the GPL and MIT licenses.</p>
<p>*A real browser here is defined as one that supports both <em>canvas</em> and <em>data-url&#8217;s</em>. The latter is being used to set the canvas as a background image for your element.</p>
<h3>Code</h3>
<p>Since it&#8217;s a <a href="http://jquery.com">jQuery</a> plugin, gridBuilder.js works for any jquery element. gridBuilder.js offers 5 customizable settings, a primary and secondary color for gridlines and secondary gridlines (positioned in the middle between two gridlines), a height for the vertical rhythm, a width for the horizontal strokes and a gutter (spacing) for between the strokes. </p>
<p>Entering <code>false</code> for any of the options will disable that particular option, so you can for example just have a vertical rhythm and no horizontal strokes, or disable the secondary gridlines. The default settings are shown below.</p>
<pre><code>$(document).ready(function(){
  $("body").gridBuilder({
    color:          '#eee',    // color of the primary gridlines
    secondaryColor: '#f9f9f9', // color of the secondary gridlines
    vertical:       18,        // height of the vertical rhythm
    horizontal:     140,       // width of horizontal strokes
    gutter:         40,        // width of the gutter between strokes
  });
});</code></pre>
<p>While this is a plugin you&#8217;d primarily use while building a website, should you want to remove it via javascript, you can call this function:</p>
<pre><code>$("body").destroyGrid();</code></pre>
<h3>Future improvements</h3>
<p>I would like to add a floating panel where you can enter all options and have the grid regenerate on the fly, as well as giving you the javascript code to invoke that particular grid. This would make it easier to tweak your grid, since you wouldn&#8217;t have to edit your file, save it and then refresh. </p>
<p>It&#8217;s hosted on <a href="http://github.com/Kilian/gridBuilder.js">Github</a>, so feel free to fork it and do with it whatever you like :)</p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://kilianvalkhof.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2009/design/gridbuilder-js-background-grid-generator-in-canvas/">gridBuilder.js, background grid generator in canvas</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kilianvalkhof.com/2009/design/gridbuilder-js-background-grid-generator-in-canvas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cufón vs. Typeface.js, which one is better?</title>
		<link>http://kilianvalkhof.com/2009/javascript/cufon-vs-typefacejs-which-one-is-better/</link>
		<comments>http://kilianvalkhof.com/2009/javascript/cufon-vs-typefacejs-which-one-is-better/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 07:00:00 +0000</pubDate>
		<dc:creator>Kilian Valkhof</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kilianvalkhof.com/?p=355</guid>
		<description><![CDATA[<blockquote><p>Cuf&#243;n and Typeface.js are very similar in use, with just a couple of key differences.</p></blockquote><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2009/javascript/cufon-vs-typefacejs-which-one-is-better/">Cufón vs. Typeface.js, which one is better?</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Cuf&oacute;n and Typeface.js are both methods to show text in custom fonts (like sIFR), are both only a couple of months old and both use canvas or VML. So what&#8217;s the difference? And which one is better?<span id="more-355"></span></p>
<h3>How does it work?</h3>
<p><a href="http://cufon.shoqolate.com/generate/">Cuf&oacute;n</a> and <a href="http://typeface.neocracy.org">Typeface.js</a> both work by converting a regular font file into an internal format. On execution, they display the font using Canvas in modern browsers, and VML in Internet Explorer. The benefits of doing it this way is that you do not need to load the Flash plugin. This makes it faster compared to <a href="http://wiki.novemberborn.net/sifr/">sIFR</a>, and visible on more computers.</p>
<h3>Quick stats</h3>
<p>Cuf&oacute;n and Typeface are very similar, here&#8217;s a quick list of their properties:</p>
<table>
<tr>
<th></th>
<th>Cuf&oacute;n</th>
<th>Typeface.js</th>
</tr>
<tr>
<th>File size</th>
<td>14.0kb (compressed)</td>
<td>16.3kb (uncompressed)</td>
</tr>
<tr class="alt">
<th>Supported browsers</th>
<td>Firefox 1.5+, Safari 3+, Opera 9.5+, Google Chrome and Internet Explorer6+</td>
<td>Firefox 1.5+, Safari 2+, and Internet Explorer 6+, but not 8</td>
</tr>
<tr>
<th>Supported file types</th>
<td>.ttf, .otf, PFB, postscript</td>
<td>.ttf</td>
</tr>
<tr class="alt">
<th>Supported font styling</th>
<td>font-size, font-style, font-weight, line-height, text-shadow, color</td>
<td>font-size, font-style, font-weight, font-stretch, letter-spacing, line-height</td>
</tr>
<tr>
<th>Selectable text?</th>
<td>not yet</td>
<td>not yet</td>
</tr>
<tr>
<th></th>
<th>Cuf&oacute;n</th>
<th>Typeface.js</th>
</tr>
</table>
<h3>Font Conversion</h3>
<p>Both Typeface.js and Cuf&oacute;n have an online font converter:</p>
<ul>
<li><a href="http://Cufon.shoqolate.com/generate/">Font converter for Cuf&oacute;n</a></li>
<li><a href="http://typeface.neocracy.org/fonts.html">Font converter for Typeface.js</a></li>
</ul>
<p>You upload your font, select which glyph groups (which are sets like uppercase, lowercase, numbers, punctuation etc.) you want to include and it returns a .js file containing your font. Typeface.js only supports TrueType (.ttf) fonts. Cuf&oacute;n also supports OpenType (.otf), Printer Font Binary and postscript. The converter for Typeface.js has a build-in check for the font license, and will refuse to convert any font that doesn&#8217;t allow embedding.</p>
<p>On uploading, Typeface.js forwards to a page where you can select your glyphs and download your file. Cuf&oacute;n lets you select the glyphs on the first page, and also give you the option to include a bold and an italic variant in the same file. Besides that, it allows you to restrict usage to certain domains, and set the quality of the font (lower quality is faster performance).</p>
<p>I used both to convert Optimer with uppercase, lowercase, numerals, punctuation and extended latin. Cuf&oacute;n&#8217;s file is called <a href="/uploads/cufon-vs-typeface/Optimer_400.font.js">Optimer_400.font.js</a> and is <strong>27.3kb</strong> while Typeface.js&#8217; file is called <a href="/uploads/cufon-vs-typeface/optimer_regular.typeface.js">optimer_regular.typeface.js</a> and is <strong>68.7kb</strong>.</p>
<h3>Including Cuf&oacute;n or Typeface.js in your website</h3>
<p>Cuf&oacute;n and Typeface.js both work by linking to their javascript file and the font file in your <code>&lt;head&gt;</code>:<br />
<strong>Cuf&oacute;n</strong></p>
<pre><code>&lt;head&gt;
  &hellip;
  &lt;script src="cufon-yui.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="Optimer_400.font.js" type="text/javascript"&gt;&lt;/script&gt;
  &hellip;
&lt;/head&gt;</code></pre>
<p><strong>Typeface.js</strong></p>
<pre><code>&lt;head&gt;
  &hellip;
  &lt;script src="typeface-0.11.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="optimer_regular.typeface.js" type="text/javascript"&gt;&lt;/script&gt;
  &hellip;
&lt;/head&gt;</code></pre>
<p>To select which elements to convert, you have to add the following <code>&lt;head&gt;</code> for Cuf&oacute;n:</p>
<pre><code>&lt;script type="text/javascript"&gt;
  Cufon.replace('h1');
  //If you also include a library, you can add complex selectors like #content h1
&lt;/script&gt;</code></pre>
<p>Typeface.js does things a bit differently, and in my opinion, easier. Typeface.js automatically changes all heading elements that reference Typeface.js fonts (which is the first part of your font file name, in our case <em>optimer</em>, and any element that has the class <code>typeface-js</code>:</p>
<pre><code>&lt;div class="myclass <strong>typeface-js</strong>"&gt;
&hellip;
h1,  h2 {
  font-family:optimer;
}</code></pre>
<h3>Multiple fonts</h3>
<p>Both Typeface.js and Cuf&oacute;n allow you to load in multiple fonts. Typeface.js finds them automatically when you specify them in your CSS, and Cuf&oacute;n allows you to use multiple fonts by specifying the font-family in it&#8217;s initial function:</p>
<pre><code>Cuf&oacute;n.replace('h2', { fontFamily: 'Qlassik Medium' }); </code></pre>
<h3>Internet Explorer 7</h3>
<p>No party would be complete without someone trying to ruin it for everyone, so here&#8217;s internet explorer&#8217;s problem: for both Cuf&oacute;n and Typeface.js, the script can have a couple of milliseconds of delay, causing the text to &#8216;flicker&#8217;. To stop it from doing so, place the following code right before the closing <code>&lt;/body&gt;</code> body tag:</p>
<p><strong>Cuf&oacute;n:</strong></p>
<pre><code>&lt;script type="text/javascript"&gt; Cufon.now(); &lt;/script&gt;</code></pre>
<p><strong>Typeface.js</strong></p>
<pre><code>&lt;script type="text/javascript"&gt; _typeface_js.renderDocument(); &lt;/script&gt;</code></pre>
<h3>Side by Side</h3>
<p>Of course, all this is fun, but it would be nice to see them in action besides each other. No worries, I&#8217;ve made a <strong><a href="/uploads/cufon-vs-typeface/">Demo Comparison Page</a></strong>.</p>
<p>On rendering, you can see a number of spacing differences. There are especially noticeable when looking at the spacing in the typographic scale, where Cuf&oacute;n performs much better than Typeface.js</p>
<h3>Conclusion</h3>
<p>Which one is better? Cuf&oacute;n or Typeface.js? In terms of functionality, the difference is small. Cuf&oacute;n supports more filetypes, Typeface.js supports more CSS properties. Both however, support the stuff you&#8217;re most likely to need. Typeface.js is easier to use (just use the right font-family and, if it&#8217;s not a header, add a class), Cuf&oacute;n is about 40kb smaller in total and handles spacing better out of the box.</p>
<p>For now, Cuf&oacute;n performs slightly better due to handling spacing better, but I don&#8217;t think there is a clear winner. That just means that the race is on: <strong>the first one to add selectable text wins!</strong></p>
<h3>Next Week</h3>
<p>Come back next week for an article on how to <strong>combine these techniques with @font-face!</strong></p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.14';
var flattr_uid = '28694';
var flattr_url = 'http://kilianvalkhof.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Kilian Valkhof';
var flattr_dsc = '';
</script>
<script src="https://api.flattr.com/js/0.5.0/load.js?mode=auto" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://kilianvalkhof.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2009/javascript/cufon-vs-typefacejs-which-one-is-better/">Cufón vs. Typeface.js, which one is better?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kilianvalkhof.com/2009/javascript/cufon-vs-typefacejs-which-one-is-better/feed/</wfw:commentRss>
		<slash:comments>71</slash:comments>
		</item>
		<item>
		<title>Fancyzoom image gallery functionality</title>
		<link>http://kilianvalkhof.com/2009/javascript/fancyzoom-1-1-1-image-gallery-functionality/</link>
		<comments>http://kilianvalkhof.com/2009/javascript/fancyzoom-1-1-1-image-gallery-functionality/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 01:00:11 +0000</pubDate>
		<dc:creator>Kilian Valkhof</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kilianvalkhof.com/?p=338</guid>
		<description><![CDATA[<blockquote><p>Since I was adding next and previous links, I wanted the arrow keys to work as well.</p></blockquote><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2009/javascript/fancyzoom-1-1-1-image-gallery-functionality/">Fancyzoom image gallery functionality</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Fancyzoom is pretty cool in a lot of ways, like it&#8217;s amazing zoom functionality modelled after OS X. The only thing missing was next and previous links for gallery functionality, so I implemented those.<span id="more-338"></span></p>
<h3>How it works</h3>
<p>This version is an edit of the original Fancyzoom, available at <a href="http://www.fancyzoom.com">http://www.fancyzoom.com</a>.</p>
<p>I&#8217;m used to writing JavaScript with a library like jQuery or Prototype, but since Fancyzoom was library-free, I decided not to add additional dependencies. <em>Turns out, regular JavaScript makes you type a whole lot more.</em> Here&#8217;s what I did:</p>
<p>For next and previous links to work we need to know which images are next and previous, and even <em>if</em> there is a next or previous image. So on initialisation I compose an array of &#8216;candidate images&#8217;. When you then open an image, it checks the position of the current image in the array, and adds or hides the previous/next links accordingly. The first image doesn&#8217;t get a previous, the last image doesn&#8217;t get a next, everything in between gets both links. </p>
<p>When displaying the links, I add the corresponding image number to the previous and next links (current image number minus one for previous, and plus one for next). When you click either of the links, it finds the image in the array, sets up an onload event, and displays the loading spinner. Once the image is loaded, I remove the spinner and update the previous and next links.</p>
<h3>Keystrokes</h3>
<p>Now, one of the cool things of Fancyzoom is it&#8217;s keystrokes. <code>esc</code> closes the image overlay, <code>ctrl</code> and <code>alt</code>  are click-throughs (no overlay, just open the image). Like in OSX you can press shift while clicking to make the zoom effect go really slow. Since I was adding next and previous links, I wanted the arrow keys to work as well.</p>
<p>I started with <a href="http://www.quirksmode.org/dom/events/keys.html">PPK&#8217;s key reference page</a> to see which charcode I had to use. PPK then gave me <a href="http://twitter.com/ppk/statuses/1230393621">a smart tip</a>: &#8220;Use keydown, not keypress. Saves you a lot of hassle.&#8221;. Fancyzoom used keypress, which indeed make things more annoying to do cross-browser. I changed it to keydown, and it worked without having to change any of the other code. In the end it worked so well that for kicks I also added the spacebar as a way to go to the next image.</p>
<p>The above is of course only a cursory view of the changes made, but the fancyzoom.js and fancyzoomhtml.js files themselves are well documented so with minimal JavaScript knowledge you should be able to follow what&#8217;s happening. (and if not, don&#8217;t hesitate to ask!)</p>
<h3>Download</h3>
<p>Fancyzoom exists out of two files, and I added a third CSS file to it (which you can just copy/paste into your own css file)</p>
<ul>
<li><a href="/uploads/fancyzoom/fancyzoom.js">Fancyzoom.js</a></li>
<li><a href="/uploads/fancyzoom/fancyzoomhtml.js">Fancyzoomhtml.js</a></li>
<li><a href="/uploads/fancyzoom/fancyzoom.css">Fancyzoom.css</a></li>
</ul>
<p><strong>License</strong>: this is <strong>free for personal use</strong>. For all other uses, refer to the full license in the fancyzoom.js file.</p>
<p>You can see it in action on the numerous software pages on Wakoopa, for example the <a href="http://wakoopa.com/software/safari">Safari page</a> or the <a href="http://wakoopa.com/software/openoffice">Openoffice page</a>.</p>
<p><strong>Let me know what you think, and if you have improvements I&#8217;d love to hear them!</strong></p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://kilianvalkhof.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2009/javascript/fancyzoom-1-1-1-image-gallery-functionality/">Fancyzoom image gallery functionality</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kilianvalkhof.com/2009/javascript/fancyzoom-1-1-1-image-gallery-functionality/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Yoda and binary in Firefox with Ubiquity</title>
		<link>http://kilianvalkhof.com/2009/javascript/yoda-and-binary-in-firefox-with-ubiquity/</link>
		<comments>http://kilianvalkhof.com/2009/javascript/yoda-and-binary-in-firefox-with-ubiquity/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 00:00:00 +0000</pubDate>
		<dc:creator>Kilian Valkhof</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kilianvalkhof.com/?p=316</guid>
		<description><![CDATA[<blockquote><p>Writing a Ubiquity command is the perfect bite-size afternoon project.</p></blockquote><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2009/javascript/yoda-and-binary-in-firefox-with-ubiquity/">Yoda and binary in Firefox with Ubiquity</a></p>
]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago I made two Ubiquity commands: A binary (and back) translator, and a Yoda speak translator. While perhaps not particularly useful, they were a lot of fun to make and use, and got me acquainted with the process of building a Ubiquity command.<span id="more-316"></span></p>
<h3>Ubiquity?</h3>
<p><a href="http://ubiquity.mozilla.com/">Ubiquity</a> is quickly becoming my most used Firefox extension. <em>I love it</em>. If you are familiar with <a href="http://do.davebsd.com/">Gnome-do</a> (Linux), <a href="http://www.blacktree.com/">Quicksilver</a> (Mac) or <a href="http://www.launchy.net/">Launchy</a> (Windows) then you already know how powerful a keystroke launcher is. Ubiquity is such a keystroke launcher for the internet. For a great overview, read <a href="http://www.carsonified.com/future-predictions/the-future-is-one-ubiquitous-interface-to-the-web">this article by Ryan Carson</a>.</p>
<p>Ubiquity commands are basically Javascript, but Ubiquity provides some handy additional options to make it very easy to use (and also, you get to write Javascript for just one browser, yay!). They have an excellent tutorial available here: <a href="https://wiki.mozilla.org/Labs/Ubiquity/Ubiquity_0.1_Author_Tutorial">Ubiquity Author tutorial</a>.</p>
<h3>Binary</h3>
<p>A while ago <a href="http://xkcd.com">xkcd</a> posted <a href="http://xkcd.com/540/">this comic</a> which features a bunch of binary. Unlike <em>some people</em>, I can&#8217;t read binary, so I set out to find a binary translator for Ubiquity. Turns out there wasn&#8217;t one! So I immediatelly <a href="http://twitter.com/kilianvalkhof/statuses/1182651092">promised to make one that weekend</a>, which I didn&#8217;t. Instead I made it a weekend later.</p>
<div class="notice"><strong><a href="http://kilianvalkhof.com/uploads/ubiquity-binary/">Download the Ubiquity binary command here</a></strong></div>
<p>You can also try it out on that page, or out in the wild, for example with <a href="http://twitter.com/google/status/1251523388">Google&#8217;s first Twitter message</a>.</p>
<h3>Yoda speak</h3>
<p>Now, It might not be much of a surprise that I am a huge Star Wars geek. Dutch television recently aired all Star Wars movies, and during The Empire strikes back, <a href="http://twitter.com/LeipeLeon/statuses/1200583988">Leon</a> ported the Yoda speak translator <a href="http://gist.github.com/62350">to Ruby</a>. Realising how <strong>awesome</strong> it would be to use that in your browser as well, I immediatelly set out to port it to Ubiquity.</p>
<p>I hadn&#8217;t had much experience with handling sentences (and cutting them up and placing them back in different orders), so the Yoda translator turned out to be a bit harder to make. Luckily I had help from <a href="http://paulchaplin.com/blog">some</a> <a href="http://fluxility.com/wie-zijn-we">friends</a> that reviewed my sometimes silly code and gave corrections.</p>
<div class="notice"><strong><a href="http://kilianvalkhof.com/uploads/ubiquity-yoda/">Download the Ubiquity Yoda speak command here</a></strong></div>
<p>I also included a handy list of Star Wars quotes to get you going.</p>
<h3>Ubiquity = Fun!</h3>
<p>Building Ubiquity commands is fun. I didn&#8217;t describe how to build them in this article because the aforementioned tutorial is much better than I ever could. If you are familiar with Javascript, it&#8217;s pretty easy as well. <strong>Writing a Ubiquity command is the perfect bite-size afternoon project.</strong> </p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.14';
var flattr_uid = '28694';
var flattr_url = 'http://kilianvalkhof.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Kilian Valkhof';
var flattr_dsc = '';
</script>
<script src="https://api.flattr.com/js/0.5.0/load.js?mode=auto" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://kilianvalkhof.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2009/javascript/yoda-and-binary-in-firefox-with-ubiquity/">Yoda and binary in Firefox with Ubiquity</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kilianvalkhof.com/2009/javascript/yoda-and-binary-in-firefox-with-ubiquity/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Text-shadow in IE with jQuery</title>
		<link>http://kilianvalkhof.com/2008/javascript/text-shadow-in-ie-with-jquery/</link>
		<comments>http://kilianvalkhof.com/2008/javascript/text-shadow-in-ie-with-jquery/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 01:00:36 +0000</pubDate>
		<dc:creator>Kilian Valkhof</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kilianvalkhof.com/?p=206</guid>
		<description><![CDATA[<blockquote><p>One handy little thing of Internet Explorer is that it also gives you access to CSS declarations it does <em>not</em> understand</p></blockquote><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2008/javascript/text-shadow-in-ie-with-jquery/">Text-shadow in IE with jQuery</a></p>
]]></description>
			<content:encoded><![CDATA[<p>With the soon-released FireFox 3.1, three of the four major browsers support text-shadow. That leaves just Internet Explorer with the lack of text-shadow. <a href="http://kilianvalkhof.com/2008/design/almost-cross-browser-text-shadow/">I have already taken care of that problem</a>, but decided to wrap it up in a nice automated jQuery plugin.<span id="more-206"></span></p>
<h3>How it works</h3>
<p>One handy little thing of Internet Explorer is that it also gives you access to CSS declarations it does <em>not</em> understand, so we can simply request the text-shadow value of a given element and process that. For a more in-depth explanation of how the technique itself works, please read <a href="http://kilianvalkhof.com/2008/design/almost-cross-browser-text-shadow/">the original article</a>. It should work in Internet Explorer 5.5 to Internet Explorer 8, since I also added the new Internet Explorer 8 version of filter, <a href="http://blogs.msdn.com/ie/archive/2008/09/08/microsoft-css-vendor-extensions.aspx">-ms-filter</a>. </p>
<h3>Demo</h3>
<p><a href="/uploads/jquerytextshadow/">Demo</a>. <em>Works only in Internet Explorer.</em> :)</p>
<h3>The Plugin</h3>
<p>The plugin itself offers two functions: <code>textShadow();</code> and <code>removeTextShadow();</code>, which do what you expect them to do. </p>
<p><code>textShadow();</code> Allows you to optionally overwrite the text-shadow declaration from your CSS to tweak the look of the text-shadow in Internet Explorer, if needed. The available options look like this:</p>
<pre><code>$(elem).textShadow({
	color:   "#000",
	xoffset: "5px",
	yoffset: "5px",
	radius:  "5px",
	opacity: "50"
});</code></pre>
<p>You&#8217;ll notice that all the regular options of text-shadow are there but that I&#8217;ve also added opacity, which helps tweak the intensity of the text-shadow. It&#8217;s translates to Internet Explorer alpha-opacity, so it&#8217;s range is 0 to 100. 50 works best in most cases and is also the default.</p>
<h3>Limitations</h3>
<p>There is really only one major limitation, it just doesn&#8217;t look as good as native text-shadow support in the other browsers. It works pretty well for average-sized text-shadows, but it falls apart on smaller or larger sizes. Tweaking it may help, but <abbr title="Your Mileage May Vary">YMMV</abbr>.</p>
<p>Another small limitation is that the <code>padding-top</code> and <code>padding-left</code> of the elements that get a shadow need to be in pixels, otherwise it won&#8217;t work. I could theoretically write something that takes care of <code>em</code>, <code>%</code>, <code>cm</code>, <code>mm</code>, <code>pt</code>, <code>pc </code><em>and</em> <code>in</code>, but I&#8217;d really rather not.</p>
<h3>Download</h3>
<p>Here you go: <strong><a href="/uploads/jquerytextshadow/jquery.textshadow.js">jquery.textshadow.js</a></strong>. Tested with jQuery 1.2+ but will probably work with older versions as well.</p>
<h2>Update (26 Feb 2010)</h2>
<p>I just released version 1.1, which fixes the problems with IE8. Have fun! <em>In some cases you have to add a z-index to the element that you are adding a shadow to.</em></p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://kilianvalkhof.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2008/javascript/text-shadow-in-ie-with-jquery/">Text-shadow in IE with jQuery</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kilianvalkhof.com/2008/javascript/text-shadow-in-ie-with-jquery/feed/</wfw:commentRss>
		<slash:comments>72</slash:comments>
		</item>
		<item>
		<title>Twitter search in sidebar using Greasemonkey</title>
		<link>http://kilianvalkhof.com/2008/javascript/twitter-search-in-sidebar-using-greasemonkey/</link>
		<comments>http://kilianvalkhof.com/2008/javascript/twitter-search-in-sidebar-using-greasemonkey/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 01:00:13 +0000</pubDate>
		<dc:creator>Kilian Valkhof</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://kilianvalkhof.com/?p=183</guid>
		<description><![CDATA[<blockquote><p>There is one awesome thing about doing stuff with Greasemonkey: <em>it's easy</em></p></blockquote><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2008/javascript/twitter-search-in-sidebar-using-greasemonkey/">Twitter search in sidebar using Greasemonkey</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Twitter&#8217;s recent redesign is great, but quite a few people missed the Twitter people search, or hoped it would add the new search.twitter.com in the sidebar. As I hadn&#8217;t done anything with Greasemonkey yet, but wanted to play around with it for some time, I decided to combine the two.<span id="more-183"></span></p>
<h3>Twitter search in sidebar</h3>
<p>Click the link to install it using <a href="http://greasespot.net">Greasemonkey</a>: <strong><a href="/uploads/twittersearch.user.js">twittersearch.user.js</a></strong></p>
<p>And this is what it looks like:<br />
<img src="http://farm4.static.flickr.com/3149/2911915166_cc8605f649.jpg?v=0" alt="screenshot by Robert Gaal"/></p>
<h3>Greasemonkey</h3>
<p>There is one awesome thing about doing stuff with Greasemonkey: <em>it&#8217;s easy</em>. You&#8217;re just writing regular javascript and some comments that tell Greasemonkey the name and description, which websites to apply to (or not to apply to) and <em>that&#8217;s it</em>. The above script took me about an hour, including eating my dinner. </p>
<p>If you need to do heavier stuff and want to make use of library&#8217;s, <a href="http://wiki.greasespot.net/Code_snippets#Use_jQuery_in_a_GreaseMonkey_script">you can do that, too</a>. The only gotcha I really had, had to do with innerHTML (<strong>shock!</strong>) that acted a bit icky with onfocus functions and parameters in quotes. Solution: remove the quotes. </p>
<p><em>Onfocus</em>? Not event listeners? Well, no. Greasemonkey script themselves are javascript already, so if it&#8217;s in the page, then the user has javascript on. Using an onfocus then is just much easier :)</p>
<p>There are a couple of websites I looked around to find info on Greasemonkey:</p>
<ul>
<li><a href="http://diveintogreasemonkey.org/">Dive into Greasemonkey</a></li>
<li><a href="http://wiki.greasespot.net/Main_Page">The Greasemonkey wiki</a></li>
</ul>
<p>If there&#8217;s an annoyance with a website you use often, and you think you could fix it easily, then Greasemonkey is an excellent way to do that fast and easy. Do you have any tips for Greasemonkey?</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.14';
var flattr_uid = '28694';
var flattr_url = 'http://kilianvalkhof.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Kilian Valkhof';
var flattr_dsc = '';
</script>
<script src="https://api.flattr.com/js/0.5.0/load.js?mode=auto" type="text/javascript"></script> <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://kilianvalkhof.com/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p><p>This article is written by Kilian Valkhof, Front-end developer & User experience designer. Please visit <a href="http://kilianvalkhof.com">KilianValkhof.com</a> for more articles!<br/><br/><a href="http://kilianvalkhof.com/2008/javascript/twitter-search-in-sidebar-using-greasemonkey/">Twitter search in sidebar using Greasemonkey</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kilianvalkhof.com/2008/javascript/twitter-search-in-sidebar-using-greasemonkey/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
