<?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>Idle Hacking &#187; DOM</title>
	<atom:link href="http://www.idle-hacking.com/tag/dom/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.idle-hacking.com</link>
	<description>Ruby, XUL/Javascript, C/C++, and more...</description>
	<lastBuildDate>Tue, 11 May 2010 02:15:22 +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>DOM.ensure a DOMReady approach</title>
		<link>http://www.idle-hacking.com/2007/09/domensure-a-domready-approach/</link>
		<comments>http://www.idle-hacking.com/2007/09/domensure-a-domready-approach/#comments</comments>
		<pubDate>Fri, 28 Sep 2007 03:14:00 +0000</pubDate>
		<dc:creator>taf2</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.idle-hacking.com/2007/09/domensure-a-domready-approach/</guid>
		<description><![CDATA[DOM.ensure( function(){ $("node").observe("click",method1); }); If we decide that we want to cache that markup and reinsert it back into the DOM later we&#8217;re still safe. If we had used the DOMReady approach our code would have needed to be much more complex to track when it&#8217;s ok to call the method and when it needs [...]]]></description>
			<content:encoded><![CDATA[<pre lang="javascript">
DOM.ensure( function(){
   $("node").observe("click",method1);
});
</pre>
<p>If we decide that we want to cache that markup and reinsert it back into the DOM later we&#8217;re still safe.  If we had used the DOMReady approach our code would have needed to be much more complex to track when it&#8217;s ok to call the method and when it needs to be called in the event.  This method is really away of letting us say we want to ensure that this block of code is not executed until the DOM is really ready.</p>
<p>Here&#8217;s a solution I created for implementing DOM.ensure.</p>
<pre lang="javascript">DOM = Class.create();
Object.extend(DOM,{
  callQueue: $A([]), // store all calls in this queue
  isReady: false,
  // make sure the DOM may be effected before calling this method
  // if the DOM is ready then the method is called right away, else a timeout is set
  // until the DOM is ready
  ensureDOMIsReady: function(callback)
  {
    if( DOM.isReady ){
      callback(); // call the method now
    }
    else{ // delay the call until the DOM is ready
      DOM.callQueue.push( callback );
    }
  },
  initialize: function() // call any methods that were queued up to be run when the DOM is ready
  {
    DOM.isReady = true;
    var queue = DOM.callQueue;
    while( queue.length &gt; 0 ){
      queue.pop()();
    }
  }
}); 

// detect DOM ready once for the whole page for each specific browser type
if( Prototype.Browser.IE ){
  document.onreadystatechange = function(){
    if( document.readyState == "complete" ){
      DOM.initialize();
    }
  }
}
else if( Prototype.Browser.WebKit ){// safari 2.0
  var _timer = setInterval(function() {
  if (/loaded|complete/.test(document.readyState)) {
    clearInterval(_timer);
    DOM.initialize();
    }
  }, 10);
}
else if( document.addEventListener ){
  document.addEventListener("DOMContentLoaded", DOM.initialize.bind(this), false);
}</pre>
<p>Really it&#8217;s a change in the calling semantics for a DOMReady to think of it as more of a question of whether or not the DOM is ready for me to manipulate it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idle-hacking.com/2007/09/domensure-a-domready-approach/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My First Post, some RSS processing with Javascript</title>
		<link>http://www.idle-hacking.com/2005/05/my-first-post-some-rss-processing-with-javascript/</link>
		<comments>http://www.idle-hacking.com/2005/05/my-first-post-some-rss-processing-with-javascript/#comments</comments>
		<pubDate>Mon, 30 May 2005 17:25:00 +0000</pubDate>
		<dc:creator>taf2</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[RSS]]></category>
		<category><![CDATA[XUL]]></category>

		<guid isPermaLink="false">http://www.idle-hacking.com/2005/05/my-first-post-some-rss-processing-with-javascript/</guid>
		<description><![CDATA[I&#8217;ve been doing a lot of thinking about how to use xul templates to generate a nice display of an rss feed. I decided I might be able to get further using Javascript. In fact after writing a little code to fetch the rss document and grab the fields in javascript I think this approach [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing a lot of thinking about how to use xul templates to generate a nice display of an rss feed. I decided I might be able<br />
to get further using Javascript. In fact after writing a little code<br />
to fetch the rss document and grab the fields in javascript I think<br />
this approach isn&#8217;t half bad.</p>
<p>Here&#8217;s what I&#8217;ve come up with:</p>
<pre lang="javascript">// a global array of each RSSFeedvar gFeeds = new Array();
// loads a resource file listing each rss feed we're
// tracking
// TODO: provide a callback for progress
function loadRSSFeeds(){
  // TODO: actually load this info from a file
  loadRSSFeed( gFeeds, "http://kernel.org/kdist/rss.xml", true );
}
// TODO: provide a callback for progress
// load a single RSS Feed, non blocking
function loadRSSFeed( feeds, feedURL, display ){
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.onreadystatechange = function(){
    if( xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200 ){
       var feed =  new RSSFeed( xmlhttp.responseXML );
       feeds.push( feed );
       if( display )
         feed.show();
    }
  };
  xmlhttp.open( "GET", feedURL, true );
  xmlhttp.overrideMimeType("text/xml");
  xmlhttp.send(null);
}

// simple helper to extract the firstChild nodeValue from
// a DOM Element
function getFirstChildValue( element, name ){
  return element.getElementsByTagName( name )[0].firstChild.nodeValue;
}
function getFirstChildValueNS( element, ns, name ){
  return element.getElementsByTagNameNS( ns, name )[0].firstChild.nodeValue;
}

// given an RSS DOM object walk it's
// tree and display the content
function RSSFeed( rssDoc ){
  var channel = rssDoc.getElementsByTagName( "channel" )[0];
  this.title = getFirstChildValue( channel, "title" );
  this.link = getFirstChildValue( channel, "link" );
  this.desc = getFirstChildValue( channel, "description" );
  this.lang = getFirstChildValueNS( channel, "http://purl.org/dc/elements/1.1/", "language" );
  this.creator = getFirstChildValueNS( channel, "http://purl.org/dc/elements/1.1/", "creator" );
  this.date = getFirstChildValueNS( channel, "http://purl.org/dc/elements/1.1/", "date" );
  this.show = RSSFeed_show;  this.items = new Array();

  // now walk the items
  var items = rssDoc.getElementsByTagName( "item" );
  for( var i = 0; i < items.length; ++i ){
    this.items.push( new RSSItem( items[i] ) );
  }
}

function RSSItem( rssItem ){
  this.about = rssItem.getAttributeNS( "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "about" );
  this.title = getFirstChildValue( rssItem, "title" );
  //rssItem.getElementsByTagName( "title" )[0].firstChild.nodeValue;
  this.link = getFirstChildValue( rssItem, "link" );
  //rssItem.getElementsByTagName( "link" )[0].firstChild.nodeValue;
  this.desc = getFirstChildValue( rssItem, "description" );
  //rssItem.getElementsByTagName( "description" )[0].firstChild.nodeValue;
  this.show = RSSItem_show;
}

function RSSFeed_show(){
  dump( "RSSFeed\n" );
  dump( "Title:" + this.title + "\n" );
  dump( "Link: " + this.link + "\n" );
  dump( "Desc: " + this.desc + "\n" );
  dump( "Lang: " + this.lang + "\n" );
  dump( "Date: " + this.date + "\n" );

  for( var i = 0; i &lt; this.items.length; ++i ){
   this.items[i].show();
  }
}

function RSSItem_show(){
  dump( "RSSItem\n" );
  dump( "About: " + this.about + "\n" );
  dump( "Title: " + this.title + "\n" );
  dump( "Link: " + this.link + "\n" );
  dump( "Desc: " + this.desc + "\n" );
}
</pre>
<p>Then I found this document: http://developer.apple.com/internet/webcontent/xmltransformations.html</p>
<p>After reading this I have started to think that it might work nicely to have a default rss style sheet with more of a browser like interface. This needs some more thought...</p>
<p>Anyways, I'm happy to say I finally have my own blog setup! Hopefully, I'll be able to keep this more up to date then my website.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idle-hacking.com/2005/05/my-first-post-some-rss-processing-with-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
