<?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>[MeIsProgrammer] &#187; Javascript</title>
	<atom:link href="http://just-thor.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://just-thor.com</link>
	<description>all play and no work makes me a dull boy</description>
	<lastBuildDate>Sat, 03 Jul 2010 18:28:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>HTML5 Geolocation &#8211; Google Map with Modernizr</title>
		<link>http://just-thor.com/2010/07/04/html5-geolocation-google-map-with-modernizr/</link>
		<comments>http://just-thor.com/2010/07/04/html5-geolocation-google-map-with-modernizr/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 18:28:21 +0000</pubDate>
		<dc:creator>Thor</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://just-thor.com/?p=147</guid>
		<description><![CDATA[HTML5 defines a very handy function, which is geolocation. Basically, this function will try to locate user&#8217;s location. But at the moment, not every browser supports this function. We need [...]]]></description>
			<content:encoded><![CDATA[<p>HTML5 defines a very handy function, which is geolocation. Basically, this function will try to locate user&#8217;s location. But at the moment, not every browser supports this function. We need to implement some tedious conditions to check whether the browser supports Geolocation or not. Luckily, there is an open source javascript library, Modernizr. Using modernizr is simple, just import a script and use it. For example, if I want to check the browser whether Geolocation is supported or not, I just write the following code</p>
<p><pre><code>
if (Modernizr.geolocation){
//...Your logic here
}
</code></pre></p>
<p>Here, I wrote a simple html page that locate your location using Geolocation and show it on the Google map.</p>
<p><a href="http://just-thor.com/sample-works/geolocation.html">http://just-thor.com/sample-works/geolocation.html</a></p>
<p>Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://just-thor.com/2010/07/04/html5-geolocation-google-map-with-modernizr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Ajax Libraries Gotcha!</title>
		<link>http://just-thor.com/2010/02/23/google-ajax-libraries-gotch/</link>
		<comments>http://just-thor.com/2010/02/23/google-ajax-libraries-gotch/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 09:37:58 +0000</pubDate>
		<dc:creator>Thor</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://just-thor.com/?p=129</guid>
		<description><![CDATA[I was working on Google Map for the past few days, and was using jQuery to retrieve markers information from another URL using ajax. I came across the Google Ajax [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on Google Map for the past few days, and was using jQuery to retrieve markers information from another URL using ajax. I came across the Google Ajax Libraries (http://code.google.com/apis/ajaxlibs/) which helps to load Javascript from CDN.</p>
<p>Here&#8217;s part of the code<br />
<pre><pre class="brush: javascript">
//sample code taken from http://code.google.com/apis/ajaxlibs/
&lt;script src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;
&lt;script&gt;
&nbsp;&nbsp;// Load jQuery
&nbsp;&nbsp;google.load(&quot;jquery&quot;, &quot;1&quot;);

&nbsp;&nbsp;// on page load complete, fire off a jQuery json-p query
&nbsp;&nbsp;// against Google web search
&nbsp;&nbsp;google.setOnLoadCallback(function() {
&nbsp;&nbsp;&nbsp;&nbsp;$.getJSON(&quot;http://ajax.googleapis.com/ajax/services/search/web?q=google&amp;v=1.0&amp;callback=?&quot;,

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// on search completion, process the results
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function (data) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (data.responseData.results &amp;&amp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data.responseData.results.length &gt; 0) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var results = data.responseData.results;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var i=0; i &lt; results.length; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Display each result however you wish
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(results[i].titleNoFormatting);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;&nbsp;&nbsp;});
&lt;/script&gt;
</pre></pre><br />
By using this code, we actually load jQuery 1 from the CDN. However, there is a gotcha. If you follow the example I attached just now, it probably won&#8217;t work, well, at least not on my FF3.5 and IE8. In fact, you will have to do something like the following instead<br />
<pre><pre class="brush: javascript">
//sample code taken from http://code.google.com/apis/ajaxlibs/
&lt;script src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;
&lt;script&gt;
&nbsp;&nbsp;// Load jQuery
&nbsp;&nbsp;google.load(&quot;jquery&quot;, &quot;1&quot;);
&lt;/script&gt;
&lt;script&gt;
&nbsp;&nbsp;// on page load complete, fire off a jQuery json-p query
&nbsp;&nbsp;// against Google web search
&nbsp;&nbsp;google.setOnLoadCallback(function() {
&nbsp;&nbsp;&nbsp;&nbsp;$.getJSON(&quot;http://ajax.googleapis.com/ajax/services/search/web?q=google&amp;v=1.0&amp;callback=?&quot;,

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// on search completion, process the results
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function (data) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (data.responseData.results &amp;&amp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data.responseData.results.length &gt; 0) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var results = data.responseData.results;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var i=0; i &lt; results.length; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Display each result however you wish
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(results[i].titleNoFormatting);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;&nbsp;&nbsp;});
&lt;/script&gt;
</pre></pre><br />
You will have to close the script tag that load external script from CDN before you can use it. Else you will get javascript error, in IE8, it shows &#8216;Object expected&#8217;.I really hope you will be able to read my article before you pull all your hair off. <img src='http://just-thor.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Happy Coding</p>
]]></content:encoded>
			<wfw:commentRss>http://just-thor.com/2010/02/23/google-ajax-libraries-gotch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript manipulating multiple cookie values in one cookie</title>
		<link>http://just-thor.com/2009/08/28/javascript-manipulating-multiple-cookie-values-in-one-cookie/</link>
		<comments>http://just-thor.com/2009/08/28/javascript-manipulating-multiple-cookie-values-in-one-cookie/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 06:00:37 +0000</pubDate>
		<dc:creator>Thor</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://just-thor.com/?p=25</guid>
		<description><![CDATA[Sometimes,its convenient to store values in cookies and retrieve it later.But,when dealing with different browsers,you may have problems as different browser may support different numbers of cookies.For example, IE can [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes,its convenient to store values in cookies and retrieve it later.But,when dealing with different browsers,you may have problems as different browser may support different numbers of cookies.For example, IE can only <a href="http://support.microsoft.com/kb/306070" target="_blank">support up to 20 cookies for one single domain</a>. Therefore, we may need to compact our cookies into one instead of more.</p>
<p>How do we do that in Javascript?</p>
<p>Lets say originally we have like 3 cookies value storing for the same domain.<br />
<pre><pre class="brush: javascript">document.cookie = &quot;cookie1=val1;path=/;domain=just-thor.com&quot;
document.cookie = &quot;cookie2=val2;path=/;domain=just-thor.com&quot;
document.cookie = &quot;cookie3=val3;path=/;domain=just-thor.com&quot;</pre></pre><br />
By using javascript, first of all we store all 3 values into 1,and separate it by a separator.<br />
<pre class="brush: javascript">document.cookie = &quot;allcookies=cookie1=val1|cookie2=val2|cookie3=val3;path=/;domain=just-thor.com&quot;</pre><br />
Instead directly reading from cookies,first we translate our cookies value into array.<br />
<pre><pre class="brush: javascript">var cookieArray = translateCookiesToArray(new Array(), &quot;allcookies&quot;);
// you can append more items into the array by calling
// cookieArray = translateCookiesToArray(cookieArray, &quot;anotherCookiesCollection&quot;);

function translateCookiesToArray(result, key) {
 rawString = getCookieValue(key);
 if (rawString != null) {
 tokenizedString = rawString.split(&quot;|&quot;);

 for (i=0;i&amp;lt;tokenizedString.length;i++){
 innerArray = tokenizedString[i].split(&quot;=&quot;);
 result[innerArray[0]] = innerArray[1];
 }
 }

 return result;
}</pre></pre><br />
To get value for cookie1,simply type<br />
<pre class="brush: javascript">cookieArray[&quot;cookie1&quot;]</pre><br />
You can always refactor it by globalize the separator variable and the way you access cookieArray. Refer to the code below.</p>
<p>Here&#8217;s the complete code<br />
<pre><pre class="brush: javascript">var cookieArray = translateCookiesToArray(new Array(), &quot;allcookies&quot;);

function translateCookiesToArray(result, key) {
 rawString = getRawCookieValue(key);
 if (rawString != null) {
&nbsp;&nbsp;tokenizedString = rawString.split(&quot;|&quot;);

&nbsp;&nbsp;for (i=0;i&amp;lt;tokenizedString.length;i++){
&nbsp;&nbsp; innerArray = tokenizedString[i].split(&quot;=&quot;);
&nbsp;&nbsp; result[innerArray[0]] = innerArray[1];
&nbsp;&nbsp;}
 }

 return result;
}

function getRawCookieValue(name)
{
 var arg = name + &quot;=&quot;;
 var alen = arg.length;
 var clen = document.cookie.length;
 var i = 0;
 while (i &amp;lt; clen) {
&nbsp;&nbsp;var j = i + alen;
&nbsp;&nbsp;if (document.cookie.substring(i, j) == arg) {
&nbsp;&nbsp; return getCookieByOffset(j);
&nbsp;&nbsp;}
&nbsp;&nbsp;i = document.cookie.indexOf(&quot; &quot;, i) + 1;
&nbsp;&nbsp;if (i == 0) break;
 }
 return null;
}

function getCookieByOffset (offset)
{
 var endstr = document.cookie.indexOf (&quot;;&quot;, offset);
 if (endstr == -1) {
&nbsp;&nbsp;endstr = document.cookie.length;
 }
 return unescape(document.cookie.substring(offset, endstr));
}
function getCookieValue (name)
{
 value = cookieArray[name];
 if (typeof value == &quot;undefined&quot;) {
&nbsp;&nbsp;value = null;
 }
 return value;
}
//retrieving value
var val1 = getCookieValue(&quot;cookie1&quot;);</pre></pre><br />
Feel free to leave any comment.</p>
<p>Happy coding</p>
]]></content:encoded>
			<wfw:commentRss>http://just-thor.com/2009/08/28/javascript-manipulating-multiple-cookie-values-in-one-cookie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
