<?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>Silverlight &#124; WPF &#124; Microsoft.Net &#187; javascript</title>
	<atom:link href="http://joel.neubeck.net/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://joel.neubeck.net</link>
	<description>Simplifing structure without changing results</description>
	<lastBuildDate>Wed, 26 May 2010 18:43:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Communicating between two Silverlight objects on a single page</title>
		<link>http://joel.neubeck.net/2008/07/communicating-between-sl2-objects/</link>
		<comments>http://joel.neubeck.net/2008/07/communicating-between-sl2-objects/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 08:35:00 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[RegisterScriptableObject]]></category>
		<category><![CDATA[ScriptableMember]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2008/07/communicating-between-sl2-objects/</guid>
		<description><![CDATA[Not sure where I stumbled on it, but recently I watched video online where as the video was playing, a banner ad on the same page changed as the context of the video changed.&#160; I was intrigued by the potential this technique had in interactive marketing.&#160; As I was watching the video I was envisioning [...]]]></description>
			<content:encoded><![CDATA[<p>Not sure where I stumbled on it, but recently I watched video online where as the video was playing, a banner ad on the same page changed as the context of the video changed.&#160; I was intrigued by the potential this technique had in interactive marketing.&#160; As I was watching the video I was envisioning a character picking up a can of Pepsi and at that moment a corresponding banner ad somewhere else on the page switching to an ad for Pepsi.&#160; This could be a very powerful way to create interactive calls to action.</p>
<p>This got me thinking about how I might duplicate that technique in Silverlight 2. I figured that the first step was to figure out a simple way communicate between two distinct Silverlight object which exists on the same page.&#160; For this example I am going to have one SL object contain a series of <strong>Buttons</strong>, while the other SL object contains a single <strong>TextBlock.</strong></p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-1.png"><img title="slobjects_1" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="216" alt="slobjects_1" src="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-1-thumb.png" width="417" align="left" border="0" /></a> </p>
<p>  <br style="clear: both" />
<p>In the image above the red box I refer to as <strong>slObject1</strong>, where the blue box I refer to as <strong>slObject2</strong>.&#160; Both of these &lt;objects&gt; have unique id’s and point to their own respective Silverlight Project and both have been placed in a single html file.&#160; </p>
<p>In this example my <strong>slObject1</strong> will be executing a Javascript function, which in turn will be calling an internal function inside of <strong>slObject2</strong>.&#160; To do this I simply add a reference to the “System.Windows.Browser” namespace and call the Invoke method of the Window object.&#160; here is what my button click handler looks like.&#160; </p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-2.png"><img title="slobjects_2" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="120" alt="slobjects_2" src="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-2-thumb.png" width="445" align="left" border="0" /></a></p>
<p>  <br style="clear: both" />
<p>Once I have this defined I can now go back into my default.html file and define this Javascript function.&#160; The function finds the appropriate html object and calls the internal function in <strong>slObject2</strong>.&#160; </p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-3.png"><img title="slobjects_3" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="90" alt="slobjects_3" src="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-3-thumb.png" width="509" align="left" border="0" /></a> </p>
<p>  <br style="clear: both" />
<p>To create my “UpdateTextBlock function I need to add a few things to the <strong>slObject2</strong> project.&#160; First I have to go into my App.xaml.cs file and enter the following in my Application_Startup handler.&#160; <strong>“HtmlPage.RegisterScriptableObject(&quot;Page&quot;, page);”</strong>&#160; This registers a managed object for scriptable access by JavaScript code.&#160; Once registered I can create my methods as follows.</p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-4.png"><img title="slobjects_4" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="103" alt="slobjects_4" src="http://joel.neubeck.net/wp-content/uploads/2008/07/slobjects-4-thumb.png" width="331" align="left" border="0" /></a></p>
<p>  <br style="clear: both" />
<p>That is all there is to it.&#160; Now that I have the ability to communicate between the two SL object I can go after a more complicated implementation.</p>
<p>Code: <a onclick="javascript: pageTracker._trackPageview(&#39;/code/SLObjects.zip&#39;);" href="/wp-content/uploads/2008/07/SLObjects/SLObjects.zip">SLObjects.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2008/07/communicating-between-sl2-objects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Zombomatic 3000 on Miniclip.com</title>
		<link>http://joel.neubeck.net/2008/02/zombomatic/</link>
		<comments>http://joel.neubeck.net/2008/02/zombomatic/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 16:46:13 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Terralever]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2008/02/zombomatic/</guid>
		<description><![CDATA[Today Terralevers interactive team released our second game written for the Silverlight plugin.  Zombomatic  was writen for Miniclip and targets the  1.0 version of the silverlight plugin.  Zombomatic is a fun puzzle game that challenges you to swap electrical conductors to connect them into a path for the electricity to flow and bring your Zomomatic [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://joel.neubeck.net/wp-content/uploads/2008/02/bg_h1.jpg" alt="Miniclip" class="imageframe imgalignleft" height="47" width="218" />Today Terralevers interactive team released our second game written for the Silverlight plugin.  <a href="http://www.miniclip.com/games/zombomatic/en/" title="Zombomatic 3000">Zombomatic</a>  was writen for <a href="http://www.miniclip.com" title="Miniclip">Miniclip</a> and targets the  1.0 version of the silverlight plugin.  Zombomatic is a fun puzzle game that challenges you to swap electrical conductors to connect them into a path for the electricity to flow and bring your Zomomatic 300o back to life.  Give the game a try I gaurantee you will enjoy it.</p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2008/02/zombomatic/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>FBJS and Ajax to acheive Facebook profile link tracking</title>
		<link>http://joel.neubeck.net/2007/11/fbjs-ajax-facebook/</link>
		<comments>http://joel.neubeck.net/2007/11/fbjs-ajax-facebook/#comments</comments>
		<pubDate>Sat, 24 Nov 2007 05:16:26 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft.Net 2.0]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[fbjs]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2007/11/fbjs-ajax-facebook/</guid>
		<description><![CDATA[In interactive application development we love our ability to track and analyze the behavior of our users. Through tools like Google analytics and Urchin, web sites can monitor and analyze where their users are going, and more importantly how those users are getting there. As our company delves deeper into creating applications for the Facebook [...]]]></description>
			<content:encoded><![CDATA[<p>In interactive application development we love our ability to track and analyze the behavior of our users.   Through tools like Google analytics and Urchin, web sites can monitor and analyze where their users are going, and more importantly how those users are getting there.  </p>
<p>As our company delves deeper into creating applications for the Facebook platform, we have realized that analysis of users behavior is extremely important.  It is no secret that very few companies have mastered how to create a success Facebook application.    Those that have seen moderate success do one thing consistently, they all  leverage the social graph, but outside of that there is no clear blue print to success.   Using techniques such as user tracking we can begin to tune the way a Facebook applications evolves as a way to change its presentation based on the behaviors of its users.  </p>
<p>Integrating analytics into a  canvas view it is pretty simple, slap in some Google analytics and you can begin to monitor and tune user traffic.  The profile view is much more challenging.  In the profile view an applications FBML and images are cached and delivered from a Facebook server.  Using traditional Google analytics in the profile is not possible.   I hope someday Facebook will show us how many users view and interact with a users profile, but until then we need some way to track a users interaction with our application.  Back in October Facebook gave developers the ability to do some restricted Javascript and Ajax.  With these two features, we can begin to track what links a user click and how those clicks relate to a users interaction with the canvas view.  The following snip of FBJS will post a small JSON array to a external location, which in turn will asynchronously store that data for later analysis.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;&lt;!--</span>
    <span style="color: #003366; font-weight: bold;">var</span> uid <span style="color: #339933;">=</span> <span style="color: #3366CC;">'111111'</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">function</span> track<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> pid<span style="color: #339933;">,</span> method<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// ajax query</span>
        <span style="color: #003366; font-weight: bold;">var</span> ajax <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ajax<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        ajax.<span style="color: #660066;">responseType</span> <span style="color: #339933;">=</span> Ajax.<span style="color: #660066;">RAW</span><span style="color: #339933;">;</span>
        ajax.<span style="color: #660066;">requireLogin</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> queryParams <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;pid&quot;</span> <span style="color: #339933;">:</span> pid<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;method&quot;</span> <span style="color: #339933;">:</span> method<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;uid&quot;</span><span style="color: #339933;">:</span> uid<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;source&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;profile&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        ajax.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;http://url.com/tracker.ashx&quot;</span><span style="color: #339933;">,</span> queryParams<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">//--&gt;&lt;/script&gt;</span></pre></td></tr></table></div>

<p>To enable this tracking we must add the following callback attached to that elements onclick event.  In our example we are attaching tracking to a link which provides an external vendors affiliate link for a series of consumer products.  </p>
<p>One caveat, this approach only works correctly in Firefox if your &lt;a&gt; target is set to blank.  If you  need to use the same window, the only approach I have found  is to use the anchor that is passed into the track method combined with the ajax.ondone callback to set the document.setLocation to the anchors href.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">ajax.<span style="color: #660066;">ondone</span> <span style="color: #339933;">=</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>
<span style="color: #003366; font-weight: bold;">var</span> href <span style="color: #339933;">=</span> a.<span style="color: #660066;">getHref</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>href.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      document.<span style="color: #660066;">setLocation</span><span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">getHref</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://www.amazon.com&quot;</span> onclick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;track(this,12345,'buy');&quot;</span> <span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;buy&quot;</span> target<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;_blank&quot;</span><span style="color: #339933;">&gt;</span>BUY<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>On the back end we have a page that is waiting for this specific Ajax post, and will return a 1 for success and a 0 for failure.  It is extremely important to keep this tracking as efficient as possible.  Facebook Ajax has a <10 second maximum timeout on all requests.  In our design, the storing of the data is done using a asynchronous thread that queues up the incoming requests in hoped to avoid Facebook having to wait for us to store the data correctly.  </p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2007/11/fbjs-ajax-facebook/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
