<?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>enjoying the web</description>
	<lastBuildDate>Sun, 13 May 2012 14:05:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>SVG Movable Node Graph</title>
		<link>http://jasonrowe.com/2012/05/10/svg-movable-node-graph/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=svg-movable-node-graph</link>
		<comments>http://jasonrowe.com/2012/05/10/svg-movable-node-graph/#comments</comments>
		<pubDate>Fri, 11 May 2012 04:53:34 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Raphael]]></category>
		<category><![CDATA[SVG]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1926</guid>
		<description><![CDATA[I&#8217;ve been having fun lately with JavaScript, SVG, and simple node graphs. I just added movable/draggable nodes to my VisualizeInteractions project. It&#8217;s helping me get my head around closures. I&#8217;m not at the point of mastering JavaScript. I never think &#8230; <a href="http://jasonrowe.com/2012/05/10/svg-movable-node-graph/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been having fun lately with JavaScript, SVG, and simple node graphs. I just added movable/draggable nodes to my <a href="https://github.com/JasonRowe/VisualizeInteractions">VisualizeInteractions </a>project. It&#8217;s helping me get my head around <a href="https://developer.mozilla.org/en/JavaScript/Guide/Closures">closures</a>.</p>

<script type="text/javascript" src="http://jasonrowe.com/misc/raphael-min.js"></script>
<script type="text/javascript" src="http://jasonrowe.com/misc/interactions.js"></script>

    <div id="VisualWindow">
    </div>

<script type="text/javascript">

        var FreeTime = { "l": "", "t": "", "c": "#54A0DE", "x": 180, "y": 180, "r": 5, "m": true, "connections":
                                [{ "t": "Coding", "c": "#4BDE7F", "x": 319, "y": 253, "r": 30, "m": true },
                                 { "t": "Twitter", "c": "#F28124", "x": 120, "y": 160, "r": 5, "m": true },
                                 { "t": "Google+", "c": "#FFFF0A", "x": 30, "y": 160, "r": 10, "m": true },
                                 { "t": "Google Reader", "c": "#694E00", "x": 272, "y": 87, "r": 3, "m": true },
                                 { "t": "Biking", "c": "#694E00", "x": 30, "y": 40, "r": 1, "m": true },
                                 { "t": "Family", "c": "#694E00", "x": 101, "y": 275, "r": 30, "m": true }
                                ]
        };

        interactions.initalize("VisualWindow", 600, 350);
        interactions.draw(FreeTime);

    </script>

<p>I&#8217;m not at the point of mastering JavaScript. I never think of closures in advanced when building a project. I sort of just throw them in when an event doesn&#8217;t work or my context is suddenly wrong. At least I&#8217;m no longer using global variables to get things working. </p>

<p>Much of the code for this was borrowed from the Raphaël <a href="http://raphaeljs.com/graffle.html">sample </a>which does use global variables for the event methods and array of edges in the graph. Most of the heavy lifting is done by the Raphaël JavaScript library which I really like since it is compatible with most browsers. The only issue I have seen is old version of android which didn&#8217;t support SVG.</p>]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2012/05/10/svg-movable-node-graph/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Strophejs ejabberd IIS Setup</title>
		<link>http://jasonrowe.com/2011/11/18/strophejs-ejabberd-iis-setup/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=strophejs-ejabberd-iis-setup</link>
		<comments>http://jasonrowe.com/2011/11/18/strophejs-ejabberd-iis-setup/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 19:08:17 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[XMPP]]></category>
		<category><![CDATA[ejabberd]]></category>
		<category><![CDATA[strophejs]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1547</guid>
		<description><![CDATA[This is a simple guide for getting strophe.js, ejabberd, and IIS all working together on a local dev machine. This assumes you have IIS 7.5 installed and are familiar with the basics of IIS Manager Step 1: Download and install &#8230; <a href="http://jasonrowe.com/2011/11/18/strophejs-ejabberd-iis-setup/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is a simple guide for getting strophe.js, ejabberd, and IIS all working together on a local dev machine. This assumes you have IIS 7.5 installed and are familiar with the basics of IIS Manager</p>

<img src="http://jasonrowe.com/wp-content/uploads/2011/11/ej_iis_stro_blog1.png" alt="strophe ejabberd IIS" title="ej_iis_stro_blog" width="400" height="100" class="alignleft size-full wp-image-1563" />

<p><strong>Step 1</strong>: Download and install <a href="http://www.process-one.net/en/ejabberd/downloads">ejabberd</a>. The install is straight forward and the default configuration has everything you need. During the install it will ask you for a domain. I would recommend setting up a host alias &#8220;localhost.demo.com&#8221; because it looks nicer and easier to use but you could also just use localhost. After install check to make sure the http-bind endpoint is working http://localhost:5280/http-bind/. You should see a simple page that has &#8220;ejabberd mod_http_bind&#8221; at the top</p>

<p><strong>Step 1.5</strong>: Setup a host name if needed. If you used localhost you can skip this step. You can do this in Windows 7 via the host file which should be located &#8220;C:\Windows\System32\drivers\etc\hosts&#8221;. Add a line at the bottom with your IP and new local DNS.</p>

<p><strong>Step 2</strong>: Setup new IIS application and copy in strophe.js examples. Go into IIS manager and create a new application named &#8220;xmppExample&#8221;. Then download the latest <a href="http://strophe.im/strophejs/">strophe.js</a> and copy the contents to your new site. You should be able to access the following now. http://localhost.demo.com/xmppExample/strophejs/examples/basic.html. You will have to change the first line in basic.js to setup your endpoint. It should look like this <strong>BOSH_SERVICE = &#8216;http://localhost.demo.com/http-bind&#8217;</strong></p>

<p><strong>Step 3</strong>: Setup proxy for ejabberd http-bind endpoint. To make things simple we need everything on the same domain. Right now, the bosch http-bind endpoint is this http://localhost:5280/http-bind/ and we need it to be this http://localhost.demo.com/http-bind. Download and install the Application Request Routing for IIS. Once installed follow these steps to enable proxy.
</p>

<ol>
	<li>Open IIS Manager</li>
	<li>Select a server node in the tree view on the left hand side and then click on the &#8220;Application Request Routing&#8230;&#8221; the full name shows up as &#8220;Application Request Routing Cache&#8221;</li>
	<li>Then on the far right side click on &#8220;Server Proxy Settings&#8230;</li>
	<li>check the box next to Enable proxy and apply settings (keep everything else default)</li>
</ol>

<p>
Finally, add a rewrite rule to the web.config file in your inetpub root dir. For example, mine is located &#8220;C:\inetpub\wwwroot\web.config&#8221;. Here is my full XML configuration file:
</p>

<pre class="brush: xml; title: ; notranslate">

&lt;rewrite&gt;
    &lt;rules&gt;
          &lt;rule name=&quot;ejabberd.BOSH&quot; stopProcessing=&quot;true&quot;&gt;
               	&lt;match url=&quot;^http-bind&quot; /&gt;
               	&lt;action type=&quot;Rewrite&quot; url=&quot;http://localhost.demo.com:5280/http-bind/&quot; /&gt;
          &lt;/rule&gt;
    &lt;/rules&gt;
&lt;/rewrite&gt;
</pre>

<p>Now you should be able to run the demo at http://localhost.demo.com/xmppExample/strophejs/examples/basic.html. You will need to login with admin@localhost.demo.com (if admin is the username you selected during install) and the password you selected during install.</p>

<blockquote>I can also be found on Google+

<a title="Jason Rowe is on Google+" rel="author" href="http://profiles.google.com/jasonrowe?rel=author" alt="Google+" title="Google+">Jason Rowe</a> and twitter <a title="Jason Rowe is on twitter" rel="author" href="http://twitter.com/jsonrow?rel=author" alt="twitter" title="twitter">@jsonrow</a>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2011/11/18/strophejs-ejabberd-iis-setup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting back into JavaScript</title>
		<link>http://jasonrowe.com/2011/11/02/getting-back-into-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-back-into-javascript</link>
		<comments>http://jasonrowe.com/2011/11/02/getting-back-into-javascript/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 04:17:32 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[charting]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1498</guid>
		<description><![CDATA[The last time I did any serious JavaScript was around the time Sizzle was added to JQuery, Google Chrome was brand new, and MarketWatch.com started using canvas charts. Note: Here is a quick overview of JavaScript that is as short &#8230; <a href="http://jasonrowe.com/2011/11/02/getting-back-into-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The last time I did any serious JavaScript was around the time Sizzle was added to JQuery, Google Chrome was brand new, and MarketWatch.com started using canvas charts.</p> 

<p><strong>Note:</strong> Here is a quick <a href="http://www.2ality.com/2011/10/javascript-overview.html">overview of JavaScript</a> that is as short as possible, but explains every major feature. I would also recommend following the <a href="http://www.2ality.com/">2ality</a> website</p>

<p>Today JavaScript projects have the complexity, size, and structure of projects written in languages like C# and Java. Thankfully, the developer tools for debugging and logging are solid across browsers. *<i>Opera is still a little funky about logging using &#8220;opera.postError.apply(opera, arguments);&#8221;</i>. Looking particularly good, <a href="http://code.google.com/chrome/devtools/">Google&#8217;s version of the webkit dev tools</a> and some API&#8217;s they have in <a href="http://code.google.com/chrome/extensions/dev/experimental.devtools.html">beta</a>. I’ve started to use <a href="http://docs.jquery.com/QUnit">quint</a> for unit testing. I’ve also been looking leveraging these frameworks: <a href="http://documentcloud.github.com/underscore/">underscore.js</a>, <a href="http://jashkenas.github.com/coffee-script/">coffee script</a>, <a href="http://raphaeljs.com/">raphaeljs</a>, and <a href="http://code.google.com/closure/compiler/">closure compiler</a>.</p> <p>It’s amazing how much has changed. Now <a href="https://developer.mozilla.org/en/JavaScript/Reference">examples of good JavaScript</a> are much easier to find. Hell, here is a step by step walkthrough of how to <a href="http://dailyjs.com/tags.html#lmaf">build your very own JavaScript framework</a>.</p> 

<p>So to get some practice I went and found some JS that needed cleanup. I wanted to focus on structure and namespaces and this <a href="http://www.elated.com/res/File/articles/development/javascript/snazzy-animated-pie-chart-html5-jquery/">script</a> needed some love. View source on that page and you will notice global variables and one big pile of code.</p> <p>The first thing I did was break up the logic into separate functional script files that will later be compiled and minified into one. You can see the python script I use to minify <a href="https://raw.github.com/JasonRowe/SimpleHTML5.Charts/master/build.py">here</a>.</p> 

<ol> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/animation.js">animation.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/builder.js">builder.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/core.js">core.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/pie.js">pie.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/rendering.js">rendering.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/styles.js">styles.js</a></li>
</ol> 

<p>I then added a <a href="https://github.com/JasonRowe/SimpleHTML5.Charts/tree/master/test">test folder</a> and setup the same file names but which had test cases for each script. Then an index.html file to display the test groups or “modules” as they are called in QUnit. Here is an example of a test that always passes</p> 

<pre class="brush: jscript; title: ; notranslate">
module(&quot;sample test&quot;);

test(&quot;a sample qunit test&quot;, function () {
    ok(true, &quot;always fine&quot;);
});

</pre>  

<p>The next thing I worked on was getting a namespace around the code. I went with the following which seems to work for my needs.</p> 

<pre class="brush: jscript; title: ; notranslate">
var SimpleHtml5 = SimpleHtml5 || {};

SimpleHtml5.namespace = function (ns_string) {
    'use strict';
    var parts = ns_string.split('.'), parent = SimpleHtml5, i;
    if (parts[0] === &quot;SimpleHtml5&quot;) {
        parts = parts.slice(1);
    }
    for (i = 0; i &lt; parts.length; i += 1) {
        if (typeof parent[parts[i]] === &quot;undefined&quot;) {
            parent[parts[i]] = {};
        }
        parent = parent[parts[i]];
    }
    return parent;
};

</pre>  

<p>Stefanov, Stoyan (2010). JavaScript Patterns (pp. 89-90). OReilly Media &#8211; A. Kindle Edition. </p>

<p>So after refactoring, I’ve got the pie chart setup code to the following.</p>

<pre class="brush: jscript; title: ; notranslate">
var pieElm = document.getElementById('pieChart');
var pieData = $('#chartData td');

var pieChart = new SimpleHtml5.Core.Pie(pieElm, pieData);

$('#pieChart').click (pieChart, SimpleHtml5.Pie.Animation.HandleChartClick);
</pre>

<p>To customize the style I allow passing in a custom style object to override the defaults.</p>

<pre class="brush: jscript; title: ; notranslate">

var customStyles = {
    chartSizePercent: 49,
    maxPullOutDistance: 10,
    pullOutFrameStep: 4,
    pullOutFrameInterval: 40,
    pullOutLabelPadding: 42
};

var pieElm = document.getElementById('pieChart');
var pieData = $('#chartData td');
var pieChart = new SimpleHtml5.Core.Pie(pieElm, pieData, customStyles);
$('#pieChart').click (pieChart, SimpleHtml5.Pie.Animation.HandleChartClick);
</pre>

<p>
If you are curious about how the other parts of the chart were organized you can see the source code on <a href="https://github.com/JasonRowe/SimpleHTML5.Charts">github</a>.
</p>

<p>

<blockquote>I can also be found on Google+

<a title="Jason Rowe is on Google+" rel="author" href="http://profiles.google.com/jasonrowe?rel=author" alt="Google+" title="Google+">Jason Rowe</a> and twitter <a title="Jason Rowe is on twitter" rel="author" href="http://twitter.com/jsonrow?rel=author" alt="twitter" title="twitter">@jsonrow</a>
</blockquote>


</p>

]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2011/11/02/getting-back-into-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing Chart Color by Previous Close</title>
		<link>http://jasonrowe.com/2011/01/16/changing-chart-color-by-previous-close/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=changing-chart-color-by-previous-close</link>
		<comments>http://jasonrowe.com/2011/01/16/changing-chart-color-by-previous-close/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 01:40:14 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[charting]]></category>
		<category><![CDATA[gRaphaël]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1438</guid>
		<description><![CDATA[&#160; I frequently get asked how to create a chart in JavaScript that shows a different line color above and below the previous close price. Here is a example of what I mean. View this test page if you want &#8230; <a href="http://jasonrowe.com/2011/01/16/changing-chart-color-by-previous-close/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p> 

<p>I frequently get asked how to create a chart in JavaScript that shows a different line color above and below the previous close price. Here is a example of what I mean.</p> 

<p><a href="http://jasonrowe.com/wp-content/uploads/2011/01/final_example.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="final_example" border="0" alt="final_example" src="http://jasonrowe.com/wp-content/uploads/2011/01/final_example_thumb.png" width="244" height="177"></a></p> 

<p>View this <a href="http://jasonrowe.com/misc/chart/prevcloseline.html">test page</a> if you want skip the details and see a working example in JavaScript/SVG</p>

<p>At first glance, I’ve always thought this would be very easy and instructed them to create a new path depending on if the line is above or below the previous close line (the blue line in the image above). Simple enough right?</p> 

<p>It turns out I was missing a crucial step that might go unnoticed if you are using many data points. The problem turns up when using sparse data like the example shown above.</p> <p>Here is what it looks like if you do what I said literally.</p> <p><a href="http://jasonrowe.com/wp-content/uploads/2011/01/simple_start_broken.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="simple_start_broken" border="0" alt="simple_start_broken" src="http://jasonrowe.com/wp-content/uploads/2011/01/simple_start_broken_thumb.png" width="244" height="178"></a>&nbsp; </p> <p>&nbsp;</p> <p>That missing step I mentioned is connecting the new lines. Seems obvious now that I look at an example. So how will this be done? Here is an image showing the paths with labels for easy reference.</p> 

<p><a href="http://jasonrowe.com/wp-content/uploads/2011/01/simple_paths_connections.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="simple_paths_connections" border="0" alt="simple_paths_connections" src="http://jasonrowe.com/wp-content/uploads/2011/01/simple_paths_connections_thumb.png" width="244" height="179"></a></p> 

<p>What I have found works best is to find the intersection point between the paths and the previous close line. So you would create one line using the last point from path 1 and the first points from path2. The second line would just be the previous close line points. Unfortunately, just having the points is not enough to calculate the intersection.</p> 

<p>Below is the needed format and calculation. I created a function to do this in JS which is provided below but I wanted to include the <a href="http://www.topcoder.com/tc?module=Static&#038;d1=tutorials&#038;d2=geometry2">full explanation. </a></p> 
<blockquote>

Say we are given two different points, (x1, y1) and (x2, y2), and want to find A, B and C for the equation above. We can do so by setting

A = y2-y1
B = x1-x2
C = A*x1+B*y1

Regardless of how the lines are specified, you should be able to generate two different points along the line, and then generate A, B and C. Now, lets say that you have lines, given by the equations:

A1x + B1y = C1
A2x + B2y = C2

To find the point at which the two lines intersect, we simply need to solve the two equations for the two unknowns, x and y. 

 double det = A1*B2 &#8211; A2*B1
    if(det == 0){
        //Lines are parallel
    }else{
        double x = (B2*C1 &#8211; B1*C2)/det
        double y = (A1*C2 &#8211; A2*C1)/det
    }
</blockquote>


<p>Here is the full function in JS to create this format and find the intersection.</p> 



<pre class="brush: jscript; title: ; notranslate">
  //Line-Line Intersection
        var getXCrossing = function(p1x, p1y, p2x, p2y, marker, markerMaxX) {
               
                var retValX = 0;
                var retValY = 0;
               
                //graph lines
                var a1 = p2y - p1y;
                var b1 = p1x - p2x;
                var c1 = a1 * p1x + b1 * p1y;
                
                //marker line is always horizontal
                var a2 = marker - marker;
                var b2 = 0 - markerMaxX;
                var c2 = a2 * 0 + b2 * marker;
                
                var det = a1 * b2 - a2 * b1;
                
                if(det === 0)
                {
                    //Lines are parallel
                }
                else
                {
                    retValX = (b2 * c1 - b1 * c2) / det;
                    retValY = (a1 * c2 - a2 * c1) / det;
                }   
                
                return {
                        x: retValX,
                        y: retValY
                    };
                };
</pre>

<p>Here is a <a href="http://jasonrowe.com/misc/chart/prevcloseline.html">test page</a> which shows a working example in SVG using <a href="http://g.raphaeljs.com/">gRaphaël</a> JavaScript library.</p>
]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2011/01/16/changing-chart-color-by-previous-close/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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&#038;utm_medium=rss&#038;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[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.

<pre class="brush: jscript; title: ; notranslate">

&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&#038;utm_medium=rss&#038;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[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.

1) I had to run my JQuery code in no conflict mode. Which is a very simple change.

<pre class="brush: jscript; title: ; notranslate">

var J = jQuery.noConflict();

</pre>

Then replace all your #&#8217;s with J.

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.

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.]]></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&#038;utm_medium=rss&#038;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[<strong>Javascript Closure</strong>

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.

The function that was leaking looked like this:

<pre class="brush: jscript; title: ; notranslate">

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>

The fix was to remove the object from being a local variable.

<pre class="brush: jscript; title: ; notranslate">

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>

<strong>Drip
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.

<strong></strong><strong></strong><strong>Other Tools</strong>

<strong></strong><strong></strong><strong> </strong>

Setting up IE and Firefox private bytes counters under process in Perfmon is the most reliable way to monitor JS memory leaks.

<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>

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.

IE also has a tool bar for JS memory leaks but it didn&#8217;t work in my situation very well.

Some good pages for review:
<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>
<strong></strong><strong><a href="http://www.codeproject.com/KB/scripting/leakpatterns.aspx"></a></strong>]]></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>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&#038;utm_medium=rss&#038;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[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>

The article has lots of examples if you click on the figure links. Here was a useful one on Inheriting from a Prototype:

<code>
Inheriting from a Prototypefunction GreatDane() { }
var rover = new GreatDane();
var spot = new GreatDane();
GreatDane.prototype.getBreed = function() {
return “Great Dane”;
};</code><code>// Works, even though at this point
// rover and spot are already created.
alert(rover.getBreed());
// this hides getBreed() in GreatDane.prototype
spot.getBreed = function() {
return “Little Great Dane”;
};
alert(spot.getBreed());
// but of course, the change to getBreed
// doesn’t propagate back to GreatDane.prototype
// and other objects inheriting from it,
// it only happens in the spot object
alert(rover.getBreed());

</code>]]></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>
	</channel>
</rss>

