<?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>Tommy Lacroix &#187; HTML</title>
	<atom:link href="http://www.tommylacroix.com/category/web-development/programming/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tommylacroix.com</link>
	<description>Personal Blog</description>
	<lastBuildDate>Tue, 08 Dec 2009 18:23:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Watermarker: A tool for pixel-perfect web integration</title>
		<link>http://www.tommylacroix.com/2009/01/13/watermarker-a-tool-for-pixel-perfect-web-integration/</link>
		<comments>http://www.tommylacroix.com/2009/01/13/watermarker-a-tool-for-pixel-perfect-web-integration/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 21:45:00 +0000</pubDate>
		<dc:creator>tlacroix</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[tools]]></category>
<category>css</category><category>html</category><category>integration</category><category>programming</category><category>tools</category>
		<guid isPermaLink="false">http://www.tommylacroix.com/?p=117</guid>
		<description><![CDATA[Having worked with many fastidious web designers in the past requesting that every single integrated page looks precisely to the pixel like the PSD file &#8212; you know who you are &#8212; I developped this little JavaScript technique that allows the integrator to enable/disable a 80% alpha JPEG image overlay, in order to visually find the discrepancies. [...]]]></description>
			<content:encoded><![CDATA[<p>Having worked with many fastidious web designers in the past requesting that every single integrated page looks precisely to the pixel like the PSD file &#8212; you know who you are &#8212; I developped this little JavaScript technique that allows the integrator to enable/disable a 80% alpha JPEG image overlay, in order to visually find the discrepancies. The code is very ugly but cross-browser compatible, and I never felt compelled to make it better as it does perfectly what it has to do.</p>
<p>It&#8217;s quite easy to use: simply load the JavaScript file at the end of your HTML file, and have it point on your JPEG image to an default X/Y position.</p>
<pre class="code">&lt;script language="javascript" type="text/javascript" src="watermarker.js"&gt;&lt;/script&gt;
&lt;script language="javascript" type="text/javascript"&gt;
setWatermark("images/mywatermark.jpg",-4,-5);
&lt;/script&gt;</pre>
<p>And voila, you can toggle your JPEG overlay, move it around, change it&#8217;s alpha transparency and reset it to its default position.</p>
<p><a title="Watermarker Demo" href="http://www.tommylacroix.com/demos/watermarker/" target="_blank">A small demo is available here</a>.</p>
<p><a title="Watermarker JavaScript source" href="http://www.tommylacroix.com/demos/watermarker/watermarker.js.txt"><img style="border: 0pt none ;" src="http://www.tommylacroix.com/img/icons/script_code.gif" alt="PHP Source" width="16" height="16" /></a> <a title="Watermarker JavaScript source" href="http://www.tommylacroix.com/demos/watermarker/watermarker.js.txt">watermarker.js</a> <em>(7.8k)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tommylacroix.com/2009/01/13/watermarker-a-tool-for-pixel-perfect-web-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tips and tricks for accessible stylish HTML controls</title>
		<link>http://www.tommylacroix.com/2008/02/29/accessible-stylish-controls/</link>
		<comments>http://www.tommylacroix.com/2008/02/29/accessible-stylish-controls/#comments</comments>
		<pubDate>Fri, 29 Feb 2008 16:25:14 +0000</pubDate>
		<dc:creator>tlacroix</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[accessibility]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[javascript]]></category>
<category>accessibility</category><category>codeigniter</category><category>css</category><category>html</category><category>javascript</category><category>usability</category>
		<guid isPermaLink="false">http://www.tommylacroix.com/2008/02/29/accessible-stylish-controls/</guid>
		<description><![CDATA[A friend of mine was twittering about accessibility, which gave me the idea to write on how to do no-javascript friendly stylish controls such as check boxes, buttons, and radio buttons.
Because graphic designers care more about the look and site designers care more about accessibility and usability, it&#8217;s often the developers&#8217; role to satisfy them [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.tommylacroix.com/wp-content/uploads/2008/02/accessibility.gif" alt="Accessibility" style="float: right; margin-left: 5px; margin-bottom: 5px" />A friend of mine was <a href="http://www.twitter.com" title="Twitter" target="_blank">twittering</a> about accessibility, which gave me the idea to write on how to do <a href="http://www.tommylacroix.com/demos/stylishcontrols/" title="No-javascript friendly Stylish Controls Demo Page">no-javascript friendly stylish controls</a> such as check boxes, buttons, and radio buttons.</p>
<p>Because graphic designers care more about the look and site designers care more about accessibility and usability, it&#8217;s often the developers&#8217; role to satisfy them both. So here are the tricks I use to make stylish controls look cool when JavaScript is activated, and usable when it is not.</p>
<p>Being mainly a PHP backend programmer, I hate to see the design cripple the code. Therefore, I always make sure that stylish and standard controls end up sending the same data to the server.</p>
<p>In this post, I cover <a href="#buttons" title="Stylish buttons">buttons</a>, <a href="#checkboxes" title="Stylish check boxes">check boxes</a> and <a href="#radios" title="Stylish radio buttons">radio buttons</a>, and provide a <a href="#helper" title="A simple PHP helper to generate stylish check boxes and radio buttons code">simple PHP helper</a> that automatically generates the code. You might also want to check out the <a href="http://www.tommylacroix.com/demos/stylishcontrols/" title="No-javascript friendly Stylish Controls Demo Page" target="_blank">demo page</a> to have an idea of what it looks like.</p>
<p><span id="more-45"></span></p>
<h2><a title="buttons" name="buttons"></a>Buttons</h2>
<p>Without a doubt, this is the easiest one. We usually use an <em>A</em> tag with an <em>on-click</em> or <em>javascript: URL</em> event to show buttons when JavaScript is enabled. The reason is: the input-image tag results in drawing tiny dashed borders upon click, and that kind of kills the nice shadow effects.</p>
<p>Note that I use the CSS image cropping technique, well described by the guys at <a href="http://uxd.forumone.com/archives/149-Primary-Navigation-Image-Replacement.html" title="CSS image cropping technique" target="_blank">UXD </a>(or in french at <a href="http://www.quantiksolutions.com/fr/articles/astuce-html-des-balises-h1-et-image-indexables.html" title="CSS image cropping technique" target="_blank">Quantik Solutions</a>).<br />
So the typical JavaScript code for a button would be (I compacted the style sheet because it&#8217;s pretty long) :</p>
<pre class="code"><code>&lt;style type="text/css"&gt;
.button {
 border: 0; margin: 0; padding: 3px 0 0 0;
 background: transparent url(btn_bg.gif) no-repeat 0 0;
 display:block; width: 146px; height: 28px;
 overflow: hidden; font-family: Arial, Helvetica, sans-serif;
 text-decoration: none; font-weight: bold; color: black;
 outline: none; text-align: center;
}

.button:hover {
 background: transparent url(btn_bg.gif) no-repeat 0 -54px;
}

.button:active {
 background: transparent url(btn_bg.gif) no-repeat 0 -103px;
}
&lt;/style&gt;

&lt;h1&gt;Button&lt;/h1&gt;
&lt;a class="button" href="javascript:submitForm('formName');"
    title="Send"&gt;Send&lt;/a&gt;</code></pre>
<p>The no-JavaScript code could be simpler:</p>
<pre class="code">&lt;h1&gt;Button&lt;/h1&gt;
&lt;input type="submit" name="submit" value="Send" /&gt;</pre>
<p>Finally, the JavaScript/no-JavaScript condition display is done using <em>document.write</em> and the <em>noscript</em> tag.</p>
<pre class="code">&lt;h1&gt;Button&lt;/h1&gt;
&lt;script type="text/javascript"&gt;
document.write('&lt;a class="button" href="javascript:submitForm(\'formName\');"
    title="Send"&gt;Send&lt;/a&gt;');
&lt;/script&gt;
&lt;noscript&gt;&lt;input type="submit" name="submit" value="Send" /&gt;&lt;/noscript&gt;</pre>
<h2><a title="checkboxes" name="checkboxes"></a>Check boxes</h2>
<p>This one is a little more complex, but not as much as radio buttons (which I kept for dessert). It is basically the same principle as the button, except that JavaScript required to control the checking and unchecking action when in stylish mode (while this was being done with CSS for the buttons).</p>
<p>First, we define a simple CSS for checked and unchecked states:</p>
<pre class="code">&lt;style type="text/css"&gt;
.checked {
 background-color: black;
 width: 20px;
 display: inline-block;
 text-decoration: none;
 padding-left: 20px;
}
.unchecked {
 background-color: silver;
 width: 20px;
 display: inline-block;
 text-decoration: none;
 padding-left: 20px;
}
&lt;/style&gt;</pre>
<p>Then we create the check box, the stylish one first in JavaScript, and the standard one right after in a <em>noscript</em> tag.</p>
<pre class="code">&lt;script type="text/javascript" language="javascript"&gt;
// Write the clickable A tag
document.write('&lt;a id="checkbox1" href="#"
    onclick="toggleStylishCheckbox(\'checkbox1\', \'val\', \'checked\', \'unchecked\');"
    class="unchecked"&gt;&lt;/a&gt;');
// Write the hidden input tag
document.write('&lt;input type="hidden" name="checkbox1" id="checkbox1_val" value="" /&gt;');
&lt;/script&gt;
&lt;noscript&gt;&lt;input type="checkbox" name="test1" value="val" /&gt;&lt;/noscript&gt;
Check box label&lt;br /&gt;</pre>
<p>Finally, we need to include the control code that enables or disables the stylish check box, called by the <em>on-click</em> event.</p>
<pre class="code"><code>&lt;script type="text/javascript" language="javascript"&gt;
function toggleStylishCheckbox(id, value, classOn, classOff) {
  if (document.getElementById(id+"_val").value != "") {
    document.getElementById(id+"_val").value = "";
    document.getElementById(id).className = classOff;
  } else {
    document.getElementById(id+"_val").value = value;
    document.getElementById(id).className = classOn;
  }
}&lt;/script&gt;</code></pre>
<h2><a title="radios" name="radios"></a>Radio buttons</h2>
<p>This one is the trickiest: you need JavaScript to also to uncheck the previously checked control when checking a new one. Thus, we need to keep track of which group each radio buttons are, so we can quickly access its siblings.</p>
<p>The script goes pretty much as the check boxes one, but with a twist.You first need to define a checked and unchecked class for your radio buttons. You can use the same one as for check boxes.</p>
<p>Then we create the radio button, the stylish one first in JavaScript, and the standard one right after in a <em>noscript</em> tag.</p>
<pre class="code"><code>&lt;script type="text/javascript" language="javascript"&gt;
// Register the button in the group
var radioGroup_1;
if (radioGroup_1 == undefined) {
	// This is the first element, create the group
	radioGroup_1 = ["stylishRadio_1"];
} else {
	// This is not the first element, add to the group
	radioGroup_1.push("stylishRadio_1");
}

// Write the actual button code
document.write('&lt;a id="stylishRadio_1" href="#"
    onclick="toggleStylishRadio(\'stylishRadio_1\', \'radioGroup_1\', \'1\', \'checked\', \'unchecked\');"
    class="checked"&gt;&lt;/a&gt;');

// Create an input hidden for the group if it doesn't exist
if (!document.getElementById("radioGroup_1")) {
	document.write('&lt;input type="hidden" name="set1" id="radioGroup_1" value="1" /&gt;');
}
&lt;/script&gt;

&lt;noscript&gt;
&lt;input type="radio" name="set1" value="1"checked="checked" /&gt;
&lt;/noscript&gt;
Set 1, Option 1&lt;br /&gt;
</code></pre>
<p>Finally, we need to include the control code that enables or disables the stylish radio buttons and their siblings, called by the <em>on-click</em> events.</p>
<pre class="code"><code>&lt;script type="text/javascript" language="javascript"&gt;
function toggleStylishRadio(id, groupName, value, classOn, classOff) {
  // Get the group
  var group = eval(groupName);

  // Process each radio button within it
  for (var i=0;i&lt;group.length;i++) {
    // Get the class for this button
    var myClass;
    if (group[i] == id) {
      myClass=classOn;
    } else {
      myClass=classOff;
    }

    // Set the class
    document.getElementById(group[i]).className = myClass;
  }

  // Update the hidden input
  document.getElementById(groupName).value=value;
}
&lt;/script&gt;
</code></pre>
<h2><a title="helper" name="helper"></a>PHP helper</h2>
<p>As you probably noticed, there is a lot of repetitive markup one need to include for every single check box or radio button. Duplication and maintenance is a pain, so why not let a PHP script do it?</p>
<p>Here&#8217;s the code for a PHP helper that handles the check boxes and the radios buttons automagically. This helper has been made for <a href="http://www.codeigniter.com/" title="CodeIgniter, Rapid Develpment PHP Framework" target="_blank">CodeIgniter</a>, but can be used without it.</p>
<p>I wrote it as a demonstration, and there are many improvements to do. Including the JavaScript control scripts in a separate JavaScript file, for instance, and wrapping check box and radio buttons creation into a function to reduce the amount of repeated JavaScript code. Nonetheless, it works and can be useful as is for simple projects.</p>
<p>Also note that I did no helper for the buttons, as it is pretty simple, and the HTML markup varies a lot from project to project.</p>
<p><img src="/img/icons/script_code.gif" alt="PHP Script" border="0" height="16" width="16" /> <a href="http://www.tommylacroix.com/demos/stylishcontrols/stylishControls_helper.phps" title="No-javascript friendly stylish controls PHP helper " target="_blank">stylishControls_helper.phps</a> (6 KB)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tommylacroix.com/2008/02/29/accessible-stylish-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting your visitors timezone</title>
		<link>http://www.tommylacroix.com/2008/02/25/detect-timezone-with-javascript/</link>
		<comments>http://www.tommylacroix.com/2008/02/25/detect-timezone-with-javascript/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 14:44:29 +0000</pubDate>
		<dc:creator>tlacroix</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[detection]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[timezone]]></category>
		<category><![CDATA[Web development]]></category>
<category>detection</category><category>html</category><category>javascript</category><category>web development</category>
		<guid isPermaLink="false">http://www.tommylacroix.com/2008/02/25/detect-timezone-with-javascript/</guid>
		<description><![CDATA[Most web applications in this World 2.0 target international users distributed among many different timezones. It is pretty simple to ask the users what their timezone is when they registered to your site. This article aims to solve the case of unregistered users who you can&#8217;t ask in a usable way. The solution isn&#8217;t perfect, [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border: 1px solid black; margin: 0pt 5px 5px 0pt; float: left" src="http://www.tommylacroix.com/wp-content/uploads/2008/02/timezone.thumbnail.gif" alt="Timezone map (from netschool.de)" />Most web applications in this World 2.0 target international users distributed among many different <a title="Time zones, at Wikipedia" href="http://en.wikipedia.org/wiki/Time_zone" target="_blank">timezones</a>. It is pretty simple to ask the users what their timezone is when they registered to your site. This article aims to solve the case of unregistered users who you can&#8217;t ask in a usable way. The solution isn&#8217;t perfect, but it&#8217;s better than nothing.</p>
<p>In theory and technologically, we could determine what timezone the user is in by:</p>
<ul>
<li>Using a geo location database to guess their longitude and latitude, and then find the probable timezone from it ;</li>
<li>Using JavaScript to read the user&#8217;s workstation clock and calculate the probable timezone from it. <a title="Detecting your visitors timezone demonstration" href="http://www.tommylacroix.com/demos/timezone/" target="_self">You can see a live demo here</a>.</li>
</ul>
<p>Geo location, while pretty simple nowadays with <a href="http://www.linuxjournal.com/article/7856" target="_blank">free databases floating around</a>, leaves us with a problem: the free databases are often not good enough to pin point a precise longitude and latitude, which will cause garbage in and garbage out when trying to translate it to a timezone. Moreover, the non-free and precise databases are pretty expensive compared to the added value of timezone detection, and are most likely not worth buying just for this purpose.</p>
<p><span id="more-32"></span>JavaScript clock reading on its side offers a pretty simple yet functional solution. The two downsides are:</p>
<ul>
<li>It is impossible to detect the timezone for users who disabled JavaScript (a very few in the AJAX world).</li>
<li>The precision depends on the exactness of the users&#8217; computer clock settings, as its the piece of information we base our calculation on.</li>
</ul>
<p>Here are the three macroscopic steps for the detection:</p>
<ul>
<li>Try to detect the user&#8217;s timezone through JavaScript, then send it via an XML-HTTP call to a script that will save it either as a cookie or as a session. Alternatively, you could use the JavaScript setcookie function.</li>
<li>If detection is impossible (JavaScript is disabled), try to read the previously detected timezone in a cookie.</li>
<li>If no timezone can be detected, use a default one (or chain in the geolocation method).</li>
</ul>
<p>The detection code itself is:</p>
<pre style="border: 1px solid black; margin: 0pt 40px 20px; padding: 4px; background-color: #fafafa; color: #5f5584"><code>function setTimeZone() {
 	var xmlhttp;
 	timezone = "EDT";</code>	/* Initialize httpRequest object */
 	if (window.ActiveXObject) {
 	 	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 	} else if (window.XMLHttpRequest) {
 	 	xmlhttp = new XMLHttpRequest();
 	}
 	xmlhttp.open("POST", "/timezone-controller.php",true);
 	xmlhttp.onreadystatechange=function() {
 	 	if (xmlhttp.readyState==4) {
 	 	 	// Do nothing
 	 	}
 	}

 	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 	var visitortime = new Date();
 	xmlhttp.send('epoch='+visitortime.getTime()/1000+
 	 	'&amp;timezoneoffset='+visitortime.getTimezoneOffset()/60);
} setTimeZone();</pre>
<p>I personally prefer to use the <code>epoch</code> value rather than the <code>timezoneoffset</code> one, as, in my experience, local timezone settings are more often incorrectly set than local time.</p>
<p>In conclusion, it is possible to detect your users&#8217; timezone in a fairly simple way using JavaScript, so you can present them dates and times relative to their location, without having to ask them.</p>
<p>However, the method being imperfect, the safest way to determine their exact timezone will always be to ask them. Thus, the implementation of this method shouldn&#8217;t replace the parameter in their profile.</p>
<p><small><br />
World timezone map found on <a href="http://www.netschool.de/erd/timezone.gif" target="_blank">netschool.de</a>.<br />
Article previously published in French at <a href="http://www.quantiksolutions.com/fr/articles/detecter-le-fuseau-horaire-de-vos-visiteurs.html" target="_blank">Quantik Solutions</a>.<br />
Code distributed under the <a title="GNU Lesser General Public License" href="http://www.gnu.org/copyleft/lesser.html" target="_blank">LGPL license</a>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tommylacroix.com/2008/02/25/detect-timezone-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bunch of CSS techniques, tips and tricks</title>
		<link>http://www.tommylacroix.com/2008/02/22/bunch-of-css-techniques-tips-and-tricks/</link>
		<comments>http://www.tommylacroix.com/2008/02/22/bunch-of-css-techniques-tips-and-tricks/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 19:54:58 +0000</pubDate>
		<dc:creator>tlacroix</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[web design]]></category>
<category>css</category><category>web design</category><category>web development</category>
		<guid isPermaLink="false">http://www.tommylacroix.com/2008/02/22/bunch-of-css-techniques-tips-and-tricks/</guid>
		<description><![CDATA[In case you didn&#8217;t stumble on this pretty neat list of CSS techniques, tips and tricks from Smashing Magazine, well here it is.
Here are a few good ones:

Styling File Inputs with CSS and the DOM
Creating a table with dynamically highlighted columns like Crazy Egg’s pricing table
Hyperlink Cues with Favicons
CSS Dock Menu
CSS Speech Bubbles
CSS: Menu Descriptions
Time [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.tommylacroix.com/wp-content/uploads/2008/02/cssom.png" alt="CSS" style="margin: 5px 0pt 0pt 5px; float: right" />In case you didn&#8217;t stumble on this pretty neat list of <a href="http://www.smashingmagazine.com/2008/02/21/powerful-css-techniques-for-effective-coding/" title="CSS techniques" target="_blank">CSS techniques, tips and tricks</a> from Smashing Magazine, well here it is.</p>
<p>Here are a few good ones:</p>
<ul>
<li><a href="http://www.shauninman.com/archive/2007/09/10/styling_file_inputs_with_css_and_the_dom">Styling File Inputs with CSS and the DOM</a></li>
<li><a href="http://www.askthecssguy.com/2007/08/creating_a_table_with_dynamica.html">Creating a table with dynamically highlighted columns like Crazy Egg’s pricing table</a></li>
<li><a href="http://www.askthecssguy.com/2006/12/hyperlink_cues_with_favicons.html">Hyperlink Cues with Favicons</a></li>
<li><a href="http://www.ndesign-studio.com/blog/mac/css-dock-menu">CSS Dock Menu</a></li>
<li><a href="http://www.willmayo.com/2007/02/10/css-speech-bubbles/">CSS Speech Bubbles</a></li>
<li><a href="http://mikecherim.com/experiments/css_menu_descriptions.php#">CSS: Menu Descriptions</a></li>
<li><a href="http://www.katgal.com/2007/03/time-sensitive-css-switcher-change.html">Time Sensitive CSS Switcher</a></li>
</ul>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tommylacroix.com/2008/02/22/bunch-of-css-techniques-tips-and-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
