<?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>Luminescente &#187; 6.5</title>
	<atom:link href="http://luminescente.com/tag/6-5/feed/" rel="self" type="application/rss+xml" />
	<link>http://luminescente.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 24 Apr 2012 13:53:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>JS Lazyload for Windows Mobile 6.5 widgets</title>
		<link>http://luminescente.com/2010/03/js-lazyload-for-windows-mobile-6-5-widgets/</link>
		<comments>http://luminescente.com/2010/03/js-lazyload-for-windows-mobile-6-5-widgets/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 23:01:41 +0000</pubDate>
		<dc:creator>Pedro Cardoso</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[6.5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[lazyload]]></category>
		<category><![CDATA[widgets]]></category>
		<category><![CDATA[winmo]]></category>

		<guid isPermaLink="false">http://luminescente.com/?p=526</guid>
		<description><![CDATA[It took me the better part of  the afternoon, but I tamed it. I am creating a widget that has to run on different devices. I implemented a lazy loader to loadmost of the javascript files and it worked on all my targets, except Windows Mobile 6.5. I wanted to be notified when all the [...]]]></description>
			<content:encoded><![CDATA[<p>It took me the better part of  the afternoon, but I tamed it.</p>
<p>I am creating a widget that has to run on different devices. I implemented a lazy loader to loadmost of the javascript files and it worked on all my targets, except Windows Mobile 6.5. I wanted to be notified when all the files were loaded to proceed to my main app init code, but it was not working on the WM6.5 widget context. On the browser it worked, but when packaged as a widget it didn&#8217;t.</p>
<p>I thought I had hit a brick wall and had to resort to something (more) hackish, but in the end the perserverance  paid off, with a little luck.</p>
<p>First, for some reason, the attachEvent method does not exist on a script element when running as a widget, although it exists on Mobile IE, which was why it worked.</p>
<p>Poking at a newly created script object, I noticed a onreadystatechange property. Experimenting with it on a live widget I managed to make it call my callback function once, but when I tried to put it to use on my code it didn&#8217;t.</p>
<p>After much debugging, in which Bluetooth File Transfer.app didn&#8217;t help (on 10.6.2 it crashes 80% of the time when transferring a file to a WM device), I figured it out.</p>
<p>I was creating the new script object, setting all the properties and then adding it to the DOM. This seemed to be a sensible solution, but it didn&#8217;t work in this case. Then I tried to add the script element to the DOM, immediately  after its creation. Bingo! It worked. I only set the &#8220;src&#8221; property in the end, to prevent loading the script before I have the chance to set the onreadystatechange callback and everything else. I don&#8217;t know if this is really needed, but after wasting lots of time on this today I&#8217;ll wait until tomorrow to find out. <img src='http://luminescente.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I don&#8217;t know if this code is still working on the other platforms, but I don&#8217;t see any reason not to. Then again, I better check. <img src='http://luminescente.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here is the relevant code. I&#8217;m posting it here in case some poor soul stumps on the same problem. &#8220;cb&#8221; is the callback function.</p>
<pre>var script = document.createElement("script");
document.getElementsByTagName("head")[0].appendChild(script);
if (script.addEventListener) {
    script.addEventListener("load", cb, false);
} else if (script.attachEvent) {
    script.attachEvent("onreadystatechange", function() {
        if (script.readyState == "loaded") {
            cb();
        }
    });
}  else {
    script.onreadystatechange = function () {
        cb();
    };
}
script.type = "text/javascript";
script.src = name;
</pre>
<p>Mental note, I need some wordpress plugin for posting code.</p>
]]></content:encoded>
			<wfw:commentRss>http://luminescente.com/2010/03/js-lazyload-for-windows-mobile-6-5-widgets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

