<?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>rel=me &#187; Javascript</title>
	<atom:link href="http://rel.me/c/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://rel.me</link>
	<description>programming, objective-c, cocoa, iphone, c</description>
	<lastBuildDate>Mon, 02 Aug 2010 20:09:36 +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>Font detection with Javascript and Flash</title>
		<link>http://rel.me/2008/06/26/font-detection-with-javascript-and-flash/</link>
		<comments>http://rel.me/2008/06/26/font-detection-with-javascript-and-flash/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 22:08:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[fonts]]></category>

		<guid isPermaLink="false">/2008/06/26/font-detection-with-javascript-and-flash</guid>
		<description><![CDATA[I was playing around with jquery and I wanted to see if it was possible to generate a cheat sheet of all the fonts on your system. Its also a good run through of how to load a SWF with a callback. View a demo (Though, its possible it might not work) The steps I [...]]]></description>
			<content:encoded><![CDATA[<p>I was playing around with jquery and I wanted to see if it was possible to generate a cheat sheet of all the fonts on your system. Its also a good run through of how to load a SWF with a callback.</p>
<p><img src="http://font-detect.s3.amazonaws.com/font-detect.png" alt="" width="583" height="335" /></p>
<p><a href="http://font-detect.s3.amazonaws.com/index.html">View a demo</a> (Though, its possible it might not <a href="http://www.codinghorror.com/blog/images/works-on-my-machine-starburst.png">work</a>)</p>
<p>The steps I used to generate this are:</p>
<ul>
<li>Load SWF</li>
<li>Javascript calls to Actionscript fonts() method via <code>ExternalInterface</code></li>
<li>Get the list of system fonts in Flash via <code>Font.enumerateFonts(true)</code></li>
<li>Curse Flash for giving you a list of font names, where half of them are garbage.</li>
<li>For each font name, in javascript, create a test which adds a DOM element temporarily with a fallback font family set. For example, <code>font-family: 'Apple Garamond Pro', 'Times New Roman';</code>, where Times New Roman is your fallback.</li>
<li>Then check the actual width (via offsetWidth). If it does not match the offsetWidth of the fallback font, then we know it rendered ok. (The original idea is from <a href="http://www.lalit.org/lab/javascript-css-font-detect">http://www.lalit.org/lab/javascript-css-font-detect</a>)</li>
</ul>
<p>The only caveat is, if the actual font width and the fallback font width do match, then you would have a false negative. So its not bulletproof.</p>
<p>The actionscript to enumerate the fonts and call back out is pretty simple:<br />
<script src="http://gist.github.com/138691.js"></script><br />
Expose the method in the constructor using ExternalInterface:<br />
<script src="http://gist.github.com/138692.js"></script><br />
<a href="http://github.com/gabriel/font-detect-js/tree/master/flash/src/FontList.as">FontList.as</a></p>
<p>I used swfobject to load the SWF. Also be sure to enable <code>allowScriptAccess</code>.</p>
<p>The javascript to test the fonts is at: <a href="http://github.com/gabriel/font-detect-js/tree/master/javascripts/font-detect.js">font-detect.js</a></p>
<p>You can use it by including:</p>
<p><script src="http://gist.github.com/138690.js"></script></p>
<p>In the end, I don&#8217;t think this is useful in practice, but I thought I would share anyway. Its on <a href="http://github.com/gabriel/font-detect-js/tree/master">github</a> too.</p>
<p><strong>Updated:</strong> Now uses call straight to actionscript, doesn&#8217;t marshall JSON first so its much faster, and other refactoring.</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2008/06/26/font-detection-with-javascript-and-flash/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Automating JS behavior registration</title>
		<link>http://rel.me/2007/05/16/automating-js-behavior-registration/</link>
		<comments>http://rel.me/2007/05/16/automating-js-behavior-registration/#comments</comments>
		<pubDate>Wed, 16 May 2007 19:01:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">/2007/09/03/automating-js-behavior-registration</guid>
		<description><![CDATA[I created a behaviors javascript class to handle all my (prototype) Event observe registrations. Annotating DOM elements with the metadata needed to register itself automatically, which would save you from having to call Behavior.register(..). The behavior class is defined in behavior.js (The idea of parsing the entire DOM came from a co-worker at revolutionhealth.com). This [...]]]></description>
			<content:encoded><![CDATA[<p>I created a behaviors javascript class to handle all my (prototype) Event observe registrations. Annotating DOM elements with the metadata needed to register itself automatically, which would save you from having to call Behavior.register(..).<br/></p>
<p>The behavior class is defined in <a href="http://dclicio.us/javascripts/behavior.js">behavior.js</a> (The idea of parsing the entire DOM came from a co-worker at <a href="http://www.revolutionhealth.com">revolutionhealth.com</a>). This traversal maybe be expensive but if you had a ton of behaviors that register using CSS selectors, this might be faster (Don&#8217;t quote me on this though).<br/></p>
<p>If you have a link, and wanted to provide an AJAX call without being obtrusive:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&lt;a class=&quot;bvr-observe-click-xhrTheFunction&quot; href=&quot;/the/href&quot;&gt;The link&lt;/a&gt;</pre>
</td>
</tr>
</table>
<p>The AJAX request:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">function xhrTheFunction(event) {  <tt>
</tt>  var element = Event.element(event);<tt>
</tt>  var url = element.readAttribute(&quot;href&quot;);<tt>
</tt>  new Ajax.Updater(&quot;div_to_update&quot;, url, { });  <tt>
</tt>  Event.stop(event);<tt>
</tt>}</pre>
</td>
</tr>
</table>
<p>To create and apply the behavior, starting at id=&#8221;content&#8221;:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">var dclBehavior = new Behavior();<tt>
</tt>dclBehavior.apply($('content'));</pre>
</td>
</tr>
</table>
<p>It will automatically register for the event observe. In other words it would do the following for you automatically:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"> Event.observe(theLinkElement, &quot;click&quot;, function(event) { xhrTheFunction(event) });</pre>
</td>
</tr>
</table>
<p>You could also handle other common tasks through bvr-* naming conventions. And you could also manually register your behaviors.</p>
<p>I am using this over at <a href="http://dclicio.us">dclicio.us</a>, in a couple places, if you want to see it in action.</p>
<p><strong>Update:</strong>This is just a proof of concept (not entirely functional). The idea is to parse the DOM all in one shot so if you have a ton of behaviors, you don&#8217;t have to deal with alot of selector rules.<br />
 You could add other naming conventions, probably make them less verbose, change it to do binding, etc. Its definately not a good solution if you are only observing clicks <img src='http://rel.me/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/05/16/automating-js-behavior-registration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASProject and Flash debugging to Firebug console</title>
		<link>http://rel.me/2007/04/12/asproject-and-flash-debugging-to-firebug-console/</link>
		<comments>http://rel.me/2007/04/12/asproject-and-flash-debugging-to-firebug-console/#comments</comments>
		<pubDate>Thu, 12 Apr 2007 02:47:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[asproject]]></category>
		<category><![CDATA[asunit]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">/2007/09/03/asproject-and-flash-debugging-to-firebug-console</guid>
		<description><![CDATA[Publishing, testing, and running Actionscript projects is a pain. &#8220;AsProject automates a variety of tasks including the creation of projects, classes, test cases, test suites, and swfmill libraries. It automates the download, installation and configuration of the debug flash player and many open source tools. AsProject also includes sophisticated build tools written in rake to [...]]]></description>
			<content:encoded><![CDATA[<p>Publishing, testing, and running Actionscript projects is a pain.</p>
<blockquote><p>
&#8220;AsProject automates a variety of tasks including the creation of projects, classes, test cases, test suites, and swfmill libraries. It automates the download, installation and configuration of the debug flash player and many open source tools. AsProject also includes sophisticated build tools written in rake to automate build processes.&#8221;
</p></blockquote>
<p><a href="http://www.asserttrue.com/articles/2007/04/04/introducing-asproject">Video demo</a> or <a href="http://code.google.com/p/asproject/">Project page</a></p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">gem install asproject</pre>
</td>
</tr>
</table>
<p>Also, a friend <a href="http://www.justsuppose.com/">Corey</a> pointed out that you can debug flash using Actionscript ExternalInterface to log to Firebug console.log instead of using ASUnit&#8217;s debug console. In your actionscript: </p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"> ExternalInterface.call(&quot;console.log&quot;, &quot;FLASH: &quot; + s);</pre>
</td>
</tr>
</table>
<p>And make sure to allowScriptAccess.</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">var so = new SWFObject(&quot;flash/xxx.swf&quot;, &quot;myswf&quot;, &quot;680&quot;, &quot;200&quot;, &quot;8&quot;, &quot;#FFFFFF&quot;);<tt>
</tt> so.addParam(&quot;allowScriptAccess&quot;, &quot;always&quot;);<tt>
</tt> so.write(&quot;xxx&quot;);</pre>
</td>
</tr>
</table>
<p>And you could call any javascript from it. <a href="http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00002200.html">ExternalInterface </a> is a replacement for fscommand. I don&#8217;t remember but I don&#8217;t think ExternalInterface works in all browsers.</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/04/12/asproject-and-flash-debugging-to-firebug-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript IE PNG fix</title>
		<link>http://rel.me/2007/02/26/javascript-png-fix-for-ie/</link>
		<comments>http://rel.me/2007/02/26/javascript-png-fix-for-ie/#comments</comments>
		<pubDate>Mon, 26 Feb 2007 02:33:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[greader]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[reader]]></category>

		<guid isPermaLink="false">/2007/09/03/javascript-png-fix-for-ie</guid>
		<description><![CDATA[I adapted the pngfix.js to be rails friendly. Not that I should be using image tags anyway. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 var arVersion = navigator.appVersion.split(&#34;MSIE&#34;); var version = parseFloat(arVersion[1]); if ((version &#62;= 5.5) &#38;&#38; (document.body.filters)) { var [...]]]></description>
			<content:encoded><![CDATA[<p>I adapted the <a href="http://homepage.ntlworld.com/bobosola/pnghowto.htm">pngfix.js</a> to be rails friendly. Not that I should be using image tags anyway.</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt>15<tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt>22<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">var arVersion = navigator.appVersion.split(&quot;MSIE&quot;);<tt>
</tt>var version = parseFloat(arVersion[1]);<tt>
</tt><tt>
</tt>if ((version &gt;= 5.5) &amp;&amp; (document.body.filters)) {        <tt>
</tt>  var i;<tt>
</tt>  var length = document.images.length;<tt>
</tt>    for(i = 0; i &lt; length; i++) {<tt>
</tt>      var img = document.images[i];<tt>
</tt>      var re = /\w+\.[Pp][Nn][Gg]\w*/;<tt>
</tt>      if (img &amp;&amp; re.exec(img.src)) {<tt>
</tt>        var imgTitle = img.title ? &quot;title='&quot; + img.title + &quot;' &quot; : &quot;title='&quot; + img.alt + &quot;' &quot;;<tt>
</tt>        imgStyle = img.parentElement.href ? &quot;cursor:pointer;&quot; : &quot;&quot;;<tt>
</tt>        imgStyle += &quot;width:&quot; + img.width + &quot;px; height:&quot; + img.height + &quot;px;&quot;;<tt>
</tt>        imgStyle += &quot;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (src=\'&quot; + img.src + &quot;\', sizingMethod='scale');&quot;;<tt>
</tt>                <tt>
</tt>        var strNewHTML = &quot;&amp;lt;span &quot; + imgTitle + &quot; style=\&quot;display:inline-block; &quot; + imgStyle + &quot; \&quot;&gt;&lt;/span&gt;&quot;;<tt>
</tt><tt>
</tt>        img.outerHTML = strNewHTML;<tt>
</tt>        i = i - 1;<tt>
</tt>    }<tt>
</tt>  }<tt>
</tt>}</pre>
</td>
</tr>
</table>
<p><a href="http://dclicio.us/javascripts/pngfix.js">download</a></p>
<p>Then add this somewhere in your &lt;head&gt;</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&lt;!--[if lt IE 7]&gt;<tt>
</tt>&lt;script defer type=&quot;text/javascript&quot; src=&quot;/javascripts/pngfix.js&quot;&gt;&lt;/script&gt;<tt>
</tt>&lt;![endif]--&gt;</pre>
</td>
</tr>
</table>
<p>The only other requirement is you specify a width and height on your image_tags</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&lt;<span class="s"><span class="dl">%=</span><span class="k"> image_tag(&quot;fam/date.png&quot;, :alt </span><span class="dl">=</span></span>&gt; <span class="s"><span class="dl">&quot;</span><span class="k">ical</span><span class="dl">&quot;</span></span>, <span class="sy">:width</span> =&gt; <span class="s"><span class="dl">&quot;</span><span class="k">16px</span><span class="dl">&quot;</span></span>, <span class="sy">:height</span> =&gt; <span class="s"><span class="dl">&quot;</span><span class="k">16px</span><span class="dl">&quot;</span></span>) %&gt;</pre>
</td>
</tr>
</table>
<p>Though you should use CSS for most images, this is a fast way to make your png&#8217;s work in IE6.</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/02/26/javascript-png-fix-for-ie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
