<?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>Jason Rowe &#187; JavaScript</title>
	<atom:link href="http://jasonrowe.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://jasonrowe.com</link>
	<description></description>
	<lastBuildDate>Tue, 03 Aug 2010 23:10:14 +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>Determine if two rectangles overlap each other in JavaScript</title>
		<link>http://jasonrowe.com/2009/03/14/determine-if-two-rectangles-overlap-each-other-in-javascript/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=determine-if-two-rectangles-overlap-each-other-in-javascript</link>
		<comments>http://jasonrowe.com/2009/03/14/determine-if-two-rectangles-overlap-each-other-in-javascript/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 07:13:07 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://rowejason.com/?p=338</guid>
		<description><![CDATA[Stack Overflow has a good post on determining if two rectangles are overlapping.  I used the discussed algorithm to check for an overlap and then move one away.  I&#8217;m only moving up or down depending on which rectangle is higher &#8230; <a href="http://jasonrowe.com/2009/03/14/determine-if-two-rectangles-overlap-each-other-in-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Stack Overflow has a good <a href="http://stackoverflow.com/questions/306316/determine-if-two-rectangles-overlap-each-other">post</a> on determining if two rectangles are overlapping.  I used the discussed algorithm to check for an overlap and then move one away.  I&#8217;m only moving up or down depending on which rectangle is higher or lower and if it will fit in a specified areas min or max.</p>
<pre class="brush: js; ">

&lt;script type=&quot;text/javascript&quot;&gt;

var rectA = {x: 2, y: 5, width: 6, height: 6};
var rectB = {x: 4, y: 10, width: 6, height: 6};
var area = {min: 0, max: 100};

var overlap = rectOverlap(rectA,rectB);
alert(&quot;Does rectA and rectB overlap? &quot; + overlap);

if(overlap)
{
if(rectA.y &gt;= rectB.y)
{
if(increaseY(rectA.width, rectB.y + rectB.height, area.max))
{
rectA.y = rectB.y + rectB.height + 1;
}
else if (rectA.y - rectB.height &gt; area.min)
{
rectB.y = rectA.y - rectB.height;
}
}
else
{
if(increaseY(rectB.width, rectA.y + rectA.height, area.max))
{
rectB.y = rectA.y + rectA.height + 1;
}
else if (rectB.y - rectA.height &gt; area.min)
{
rectA.y = rectB.y - rectA.height;
}
}
}

alert(&quot;Does rectA and rectB overlap? &quot; + rectOverlap(rectA,rectB));

function increaseY(width, bottomEdge, Max)
{
return (bottomEdge + width &lt; Max);
}

function valueInRange(value, min, max)
{

return (value &lt;= max) &amp;&amp; (value &gt;= min);

}

function rectOverlap(A, B)
{
var xOverlap = valueInRange(A.x, B.x, B.x + B.width) ||
valueInRange(B.x, A.x, A.x + A.width);

var yOverlap = valueInRange(A.y, B.y, B.y + B.height) ||
valueInRange(B.y, A.y, A.y + A.height);

return xOverlap &amp;&amp; yOverlap;
}

&lt;/script&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2009/03/14/determine-if-two-rectangles-overlap-each-other-in-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SmoothGallery is good stuff</title>
		<link>http://jasonrowe.com/2009/01/18/smoothgallery-is-good-stuff/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=smoothgallery-is-good-stuff</link>
		<comments>http://jasonrowe.com/2009/01/18/smoothgallery-is-good-stuff/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 00:51:37 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://rowejason.com/?p=331</guid>
		<description><![CDATA[I was recently shown the SmoothGallery javascript picture carousel and I really like.  If you need a simple way to display pictures and do some pretty flashy things quickly this is your best bet. I only ran into a few &#8230; <a href="http://jasonrowe.com/2009/01/18/smoothgallery-is-good-stuff/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was recently shown the<a href="http://smoothgallery.jondesign.net/"> SmoothGallery</a> javascript picture carousel and I really like.  If you need a simple way to display pictures and do some pretty flashy things quickly this is your best bet. I only ran into a few issue.</p>
<p>1) I had to run my JQuery code in no conflict mode. Which is a very simple change.</p>
<pre class="brush: js; ">

var J = jQuery.noConflict();
</pre>
<p>Then replace all your #&#8217;s with J.</p>
<p>2) I had an issue in IE7 where my drop down menu&#8217;s would go behind the SmoothGallery module. It turned out to be a very simple z-index issue and making sure the menu was not absolutely positioned.</p>
<p>Other then those quick things I had a very nice fully functional picture gallery up and running in minutes.  It was also very refreshing to see a library with very simple setup instructions.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2009/01/18/smoothgallery-is-good-stuff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JS Memory Leak Tools &amp; Tips</title>
		<link>http://jasonrowe.com/2008/12/23/js-memory-leak-tools-tips/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=js-memory-leak-tools-tips</link>
		<comments>http://jasonrowe.com/2008/12/23/js-memory-leak-tools-tips/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 22:09:06 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://rowejason.com/?p=211</guid>
		<description><![CDATA[Javascript Closure If you refresh the browser or go to another page and the memory doesn&#8217;t go down you probably have a closure. I just ran into a tricky situation where my closure was being caused during the successful call &#8230; <a href="http://jasonrowe.com/2008/12/23/js-memory-leak-tools-tips/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Javascript Closure</strong></p>
<p>If you refresh the browser or go to another page and the memory doesn&#8217;t go down you probably have a closure. I just ran into a tricky situation where my closure was being caused during the successful call back of a JQuery Ajax call.</p>
<p>The function that was leaking looked like this:</p>
<pre class="brush: js; ">

function &lt;span&gt;GetData&lt;/span&gt;(object) {

var requestObject = object.buildRequest()

$.ajax({
type: &quot;POST&quot;,
url: object.url,
dataType: &quot;json&quot;,
data: requestObject,
success: function(jsonResult) {
object.data = jsonResult;
object.DoStuffWithData();
}
});
}
</pre>
<p>The fix was to remove the object from being a local variable.</p>
<pre class="brush: js; ">

function GetData(object) {

var requestObject = object.buildRequest()

$.ajax({
type: &quot;POST&quot;,
url: object.url,
dataType: &quot;json&quot;,
data: requestObject,
success: function(data) {
//On Success Call Data Updater
data.id = object.Id;
DataUpdater(data);
}
});

requestObject = null;
}

function DataUpdater(data) {

//loop through Requesters Array

//must add object to global array before making DataUpdater
for (i = 0; i &lt; Requesters.length; i++) {

var temp = Requesters[i];

var requestId = temp.Id;
var dataId = data.Id;

//Find object with matching id
if (requestId == dataId ) {

temp .data = data;
temp .DoStuffWithData();
}
}

}
</pre>
<p><strong>Drip<br />
While tracking down this memory leak I decided to try out a memory leak tool called <a href="http://www.outofhanwell.com/ieleak/index.php?title=Main_Page">Drip</a>. Unfortunately, It didn&#8217;t work in my situation. Drip actually started causing memory leaks so it made it hard to tell if I actually fixed the problem or not. I think the reason it doesn&#8217;t work is the script is recursive using setInterval.</p>
<p><strong></strong><strong></strong><strong>Other Tools</strong></p>
<p><strong></strong><strong></strong><strong> </strong></p>
<p>Setting up IE and Firefox private bytes counters under process in Perfmon is the most reliable way to monitor JS memory leaks.</p>
<p><strong></strong><strong><a rel="attachment wp-att-313" href="http://rowejason.com/2008/12/23/js-memory-leak-tools-tips/perfmon/"><img class="alignnone size-full wp-image-313" title="perfmon" src="http://rowejason.com/wp-content/uploads/2008/12/perfmon.jpg" alt="perfmon" width="578" height="347" /></a></strong></p>
<p>Another common gotcha is the FireFox web developer plug-in. Turn that off if you are going to do any JS memory leak testing. It&#8217;s probably a good idea to turn off any IE plug-ins too just incase but I haven&#8217;t ran into any problems with theirs yet.</p>
<p>IE also has a tool bar for JS memory leaks but it didn&#8217;t work in my situation very well.</p>
<p>Some good pages for review:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/bb250448.aspx">Understanding and Solving Internet Explorer Leak Patterns</a></li>
<li><a href="http://www.javascriptkit.com/javatutors/closuresleak/index.shtml">JavaScript and memory leaks</a></li>
<li><a href="http://www.codeproject.com/KB/scripting/leakpatterns.aspx">Memory Leakage in Internet Explore</a></li>
<li><a href="http://javascript.crockford.com/memory/leak.html">http://javascript.crockford.com/memory/leak.html</a></li>
</ul>
<p><strong></strong><strong><a href="http://www.codeproject.com/KB/scripting/leakpatterns.aspx"></a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2008/12/23/js-memory-leak-tools-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>yui number sorting issue</title>
		<link>http://jasonrowe.com/2008/01/17/yui-number-sorting-issue/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=yui-number-sorting-issue</link>
		<comments>http://jasonrowe.com/2008/01/17/yui-number-sorting-issue/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 07:05:31 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://rowejason.com/2008/01/17/yui-number-sorting-issue/</guid>
		<description><![CDATA[So if you are using the YUI DataTable with XHR and numbers you might have noticed the sort is not working correctly. Below is a quick explination and a work around. &#8220;DataTable currently sorts strings, numbers, and dates, but only &#8230; <a href="http://jasonrowe.com/2008/01/17/yui-number-sorting-issue/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So if you are using the YUI DataTable with XHR and numbers you might have noticed the sort is not working correctly. Below is a quick explination and a work around.</p>
<blockquote><p>&#8220;DataTable currently sorts strings, numbers, and dates, but <em>only when the values are already those types in JavaScript</em>. In contrast, if you get values over the wire (<abbr title="XMLHttpRequest">XHR</abbr>), DataTable will treat all values as strings in those cases. As a workaround, you could implement a custom sort function to do the data type conversion. Data parsed from markup will be typed correctly, and so we’re a part of the way there; before we get out of beta we plan to provide a mechanism so a value can be treated as a specific type regardless of its origin. I can tell you that in the next release (coming soon) we’ll have a hook for you to do your own conversion of data coming over <abbr title="XMLHttpRequest">XHR</abbr>, and in the subsequent release it will do a lot of conversions for you out of the box and also provide a mechanism for you to do more sophisticated custom conversions.&#8221;</p></blockquote>
<p>Here is the custom sort function I created to fix the issue. It still doesn&#8217;t work well if you have multipage result lists because the string has to go through the function before it becomes an integer. It works well for small lists or where all the results appear right away.</p>
<p>In the snippet below<strong>, &#8220;u&#8221;</strong> would be the variable you  want to get sorting correctly in the data grid results. If you are not familiar with using custom sort functions take a look at the yui data grid docs. It&#8217;s very easy.</p>
<pre>
<pre class="brush: javascript; ">

var myFormatStringFix = 

function(elCell, oRecord, oColumn, oData) 

{ 

oRecord._oData.u = parseInt(oRecord._oData.u); 

elCell.innerHTML = oRecord._oData.u; 

} 
</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2008/01/17/yui-number-sorting-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Carousel Control CD Collection</title>
		<link>http://jasonrowe.com/2007/07/18/carousel-control-cd-collection/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=carousel-control-cd-collection</link>
		<comments>http://jasonrowe.com/2007/07/18/carousel-control-cd-collection/#comments</comments>
		<pubDate>Wed, 18 Jul 2007 05:29:00 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://rowejason.com/?p=96</guid>
		<description><![CDATA[I wanted to find an easy way to display a CD collection using javascript instead of flash. While looking around I found a YUI extension called carousel. Here is my small static example of a CD collection. Bill Scott actually &#8230; <a href="http://jasonrowe.com/2007/07/18/carousel-control-cd-collection/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://rowejason.com/search"><img style="float: left; margin: 0px 10px 10px 0px; cursor: hand" src="http://www.rowejason.com/uploaded_images/carousel_example-779114.JPG" border="0" alt="snapshot of carousel" /></a> I wanted to find an easy way to display a CD collection using javascript instead of flash. While looking around I found a YUI extension called carousel. Here is my small static example of a CD collection.</p>
<p>Bill Scott actually doesn&#8217;t support this anymore and the YUI team has taken this on. The new version is very clean and I did try it out. I converted my carousel to the new YUI version but later decided to go with a JQuery extention called jCarousel. They both worked but I think I am going to move in the Jquery direction for awhile.<br />
<a href="http://jasonrowe.com/search"> http://jasonrowe.com/search</a></p>
<p>References:<br />
<a href="http://billwscott.com/carousel/">http://billwscott.com/carousel/</a></p>
<p><a href="http://sorgalla.com/projects/jcarousel/">http://sorgalla.com/projects/jcarousel/</a></p>
<p><a href="http://developer.yahoo.com/yui/carousel/">http://developer.yahoo.com/yui/carousel/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2007/07/18/carousel-control-cd-collection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript: Create Advanced Web Applications With Object-Oriented Techniques</title>
		<link>http://jasonrowe.com/2007/05/07/javascript-create-advanced-web-applications-with-object-oriented-techniques/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=javascript-create-advanced-web-applications-with-object-oriented-techniques</link>
		<comments>http://jasonrowe.com/2007/05/07/javascript-create-advanced-web-applications-with-object-oriented-techniques/#comments</comments>
		<pubDate>Mon, 07 May 2007 15:47:00 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://rowejason.com/?p=83</guid>
		<description><![CDATA[I just started working with OOP in javascript and found this article very informative. The section on prototypes was very helpful as I have been digging around in the YUI library lately and found that area confusing. JavaScript: Create Advanced &#8230; <a href="http://jasonrowe.com/2007/05/07/javascript-create-advanced-web-applications-with-object-oriented-techniques/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I just started working with OOP in javascript and found this article very informative. The section on prototypes was very helpful as I have been digging around in the YUI library lately and found that area confusing. <a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx">JavaScript: Create Advanced Web Applications With Object-Oriented Techniques</a></p>
<p>The article has lots of examples if you click on the figure links. Here was a useful one on Inheriting from a Prototype:</p>
<p><code><br />
Inheriting from a Prototypefunction GreatDane() { }<br />
var rover = new GreatDane();<br />
var spot = new GreatDane();<br />
GreatDane.prototype.getBreed = function() {<br />
return “Great Dane”;<br />
};</code><code>// Works, even though at this point<br />
// rover and spot are already created.<br />
alert(rover.getBreed());<br />
// this hides getBreed() in GreatDane.prototype<br />
spot.getBreed = function() {<br />
return “Little Great Dane”;<br />
};<br />
alert(spot.getBreed());<br />
// but of course, the change to getBreed<br />
// doesn’t propagate back to GreatDane.prototype<br />
// and other objects inheriting from it,<br />
// it only happens in the spot object<br />
alert(rover.getBreed());</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2007/05/07/javascript-create-advanced-web-applications-with-object-oriented-techniques/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mouse Events onmouseout issue event bubbling</title>
		<link>http://jasonrowe.com/2007/01/12/mouse-events-onmouseout-issue-event-bubbling/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=mouse-events-onmouseout-issue-event-bubbling</link>
		<comments>http://jasonrowe.com/2007/01/12/mouse-events-onmouseout-issue-event-bubbling/#comments</comments>
		<pubDate>Fri, 12 Jan 2007 23:23:00 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://rowejason.com/?p=68</guid>
		<description><![CDATA[Quick JavaScript example to handle the onmouseout event to prevent event bubbling in IE. if(window.addEventListener) { // Mozilla, Netscape, Firefox object.addEventListener(&#8216;mouseover&#8217;,function() {this.className = &#8220;objectVisible&#8221;;false) object.addEventListener(&#8216;mouseout&#8217;,function() {this.className = &#8220;objectNotVisible&#8221;;return true;}, false)} else { // IE object.onmouseenter = function() {this.className = &#8220;objectVisible&#8221;;return &#8230; <a href="http://jasonrowe.com/2007/01/12/mouse-events-onmouseout-issue-event-bubbling/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Quick JavaScript example to handle the onmouseout event to prevent event bubbling in IE.<br />
<blockquote>
<p>if(window.addEventListener)</p>
<p>{</p>
<p>// Mozilla, Netscape, Firefox</p>
<p>object.addEventListener(&#8216;mouseover&#8217;,function() {this.className = &#8220;objectVisible&#8221;;false)</p>
<p>object.addEventListener(&#8216;mouseout&#8217;,function() {this.className = &#8220;objectNotVisible&#8221;;return true;}, false)} </p>
<p>else { // IE</p>
<p>object.onmouseenter = function() {this.className = &#8220;objectVisible&#8221;;return false;};</p>
<p>object.onmouseleave = function() {this.className = &#8220;objectNotVisible&#8221;;return false;}; </p>
<p>}</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2007/01/12/mouse-events-onmouseout-issue-event-bubbling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
