<?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>User Agent Man &#187; XML</title>
	<atom:link href="http://www.useragentman.com/blog/category/technologies/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.useragentman.com/blog</link>
	<description>A Blog about Client Side Web Technology</description>
	<lastBuildDate>Wed, 08 Sep 2010 14:02:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Configuring JavaScript Applications With XML</title>
		<link>http://www.useragentman.com/blog/2009/10/27/configuring-javascript-applications/</link>
		<comments>http://www.useragentman.com/blog/2009/10/27/configuring-javascript-applications/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 02:37:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=71</guid>
		<description><![CDATA[I have been hacking JavaScript for close to 12 years now, and love it.  But just like anyone you have been enamored with for a long time, there are bound to be things that drive you crazy about the object of your affection.  Sure, your feelings are stronger than when you first met, but sometimes, [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-283 alignleft whiteImage" title="configurationXML" src="http://www.useragentman.com/blog/wp-content/uploads/2009/10/configurationXML.png" alt="Remixed from an image from the Open Clip Art Library" width="250" height="89" /></p>
<p>I have been hacking JavaScript for close to 12 years now, and love it.  But just like anyone you have been enamored with for a long time, there are bound to be things that drive you crazy about the object of your affection.  Sure, your feelings are stronger than when you first met, but sometimes, after you&#8217;ve had an a disagreement after a late night of coding, you catch yourself thinking “why in the world does she do things that way!?! Ridiculous!  She is driving me crazy with her inflexibility!”  You then calm down, and realize that despite her flaws, she is still the exciting, cool and can&#8217;t-live-without-her girl she was when you first met her – maybe even more so.</p>
<p>Okay, I don&#8217;t mean to equate JavaScript with my wife (that may result with me sleeping on the couch tonight).  But sometimes the way JavaScript does things is pretty silly.  You&#8217;d figure after all these years, some of these things would have changed, but they haven&#8217;t.</p>
<h2>Long Strings in JavaScript</h2>
<p>Take for example the way that JavaScript likes to handle long, multi-line strings:</p>
<blockquote class="code">
<pre>var html = "&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Address&lt;/th&gt;&lt;th&gt;City&lt;/th&gt;" +
"&lt;th&gt;Province&lt;/th&gt;&lt;th&gt;Postal Code&lt;/th&gt;&lt;th&gt;Telephone&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;";</pre>
</blockquote>
<p>Concatenating strings is a pretty expensive operation, both in <a title=" String Performance: an Analysis" href="http://www.sitepen.com/blog/2008/05/09/string-performance-an-analysis/">memory and processing time</a>, and using concatenation  it to describe a constant string doesn&#8217;t make too much sense.  But putting this string on one line would make the code quite unwieldy to read.  Plus it looks ugly.  I may be a slob in real life (my coworkers and my family could go on for hours about that one) , but I love my code neat.</p>
<h2>Hard-Coding Values into Scripts</h2>
<p>Another problem I have with this method of defining strings is that we are hard-coding text into the script. This is not a problem unique to JavaScript by any means, but this breaks the <a title="Wikipedia article on Unobtrusive JavaScript" href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript">Structure/View/Behaviour separation</a> model that I like to follow when I code a web application.  Furthermore, if we had two pages with the same content but written in different languages (like in Canada, where a lot of sites are in English and French) we either have to have two versions of our script, or have the script broken into two parts: one with all the general code in it and one containing the language specific code.    While the latter is the more desirable of the two, it doesn&#8217;t lend itself to integrate well with some server-side web application frameworks like <a title="Java Struts home page." href="http://struts.apache.org/">Java Struts</a>.</p>
<p>Furthermore, I hate hard-coding <strong>any</strong> type of value (strings, integers, and any type of objects) directly into my scripts.  Scripts should be flexible enough to be used in any type of situation &#8211; your table pagination script may work well with having ten rows on the page at the time in one situation, but in another, you may want 15 or 20.</p>
<p>One comment I hear all the time is <strong>&#8220;Why not use JSON&#8221;?</strong> JSON is great, but because it is based on JavaScript, it is still gets ugly when manipulating long strings.</p>
<h2>Enter config.js to the Rescue</h2>
<p>In fact, it was Struts that inspired me to write the config.js JavaScript library.  If you aren&#8217;t familiar with it, Struts is a Java Framework that allows developers to configure their server-side web applications easily with a set of XML files.  It seemed natural to do the same in JavaScript, given all the DOM and XML processing routines that it has at its disposal, so I built config.js to do this task.  With this library, JavaScript developers can configure their own scripts using a block of XML.  This block of XML can be either embedded inside the HTML document (via an HTML comment) or in a separate XML file of its own.  And this configuration block can contain any number of strings, numbers, arrays or objects that a developer would need to get the job done.</p>
<p>For example, let&#8217;s say you had a JavaScript function that looked like this:</p>
<blockquote class="code">
<pre>function submitFormEvent(e){
  var amount = document.getElementById("amount").innerHTML;
  var creditCardType = document.getElementById("ccType").value;
  var month = document.getElementById("month").value;

  var configString = "Submitting this order will charge " + amount +
    " to your " + creditCardType +
    " and will be received on your " + month +
    " credit card bill.  Are you sure you want to do" +
    " this?");

  if (window.confirm(configString)) {
    window.location = "http://www.mycompany.com/myApp/chargeMe.do";
  }
  return;
}</pre>
</blockquote>
<p>As you can see, the English literals are hard-coded in the script and there is a lot of string concatenation going on.  One could refactor the script to use config.js to fix these issues  in four simple steps:</p>
<ol>
<li>Include the EventHelpers.js and config.js scripts in the &lt;head&gt; of your document (EventHelpers.js is included with the config.js archive):<br />
<blockquote class="code">
<pre>&lt;script type=”text/javascript” src=”/path/to/EventHelpers.js”&gt;&lt;/script&gt;
&lt;script type=”text/javascript” src=”/path/to/config.js”&gt;&lt;/script&gt;</pre>
</blockquote>
</li>
<li>Insert an XML block that contains the hard-coded strings in an HTML tag with an <code>id</code> of <code>config</code>:<br />
<blockquote class="code">
<pre>&lt;div id="config"&gt;
&lt;!--
&lt;config&gt;
  &lt;myApp&gt;
   &lt;confirmCharge&gt;
      &lt;text&gt;
Submitting this order will charge @amount@  to your
@creditCardType@ and will be received on your @month@
credit card bill.  Are you sure you want to do this?
      &lt;/text&gt;
      &lt;url&gt;http://www.mycompany.com/myApp/confirm.do&lt;/url&gt;
   &lt;/confirmCharge&gt;
  &lt;/myApp&gt;
&lt;/config&gt;
 --&gt;
&lt;/div&gt;</pre>
</blockquote>
</li>
<li>Refactor you code to use config.js routines:<br />
<blockquote class="code">
<pre>function submitFormEvent(e){
      var amount = document.getElementById("amount").innerHTML;
      var creditCardType = document.getElementById("ccType").value;
      var month = document.getElementById("month").value;
<strong>
      var configString = config.getScriptedValue(
          "myApp.confirmCharge.text",
          {
            amount: amount,
            creditCardType: creditCardType,
            month: month
          });

      if (window.confirm(configString)) {
          window.location = config.getValue("myApp.confirmCharge.url");
      }
</strong>
      return;
}</pre>
</blockquote>
</li>
<li>Replace any <code>window.onload</code> calls in your code with <code>config.addLoadEvent()</code> to ensure that any code that relies on config.js is initialized <strong>after</strong> the XML block is loaded into memory:<br />
<blockquote class="code">
<pre>config.addLoadEvent(exampleConfigForm.init);</pre>
</blockquote>
</li>
</ol>
<p>That&#8217;s it!  If you need to internationalize your application, use whatever internationalization framework your server side code uses &#8211; it should integrate well with config.js.  I use it with Java Struts all the time.</p>
<p><a class="exampleLink" href="/tests/config/example.html">See an example of the above code in action</a></p>
<h2>Use config.js in All Your Scripts</h2>
<p>Have more than one script on a page that you want to use config.js with?  No problem!  Add another block of XML inside the &lt;config&gt; node right after your other scripts config information:</p>
<blockquote class="code">
<pre>&lt;div id=”config”&gt;
&lt;!--
&lt;config&gt;
  &lt;myApp&gt;
   &lt;confirmCharge&gt;
      &lt;text&gt;
Submitting this order will charge @amount@  to your
@creditCardType@ and will be received on your @month@
credit card bill.  Are you sure you want to do this?
      &lt;/text&gt;
      &lt;url&gt;http://www.mycompany.com/myApp/confirm.do&lt;/url&gt;
   &lt;/confirmCharge&gt;
  &lt;/myApp&gt;

<span class="hilite">&lt;calendarWidget&gt;
  &lt;instructions&gt;Enter in a valid date after @dateBegin@&lt;/instructions&gt;
  &lt;errors&gt;
    &lt;notValid&gt;The date you entered is not valid&lt;/notValid&gt;
    &lt;holiday&gt;
Sorry, @date@ is a holiday and we won't be open
at that time.  Please try again.
    &lt;/holiday&gt;
  &lt;/errors&gt;
&lt;/calendarWidget&gt;
</span>
&lt;/config&gt;
--&gt;
&lt;/div&gt;</pre>
</blockquote>
<p>Now, all your configuration information for all your scripts can be in one place.  Programmers can now develop the code with place holders for the text, and not worry about accidentally messing up the code when marketing or customer service wants to make some textual changes.</p>
<h2>config.js can also handle HTML</h2>
<p>You can even insert full HTML inside the configuration XML block using a CDATA node:</p>
<blockquote class="code">
<pre>&lt;config&gt;
&lt;myApp&gt;
  &lt;browserWarning&gt;&lt;![CDATA[
    &lt;div class=”warning”&gt;
    As of @date@ we will &lt;strong&gt;not&lt;/strong&gt; be supporting Internet
    Explore 6 or lower.  Please &lt;a href=”/howToUpgradeIE.html"&gt;upgrade your
    installation of Internet Explorer&lt;/a&gt;, or install the latest version of one
    &lt;a href=”/otherChoices.html”&gt;the many alternative browsers available&lt;/a&gt;.
    &lt;/div&gt;
  ]]&gt;&lt;/browserWarning&gt;
  &lt;/myApp&gt;
&lt;/config&gt;</pre>
</blockquote>
<p>This makes using an HTML node&#8217;s .innerHTML property even more fun!  You longer do you have to hard-code  long chunks of HTML inside your scripts.  Try that with JSON!</p>
<h2>Framework Independent</h2>
<p>Config.js is not part of a JavaScript framework – you can use this library whether you use prototype, mootools, Dojo, jQuery or anything else that may come along.  Please feel free to make improvements and changes on it &#8211; if you submit the changes back to me, I&#8217;ll incorporate them into the next official release.</p>
<h2>More Information</h2>
<p>There is way more to config.js than is explained here.  Complete documentation for the library can be found here:<br />
<a class="exampleLink" href="/blog/config-js-–-a-javascript-cofiguration-library/">config.js manual page</a></p>
<h2>Download</h2>
<p>You can get full source here:</p>
<p><a class="exampleLink" href="/downloads/config.zip">config.js v.2.0 and example code (zip format)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2009/10/27/configuring-javascript-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More @font-face fun</title>
		<link>http://www.useragentman.com/blog/2009/10/09/more-font-face-fun/</link>
		<comments>http://www.useragentman.com/blog/2009/10/09/more-font-face-fun/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 00:53:36 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[@font-face. opera. chrome]]></category>
		<category><![CDATA[anti-aliasing]]></category>
		<category><![CDATA[cleartype]]></category>
		<category><![CDATA[svg fonts]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=237</guid>
		<description><![CDATA[My first post @font-face in Depth got a huge amount of unexpected attention.  Thank you all for your comments and criticism.  Since the post, there have been quite a bit of information I have read about and thought I should share. SVG fonts for Opera and Chrome Jonathan Snook wrote a great article regarding Opera [...]]]></description>
			<content:encoded><![CDATA[<p>My first post <a href="/blog/2009/09/20/font-face-in-depth/">@font-face in Depth</a> got a <strong>huge</strong> amount of unexpected attention.  Thank you all for your comments and criticism.  Since the post, there have been quite a bit of information I have read about and thought I should share.</p>
<h2>SVG fonts for Opera and Chrome</h2>
<p><a href="http://www.snook.ca/">Jonathan Snook</a> wrote a great article <a href="http://www.snook.ca/archives/html_and_css/becoming-a-font-embedding-master">regarding Opera 10 and Google Chrome supporting SVG fonts</a> (Chrome can load them without any pesky command line switch!).   He mentions how to convert TrueType fonts to this format using <a href="http://xml.apache.org/batik/">Batik</a>, and that by removing all the <code>&lt;hkren&gt;</code> elements inside the file&#8217;s XML can make the font smaller than the original TrueType file.  Too bad the browsers don&#8217;t support this format.</p>
<h2>Opera&#8217;s buggy implementation</h2>
<p>I noticed after I launched my first @font-face article that Opera was not loading the fonts on my blog when users visited more than one page.  It turns out that Opera 10&#8242;s implementation of @font-face is a little buggy.  When you feed it a page with an embedded font, you may not see the embedded fonts properly, like in the screenshot below:</p>
<div id="attachment_238" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.useragentman.com/blog/wp-content/uploads/2009/10/screenshotOpera.png"><img class="size-medium wp-image-238 " title="screenshotOpera" src="http://www.useragentman.com/blog/wp-content/uploads/2009/10/screenshotOpera-300x215.png" alt="screenshotOpera" width="300" height="215" /></a><p class="wp-caption-text">Opera sometimes doesn&#39;t load the font at all, and removes other styling (click to enlarge).</p></div>
<p><a href="http://readableweb.com/opera-admits-font-face-bugs-in-opera-10/">According to Opera</a>, this happens when &#8220;specifying different weights and styles for a single font-family name&#8221;.  Håkon Wium Lie, the company&#8217;s Chief Technology Officer , <a href="http://devfiles.myopera.com/articles/751/webfonts-workaround.html">has described a work-around</a> until the company can fix the problem properly.</p>
<p>I am debating whether to implement the work around on my site, or to wait for Opera to fix the problem and patch all Opera 10 installations via auto-update (I&#8217;m leaning towards the latter).</p>
<h2>Performance Issues With Font Embedding</h2>
<p>One of the comments on the last article came from <a href="http://stevesouders.com/">Steve Souders</a> who had <a href="/blog/2009/09/20/font-face-in-depth/#comment-37">performance concerns with font-embedding</a>.  Paul Irish came back with information showing the <a href="http://paulirish.com/2009/fighting-the-font-face-fout/">when browsers load the fonts, and what they do before the font is loaded</a>.  He also shows how to use JavaScript to make the loading behaviour consistent between browsers.</p>
<p>The performance issues with font-embedding is something I am going to be keeping an eye on, especially when it comes to font-services, which the OpenType site believes will be <a href="http://opentype.info/blog/2009/07/29/why-webfont-services-are-the-future-of-fonts-on-the-web/">the future of web font distribution for commercial fonts</a>.  Although it doesn&#8217;t seem like much of an issue currently (my blog <em>seems</em> to load quickly), I don&#8217;t want to do anything that would slow down my web applications &#8211; especially if I am using them just to make the text look a little prettier.</p>
<h2>Windows XP Rendering Issues</h2>
<p>Boing-Boing had a bad experience with font-embedding.  Turns out <a href="http://www.webmonkey.com/blog/Boing_Boing_s_Redesign_Uncovers_the_Dark_Side_of_Web_Fonts">they got a lot of complaints when they decided to incorporate it into their website</a>.  The reason: some users didn&#8217;t have ClearType turned on, and the font Boing-Boing chose looked &#8220;like ass&#8221; without ClearType.</p>
<p>Below are screenshots of this site without ClearType on:</p>
<div id="attachment_250" class="wp-caption aligncenter" style="width: 449px"><img class="size-full wp-image-250" title="ieNoAA" src="http://www.useragentman.com/blog/wp-content/uploads/2009/10/ieNoAA.png" alt="ieNoAA" width="439" height="336" /><p class="wp-caption-text">Internet Explorer without ClearType</p></div>
<p style="text-align: center;">
<div id="attachment_251" class="wp-caption aligncenter" style="width: 465px"><img class="size-full wp-image-251" title="firefoxNoAA" src="http://www.useragentman.com/blog/wp-content/uploads/2009/10/firefoxNoAA.png" alt="Firefox without ClearType" width="455" height="327" /><p class="wp-caption-text">Firefox without ClearType</p></div>
<p>The article stated that there are quite a few XP computers which apparently don&#8217;t have ClearType on by default. I wonder if there are any stats to back that up. If so, then developers embed fonts into pages should test that scenario as well.  It does look different.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2009/10/09/more-font-face-fun/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
