<?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>Der Blog von Benny Neugebauer &#187; JavaScript</title>
	<atom:link href="http://www.bennyn.de/programmierung/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bennyn.de</link>
	<description>Alles über die Informatik &#38; Co.</description>
	<lastBuildDate>Fri, 18 May 2012 10:09:17 +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>Check for HTML5 features with JavaScript</title>
		<link>http://www.bennyn.de/programmierung/javascript/check-for-html5-features-with-javascript.html</link>
		<comments>http://www.bennyn.de/programmierung/javascript/check-for-html5-features-with-javascript.html#comments</comments>
		<pubDate>Thu, 17 May 2012 09:58:49 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[checking]]></category>
		<category><![CDATA[features]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[Modernizr]]></category>
		<category><![CDATA[WebSockets]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=3671</guid>
		<description><![CDATA[There is no magic behind checking a web-browsers support for a specific HTML5 feature. If you want to check if a browser supports the latest HTML5 WebSocket API then you just have to take care if there is an object called &#8220;WebSocket&#8221; available via the DOM: &#60;script&#62; if&#40;'WebSocket' in window&#41;&#123; alert&#40;'Hurray! Your browser supports HTML5 [...]]]></description>
			<content:encoded><![CDATA[<p>There is no magic behind checking a web-browsers support for a specific HTML5 feature. If you want to check if a browser supports the latest <a href="http://dev.w3.org/html5/websockets/">HTML5 WebSocket API</a> then you just have to take care if there is an object called &#8220;WebSocket&#8221; available via the DOM:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'WebSocket'</span> <span style="color: #000066; font-weight: bold;">in</span> window<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hurray! Your browser supports HTML5 WebSockets.'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Sorry, but you are out of date!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Nevertheless, there are still people who want to include a fancy library for such an inspection. You can do the same with <a href="http://modernizr.com/">Modernizr</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://www.modernizr.com/downloads/modernizr-latest.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>Modernizr.<span style="color: #660066;">websockets</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hurray! Your browser supports HTML5 WebSockets.'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Sorry, but you are out of date!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/javascript/check-for-html5-features-with-javascript.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vergleich von Tweening und Easing in KineticJS &amp; CreateJS</title>
		<link>http://www.bennyn.de/programmierung/javascript/vergleich-von-tweening-und-easing-in-kineticjs-createjs.html</link>
		<comments>http://www.bennyn.de/programmierung/javascript/vergleich-von-tweening-und-easing-in-kineticjs-createjs.html#comments</comments>
		<pubDate>Tue, 15 May 2012 13:05:40 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[EaselJS]]></category>
		<category><![CDATA[Easing]]></category>
		<category><![CDATA[KineticJS]]></category>
		<category><![CDATA[Tweening]]></category>
		<category><![CDATA[TweenJS]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=3675</guid>
		<description><![CDATA[Die folgenden zwei Beispiele zeigen, wie das Tweening und Easing mit KineticJS und mit den CreateJS-Bestandteilen EaselJS und TweenJS funktioniert. Das Beispiel zeigt ein HTML5-Logo in der linken oberen Canvas-Ecke und transformiert dieses Logo beim Anklicken in Richtung Mitte. CreateJS 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [...]]]></description>
			<content:encoded><![CDATA[<p>Die folgenden zwei Beispiele zeigen, wie das Tweening und Easing mit <a href="http://www.kineticjs.com/">KineticJS</a> und mit den <a href="http://createjs.org/">CreateJS</a>-Bestandteilen EaselJS und TweenJS funktioniert. Das Beispiel zeigt ein HTML5-Logo in der linken oberen Canvas-Ecke und transformiert dieses Logo beim Anklicken in Richtung Mitte.<br />
<span id="more-3675"></span></p>
<h2>CreateJS</h2>

<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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>meta charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span> <span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>CreateJS<span style="color: #339933;">:</span> EaselJS <span style="color: #339933;">&amp;</span> TweenJS<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>style type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/css&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">*</span> <span style="color: #009900;">&#123;</span> margin<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> padding<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> border<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #339933;">&lt;/</span>style<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>  
    <span style="color: #339933;">&lt;</span>canvas id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;container&quot;</span> width<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;800&quot;</span> height<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;600&quot;</span><span style="color: #339933;">&gt;&lt;/</span>canvas<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://code.createjs.com/easeljs-0.4.2.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://code.createjs.com/tweenjs-0.2.0.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
      <span style="color: #006600; font-style: italic;">// Set-up stage</span>
      <span style="color: #003366; font-weight: bold;">var</span> container <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;container&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> stage <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Stage<span style="color: #009900;">&#40;</span>container<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      stage.<span style="color: #660066;">mouseEventsEnabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// Set-up layer</span>
      <span style="color: #003366; font-weight: bold;">var</span> layer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Container<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// Set-up image</span>
      <span style="color: #003366; font-weight: bold;">var</span> image <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>
      image.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;./images/html5-logo.png&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// Append image to object</span>
      <span style="color: #003366; font-weight: bold;">var</span> object <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Bitmap<span style="color: #009900;">&#40;</span>image<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      object.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
      object.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// Recognize click on object</span>
      object.<span style="color: #660066;">onPress</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;">// Tweening &amp; Easing</span>
        Tween.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">to</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
          x<span style="color: #339933;">:</span> <span style="color: #CC0000;">222</span><span style="color: #339933;">,</span>
          y<span style="color: #339933;">:</span> <span style="color: #CC0000;">333</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span>Ease.<span style="color: #660066;">bounceInOut</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// Add object to layer</span>
      layer.<span style="color: #660066;">addChild</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// Add layer to stage</span>
      stage.<span style="color: #660066;">addChild</span><span style="color: #009900;">&#40;</span>layer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// Render</span>
      Ticker.<span style="color: #660066;">setFPS</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      Ticker.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span>stage<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h2>KineticJS</h2>

<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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>meta charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span> <span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>KineticJS<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>style type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/css&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">*</span> <span style="color: #009900;">&#123;</span> margin<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> padding<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> border<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #339933;">&lt;/</span>style<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;container&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://www.html5canvastutorials.com/libraries/kinetic-v3.9.4.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
      <span style="color: #006600; font-style: italic;">// Set-up stage</span>
      <span style="color: #003366; font-weight: bold;">var</span> stage <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Kinetic.<span style="color: #660066;">Stage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
        container<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;container&quot;</span><span style="color: #339933;">,</span>
        width<span style="color: #339933;">:</span> <span style="color: #CC0000;">800</span><span style="color: #339933;">,</span>
        height<span style="color: #339933;">:</span> <span style="color: #CC0000;">600</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// Set-up layer</span>
      <span style="color: #003366; font-weight: bold;">var</span> layer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Kinetic.<span style="color: #660066;">Layer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// Set-up image</span>
      <span style="color: #003366; font-weight: bold;">var</span> image <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>
      image.<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><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Append image to object</span>
        <span style="color: #003366; font-weight: bold;">var</span> object <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Kinetic.<span style="color: #660066;">Image</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
          x<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
          y<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
          image<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span>
          detectionType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;pixel&quot;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">// Recognize click on object</span>
        object.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click touchend&quot;</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: #006600; font-style: italic;">// Tweening &amp; Easing</span>
          object.<span style="color: #660066;">transitionTo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
            x<span style="color: #339933;">:</span> <span style="color: #CC0000;">222</span><span style="color: #339933;">,</span>
            y<span style="color: #339933;">:</span> <span style="color: #CC0000;">333</span><span style="color: #339933;">,</span>
            duration<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>
            easing<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;ease-in-out&quot;</span>
          <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">// Add object to layer</span>
        layer.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        layer.<span style="color: #660066;">draw</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        object.<span style="color: #660066;">saveData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
      image.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;./images/html5-logo.png&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">// Add layer to stage and render</span>
      stage.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>layer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>I have chosen KineticJS because the <code>"click touchend"</code> still works if you use it in connection with this code (to prevent iOS bumping and scrolling on mobile devices):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
  document.<span style="color: #660066;">ontouchstart</span> <span style="color: #339933;">=</span> document.<span style="color: #660066;">ontouchmove</span> <span style="color: #339933;">=</span> document.<span style="color: #660066;">ontouchend</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>
    event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The <code>object.onPress</code> function of EaselJS will not work with the code above.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/javascript/vergleich-von-tweening-und-easing-in-kineticjs-createjs.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>socket.io und node.js Einsteiger-Tutorial für Windows</title>
		<link>http://www.bennyn.de/programmierung/javascript/socket-io-und-node-js-einsteiger-tutorial-fur-windows.html</link>
		<comments>http://www.bennyn.de/programmierung/javascript/socket-io-und-node-js-einsteiger-tutorial-fur-windows.html#comments</comments>
		<pubDate>Thu, 10 May 2012 14:46:56 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[npm]]></category>
		<category><![CDATA[socket.io]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=3610</guid>
		<description><![CDATA[Die Benutzung von socket.io mit node.js ist einfach aber wird oft unverständlich erklärt. Deshalb schreibe ich kurz das Wichtigste in wenigen Schritten nieder: node.js v0.6.16 für Windows herunterladen und installieren C:\Windows\System32\cmd.exe aufrufen Ins Projektverzeichnis wechseln, z.B.: cd C:\my_project npm install socket.io eingeben, wodurch socket.io im Ordner &#8220;C:\my_project\node_modules\socket.io&#8221; installiert wird Die Datei C:\my_project\server.js mit diesem Inhalt [...]]]></description>
			<content:encoded><![CDATA[<p>Die Benutzung von socket.io mit node.js ist einfach aber wird oft unverständlich erklärt. Deshalb schreibe ich kurz das Wichtigste in wenigen Schritten nieder:</p>
<ol>
<li><a href="http://nodejs.org/dist/v0.6.16/node-v0.6.16.msi">node.js v0.6.16 für Windows</a> herunterladen und installieren</li>
<li><strong>C:\Windows\System32\cmd.exe</strong> aufrufen</li>
<li>Ins Projektverzeichnis wechseln, z.B.: <strong>cd C:\my_project</strong>
<li><strong>npm install socket.io</strong> eingeben, wodurch socket.io im Ordner &#8220;C:\my_project\node_modules\socket.io&#8221; installiert wird
</li>
<li>Die Datei <strong>C:\my_project\server.js</strong> mit diesem Inhalt anlegen:

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> io <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'socket.io'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">listen</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">72</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
io.<span style="color: #660066;">sockets</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'connection'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>socket<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  socket.<span style="color: #660066;">emit</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'news'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    hello<span style="color: #339933;">:</span> <span style="color: #3366CC;">'world'</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  socket.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'my other event'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>Die Datei <strong>C:\my_project\client.html</strong> mit diesem Inhalt anlegen:

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>meta charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span> <span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Test<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>style type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/css&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #339933;">*</span> <span style="color: #009900;">&#123;</span> margin<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> padding<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> border<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #339933;">&lt;/</span>style<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>  
    <span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://localhost:72/socket.io/socket.io.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
      <span style="color: #003366; font-weight: bold;">var</span> socket <span style="color: #339933;">=</span> io.<span style="color: #660066;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http://localhost:72'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      socket.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'news'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        socket.<span style="color: #660066;">emit</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'my other event'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> my<span style="color: #339933;">:</span> <span style="color: #3366CC;">'data'</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

</li>
<li>Folgende Befehle in der <strong>cmd</strong> ausführen:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> C:\my_project
node server.js</pre></div></div>

</li>
<li><strong>C:\my_project\client.html</strong> im Browser öffnen und das Ergebnis in der JavaScript-Konsole bewundern</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/javascript/socket-io-und-node-js-einsteiger-tutorial-fur-windows.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error: spawn ENOTSUP when installing socket.io with npm install</title>
		<link>http://www.bennyn.de/programmierung/javascript/error-spawn-enotsup-when-installing-socket-io-with-npm-install.html</link>
		<comments>http://www.bennyn.de/programmierung/javascript/error-spawn-enotsup-when-installing-socket-io-with-npm-install.html#comments</comments>
		<pubDate>Wed, 09 May 2012 14:13:59 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[exec.js]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[npm]]></category>
		<category><![CDATA[socket.io]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=3600</guid>
		<description><![CDATA[If you have installed node.js v0.6.16 for Windows and you want to install socket.io with the following command: npm install socket.io Then it could happen that you will get this error message on Windows 7 (64-Bit): &#62; node install.js &#160; npm ERR! Error: spawn ENOTSUP npm ERR! at errnoException &#40;child_process.js:483:11&#41; npm ERR! at ChildProcess.spawn &#40;child_process.js:446:11&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>If you have installed <a href="http://nodejs.org/dist/v0.6.16/node-v0.6.16.msi">node.js v0.6.16 for Windows</a> and you want to install <a href="http://socket.io/">socket.io</a> with the following command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">npm <span style="color: #c20cb9; font-weight: bold;">install</span> socket.io</pre></div></div>

<p>Then it could happen that you will get this error message on Windows 7 (64-Bit):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> node install.js
&nbsp;
npm ERR<span style="color: #000000; font-weight: bold;">!</span> Error: spawn ENOTSUP
npm ERR<span style="color: #000000; font-weight: bold;">!</span>     at errnoException <span style="color: #7a0874; font-weight: bold;">&#40;</span>child_process.js:<span style="color: #000000;">483</span>:<span style="color: #000000;">11</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
npm ERR<span style="color: #000000; font-weight: bold;">!</span>     at ChildProcess.spawn <span style="color: #7a0874; font-weight: bold;">&#40;</span>child_process.js:<span style="color: #000000;">446</span>:<span style="color: #000000;">11</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
npm ERR<span style="color: #000000; font-weight: bold;">!</span>     at Object.spawn <span style="color: #7a0874; font-weight: bold;">&#40;</span>child_process.js:<span style="color: #000000;">342</span>:<span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
npm ERR<span style="color: #000000; font-weight: bold;">!</span>     at spawn <span style="color: #7a0874; font-weight: bold;">&#40;</span>C:\Program Files <span style="color: #7a0874; font-weight: bold;">&#40;</span>x86<span style="color: #7a0874; font-weight: bold;">&#41;</span>\nodejs\node_mod
npm ERR<span style="color: #000000; font-weight: bold;">!</span>     at <span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>C:\Program Files <span style="color: #7a0874; font-weight: bold;">&#40;</span>x86<span style="color: #7a0874; font-weight: bold;">&#41;</span>\nodejs\node_modu
npm ERR<span style="color: #000000; font-weight: bold;">!</span>     at Array.0 <span style="color: #7a0874; font-weight: bold;">&#40;</span>C:\Program Files <span style="color: #7a0874; font-weight: bold;">&#40;</span>x86<span style="color: #7a0874; font-weight: bold;">&#41;</span>\nodejs\node_m
npm ERR<span style="color: #000000; font-weight: bold;">!</span>     at EventEmitter._tickCallback <span style="color: #7a0874; font-weight: bold;">&#40;</span>node.js:<span style="color: #000000;">192</span>:<span style="color: #000000;">40</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Fortunately, there is a solution! Open this file:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">C:\Program Files (x86)\nodejs\node_modules\npm\lib\utils\exec.js</pre></div></div>

<p>Replace these two lines (around line 109 &#038; 110):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isNaN<span style="color: #009900;">&#40;</span>uid<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> opts.<span style="color: #660066;">uid</span> <span style="color: #339933;">=</span> uid
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isNaN<span style="color: #009900;">&#40;</span>gid<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> opts.<span style="color: #660066;">gid</span> <span style="color: #339933;">=</span> gid</pre></div></div>

<p>That&#8217;s all. For more information see: <a href="https://github.com/isaacs/npm/issues/2405">Error on socket.io installing on Windows 7</a>.</p>
<p>With these ones:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>uid <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>isNaN<span style="color: #009900;">&#40;</span>uid<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> opts.<span style="color: #660066;">uid</span> <span style="color: #339933;">=</span> <span style="color: #339933;">+</span>uid
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>gid <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>isNaN<span style="color: #009900;">&#40;</span>gid<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> opts.<span style="color: #660066;">gid</span> <span style="color: #339933;">=</span> <span style="color: #339933;">+</span>gid</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/javascript/error-spawn-enotsup-when-installing-socket-io-with-npm-install.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook JavaScript SDK made simple</title>
		<link>http://www.bennyn.de/programmierung/javascript/facebook-javascript-sdk-made-simple.html</link>
		<comments>http://www.bennyn.de/programmierung/javascript/facebook-javascript-sdk-made-simple.html#comments</comments>
		<pubDate>Sat, 28 Apr 2012 09:59:21 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[facebook-jssdk]]></category>
		<category><![CDATA[fb-root]]></category>
		<category><![CDATA[FB.init]]></category>
		<category><![CDATA[FB.login]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[scope]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=3524</guid>
		<description><![CDATA[To work with the Facebook API you have to load the Facebook JavaScript SDK, initialize your Facebook application, authenticate the user and request an access token to then send the final Facebook API calls. In this long process chain much can go wrong. Especially because the calls happen all asnychron. You have to work with [...]]]></description>
			<content:encoded><![CDATA[<p>To work with the Facebook API you have to load the Facebook JavaScript SDK, initialize your Facebook application, authenticate the user and request an access token to then send the final Facebook API calls. In this long process chain much can go wrong. Especially because the calls happen all asnychron. You have to work with the correct callback mechanisms to reach the goal. To hide this mechanism and to make the Facebook API easier to use, I have created an abstraction, with which you can work much easier, as you can see here:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;./js/simple-facebook.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
  <span style="color: #006600; font-style: italic;">// Setup</span>
  <span style="color: #003366; font-weight: bold;">var</span> fb <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> SimpleFacebook<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fb.<span style="color: #660066;">setAppId</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'255100001240698'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fb.<span style="color: #660066;">setLocale</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'de_DE'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fb.<span style="color: #660066;">setPermissions</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'email,user_about_me,friends_about_me,publish_actions'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">// Usage</span>
  fb.<span style="color: #660066;">showUsersName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fb.<span style="color: #660066;">showUsersLink</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Doesn&#8217;t it look great? No more need to include a <code>fb-root</code> tag or many JavaScript snippets. All you need is the <code>simple-facebook.js</code> file, which can be expanded depending on your needs. Here is a basic version, which illustrates the concept:<br />
<span id="more-3524"></span></p>
<h2>simple-facebook.js</h2>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> SimpleFacebook<span style="color: #009900;">&#40;</span><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;">appId</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">userId</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">accessToken</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">locale</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'en_US'</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">permissions</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'page'</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Can be page, popup, iframe, or touch</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
SimpleFacebook.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">setAppId</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>appId<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;">appId</span> <span style="color: #339933;">=</span> appId<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
SimpleFacebook.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">setPermissions</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>permissions<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;">permissions</span> <span style="color: #339933;">=</span> permissions<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
SimpleFacebook.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">setLocale</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>locale<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;">locale</span> <span style="color: #339933;">=</span> locale<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
SimpleFacebook.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">setDisplay</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>display<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;">display</span> <span style="color: #339933;">=</span> display<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
SimpleFacebook.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">loadSdk</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Load Facebook JavaScript SDK asynchronously'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> that <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
&nbsp;
  window.<span style="color: #660066;">fbAsyncInit</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: #006600; font-style: italic;">// Prevents: FB.login() called before FB.init().</span>
    that.<span style="color: #660066;">initApp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// Prevents: An active access token must be used to query information about the current user.</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> callback <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span>
      that.<span style="color: #660066;">executeWithAccessToken</span><span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
      that.<span style="color: #660066;">executeWithAccessToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Prevents: FB is not defined.</span>
  <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> js<span style="color: #339933;">,</span> id <span style="color: #339933;">=</span> <span style="color: #3366CC;">'facebook-jssdk'</span><span style="color: #339933;">,</span> ref <span style="color: #339933;">=</span> d.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>d.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    js <span style="color: #339933;">=</span> d.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    js.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
    js.<span style="color: #660066;">async</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    js.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;//connect.facebook.net/&quot;</span><span style="color: #339933;">+</span>that.<span style="color: #660066;">locale</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;/all.js&quot;</span><span style="color: #339933;">;</span>
    ref.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">insertBefore</span><span style="color: #009900;">&#40;</span>js<span style="color: #339933;">,</span> ref<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
SimpleFacebook.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">initApp</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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> FB <span style="color: #339933;">!==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    FB.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      appId<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">appId</span><span style="color: #339933;">,</span> 
      <span style="color: #000066;">status</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> 
      cookie<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> 
      xfbml<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">loadSdk</span><span style="color: #009900;">&#40;</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: #339933;">;</span>
&nbsp;
SimpleFacebook.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">executeWithAccessToken</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Request access token...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> that <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</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> FB <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    that.<span style="color: #660066;">loadSdk</span><span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> that.<span style="color: #660066;">accessToken</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'string'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      FB.<span style="color: #660066;">login</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>response.<span style="color: #660066;">authResponse</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          that.<span style="color: #660066;">accessToken</span> <span style="color: #339933;">=</span> response.<span style="color: #660066;">authResponse</span>.<span style="color: #660066;">accessToken</span><span style="color: #339933;">;</span>
          console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Got access token: '</span><span style="color: #339933;">+</span>that.<span style="color: #660066;">accessToken</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><span style="color: #000066; font-weight: bold;">typeof</span> callback <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            callback<span style="color: #009900;">&#40;</span>that.<span style="color: #660066;">accessToken</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: #339933;">,</span><span style="color: #009900;">&#123;</span>
        scope<span style="color: #339933;">:</span>that.<span style="color: #660066;">permissions</span><span style="color: #339933;">,</span>
        display<span style="color: #339933;">:</span>that.<span style="color: #660066;">display</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> callback <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        callback<span style="color: #009900;">&#40;</span>that.<span style="color: #660066;">accessToken</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;">&#125;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/* Custom API functions */</span>
SimpleFacebook.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">showUsersName</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> that <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> callback <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>
    FB.<span style="color: #660066;">api</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/me?access_token='</span><span style="color: #339933;">+</span>that.<span style="color: #660066;">accessToken</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Show user<span style="color: #000099; font-weight: bold;">\'</span>s name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>response.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  that.<span style="color: #660066;">executeWithAccessToken</span><span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
SimpleFacebook.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">showUsersLink</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> that <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> callback <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>
    FB.<span style="color: #660066;">api</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/me?access_token='</span><span style="color: #339933;">+</span>that.<span style="color: #660066;">accessToken</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Show user<span style="color: #000099; font-weight: bold;">\'</span>s link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>response.<span style="color: #660066;">link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  that.<span style="color: #660066;">executeWithAccessToken</span><span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Process chain</h2>
<p>The first call to <code>fb.showUsersName();</code> does the following:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Request access token...
Load Facebook JavaScript SDK asynchronously
The &quot;fb-root&quot; div has not been created, auto-creating
Request access token...
Got access token: AAA[...]
Show user's name</pre></div></div>

<p>Another call to <code>fb.showUsersName();</code> leads to improved treatment of the process:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Request access token...
Show user's name</pre></div></div>

<p>Simplification and optimization in one. That&#8217;s how JavaScript tools should work!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/javascript/facebook-javascript-sdk-made-simple.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

