<?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>Feet Have Been &#187; Tutorials</title>
	<atom:link href="http://wheremy.feethavebeen.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://wheremy.feethavebeen.com</link>
	<description>Sometimes, you just go where your feet take you</description>
	<lastBuildDate>Tue, 17 Aug 2010 13:40:50 +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>Custom Select Element</title>
		<link>http://wheremy.feethavebeen.com/2010/08/custom-select-element/</link>
		<comments>http://wheremy.feethavebeen.com/2010/08/custom-select-element/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 22:04:59 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Concepts]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[dropdown]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[form]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=475</guid>
		<description><![CDATA[Since the post on styling the input box I thought I&#8217;d post a another method to create custom drop-down lists. Again, most browsers won&#8217;t let you do very much in the way of styling. IE lets you mess with scrollbars and gecko and webkit let you adjust line-heights and padding, but really, you are STILL [...]]]></description>
			<content:encoded><![CDATA[<p>Since the post on styling the input box I thought I&#8217;d post a another method to create custom drop-down lists. Again, most browsers won&#8217;t let you do very much in the way of styling. IE lets you mess with scrollbars and gecko and webkit let you adjust line-heights and padding, but really, you are STILL left with the default select. However, utilizing some html, css and JavaScript (through jQuery) we can have our own pretty nifty looking drop down. This is part of a UI suite I&#8217;m hoping to work on called Clair. </p>
<div id="attachment_481" class="wp-caption aligncenter" style="width: 310px"><a href="http://wheremy.feethavebeen.com/wp-content/uploads/2010/08/all-browser.png"><img src="http://wheremy.feethavebeen.com/wp-content/uploads/2010/08/all-browser-300x260.png" alt="" title="Custom dropdown" width="300" height="260" class="size-medium wp-image-481" /></a><p class="wp-caption-text">Custom Dropdown</p></div>
<p>The functionality of our drop-down will mimic that of a regular dropdown box with one exception. Since we can not style the scrollbar, our drop-down will never display one. Instead, it will just keep expanding as you add new links. </p>
<p><strong>HTML</strong><br />
To start off with, our select needs a few different elements to work properly. First off, we need a container that will hold our select. We will also require a list of elements that we want to appear when you click the drop-down. Finally, we need a default element to hold the current selected item and an arrow to signify that we can click on it to display more options. I&#8217;ve assigned the classes and Id&#8217;s to the elements as necessary. <code>clair-select-active</code> is the default item that will be displayed as well as what is displayed when an element is clicked on.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;clair-select-container&quot;&gt;
  &lt;div class=&quot;clair-select&quot;&gt;
    &lt;div id=&quot;clair-select-active&quot;&gt;Where My.Feet Have Been&lt;/div&gt;
    &lt;ul class=&quot;clair-select-links&quot;&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Nookish&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Orange Pine Co&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Where My.Feet Have Been&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Your Website&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p><strong>CSS</strong><br />
Before we get to the clair specific styles, these are the default ones applied to the entire page:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> Arial<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> 
  <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">14pt</span><span style="color: #00AA00;">;</span> 
  <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'bg.png'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> 
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
a <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The first style we get is the <code>clair-select</code> and the <code>clair-select-container</code> These style our entire select container.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.clair-select-container<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.clair-select</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span> 
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</span>
  -moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
  -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
  -o-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
  -khtml-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
  border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span> <span style="color: #933;">12px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#555</span><span style="color: #00AA00;">;</span> 
  <span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">230px</span><span style="color: #00AA00;">;</span>
  -moz-box-sizing<span style="color: #00AA00;">:</span> border-box<span style="color: #00AA00;">;</span>
  box-sizing<span style="color: #00AA00;">:</span> border-box<span style="color: #00AA00;">;</span>
  opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0.7</span><span style="color: #00AA00;">;</span>
  filter<span style="color: #00AA00;">:</span> alpha<span style="color: #00AA00;">&#40;</span>opacity <span style="color: #00AA00;">=</span> <span style="color: #cc66cc;">70</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The purpose of <code>clair-select-container</code> is to make sure when we expand our select dropdown it doesn&#8217;t push elements out of the way. Instead of floats nicely above them, and our slight opacity setting will display a faint outline of what it&#8217;s coverting. </p>
<p>There is a lot of vendor specific styling going on in <code>clair-select</code>, but the only one that I think warrants explanation is <code>box-sizing</code> and <code>filter</code>. </p>
<ul>
<li><code>box-sizing</code>: is a CSS3 spec that allows us to change the way that the browser interprets the &#8220;box-model&#8221; I&#8217;ll have to do another post to fully explain the box-model, but essentially it is the difference between including padding and border sizes within the &#8220;width&#8221; element, or adding it on afterwards. This forces Firefox to render the box-model the way Internet Explorer would  <a class="simple-footnote" title="The IE way, takes your width and keeps your content that size, and adds borders and padding within it" id="return-note-475-1" href="#note-475-1"><sup>1</sup></a>. </li>
<li><code>filter</code>: is a <a href="http://msdn.microsoft.com/en-us/library/ms532847(VS.85).aspx">Microsoft proprietary spec</a> that allows us to use a number of IE only effects. The particular effect I am utilizing is alpha-blending which allows us to change the opacity of the element. I&#8217;ve turned the opacity done just a little so that things are still readable, while allowing us to see the background. This has the added benefit of a neat visual effect whereby it looks like our element is slightly inset.</li>
</ul>
<p>The next style we&#8217;re going to add is that of the active element. All we do here is add the arrow as a background image and position it to appear on the right side of the element.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#clair-select-active</span><span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'down.png'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> 
  <span style="color: #000000; font-weight: bold;">background-repeat</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Finally, we&#8217;re going to style all the links. Nothing too fancy here. We&#8217;re just getting rid of bullets, spacing everything out a little and treating the anchor tags as block elements within our li&#8217;s.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.clair-select-links</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> 
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.clair-select-links</span> li<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.clair-select-links</span> li a<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span> 
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.clair-select-links</span> li a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#282828</span><span style="color: #00AA00;">;</span>
  -moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">8px</span><span style="color: #00AA00;">;</span>
  -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">8px</span><span style="color: #00AA00;">;</span>
  -o-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">8px</span><span style="color: #00AA00;">;</span>
  -khtml-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">8px</span><span style="color: #00AA00;">;</span>
  border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">8px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#DDD</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><strong>JavaScript</strong><br />
To add functionality to our drop-down we need a bit of JavaScript. I&#8217;m utilizing jQuery, but your own JavaScript library should have similar functions. We need to add two kinds of functionality. </p>
<ol>
<li>We need to switch between minimized and maximized states whenever a user clicks on the <code>clair-select-active</code> element.</li>
<li>We need to switch to minimized and populate <code>clair-select-active</code> with the text from the menu item</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">$(document).ready(function(e) {
  // This is just for cross-browser prettiness
  $('#clair-select-active').css('cursor','pointer');
&nbsp;
  // This will toggle everything as necessary
  $('#clair-select-active').click(function(e) {
    if($('.clair-select-links').css('display') == 'block') {
      $('.clair-select-links').slideUp(); 
    }
    else {
      $('.clair-select-links').slideDown();
    }
  });
&nbsp;
  // This will populate clair-select-active with whatever you click on
  $('.clair-select-links a').click(function(e) {
    e.preventDefault(); 
    $('#clair-select-active').html($(this).html()); 
    $('.clair-select-links').slideUp(); 
  });
});</pre></div></div>

<p>And that&#8217;s it, you&#8217;ve built a custom select drop-down. With a little JavaScript trickery, we can even go so far as to include it within forms. We&#8217;d just need a hidden form element and then when we populate <code>clair-select-active</code> we would also populate the value attribute of our form element.</p>
<p>This solution works in the following scenarios: </p>
<ul>
<li>IE 7+</li>
<li>Firefox 3.5+</li>
<li>Chrome 3+</li>
<li>Opera 10+</li>
</ul>
<p>You can download all the files used in this tutorial here: <a href='http://wheremy.feethavebeen.com/wp-content/uploads/2010/08/custom-select.zip'>Custom Select Files</a></p>
<div class="simple-footnotes"><p class="notes">Notes:</p><ol><li id="note-475-1">The IE way, takes your width and keeps your content that size, and adds borders and padding within it <a href="#return-note-475-1">&#8617;</a></li></ol></div>]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2010/08/custom-select-element/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inconsistencies with File Upload</title>
		<link>http://wheremy.feethavebeen.com/2010/08/inconsistencies-with-file-upload/</link>
		<comments>http://wheremy.feethavebeen.com/2010/08/inconsistencies-with-file-upload/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 03:17:21 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[file upload]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=456</guid>
		<description><![CDATA[Before I even begin I want to state that this shouldn&#8217;t be used as a definitive source for this information. I am utilizing an older version of Firefox (3.0) and IE7 for all my tests. I can&#8217;t vouch for Chrome, Opera or Safari&#8217;s take on any of this, but I gather that it is much [...]]]></description>
			<content:encoded><![CDATA[<p>Before I even begin I want to state that this shouldn&#8217;t be used as a definitive source for this information. I am utilizing an older version of Firefox (3.0) and IE7 for all my tests. I can&#8217;t vouch for Chrome, Opera or Safari&#8217;s take on any of this, but I gather that it is much the same.</p>
<p>At some point in your web programming or web design career you will inevitably encounter the dreaded file upload &#8220;utility&#8221;. This piece of crap, is only present to allow users to select a file on their machine and eventually transfer it to your servers. Of course, this is a vital piece now, but perhaps at the time it was something that was easily overlooked. After all, at a time when your ISP speeds were approaching the 14.4kbps mark, uploading files was really something only the computer geeks did. </p>
<p>Now however, with profile pictures, online resumes, cloud storage and so much more, the file upload feature is front and center. Some places have gone so far as to eliminate the default HTML object and instead go with a Flash equivalent. This doesn&#8217;t really fix the issue, it&#8217;s like me saying &#8220;oh your computer doesn&#8217;t work? Here, use my iPad&#8221; <a class="simple-footnote" title="I really don&#8217;t have one http://wheremy.feethavebeen.com/2010/02/blagging-about-the-ipad/" id="return-note-456-1" href="#note-456-1"><sup>1</sup></a> It&#8217;s just a bypass. We need to fix this now! It&#8217;s already too late, we&#8217;re just playing catch up.</p>
<p><strong>Understanding the Process</strong><br />
File uploading is one of those features that, if you&#8217;re unlucky, you&#8217;ll have to design a layout around. That&#8217;s because, for some reason, every browser has decided that the File upload object is completely immune to CSS. No amount of styling can ever achieve what you want. It will always look like ass.</p>
<div id="attachment_470" class="wp-caption aligncenter" style="width: 295px"><a href="http://wheremy.feethavebeen.com/wp-content/uploads/2010/08/file-upload.png"><img src="http://wheremy.feethavebeen.com/wp-content/uploads/2010/08/file-upload.png" alt="File upload in Firefox and IE" title="File upload in Firefox and IE" width="285" height="266" class="size-full wp-image-470" /></a><p class="wp-caption-text">File upload in Firefox and IE</p></div>
<p>There is no easy way to style it, there is no way to replace it (unless you use flash, but that&#8217;s a whole different issue) and the only way to get around it is to hide it or integrate it directly into your design. There is absolutely no way to pretty it up. You can&#8217;t adjust the size of the button or the size of the input box. You are essentially stuck, with what you see. No way around it. Or is there? </p>
<p>Short of changing your entire design to work with default form elements (euych!) the only way to fix the file upload feature is to hide it completely. See, because we can still apply some style features to an encapsulating element <a class="simple-footnote" title="A div that contains the file upload field, for example" id="return-note-456-2" href="#note-456-2"><sup>2</sup></a>. So we could technically just hide the entire form field, and absolutely position it over our custom designed field. If we do it all right (we WILL have to use either a custom IE stylesheet or a bunch of hacks) we can make it look like our pretty file upload field is actually doing the work!</p>
<p><strong>The Code</strong><br />
The code for this is primarily CSS with some JavaScript sprinkled in to make sure that everything is positioned where it should be. I am utilizing the jQuery library for a lot of this simply because I use it in a lot of my projects. If you use any other libraries, they should all have equivalent methods and if they don&#8217;t, you should ditch them and switch to something else. If you are trying to follow along in straight JavaScript good luck. One of the primary reasons I work with a JavaScript library is because of cross browser inconsistencies. With a library, I can be sure that someone has gone through the painstaking task of setting up different kinds of math and implementation for the different browsers.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;File Upload&lt;/title&gt;
  &lt;style type=&quot;text/css&quot;&gt;
&nbsp;
  &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;fake-file&quot;&gt;
  &lt;input type=&quot;text&quot; id=&quot;fake-file-title&quot; name=&quot;fake_file_title&quot; value=&quot;&quot;&gt;
  &lt;button&gt;Browse&lt;/button&gt;
&lt;/div&gt;
&lt;div id=&quot;file-constraint&quot;&gt;
  &lt;input type=&quot;file&quot; id=&quot;real-file&quot;&gt;
&lt;/div&gt;
&nbsp;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>The CSS below is what we will be using to style our new input fields.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#fake-file</span> input <span style="color: #00AA00;">&#123;</span>
    -moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> 
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#555</span><span style="color: #00AA00;">;</span> 
    -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> 
    -o-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> 
    -khtml-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> 
    border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
  <span style="color: #cc00cc;">#fake-file</span> button <span style="color: #00AA00;">&#123;</span>
    -moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> 
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#555</span><span style="color: #00AA00;">;</span> 
    -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> 
    -o-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> 
    -khtml-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> 
    border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">8px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FFF</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Now it&#8217;s as simple as adding some positioning values to our file-constraint field. We will also alter the z-index and position it higher vertically than our fake file upload. Then we can simply utilize some JavaScript to make things work like it should.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#file-constraint</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> 
<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> 
<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Bam instant hidden. Based on the position of your actual fake file field the top/left attributes will obviously change. The JavaScript is just as simple. I am utilizing jQuery to hook in to the onChange event for the real-file field, but it&#8217;s not necessary. You can do the same without a library. I just prefer jQuery because it means I can target all browsers the exact same way.</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">$('#real-file').change(function(e) {
var str = $(this).val(); 
str = str.split('\\')[str.length-1]; 
$('#fake-file-title').val(str);
});</pre></div></div>

<p>Basically we get the value of the file upload field. In Firefox this is just the name of the file, while in IE it contains the complete path to the file. I prefer stripping out the path, but that is up to you. Basically the value from the real file field is just assigned to the fake file field. </p>
<p>Working with file uploads are a hassle and this really only covers a portion of the client-side. There are still many things to take into account such as temporary file locations, file permissions, fake-ajax / standard uploading etc. This tutorial isn&#8217;t meant to be a complete compendium of all things file uploading, but merely to point out some annoying UI inconsistencies. </p>
<div class="simple-footnotes"><p class="notes">Notes:</p><ol><li id="note-456-1">I really don&#8217;t have one <a href="http://wheremy.feethavebeen.com/2010/02/blagging-about-the-ipad/">http://wheremy.feethavebeen.com/2010/02/blagging-about-the-ipad/</a> <a href="#return-note-456-1">&#8617;</a></li><li id="note-456-2">A div that contains the file upload field, for example <a href="#return-note-456-2">&#8617;</a></li></ol></div>]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2010/08/inconsistencies-with-file-upload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some useful array functions for JavaScript</title>
		<link>http://wheremy.feethavebeen.com/2010/07/some-useful-array-functions-for-javascript/</link>
		<comments>http://wheremy.feethavebeen.com/2010/07/some-useful-array-functions-for-javascript/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 20:40:43 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=450</guid>
		<description><![CDATA[JavaScript is a great language. There was a time when I was rather against it (mainly during the browser wars) but with modern libraries and the like, cross browser processing is exactly where it should be. However, there are a lot of times when you just need some simple processing done and most libraries &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript is a great language. There was a time when I was rather against it (mainly during the browser wars) but with modern libraries and the like, cross browser processing is exactly where it should be. However, there are a lot of times when you just need some simple processing done and most libraries &#8211; even their cores &#8211; are too bloated to be of any use.  Below I&#8217;ve outlined three functions has(), indexOf() and remove() that extend the existing Array prototype to add some much needed features.</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">Array.prototype.indexOf = function(val) {
	for(i = 0; i &lt; this.length; i++) {
		if(this[i] == val) {
			return i; 
		}
	}
	return -1;
};
&nbsp;
Array.prototype.has = function(val) {
	return this.indexOf(val) &gt; 0 ? true:false;
};
&nbsp;
Array.prototype.remove = function(val) {
	var x = this.indexOf(val), y = 0;
	for(i = 0; i &lt; this.length; i++) {
		if(i != x) {
			this[y]= this[i];
			y++;
		}
	}
	this.pop();
};</pre></div></div>

<p><strong>indexOf()</strong><br />
Often times you have a string and you need to figure out where in the array it appears. Since JavaScript doesn&#8217;t technically support associative arrays (array object conversion does occur implicitly) you can either loop through the array every time, or just extend array!</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">Example for indexOf()
var myArray = [&quot;an&quot;,&quot;array&quot;,&quot;with&quot;,&quot;a&quot;,&quot;bunch&quot;,&quot;of&quot;,&quot;words&quot;]; 
document.Write(myArray.indexOf(&quot;a&quot;));   // returns 3
document.Write(myArray.indexOf(&quot;491&quot;));  // returns -1</pre></div></div>

<p><strong>has()</strong><br />
Sometimes you just need to know if a value is present within an array. has() takes care of that returning a simple true:false boolean. Rather than re-inventing the wheel, it works in conjunction with indexOf()</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">Example for has()
var myArray = [&quot;an&quot;,&quot;array&quot;,&quot;with&quot;,&quot;a&quot;,&quot;bunch&quot;,&quot;of&quot;,&quot;words&quot;]; 
document.Write(myArray.has(&quot;with&quot;)); // returns true
document.Write(myArray.has(&quot;feet&quot;)); // returns false</pre></div></div>

<p><strong>remove()</strong><br />
Finally, sometimes removing a single element from an array is necessary.</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">Example for remove()
var myArray = [&quot;an&quot;,&quot;array&quot;,&quot;with&quot;,&quot;a&quot;,&quot;bunch&quot;,&quot;of&quot;,&quot;words&quot;]; 
myArray.remove(&quot;array&quot;); // myArray now contains [&quot;an&quot;,&quot;with&quot;,&quot;a&quot;,&quot;bunch&quot;,&quot;of&quot;,&quot;words&quot;]</pre></div></div>

<p>Hopefully the functions are of help! If there are a lot of people confused over Prototypal Inheritance, maybe that would be an interesting topic.</p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2010/07/some-useful-array-functions-for-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DataGrid Control V2</title>
		<link>http://wheremy.feethavebeen.com/2010/07/datagrid-control-v2/</link>
		<comments>http://wheremy.feethavebeen.com/2010/07/datagrid-control-v2/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 02:43:04 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[Controls]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Project]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[datagrid]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=400</guid>
		<description><![CDATA[I&#8217;ve been working on a series of &#8220;Control Objects&#8221; to include in my usual projects, and I thought I&#8217;d post one of the completed ones up here. Basically it mimcs the use of the DataGrid control in Visual Studio but in a way I find a lot easier and more in-tune with PHP. After creating [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a series of &#8220;Control Objects&#8221; to include in my usual projects, and I thought I&#8217;d post one of the completed ones up here. Basically it mimcs the use of the DataGrid control in Visual Studio but in a way I find a lot easier and more in-tune with PHP. After creating the DataGrid, you define a &#8220;source&#8221;. The Source is essentially a multi-dimensional array that you could assign with a simple</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>you would then pass $r as the source to the DataGrid. You have the ability to set some options (like specifying specific style sheets, JS libraries for AJAX editing or defining and renaming visible columns) and then a single build(); command will output the table. Of course, you can also build(true); to return the table incase you&#8217;re using some sort of theme system.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'f_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Angelo'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'l_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Rodrigues'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'f_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Darth'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'l_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Vader'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'f_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Luke'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'l_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Skywalker'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'f_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Han'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'l_name'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'Solo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$DataGrid</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DataGrid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$DataGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">configure</span><span style="color: #009900;">&#40;</span>
  <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'primary_key'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">'sortable'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">'striped'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'even_row'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">'odd_row'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'striped'</span>
    <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// This not only defines display fields, but the order as well </span>
<span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
  <span style="color: #0000ff;">'f_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'First Name'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'l_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Last Name'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$DataGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDisplayFields</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$DataGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Headers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'css'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'js'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'object'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'js'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$DataGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">source</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000088;">$DataGrid</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">build</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The code can be further simplified by using a new class called ControlObjectManager (or COM for short). COM can be used to instantiate multiple Controls at once and even assign shortcuts to commonly used Controls. For example, if you need DataGrids a lot, you can initiate them via a simple call like <code>$COM->init(array('dg'))</code> and as long as you set up that dg means DataGrid in the configuration for COM, you&#8217;re good to go. </p>
<p>I&#8217;ll post up some more on the COM when it&#8217;s done, but for now, here&#8217;s a link to the latest iteration of DataGrid v2. </p>
<p><a href="http://pastebin.com/nD969RJp">View on Pastebin</a> &#8211; Just note that this is the debug version of the script, so there are tons of comments and explanations.</p>
<p>The original DataGrid actually tied in to MySql directly and required the MySqlAdapter control to even function. This latest iteration removes all ties to any database instead focusing on a simple multi-dimensional array of data. As well it drops the code-base down quite a bit and condenses a lot of functionality. For example: originally you would have had to set the display columns and then order them, but by compressing them into a single function it not only makes MORE sense, but is easier to read.</p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2010/07/datagrid-control-v2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Search array for Substring</title>
		<link>http://wheremy.feethavebeen.com/2010/07/search-array-for-substring/</link>
		<comments>http://wheremy.feethavebeen.com/2010/07/search-array-for-substring/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 14:56:22 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[Search]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=397</guid>
		<description><![CDATA[Occasionally you&#8217;ll need to create some sort of auto-complete field. While you could power this entirely via AJAX requests on a per-character basis, with limited resources, you may want to look at this alternative. Essentially you&#8217;ll create a javascript array containing allowed values. Whenever a user types in some characters, we can use some regex [...]]]></description>
			<content:encoded><![CDATA[<p>Occasionally you&#8217;ll need to create some sort of auto-complete field. While you could power this entirely via AJAX requests on a per-character basis, with limited resources, you may want to look at this alternative.</p>
<p>Essentially you&#8217;ll create a javascript array containing allowed values. Whenever a user types in some characters, we can use some regex coupled with a quick iteration to see if whatever the user entered is valid. If it is, we can easily return the matched values.</p>
<p>The function below is written in straight JavaScript. I monitor my keypress events via jQuery, but any way you want to do it is fine. Just make sure you call arrayFind() with the string you want to find and the array you want to search in.</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">function arrayFind(needle,haystack) {
var matchList = [];
var regex = new RegExp(needle,'gi');
for(i in haystack) {
	if(haystack[i].match(regex)) {
		matchList[matchList.length] = haystack[i];
	}
}
return matchList;
}</pre></div></div>

<p>If you didn&#8217;t need to use a variable for the regex you could eliminate that line and just use /searchterm/gi for a global case-insensitive search of the array. Since we are however, we need to make use of the RegExp object.</p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2010/07/search-array-for-substring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Model &#8211; View &#8211; Controller</title>
		<link>http://wheremy.feethavebeen.com/2010/06/model-view-controller/</link>
		<comments>http://wheremy.feethavebeen.com/2010/06/model-view-controller/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 19:45:50 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[Concepts]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=377</guid>
		<description><![CDATA[The Model-View-Controller (MVC) paradigm of programming is one that is often misused by most developers because it is simply the least understood. When reading tutorials on MVC principles most developers will launch right into the code, which is easy to follow for the purpose of the tutorial. But when those same users try and do [...]]]></description>
			<content:encoded><![CDATA[<p>The Model-View-Controller (MVC) paradigm of programming is one that is often misused by most developers because it is simply the least understood. When reading tutorials on MVC principles most developers will launch right into the code, which is easy to follow for the purpose of the tutorial. But when those same users try and do it themselves, they find out that it&#8217;s a lot harder than it seems. This post aims to correct that by explaining the principles behind the MVC framework and the pro&#8217;s and con&#8217;s of using it.</p>
<p>In web development, every page will have it&#8217;s own Model, View and Controller. This is to ensure that only the information you are requesting is loaded. A lot of those new to the MVC approach will attempt to create a master controller which will then delegate this information to each Model as requested. In MVC, this approach doesn&#8217;t quite work. By creating separate entities for each requested page you will find that not only is it easier to maintain and update, but that MVC isn&#8217;t that hard to understand at all.</p>
<p><strong>The Big Picture<br />
</strong>The easiest way to understand MVC is to step back and look at the whole picture in terms of real-life. In this example, our Controller is going to be the Librarian, the Model is going to be the Library Catalogue and the View is going to be a Book. A user will come up to the Librarian and say &#8220;Hey, do you have Book XYZ?&#8221; The Librarian of course has no idea. It&#8217;s not their job to know where each Book is, but simply to know where to find the information that you are requesting. Regardless of what you are requesting the Librarian will look through a Library Catalogue, but they may look in different kinds of Catalogues. For example, if you say &#8220;Hey, do you have the Horror Book XYZ?&#8221; they can ignore every other category except Horror. Likewise if you say &#8220;Hey, do you have the Romance Book XYZ?&#8221; they can ignore every other category except Romance.</p>
<p><strong>The Pieces of the Puzzle &#8211; The Controller<br />
</strong>The Controller the is the primary building block of an MVC system. Everything you build is managed by the Controller (it Controls see? Programmers love these little word games). The Controller figures out what the user is trying to do and accordingly it goes through the appropriate Model and returns those results to the appropriate View. You can think of the Controller as a messenger. Basically when the user visits a page they are saying &#8220;I would like to see the [Gallery] page&#8221;. The Gallery Controller will see this and go right over to the GalleryModel and say &#8220;The user has requested this information&#8221;. It then waits for GalleryModel to respond, and then it takes those results and runs over to GalleryView and goes &#8220;Pretty this up&#8221;. It then shows you the prettied-up version.</p>
<p><strong>The Model<br />
</strong>The Model is also known as your Data Manipulation layer. This should contain functions that interface with the database. Insertion, Updating and Deletion should all occur here, with the results of each passed back to the caller. This centralizes all your DB calls to a single file for a single controller. In this way you know that modifying your &#8220;Gallery&#8221; table means only modifying your GalleryModel and GalleryView. It doesn&#8217;t seem like a big issue to inter-twine your database manipulation and controller at this stage simply because it isn&#8217;t. Of course you can integrate your Model directly with the Controller, but by segmenting these you can ensure a much easier re-use of code. Think about it this way &#8211; a gallery model can be copied and modified a little to turn it into a blog model. Since the Model doesn&#8217;t care about what to DO with the fields, you just need to update what fields it SHOULD be dealing with.</p>
<p><strong>The View<br />
</strong>The View is the easiest piece to explain. It simply acts as a display mechanism. It accepts some values from the Controller, mixes it with HTML and spits the result back to the controller. Think of it is a node-based theme engine. For example, you could have a function in your GalleryView that just accepted the URL of a thumbnail and added some HTML which, when styled, made it resemble a Polariod. At a later point in time, if you want to change this, modifying this single function will ensure that everything is changed uniformly.</p>
<p><strong>The Big Picture &#8211; Now with the right words<br />
</strong>So now we can revisit our Librarian and ask for a new book. We ask the LibraryController for &#8220;Horror book XYZ&#8221;. The LibraryController invokes the LibraryModel and executes the findBook() function passing it the genre (horror) and book name (XYZ). The LibraryModel executes a quick Database Query to figure out the results. Just so happens there are 5 books in that genre that contain XYZ (XYZ, WXYZ, AXYZ, XYZZ, XXYZ). It passes the result set BACK to LibraryController. LibraryControlled takes the result set and invokes LibraryView, calling the formatBookList() function using the result set as the argument. formatBookList() adds some HTML mockup to each entry and makes everything look good and then passes the HTML back to LibraryController. LibraryController shows you the result.</p>
<p><strong>Variations<br />
</strong>Some descriptions of MVC will modify it so that the Controller ignores the view and instead the Model is what passes the data to the View. Either way still conforms with MVC standards, which really just involve separting everything.</p>
<p><strong>Advanced Concepts</strong></p>
<p><strong><br />
Routers<br />
</strong>When dealing with server-side languages on the web we have to remember that things don&#8217;t work the same as in a desktop environment. Event-driven programming may work fine for C# and Java, but doesn&#8217;t work the same way for PHP. In PHP, our equivalent fo Event-driven programming would be URL-based programming. An &#8220;event&#8221; as far as PHP is concerned, is the user trying to visit a page. This page should trigger some kind of action. In most MVC frameworks (all I would think), you get something called a &#8220;Router&#8221;. This Router class is essentially a way of registering URLS to certain Controllers. For example visiting www.example.com/gallery/view/48 would cause the Router (or page that invokes the Router) to invoke the GalleryController and make a call to the view() function passing it 48 as an argument. In this way they abstract away explicitly invoking galleryies and can have a single index.php page which invokes the Router and makes the calls as necessary.</p>
<p><strong>Multiple Inheritance<br />
</strong>While PHP doesn&#8217;t allow for Multiple inheritance (ie GalleryController extends c1, c2, c3) it does allow for cascading inheritance (GalleryController extends c3; c3 extends c2; c2 extends c1; and now GalleryController can do everything c1, c2 and c3 can). Because of this we can actually speed up our Model/Controller creation by extending a singple base Model or Controller class. These classes would ideally have common functions that all Models or Controllers could potentially need at some point. One example would be to force all Models to inherit from BaseModel which could be a custom created Database Manipulation functions that all Models would need.</p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2010/06/model-view-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aggro Detection with Javascript</title>
		<link>http://wheremy.feethavebeen.com/2009/12/aggro-detection-with-javascript/</link>
		<comments>http://wheremy.feethavebeen.com/2009/12/aggro-detection-with-javascript/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 14:00:35 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[Concepts]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=358</guid>
		<description><![CDATA[So you want to make some games? Sure it sounds easy, but until you dive into it you&#8217;ll never notice all the little things that go into the backend of it that make or break your game. While this isn&#8217;t as big a deal in current browser-based games (they&#8217;re either muds, flash or static maps) [...]]]></description>
			<content:encoded><![CDATA[<p>So you want to make some games? Sure it sounds easy, but until you dive into it you&#8217;ll never notice all the little things that go into the backend of it that make or break your game. While this isn&#8217;t as big a deal in current browser-based games (they&#8217;re either muds, flash or static maps) things are changing in the browser. Everything is getting faster, and things like javascript based animation is actually feasible! So what is an aspiring game developer to do except buckle in and start programming their games?</p>
<p>Once you begin researching you&#8217;ll notice that while a lot of browser-based text games take into account Collision detection, they seem to be missing Aggro detection. Aggro stands for either aggravation or aggression and is essentially a way to tell if a monster will attack you or not.. As you&#8217;ve probably noticed some monsters tend to rush at you from across the map, while others seem to completely ignore you until you attack them. This is Aggro.</p>
<p>One of the easiest ways to detect aggro is to simply add a variable to your monsters to signify &#8220;sight&#8221;. This sight variable will dictate how far away you need to be before a monster will attack you. Set this to 100 to have a monster rush at you from across your map or set it to 0 so that it will never attack unless you attack first.</p>
<p>Detection aggro is as simple as following two formula&#8217;s. The first will be to figure out the distance between you and the monster and the second will simply be a quick check to see if you fall within the monsters aggro radius. To start off, you need to grab the <a href="http://www.jquery.com">jQuery</a> javascript framework. While you CAN do this from scratch, jQuery lets you do it a lot easier, plus you can probably add a bit more jazz to your current game if you&#8217;re not already using it. If you&#8217;re unsure of how jQuery works, take a look at our quick <a href="http://wheremy.feethavebeen.com/2009/11/jquery-primer-an-intro-to-client-side-functionality/">intro to jQuery</a> or just check out the <a href="http://docs.jquery.com/Main_Page">jQuery documentation</a>. Now just cobble together a quick webpage and include the jQuery library. I&#8217;m using the minified version 1.3.2 of jQuery, so if you&#8217;re not using the same one, make sure you replace that line.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Collision Detection&lt;/title&gt;
	&lt;style type=&quot;text/css&quot;&gt;
	table#grid{
		border-style: solid; 
		border-width: 0px 1px 1px 0px; 
		border-color: #CCC; 
		padding: 0px;
	}
	table#grid tr th{
		border-style: solid; 
		border-width: 1px 0px 0px 1px; 
		border-color: #CCC; 
		text-align: center; 
		color: #333; 
		font-size: 0.7em; 
		font-weight: bold; 
		font-family: &quot;Arial&quot;;
		background-color: #EDEDED;
	}
	table#grid tr th.run{
		width: 12px;
	}
	table#grid tr td{
		width: 50px; 
		height: 50px; 
		border-style: solid; 
		border-width: 1px 0px 0px 1px; 
		border-color: #CCC; 
		text-align: center; 
		color: #E0E0E0; 
		font-size: 0.7em; 
		font-weight: normal; 
		font-family: &quot;Arial&quot;;
	}
	table#grid tr td:hover{
		color: #333;
		background-color: #F3F3F3;	
	}
	.player{
		background-color: #333; 
	}
	.monsterA{
		color: #333; 
		background-color: #AA0000;
	}
	div#debug{
		border-style: solid; 
		border-color: #333; 
		border-width: 1px; 
		float: right; 
		border-color: #EDEDED;
		text-align: left; 
		color: #333; 
		font-size: 0.9em; 
		font-weight: normal; 
		font-family: &quot;Arial&quot;;
		width: 300px; 
		padding: 10px;
	}
	.monsterN{
		background-color: #00AA00;
	}
	&lt;/style&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&nbsp;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>You&#8217;ll notice a bunch of CSS in there, but you can ignore that. It&#8217;s pretty straight forward and really it&#8217;s just meant to pretty things up a little. Now we&#8217;re going to add a quick grid so that you can get an easy visual representation of where you are and where your monsters are and if they will aggro or not. You can copy and paste the following line a few times, and change the y coordinate (x,y) to match which row you&#8217;re on.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;tr&gt;
	&lt;td&gt;0,1&lt;/td&gt;&lt;td&gt;1,1&lt;/td&gt;&lt;td&gt;2,1&lt;/td&gt;&lt;td&gt;3,1&lt;/td&gt;&lt;td&gt;4,1&lt;/td&gt;&lt;td&gt;5,1&lt;/td&gt;&lt;td&gt;6,1&lt;/td&gt;&lt;td&gt;7,1&lt;/td&gt;&lt;td&gt;8,1&lt;/td&gt;&lt;td&gt;9,1&lt;/td&gt;
&lt;/tr&gt;</pre></div></div>

<p>Finally, I&#8217;ve just added a &#8220;debug&#8221; section, so you can get a textual representation of what&#8217;s going on. It&#8217;s just a div placed above the grid.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;debug&quot;&gt;
	&lt;b&gt;Debug&lt;/b&gt;&lt;br&gt;&lt;br&gt;
&lt;/div&gt;</pre></div></div>

<p><strong>The Code</strong><br />
Now for the code that will give us a visual representation of our player and our monsters. First off we are going to initiate a few variables that we will be using throughout our script. They&#8217;re pretty self explanatory.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> playerPlaced <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
<span style="color: #003366; font-weight: bold;">var</span> monster <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
<span style="color: #003366; font-weight: bold;">var</span> player <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now we&#8217;re going to set it up so that when we click a square it will check if our player is already placed or not. If he is NOT placed, then we are going to place him and update our &#8220;debug&#8221; section.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#grid tr td'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> distance<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>playerPlaced<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	player<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'loc'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	player<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'sight'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> 
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'@'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'player'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	playerPlaced <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span> 
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#debug'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Player: '</span><span style="color: #339933;">+</span>player<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'loc'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;br&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Notice that we&#8217;ve set player['sight'] to 0. Why? Simply because your player doesn&#8217;t have an aggro radius. He may or may not attack at your discretion, so it&#8217;s irrelevant. A monster however, will ALWAYS attack if you get within its aggro radius (assuming no other modifiers).</p>
<p>The next bit will just place our monsters if there is already a player on the field. When we do, however, we are going to call some functions that will take care of calculating distance and checking if the monster will aggro. We&#8217;ll go over those first, since they&#8217;re more complicated.</p>
<p><strong>Distance</strong><br />
To calculate the distance of two points we are simply going to take the x,y coordinates of both our monster and player and perform some math on them. The formula that we will be using is actually the distance formula between two points (and you wondered when you would ever use it&#8230;) and something that&#8217;s been drilled into us in every math class. The formula itself is a basically sqrt(sq(x1-x2)+sq(y1-y2)) so translating that to our game code it will look more like</p>
<p>sqrt(sq(player[x]-monster[x])+sq(player[y]-monster[y]))</p>
<p>The squaring and square rooting would take us a lot more work, if JavaScript didn&#8217;t already have those built in! Our actual distance formula in JavaScript (after being placed in a function) will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> getDistance<span style="color: #009900;">&#40;</span>from<span style="color: #339933;">,</span>to<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	distance <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">sqrt</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>from<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span>to<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>from<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span>to<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #000066; font-weight: bold;">return</span> distance<span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Intersection</strong><br />
Basically intersection in our scenario will take a look at the player and see if he falls within the aggro radius of the monster. It&#8217;s a very simple check that just goes if (distance &lt; aggroRad) then it will aggro.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> willAggro<span style="color: #009900;">&#40;</span>aggro<span style="color: #339933;">,</span>distance<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>distance <span style="color: #339933;">&gt;</span> aggro<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Monster Insertion</strong><br />
Finally, we&#8217;re going to do our check to see if a monster will aggro a player or not depending on its distance to the player.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">monster<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'loc'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
monster<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'sight'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> 
$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'X'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
distance <span style="color: #339933;">=</span> getDistance<span style="color: #009900;">&#40;</span>player<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'loc'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>monster<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'loc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>willAggro<span style="color: #009900;">&#40;</span>monster<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'sight'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>distance<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'monsterA'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'monsterN'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#debug'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;b&gt;Monster:&lt;/b&gt; '</span><span style="color: #339933;">+</span>monster<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'loc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#debug'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' &lt;b&gt;Distance:&lt;/b&gt; '</span><span style="color: #339933;">+</span>distance<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#debug'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' &lt;b&gt;Aggro:&lt;/b&gt; '</span><span style="color: #339933;">+</span>willAggro<span style="color: #009900;">&#40;</span>monster<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'sight'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>distance<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;br&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And that&#8217;s all there is to it. If you run this page and take a look, you&#8217;ll notice that clicking a grid will place your player and clicking anywhere else will cause the monsters to appear in either green (if too far away to aggro) or red (if it will aggro). This is also noted in the debug section!</p>
<p>Here is our completed javascript section</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> playerPlaced <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
	<span style="color: #003366; font-weight: bold;">var</span> monster <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> 
	<span style="color: #003366; font-weight: bold;">var</span> player <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#grid tr td'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> distance<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>playerPlaced<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			player<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'loc'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			player<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'sight'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> 
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'@'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'player'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			playerPlaced <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span> 
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#debug'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Player: '</span><span style="color: #339933;">+</span>player<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'loc'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;br&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
			monster<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'loc'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			monster<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'sight'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> 
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'X'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			distance <span style="color: #339933;">=</span> getDistance<span style="color: #009900;">&#40;</span>player<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'loc'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>monster<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'loc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>willAggro<span style="color: #009900;">&#40;</span>monster<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'sight'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>distance<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'monsterA'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'monsterN'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#debug'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;b&gt;Monster:&lt;/b&gt; '</span><span style="color: #339933;">+</span>monster<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'loc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#debug'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' &lt;b&gt;Distance:&lt;/b&gt; '</span><span style="color: #339933;">+</span>distance<span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#debug'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' &lt;b&gt;Aggro:&lt;/b&gt; '</span><span style="color: #339933;">+</span>willAggro<span style="color: #009900;">&#40;</span>monster<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'sight'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>distance<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;br&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> getDistance<span style="color: #009900;">&#40;</span>from<span style="color: #339933;">,</span>to<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	distance <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">sqrt</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>from<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span>to<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>from<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span>to<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #000066; font-weight: bold;">return</span> distance<span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>	
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> willAggro<span style="color: #009900;">&#40;</span>aggro<span style="color: #339933;">,</span>distance<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>distance <span style="color: #339933;">&gt;</span> aggro<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is a very simple way to check aggro and the reason I placed it in its own function was incase you needed to modify it in any way (for example if a monster was under 10 levels its aggro would be 0 always). <strong> </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2009/12/aggro-detection-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Website Instant Messenger &#8211; Client-side Functionality</title>
		<link>http://wheremy.feethavebeen.com/2009/11/simple-website-instant-messenger-client-side-functionality/</link>
		<comments>http://wheremy.feethavebeen.com/2009/11/simple-website-instant-messenger-client-side-functionality/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 05:22:58 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=319</guid>
		<description><![CDATA[This is part two of the Simple Website Instant Messenger (SWIM for short, I love it when acronyms just work themselves out) and will cover adding some client-side functionality to our system. For part 1, click here. Client-side functionality essentially translates itself to &#8220;using JavaScript to do some funcy (eh? get it? Funcy? Functional?) things&#8221;. [...]]]></description>
			<content:encoded><![CDATA[<p>This is part two of the Simple Website Instant Messenger (SWIM for short, I love it when acronyms just work themselves out) and will cover adding some client-side functionality to our system. <a href="http://wheremy.feethavebeen.com/2009/11/simple-website-instant-messenger-the-static-prototype/">For part 1, click here.</a></p>
<p>Client-side functionality essentially translates itself to &#8220;using JavaScript to do some funcy (eh? get it? Funcy? Functional?) things&#8221;. It will allow us to add a level of interaction that users are familiar with and that they come to expect from applications. We want them to have the ability to minimize or maximize the windows, as well as close them. We also want to do all of this without page refreshes. Since actions like this are on a per-session basis, we don&#8217;t need to have any server-side code to handle it. We can let the browsers do all the work for us.</p>
<p>For this section we&#8217;ll be making some heavy use of jQuery and some rather complex DOM manipulation. I&#8217;ve also opted to use the long-hand version of everything instead of shorthand. This is so that you guys will be able to read the code and such. I&#8217;ve opted to use the production version of jQuery, but if you&#8217;re just getting started, you may as well download the development version. The bonus of this is that if you&#8217;re just learning you can easily pop in to the jQuery code and see how things are done. As well, if you are using an advanced IDE (such as Dreamweaver) you&#8217;ll get full code hinting. You can do this by heading to <a href="http://jquery.com/">this website</a> and downloading the appropriate version. I also recommend that you bookmark the documentation for jQuery (<a href="http://docs.jquery.com">http://docs.jquery.com</a>) as you&#8217;ll end up using it a lot.</p>
<p>Setup jQuery in whatever folder you&#8217;ve stored the HTML/CSS file from the previous tutorial (setup is actually just copy/paste). You&#8217;ll then need to link the script in your HTML by adding the following line of code to your HTML file in the head section of the code</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script src=&quot;jquery.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>Note the src attribute contains the name of the jquery file that I am using. You may have to edit it so that the name of the file matches the name of the file you downloaded.</p>
<p>Directly below that you can add this line as well</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script src=&quot;im.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>That line of code will link to our not-yet-created javascript file which will hold all the client-side functionality for our IM script. Once that&#8217;s done you can pop open your editor and get started with the actual jQuery code. However, before we continue with the tutorial note that this is NOT a jQuery primer. This tutorial is expecting you to have some knowledge of jQuery and javascript syntax. If you do not, please read this <a href="http://wheremy.feethavebeen.com/2009/11/jquery-primer-an-intro-to-client-side-functionality/">jQuery primer tutorial</a> first before continuing.</p>
<p>The first thing we are going to do is ensure that our &#8220;information&#8221; window has a toggle-state. Instead of using jQuery&#8217;s built in toggle() method, I&#8217;ve decided to go with a simple boolean check.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> windowOpen <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.info'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>windowOpen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.more'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'/icon/bullet_arrow_up.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				windowOpen <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.more'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'/icon/bullet_arrow_down.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				windowOpen <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Basically, this will apply the &#8220;onclick&#8221; event to our main window launching button. When clicked it will check if the window is already open and depending on the value of windowOpen, it will close/open it accordingly.</p>
<p>This next section of code will handle opening the chat windows. Since we want to make sure that only windows that AREN&#8217;T opened can be opened (redundant? yes, but completely necessary). This will ensure that if a window is already open, it won&#8217;t open it again.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.contacts span'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> id <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> found <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> 
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #000066; font-weight: bold;">in</span> openWindows<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>openWindows<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> id<span style="color: #339933;">+</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				found <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>found<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.im-bar'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prepend</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;span class=&quot;task&quot; id=&quot;'</span><span style="color: #339933;">+</span>id<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;&lt;div class=&quot;convo&quot;&gt;&lt;img src=&quot;/icon/cancel.png&quot; id=&quot;close-win&quot; alt=&quot;Cancel&quot;&gt;&lt;span class=&quot;system&quot;&gt;You have entered a conversation with '</span><span style="color: #339933;">+</span><span style="color: #000066;">name</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/span&gt;&lt;textarea name=&quot;message&quot; id=&quot;message&quot;&gt;&lt;/textarea&gt;&lt;/div&gt;&lt;div class=&quot;win&quot; name=&quot;'</span><span style="color: #339933;">+</span><span style="color: #000066;">name</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;'</span><span style="color: #339933;">+</span><span style="color: #000066;">name</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.convo'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'inline'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			openWindows<span style="color: #009900;">&#91;</span>openWindows.<span style="color: #660066;">length</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">+</span><span style="color: #000066;">name</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.win'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'padding-top'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'50px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			convoOpen <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> offset <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>openWindows.<span style="color: #660066;">length</span><span style="color: #339933;">*</span><span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>openWindows.<span style="color: #660066;">length</span><span style="color: #339933;">*</span><span style="color: #CC0000;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.convo'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'right'</span><span style="color: #339933;">,</span>offset<span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>id<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'textarea'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.more'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.info'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'/icon/bullet_arrow_up.png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		windowOpen <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The code itself remains fairly straightforward albeit long. First it does some variable assignment and then checks the openWindows array to see if it can find this particular window. If it can&#8217;t, it simply continues with the code. First it creates the new window and places it at the front of the open-window list. Then it just adds it to the openWindows array and does a bit more manipulation to create a text-box and align it properly with the current tab. It also opens the window and focuses on the text area. Finally it fades out the main information window and resets the image and boolean var. </p>
<p>Something to note here: Since we want openWindows and convoOpen to be accessible to ALL our functions, we can place it next to the &#8220;openWindow&#8221; declaration at the top of the script. It would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> openWindows <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #003366; font-weight: bold;">var</span> convoOpen <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span></pre></div></div>

<p>This next bit will just pop open the window if you click on the tab, and minimize it again if you click again.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.task .win'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>convoOpen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'none'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'padding-top'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'5px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			convoOpen <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.convo'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'block'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'padding-top'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'50px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			convoOpen <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>		   
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We&#8217;re nearing the end of our code. This block of code will handle the &#8220;Close&#8221; button on a conversation window. If it is clicked, the window is removed from the tab bar and the openWindows array and the remaining positions are re-calculated.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.task .convo #close-win'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> id <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #000066; font-weight: bold;">in</span> openWindows<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>openWindows<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> id<span style="color: #339933;">+</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				openWindows.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		convoOpen <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> openWindows.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.im-bar'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.convo'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> offset <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span><span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">*</span><span style="color: #CC0000;">15</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'right'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span>offset<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			i<span style="color: #339933;">--;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This last block of code will take any text in our textarea and submit it to the server when you press enter. The AJAX portion of this tutorial will be following, so in the mean-time everything else is showed here. The message is sent to the server, and then it is also automatically placed into the conversation window. We also strip out all tags from the code to ensure that nothing breaks our layout or is able to get through.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.task .convo #message'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'keyup'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			data <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			data <span style="color: #339933;">=</span> data.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&lt;\/?[^&gt;]+&gt;/gi</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">// Send message</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'text'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'system'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'system'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>data <span style="color: #339933;">!=</span> <span style="color: #3366CC;">''</span> <span style="color: #339933;">&amp;&amp;</span> data <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;p&gt;&lt;b&gt;'</span><span style="color: #339933;">+</span>yourName<span style="color: #339933;">+</span><span style="color: #3366CC;">':&lt;/b&gt; '</span><span style="color: #339933;">+</span>data<span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> scrollTop<span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;scrollHeight&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That is the basics of our Client-Side functionality to our Simple Website Instant Messenger system. The next installment will cover adding the AJAX function and modifying this last section sightly to reflect it.</p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2009/11/simple-website-instant-messenger-client-side-functionality/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>jQuery Primer &#8211; An Intro to Client-side Functionality</title>
		<link>http://wheremy.feethavebeen.com/2009/11/jquery-primer-an-intro-to-client-side-functionality/</link>
		<comments>http://wheremy.feethavebeen.com/2009/11/jquery-primer-an-intro-to-client-side-functionality/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 14:00:10 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=321</guid>
		<description><![CDATA[If you&#8217;re interested in web development, you&#8217;ve doubtlessly come across jQuery and wondered about how you could utilize it in your own projects. jQuery looks a little daunting at first, but hopefully by the end of this little introduction to jQuery you&#8217;ll have a much firmer grasp on it and be able to take your [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re interested in web development, you&#8217;ve doubtlessly come across jQuery and wondered about how you could utilize it in your own projects. jQuery looks a little daunting at first, but hopefully by the end of this little introduction to jQuery you&#8217;ll have a much firmer grasp on it and be able to take your projects to the next level.</p>
<p><strong>What is it?<br />
<span style="font-weight: normal;"><a href="http://wheremy.feethavebeen.com/wp-content/uploads/2009/11/jquery1.PNG"><img class="alignright size-full wp-image-327" title="jquery1" src="http://wheremy.feethavebeen.com/wp-content/uploads/2009/11/jquery1.PNG" alt="jquery1" width="233" height="93" /></a>If you go by their website jQuery touts itself as being able to do damn near everything. And in truth, it does. It simplifies otherwise tedious tasks and allows you to add huge amounts of functionality to your website without much code. What it IS, however, is a Framework that provides you the ability to perform these tedious tasks in a way that&#8217;s simple and concise while achieving cross-browser support. This means that you can write your code quickly while knowing that it will work exactly how you expect it to in every browser. This cuts down on the amount of development time that you spend. Another bonus is the way that jQuery naming conventions make sense. Things like adding onclick handlers are as simple as adding .click(); to a selector (more on this later). This means that the learning curve is very shallow allowing you to literally just jump right now.</span></strong></p>
<p><strong>Getting started</strong><br />
<span style="font-weight: normal;">Your first step will be to download jQuery. To do that, just head over to their website (<a href="http://jquery.com/">http://www.jquery.com</a>) and you can download it. It will be up to you whether you want to download the production or development versions. Both are the same, it&#8217;s just that the production code has been minified so it results in a much smaller file size. If you are just starting out however, I&#8217;d recommend going with the development version. If you have a full fledged IDE then your code hinting will come into play and you&#8217;ll be able to see descriptions of what the arguments are and such. However, even if you don&#8217;t, the development code will definitely be something you&#8217;ll want to peruse through in your spare time. You can learn a lot from looking at other peoples code. Once you have it downloaded, you can use it by simply including the following: </span></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;path/to/jquery.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>I&#8217;ve intentionally left the &#8220;src&#8221; attribute pointing to a random file as you will have to change it to point to wherever your jQuery file is. </p>
<p><strong>First Steps</strong><br />
When using jQuery you have to remember that you&#8217;ll be spending a lot of time manipulating the DOM. In order for this to occur, you&#8217;ll have to wait till the DOM is loaded. However, because of where your script files are generally located, they may load before the DOM has completely finished. If this happens then your scripts will just run in to a lot of errors. jQuery comes with a built in way to check that the DOM is ready for use. All your jQuery scripts should run only AFTER the DOM is ready. In a separate script tag, you can add the following</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">$(document).ready(function(){ })</pre></div></div>

<p>jQuery makes use of anonymous functions quite a bit, so you may want to make a note of that. You don&#8217;t NEED to have a function name in JavaScript. $ is a global variable created by jQuery as an accessor to all of its methods. This means that all your scripts in jQuery will utilize $ to perform it&#8217;s functions. $ will accept multiple types of arguments. You can either provide an ID, a Class or even an html tag for jQuery to work its magic on. I recommend you read up on the documentation for $ as it is one thing that you will definitely need to understand to perform complex manipulations. </p>
<p>You can go ahead and add</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;#&quot;&gt;Link&lt;/a&gt;</pre></div></div>

<p> to the body section of your code. This is so that we have something to work with in jQuery. </p>
<p>Going back to our anonymous function, you can change it so that it looks like this</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">$(document).ready(function(){
$('a').click(function(){ alert('Works!'); }); 
}</pre></div></div>

<p>Because of how powerful jQuery is, that will actually apply itself to EVERY anchor tag in the DOM. You can pick and choose which ones by applying numerous <a href="http://docs.jquery.com/Selectors">selectors</a>. There are so many involved that that itself is the topic of another discussion. However, if you are looking to work on a particular id the code would be</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">$('#id')</pre></div></div>

<p> and if you were working on a class you could use</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">$('.class')</pre></div></div>

<p> Keep in mind that jQuery will always work on EVERYTHING that matches the selector that you have provided. </p>
<p>jQuery is also chainable. Because of how the code is written, you can keep tacking on different functions. For example, if we look through the <a href="http://docs.jquery.com/Effects">effects </a>section of the documentation you&#8217;ll see things like slideDown() and fadeIn(). These effects can be chained together to create multiple tiers of animations or events. </p>
<p>My recommendation is that you definitely check out the full documentation and spend a lot of time playing around with it. There will be a few more jQuery tutorials popping up on the website as I start preparing the gradual jump from no jQuery experience to enough experience to write the client-side functionality of our <a href="http://wheremy.feethavebeen.com/2009/11/simple-website-instant-messenger-the-static-prototype/">SWIM!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2009/11/jquery-primer-an-intro-to-client-side-functionality/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple Website Instant Messenger &#8211; The Static Prototype</title>
		<link>http://wheremy.feethavebeen.com/2009/11/simple-website-instant-messenger-the-static-prototype/</link>
		<comments>http://wheremy.feethavebeen.com/2009/11/simple-website-instant-messenger-the-static-prototype/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 13:00:32 +0000</pubDate>
		<dc:creator>xangelo</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://wheremy.feethavebeen.com/?p=311</guid>
		<description><![CDATA[For the past day I have been laying the ground-work for a little side-project of mine. My eventual goal is to offer the application for free, but in the mean time I thought I&#8217;d go through a bit of a tutorial outlining how I came up with the prototype for SWIM. This probably won&#8217;t be [...]]]></description>
			<content:encoded><![CDATA[<p>For the past day I have been laying the ground-work for a little side-project of mine. My eventual goal is to offer the application for free, but in the mean time I thought I&#8217;d go through a bit of a tutorial outlining how I came up with the prototype for SWIM. This probably won&#8217;t be a project that you will want to include on a large website as the constant back-end polls will probably take their toll on your server. However, as an informative piece outlining complex application development with a multitude of programming languages SWIM will be right at home.</p>
<p><strong>The Vision</strong><br />
I wanted to create a completely self contained Website IM system. Apart from an installation file that would handle the database setup, I wanted developers to be able to copy a few lines of code into their current websites and have the client up and running. It would consist of a little bar along the bottom of the screen that would allow the user to easily keep track of their contacts as well as any open conversations. From the beginning the idea was the integration with a website had to be simple. If I ever felt the need to include it in a website I was developing, I didn&#8217;t want the hassle of actually integrating it. I wanted to be able to say something like swim_ui(); and have it take care of everything else. I knew it wouldn&#8217;t be THAT simple, but simplicity was something I was aiming for. Here are a few examples of what I expected the app to look like.</p>
<p style="text-align: center;"><a href="http://wheremy.feethavebeen.com/wp-content/uploads/2009/11/improto1.png"><img class="aligncenter size-full wp-image-312" title="improto1" src="http://wheremy.feethavebeen.com/wp-content/uploads/2009/11/improto1.png" alt="improto1" width="736" height="524" /></a></p>
<p><strong>Refining<br />
<span style="font-weight: normal;">Once I had established a rough look to the IM client I took a moment to re-evaluate the different elements involved. It is something, that as a designer, I find essential to do. I had to make absolutely sure that every element in the prototype was required 100%. If it could do without, it was useless and removed. The reason was simple. I didn&#8217;t want a massive file included with every page. It would become a problem as websites grew.  Even the use of images was something I didn&#8217;t want to get in to. As I said before, my motto with this was &#8220;If it could do without, it was useless&#8221; and there was no room for useless elements. </span></strong></p>
<p style="text-align: center;"><strong><span style="font-weight: normal;"><a href="http://wheremy.feethavebeen.com/wp-content/uploads/2009/11/improto2.png"><img class="aligncenter size-full wp-image-313" title="improto2" src="http://wheremy.feethavebeen.com/wp-content/uploads/2009/11/improto2.png" alt="improto2" width="736" height="524" /></a><br />
</span></strong></p>
<p><strong>The Static Mockup<br />
<span style="font-weight: normal;">This is another step that I absolutely have to go through. Before I start adding the dynamic PHP and even Javascript, I build a completely static version of what I want to eventually build. For one thing it lets me re-evaluate everything in the design, and when deadlines start coming up, it&#8217;s easy to find things that will give you problems later on. As well, actually having a finished product really boosts your morale and makes you want to work more. The static mockup was very simple. Even though I eliminated the chat taskbar, you&#8217;ll notice (or maybe not, since the screenshot is rather hard to read) I left the chat taskbar text in place. This is because that even though we won&#8217;t have a physical task bar, it will still exist in our code. This lets us position things properly.</span></strong></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;im-bar&quot;&gt;
	&lt;span class=&quot;task&quot; id=&quot;'user-id'&quot;&gt;
		&lt;div class=&quot;convo&quot;&gt;
			&lt;img src=&quot;/icon/cancel.png&quot; id=&quot;close-win&quot; alt=&quot;Cancel&quot;&gt;
			&lt;span class=&quot;system&quot;&gt;You have entered a conversation with Name&lt;/span&gt;
			&lt;textarea name=&quot;message&quot; id=&quot;message&quot;&gt;&lt;/textarea&gt;
		&lt;/div&gt;
		&lt;div class=&quot;win&quot; name=&quot;Name&quot;&gt;Name&lt;/div&gt;
	&lt;/span&gt;
	&lt;div class=&quot;more&quot;&gt;
		&lt;div class=&quot;user-info&quot;&gt;
			Angelo R. 
			&lt;span&gt;&lt;img src=&quot;/icon/bullet_green.png&quot; alt=&quot;Online&quot; id=&quot;status&quot;&gt;&lt;/span&gt;
		&lt;/div&gt;
		&lt;div class=&quot;contacts&quot;&gt;
			&lt;span id=&quot;cname1&quot; name=&quot;Name&quot;&gt;
				&lt;img src=&quot;/icon/user.png&quot; id=&quot;cname-dp&quot; alt=&quot;Username&quot;&gt;
				&lt;ul&gt;
					&lt;li class=&quot;name&quot;&gt;Name&lt;/li&gt;
					&lt;li class=&quot;status&quot;&gt;Status&lt;/li&gt;
				&lt;/ul&gt;
			&lt;/span&gt;
			&lt;span id=&quot;cname2&quot; name=&quot;Name 2&quot;&gt;
				&lt;img src=&quot;/icon/user_gray.png&quot; id=&quot;cname-dp&quot; alt=&quot;Username&quot;&gt;
				&lt;ul&gt;
					&lt;li class=&quot;name&quot;&gt;Name 2&lt;/li&gt;
					&lt;li class=&quot;status&quot;&gt;Status&lt;/li&gt;
				&lt;/ul&gt;
			&lt;/span&gt;
			&lt;span id=&quot;cname3&quot; name=&quot;Name 3&quot;&gt;
				&lt;img src=&quot;/icon/user_gray.png&quot; id=&quot;cname-dp&quot; alt=&quot;Username&quot;&gt;
				&lt;ul&gt;
					&lt;li class=&quot;name&quot;&gt;Name 3&lt;/li&gt;
					&lt;li class=&quot;status&quot;&gt;Status&lt;/li&gt;
				&lt;/ul&gt;
			&lt;/span&gt;
		&lt;/div&gt;
		&lt;div class=&quot;bottom-bar&quot;&gt;
			&lt;img src=&quot;/icon/add.png&quot; id=&quot;add&quot; alt=&quot;Add User&quot;&gt;
			&lt;a href=&quot;#&quot;&gt;Settings&lt;/a&gt;
		&lt;/div&gt;
	&lt;/div&gt;
	&lt;div class=&quot;info&quot;&gt;
		&lt;img src=&quot;/icon/bullet_green.png&quot; alt=&quot;Online&quot; align=&quot;top&quot;&gt;Online 
		&lt;span&gt;&lt;img src=&quot;/icon/bullet_arrow_up.png&quot; alt=&quot;More&quot;&gt;&lt;/span&gt;
	&lt;/div&gt;
&lt;/div&gt;</pre></div></div>

<p>As you can see I&#8217;ve tried to keep the code as self explanatory as possible. It&#8217;s very simple HTML without the use of Tables or any inline CSS. This was to ensure that even skinning the SWIM system would be as simple as editing a single file. </p>
<p>The CSS for this file is where things will get a lot more confusing. Because of the fact that this will be included in your website, I had to ensure that my css wouldn&#8217;t overwrite any of your css. So everything is explicitly stated. When I wanted to style the .info class, I pointed to it through it&#8217;s full &#8220;path&#8221; of .im-bar .info This was to ensure that only that element would get skinned. The CSS is a little advanced, and has an added line for webkit based browers that the gecko ones won&#8217;t see. This is also only going to look exactly as planned in those browsers. Sorry Trident users, I&#8217;ll be updating this code once I sort out a few more bugs.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.im-bar<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">100</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;Arial&quot;</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0.8em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#555</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>	
<span style="color: #6666ff;">.im-bar</span> a<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.im-bar</span> a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">underline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.info</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.im-bar</span> .win<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">7px</span><span style="color: #00AA00;">;</span> 
	-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">7px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#EFEFEF</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #933;">10px</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#F0F0F0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">6px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">default</span><span style="color: #00AA00;">;</span>
	-webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">4px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0.9</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> .win<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> reset<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>	
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.info</span> span<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.info</span><span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.win</span><span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#E7E7E7</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> .more<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#EFEFEF</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">350px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#F0F0F0</span><span style="color: #00AA00;">;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">7px</span><span style="color: #00AA00;">;</span>
	-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">7px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">100</span><span style="color: #00AA00;">;</span>
	-webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">4px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0.9</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.more</span> .contacts<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FFF</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">86</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.more</span> <span style="color: #6666ff;">.contacts</span> span<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">1px</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#F0F0F0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.more</span> <span style="color: #6666ff;">.contacts</span> span<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FAFAFA</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.more</span> <span style="color: #6666ff;">.contacts</span> span img<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#F0F0F0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.more</span> <span style="color: #6666ff;">.contacts</span> span ul<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.more</span> <span style="color: #6666ff;">.contacts</span> span ul li<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">default</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.more</span> <span style="color: #6666ff;">.contacts</span> span ul li.status<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">italic</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.more</span> <span style="color: #6666ff;">.user-info</span><span style="color: #00AA00;">,</span><span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.more</span> .bottom-bar<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.more</span> <span style="color: #6666ff;">.user-info</span> span<span style="color: #00AA00;">,</span><span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.more</span> <span style="color: #6666ff;">.bottom-bar</span> a<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.task</span> .convo<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">300px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">7px</span><span style="color: #00AA00;">;</span> 
	-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">7px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#EFEFEF</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FFF</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	-webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">4px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0.9</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.task</span> <span style="color: #6666ff;">.convo</span> <span style="color: #cc00cc;">#close-win</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.task</span> <span style="color: #6666ff;">.convo</span> <span style="color: #cc00cc;">#message</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;Arial&quot;</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#555</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> .system<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</span> 
	<span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">italic</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">75</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.task</span> <span style="color: #6666ff;">.convo</span> .<span style="color: #993333;">text</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">font-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">75</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.im-bar</span> <span style="color: #6666ff;">.task</span> <span style="color: #6666ff;">.convo</span> <span style="color: #6666ff;">.text</span> p<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>You&#8217;ll notice that everything in the stylesheet is actually really simple. Other than a few pieces such as the overflow attribute in the .im-bar .task .convo .text selector which just adds a scrollbar to the chat window if necessary. The z-indexes are also used to place windows on top of each other (obviously) but keep things in the high 90&#8242;s. This is so that incase you have an z-indexed elements on your website, this will hopefully not interfere. </p>
<p>Finally, here&#8217;s a screenshot of what our HTML mockup looks like. Stay tuned for the next part in which we add jQuery into the mix to really get our Prototype up and running! </p>
<div id="attachment_314" class="wp-caption aligncenter" style="width: 391px"><a href="http://wheremy.feethavebeen.com/wp-content/uploads/2009/11/swim-minwin.PNG"><img src="http://wheremy.feethavebeen.com/wp-content/uploads/2009/11/swim-minwin.PNG" alt="SWIM - Minimized Convo Windows with Open Chat Window" title="swim-minwin" width="381" height="461" class="size-full wp-image-314" /></a><p class="wp-caption-text">SWIM - Minimized Convo Windows with Open Chat Window</p></div>
<div id="attachment_315" class="wp-caption aligncenter" style="width: 394px"><a href="http://wheremy.feethavebeen.com/wp-content/uploads/2009/11/swim-winopen.PNG"><img src="http://wheremy.feethavebeen.com/wp-content/uploads/2009/11/swim-winopen.PNG" alt="SWIM - Open conversation window" title="swim-winopen" width="384" height="396" class="size-full wp-image-315" /></a><p class="wp-caption-text">SWIM - Open conversation window</p></div>
]]></content:encoded>
			<wfw:commentRss>http://wheremy.feethavebeen.com/2009/11/simple-website-instant-messenger-the-static-prototype/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
