<?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>Floorplanner Tech Blog &#187; Javascript</title>
	<atom:link href="http://techblog.floorplanner.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.floorplanner.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 19 Nov 2009 04:00:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Crossdomain JSON troubles: JSONCrossdomainRequest</title>
		<link>http://techblog.floorplanner.com/2008/12/05/crossdomain-ajax-json-request-troubles/</link>
		<comments>http://techblog.floorplanner.com/2008/12/05/crossdomain-ajax-json-request-troubles/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 12:58:07 +0000</pubDate>
		<dc:creator>jaap</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[crossdomain]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[request]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=292</guid>
		<description><![CDATA[This week I was doing some work on a crossdomain JSON request. This was a pitty, because I had in mind, Ajax requests could be made between subdomains, but that wasn&#8217;t the case, therefore I had to come up with a solution.
Solution 1: Server-side proxy
One option we had, was a server-side proxy, but I didn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F12%2F05%2Fcrossdomain-ajax-json-request-troubles%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F12%2F05%2Fcrossdomain-ajax-json-request-troubles%2F" height="61" width="51" /></a></div><p>This week I was doing some work on a crossdomain JSON request. This was a pitty, because I had in mind, Ajax requests could be made between subdomains, but that wasn&#8217;t the case, therefore I had to come up with a solution.</p>
<p><strong>Solution 1: Server-side proxy</strong><br />
One option we had, was a server-side proxy, but I didn&#8217;t like this solution. If you are proxying your crossdomain request through a webserver that has to handle a lot of requests per second, these requests can block other requests, because proxying is always a slow process.</p>
<p><strong>Solution 2: JSONP</strong><br />
Then there is the <a href="http://Ajaxian.com/archives/jsonp-json-with-padding">JSONP method</a>, which includes a script on the fly in the browser and this script is then evaluated. The problem however with this approach is that your JSON resources have to be rewritten as a evaluation. This evaluation is then executed and your JSON loaded in a variable.</p>
<p>Instead of:</p>
<pre><code>{"somejsonobject":1}
</code></pre>
<p>you have to write:</p>
<pre><code>var jsonobject = {"somejsonobject":1};
someCallback(jsonobject);
</code></pre>
<p>This is not very clean, because you have to decide in your remote JSON file what the variable will be named. JSONP is a method in which you give a variable and callback in the url and then the JSON will be rewritten. This solution is just not the right way, as we programmers all know why it is better to isolate logic from real data.</p>
<p><strong>Solution 3: Crossdomain through flash</strong><br />
Then I looked at another solution that does crossdomain Ajax requests through a flash proxy. These solutions all gave a lot of problems, cause the encoding of characters was not handled properly by the Flash ExternalInterface compononent, which sended the JSON string it received to Javascript.</p>
<p><strong>Solution 4: Parsing the JSON by flash</strong><br />
I then tried to make a solution myself that doesn&#8217;t send JSON string to Javascript, but (thanks for the idea <a href="http://www.twitter.com/hertog">Gert-Jan</a>) sends the objects to Javascript. So the JSON is parsed into an object at the Actionscript side and it now all works. The project is opensourced under a MIT license and called: JSONCrossdomainRequest. It is a js file which includes a swf file in your page that can handle the requests. Please come over to GitHub and read more about how to install and use this project. The Actionscript project is also included. Good luck if you are going to use it and if you have any modifications let me know, it is a work in progress and we appreciate any help!</p>
<p><strong>Project location:</strong><br />
<a href="http://github.com/japetheape/jsoncrossdomainrequest/tree/master">http://github.com/japetheape/jsoncrossdomainrequest/tree/master</a></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/12/05/crossdomain-ajax-json-request-troubles/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Generating thumbnails</title>
		<link>http://techblog.floorplanner.com/2008/11/26/generating-thumbnails/</link>
		<comments>http://techblog.floorplanner.com/2008/11/26/generating-thumbnails/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 06:27:05 +0000</pubDate>
		<dc:creator>Willem van Bergen</dc:creator>
				<category><![CDATA[Floorplanner]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[client-side]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[S3]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=271</guid>
		<description><![CDATA[I would like to thank you all for helping us build our thumbnail database!  I presume this statement might be in need of some clarification, so bear with me when I go into the technical details on this one.
For every design that is saved on Floorplanner, we create a thumbnail in JPEG format. We [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F11%2F26%2Fgenerating-thumbnails%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F11%2F26%2Fgenerating-thumbnails%2F" height="61" width="51" /></a></div><p>I would like to thank you all for helping us build our thumbnail database! <br /> I presume this statement might be in need of some clarification, so bear with me when I go into the technical details on this one.</p>
<p>For every design that is saved on Floorplanner, we create a thumbnail in JPEG format. We use these thumbnails for the <a href="http://beta.floorplanner.com/gallery">gallery</a>, and now we have included them on everyone&#8217;s <a href="http://beta.floorplanner.com/dashboard">dashboard</a>. However, for various reasons, we do not have a thumbnail available for every design. However, with your help, we are improving the thumbnail database while you our browsing the site!</p>
<p>The thumbnail images are stored on <a href="http://aws.amazon.com/s3/">Amazon AWS S3</a>. We know the URL that a thumbnail of a design should have, but we do not know if it actually is available. In the latter case, the result is a nasty <em>image not found</em> placeholder on the dashboard. This of course is not acceptable! We cannot know if a thumbnail exists other than doing a request to the URL and see whether we get an image back from Amazon, or a HTTP 404 status. This is a very time-consuming procedure to run server side so we chose to find a client-side solution.</p>
<p>We found that javascript can be used to check if an image exist. An AJAX call cannot be used, because cross-site calls are not supported. However, the javascript <code>Image</code> object <em>can</em> be used for this purpose.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family: Monaco,monospace;"><span style="color: #003366; font-weight: bold;">var</span> img <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
img.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// image was found and loaded successfully</span>
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img-tag'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> img.<span style="color: #660066;">src</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
img.<span style="color: #000066;">onerror</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// An error occured while loading the image</span>
  document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img-tag'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/images/thumb-unavailable.jpg'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Setting the src property will trigger the events.</span>
img.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://link.to.amazon.s3/design/thumbnail.jpg'</span><span style="color: #339933;">;</span></pre></div></div>

<p>A nice <em>thumbnail not available</em> image will be shown if the thumbnail file cannot be found on S3. This is much nicer, and the check is completely done client-side! However, we found a way this could even be better by changing the <code>onerror</code> event handler. Instead of displaying a <em>thumbnail not available</em> image, we can simply load a small instance of the Floorplanner application to display a small version of the design. Moreover, we can instruct it to generate a thumbnail JPEG and save it to S3!</p>
<p>So, every time you see a small Floorplanner loading on your dashboard, you are creating a missing thumbnail. Next time, the thumbnail will be available on S3 and there will be no need to start the Floorplanner application. A nice example of <a href="http://en.wikipedia.org/wiki/Distributed_computing">distributed computing</a>, mixed with a hint of <a href="http://setiathome.berkeley.edu/">SETI@home</a>. I like it!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/11/26/generating-thumbnails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drag&#8217;n&#039;drop from HTML to Flash</title>
		<link>http://techblog.floorplanner.com/2008/11/06/dragndrop-from-html-to-flash/</link>
		<comments>http://techblog.floorplanner.com/2008/11/06/dragndrop-from-html-to-flash/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 10:42:12 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[drag]]></category>
		<category><![CDATA[drop]]></category>
		<category><![CDATA[externalinterface]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[script.aculo.us]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=247</guid>
		<description><![CDATA[Last week we released a new Floorplanner account, the Enterprise account. With it, companies can have an online Floorplanner solution completely branded to their wishes. It includes the Roomplanner module and a custom library of their own furniture elements.  Steelcase and Maxon are the first to have an active Enterprise account.

The interesting part of this [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F11%2F06%2Fdragndrop-from-html-to-flash%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F11%2F06%2Fdragndrop-from-html-to-flash%2F" height="61" width="51" /></a></div><p>Last week we released a new Floorplanner account, the <a href="http://beta.floorplanner.com/products/comparison">Enterprise account</a>. With it, companies can have an online Floorplanner solution completely branded to their wishes. It includes the Roomplanner module and a custom library of their own furniture elements.  <a href="http://steelcase.floorplanner.com">Steelcase</a> and <a href="http://maxon.floorplanner.com">Maxon</a> are the first to have an active Enterprise account.</p>
<div style="float:right;margin-left:10px;margin-bottom:10px;border:1px solid #ccc;"><img title="drag-n-drop" src="http://techblog.floorplanner.com/wp-content/uploads/2008/11/afbeelding-7.png" alt="" width="296" height="150" /></div>
<p>The interesting part of this release, from a tech point of view, is the new drag-and-drop functionality. The Roomplanner is running in the Flash Player. However, the library of furniture elements is in HTML. We chose to build the furniture library in the HTML sidebar for a couple of reasons. It&#8217;s not in the Roomplanner, so there is more space left to design. It gives us more freedom in the page layout. All items on the page are indexed and things like sorting and tags we&#8217;re easier to build in Ruby on Rails than in Flash.</p>
<p>Now we only needed a way to get the furniture from the sidebar to the Roomplanner. That&#8217;s where the drag&#8217;n'drop comes in, drag from HTML and drop in Flash. To drag an image of a furniture element in HTML we used the fantastic JavaScript <a href="http://script.aculo.us/">script.aculo.us</a> framework. The next step was to swap the image to an element in the Roomplanner and to update the position of the element while moving the cursor on the Flash content. For this we used ExternalInterface to communicate between JavaScript and ActionScript. That&#8217;s all there is to it. The theory is actually quite simple, but in practice it was very (I repeat, VERY) difficult to get it working in all the main browsers. All those nitty gritty browser details&#8230;</p>
<p>At this moment everything seems to work just fine, so please take a look at <a href="http://steelcase.floorplanner.com">Steelcase</a> and/or <a href="http://maxon.floorplanner.com">Maxon</a> and let me know what you think!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/11/06/dragndrop-from-html-to-flash/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using setInterval in a JavaScript class</title>
		<link>http://techblog.floorplanner.com/2008/07/16/using-setinterval-in-a-javascript-class/</link>
		<comments>http://techblog.floorplanner.com/2008/07/16/using-setinterval-in-a-javascript-class/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 10:13:48 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[setInterval]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=98</guid>
		<description><![CDATA[I just figured out how to use setInterval in a JavaScript class. This little snippet shows how I used setInterval in a recursive way.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function MyClass&#40;&#41; &#123;&#125;
&#160;
MyClass.prototype.doNext = function&#40; pArray &#41; &#123;
	clearInterval&#40; this.interval &#41;;
&#160;
	if&#40; pArray.length &#62; 0 &#41; &#123;
		// do something with the array record
		this.doSomething&#40; pArray.pop&#40;&#41; &#41;;
&#160;
		// call this function again in a couple of milliseconds
		var [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F07%2F16%2Fusing-setinterval-in-a-javascript-class%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F07%2F16%2Fusing-setinterval-in-a-javascript-class%2F" height="61" width="51" /></a></div><p>I just figured out how to use setInterval in a JavaScript class. This little snippet shows how I used setInterval in a recursive way.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="javascript" style="font-family: Monaco,monospace;"><span style="color: #003366; font-weight: bold;">function</span> MyClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
MyClass.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">doNext</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> pArray <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	clearInterval<span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">interval</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> pArray.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// do something with the array record</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">doSomething</span><span style="color: #009900;">&#40;</span> pArray.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// call this function again in a couple of milliseconds</span>
		<span style="color: #003366; font-weight: bold;">var</span> scope <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> milliseconds <span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">interval</span> <span style="color: #339933;">=</span> setInterval<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> scope.<span style="color: #660066;">doNext</span><span style="color: #009900;">&#40;</span> pArray <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> milliseconds <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span> 
&nbsp;
MyClass.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">doSomething</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> pRecord <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// do something</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> myObj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> MyClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myObj.<span style="color: #660066;">doNext</span><span style="color: #009900;">&#40;</span> myArray <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/07/16/using-setinterval-in-a-javascript-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mousewheel events in Flash on OS X</title>
		<link>http://techblog.floorplanner.com/2008/05/07/using-mousewheel-in-the-flash-player-on-mac-os-x/</link>
		<comments>http://techblog.floorplanner.com/2008/05/07/using-mousewheel-in-the-flash-player-on-mac-os-x/#comments</comments>
		<pubDate>Wed, 07 May 2008 08:05:12 +0000</pubDate>
		<dc:creator>Rinde van Lon</dc:creator>
				<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Floorplanner]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[OS X]]></category>

		<guid isPermaLink="false">http://www.suite75.net/blog/dev/using-mousewheel-in-the-flash-player-on-mac-os-x.html</guid>
		<description><![CDATA[The Flash Player on OS X currently lacks support for mousewheel events. This means that users cannot use their mousewheel on OS X, in the Floorplanner we use the mousewheel to easily zoom in to your Floorplan. After reading this post from pixelbreaker, I was inspired to implement this in the Floorplanner which was, in [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F05%2F07%2Fusing-mousewheel-in-the-flash-player-on-mac-os-x%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F05%2F07%2Fusing-mousewheel-in-the-flash-player-on-mac-os-x%2F" height="61" width="51" /></a></div><p>The Flash Player on OS X currently lacks support for mousewheel events. This means that users cannot use their mousewheel on OS X, in the <a href="http://www.floorplanner.com/">Floorplanner</a> we use the mousewheel to easily zoom in to your Floorplan. After reading this post from <a href="http://blog.pixelbreaker.com/flash/as30-mousewheel-on-mac-os-x/">pixelbreaker</a>, I was inspired to implement this in the Floorplanner which was, in fact, very easy. I decided to only use the JavaScript class of pixelbreaker, which sends the mousewheel events to the Flash Player (on the Mac). In the Floorplanner ActionScript this event is handled by our own internal Event management system, which sends the Event to the reponsible part of the code. So thumbs up for <a href="http://blog.pixelbreaker.com/">pixelbreaker</a>, for making this really easy to implement!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/05/07/using-mousewheel-in-the-flash-player-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSON Validator</title>
		<link>http://techblog.floorplanner.com/2008/04/15/json-validator/</link>
		<comments>http://techblog.floorplanner.com/2008/04/15/json-validator/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 09:12:51 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Floorplanner]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.suite75.net/blog/dev/json-validator.html</guid>
		<description><![CDATA[I&#8217;m currently working on a JSON export from the Floorplanner and I&#8217;m glad I found the excelent JSON Validator made by arc90 lab. They made the debugging process a lot easier. Thanks guys!
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F04%2F15%2Fjson-validator%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F04%2F15%2Fjson-validator%2F" height="61" width="51" /></a></div><p>I&#8217;m currently working on a JSON export from the <a href="http://www.floorplanner.com/">Floorplanner</a> and I&#8217;m glad I found the excelent <a href="http://www.jsonlint.com/">JSON Validator</a> made by <a href="http://lab.arc90.com/">arc90 lab</a>. They made the debugging process a lot easier. Thanks guys!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/04/15/json-validator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Consume SOAP web service from Javascript</title>
		<link>http://techblog.floorplanner.com/2008/04/02/consume-soap-web-service-from-javascript/</link>
		<comments>http://techblog.floorplanner.com/2008/04/02/consume-soap-web-service-from-javascript/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 15:47:53 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[NuSOAP]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.suite75.net/blog/dev/consume-soap-web-service-from-javascript.html</guid>
		<description><![CDATA[I wanted to get some data from a web service using Javascript. I looked at several Javascript classes (like this), but because the web service was running on another server it got a little troublesome. As a solution I tried to call the web service through a proxy, but that didn&#8217;t make it any easier.
Jaap [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F04%2F02%2Fconsume-soap-web-service-from-javascript%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F04%2F02%2Fconsume-soap-web-service-from-javascript%2F" height="61" width="51" /></a></div><p>I wanted to get some data from a web service using Javascript. I looked at several Javascript classes (like <a href="http://www.codeproject.com/KB/ajax/JavaScriptSOAPClient.aspx">this</a>), but because the web service was running on another server it got a little troublesome. As a solution I tried to call the web service through a proxy, but that didn&#8217;t make it any easier.</p>
<p>Jaap suggested to take a look at <a href="http://sourceforge.net/projects/nusoap/">NuSOAP</a>, a -kinda old- SOAP toolkit for PHP. With an AJAX request I could call a PHP page that uses NuSOAP to consume the web service. It was actually easier then I thought it would be.</p>
<p>To make the AJAX call from Javascript I used <a href="http://prototypejs.org/">Prototype</a> and this script:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family: Monaco,monospace;">  <span style="color: #003366; font-weight: bold;">function</span> doRequest<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> url <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;ajax/consume_webservice.php&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> param1 <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;value1&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> param2 <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;value2&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;param1=&quot;</span><span style="color: #339933;">+</span> param1 <span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&amp;param2=&quot;</span><span style="color: #339933;">+</span> param2<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Request</span> <span style="color: #009900;">&#40;</span> url<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span> parameters<span style="color: #339933;">:</span> params<span style="color: #339933;">,</span>
      onComplete<span style="color: #339933;">:</span> onResult <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> onResult<span style="color: #009900;">&#40;</span> result <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> result.<span style="color: #660066;">responseText</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>The PHP file consume.php looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family: Monaco,monospace;"><span style="color: #339933;">&lt;</span> ?php
&nbsp;
  <span style="color: #000088;">$param1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$POST_</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param1'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$POST_</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param1'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$param2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$POST_</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param2'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$POST_</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'param2'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// this is the only file I used from the NuSOAP project</span>
  <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;nusoap.php&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> webserviceurl<span style="color: #339933;">;</span>
  <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;param1&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$param1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;param2&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$param2</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$soap</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> nusoap_client<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">60</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$proxy</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$soap</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getProxy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$proxy</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">functionname</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$params</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$proxy</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">response</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>That&#8217;s all. Do a AJAX request from Javascript to a PHP page. Then the PHP page uses NuSOAP to consume the web service and returns the result. Back in Javascript you can do whatever you want with the given data.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/04/02/consume-soap-web-service-from-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rounding errors in practice</title>
		<link>http://techblog.floorplanner.com/2008/03/28/rounding-errors-in-practice/</link>
		<comments>http://techblog.floorplanner.com/2008/03/28/rounding-errors-in-practice/#comments</comments>
		<pubDate>Fri, 28 Mar 2008 14:03:47 +0000</pubDate>
		<dc:creator>Willem van Bergen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.suite75.net/blog/dev/rounding-errors-in-practice.html</guid>
		<description><![CDATA[In college I followed a course in numerical analysis. The main point of the course was to be careful with floating point arithmetic, because it is vulnerable to rounding errors that can significantly influence the result of complex computations. Until yesterday I never had encountered such a problem. Now that I have lost my innocence [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F03%2F28%2Frounding-errors-in-practice%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F03%2F28%2Frounding-errors-in-practice%2F" height="61" width="51" /></a></div><p>In college I followed a course in <a href="http://en.wikipedia.org/wiki/Numerical_analysis">numerical analysis</a>. The main point of the course was to be careful with floating point arithmetic, because it is vulnerable to rounding errors that can significantly influence the result of complex computations. Until yesterday I never had encountered such a problem. Now that I have lost my innocence in this matter, I would like to share my tale of nasty debugging and frustration.</p>
<p>After receiving some bug reports of Floorplanner designs that failed to save properly, we dove into the code to see what was going wrong. After some time, we found that the errors were caused by the script that loads the design after it has been saved with a unique name. This unique name is passed to the script to be able to find the design. We used the current timestamp as a unique name for the design. The current timestamp simply is the number of seconds passed since January 1, 1970 and looks something like this: 1206712028. As a design name, this number was passed to different scripts, both client-side and server-side. However, at some point in this chain of scripts, the number was changed slightly to 1206712030 and because of this the associated design could not be found, resulting in an error.</p>
<p>At first, we investigated the possibility that the stored timestamp was overwritten by a newer timestamp, as this could explain the slight increase in the number. However, we were not able to find this anywhere in the code and sometimes, the number was decreased a bit instead of being increased.</p>
<p>Finally, we monitored the data being sent between the different scripts, and we found that ActionScript automatically converted the numeric design name into a number in scientific notation. In our case, this would be 0.1206712028 x 10^10. Unfortunately, this number was rounded to 0.120671203 x 10^10 because computers use floating point arithmetic to store numbers in scientific notation. This number would eventually be converted back to normal notation, but it was now 1206712030 because of the rounding error.</p>
<p>We fixed it by putting an &#8216;a&#8217; in front of the timestamp, preventing the automatic conversion to a number. Not very elegant, but it works!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/03/28/rounding-errors-in-practice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encoding UTF-8 in Javascript</title>
		<link>http://techblog.floorplanner.com/2008/03/25/encoding-utf-8-in-javascript/</link>
		<comments>http://techblog.floorplanner.com/2008/03/25/encoding-utf-8-in-javascript/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 17:16:38 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.suite75.net/blog/dev/encoding-utf-8-in-javascript.html</guid>
		<description><![CDATA[I had to make a call from Javascript to a SOAP web service (more on that later). The data I had to send to the web service was in a XML format that contained non ASCII characters (for example: é). I tried to use the standard escape() function, but that one couldn&#8217;t handle the special [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F03%2F25%2Fencoding-utf-8-in-javascript%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F03%2F25%2Fencoding-utf-8-in-javascript%2F" height="61" width="51" /></a></div><p>I had to make a call from Javascript to a SOAP web service (more on that later). The data I had to send to the web service was in a XML format that contained non ASCII characters (for example: é). I tried to use the standard <b>escape()</b> function, but that one couldn&#8217;t handle the special characters.</p>
<p>Thanks to <a href="http://ecmanaut.blogspot.com/2006/07/encoding-decoding-utf8-in-javascript.html">ecmanaut</a> I found a very simple solution: <b>encodeURIComponent()</b> (with <b>decodeURIComponent()</b> as its counterpart).</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/03/25/encoding-utf-8-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript &amp; XML</title>
		<link>http://techblog.floorplanner.com/2008/02/14/javascript-xml/</link>
		<comments>http://techblog.floorplanner.com/2008/02/14/javascript-xml/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 14:21:59 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.suite75.net/blog/dev/javascript-xml.html</guid>
		<description><![CDATA[Recently I&#8217;ve been working with Javascript in combination with XML and I found these methods quite usefull to switch between a string and a xml object.

function stringToXML( pString ){
	var lXML;
	// IE
	if( window.ActiveXObject ){
		lXML = new ActiveXObject( 'Microsoft.XMLDOM' );
		lXML.async = 'false';
		lXML.loadXML( pString );
	// no IE
	} else {
		var lParser = new DOMParser();
		lXML = lParser.parseFromString( pString, 'text/xml' );
	}
	return [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F02%2F14%2Fjavascript-xml%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F02%2F14%2Fjavascript-xml%2F" height="61" width="51" /></a></div><p>Recently I&#8217;ve been working with Javascript in combination with XML and I found these methods quite usefull to switch between a string and a xml object.</p>
<pre lang=javascript">
function stringToXML( pString ){
	var lXML;
	// IE
	if( window.ActiveXObject ){
		lXML = new ActiveXObject( 'Microsoft.XMLDOM' );
		lXML.async = 'false';
		lXML.loadXML( pString );
	// no IE
	} else {
		var lParser = new DOMParser();
		lXML = lParser.parseFromString( pString, 'text/xml' );
	}
	return lXML;
}

function xmlToString( pXML ){
	// IE
	if( window.ActiveXObject ){
		return pXML.xml;
	// no IE
	} else {
		return ( new XMLSerializer() ).serializeToString( pXML );
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/02/14/javascript-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
