<?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>Blog &#187; Javascript</title>
	<atom:link href="http://blog.marcuscobden.co.uk/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.marcuscobden.co.uk</link>
	<description>Reflections of a compulsive engineer</description>
	<lastBuildDate>Wed, 01 Sep 2010 10:05:25 +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>Not your regular TI-83</title>
		<link>http://blog.marcuscobden.co.uk/2008/11/not-your-regular-ti-83/</link>
		<comments>http://blog.marcuscobden.co.uk/2008/11/not-your-regular-ti-83/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 18:05:00 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Graph]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://newblog.marcuscobden.co.uk/?p=11</guid>
		<description><![CDATA[Over a couple of days I put together a <a href="http://www.marcuscobden.co.uk/stuff/2008-10/plot" title="Javascript &#38; Canvas equation plotter">Javascript powered equation plotter</a>, with much the same functionality as my old <a href="http://en.wikipedia.org/wiki/TI-83" title="TI-83 series calculator">TI-83</a>.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve only ever owned one graphical calculator, a <a href="http://en.wikipedia.org/wiki/TI-83" title="TI-83 series calculator">TI-83</a>, which was bought for me around when I started Secondary School. It was the device on which I broke my programming teeth, making crummy games and utilities to make maths exercises less tedious.</p>
<p>The other week I was experimenting with the HTML <a href="http://en.wikipedia.org/wiki/Canvas_tag" title="HTML Canvas tag">Canvas element</a> for another little side-project of mine when I was reminded of the Graph Plot screen which my old calculator has. Essentially it lets you enter a Cartesian equation which it will then plot on the screen.</p>
<p>Subsequently, over a couple of days I put together a <a href="http://www.marcuscobden.co.uk/stuff/2008-10/plot" title="Javascript &amp; Canvas equation plotter"><strong>Javascript powered equation plotter</strong></a>, with much the same functionality as my TI-83. Oh and in the process I found a <a href="https://bugs.webkit.org/show_bug.cgi?id=21888">bug in the WebKit nightly</a>, which they swiftly fixed.</p>
<p>You&#8217;re free to use the <a href="http://www.marcuscobden.co.uk/stuff/2008-10/plot/js/graphPlot.js" title="Javascript equation plotter source code">source</a> to the how you wish, if you&#8217;re that way inclined (it&#8217;s a client-side web script so it&#8217;s practically open source off the bat). Under the hood it makes use of the <a href="http://mootools.net/" title="MooTools - a compact javascript framework">MooTools</a> javascript framework, though I&#8217;ve not made use of its features extensively, so It would only be a matter of an evening&#8217;s work to remove this dependancy.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcuscobden.co.uk/2008/11/not-your-regular-ti-83/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A case of bad cropping</title>
		<link>http://blog.marcuscobden.co.uk/2008/08/case-of-bad-cropping/</link>
		<comments>http://blog.marcuscobden.co.uk/2008/08/case-of-bad-cropping/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 21:41:00 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Applet]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://newblog.marcuscobden.co.uk/?p=10</guid>
		<description><![CDATA[Recently, by pure chance, I&#8217;ve been working for two different research projects which both have involved Java Applets. The first project ran afoul of bug #6669818 which prevented the applet from connecting back to the originating server during LiveConnect calls, in Mozilla Firefox on a Windows XP platform. Fortunately there is a workaround for this; [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, by pure chance, I&#8217;ve been working for two different research projects which both have involved Java Applets.</p>
<p>The first project ran afoul of <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6669818">bug #6669818</a> which prevented the applet from connecting back to the originating server during <a href="http://en.wikipedia.org/wiki/LiveConnect">LiveConnect</a> calls, in Mozilla Firefox on a Windows XP platform.</p>
<p>Fortunately there is a workaround for this; by passing the task off to another thread which was started in a non-LiveConnect part of the <a href="http://java.sun.com/docs/books/tutorial/deployment/applet/lifeCycle.html" title="Applet Lifecycle">Applet&#8217;s lifecycle</a>, the task is then executed in another thread which is not subject to the same malfunctioning security check.</p>
<p>If you&#8217;d rather not have to create a thread just for this, a quick hack is to pass the event off to the applet rendering thread using the <code>SwingUtilities.invokeLater(Runnable);</code> function.</p>
<p>In the second project I&#8217;ve now encountered another platform-specific Applet quirk, this time with Mac OSX.</p>
<p>Using Javascript it is possible to change the size of an Applet on the page in the same way you would any other DOM element, however on Mac OSX any browser using the <a href="http://javaplugin.sourceforge.net/" title="Java Embedding Plugin">Java Embedding Plugin</a> (Firefox, Opera and others) will fail to resize Java Applets correctly.</p>
<p>I&#8217;ve knocked up a simple <a href="http://marcuscobden.co.uk/stuff/2008-07/applet/" title="Applet resize test page">test page</a> which allows this to be tested, and shows a potential workaround.</p>
<p>There appear to be two problems cropping up; the first is that the Browser does not notify the Applet that it ought to resize. If you leave the &#8220;Notify Java&#8221; check-box un-checked when submitting the form, the browser expands the area the Applet ought to be using, but the applet continues to draw in it&#8217;s original position.</p>
<p>The second issue is that when axis are changed and Java is <strong>manually</strong> notified the behaviour still does not perform as it ought to. The clipping region of the Java applet rendering is not updated correctly, and thus only part of the applet is correctly rendered.</p>
<p>There is a temperamental workaround for this, by programatically resizing one axis and then the other in quick succession, but this seems to fail as often as it works, depending on whether the page is being loaded from nothing, refreshed, no-cache refreshed or returned to via the browser &#8216;Back&#8217; action.</p>
<p>In the interest of getting this bug fixed the code to the <a href="http://marcuscobden.co.uk/stuff/2008-07/applet/" title="Applet resize test page">Applet resize test page</a> is linked from the test page and free for all to use.</p>
<p>Bugs:</p>
<ul>
<li>Java Embedding Plugin tracker: <a href="http://sourceforge.net/tracker/index.php?func=detail&amp;aid=2030298&amp;group_id=107955&amp;atid=649116">#2030298</a></li>
<li>Firefox Bugzilla: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=451882">#451882</a></li>
</ul>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcuscobden.co.uk/2008/08/case-of-bad-cropping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unrestrict BBC Radio iPlayer</title>
		<link>http://blog.marcuscobden.co.uk/2008/04/urestrict-bbc-radio-iplayer/</link>
		<comments>http://blog.marcuscobden.co.uk/2008/04/urestrict-bbc-radio-iplayer/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 12:35:00 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[BBC]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Radio]]></category>

		<guid isPermaLink="false">http://newblog.marcuscobden.co.uk/?p=9</guid>
		<description><![CDATA[As long as I can remember, the BBC&#8217;s online music streaming service has restricted the control you have on playback streams, restricting the embedded realplayer controls to allow you pause, skip 5 minutes or skip 15 and change the volume. I can understand the legal obligations they may have, but from a piracy perspective stopping [...]]]></description>
			<content:encoded><![CDATA[<p>As long as I can remember, the <a href="http://www.bbc.co.uk/radio/aod/" title="BBC iPlayer">BBC&#8217;s online music</a> streaming service has restricted the control you have on playback streams, restricting the embedded realplayer controls to allow you pause, skip 5 minutes or skip 15 and change the volume. I can understand the legal obligations they may have, but from a piracy perspective stopping people skipping tracks is irrelevant, its only use is as a measure to stop people re-listening to the same track without having to go back to the start each time.</p>
<p>The controls on Mac OS X are less restrictive, but still restrict you to pause, fast forward or stop, however some simple javascript manipulation of the page can enable the regular <a href="http://service.real.com/help/library/guides/production8/media/embed/plugin.htm" title="RealPlayer Controls">RealPlayer controls</a>, complete with a seek-bar.</p>
<p>Bookmark either download the <a href="http://www.marcuscobden.co.uk/stuff/2008-03/R1.js" title="source code">source file</a> or view the <a href="http://www.marcuscobden.co.uk/stuff/2008-03/R1-bookmarklet.js" title="bookmarklet">bookmarklet source</a>. Unfortunately blogger won&#8217;t let me create an actual <a href="http://en.wikipedia.org/wiki/Bookmarklet" title="Wikipedia: Bookmarklet">bookmarklet</a> link, so you will manually have to save the bookmarklet into a bookmark in your browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcuscobden.co.uk/2008/04/urestrict-bbc-radio-iplayer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google Maps Placemark</title>
		<link>http://blog.marcuscobden.co.uk/2008/03/google-maps-placemark/</link>
		<comments>http://blog.marcuscobden.co.uk/2008/03/google-maps-placemark/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 10:00:00 +0000</pubDate>
		<dc:creator>Marcus</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://newblog.marcuscobden.co.uk/?p=8</guid>
		<description><![CDATA[This post has been sitting for quite a while now, pending me having time to sit down and write some text to go alongside the code. It would appear that I now have the time to write it up. Back when I was writing my Google Maps property finder I was using Google&#8217;s Geocoding API [...]]]></description>
			<content:encoded><![CDATA[<p>This post has been sitting for quite a while now, pending me having time to sit down and write some text to go alongside the code.<br />
It would appear that I now have the time to write it up.
</p>
<p>
<a href="http://blog.marcuscobden.co.uk/2007/12/spring-mvc-wizards-form-taglib.html" title="Spring MVC Wizards &amp; Form Taglib">Back when</a><br />
I was writing my Google Maps property finder I was using Google&#8217;s Geocoding API to get a set of co-ordinates based on a search string.
</p>
<p>
Specifically I was using the <code>getLocations</code> method of the <a href="http://code.google.com/apis/maps/documentation/reference.html#GClientGeocoder" title="Google Maps API - GClientGeocoder"><code>GClientGeocoder</code> object</a>.<br />
This would return a number of <code>Placemark</code> objects with a bunch of information about the potential matches.<br />
They don&#8217;t really document this object, but to be honest they don&#8217;t really need to, below is an example Placemark expressed in JSON-ish notation.
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>   <span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;p1&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;address&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;AddressDetails&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #3366CC;">&quot;Country&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #3366CC;">&quot;CountryNameCode&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;US&quot;</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">&quot;AdministrativeArea&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #3366CC;">&quot;AdministrativeAreaName&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;CA&quot;</span><span style="color: #339933;">,</span>
                <span style="color: #3366CC;">&quot;SubAdministrativeArea&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #3366CC;">&quot;SubAdministrativeAreaName&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Santa Clara&quot;</span><span style="color: #339933;">,</span>
                    <span style="color: #3366CC;">&quot;Locality&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #3366CC;">&quot;LocalityName&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Mountain View&quot;</span><span style="color: #339933;">,</span>
                        <span style="color: #3366CC;">&quot;Thoroughfare&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #3366CC;">&quot;ThoroughfareName&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1600 Amphitheatre Pkwy&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                            <span style="color: #3366CC;">&quot;PostalCode&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
                                <span style="color: #3366CC;">&quot;PostalCodeNumber&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;94043&quot;</span>
                            <span style="color: #009900;">&#125;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;Accuracy&quot;</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">8</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;Point&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #3366CC;">&quot;coordinates&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">122.081783</span><span style="color: #339933;">,</span><span style="color: #CC0000;">37.423111</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The only thing is, if you want to get a specific element, the tree will not necessarily be the same each time, so traversal is a pain.<br />
The <a href="http://marcuscobden.co.uk/stuff/2008-03/Placemark.js" title="">code below</a> will condense all this into the root level of an object, so you can pick out the key/value pairs you want, and easily tell if some aren&#8217;t there.</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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Placemark <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    initialize<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>placemark<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">traverse</span><span style="color: #009900;">&#40;</span>placemark<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    traverse<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> key<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> key <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>key <span style="color: #339933;">==</span> <span style="color: #3366CC;">'prototype'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #000066; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'object'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">else</span>
                <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">traverse</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>One thing to note is that this was written for to use the <a href="http://mootools.net/" title="mootools">Mootools</a> class system, though it shouldn&#8217;t be very hard to remove this dependancy.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.marcuscobden.co.uk/2008/03/google-maps-placemark/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
