<?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>The Bloggery of Jason Lydon</title>
	<atom:link href="http://jasonlydon.com/bloggery/feed" rel="self" type="application/rss+xml" />
	<link>http://jasonlydon.com/bloggery</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 18 Feb 2012 06:47:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Dreamweaver 5.5 HTML5 / CSS / JS Setup done right</title>
		<link>http://jasonlydon.com/bloggery/dreamweaver-5-5-html5-css-js-setup-done-right</link>
		<comments>http://jasonlydon.com/bloggery/dreamweaver-5-5-html5-css-js-setup-done-right#comments</comments>
		<pubDate>Sat, 18 Feb 2012 06:24:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Interactive Development]]></category>
		<category><![CDATA[Javascript 101]]></category>
		<category><![CDATA[Javascript Libraries]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Developement]]></category>
		<category><![CDATA[Adobe Dreamweaver CS5.5]]></category>
		<category><![CDATA[css reset]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://jasonlydon.com/bloggery/?p=383</guid>
		<description><![CDATA[At work I recently upgraded to Adobe Dreamweaver 5.5. I forgot that I added the HTML5 Pack via Adobe Extensions to DW, but was quickly reminded when I created new files and no longer had CSS reset or dom.ready in my files. I soon found that the HTML5 Pack is &#8216;included&#8217; with the defaults of [...]]]></description>
			<content:encoded><![CDATA[<p><strong>At work I recently upgraded to Adobe Dreamweaver 5.5. I forgot that I added the <a href="http://labs.adobe.com/downloads/html5pack.html" target="_blank">HTML5 Pack</a> via Adobe Extensions to DW, but was quickly reminded when I created new files and no longer had CSS reset or dom.ready in my files. I soon found that the HTML5 Pack is &#8216;included&#8217; with the defaults of DW5.5, except my default files were all lame and empty.</strong></p>
<p>[I already know that most 'professionals' poop all over DW, but it is the program I learned to code in and mocking me will not get me to change my mind]</p>
<p>This led me to learn how actually customize the default files for DW and eventually I created a nice little stripped down DW Boilerplate for myself. I didn&#8217;t find any good documentation, so I figured I use the moment of inspiration to write a post.</p>
<p><strong>Setup the default html file</strong></p>
<ul>
<li><strong>Summary: </strong>HTML5 Template with generic links to styles, scripts, etc</li>
<li>1. Set DW to open your html files with the HTML5 doctype.<br />
&#8211; Dreamweaver -> Preferences -> New Document -> Default Document Type (DDT):<br />
&#8211; change the setting to HTML5<br />
This will give you a nice little naked HTML5 file, but we can make it better.</li>
<li>2. Build you preferred HTML template that will open each time you open a new html document.<br />
&#8211; In your computer, find: Dreamweaver 5.5 -> Configuration -> DocumentTypes -> NewDocuments -> Default.html<br />
Open the file in DW, then just type or copy/paste in your new html template. Save, then open a new html file, and you should see exactly what you just added!</li>
</ul>
<p class='mt20'><strong>Setup the default javascript file</strong></p>
<ul>
<li><strong>Summary: </strong>basic js file with jQuery doc.ready and window.load ready to rock</li>
<li>1. Build you preferred javascript template that will open each time you open a new javascript document. Really, the html file is the hardest to to, because it is two steps.<br />
&#8211; In your computer, find: Dreamweaver 5.5 -> Configuration -> DocumentTypes -> NewDocuments -> Default.js<br />
Open the file in DW, then just type or copy/paste in your new javascript template. Follow the same process for testing.</li>
</ul>
<p class='mt20'><strong>Setup the default css file</strong></p>
<ul>
<li><strong>Summary: </strong>default css file with reset, author comments, indexing and device widths</li>
<li>1. HTML5 is sweet, JS is ok, but the CSS is where I really pat myself on the back.<br />
&#8211; In your computer, find: Dreamweaver 5.5 -> Configuration -> DocumentTypes -> NewDocuments -> Default.css<br />
Thats it, you are good to go.</li>
</ul>
<p class='mt20'>So now knowing these principles, you know where every default file template is in DW and you can customize all the templates you use.</p>
<p>As for more details about my boilerplate. I found other boilerplates to be informative, but bloated. I was always removing things or noticing things I forgot to remove. I wanted to come from the other direction. Just the proper basics that will provide the things I need and save me time. This is my first draft of these files, but this shit is organic and will evolve, so feel free to take mine and use them as your starting point.</p>
<ul>
<li><strong>HTML: </strong>HTML5 document with title tag, favicon link, screen/mobile/print css linked, html5 shiv, some base html tags (header/content/footer), js file linked.</li>
<li><strong>js: </strong>I always find myself using jQuery, so the file has the standard doc.ready and window.load functions</li>
<li><strong>css: </strong>This is the file that I really appreciate. It starts with project details, including the math my heights &amp; widths are based on (used for my mobile specific css). It is followed by a basic index, I do this because css files always become a mess if you don&#8217;t stay on top of them. Then we roll into <a href='http://meyerweb.com/eric/tools/css/reset/' target='_blank'>Eric Meyer&#8217;s reset css</a> with html5 selectors included (I remove the body {line-height} css because it causes me more problems that it solves). It then has the comments that match the index setup. Finishing with some <a href='http://www.w3.org/TR/css3-mediaqueries/' target='_blank'>CSS Media Queries</a> for device width. This has it&#8217;s own index for all my testing devices and then the corresponding widths breaking down the devices again. Like I said above, I&#8217;m pretty proud of this file, makes my life easier.</li>
</ul>
<p class='mt20'><a href="/downloads/site-defaults.zip" title="Download the files">Download the files(html, css, js)[8kb]</a></p>
<p>I would love to hear how other folks start there projects off. Their default files.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonlydon.com/bloggery/dreamweaver-5-5-html5-css-js-setup-done-right/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5 Input Placeholder Safari Bug</title>
		<link>http://jasonlydon.com/bloggery/html5-input-placeholder-safari-bug</link>
		<comments>http://jasonlydon.com/bloggery/html5-input-placeholder-safari-bug#comments</comments>
		<pubDate>Mon, 05 Dec 2011 21:06:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Web Developement]]></category>
		<category><![CDATA[Placeholder]]></category>

		<guid isPermaLink="false">http://jasonlydon.com/bloggery/?p=378</guid>
		<description><![CDATA[When using placeholder in text inputs, Safari won&#8217;t respect line-height. The text won&#8217;t appear to be centered vertically. But if you remove the line-height, it will. Just a heads up.]]></description>
			<content:encoded><![CDATA[<p>When using placeholder in text inputs, Safari won&#8217;t respect line-height. The text won&#8217;t appear to be centered vertically. But if you remove the line-height, it will. Just a heads up.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonlydon.com/bloggery/html5-input-placeholder-safari-bug/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nerd alert: Mike Tyson&#8217;s Punch Out Training all CSS &amp; jQuery</title>
		<link>http://jasonlydon.com/bloggery/nerd-alert-mike-tysons-punch-out-training-all-css-jquery</link>
		<comments>http://jasonlydon.com/bloggery/nerd-alert-mike-tysons-punch-out-training-all-css-jquery#comments</comments>
		<pubDate>Wed, 06 Apr 2011 22:47:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript Libraries]]></category>
		<category><![CDATA[NO FLASH]]></category>
		<category><![CDATA[Addy Osmani]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Mike Tyson's Punch Out]]></category>
		<category><![CDATA[Spritely]]></category>

		<guid isPermaLink="false">http://jasonlydon.com/bloggery/?p=371</guid>
		<description><![CDATA[Today I found a blog via a LinkedIn group that loves HTML5. Addy Osmani is the man, no questions asked. So I did a little tutorial off his site doing animation based on a jQuery plugin called Spritely. The end result is the jogging screen from Mike Tyson&#8217;s Punch Out NES game. All HTML, CSS, [...]]]></description>
			<content:encoded><![CDATA[<p>Today I found a blog via a  LinkedIn group that loves HTML5. <a href="http://addyosmani.com/" target="_blank">Addy Osmani</a> is the man, no questions asked. So I did a little tutorial off his site doing animation based on a <a href="http://api.jquery.com/" target="_blank">jQuery</a> plugin called <a href="http://spritely.net" target="_blank">Spritely</a>.</p>
<p><a href="/spritely_test.html"><img src="/img/tyson/screenshot.png" alt="The Mike Tyson's Punch Out training screen done with Spritely" /></a></p>
<p><a href="/spritely_test.html">The end result</a> is the jogging screen from Mike Tyson&#8217;s Punch Out NES game. All HTML, CSS, jQuery &amp; Spritely! I really couldn&#8217;t help myself!</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonlydon.com/bloggery/nerd-alert-mike-tysons-punch-out-training-all-css-jquery/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JS101 Week 3 &#8211; Track 1</title>
		<link>http://jasonlydon.com/bloggery/js101-week-3-track-1</link>
		<comments>http://jasonlydon.com/bloggery/js101-week-3-track-1#comments</comments>
		<pubDate>Thu, 10 Mar 2011 18:02:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript 101]]></category>
		<category><![CDATA[P2PU]]></category>

		<guid isPermaLink="false">http://jasonlydon.com/bloggery/?p=358</guid>
		<description><![CDATA[So it&#8217;s week 3 in JS101 in my world, but the class actually ended today after 6 weeks. Week 3 appeared to give everyone in class a lot of trouble, hopefully I can bang it out and try to get week 5 &#38; 6 knocked out. Work &#38; school did not want to co-exist for [...]]]></description>
			<content:encoded><![CDATA[<p> So it&#8217;s week 3 in JS101 in my world, but the class actually ended today after 6 weeks. Week 3 appeared to give everyone in class a lot of trouble, hopefully I can bang it out and try to get week 5 &amp; 6 knocked out. Work &amp; school did not want to co-exist for the last few weeks&#8230;</p>
<p>Please watch the videos in the links listed below. Some links may contain further notes and links to resources covered in the videos. After watching the videos, reflect on the questions, discuss them on the forums, post your reflections on your blogs. The assignments are for practicing the concepts learned. You can discuss them on the forums, and upload them on your blog or any open source repository where your course peers and facilitators can review and comment on them.</p>
<p>Video 3</p>
<div><object width="512" height="322"><param name="movie" value="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" /><param name="allowFullScreen" value="true" /><param name="AllowScriptAccess" VALUE="always" /><param name="bgcolor" value="#000000" /><param name="flashVars" value="id=1710607&#038;vid=111595&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111595_320_240.jpeg&#038;embed=1" /><embed src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" type="application/x-shockwave-flash" width="512" height="322" allowFullScreen="true" AllowScriptAccess="always" bgcolor="#000000" flashVars="id=1710607&#038;vid=111595&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111595_320_240.jpeg&#038;embed=1" ></embed></object><br /><a href="http://video.yahoo.com/watch/111595/1710607">Douglas Crockford: &quot;The JavaScript Programming Language&quot;/3 of 4</a> @ <a href="http://video.yahoo.com" >Yahoo! Video</a></div>
<p>Video 4</p>
<div><object width="512" height="322"><param name="movie" value="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" /><param name="allowFullScreen" value="true" /><param name="AllowScriptAccess" VALUE="always" /><param name="bgcolor" value="#000000" /><param name="flashVars" value="id=1710658&#038;vid=111596&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111596_320_240.jpeg&#038;embed=1" /><embed src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" type="application/x-shockwave-flash" width="512" height="322" allowFullScreen="true" AllowScriptAccess="always" bgcolor="#000000" flashVars="id=1710658&#038;vid=111596&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111596_320_240.jpeg&#038;embed=1" ></embed></object><br /><a href="http://video.yahoo.com/watch/111596/1710658">Douglas Crockford: &quot;The JavaScript Programming Language&quot;/4 of 4</a> @ <a href="http://video.yahoo.com" >Yahoo! Video</a></div>
<p>Questions for reflection (please reflect on your blog and discuss in comments below):</p>
<ul class='p2pu'>
<li>Q: 1. In Javascript, functions are first class objects. What does it mean to be a first class object?<br />
A: According to the video:<br />
1. Functions can be passed, returned, and stored just like any other value<br />
2. Functions inherit from Object and can store name/value pairs<br />
i.e. they are objects and can be manipulated and passed around like just like any other object. Specifically, they are Function objects(<a href='https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope' target='_blank'>source</a>)</li>
<li>Q: 2. Functions and variables share the same namespace. What does this mean and what important implication does this have?<br />
A: This means that variables and functions can have the same name and should not be named the same because it can cause conflict/problems<br />
function foo(){}<br />
expands to<br />
var foo = function foo()();</li>
<li>3. Douglas Crockford equates Javascript functions with Lambdas, and also mentions that they are a secure construct. Can you do some research and reflect on what he means by &#8216;secure construct&#8217;?<br />
A: Lambda comes from the Lambda Calculus and refers to anonymous functions in programming.<br />
Why is this cool? It allows you to write quick throw away functions without naming them. It also provides a nice way to write closures. With that power you can do things like this.<br />
<strong>Javascript</strong></p>
<pre>
adder = function (x) {
    return function (y) {
        x + y
    }
};
add5 = adder(5);
add5(1) == 6
</pre>
<p>As you can see from the snippet of python and js, the function adder takes in an argument x, and returns an anonymous function, or lambda, that takes another argument y. That anonymous function allows you to create functions from functions. This is a simple example, but it should convey the power lambdas and closures have.(<a href='http://stackoverflow.com/questions/16501/what-is-a-lambda-function' target='_blank'>source</a>)</li>
<li>4. Can you explain the concept of a closure.<br />
A: Two one sentence summaries (<a href='http://www.javascriptkit.com/javatutors/closures.shtml' target='_blank'>source</a>):<br />- a closure is the local variables for a function &#8211; kept alive after the function has returned, or<br />
- a closure is a stack-frame which is not deallocated when the function returns. (as if a &#8216;stack-frame&#8217; were malloc&#8217;ed instead of being on the stack!<br />
That same article breaks this out as the definition: &#8220;In JavaScript, if you use the function keyword inside another function, you are creating a closure.&#8221; So if you use something like alert(); inside your function, you are creating closure because the alert exists after/outside the function&#8230;</li>
<li>5. What is the difference between a function and a method?<br />
A: &#8216;A function in an object is called a method.&#8217; That appears to be the only difference.</li>
<li>6. In Javascript there is no implicit type checking of arguments passed to functions. This could lead to bugs if programmers are not careful about what they pass to functions. If you create a function, how would you protect it from well meaning but careless programmers?<br />
A: &#8216;We can use “arguments” and check at the very beginning whether the programmers had entered the right number of arguments to the function.&#8217; IE arguments.length. Or we can check for the type we are look for using typeof() = type</li>
<li>7. Javascript functions have implicit access to something called this. this points to different things depending on how the function was created. Can you explain why we need this, and what it represents in different type of functions.<br />
A: &#8216;this&#8217; is important because it &#8216;gives methods access to their objects&#8217;<br />
Function form ==> functionObject(arguments) ==> this is set to the global object so we must use var that = this; to have  access to the outer this<br />
Method form ==> thisObject.methodName(arguments) ==> this = thisObject aka the object containing the function<br />
Constructor form ==> new functionObject(arguments) ==> a new object is created and assigned to this.<br />
Apply form ==> undefined in the video&#8230;</li>
<li>8. Why doesn&#8217;t Javascript have a cast operator?<br />
A: &#8220;In javascript, we never cast. An object reference is always an object reference.&#8221; In english, this basically means that js does type casts automatically. However, types can be converted as desired using the conversion functions: String(), Number(), Boolean(), etc.(<a href='http://blog.patrickcollins.me/?p=13' target='_blank'>source</a>)</li>
<li>9. What is reflection and why is it easy in Javascript (you may need to do research to answer this question)?<br />
A: &#8216;Sometimes you want to find out what members an object exposes. There&#8217;s a pretty simple way to do this. A simple for-in statement.&#8217;</p>
<pre>
for(var member in obj){
  alert(member);
};
</pre>
<p>or something like this:</p>
<pre>
for (var member in object) {
	alert('Name: ' + member);
	alert('Value: ' + object[member]);
}
</pre>
</li>
</ul>
<p><strong>Homework:</strong></p>
<p><a href='http://eloquentjavascript.net/chapter6.html' target='_blank'>Exercises 6.1 &#8211; 6.5 from the book Eloquent Javascript</a>. Follow good Javascript style.</p>
<ul class='p2pu'>
<li>Q: 1. <a href='http://eloquentjavascript.net/chapter6.html' target='_blank'>Exercises 6.1 &#8211; 6.5 from the book Eloquent Javascript</a>. Follow good Javascript style.<br />
A: coming soon&#8230;</li>
<li>Q: 2. Run all the exercises you did (6.1 &#8211; 6.5) through <a href='http://www.jslint.com/' target='_blank'>JSLint</a> and change your code to improve it.<br />
A: coming soon&#8230;</li>
</ul>
<p>Run all the exercises you did (6.1 &#8211; 6.5) through <a href='http://www.jslint.com/' target='_blank'>JSLint</a> and change your code to improve it.</p>
<p>#p2pu-Jan2011-javascript101</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonlydon.com/bloggery/js101-week-3-track-1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JS101 Week 4</title>
		<link>http://jasonlydon.com/bloggery/js101-week-4</link>
		<comments>http://jasonlydon.com/bloggery/js101-week-4#comments</comments>
		<pubDate>Wed, 09 Mar 2011 18:05:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript 101]]></category>
		<category><![CDATA[Web Developement]]></category>
		<category><![CDATA[P2PU]]></category>

		<guid isPermaLink="false">http://jasonlydon.com/bloggery/?p=344</guid>
		<description><![CDATA[TRACK 1 &#8211; Javascript Videos Please watch the videos in the links listed below. Some links may contain further notes and links to resources covered in the videos. After watching the videos, reflect on the questions, discuss them on the forums, post your reflections on your blogs. The assignments are for practicing the concepts learned. [...]]]></description>
			<content:encoded><![CDATA[<p>TRACK 1 &#8211; Javascript Videos<br />
Please watch the videos in the links listed below. Some links may contain further notes and links to resources covered in the videos. After watching the videos, reflect on the questions, discuss them on the forums, post your reflections on your blogs. The assignments are for practicing the concepts learned. You can discuss them on the forums, and upload them on your blog or any open source repository where your course peers and facilitators can review and comment on them.</p>
<ul>
<li><object width="512" height="322"><param name="movie" value="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" /><param name="allowFullScreen" value="true" /><param name="AllowScriptAccess" VALUE="always" /><param name="bgcolor" value="#000000" /><param name="flashVars" value="id=992708&#038;vid=111582&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111582_320_240.jpeg&#038;embed=1" /><embed src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.46" type="application/x-shockwave-flash" width="512" height="322" allowFullScreen="true" AllowScriptAccess="always" bgcolor="#000000" flashVars="id=992708&#038;vid=111582&#038;lang=en-us&#038;intl=us&#038;thumbUrl=http%3A//l.yimg.com/a/i/us/sch/cn/v/v0/w326/111582_320_240.jpeg&#038;embed=1" ></embed></object><br /><a href="http://video.yahoo.com/watch/111582/992708">Douglas Crockford: &quot;Theory of the DOM &quot; (1 of 3)</a> @ <a href="http://video.yahoo.com" >Yahoo! Video</a></li>
<li><a href="http://dev.opera.com/articles/view/traversing-the-dom/" target="_blank">Article: Traversing the DOM</a></li>
<li><a href="http://www.quirksmode.org/dom/intro.html" target="_blank">Introduction to modifying the DOM</a></li>
<li><a href="http://www.javascript-coder.com/javascript-form/javascript-get-form.phtml" target="_blank">How to access a form element with Javascript</a></li>
</ul>
<p>Questions for reflection (please reflect on your blog and discuss in comments below):</p>
<ul class="p2pu">
<li>Q: There were two key innovations to the original (fetch-parse-flow-paint) linear workflow that the Mosaic browser used to render web pages. One allowed for a perception of faster rendering, and the other allowed for us to use AJAX. Explain both?<br />
A: 1) The Mosaic engine had a problem with images, it didn&#8217;t know the size of the image. It would reach the parse stage of the workflow have to return fetch stage of the workflow. To fix this, Netscape followed the same workflow, but put a marker in the fetch stage and kept going, and then later, when it got the image, it would paint it in. Essentially, the load didn&#8217;t get hung up on an image, it would build around it. Flow and Paint multiple times.<br />
2) Netscape 2 built on this by adding events, which cause a script to get executed. Creating a &#8216;Flow -> Paint -> Event -> Script&#8217; loop. Something all browsers still use today.</li>
<li>Q: What are the roles of &#8216;name&#8217; and &#8216;id&#8217; attributes in HTML tags? What is an appropriate use of both?<br />
A: &#8216;name&#8217; = Identifies values in form data, Identifies a window/frame. They are mostly used in forms and such<br />
&#8216;id&#8217; = Uniquely identifies an element. This can be used to gain access to an object for use with JS &amp; CSS.</li>
<li>Q: Which pointers does each node in the DOM tree typically have?<br />
A: child, sibling, parent.</li>
<li>Q: Given a node object from a DOM tree, how do we determine if it is a text node or a regular node?<br />
A: If you get a nodes nodeName, a Text node will return #text, a regular node will return something other that #text.</p>
<table>
<tr>
<td width="50%">Element</td>
<td width="50%">The tag name, eg. HTML</td>
</tr>
<tr>
<td>Attr</td>
<td>The attribute name, eg. id</td>
</tr>
<tr>
<td>Text</td>
<td>#text</td>
</tr>
<tr>
<td>CDATASection</td>
<td>#cdata-section</td>
</tr>
<tr>
<td>EntityReference</td>
<td>The name of the entity reference, eg. amp</td>
</tr>
<tr>
<td>Entity</td>
<td>The entity name, eg. &#038;</td>
</tr>
<tr>
<td>ProcessingInstruction</td>
<td>The target of the processing instruction, eg. xml-stylesheet</td>
</tr>
<tr>
<td>Comment</td>
<td>#comment</td>
</tr>
<tr>
<td>Document </td>
<td>#document</td>
</tr>
<tr>
<td>DocumentType</td>
<td>The name of the document type, eg. html</td>
</tr>
<tr>
<td>DocumentFragment</td>
<td>#document-fragment</td>
</tr>
<tr>
<td>Notation</td>
<td>The notation name</td>
</tr>
</table>
<p>or refer to this check node.nodeType for these:<br />
Node.ELEMENT_NODE == 1<br />
Node.ATTRIBUTE_NODE == 2<br />
Node.TEXT_NODE == 3<br />
Node.CDATA_SECTION_NODE == 4<br />
Node.ENTITY_REFERENCE_NODE == 5<br />
Node.ENTITY_NODE == 6<br />
Node.PROCESSING_INSTRUCTION_NODE == 7<br />
Node.COMMENT_NODE == 8<br />
Node.DOCUMENT_NODE == 9<br />
Node.DOCUMENT_TYPE_NODE == 10<br />
Node.DOCUMENT_FRAGMENT_NODE == 11<br />
Node.NOTATION_NODE == 12</p>
</li>
</ul>
<p>Homework:</p>
<ul class="p2pu">
<li>Q: Download the source for the web page &#8216;http://www.useit.com/about/nographics.html&#8217;. In the source page itself, write a Javascript function which counts the number of text nodes in the document and shows the count in an alert dialogue. You can choose how you want to trigger the function (through a button click, link click, or any other event).<br />
A: I had a real hard time putting this one together. I couldn&#8217;t think it all the way through the process, I actually poached the code from <a href='https://gist.github.com/835680' target='_blank'>Melipone Moody</a>. See my version in action <a href='/P2PU/HotJava/week4/homework-1.html' target='_blank'>here</a>.</p>
<pre>
function walkTheDOM(node, func) {
	func(node);
	node = node.firstChild;
	while (node) {
		walkTheDOM(node, func);
		node = node.nextSibling;
	}
}
function countTextNodes() {
	var sum = 0;
	function count (node) {
		if (node.nodeType == 3) // TEXT_NODE
	sum++;
	}
	var root = document.documentElement;
	walkTheDOM(root, count);
	alert (sum + " text nodes found");
}
countTextNodes()
</pre>
</li>
<li>Q: Change the example above so that instead of displaying the count in an alert dialogue, it is displayed in a span tag in the HTML page itself.<br />
A: Simply just built of the previous example and used innerHTML. See it in action <a href='/P2PU/HotJava/week4/homework-2.html' target='_blank'>here</a>.</p>
<pre>
function walkTheDOM(node, func) {
	func(node);
	node = node.firstChild;
	while (node) {
		walkTheDOM(node, func);
		node = node.nextSibling;
	}
}
function countTextNodes() {
	var sum = 0;
	function count (node) {
		if (node.nodeType == 3) // TEXT_NODE
	sum++;
	}
	var root = document.documentElement;
	walkTheDOM(root, count);
	var add_this_copy = (sum + " text nodes found");
	// alert(add_this_copy);
	document.getElementById('place_content_here').innerHTML = add_this_copy;

}
countTextNodes()
</pre>
</li>
<li>Q: Add a link besides the button, such that when the link is click, it changes the style on the span tag to make it&#8217;s contents bold.<br />
A: Again, building off the previous example&#8230; See it <a href='/P2PU/HotJava/week4/homework-3.html' target='_blank'>here</a>.</p>
<pre>
window.onload=function(){
	countTextNodes();
}
function walkTheDOM(node, func) {
	func(node);
	node = node.firstChild;
	while (node) {
		walkTheDOM(node, func);
		node = node.nextSibling;
	}
}
function countTextNodes() {
	var sum = 0;
	function count (node) {
		if (node.nodeType == 3) // TEXT_NODE
	sum++;
	}
	var root = document.documentElement;
	walkTheDOM(root, count);
	var add_this_copy = (sum + " text nodes found");
	// alert(add_this_copy);
	document.getElementById('place_content_here').innerHTML = add_this_copy;
	return add_this_copy;
}
function change_to_bold(){
	var current_text = document.getElementById('place_content_here').innerHTML;
	var current_text = '<strong>'+current_text+'</strong>';
	document.getElementById('place_content_here').innerHTML = current_text;
}
function change_to_normal(){
	var current_text = document.getElementById('place_content_here').lastChild.innerHTML;
	document.getElementById('place_content_here').innerHTML = current_text;
}
</pre>
</li>
</ul>
<p>#p2pu-Jan2011-javascript101</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonlydon.com/bloggery/js101-week-4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

