<?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>Doings &#187; javascript</title>
	<atom:link href="http://do-boy.com/doings/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://do-boy.com/doings</link>
	<description>What a do-boy does</description>
	<lastBuildDate>Thu, 12 Aug 2010 16:20:51 +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>console.log(&#8216;Blues&#8217;)</title>
		<link>http://do-boy.com/doings/2010/08/11/console-logblues/</link>
		<comments>http://do-boy.com/doings/2010/08/11/console-logblues/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 20:42:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[hack]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://do-boy.com/doings/?p=61</guid>
		<description><![CDATA[In web development, the first 90% of development time is devoted to all the other browsers, and another 90% of the time is devoted to Internet Explorer. Thanks to Firebug in Firefox and Safari&#8217;s excellent developer tools, I&#8217;ve given up hideous &#8220;alert-debugging&#8221; in favor of logging informative messages to the console with console.log('a message'). You [...]]]></description>
			<content:encoded><![CDATA[<p>In web development, the first 90% of development time is devoted to all the other browsers, and another 90% of the time is devoted to Internet Explorer. Thanks to Firebug in Firefox and Safari&#8217;s excellent developer tools, I&#8217;ve given up hideous &#8220;alert-debugging&#8221; in favor of logging informative messages to the console with <code>console.log('a message')</code>. You can even get a little fancy with printf-style formatted output, e.g., <code>console.log("var i: %s",i)</code>.</p>
<p>But then development moves to IE, and I get bitten by the forgotten <code>console.log()</code> left in the code somewhere. Presumably, IE9 will have some kind of console, but we&#8217;ll be testing back to IE6 for years, so this is a problem that&#8217;s not going away.</p>
<p>I&#8217;ve seen a lot of &#8220;solutions&#8221; that create new jQuery functions&#8211;and we&#8217;re all using jQuery now anyway, right?&#8211;<a href="http://www.dotnetcurry.com/(S(z223yvqreld2o355huosr145))/ShowArticle.aspx?ID=425">like <code>$.log()</code></a> and then you&#8217;re supposed to stop using <code>console.log()</code> in favor of this new function.</p>
<p>But I&#8217;m a stubborn old man, and my arthritic old fingers won&#8217;t soon forget the keystrokes, so I find this approach a little unworkable. What I really want is to leave <code>console.log()</code> alone if it&#8217;s available, and if not, drop a DIV into the page to send output to. So I used the code from the above link as a point of departure, and worked it into something that does what I want:</p>
<p><code><br />
jQuery.extend({<br />
    log: function(msg) {<br />
        $("body").append("&lt;div style=\"width:600px;color:#fff;background-color:#666;\"&gt;" + msg + "&lt;/div&gt;");<br />
        return true;<br />
    }<br />
});</p>
<p>// create object and define method if not present<br />
if ( !window.console )<br />
{<br />
    window.console = new Object;<br />
    window.console.log = $.log;<br />
}</code></p>
<p>The strategy is, define a jQuery function <code>$.log()</code> (or <code>jQuery.log()</code> if you prefer) and then assign it to <code>console.log()</code> if it doesn&#8217;t already exist. The last block is the key: create an object <code>window.console</code> and assign $.log to a method in the object.</p>
<p>Now I can continue leaving <code>console.log()</code> in my code to debug. If window.console exists, <code>$.log()</code> is defined but never used; if window.console does not exist, it is created and passed $.log and uses that.</p>
<p>Now I just have to remember to include a file debug.js which contains this mess, but to me that&#8217;s easier than learning a whole new function which also requires the extra code to define it anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://do-boy.com/doings/2010/08/11/console-logblues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Form Field Backgrounds</title>
		<link>http://do-boy.com/doings/2008/08/11/form-field-backgrounds/</link>
		<comments>http://do-boy.com/doings/2008/08/11/form-field-backgrounds/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 03:47:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[hack]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://do-boy.com/doings/?p=8</guid>
		<description><![CDATA[At the Day Job I was called upon to make form fields with rounded corners. There&#8217;s a lot of approaches out there, but most of them are a bit too complex for my liking. Generally, it&#8217;s some variation on the old-tymey technique of putting something in the center of a 3&#215;3 table, but with DIVs [...]]]></description>
			<content:encoded><![CDATA[<p>At the Day Job I was called upon to make form fields with rounded corners. There&#8217;s a lot of approaches out there, but most of them are a bit too complex for my liking. Generally, it&#8217;s some variation on the old-tymey technique of putting something in the center of a 3&#215;3 table, but with DIVs or what-have-you.</p>
<p>Forget that, I want something simple, just a bit of CSS I can tack onto text input objects. The simple approach seemed to work:</p>
<pre>input{</pre>
<pre>   width: 90px;</pre>
<pre>   height: 26px;</pre>
<pre>   background: url(/images/text-field.png)</pre>
<pre>     no-repeat;</pre>
<pre>}</pre>
<p>…at first. It turns out Internet Explorer anchors the background image to the text field, and if you type beyond the border, the image scrolls off to the left as you type.</p>
<p>Well, that&#8217;s okay, you can just anchor the background with &#8220;background-attachment: fixed;&#8221; like so:</p>
<pre>input{</pre>
<pre>   width: 90px;</pre>
<pre>   height: 26px;</pre>
<pre>   background: url(/images/text-field.png)</pre>
<pre>     fixed no-repeat;</pre>
<pre>}</pre>
<p>Ah, but there&#8217;s a slight problem now: Firefox and Safari respond to this new attribute by not showing the background image at all. I have to say, and this could be a first for me, my opinion is that IE gets this one right. Scrolling makes sense, and a &#8220;fixed&#8221; background is the right solution.</p>
<p>But such is the life of a web developer, making things work the way they are, not the way they ought to be. So, alas, I left the &#8220;fixed&#8221; attribute out of the CSS&#8211;works for Safari and Firefox&#8211;and used jQuery&#8217;s &#8220;document ready&#8221; function for IE:</p>
<pre>$(document).ready(function(){</pre>
<pre>if ( $.browser.msie )</pre>
<pre>    $('input').css('background-attachment','fixed');</pre>
<pre>});</pre>
<p>It&#8217;s a little weak, I know, but sometimes quick and dirty is the best solution. Besides, without JavaScript, the rest of the site will fail much worse than this form field.</p>
]]></content:encoded>
			<wfw:commentRss>http://do-boy.com/doings/2008/08/11/form-field-backgrounds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
