<?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>Wed, 08 Feb 2012 16:31:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>JavaScript AMD Example with RequireJS</title>
		<link>http://www.bennyn.de/programmierung/javascript/javascript-amd-example-with-requirejs.html</link>
		<comments>http://www.bennyn.de/programmierung/javascript/javascript-amd-example-with-requirejs.html#comments</comments>
		<pubDate>Wed, 25 Jan 2012 14:09:18 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[amd]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[loading]]></category>
		<category><![CDATA[Module]]></category>
		<category><![CDATA[requirejs]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=3131</guid>
		<description><![CDATA[One line of code is worth ten thousand words. ./index.html &#60;!DOCTYPE html&#62; &#60;html&#62; &#60;head&#62; &#60;meta charset=&#34;utf-8&#34; /&#62; &#60;title&#62;Asynchronous Module Definition Example with RequireJS&#60;/title&#62; &#60;/head&#62; &#60;body&#62; &#60;!-- Let's use RequireJS as module loader (there are also others!) --&#62; &#60;script src=&#34;./js/require-1.0.4.js&#34;&#62;&#60;/script&#62; &#60;script&#62; require(['js/my_amd_module'], // Requires ./js/my_amd_module.js function(myModule) { myModule.sayHello(); myModule.doSomething(); }); &#60;/script&#62; &#60;/html&#62; ./js/my_amd_module.js define&#40;'js/my_amd_module', // module [...]]]></description>
			<content:encoded><![CDATA[<p>One line of code is worth ten thousand words.</p>
<h2>./index.html</h2>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;title&gt;Asynchronous Module Definition Example with RequireJS&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;  
    &lt;!-- Let's use RequireJS as module loader (there are also others!) --&gt;
    &lt;script src=&quot;./js/require-1.0.4.js&quot;&gt;&lt;/script&gt;
    &lt;script&gt;
      require(['js/my_amd_module'], // Requires ./js/my_amd_module.js
      function(myModule)
      {
        myModule.sayHello();
        myModule.doSomething();        
      });
    &lt;/script&gt;
&lt;/html&gt;</pre></div></div>

<h2>./js/my_amd_module.js</h2>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">define<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'js/my_amd_module'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// module name, has to match filename (without .js)</span>
  <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'js/jquery-1.7.min'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// requirements of this module (./js/jquery-1.7.min.js)</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: #006600; font-style: italic;">// $ for jQuery</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
      sayHello<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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hello World!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      doSomething<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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'I did.'</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>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/javascript/javascript-amd-example-with-requirejs.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to parse JSON with jQuery</title>
		<link>http://www.bennyn.de/programmierung/javascript/how-to-parse-json-with-jquery.html</link>
		<comments>http://www.bennyn.de/programmierung/javascript/how-to-parse-json-with-jquery.html#comments</comments>
		<pubDate>Tue, 27 Dec 2011 19:37:25 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[boolean]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=3075</guid>
		<description><![CDATA[With jQuery you could easily parse a JSON (which is an object in JavaScript Object Notation). The method parseJSON of jQuery translates the JSON even into the corresponding JavaScript data types. As an example I have chosen the following JSON: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [...]]]></description>
			<content:encoded><![CDATA[<p>With jQuery you could easily parse a JSON (which is an object in JavaScript Object Notation). The method <code>parseJSON</code> of jQuery translates the JSON even into the corresponding JavaScript data types. As an example I have chosen the following JSON:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="json" style="font-family:monospace;">{
        &quot;firstName&quot;: &quot;Joe&quot;,
        &quot;lastName&quot; : &quot;Black&quot;,
        &quot;age&quot;      : 28,
        &quot;address&quot;  :
        {
          &quot;streetAddress&quot;: &quot;1st Street&quot;,
          &quot;city&quot;         : &quot;New York&quot;,
          &quot;state&quot;        : &quot;NY&quot;,
          &quot;postalCode&quot;   : &quot;10021&quot;
        },
        &quot;phoneNumber&quot;:
        [
          {
            &quot;type&quot;  : &quot;home&quot;,
            &quot;number&quot;: &quot;212555-1234&quot;
          },
          {
            &quot;type&quot;  : &quot;fax&quot;,
            &quot;number&quot;: &quot;646555-4567&quot;
          }
        ],
        &quot;married&quot; : true,
        &quot;developer&quot; : true	
}</pre></td></tr></table></div>

<p>This JSON contains nested objects like <code>address</code>, an array like <code>phoneNumber</code> and key-value pairs of different types like <code>firstName</code> (string), <code>age</code> (number) and <code>married</code> (boolean).</p>
<p><strong>Here it is shown how it is parsed:</strong><br />
<span id="more-3075"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script src=&quot;./js/jquery-1.7.min.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #003366; font-weight: bold;">var</span> json <span style="color: #339933;">=</span> <span style="color: #3366CC;">'{&quot;firstName&quot;:&quot;Joe&quot;,&quot;lastName&quot;:&quot;Black&quot;,&quot;age&quot;:28,&quot;address&quot;:{&quot;streetAddress&quot;:&quot;1st Street&quot;,&quot;city&quot;:&quot;New York&quot;,&quot;state&quot;:&quot;NY&quot;,&quot;postalCode&quot;:&quot;10021&quot;},&quot;phoneNumber&quot;:[{&quot;type&quot;:&quot;home&quot;,&quot;number&quot;:&quot;212555-1234&quot;},{&quot;type&quot;:&quot;fax&quot;,&quot;number&quot;:&quot;646555-4567&quot;}],&quot;married&quot;:true,&quot;developer&quot;:false}'</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> object <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">parseJSON</span><span style="color: #009900;">&#40;</span>json<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> firstName <span style="color: #339933;">=</span> object.<span style="color: #660066;">firstName</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Joe</span>
  <span style="color: #003366; font-weight: bold;">var</span> age <span style="color: #339933;">=</span> object.<span style="color: #660066;">age</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 28</span>
  <span style="color: #003366; font-weight: bold;">var</span> streetAddress  <span style="color: #339933;">=</span> object.<span style="color: #660066;">address</span>.<span style="color: #660066;">streetAddress</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> numberOfPhoneNumbers <span style="color: #339933;">=</span> object.<span style="color: #660066;">phoneNumber</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 2</span>
  <span style="color: #003366; font-weight: bold;">var</span> homeNumber <span style="color: #339933;">=</span> object.<span style="color: #660066;">phoneNumber</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">number</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 212555-1234</span>
  <span style="color: #003366; font-weight: bold;">var</span> faxNumber <span style="color: #339933;">=</span> object.<span style="color: #660066;">phoneNumber</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">number</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 646555-4567</span>
  <span style="color: #003366; font-weight: bold;">var</span> married <span style="color: #339933;">=</span> object.<span style="color: #660066;">married</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// true</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>married <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'He is a lucky one!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// ...and he is ;)</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Checking data types</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>firstName<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// string</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>age<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// number</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>married<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// boolean</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/javascript/how-to-parse-json-with-jquery.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook Authentication with JavaScript SDK</title>
		<link>http://www.bennyn.de/programmierung/javascript/facebook-authentication-with-javascript-sdk.html</link>
		<comments>http://www.bennyn.de/programmierung/javascript/facebook-authentication-with-javascript-sdk.html#comments</comments>
		<pubDate>Fri, 23 Dec 2011 17:46:04 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[connect]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[fbml]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=3066</guid>
		<description><![CDATA[Over the years many ways have been created in order to authenticate through Facebook. One of the easiest ways is to use the Facebook Markup Language (FBML). However, from January 2012 is FBML is no longer supported. Who wants to use Facebook Connect to login and logout then, should use the JavaScript SDK provided by [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years many ways have been created in order to authenticate through Facebook. One of the easiest ways is to use the Facebook Markup Language (FBML). However, from January 2012 is FBML is no longer supported. Who wants to use <strong>Facebook Connect</strong> to login and logout then, should use the <strong>JavaScript SDK</strong> provided by Facebook. This supports authentication via <strong>OAuth 2.0</strong>, which is the recommended way to handle authentication. I programmed an example, that shows how to <strong>login</strong> and <strong>logout</strong> with the JavaScript SDK. This example is based on the current JavaScript SDK methods and does not use deprecated methods (because in July 2011 there were some changes).<br />
<span id="more-3066"></span></p>
<h2>Facebook Authentication with JavaScript SDK (and standard Facebook Log In Button):</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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;!DOCTYPE html&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; 
      xmlns:fb=&quot;http://ogp.me/ns/fb#&quot;&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;title&gt;Facebook Authentication with JavaScript SDK&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt; 
    &lt;!-- Facebook JS SDK --&gt;
    &lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt;
    &lt;!-- 
    Facebook Auth Button
    See https://developers.facebook.com/docs/reference/plugins/login/
    --&gt;
    &lt;div id=&quot;fb-auth&quot; 
         class=&quot;fb-login-button&quot;
         scope=&quot;email,user_about_me,friends_about_me,publish_stream,publish_actions&quot;
         &gt;
    &lt;/div&gt;
    <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #006600; font-style: italic;">/*
       * Facebook Authentication with JavaScript SDK
       * 
       * Based on new methods announced on:
       * https://developers.facebook.com/blog/post/525/
       */</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">// Your Facebook application settings</span>
      <span style="color: #006600; font-style: italic;">// See: https://developers.facebook.com/apps/</span>
      <span style="color: #003366; font-weight: bold;">var</span> facebookAppId <span style="color: #339933;">=</span> <span style="color: #3366CC;">'156477777792853'</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> facebookAppDomain <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://www.bennyn.de/'</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> facebookAuthButtonId <span style="color: #339933;">=</span> <span style="color: #3366CC;">'fb-auth'</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">function</span> loginCallback<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>
          <span style="color: #003366; font-weight: bold;">var</span> uid <span style="color: #339933;">=</span> response.<span style="color: #660066;">authResponse</span>.<span style="color: #660066;">userID</span><span style="color: #339933;">;</span>
          <span style="color: #003366; font-weight: bold;">var</span> accessToken <span style="color: #339933;">=</span> response.<span style="color: #660066;">authResponse</span>.<span style="color: #660066;">accessToken</span><span style="color: #339933;">;</span>
          FB.<span style="color: #660066;">api</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/me'</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>
            <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Nice to see you, '</span> <span style="color: #339933;">+</span> response.<span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'!'</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>
&nbsp;
          createLogoutButton<span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">function</span> logoutCallback<span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Refresh page if the user logs out</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>response.<span style="color: #660066;">authResponse</span><span style="color: #009900;">&#41;</span> 
          window.<span style="color: #660066;">location</span>.<span style="color: #660066;">reload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">function</span> createLogoutButton<span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Class names come from standard Facebook JS SDK CSS styles</span>
        <span style="color: #006600; font-style: italic;">// See: https://developers.facebook.com/docs/reference/plugins/login/</span>
        <span style="color: #003366; font-weight: bold;">var</span> facebookLoginButton <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>facebookAuthButtonId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> elements <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fb_button_text'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> facebookLoginButtonText <span style="color: #339933;">=</span> elements<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
        facebookLoginButtonText.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'Logout'</span><span style="color: #339933;">;</span>          
        facebookLoginButton.<span style="color: #660066;">onclick</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>
          FB.<span style="color: #660066;">logout</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> 
            console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'User logged out.'</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;
        <span style="color: #006600; font-style: italic;">// Remove login behaviour of DOM element 'fb_button'</span>
        <span style="color: #003366; font-weight: bold;">var</span> facebookLoginInnerButton <span style="color: #339933;">=</span> facebookLoginButton.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        facebookLoginInnerButton.<span style="color: #660066;">onclick</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: #009900;">&#125;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">function</span> showInitialButtonState<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> 
          createLogoutButton<span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">// Use Facebook JavaScript SDK</span>
      <span style="color: #006600; font-style: italic;">// See: https://developers.facebook.com/docs/reference/javascript/</span>
      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>
        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> facebookAppId<span style="color: #339933;">,</span>
          channelUrl<span style="color: #339933;">:</span> <span style="color: #3366CC;">'//'</span><span style="color: #339933;">+</span>facebookAppDomain<span style="color: #339933;">+</span><span style="color: #3366CC;">'/channel.html'</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: #339933;">,</span>
          oauth<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>
&nbsp;
        FB.<span style="color: #660066;">getLoginStatus</span><span style="color: #009900;">&#40;</span>showInitialButtonState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        FB.<span style="color: #660066;">Event</span>.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'auth.login'</span><span style="color: #339933;">,</span> loginCallback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        FB.<span style="color: #660066;">Event</span>.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'auth.logout'</span><span style="color: #339933;">,</span> logoutCallback<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;">// Load Facebook JavaScript SDK asynchronously</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>
        <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/en_US/all.js&quot;</span><span style="color: #339933;">;</span>
        d.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'head'</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: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>js<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: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
  &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<h2>Facebook Authentication with JavaScript SDK (and custom Facebook Log In Button)</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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;!DOCTYPE html&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; 
      xmlns:fb=&quot;http://ogp.me/ns/fb#&quot;&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;title&gt;Facebook Authentication with JavaScript SDK&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt; 
    &lt;!-- Facebook JS SDK --&gt;
    &lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt;
    &lt;!-- Custom Facebook Auth Button --&gt;
    &lt;button id=&quot;fb-auth&quot;&gt;&lt;/button&gt;
    <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
      <span style="color: #006600; font-style: italic;">/*
       * Facebook Authentication with JavaScript SDK
       * 
       * Based on new methods announced on:
       * https://developers.facebook.com/blog/post/525/
       */</span>
&nbsp;
      <span style="color: #006600; font-style: italic;">// Your Facebook application settings</span>
      <span style="color: #006600; font-style: italic;">// See: https://developers.facebook.com/apps/</span>
      <span style="color: #003366; font-weight: bold;">var</span> facebookAppId <span style="color: #339933;">=</span> <span style="color: #3366CC;">'156477777792853'</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> facebookAppDomain <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://www.bennyn.de/'</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> facebookAuthButtonId <span style="color: #339933;">=</span> <span style="color: #3366CC;">'fb-auth'</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #003366; font-weight: bold;">function</span> updateButton<span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> button <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>facebookAuthButtonId<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>response.<span style="color: #660066;">authResponse</span><span style="color: #009900;">&#41;</span> 
        <span style="color: #009900;">&#123;</span>
          <span style="color: #006600; font-style: italic;">// User is already logged in</span>
          button.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'Logout'</span><span style="color: #339933;">;</span>
          button.<span style="color: #660066;">onclick</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>
            FB.<span style="color: #660066;">logout</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> 
              console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'User logged out.'</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>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">else</span>
        <span style="color: #009900;">&#123;</span>
          <span style="color: #006600; font-style: italic;">// User is not logged in</span>
          button.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'Login'</span><span style="color: #339933;">;</span>
          button.<span style="color: #660066;">onclick</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>
            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>
                <span style="color: #003366; font-weight: bold;">var</span> uid <span style="color: #339933;">=</span> response.<span style="color: #660066;">authResponse</span>.<span style="color: #660066;">userID</span><span style="color: #339933;">;</span>
                <span style="color: #003366; font-weight: bold;">var</span> accessToken <span style="color: #339933;">=</span> response.<span style="color: #660066;">authResponse</span>.<span style="color: #660066;">accessToken</span><span style="color: #339933;">;</span>
                FB.<span style="color: #660066;">api</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/me'</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>
                  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Nice to see you, '</span> <span style="color: #339933;">+</span> response.<span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'!'</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>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
            <span style="color: #009900;">&#123;</span>
              <span style="color: #006600; font-style: italic;">// Get access to additional user information</span>
              <span style="color: #006600; font-style: italic;">// See: https://developers.facebook.com/docs/reference/api/permissions/</span>
              scope<span style="color: #339933;">:</span> <span style="color: #3366CC;">'email,user_about_me,friends_about_me,publish_stream,publish_actions'</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: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #006600; font-style: italic;">// Use Facebook JavaScript SDK</span>
      <span style="color: #006600; font-style: italic;">// See: https://developers.facebook.com/docs/reference/javascript/</span>
      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>
        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> facebookAppId<span style="color: #339933;">,</span>
          channelUrl<span style="color: #339933;">:</span> <span style="color: #3366CC;">'//'</span><span style="color: #339933;">+</span>facebookAppDomain<span style="color: #339933;">+</span><span style="color: #3366CC;">'/channel.html'</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: #339933;">,</span>
          oauth<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>
&nbsp;
        <span style="color: #006600; font-style: italic;">// Use updateButton method as event handler</span>
        FB.<span style="color: #660066;">getLoginStatus</span><span style="color: #009900;">&#40;</span>updateButton<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        FB.<span style="color: #660066;">Event</span>.<span style="color: #660066;">subscribe</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'auth.authResponseChange'</span><span style="color: #339933;">,</span> updateButton<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;">// Load Facebook JavaScript SDK asynchronously</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>
        <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/en_US/all.js&quot;</span><span style="color: #339933;">;</span>
        d.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'head'</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: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>js<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: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
  &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/javascript/facebook-authentication-with-javascript-sdk.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to check for NaN with JavaScript?</title>
		<link>http://www.bennyn.de/programmierung/javascript/how-to-check-for-nan-with-javascript.html</link>
		<comments>http://www.bennyn.de/programmierung/javascript/how-to-check-for-nan-with-javascript.html#comments</comments>
		<pubDate>Thu, 15 Dec 2011 15:46:35 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[hexadecimal]]></category>
		<category><![CDATA[isFinite]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[NaN]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[parseInt]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=3046</guid>
		<description><![CDATA[If you explicitly convert a JavaScript variable to a number (e.g. by using the parseInt function), then you have to check if the value of the converted number is really a number. In case that it is not, it will present you NaN (Not a Number). You can check for NaN with the isFinite function. [...]]]></description>
			<content:encoded><![CDATA[<p>If you explicitly convert a JavaScript variable to a number (e.g. by using the <code>parseInt</code> function), then you have to check if the value of the converted number is really a number. In case that it is not, it will present you <code>NaN</code> (Not a Number). You can check for <code>NaN</code> with the <code>isFinite</code> function.</p>
<p><strong>Example:</strong></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;"><span style="color: #006600; font-style: italic;">// Check for hexadecimal value</span>
<span style="color: #003366; font-weight: bold;">var</span> convertedNumber <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'G'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">16</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>isFinite<span style="color: #009900;">&#40;</span>convertedNumber<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'The value of the converted number is NaN!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">else</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'The number is: '</span><span style="color: #339933;">+</span>convertedNumber<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/javascript/how-to-check-for-nan-with-javascript.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Image preloader with jQuery</title>
		<link>http://www.bennyn.de/programmierung/javascript/image-preloader-with-jquery.html</link>
		<comments>http://www.bennyn.de/programmierung/javascript/image-preloader-with-jquery.html#comments</comments>
		<pubDate>Wed, 16 Nov 2011 13:34:42 +0000</pubDate>
		<dc:creator>bennyn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Preloader]]></category>
		<category><![CDATA[Preloading]]></category>
		<category><![CDATA[setDragImage]]></category>

		<guid isPermaLink="false">http://www.bennyn.de/?p=2945</guid>
		<description><![CDATA[Today I saw a tiny JavaScript code on Stack Overflow which can be used as a jQuery plugin for preloading images. It is very handy and can be used easily: jQuery.fn.preload = function&#40;&#41; &#123; this.each&#40;function&#40;&#41; &#123; $&#40;'&#60;img/&#62;'&#41;&#91;0&#93;.src = this; &#125;&#41;; &#125; &#160; jQuery&#40;document&#41;.ready&#40;function&#40;$&#41; &#123; $&#40;&#91;'./images/image1.png', './images/image2.png'&#93;&#41;.preload&#40;&#41;; &#125;&#41;; I use this function to preload drag images [...]]]></description>
			<content:encoded><![CDATA[<p>Today I saw a tiny JavaScript code on <a href="http://stackoverflow.com/">Stack Overflow</a> which can be used as a jQuery plugin for preloading images. It is very handy and can be used easily:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">preload</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;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;img/&gt;'</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: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</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;
jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>    
  $<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'./images/image1.png'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'./images/image2.png'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">preload</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;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I use this function to preload drag images which are used by <code>event.dataTransfer.setDragImage</code> but you can still preload everything else. It makes also much sense for hover images.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bennyn.de/programmierung/javascript/image-preloader-with-jquery.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

