<?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"
	>

<channel>
	<title>CreateOpen</title>
	<atom:link href="http://www.createopen.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.createopen.com/blog</link>
	<description>Coding to the max!</description>
	<pubDate>Tue, 30 Sep 2008 17:34:52 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Easy Ajax: From Web 1.0 to Web 2.0 in 5 steps</title>
		<link>http://www.createopen.com/blog/2008/09/easy-ajax-from-web-10-to-web-20-in-5-steps/</link>
		<comments>http://www.createopen.com/blog/2008/09/easy-ajax-from-web-10-to-web-20-in-5-steps/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 17:08:41 +0000</pubDate>
		<dc:creator>David Hulbert</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.createopen.com/blog/?p=11</guid>
		<description><![CDATA[Ajax is a method used to update a page with JavaScript, without reloading the page. This is the basis of all web applications.

The main ways to update a page are as follows:

With an XML HTTP Request
Using a hidden Iframe
Using a hidden image
Using a plain old &#60;script&#62; tag.

In this tutorial we will be using the &#60;script&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Ajax is a method used to update a page with JavaScript, without reloading the page. This is the basis of all web applications.<br />
<a href='http://www.createopen.com/examples/script-ajax/'><img src="http://www.createopen.com/blog/wp-content/uploads/2008/09/ajax.png" alt="ajax in 5 steps" width="200" height="150" class="alignright size-full wp-image-20" /></a><br />
The main ways to update a page are as follows:</p>
<ul>
<li>With an XML HTTP Request</li>
<li>Using a hidden Iframe</li>
<li>Using a hidden image</li>
<li>Using a plain old <code>&lt;script&gt;</code> tag.</li>
</ul>
<p>In this tutorial we will be using the <code>&lt;script&gt;</code> tag, as it is the easiest, cross browser and is the most logical.</p>
<p>Our aim is to process the user&#8217;s data (their name) on the server, without the user having to submit a form and load another page.</p>
<p>Take a look at the View the <a href="/examples/script-ajax/">completed ajax demo</a> if you&#8217;re feeling sneaky.</p>
<h3>Step 1: Set up the HTML</h3>
<p>Our basic HTML is as follows:</p>
<pre class="syntax-highlight:html">
&lt;html&gt;
	&lt;body&gt;
		&lt;form name=&quot;ajaxform&quot; onsubmit=&quot;return doajax()&quot;&gt;
			&lt;label&gt;
				What is your name?
				&lt;input type=&quot;text&quot; name=&quot;yourname&quot; id=&quot;yourname&quot;&gt;
			&lt;/label&gt;
			&lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;
		&lt;/form&gt;
		&lt;h2&gt;Results&lt;/h2&gt;
		&lt;textarea id=&quot;results&quot;&gt;&lt;/textarea&gt;
	&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>(Doctype etc removed here to be concise)</p>
<h3>Step 2: Requesting a script</h3>
<p>When the form is submitted, we want it to load a server side script and process our data. The doajax() function below will load a server side script (ajax.php) with the contents of the form.</p>
<pre class="syntax-highlight:js">
function doajax() {
	// get our data
	var yourname = document.getElementById(&quot;yourname&quot;).value;
	// create a new script element
	var ajaxscript = document.createElement(&#039;script&#039;);
	// set the data as a parameter
	ajaxscript.src = &#039;ajax.php?yourname=&#039; + yourname; to the script&#039;s source
	// load the script
	document.getElementsByTagName(&quot;head&quot;)[0].appendChild(ajaxscript);
	// stop the form from submitting
	return false;
}
</pre>
<h3>Step 3: Processing the data</h3>
<p>This is where the clever stuff happens. Normally you&#8217;d use the form data, look it up in a database and return a response. We&#8217;ll keep this example as simple as possible, so it should be easy to adapt and extend. This code is written in PHP, but you can use any language you want.</p>
<p>This code takes the &#8220;yourname&#8221; request parameter and converts it to upper case. Of course, this could easily be done with JavaScript, but that&#8217;s not the point of this tutorial.</p>
<pre class="syntax-highlight:js">
loadResponse(&#039;&lt;?php print addslashes(strtoupper($_REQUEST[&quot;yourname&quot;])); ?&gt;&#039;);
</pre>
<p>Yes, it&#8217;s just 1 line. The PHP here is writing the JavaScript. If you run <a href="/examples/script-ajax/ajax.php?yourname=Dave">ajax.php?yourname=Dave</a> it will generate the JavaScript:</p>
<pre class="syntax-highlight:js">
loadResponse(&#039;DAVE&#039;);
</pre>
<p>The important thing to note is that the server side script is taking in the request parameter, processing it, then writing out some JavaScript.</p>
<h3>Step 4: Displaying the data</h3>
<p>As you can see form step 3 above, a function <code>loadResponse()</code> is being called by <code>ajax.php</code>. We need to create this function and do something with the data.</p>
<pre class="syntax-highlight:js">
function loadResponse(responseString) {
	document.getElementById(&quot;results&quot;).value = responseString;
}
</pre>
<h3>Step 5: Extend it!</h3>
<p>I lied: there are only really 4 steps. This code is very basic and could do with some error checking. </p>
<p>Further ideas to try:</p>
<ul>
<li>Make the JavaScript unobtrusive. The code should check whether the browser supports specific functions and only &#8220;ajaxify&#8221; the page is it passes. If not, it should gracefully degrade to plain HTML.</li>
<li>Implement caching. Store frequent requests in the browser, then load them locally to make it look like your Ajax page is instantaneous.</li>
<li>Add <code>onkeyup="doajax()"</code> to the input field. This will send of a request to <code>ajax.php</code> a lot, so is not recommended on its own!</li>
<li>Add a timer to the page, so the page is not updated more than once in 200ms</li>
<li>After playing with the page a bit you&#8217;ll notice there are many <code>script</code> tags. These should be removed.</li>
<li>Cheat with a JavaScript library</li>
<li>Learn how to do it with XML HTTP Request (post coming soon)</li>
</ul>
<p>View the <a href="/examples/script-ajax/">completed demo here</a>. Any questions? Comments? Errors?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.createopen.com/blog/2008/09/easy-ajax-from-web-10-to-web-20-in-5-steps/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Son of Suckerfish dropdowns in jQuery</title>
		<link>http://www.createopen.com/blog/2008/09/son-of-suckerfish-dropdowns-in-jquery/</link>
		<comments>http://www.createopen.com/blog/2008/09/son-of-suckerfish-dropdowns-in-jquery/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 17:58:40 +0000</pubDate>
		<dc:creator>David Hulbert</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.createopen.com/blog/?p=19</guid>
		<description><![CDATA[If you&#8217;ve never heard of Suckerfish menus, they&#8217;re a simple way to get drop-down menus working in IE6. IE6 has lacks many features of modern browsers. One of the most important missing features is the ability to define hover pseudo classes to elements other than A (anchor links).  The original Suckerfish dropdown code from [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve never heard of Suckerfish menus, they&#8217;re a simple way to get drop-down menus working in IE6. IE6 has lacks many features of modern browsers. One of the most important missing features is the ability to define hover pseudo classes to elements other than A (anchor links).  The original Suckerfish dropdown code from <a href="http://www.alistapart.com/articles/dropdowns/">A List Apart</a> is as follows:</p>
<pre class="syntax-highlight:js">startList = function() { if (document.all &amp;&amp; document.getElementById) {
navRoot = document.getElementById(&quot;nav&quot;);
for (i=0; i&lt;navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName==&quot;LI&quot;) {
node.onmouseover=function() {this.className+=&quot; over&quot;; }
node.onmouseout=function() { this.className=this.className.replace(&quot; over&quot;, &quot;&quot;); }
}
}
}
}
window.onload=startList;</pre>
<p>  As you can see, this code isn&#8217;t very neat and fails if &#8220;over&#8221; is part of another class name. It also overrides any other onload events you have and only runs the code when the page (including images) is fully loaded. The site HTML Dog updated the code to <a href="http://www.htmldog.com/articles/suckerfish/dropdowns/">Son of Suckerfish dropdowns</a>:
<pre class="syntax-highlight:js"> sfHover = function() {
var sfEls = document.getElementById(&quot;nav&quot;).getElementsByTagName(&quot;LI&quot;);
for (var i=0; i&lt;sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=&quot; sfhover&quot;;
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(&quot; sfhover\\b&quot;), &quot;&quot;);
}
}
}
if (window.attachEvent) window.attachEvent(&quot;onload&quot;, sfHover);
</pre>
<p>  This is much neater and uses a nice regular expression to remove the class name. It also uses Microsoft&#8217;s <code class="javascript">attachEvent, which is much easier to make non-distructive.</code> There is still a problem with this: the code only executes when the page is fully loaded. What we really need is to wait until the DOM is ready to be manipulated, then run the code. Unfortunately, as we&#8217;re aiming this code at IE6, we can&#8217;t just do a       document.addEventListener(&#8221;DOMContentLoaded&#8221;, sfHover<span class="brackets">). The only way we can get a DOM ready event is by creating an empty script with defer=&#8221;defer&#8221; and listen for it to load, then run our code. This was thought up by </span><a href="http://blog.outofhanwell.com/2006/06/08/the-windowonload-problem-revisited/">Matthias Miller</a>.</p>
<p>The code is now starting to get more complex. We&#8217;re also going to be creating functions we&#8217;ll probably reuse in the future. Instead of writing our functions from scratch, we&#8217;ll use a jQuery, a JavaScript library to do most of the hard work for us.</p>
<p>The jQuery version:</p>
<pre class="syntax-highlight:js">$(function() {
$(&quot;#nav li&quot;).hover(
function() {$(this).addClass(&quot;sfhover)},
function() {$(this).removeClass(&quot;sfhover)}
);
};</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.createopen.com/blog/2008/09/son-of-suckerfish-dropdowns-in-jquery/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Fading menus in 5 lines of JavaScript</title>
		<link>http://www.createopen.com/blog/2008/09/fading-menus-in-5-lines-of-javascript/</link>
		<comments>http://www.createopen.com/blog/2008/09/fading-menus-in-5-lines-of-javascript/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 06:48:26 +0000</pubDate>
		<dc:creator>David Hulbert</dc:creator>
		
		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.createopen.com/blog/?p=5</guid>
		<description><![CDATA[Ever wanted your menus to fade when you mouse over them? With jQuery, copy this code into your page and run it when the DOM is ready (That means wrapping it with $(function(){ ... }); to use jQuery&#8217;s $(document).ready() function).
Replace #nav li below with whatever your navigation items are.

$(&#34;#nav li&#34;).hover(function(){ //add an event listener for [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted your menus to fade when you mouse over them? With jQuery, copy this code into your page and run it when the DOM is ready (That means wrapping it with <code>$(function(){ ... });</code> to use jQuery&#8217;s $(document).ready() function).</p>
<p>Replace <code>#nav li</code> below with whatever your navigation items are.</p>
<pre class="syntax-highlight:js">
$(&quot;#nav li&quot;).hover(function(){ //add an event listener for hover on the li nodes
$(this).fadeOut(0); // fade them to white immediately
},function(){
$(this).fadeIn(&quot;slow&quot;); // fade them to their original color our mouse out
});
</pre>
<p>To extend this, you could use the jQuery animate function, along with the <a href="http://plugins.jquery.com/project/color">color</a> plug in to just fade the background color and not the text itself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.createopen.com/blog/2008/09/fading-menus-in-5-lines-of-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Making a bookmarklet to swap images with jQuery</title>
		<link>http://www.createopen.com/blog/2008/05/making-a-bookmarklet-to-swap-images-with-jquery/</link>
		<comments>http://www.createopen.com/blog/2008/05/making-a-bookmarklet-to-swap-images-with-jquery/#comments</comments>
		<pubDate>Tue, 06 May 2008 17:51:52 +0000</pubDate>
		<dc:creator>David Hulbert</dc:creator>
		
		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.createopen.com/blog/?p=3</guid>
		<description><![CDATA[Here's a rough guide on making a bookmarklet to change the images in a
page on hover.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a rough guide on making a bookmarklet to change the images in a page on hover. This looks for images with &#8220;without&#8221; in the src and replaces them with &#8220;with&#8221;. For example, <code>&lt;img src="a-without.jpg"&gt;</code> becomes <code>&lt;img src="a-with.jpg"&gt;</code>. This is useful for testing new versions of an image on a page.<br />
First, the jQuery:</p>
<pre class="syntax-highlight:js">
jQuery(&quot;img[@src*=without]&quot;).hover(
  function(){
    withLink=jQuery(this).attr(&quot;src&quot;).replace(&#039;without&#039;,&#039;with&#039;);
    jQuery(this).attr(&quot;src&quot;,withLink);
  },
  function(){
    withOutLink=jQuery(this).attr(&quot;src&quot;).replace(&#039;with&#039;,&#039;without&#039;);
    jQuery(this).attr(&quot;src&quot;,withOutLink);
  }
);
</pre>
<p>Second, wrap it in javascript:(function(){ &#8230; })() and remove the<br />
whitespace:</p>
<pre class="syntax-highlight:js">javascript:(function(){jQuery(&quot;img[@src*=without]&quot;).hover(function()
{withLink=jQuery(this).attr(&quot;src&quot;).replace(&#039;without&#039;,&#039;with&#039;);jQuery(this).attr(&quot;src&quot;,withLink);},function()
{withOutLink=jQuery(this).attr(&quot;src&quot;).replace(&#039;with&#039;,&#039;without&#039;);jQuery(this).attr(&quot;src&quot;,withOutLink);})})
()</pre>
<p>Save this as a bookmark and click on it on any page with jQuery.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.createopen.com/blog/2008/05/making-a-bookmarklet-to-swap-images-with-jquery/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Welcome to CreateOpen</title>
		<link>http://www.createopen.com/blog/2008/04/hello-world/</link>
		<comments>http://www.createopen.com/blog/2008/04/hello-world/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 16:36:07 +0000</pubDate>
		<dc:creator>David Hulbert</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.createopen.com/blog/?p=1</guid>
		<description><![CDATA[Hello people.
Here you&#8217;ll soon see posts about web development, specifically:

Web standards
JavaScript
CSS
PHP

]]></description>
			<content:encoded><![CDATA[<p>Hello people.</p>
<p>Here you&#8217;ll soon see posts about web development, specifically:</p>
<ul>
<li>Web standards</li>
<li>JavaScript</li>
<li>CSS</li>
<li>PHP</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.createopen.com/blog/2008/04/hello-world/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
