<?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>Eric Wendelin&#039;s Blog &#187; Javascript</title>
	<atom:link href="http://eriwen.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://eriwen.com</link>
	<description>Programming productively with open-source tools</description>
	<lastBuildDate>Thu, 26 Apr 2012 18:48:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Continuation-passing and tail call elimination in Javascript</title>
		<link>http://eriwen.com/javascript/cps-tail-call-elimination/</link>
		<comments>http://eriwen.com/javascript/cps-tail-call-elimination/#comments</comments>
		<pubDate>Tue, 02 Nov 2010 08:00:44 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://eriwen.com/?p=1199</guid>
		<description><![CDATA[I've been spending a lot of time recently tinkering with different constructs and methodologies in Javascript, and one of the most fascinating things I've come across is <a href="http://spencertipping.com/blog/" title="Spencer Tipping's Blog">Spencer Tipping</a>'s use of continuation-passing style. 

It's ok if you aren't familiar with <abbr title="Continuation-Passing Style">CPS</abbr>, but I think anyone hoping to make the cognitive leap to <a href="http://en.wikipedia.org/wiki/Functional_programming">functional programming</a> should study it. As a bare miniumum, you need to know that a continuation is:

<blockquote>[a reification of] an instance of a computational process at a given point in the process's execution</blockquote>
 <a href="http://eriwen.com/javascript/cps-tail-call-elimination/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/javascript/js-stack-trace/' rel='bookmark' title='A Javascript stacktrace in any browser'>A Javascript stacktrace in any browser</a></li>
<li><a href='http://eriwen.com/javascript/measure-ems-for-layout/' rel='bookmark' title='Javascript: Measure those &#8220;em&#8221;s for your layout'>Javascript: Measure those &#8220;em&#8221;s for your layout</a></li>
<li><a href='http://eriwen.com/javascript/highlight-search-results-with-js/' rel='bookmark' title='How to highlight search results with JavaScript and CSS'>How to highlight search results with JavaScript and CSS</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been spending a lot of time recently tinkering with different constructs and methodologies in Javascript, and one of the most fascinating things I&#8217;ve come across is <a href="http://spencertipping.com/blog/" title="Spencer Tipping's Blog">Spencer Tipping</a>&#8216;s use of continuation-passing style. </p>
<p>It&#8217;s ok if you aren&#8217;t familiar with <abbr title="Continuation-Passing Style">CPS</abbr>, but I think anyone hoping to make the cognitive leap to <a href="http://en.wikipedia.org/wiki/Functional_programming">functional programming</a> should study it. As a bare miniumum, you need to know that a continuation is:</p>
<blockquote><p>[a reification of] an instance of a computational process at a given point in the process&#8217;s execution</p></blockquote>
<p>Therefore, <a href="http://en.wikipedia.org/wiki/Continuation-passing_style">continuation-passing style</a> is just:</p>
<blockquote><p>a <strong>style of programming</strong> in which control is passed explicitly in the form of a continuation</p></blockquote>
<p class="update"><strong>NOTE:</strong> I have replaced my crappy examples just below with <a href="http://eriwen.com/javascript/cps-tail-call-elimination/#comment-7110">Outis&#8217;s much more reasonable (and correct) ones</a>. I take no credit for the simple CPS code below. Thank you Outis and David for the suggestions.</p>
<p>Consider the naive implementation of the recursive fibonacci function:</p>
<pre class="brush: jscript; title: Recursive fibonacci function; notranslate">
function fib(n) {
    if (n &lt; 1) {
        return 1;
    } else {
        return fib(n-2) + fib(n-1);
    }
}
</pre>
<p>Then, identify function calls and returns. For each such point, create a continuation and pass it to the function call or return it. For example, the continuation for <code>fibr(n-1) + fibr(n-2)</code> is:</p>
<pre class="brush: jscript; light: true; title: continuation for recursive fibonacci; notranslate">
function(x) {
    return x + fib(n-2);
}
</pre>
<p>and you get:</p>
<pre class="brush: jscript; title: Applying continuation passing to fibonacci; notranslate">
function cpsFib(n, _return) {
    if (n &lt;= 1) {
        return _return(1);
    } else {
        return cpsFib(n-2, function(a) {
            return cpsFib(n-1, function(b) {
                return _return(a+b);
            });
        });
    }
}
</pre>
<p>Apply this process to the linear recursive fibonacci function and you get:</p>
<pre class="brush: jscript; highlight: [9]; title: ; notranslate">
function cpsFib(n, prev, cur, _return) {
    // Key component: call escape function when done
    if (n &lt; 2) {
        return _return(cur);
    }
    return cpsFib(--n, cur, cur + prev, _return);
}
// Note the use of an identity function here
cpsFib(1000, 0, 1, function(x) {return x});
</pre>
<p>The only problem with this, however, is that <strong>Javascript engines to not optimize tail recursion</strong>, so calling: <em>fibonacci_cps(10000)</em> would cause a <em>StackOverflowError</em> in some browsers. </p>
<pre class="brush: jscript; light: true; title: StackOverflow!; notranslate">
function() {
	return [1000, 0, 1,
		function() { return [999, 1, 1,
			function() { return [998, 1, 2,
				... ]]
			}
		}
	];
}
</pre>
<p>However, by adding to Function.prototype and changing the way we pass continuations, <strong>we can fix this problem.</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// Function prototypes heavily inspired by Spencer Tipping's js-in-ten-minutes:
//   http://github.com/spencertipping/js-in-ten-minutes
Function.prototype.tail = function() {
	return [this, arguments];
}
// Tail-call optimization
Function.prototype.tco = function() {
	var continuation = [this, arguments];
	var escapeFn = arguments[arguments.length - 1];
	while (continuation[0] !== escapeFn) {
		continuation = continuation[0].apply(this, continuation[1]);
	}
	return escapeFn.apply(this, continuation[1]);
}

// Note the use of &quot;Function.prototype.tail()&quot;
function cpsFib(n, prev, cur, escapeFn) {
	if (n &lt; 2) {
		return escapeFn.tail(cur);
	}
	return cpsFib.tail(--n, cur, cur + prev, escapeFn);
}

function identity(x) {return x}

// We pass the escape function instead of a reference to cpsFib
cpsFib.tco(1000, 0, 1, identity);
</pre>
<pre class="brush: jscript; light: true; title: Tail-call optimized; notranslate">
// within while (continuation[0] !== escapeFn) {
[cpsFib, [1000, 0, 1, identity]]
[cpsFib, [999, 1, 1, identity]]
[cpsFib, [998, 1, 2, identity]]
[cpsFib, [3, 2.686e+208, 4.3467e+208, identity]]

// return escapeFn.apply(this, continuation[1]);
[identity, 4.34673e+208]
</pre>
<h2>How CPS and TCO can be practical</h2>
<p>All this talk about styles and optimizations can sound rather like &#8220;over-engineering&#8221; to those of us who aren&#8217;t familiar with these concepts. While it&#8217;s a risk, good engineers will know when it is effective. Here&#8217;s how I would recommend you use these concepts:</p>
<ol>
<li>Processing large structures in a recursive way, perhaps recursing through an Object or HTML tree of indeterminate depth</li>
<li>You&#8217;re adding functional methods to iterable objects (adding Array.prototype.map())</li>
<li>Practicing uses of functional programming with Javascript</li>
</ol>
<h2>Conclusion</h2>
<p>Knowing how to use functional techniques in Javascript will be more valuable as it moves to the server-side (due to the rising popularity of <a href="http://nodejs.org/">node.js</a>) because doing more actual computation will be acceptable instead of blocking a <abbr title="User Interface">UI</abbr>. </p>
<p>I learned a lot from Spencer&#8217;s write-up <a href="http://github.com/spencertipping/js-in-ten-minutes">Javascript in Ten Minutes</a>, and would recommend you check it out. I&#8217;ve also found reading <a href="http://github.com/spencertipping">his other Javascript code</a> and comments very insightful.</p>
<p>Please share other uses of functional Javascript you&#8217;ve come across.</p>


<p>Related posts:<ol><li><a href='http://eriwen.com/javascript/js-stack-trace/' rel='bookmark' title='A Javascript stacktrace in any browser'>A Javascript stacktrace in any browser</a></li>
<li><a href='http://eriwen.com/javascript/measure-ems-for-layout/' rel='bookmark' title='Javascript: Measure those &#8220;em&#8221;s for your layout'>Javascript: Measure those &#8220;em&#8221;s for your layout</a></li>
<li><a href='http://eriwen.com/javascript/highlight-search-results-with-js/' rel='bookmark' title='How to highlight search results with JavaScript and CSS'>How to highlight search results with JavaScript and CSS</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/javascript/cps-tail-call-elimination/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Javascript Stacktrace update</title>
		<link>http://eriwen.com/javascript/stacktrace-update/</link>
		<comments>http://eriwen.com/javascript/stacktrace-update/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 11:00:10 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://eriwen.com/?p=1050</guid>
		<description><![CDATA[I started a <a href="http://eriwen.com/javascript/js-stack-trace/" title="A Javascript stacktrace in any browser">Javascript Stacktrace project</a> back in August 2008. The idea was to give additional debugging power to browsers where you don't have good tools to work with. I'd like to give you an update on where the project is today.

Lately, I've been working on updating my old script. Since it was written, we've seen lots of major browser releases and the introduction of the V8 Javascript engine used by <a href="http://www.google.com/chrome">Google Chrome</a>.

<h2>Updated browser compatibility</h2>
Browsers that are fully-supported and well-tested:
<ol>
<li>Firefox (and Iceweasel) 0.9+</li>
<li>Safari 3+</li>
<li>IE 5.5+</li>
<li>Konqueror 3.5+</li>
<li>K-Meleon 1.5.3+</li>
<li>Epiphany 2.28.0+</li>
</ol>

Browsers that are supported in almost all cases but not as well-tested:
<ol>
<li>Chrome 1+ - One bug (feature?) that may be in Chrome reporting functions as anonymous when they aren't. HOWEVER, Chrome's stack gives us line numbers AND column numbers, so we can see exactly where our problem is - even in minified Javascript! Sweet!</li>
<li>Opera 9+ - Opera is dead to me now. Opera 10+ has removed the error.stack info we needed and introduced error.stacktrace, but it seems very unstable.</li>
</ol>

More info about compatibility can be shown with the <a href="http://browsershots.org/http://eriwen.com/js/javascript-stacktrace/test-stacktrace.html" title="BrowserShots site testing">BrowserShots of the test suite</a>. 
 <a href="http://eriwen.com/javascript/stacktrace-update/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/javascript/js-stack-trace/' rel='bookmark' title='A Javascript stacktrace in any browser'>A Javascript stacktrace in any browser</a></li>
<li><a href='http://eriwen.com/python/update-feedburner-count/' rel='bookmark' title='Using Python to update your FeedBurner stats'>Using Python to update your FeedBurner stats</a></li>
<li><a href='http://eriwen.com/javascript/cps-tail-call-elimination/' rel='bookmark' title='Continuation-passing and tail call elimination in Javascript'>Continuation-passing and tail call elimination in Javascript</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I started a <a href="http://eriwen.com/javascript/js-stack-trace/" title="A Javascript stacktrace in any browser">Javascript Stacktrace project</a> back in August 2008. The idea was to give additional debugging power to browsers where you don&#8217;t have good tools to work with. I&#8217;d like to give you an update on where the project is today.</p>
<p>Lately, I&#8217;ve been working on updating my old script. Since it was written, we&#8217;ve seen lots of major browser releases and the introduction of the V8 Javascript engine used by <a href="http://www.google.com/chrome">Google Chrome</a>.</p>
<h2>Updated browser compatibility</h2>
<p>Browsers that are fully-supported and well-tested:</p>
<ol>
<li>Firefox (and Iceweasel) 0.9+</li>
<li>UPDATE: Chrome 1+ now perfectly supported</li>
<li>Safari 3+</li>
<li>IE 5.5+</li>
<li>Opera 9+</li>
<li>Konqueror 3.5+</li>
<li>K-Meleon 1.5.3+</li>
<li>Epiphany 2.28.0+</li>
</ol>
<p>Browsers that are supported in almost all cases but not as well-tested:</p>
<ol>
<li><span style="text-decoration: line-through;">Chrome 1+ &#8211; One bug (feature?) that may be in Chrome reporting functions as anonymous when they aren&#8217;t. HOWEVER, Chrome&#8217;s stack gives us line numbers AND column numbers, so we can see exactly where our problem is &#8211; even in minified Javascript! Sweet!</span> Chrome 1+ now fully supported.</li>
<li>Opera 7-8 &#8211; Opera is dead to me now. Opera 10+ has removed the error.stack info we needed and introduced error.stacktrace, but it seems very unstable. Argh.</li>
</ol>
<p>More info about compatibility can be shown with the <a href="http://browsershots.org/http://eriwen.com/js/javascript-stacktrace/test-stacktrace.html" title="BrowserShots site testing">BrowserShots of the test suite</a>. </p>
<h2>Now socially coded</h2>
<p>I&#8217;m not going to post the code here because the source and tests are now on the <a href="https://github.com/eriwen/javascript-stacktrace">javascript-stacktrace project on GitHub</a>. You can download it <a href="https://github.com/eriwen/javascript-stacktrace/downloads" title="Javascript Stacktrace downloads">here</a>.</p>
<p>Follow it, file bugs, and make comments there. If you have improvements to make, please fork the project and then contact me or do a &#8220;push request&#8221;. I&#8217;ll make sure you get credit ;)</p>
<p class="update">UPDATE: <a href="http://kinsey.no/blog" title="rantings in the dark">Øyvind Sean Kinsey</a> has added memoization (caching the implementation) for the mode and XHR bits as well as the ability to pass an <strong>existing Javascript Error</strong> and get a stacktrace.  We&#8217;re working on tests and you should see project updates soon. Thanks, Øyvind!</p>
<pre class="brush: jscript; light: true; title: ; notranslate">
var lastError;
try {
    // error producing code
} catch(e) {
   lastError = e;
   // do something else with error
}

// later...
printStackTrace({e: lastError}); //Returns stacktrace from lastError!
</pre>
<h2>Try it out!</h2>
<p>The code is in use on my blog. <a href="javascript:foo();">Click here</a> to give it a spin. </p>
<pre class="brush: jscript; light: true; title: ; notranslate">
function foo() {
    var blah;
    bar(&quot;blah&quot;);
}

function bar(blah) {
    var stuff;
    thing();
}

function thing() {
    if (true) { //your error condition here
        var st = printStackTrace();
        alert(st.join(&quot;\n\n&quot;));
    }
}

foo();
</pre>
<p>Random note: one cool suggestion I saw was to assign printStackTrace to window.onerror. Pretty brilliant if you ask me. </p>
<p>I want to thank the guys who contributed to the script: <strong><a href="http://lucassmith.name">Luke Smith</a>, Loic Dachary and Johan Euphrosine.</strong></p>
<p>I could use a bit of help getting the Chrome and Opera bugs worked out. I&#8217;m sure some of you guys who remember how to write software can help. Suggestions and whinings are welcome as long as they don&#8217;t get out of hand in the comments.</p>
<p><a href="https://github.com/eriwen/javascript-stacktrace">stacktrace.js on GitHub</a></p>


<p>Related posts:<ol><li><a href='http://eriwen.com/javascript/js-stack-trace/' rel='bookmark' title='A Javascript stacktrace in any browser'>A Javascript stacktrace in any browser</a></li>
<li><a href='http://eriwen.com/python/update-feedburner-count/' rel='bookmark' title='Using Python to update your FeedBurner stats'>Using Python to update your FeedBurner stats</a></li>
<li><a href='http://eriwen.com/javascript/cps-tail-call-elimination/' rel='bookmark' title='Continuation-passing and tail call elimination in Javascript'>Continuation-passing and tail call elimination in Javascript</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/javascript/stacktrace-update/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>A Javascript stacktrace in any browser</title>
		<link>http://eriwen.com/javascript/js-stack-trace/</link>
		<comments>http://eriwen.com/javascript/js-stack-trace/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 12:00:58 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://eriwen.com/?p=71</guid>
		<description><![CDATA[<p class="update">UPDATE: You'll want to check out the <a href="http://eriwen.com/javascript/stacktrace-update/" title="Javascript Stacktrace update">updated post</a> with new code, tests, and compatibility.</p>

Chances are that if you've done any significant Javascript work, you've run into a situation where part of the debugging process could be much improved if you just had the function call stack.

I'm going to give you some ways of doing this with and without the popular <a href="http://getfirebug.com" title="UI debugging">Firebug</a> extension and have some examples of their uses.

<h2>Without Firebug and friends? Using IE?</h2>

Sometimes s**t only happens in other browsers. Here's how to create/log your own stack trace. Put this code in an accessible place in your Javascript file(s) and call the <em>printStackTrace()</em> function inside any function. 

I'm going to give you some ways of doing this with and without the popular <a href="http://getfirebug.com" title="UI debugging">Firebug</a> extension and have some examples of their uses.

<h2>Without Firebug and friends? Using IE?</h2>

Sometimes s**t only happens in other browsers. Here's how to create/log your own stack trace. Put this code in an accessible place in your Javascript file(s) and call the <em>printStackTrace()</em> function inside any function. <a href="http://eriwen.com/javascript/js-stack-trace/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/javascript/stacktrace-update/' rel='bookmark' title='Javascript Stacktrace update'>Javascript Stacktrace update</a></li>
<li><a href='http://eriwen.com/javascript/measure-ems-for-layout/' rel='bookmark' title='Javascript: Measure those &#8220;em&#8221;s for your layout'>Javascript: Measure those &#8220;em&#8221;s for your layout</a></li>
<li><a href='http://eriwen.com/javascript/cps-tail-call-elimination/' rel='bookmark' title='Continuation-passing and tail call elimination in Javascript'>Continuation-passing and tail call elimination in Javascript</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p class="update"><strong>UPDATE:</strong> This is now a mature <a href="http://git.io/stacktracejs">project on GitHub</a>! Please submit comments/issues there. <iframe src="http://markdotto.github.com/github-buttons/github-btn.html?user=eriwen&#038;repo=javascript-stacktrace&#038;type=watch&#038;count=true" allowtransparency="true" frameborder="0" scrolling="0" width="110px" height="20px"></iframe></p>
<p>Chances are that if you&#8217;ve done any significant Javascript work, you&#8217;ve run into a situation where part of the debugging process could be much improved if you just had the function call stack.</p>
<p>I&#8217;m going to give you some ways of doing this with and without the popular <a href="http://getfirebug.com" title="UI debugging">Firebug</a> extension and have some examples of their uses.</p>
<h2>Without Firebug and friends? Using IE?</h2>
<p>Sometimes s**t only happens in other browsers. Here&#8217;s how to create/log your own stack trace. Put this code in an accessible place in your Javascript file(s) and call the <em>printStackTrace()</em> function inside any function. </p>
<pre class="brush: jscript; title: ; wrap-lines: false; notranslate">
function printStackTrace() {
  var callstack = [];
  var isCallstackPopulated = false;
  try {
    i.dont.exist+=0; //doesn't exist- that's the point
  } catch(e) {
    if (e.stack) { //Firefox
      var lines = e.stack.split('\n');
      for (var i=0, len=lines.length; i&amp;lt;len; i++) {
        if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
          callstack.push(lines[i]);
        }
      }
      //Remove call to printStackTrace()
      callstack.shift();
      isCallstackPopulated = true;
    }
    else if (window.opera &amp;amp;&amp;amp; e.message) { //Opera
      var lines = e.message.split('\n');
      for (var i=0, len=lines.length; i&amp;lt;len; i++) {
        if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
          var entry = lines[i];
          //Append next line also since it has the file info
          if (lines[i+1]) {
            entry += ' at ' + lines[i+1];
            i++;
          }
          callstack.push(entry);
        }
      }
      //Remove call to printStackTrace()
      callstack.shift();
      isCallstackPopulated = true;
    }
  }
  if (!isCallstackPopulated) { //IE and Safari
    var currentFunction = arguments.callee.caller;
    while (currentFunction) {
      var fn = currentFunction.toString();
      var fname = fn.substring(fn.indexOf(&amp;amp;quot;function&amp;amp;quot;) + 8, fn.indexOf('')) || 'anonymous';
      callstack.push(fname);
      currentFunction = currentFunction.caller;
    }
  }
  output(callstack);
}

function output(arr) {
  //Optput however you want
  alert(arr.join('\n\n'));
}
</pre>
<p class="update"><strong>UPDATE:</strong> A few others have taken and upgraded the script with a bunch of new features. Their changes and mine are now <a href="http://github.com/eriwen/javascript-stacktrace">on GitHub</a>. Contribute!</p>
<p>It&#8217;s ugly, but this works for the latest versions of IE, Firefox, Opera, and Safari. Firefox and Opera give you file names and line numbers when they can, but I couldn&#8217;t find a mechanism to get the same from IE and Opera. Hopefully the inline comments describe enough of what is going on. If not, ask :). </p>
<h2>Try it out</h2>
<p>Give it a shot by <a href="javascript:foo();">clicking here</a>. It will run the snippet below.</p>
<pre class="brush: jscript; light: true; title: ; notranslate">
function foo() {
    var blah;
    bar('blah');
}

function bar(blah) {
    // some code
    thing();
}

function thing() {
    if (true) { //your error condition here
        printStackTrace();
    }
}

foo();
</pre>
<h2>Obvious easy way: Firebug (and Drosera and Dragonfly)</h2>
<p>You can easily get a stack trace at any time by calling <code>console.trace()</code> in your Javascript or in the Firebug console.<br />
<blockquote>Not only will it tell you which functions are on the stack, but it will include the value of each argument that was passed to each function.</p></blockquote>
<p> This is obviously the best way to go if you are using <a href="http://getfirefox.com" title="Firefox web browser">Firefox</a>. </p>
<p>Furthermore, these tools allow you to dig deeper. Of course, we can&#8217;t count on them for ALL situations. </p>
<h2>Conclusion</h2>
<p>I hope you find this useful. If you have any suggestions/improvements I&#8217;d like to hear them! Also all kidding aside, I worked pretty hard on this function, so I&#8217;d really appreciate if you&#8217;d help me share this with more people. Thanks!</p>


<p>Related posts:<ol><li><a href='http://eriwen.com/javascript/stacktrace-update/' rel='bookmark' title='Javascript Stacktrace update'>Javascript Stacktrace update</a></li>
<li><a href='http://eriwen.com/javascript/measure-ems-for-layout/' rel='bookmark' title='Javascript: Measure those &#8220;em&#8221;s for your layout'>Javascript: Measure those &#8220;em&#8221;s for your layout</a></li>
<li><a href='http://eriwen.com/javascript/cps-tail-call-elimination/' rel='bookmark' title='Continuation-passing and tail call elimination in Javascript'>Continuation-passing and tail call elimination in Javascript</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/javascript/js-stack-trace/feed/</wfw:commentRss>
		<slash:comments>65</slash:comments>
		</item>
		<item>
		<title>Create a Color Palette Using CSS and MooTools 1.2</title>
		<link>http://eriwen.com/css/color-palette-with-css-and-moo/</link>
		<comments>http://eriwen.com/css/color-palette-with-css-and-moo/#comments</comments>
		<pubDate>Thu, 15 May 2008 07:00:54 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Guest]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://eriwen.com/?p=50</guid>
		<description><![CDATA[<p class="update">This entry was authored by highly-respected blogger and friend <a href="http://davidwalsh.name" target="_blank">David Walsh</a>. <a href="http://eriwen.com/css/color-palette-with-css-and-moo/#bio-david">Learn more about David</a></p>
<p>As you can see from my site's <span style="text-decoration: line-through;">lack of</span> design (<a href="http://davidwalsh.name/" target="_blank">davidwalsh.name</a>), I'm about 90% programmer and 10% designer.  As someone that's not a designer, I'm really grateful for websites like <a href="http://www.colourlovers.com/" target="_blank">ColourLovers</a> -- websites that provide you palettes of colors that look good together.  Let's pretend for a moment that I do have a good design and I want others to know my palette.  MooTools 1.2 has made that a reality.</p>
<p><a href="http://davidwalsh.name/dw-content/color-palette.php" target="_blank"><img src="http://davidwalsh.name/dw-content/palette.jpg" alt="" /></a></p> <a href="http://eriwen.com/css/color-palette-with-css-and-moo/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/javascript/text-size-prefs/' rel='bookmark' title='Guest Post: Save Text Size Preference Using MooTools and PHP'>Guest Post: Save Text Size Preference Using MooTools and PHP</a></li>
<li><a href='http://eriwen.com/css/css-indirect-adjacent-combinator/' rel='bookmark' title='About the indirect adjacent combinator (~) in CSS'>About the indirect adjacent combinator (~) in CSS</a></li>
<li><a href='http://eriwen.com/css/speech-bubble/' rel='bookmark' title='A CSS-only speech bubble'>A CSS-only speech bubble</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p class="update">This entry was authored by highly-respected blogger and friend <a href="http://davidwalsh.name" target="_blank">David Walsh</a>. <a href="http://eriwen.com/css/color-palette-with-css-and-moo/#bio-david">Learn more about David</a></p>
<p>As you can see from my site&#8217;s <span style="text-decoration: line-through;">lack of</span> design (<a href="http://davidwalsh.name/" target="_blank">davidwalsh.name</a>), I&#8217;m about 90% programmer and 10% designer.  As someone that&#8217;s not a designer, I&#8217;m really grateful for websites like <a href="http://www.colourlovers.com/" target="_blank">ColourLovers</a> &#8212; websites that provide you palettes of colors that look good together.  Let&#8217;s pretend for a moment that I do have a good design and I want others to know my palette.  MooTools 1.2 has made that a reality.</p>
<p><a href="http://davidwalsh.name/dw-content/color-palette.php" target="_blank"><img src="http://davidwalsh.name/dw-content/palette.jpg" alt="" /></a></p>
<h2>Step 1: The XHTML</h2>
<pre class="brush: xml; title: ; notranslate">
&lt;input type=&quot;button&quot; id=&quot;get-colors&quot; value=&quot;Get Colors&quot; class=&quot;button&quot; /&gt;
&lt;div id=&quot;colors-wrapper&quot;&gt;&lt;/div&gt;
</pre>
<p>I&#8217;ve created two elements to begin with:  a DIV that will serve as a wrapper for the color palette and a button that will trigger the color palette&#8217;s creation.</p>
<h2>Step 2: The CSS</h2>
<pre class="brush: css; title: ; notranslate">
.dcolor { height:40px; }
.dtext {  }
.dwrapper { width:100px; float:left; padding:10px; margin:0 20px 20px 0; border:1px solid #ccc; }
</pre>
<p>The above CSS simply formats the elements that are needed to create the palette.</p>
<h2>Step 3: The Moo 1.2 Javascript</h2>
<pre class="brush: jscript; title: ; notranslate">
//once the dom is ready
window.addEvent('domready', function() {

	//do it!
	$('get-colors').addEvent('click', function() {
		//starting the colors array
		var colors = [];
		var disallows = ['transparent'];

		//for every element
		$$('*').each(function(el) {
			//record colors!
			colors.include(el.getStyle('color'));
			colors.include(el.getStyle('background-color'));
			el.getStyle('border-color').split(' ').each(function(c) {
				colors.include(c);
			});
		});

		//sort the colors
		colors.sort();

		//empty wrapper
		$('colors-wrapper').empty();

		//for every color...
		colors.each(function(val,i) {

			//if it's good
			if(!disallows.contains(val))
			{
				//create wrapper div
				var wrapper = new Element('div', {
					'class':'dwrapper'
				});

				//create color div, inject
				var colorer = new Element('div', {
					'class':'dcolor',
					'style': 'background:' + val
				});
				colorer.inject(wrapper);

				//alert(val);

				//create text div, inject
				var texter = new Element('div', {
					'class':'dtext',
					'text':val
				});
				texter.inject(wrapper);

				//inject wrapper
				wrapper.inject($('colors-wrapper'));
			}
		});
	});
});
</pre>
<p>Once the DOM is ready, we start listening for a click on our &#8220;Get Colors&#8221; button.  When the button is clicked, we store every element&#8217;s background color, border color, and text color.  Once we have every color in our array, we sort the array and clear the wrapper DIV.  For every color we&#8217;ve found, we create a DIV that displays the color and it&#8217;s hex value.  That&#8217;s it!</p>
<p>The result?  A sweet javascript script giving you a color palette of the current page.  <a href="http://davidwalsh.name/dw-content/color-palette.php" target="_blank">Click here to build a color palette</a> of my example page!</p>
<p><em>Note: This script doesn&#8217;t accommodate images.</em></p>
<p><a name="bio-david" /></p>
<p class="bio"><img src="http://eriwen.com/images/david-walsh.gif" alt="David Walsh" style="float: left; margin: 0px 8px 4px 0px;" /><a href="http://davidwalsh.name" target="_blank">David Walsh</a> is a Senior Web Developer residing in Madison, WI. He spends most of his day getting a monitor tan coding PHP, CSS, MooTools, and XHTML. When not tinkering with the newest version of <a href="http://mootools.net" target="_blank">Moo</a>, David uses soccer, Rock Band, and movies to dull his coding pains.</p>


<p>Related posts:<ol><li><a href='http://eriwen.com/javascript/text-size-prefs/' rel='bookmark' title='Guest Post: Save Text Size Preference Using MooTools and PHP'>Guest Post: Save Text Size Preference Using MooTools and PHP</a></li>
<li><a href='http://eriwen.com/css/css-indirect-adjacent-combinator/' rel='bookmark' title='About the indirect adjacent combinator (~) in CSS'>About the indirect adjacent combinator (~) in CSS</a></li>
<li><a href='http://eriwen.com/css/speech-bubble/' rel='bookmark' title='A CSS-only speech bubble'>A CSS-only speech bubble</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/css/color-palette-with-css-and-moo/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Guest Post: Save Text Size Preference Using MooTools and PHP</title>
		<link>http://eriwen.com/javascript/text-size-prefs/</link>
		<comments>http://eriwen.com/javascript/text-size-prefs/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 13:40:19 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://eriwen.com/?p=47</guid>
		<description><![CDATA[<p>I have posted a <a href="http://davidwalsh.name/save-text-size-preference-mootools-12">major update</a> to my <a href="http://davidwalsh.name/change-text-size-onclick-with-javascript" target="_blank">original post</a> about Changing Text Size onClick with JavaScript at the <a href="http://davidwalsh.name" target="_blank">David Walsh Blog</a>.</p>
<p>It allows you to store your users' text-size preferences in a cookie so that they don't have to resize the text to their liking on every page. <a href="http://eriwen.com/examples/save-font-size-prefs-example.php" target="_blank">Check out the demo</a> (remember to refresh the page to test the cookie!) and then check out how to<a href="http://davidwalsh.name/save-text-size-preference-mootools-12" target="_blank">Save Text Size Preference using MooTools and PHP</a>!</p> <a href="http://eriwen.com/javascript/text-size-prefs/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/javascript/change-text-size-onclick-with-javascript/' rel='bookmark' title='Guest Post: change text size onclick with JavaScript'>Guest Post: change text size onclick with JavaScript</a></li>
<li><a href='http://eriwen.com/css/color-palette-with-css-and-moo/' rel='bookmark' title='Create a Color Palette Using CSS and MooTools 1.2'>Create a Color Palette Using CSS and MooTools 1.2</a></li>
<li><a href='http://eriwen.com/firefox/firecookie/' rel='bookmark' title='Firefox extension to watch: Firecookie'>Firefox extension to watch: Firecookie</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I have posted a <a href="http://davidwalsh.name/save-text-size-preference-mootools-12">major update</a> to my <a href="http://davidwalsh.name/change-text-size-onclick-with-javascript" target="_blank">original post</a> about Changing Text Size onClick with JavaScript at the <a href="http://davidwalsh.name" target="_blank">David Walsh Blog</a>.</p>
<p>It allows you to store your users&#8217; text-size preferences in a cookie so that they don&#8217;t have to resize the text to their liking on every page. <a href="http://eriwen.com/examples/save-font-size-prefs-example.php" target="_blank">Check out the demo</a> (remember to refresh the page to test the cookie!) and then check out how to <a href="http://davidwalsh.name/save-text-size-preference-mootools-12" target="_blank">Save Text Size Preference using MooTools and PHP</a>!</p>


<p>Related posts:<ol><li><a href='http://eriwen.com/javascript/change-text-size-onclick-with-javascript/' rel='bookmark' title='Guest Post: change text size onclick with JavaScript'>Guest Post: change text size onclick with JavaScript</a></li>
<li><a href='http://eriwen.com/css/color-palette-with-css-and-moo/' rel='bookmark' title='Create a Color Palette Using CSS and MooTools 1.2'>Create a Color Palette Using CSS and MooTools 1.2</a></li>
<li><a href='http://eriwen.com/firefox/firecookie/' rel='bookmark' title='Firefox extension to watch: Firecookie'>Firefox extension to watch: Firecookie</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/javascript/text-size-prefs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript: Measure those &#8220;em&#8221;s for your layout</title>
		<link>http://eriwen.com/javascript/measure-ems-for-layout/</link>
		<comments>http://eriwen.com/javascript/measure-ems-for-layout/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 04:08:24 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://eriwen.com/javascript/measure-ems-for-layout/</guid>
		<description><![CDATA[For many of us designing fluid layouts, which are generally based in "em"s (pronounced like the letter M) you end up not really knowing how many pixels an "em" is while you are deep in the <abbr title="Document Object Model">DOM</abbr> tree. This is especially confusing if you increase/decrease text size with your browser.

For this reason, I have created a simple Javascript function that you can use to poll any element on your test page and figure out what size an "em" is.
 <a href="http://eriwen.com/javascript/measure-ems-for-layout/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/firefox/editing-layout-in-firebug/' rel='bookmark' title='Quick Tip: Editing layout in Firebug'>Quick Tip: Editing layout in Firebug</a></li>
<li><a href='http://eriwen.com/css/use-the-table-layout-css-property-to-speed-up-table-rendering/' rel='bookmark' title='Use the table-layout CSS property to speed up table rendering'>Use the table-layout CSS property to speed up table rendering</a></li>
<li><a href='http://eriwen.com/javascript/highlight-search-results-with-js/' rel='bookmark' title='How to highlight search results with JavaScript and CSS'>How to highlight search results with JavaScript and CSS</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>For many of us designing fluid layouts, which are generally based in &#8220;em&#8221;s (pronounced like the letter M) you end up not really knowing how many pixels an &#8220;em&#8221; is while you are deep in the <abbr title="Document Object Model">DOM</abbr> tree. This is especially confusing if you increase/decrease text size with your browser.</p>
<p>For this reason, I have created a simple Javascript function that you can use to poll any element on your test page and figure out what size an &#8220;em&#8221; is.</p>
<h2>The Javascript code:</h2>
<p>Old, busted way that supports Safari 2:</p>
<pre class="brush: jscript; light: true; title: ; notranslate">
function getEmSize(el) {
  // If you pass in an element ID then get a reference to the element
  if (typeof el == &quot;string&quot;) el = document.getElementById(el);

  if (el != null) {
    var tempDiv = document.createElement('div');
    tempDiv.style.height = '1em';
    el.appendChild(tempDiv);
    var emSize = tempDiv.offsetHeight;
    el.removeChild(tempDiv);
    return emSize;
  }
}
</pre>
<p>New hotness (from <a href="http://stackoverflow.com/questions/4571813/why-is-this-javascript-function-so-slow-on-firefox">David Baron&#8217;s suggestion on StackOverflow</a>):</p>
<pre class="brush: jscript; light: true; title: ; notranslate">
function getEmSize(el) {
    return Number(getComputedStyle(el, '').fontSize.match(/(\d+)px/)[1]);
}
</pre>
<h2>Explanation and Usage</h2>
<p>You can easily use this function by calling:</p>
<pre class="brush: jscript; light: true; title: ; notranslate">
    getEmSize(&quot;elementid&quot;);
    // OR
    getEmSize(elementReference);
</pre>
<p>from your navigation bar or <a href="http://getfirebug.com" target="_blank">Firebug</a> console or of course within a loop traversing your entire DOM tree (watch out for those text nodes though!).</p>
<h2>Caveats</h2>
<p>You could improve this by using a loop as I said earlier and print out a nice <abbr title="Document Object Model">DOM</abbr> tree with pixel values.</p>
<p>I know that there are some improvements to be made here so I wanna see some in the comments! What other ways do you keep track of your &#8220;em&#8221;s in a fluid layout?</p>


<p>Related posts:<ol><li><a href='http://eriwen.com/firefox/editing-layout-in-firebug/' rel='bookmark' title='Quick Tip: Editing layout in Firebug'>Quick Tip: Editing layout in Firebug</a></li>
<li><a href='http://eriwen.com/css/use-the-table-layout-css-property-to-speed-up-table-rendering/' rel='bookmark' title='Use the table-layout CSS property to speed up table rendering'>Use the table-layout CSS property to speed up table rendering</a></li>
<li><a href='http://eriwen.com/javascript/highlight-search-results-with-js/' rel='bookmark' title='How to highlight search results with JavaScript and CSS'>How to highlight search results with JavaScript and CSS</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/javascript/measure-ems-for-layout/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to highlight search results with JavaScript and CSS</title>
		<link>http://eriwen.com/javascript/highlight-search-results-with-js/</link>
		<comments>http://eriwen.com/javascript/highlight-search-results-with-js/#comments</comments>
		<pubDate>Sun, 24 Feb 2008 05:29:54 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://eriwen.com/javascript/highlight-search-results-with-js/</guid>
		<description><![CDATA[<img alt="Google highlight search text" src="http://static.eriwen.com/images/highlight_search.jpg" style="padding: 0px 0px 4px 6px; float: right;" />You see it in Google search results and a lot of other sites that have good search functionality. When you perform a search, your words or phrases are highlighted in the search results making it easy for you to find the most relevant content.

Today I'm going to show you a simple way to add this to your website or blog so your users can find what they need in style. I think that this kind of thing should be implemented more often for how easy it is to implement.

Here we go! <a href="http://eriwen.com/javascript/highlight-search-results-with-js/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/css/color-palette-with-css-and-moo/' rel='bookmark' title='Create a Color Palette Using CSS and MooTools 1.2'>Create a Color Palette Using CSS and MooTools 1.2</a></li>
<li><a href='http://eriwen.com/javascript/measure-ems-for-layout/' rel='bookmark' title='Javascript: Measure those &#8220;em&#8221;s for your layout'>Javascript: Measure those &#8220;em&#8221;s for your layout</a></li>
<li><a href='http://eriwen.com/javascript/change-text-size-onclick-with-javascript/' rel='bookmark' title='Guest Post: change text size onclick with JavaScript'>Guest Post: change text size onclick with JavaScript</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p class="update">Welcome to Eric Wendelin&#8217;s blog! You&#8217;re guaranteed to more great Javascript tutorials if you <a href="http://eriwen.com/feed/">subscribe via RSS</a>.</p>
<p><img alt="Google highlight search text" src="http://static.eriwen.com/images/highlight_search.jpg" style="margin: 0px 0px 4px 8px; float: right;" />You see it in Google search results and a lot of other sites that have good search functionality. When you perform a search, your words or phrases are highlighted in the search results making it easy for you to find the most relevant content.</p>
<p>Today I&#8217;m going to show you a simple way to add this to your website or blog so your users can find what they need in style. I think that this kind of thing should be implemented more often for how easy it is to implement.</p>
<h2>Search Results JavaScript code:</h2>
<pre class="brush: jscript; title: ; notranslate">
function highlightOnLoad() {
  // Get search string
  if (/s\=/.test(window.location.search)) {
    var searchString = getSearchString();
    // Starting node, parent to all nodes you want to search
    var textContainerNode = document.getElementById(&quot;content&quot;);

    // Informational message for search
    var searchInfo = 'Search Results for: ';

    // Split search terms on '|' and iterate over resulting array
    var searchTerms = searchString.split('|');
    for (var i in searchTerms) 	{
      // The regex is the secret, it prevents text within tag declarations to be affected
      var regex = new RegExp(&quot;&gt;([^&lt;]*)?(&quot;+searchTerms[i]+&quot;)([^&gt;]*)?&lt;&quot;,&quot;ig&quot;);
      highlightTextNodes(textContainerNode, regex, i);
      // Add to info-string
      searchInfo += ' &lt;span class=&quot;highlighted term'+i+'&quot;&gt;'+searchTerms[i]+'&lt;/span&gt; ';
    }

    // Create div describing the search
    var searchTermDiv = document.createElement(&quot;H2&quot;);
    searchTermDiv.className = 'searchterms';
    searchTermDiv.innerHTML = searchInfo;

    // Insert as very first child in searched node
    textContainerNode.insertBefore(searchTermDiv, textContainerNode.childNodes[0]);
  }
}

// Pull the search string out of the URL
function getSearchString() {
  // Return sanitized search string if it exists
  var rawSearchString = window.location.search.replace(/[a-zA-Z0-9\?\&amp;\=\%\#]+s\=(\w+)(\&amp;.*)?/,&quot;$1&quot;);
  // Replace '+' with '|' for regex
  // Also replace '%20' if your cms/blog uses this instead (credit to erlando for adding this)
  return rawSearchString.replace(/\%20|\+/g,&quot;\|&quot;);
}

function highlightTextNodes(element, regex, termid) {
  var tempinnerHTML = element.innerHTML;
  // Do regex replace
  // Inject span with class of 'highlighted termX' for google style highlighting
  element.innerHTML = tempinnerHTML.replace(regex,'&gt;$1&lt;span class=&quot;highlighted term'+termid+'&quot;&gt;$2&lt;/span&gt;$3&lt;');
}

// Call this onload, I recommend using the function defined at: http://untruths.org/technology/javascript-windowonload/
addOnLoad(highlightOnLoad());
</pre>
<h2>Now, the highlighting CSS:</h2>
<pre class="brush: css; title: ; notranslate">
span.highlighted {
  background-color: #161616;
  font-weight: bold;
}
span.term0 {
  background-color: #161633;
}
span.term1 {
  background-color: #331616;
}
span.term2 {
  background-color: #163316;
}
</pre>
<h2>Code explanation</h2>
<p>First, the <em>highlightOnLoad()</em> function checks <em>window.location.search</em> to see if we need to be running any of this stuff, then calls <em>getSearchString</em> to get a sanitized search string so that nothing funky can happen if, say, the user searches for &#8216;&lt;script&gt;&#8217;. You should really be sanitizing all search inputs at least on the back-end anyway.</p>
<p>Then, the <em>highlightTextNodes</em> function uses a regex replace on our textContainerNode&#8217;s innerHTML. The regex verifies that the text is between a &gt; and a &lt; (and not the other way around). Actually nice and simple!</p>
<h2>Caveats</h2>
<p>This may end up being a bit slow if you are doing this on a LOT of text, but for my blog text, it seems quite snappy to me. Also, the CSS does not bold text inside links, but the background color is there to make it obvious.</p>
<p>What do you think? Try it out on the search box on the upper-right. I&#8217;m hoping for some optimizations in the comments.</p>


<p>Related posts:<ol><li><a href='http://eriwen.com/css/color-palette-with-css-and-moo/' rel='bookmark' title='Create a Color Palette Using CSS and MooTools 1.2'>Create a Color Palette Using CSS and MooTools 1.2</a></li>
<li><a href='http://eriwen.com/javascript/measure-ems-for-layout/' rel='bookmark' title='Javascript: Measure those &#8220;em&#8221;s for your layout'>Javascript: Measure those &#8220;em&#8221;s for your layout</a></li>
<li><a href='http://eriwen.com/javascript/change-text-size-onclick-with-javascript/' rel='bookmark' title='Guest Post: change text size onclick with JavaScript'>Guest Post: change text size onclick with JavaScript</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/javascript/highlight-search-results-with-js/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>Guest Post: change text size onclick with JavaScript</title>
		<link>http://eriwen.com/javascript/change-text-size-onclick-with-javascript/</link>
		<comments>http://eriwen.com/javascript/change-text-size-onclick-with-javascript/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 13:45:37 +0000</pubDate>
		<dc:creator>Eric Wendelin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[guest post]]></category>

		<guid isPermaLink="false">http://eriwen.com/javascript/change-text-size-onclick-with-javascript/</guid>
		<description><![CDATA[I have been featured on the <a href="http://davidwalsh.name/" target="_blank">David Walsh Blog</a> with a post telling you how to <a href="http://davidwalsh.name/change-text-size-onclick-with-javascript" target="_blank">Change Text Size On Click With Javascript</a>. My code and explanation is there, but I do have a nice sample of the script in action.
 <a href="http://eriwen.com/javascript/change-text-size-onclick-with-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>


Related posts:<ol><li><a href='http://eriwen.com/javascript/text-size-prefs/' rel='bookmark' title='Guest Post: Save Text Size Preference Using MooTools and PHP'>Guest Post: Save Text Size Preference Using MooTools and PHP</a></li>
<li><a href='http://eriwen.com/javascript/measure-ems-for-layout/' rel='bookmark' title='Javascript: Measure those &#8220;em&#8221;s for your layout'>Javascript: Measure those &#8220;em&#8221;s for your layout</a></li>
<li><a href='http://eriwen.com/javascript/highlight-search-results-with-js/' rel='bookmark' title='How to highlight search results with JavaScript and CSS'>How to highlight search results with JavaScript and CSS</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I have been featured on the <a href="http://davidwalsh.name/" target="_blank">David Walsh Blog</a> with a post telling you how to <a href="http://davidwalsh.name/change-text-size-onclick-with-javascript" target="_blank">Change Text Size On Click With Javascript</a>. My code and explanation is there, but I do have a nice sample of the script in action.</p>
<p>Share your thoughts in the comments!</p>
<p><span style="padding: 2px 5px; background-color: #000000; float: right"><a href="javascript:void(0);" onclick="resizeText(1)" id="plustext">Make text bigger</a> | <a href="javascript:void(0);" onclick="resizeText(-1)" id="minustext">Make text smaller</a></span><br />
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
<p><script type="text/javascript"> var c = document.getElementById("content"); function resizeText(multiplier) { if (c.style.fontSize == "") { c.style.fontSize = "1.0em"; } c.style.fontSize = parseFloat(c.style.fontSize) + (multiplier * 0.2) + "em"; } </script></p>


<p>Related posts:<ol><li><a href='http://eriwen.com/javascript/text-size-prefs/' rel='bookmark' title='Guest Post: Save Text Size Preference Using MooTools and PHP'>Guest Post: Save Text Size Preference Using MooTools and PHP</a></li>
<li><a href='http://eriwen.com/javascript/measure-ems-for-layout/' rel='bookmark' title='Javascript: Measure those &#8220;em&#8221;s for your layout'>Javascript: Measure those &#8220;em&#8221;s for your layout</a></li>
<li><a href='http://eriwen.com/javascript/highlight-search-results-with-js/' rel='bookmark' title='How to highlight search results with JavaScript and CSS'>How to highlight search results with JavaScript and CSS</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eriwen.com/javascript/change-text-size-onclick-with-javascript/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

