<?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>ajaxBlender.com&#8212; A Whole Lot of AJAX! Directory for Web 2.0 AJAX scripts, demos and tutorials. Custom AJAX Coding Service for Your Web 2.0 Website.</title>
	<atom:link href="http://www.ajaxblender.com/tutorials/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ajaxblender.com</link>
	<description>A Whole Lot of AJAX!</description>
	<lastBuildDate>Sun, 07 Mar 2010 20:30:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Add Hints &amp; Auto Focus Form Fields using jQuery</title>
		<link>http://www.ajaxblender.com/howto-add-hints-form-auto-focus-using-javascript.html</link>
		<comments>http://www.ajaxblender.com/howto-add-hints-form-auto-focus-using-javascript.html#comments</comments>
		<pubDate>Fri, 19 Feb 2010 15:52:16 +0000</pubDate>
		<dc:creator>ajaxBlender.com</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[beginner's guide]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.ajaxblender.com/?p=1128</guid>
		<description><![CDATA[This tutorial teaches you how to easily add hints to your forms and auto focus fields.
We are continuing a series of quick articles for web developers which explain how to automate things during website programming. Today we will talk about forms and two usability items the every current website should have:

Auto Focus Fields. The first [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial teaches you how to easily add hints to your forms and auto focus fields.<span id="more-1128"></span></p>
<p>We are continuing a series of quick articles for web developers which explain how to automate things during website programming. Today we will talk about forms and two usability items the every current website should have:</p>
<ul>
<li><strong>Auto Focus Fields.</strong> The first field in the form should be focused by default, so that the user can start entering his password or name right after page loaded and would not have to click the field to start typing. This is a small and obvious usability items, but still a very important one.</li>
<li><strong>Hints.</strong> Forms should have quick tips for fields which requires entering data in a specific format (for example email address, phone number, date / time, etc.)</li>
</ul>
<p>So, let&#8217;s say our website have this contact form:</p>
<p><img title="screen-1" src="../wp-content/uploads/2010/02/screen-1.gif" alt="screen-1" width="370" height="218" /></p>
<h3>Auto Focus</h3>
<p>Full Name &#8211; this field will be automatically focused when the page loads, here is how it will be coded in the markup:</p>
<pre class="html">
<span class="htmlFormTag">&lt;input type=<span class="htmlAttributeValue">&quot;text&quot;</span> name=<span class="htmlAttributeValue">&quot;fullname&quot;</span> id=<span class="htmlAttributeValue">&quot;fullname&quot;</span> class=<span class="htmlAttributeValue">&quot;auto-focus&quot;</span> /&gt;</span>
</pre>
<p>Notice the field has &#8216;auto-focus&#8217; class. This is so that any field in the form with this CSS class will be automatically focused on page load.</p>
<p>The auto focus can be implemented in JavaScript:</p>
<pre class="php">
$<span class="phpOperator">(</span><span class="phpString">'<span class="phpOperator">.</span>auto-focus<span class="phpOperator">:</span>first'</span><span class="phpOperator">)</span>.focus<span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpText">;</span>
</pre>
<p>2.) Email Address (the same for phone number and message fields) &#8211; If the field does not contain any value it will show a quick tip on the required data format. When the user clicks the field, the tip will disappear and let the user enter data. Here is how it will look in the markup:</p>
<pre class="html">
<span class="htmlFormTag">&lt;input type=<span class="htmlAttributeValue">&quot;text&quot;</span> name=<span class="htmlAttributeValue">&quot;email&quot;</span> id=<span class="htmlAttributeValue">&quot;email&quot;</span> title=<span class="htmlAttributeValue">&quot;i.e. me@example.com&quot;</span> class=<span class="htmlAttributeValue">&quot;auto-hint&quot;</span> /&gt;</span>
</pre>
<p>As you see, our hint will be stored in &#8216;title&#8217; attribute of the field. This will let user see it when the field already contains a value in it.</p>
<p>By default, the color of text in input field will be black, we need to differentiate the color of the hint and common input value. Let&#8217;s set this color in CSS:</p>
<pre class="html">
<span class="htmlStyleTag">&lt;style type=<span class="cssString">&quot;text/css&quot;</span>&gt;</span>
    <span class="cssSelector">.auto-hint {</span> <span class="cssProperty">color</span><span class="cssRest">:</span><span class="cssValue"> #AAAAAA</span><span class="cssRest">;</span> <span class="cssSelector">}</span>
<span class="htmlStyleTag">&lt;/style&gt;</span>
</pre>
<p>Now we move to JavaScript implementation. At first we should display the hint in fields which have empty values:</p>
<pre class="php">
$<span class="phpOperator">(</span><span class="phpString">'INPUT<span class="phpOperator">.</span>auto-hint, TEXTAREA<span class="phpOperator">.</span>auto-hint'</span><span class="phpOperator">)</span>.focus<span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
   <span class="phpKeyword"> if<span class="phpOperator">(</span></span>$<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.val<span class="phpOperator">(</span><span class="phpOperator">)</span> <span class="phpOperator"><span class="phpOperator">=</span>=</span> $<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.attr<span class="phpOperator">(</span><span class="phpString">'title'</span><span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
        $<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.val<span class="phpOperator">(</span><span class="phpString">''</span><span class="phpOperator">)</span><span class="phpText">;</span>
        $<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.removeClass<span class="phpOperator">(</span><span class="phpString">'auto-hint'</span><span class="phpOperator">)</span><span class="phpText">;</span>
    <span class="phpOperator">}</span>
<span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
</pre>
<p>And handle focus / blur events:</p>
<pre class="php">
$<span class="phpOperator">(</span><span class="phpString">'INPUT<span class="phpOperator">.</span>auto-hint, TEXTAREA<span class="phpOperator">.</span>auto-hint'</span><span class="phpOperator">)</span>.blur<span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
   <span class="phpKeyword"> if<span class="phpOperator">(</span></span>$<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.val<span class="phpOperator">(</span><span class="phpOperator">)</span> <span class="phpOperator"><span class="phpOperator">=</span>=</span> <span class="phpString">''</span> &#038;amp<span class="phpText">;</span>&#038;amp<span class="phpText">;</span> $<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.attr<span class="phpOperator">(</span><span class="phpString">'title'</span><span class="phpOperator">)</span> <span class="phpOperator">!</span><span class="phpOperator">=</span> <span class="phpString">''</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
       $<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.val<span class="phpOperator">(</span>$<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.attr<span class="phpOperator">(</span><span class="phpString">'title'</span><span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpText">;</span>
       $<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.addClass<span class="phpOperator">(</span><span class="phpString">'auto-hint'</span><span class="phpOperator">)</span><span class="phpText">;</span>
    <span class="phpOperator">}</span>
<span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
$<span class="phpOperator">(</span><span class="phpString">'INPUT<span class="phpOperator">.</span>auto-hint, TEXTAREA<span class="phpOperator">.</span>auto-hint'</span><span class="phpOperator">)</span>.<span class="phpFunction">each</span><span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
   <span class="phpKeyword"> if<span class="phpOperator">(</span></span>$<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.attr<span class="phpOperator">(</span><span class="phpString">'title'</span><span class="phpOperator">)</span> <span class="phpOperator"><span class="phpOperator">=</span>=</span> <span class="phpString">''</span><span class="phpOperator">)</span><span class="phpOperator">{</span><span class="phpKeyword"> return<span class="phpText">;</span></span> <span class="phpOperator">}</span>
   <span class="phpKeyword"> if<span class="phpOperator">(</span></span>$<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.val<span class="phpOperator">(</span><span class="phpOperator">)</span> <span class="phpOperator"><span class="phpOperator">=</span>=</span> <span class="phpString">''</span><span class="phpOperator">)</span><span class="phpOperator">{</span> $<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.val<span class="phpOperator">(</span>$<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.attr<span class="phpOperator">(</span><span class="phpString">'title'</span><span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpText">;</span> <span class="phpOperator">}</span>
   <span class="phpKeyword"> else </span><span class="phpOperator">{</span> $<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.removeClass<span class="phpOperator">(</span><span class="phpString">'auto-hint'</span><span class="phpOperator">)</span><span class="phpText">;</span> <span class="phpOperator">}</span>
<span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
</pre>
<p>That&#8217;s it! ;) Click the <strong>Demo</strong> button to see it in action.</p>
<img src="http://www.ajaxblender.com/?ak_action=api_record_view&id=1128&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.ajaxblender.com/howto-add-hints-form-auto-focus-using-javascript.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Images to Grayscale</title>
		<link>http://www.ajaxblender.com/howto-convert-image-to-grayscale-using-javascript.html</link>
		<comments>http://www.ajaxblender.com/howto-convert-image-to-grayscale-using-javascript.html#comments</comments>
		<pubDate>Mon, 07 Dec 2009 15:33:03 +0000</pubDate>
		<dc:creator>ajaxBlender.com</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[beginner guide]]></category>
		<category><![CDATA[desaturate]]></category>
		<category><![CDATA[grayscale]]></category>
		<category><![CDATA[image effects]]></category>

		<guid isPermaLink="false">http://www.ajaxblender.com/?p=1113</guid>
		<description><![CDATA[Read this tutorial to find out how to desaturate an image (convert color images to grayscale) using JavaScript. A cross-browser code sample is supplied.
Recently we published a tutorial explaining how to rotate images using JavaScript. To continue this series of tutorials on image manipulation using JavaScript, we would like to explain how to change color [...]]]></description>
			<content:encoded><![CDATA[<p>Read this tutorial to find out how to desaturate an image (convert color images to grayscale) using JavaScript. A cross-browser code sample is supplied.<span id="more-1113"></span><br />
Recently we published a tutorial explaining <a title="How to Rotate Images using JavaScript" href="http://www.ajaxblender.com/howto-rotate-image-using-javascript-canvas.html" target="_blank">how to rotate images using JavaScript</a>. To continue this series of tutorials on image manipulation using JavaScript, we would like to explain how to change color images to grayscale using JavaScript.</p>
<p>This is a relatively simple task, but there are two methods (one method for Internet Explorer and one method for all other browsers).</p>
<h3>Canvas Method</h3>
<p>As you probably know, screen color consists of 3 components: red, green and blue. Each component or color (for example, red) has a value from 0 to 255. The value 0 indicates there is no red color and the value 255 would be the brightest possible red color. To convert a color to grayscale you just need to calculate the average for all three components. This can be done using the simple formula below:</p>
<pre class="php">
grayscalecolor <span class="phpOperator">=</span> <span class="phpOperator">(</span>red <span class="phpOperator">+</span> green <span class="phpOperator">+</span> blue<span class="phpOperator">)</span> / 3;
</pre>
<p>All modern browsers support the CANVAS tag which is allowed access to the image’s pixels. The code below will go through each pixel in the image and replace the color values with an average value. Here is the code:</p>
<pre class="php">
<span class="phpKeyword">
var </span>canvas <span class="phpOperator">=</span> document.createElement<span class="phpOperator">(</span><span class="phpString">'canvas'</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpKeyword">
var </span>canvasContext <span class="phpOperator">=</span> canvas<span class="phpOperator">.</span>getContext<span class="phpOperator">(</span><span class="phpString">'2d'</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpKeyword">
var </span>imgW <span class="phpOperator">=</span> imgObj<span class="phpOperator">.</span>width<span class="phpText">;</span>
<span class="phpKeyword">
var </span>imgH <span class="phpOperator">=</span> imgObj<span class="phpOperator">.</span>height;
canvas<span class="phpOperator">.</span>width <span class="phpOperator">=</span> imgW<span class="phpText">;</span>
canvas<span class="phpOperator">.</span>height <span class="phpOperator">=</span> imgH<span class="phpText">;</span>
canvasContext.drawImage<span class="phpOperator">(</span>imgObj, <span class="phpNumber">0</span>, <span class="phpNumber">0</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpKeyword">
var </span>imgPixels <span class="phpOperator">=</span> canvasContext.getImageData<span class="phpOperator">(</span><span class="phpNumber">0</span>, <span class="phpNumber">0</span>, imgW, imgH<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpKeyword">
for<span class="phpOperator">(</span></span>>var y <span class="phpOperator">=</span> 0; y <span class="phpOperator">&lt;</span> imgPixels<span class="phpOperator">.</span>height; y<span class="phpOperator"><span class="phpOperator">+</span><span class="phpOperator">+</span></span><span class="phpOperator">)</span><span class="phpOperator">{</span>
    <span class="phpKeyword"> for<span class="phpOperator">(</span></span>>var x <span class="phpOperator">=</span> 0; x <span class="phpOperator">&lt;</span> imgPixels<span class="phpOperator">.</span>width<span class="phpText">;</span> x<span class="phpOperator"><span class="phpOperator">+</span><span class="phpOperator">+</span></span><span class="phpOperator">)</span><span class="phpOperator">{</span>
         <span class="phpKeyword"> var </span>i <span class="phpOperator">=</span> <span class="phpOperator">(</span>y * <span class="phpNumber">4</span><span class="phpOperator">)</span> * imgPixels<span class="phpOperator">.</span>width <span class="phpOperator">+</span> x * <span class="phpNumber">4</span><span class="phpText">;</span>
         <span class="phpKeyword"> var </span>avg <span class="phpOperator">=</span> <span class="phpOperator">(</span>imgPixels<span class="phpOperator">.</span>data<span class="phpOperator">[</span>i<span class="phpOperator">]</span> <span class="phpOperator">+</span> imgPixels<span class="phpOperator">.</span>data<span class="phpOperator">[</span>i <span class="phpOperator">+</span> <span class="phpNumber">1</span><span class="phpOperator">]</span> <span class="phpOperator">+</span> imgPixels<span class="phpOperator">.</span>data<span class="phpOperator">[</span>i <span class="phpOperator">+</span> <span class="phpNumber">2</span><span class="phpOperator">]</span><span class="phpOperator">)</span> / 3;
          imgPixels<span class="phpOperator">.</span>data<span class="phpOperator">[</span>i<span class="phpOperator">]</span> <span class="phpOperator">=</span> avg;
          imgPixels<span class="phpOperator">.</span>data<span class="phpOperator">[</span>i <span class="phpOperator">+</span> <span class="phpNumber">1</span><span class="phpOperator">]</span> <span class="phpOperator">=</span> avg;
          imgPixels<span class="phpOperator">.</span>data<span class="phpOperator">[</span>i <span class="phpOperator">+</span> <span class="phpNumber">2</span><span class="phpOperator">]</span> <span class="phpOperator">=</span> avg;
     <span class="phpOperator">}</span>
<span class="phpOperator">}</span>
canvasContext.putImageData<span class="phpOperator">(</span>imgPixels, <span class="phpNumber">0</span>, <span class="phpNumber">0</span>, <span class="phpNumber">0</span>, <span class="phpNumber">0</span>, imgPixels<span class="phpOperator">.</span>width, imgPixels<span class="phpOperator">.</span>height<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpKeyword">
return </span>canvas<span class="phpOperator">.</span>toDataURL<span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpText">;</span>
</pre>
<p>From the above code sample, you see that we created a canvas, loaded the image into it, and then changed the color values of each pixel in the image to an average value. After that we simply replaced the SRC of our image to the image changed in the canvas.</p>
<p>Using the same method you can also flip images using JavaScript. (We will create a tutorial for this in the future).</p>
<h3>MSIE (Internet Explorer) method</h3>
<p>Microsoft Internet Explorer does not support the CANVAS tag, but Microsoft does provide image manipulation through filters. The filter to use for converting images to grayscale is the filter named <strong>DXImageTransform.Microsoft.BasicImage</strong>. Therefore, we simply apply this filter to our image, and it will work in all versions of MSIE (starting from version 6).</p>
<pre class="php">
imgObj<span class="phpOperator">.</span>style.filter <span class="phpOperator">=</span> <span class="phpString">'progid<span class="phpOperator">:</span>DXImageTransform<span class="phpOperator">.</span>Microsoft.BasicImage<span class="phpOperator">(</span>grayScale=<span class="phpNumber">1</span><span class="phpOperator">)</span>'</span><span class="phpText">;</span>
</pre>
<p>That&#8217;s it ;) Click the <strong>Demo</strong> to see it in action.</p>
<img src="http://www.ajaxblender.com/?ak_action=api_record_view&id=1113&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.ajaxblender.com/howto-convert-image-to-grayscale-using-javascript.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Advanced Plugins Development with ExtJS</title>
		<link>http://www.ajaxblender.com/advanced-plugins-development-with-extjs.html</link>
		<comments>http://www.ajaxblender.com/advanced-plugins-development-with-extjs.html#comments</comments>
		<pubDate>Wed, 02 Dec 2009 18:04:59 +0000</pubDate>
		<dc:creator>ajaxBlender.com</dc:creator>
				<category><![CDATA[Ext.JS]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[plugin development]]></category>

		<guid isPermaLink="false">http://www.ajaxblender.com/?p=1109</guid>
		<description><![CDATA[In this ExtJS tutorial, the author provides helpful tips for successful Ext JS plug-in development. Basic questions are answered such as: &#8220;What is an Ext JS plug-in?&#8221; and more. Also discussed are advanced methods of adding your own custom functionality to the Ext JS framework. We highly recommend this article to those creating UI’s with [...]]]></description>
			<content:encoded><![CDATA[<p>In this ExtJS tutorial, the author provides helpful tips for successful Ext JS plug-in development. Basic questions are answered such as: &#8220;What is an Ext JS plug-in?&#8221; and more. Also discussed are advanced methods of adding your own custom functionality to the Ext JS framework. We highly recommend this article to those creating UI’s with ExtJS.</p>
<img src="http://www.ajaxblender.com/?ak_action=api_record_view&id=1109&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.ajaxblender.com/advanced-plugins-development-with-extjs.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rotate Images Using JavaScript</title>
		<link>http://www.ajaxblender.com/howto-rotate-image-using-javascript-canvas.html</link>
		<comments>http://www.ajaxblender.com/howto-rotate-image-using-javascript-canvas.html#comments</comments>
		<pubDate>Mon, 30 Nov 2009 17:32:19 +0000</pubDate>
		<dc:creator>ajaxBlender.com</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.ajaxblender.com/?p=1100</guid>
		<description><![CDATA[Rotate images using JavaScript &#8211; is this even possible? Of course ;) Read this tutorial to find out how to rotate images using JavaScript, and the code is a cross-browser solution.
Ok, let&#8217;s start from the easiest part. Let&#8217;s say we have the following markup:

&#60;img src=&#34;/article-sources/images/plane-1.jpg&#34; alt=&#34;&#34; id=&#34;image&#34; /&#62;
&#60;canvas id=&#34;canvas&#34;&#62;&#60;/canvas&#62;

The markup above adds the image that [...]]]></description>
			<content:encoded><![CDATA[<p>Rotate images using JavaScript &#8211; is this even possible? Of course ;) Read this tutorial to find out how to rotate images using JavaScript, and the code is a cross-browser solution.<span id="more-1100"></span></p>
<p>Ok, let&#8217;s start from the easiest part. Let&#8217;s say we have the following markup:</p>
<pre class="html">
<span class="htmlImageTag">&lt;img src=<span class="htmlAttributeValue">&quot;/article-sources/images/plane-1.jpg&quot;</span> alt=<span class="htmlAttributeValue">&quot;&quot;</span> id=<span class="htmlAttributeValue">&quot;image&quot;</span> /&gt;</span>
<span class="htmlOtherTag">&lt;canvas id=<span class="htmlAttributeValue">&quot;canvas&quot;</span>&gt;</span><span class="htmlOtherTag">&lt;/canvas&gt;</span>
</pre>
<p>The markup above adds the image that we will rotate and the <strong>CANVAS </strong>tag (which is used to display the rotated image). The CANVAS tag only works for current browsers such as FF, Opera, Chrome, IE8 and Safari. IE 6 and IE 7 do not support the CANVAS tag, so that we will remove it if browser is IE.</p>
<p>Now let’s review how we will rotate the image. Most current browsers supports the <strong>&lt;canvas&gt;</strong> object which actually allows for &#8216;rotate&#8217; and &#8216;drawImage&#8217; methods in 2D context, but the IE 6 and IE7 will not recognize this tag. So Microsoft invented rotation using their filters via <strong>DXImageTransform.Microsoft.BasicImage</strong> (here is a <a href="http://msdn.microsoft.com/en-us/library/ms532918%28VS.85%29.aspx" target="_blank">quick link to MSDN</a>). The good news is that the filter works and is easy to use, but the bad news is that it supports only 4 angles (0, 90, 180 and 270 degrees). The code to rotate images for IE will look like this:</p>
<pre class="php">
<span class="phpComment">//  Use DXImageTransform<span class="phpOperator">.</span>Microsoft.BasicImage filter<span class="phpKeyword"> for </span>MSIE
</span>>switch<span class="phpOperator">(</span>degree<span class="phpOperator">)</span><span class="phpOperator">{</span>
    <span class="phpKeyword"> case </span><span class="phpNumber">0</span><span class="phpOperator">:</span> image.style.filter <span class="phpOperator">=</span> <span class="phpString">'progid<span class="phpOperator">:</span>DXImageTransform<span class="phpOperator">.</span>Microsoft.BasicImage<span class="phpOperator">(</span>rotation<span class="phpOperator">=</span><span class="phpNumber">0</span><span class="phpOperator">)</span>'</span><span class="phpText">;</span><span class="phpKeyword"> break<span class="phpText">;</span></span>
    <span class="phpKeyword"> case </span>90<span class="phpOperator">:</span> image.style.filter <span class="phpOperator">=</span> <span class="phpString">'progid<span class="phpOperator">:</span>DXImageTransform<span class="phpOperator">.</span>Microsoft.BasicImage<span class="phpOperator">(</span>rotation<span class="phpOperator">=</span><span class="phpNumber">1</span><span class="phpOperator">)</span>'</span><span class="phpText">;</span><span class="phpKeyword"> break<span class="phpText">;</span></span>
    <span class="phpKeyword"> case </span>180<span class="phpOperator">:</span> image.style.filter <span class="phpOperator">=</span> <span class="phpString">'progid<span class="phpOperator">:</span>DXImageTransform<span class="phpOperator">.</span>Microsoft.BasicImage<span class="phpOperator">(</span>rotation<span class="phpOperator">=</span><span class="phpNumber">2</span><span class="phpOperator">)</span>'</span><span class="phpText">;</span><span class="phpKeyword"> break<span class="phpText">;</span></span>
    <span class="phpKeyword"> case </span>270<span class="phpOperator">:</span> image.style.filter <span class="phpOperator">=</span> <span class="phpString">'progid<span class="phpOperator">:</span>DXImageTransform<span class="phpOperator">.</span>Microsoft.BasicImage<span class="phpOperator">(</span>rotation<span class="phpOperator">=</span><span class="phpNumber">3</span><span class="phpOperator">)</span>'</span><span class="phpText">;</span><span class="phpKeyword"> break<span class="phpText">;</span></span>
<span class="phpOperator">}</span>
</pre>
<p>And for browsers that support the CNAVAS tag, the code will look like this:</p>
<pre class="php">
<span class="phpKeyword">
var </span>cContext <span class="phpOperator">=</span> canvas<span class="phpOperator">.</span>getContext<span class="phpOperator">(</span><span class="phpString">'2d'</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpKeyword">
var </span>cw <span class="phpOperator">=</span> img<span class="phpOperator">.</span>width, ch <span class="phpOperator">=</span> img<span class="phpOperator">.</span>height, cx <span class="phpOperator">=</span> <span class="phpNumber">0</span>, cy <span class="phpOperator">=</span> 0;
<span class="phpComment">//   Calculate<span class="phpKeyword"> new </span>canvas size and x/y coorditates<span class="phpKeyword"> for </span>image
</span>>switch<span class="phpOperator">(</span>degree<span class="phpOperator">)</span><span class="phpOperator">{</span>
    <span class="phpKeyword"> case </span>90<span class="phpOperator">:</span>
          cw <span class="phpOperator">=</span> img<span class="phpOperator">.</span>height;
          ch <span class="phpOperator">=</span> img<span class="phpOperator">.</span>width<span class="phpText">;</span>
          cy <span class="phpOperator">=</span> img<span class="phpOperator">.</span>height * <span class="phpOperator">(</span>-<span class="phpNumber">1</span><span class="phpOperator">)</span><span class="phpText">;</span>
         <span class="phpKeyword"> break<span class="phpText">;</span></span>
    <span class="phpKeyword"> case </span>180<span class="phpOperator">:</span>
          cx <span class="phpOperator">=</span> img<span class="phpOperator">.</span>width * <span class="phpOperator">(</span>-<span class="phpNumber">1</span><span class="phpOperator">)</span><span class="phpText">;</span>
          cy <span class="phpOperator">=</span> img<span class="phpOperator">.</span>height * <span class="phpOperator">(</span>-<span class="phpNumber">1</span><span class="phpOperator">)</span><span class="phpText">;</span>
         <span class="phpKeyword"> break<span class="phpText">;</span></span>
    <span class="phpKeyword"> case </span>270<span class="phpOperator">:</span>
          cw <span class="phpOperator">=</span> img<span class="phpOperator">.</span>height;
          ch <span class="phpOperator">=</span> img<span class="phpOperator">.</span>width<span class="phpText">;</span>
          cx <span class="phpOperator">=</span> img<span class="phpOperator">.</span>width * <span class="phpOperator">(</span>-<span class="phpNumber">1</span><span class="phpOperator">)</span><span class="phpText">;</span>
         <span class="phpKeyword"> break<span class="phpText">;</span></span>
<span class="phpOperator">}</span>
<span class="phpComment">//  Rotate image
</span>canvas<span class="phpOperator">.</span>setAttribute<span class="phpOperator">(</span><span class="phpString">'width'</span>, cw<span class="phpOperator">)</span><span class="phpText">;</span>
canvas<span class="phpOperator">.</span>setAttribute<span class="phpOperator">(</span><span class="phpString">'height'</span>, ch<span class="phpOperator">)</span><span class="phpText">;</span>
cContext.rotate<span class="phpOperator">(</span>degree * Math<span class="phpOperator">.</span>PI / 180<span class="phpOperator">)</span><span class="phpText">;</span>
cContext.drawImage<span class="phpOperator">(</span>img, cx, cy<span class="phpOperator">)</span><span class="phpText">;</span>
</pre>
<p>We have to change the X/Y coordinates for drawImage function. Otherwise it will not be visible in the viewport (see Figure B versus Figure C on the illustration below).</p>
<p><img class="alignnone size-full wp-image-1101" title="image-rotation-canvas-illustration" src="http://www.ajaxblender.com/wp-content/uploads/2009/11/image-rotation-canvas-illustration.gif" alt="image-rotation-canvas-illustration" width="581" height="420" /></p>
<p>That&#8217;s it ;) Click the <strong>Demo</strong> to see it in action.</p>
<img src="http://www.ajaxblender.com/?ak_action=api_record_view&id=1100&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.ajaxblender.com/howto-rotate-image-using-javascript-canvas.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Create Custom Cursors without .cur File</title>
		<link>http://www.ajaxblender.com/howto-create-custom-image-cursors.html</link>
		<comments>http://www.ajaxblender.com/howto-create-custom-image-cursors.html#comments</comments>
		<pubDate>Wed, 25 Nov 2009 14:33:10 +0000</pubDate>
		<dc:creator>ajaxBlender.com</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[beginner's guide]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.ajaxblender.com/?p=1095</guid>
		<description><![CDATA[Sometimes you may want to replace your cursor with a custom image or use a custom image to move with your cursor. This quick JavaScript tutorial will show you how to implement it.
The task is pretty simple. At first we should hide the default cursor for the section where we will display our custom one. [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you may want to replace your cursor with a custom image or use a custom image to move with your cursor. This quick JavaScript tutorial will show you how to implement it.<span id="more-1095"></span><br />
The task is pretty simple. At first we should hide the default cursor for the section where we will display our custom one. Our custom cursor will actually be a DIV with an image on the background. We will use JavaScript to change the position of this DIV when the user moves the mouse over the section.</p>
<h3>The markup</h3>
<pre class="html">
<span class="htmlOtherTag">&lt;div id=<span class="htmlAttributeValue">&quot;test-area&quot;</span>&gt;</span>
     Move mouse over this area.
<span class="htmlOtherTag">&lt;/div&gt;</span>
<span class="htmlOtherTag">&lt;div id=<span class="htmlAttributeValue">&quot;mycursor&quot;</span>&gt;</span><span class="htmlOtherTag">&lt;/div&gt;</span>
</pre>
<p>The <strong>#test-area</strong> will be the section with our custom cursor to appear and the <strong>#mycursor</strong> will be the actual DIV with the custom cursor image. Here are a few lines of CSS code to stylize the markup:</p>
<pre class="css">
<span class="cssSelector">#test-area {</span>
     <span class="cssProperty">height</span><span class="cssRest">:</span><span class="cssValue"> 200px</span><span class="cssRest">;</span>
     <span class="cssProperty">border</span><span class="cssRest">:</span><span class="cssValue"> 3px dashed #CCCCCC</span><span class="cssRest">;</span>
     <span class="cssProperty">background</span><span class="cssRest">:</span><span class="cssValue"> #FFFFFF</span><span class="cssRest">;</span>
     <span class="cssProperty">padding</span><span class="cssRest">:</span><span class="cssValue"> 20px</span><span class="cssRest">;</span>
     <span class="cssProperty">cursor</span><span class="cssRest">:</span><span class="cssValue"> url(./blank.cur), none</span><span class="cssRest">;</span>
<span class="cssSelector">}</span>
<span class="cssSelector">#mycursor {</span>
     <span class="cssProperty">cursor</span><span class="cssRest">:</span><span class="cssValue"> none</span><span class="cssRest">;</span>
     <span class="cssProperty">width</span><span class="cssRest">:</span><span class="cssValue"> 97px</span><span class="cssRest">;</span>
     <span class="cssProperty">height</span><span class="cssRest">:</span><span class="cssValue"> 137px</span><span class="cssRest">;</span>
     <span class="cssProperty">background</span><span class="cssRest">:</span><span class="cssValue"> url(<span class="cssString">"/article-sources/images/pointer-cursor.gif"</span>) no-repeat left top</span><span class="cssRest">;</span>
     <span class="cssProperty">position</span><span class="cssRest">:</span><span class="cssValue"> absolute</span><span class="cssRest">;</span>
     <span class="cssProperty">display</span><span class="cssRest">:</span><span class="cssValue"> none</span><span class="cssRest">;</span>
     <span class="cssProperty">top</span><span class="cssRest">:</span><span class="cssValue"> 0</span><span class="cssRest">;</span>
     <span class="cssProperty">left</span><span class="cssRest">:</span><span class="cssValue"> 0</span><span class="cssRest">;</span>
     <span class="cssProperty">z-index</span><span class="cssRest">:</span><span class="cssValue"> 10000</span><span class="cssRest">;</span>
<span class="cssSelector">}</span>
</pre>
<p>The code (we hope) is crystal clear but let&#8217;s stop to review one aspect. In the #test-area you see the &#8216;cursor: …&#8217; declaration. We will use this to hide the default browser cursor. The easiest way to do so is to load a blank cursor (you may <a href="http://www.ajaxblender.com/article-sources/jquery/custom-cursors/blank.cur" target="_blank">download it here</a>), but this unfortunately will not work in Chrome &amp; Opera. It will display a black rectangle in Chrome and a default pointer cursor in Opera. But since this tutorial covers other important aspects related to cursor behavior (such as how to handle mouse movement, etc.), it is still a useful topic to cover for those just starting to learn JavaScript programming. So, let&#8217;s continue ;).</p>
<p>The finishing part is to add a few lines of JavaScript code for jQuery to make our arrow follow the cursor.</p>
<pre class="php">
<span class="phpOperator">&lt;</span>script type=<span class="phpString">"text/javascript"</span><span class="phpOperator">&gt;</span>
     $<span class="phpOperator">(</span>document<span class="phpOperator">)</span>.ready<span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
          $<span class="phpOperator">(</span><span class="phpString">'#test-area'</span><span class="phpOperator">)</span>.mouseout<span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
               $<span class="phpOperator">(</span><span class="phpString">'#mycursor'</span><span class="phpOperator">)</span>.hide<span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpText">;</span>
              <span class="phpKeyword"> return </span>>false<span class="phpText">;</span>
          <span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
          $<span class="phpOperator">(</span><span class="phpString">'#test-area'</span><span class="phpOperator">)</span>.mouseenter<span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
               $<span class="phpOperator">(</span><span class="phpString">'#mycursor'</span><span class="phpOperator">)</span>.show<span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpText">;</span>
              <span class="phpKeyword"> return </span>>false<span class="phpText">;</span>
          <span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
          $<span class="phpOperator">(</span><span class="phpString">'#test-area'</span><span class="phpOperator">)</span>.mousemove<span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span>e<span class="phpOperator">)</span><span class="phpOperator">{</span>
               $<span class="phpOperator">(</span><span class="phpString">'#mycursor'</span><span class="phpOperator">)</span>.css<span class="phpOperator">(</span><span class="phpString">'left'</span>, e.clientX - 20<span class="phpOperator">)</span>.css<span class="phpOperator">(</span><span class="phpString">'top'</span>, e.clientY <span class="phpOperator">+</span> <span class="phpNumber">7</span><span class="phpOperator">)</span><span class="phpText">;</span>
          <span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpOperator">&lt;</span>/script<span class="phpOperator">&gt;</span>
</pre>
<p>That&#8217;s it ;) Click the <strong>Demo</strong> button to view it in action.</p>
<img src="http://www.ajaxblender.com/?ak_action=api_record_view&id=1095&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.ajaxblender.com/howto-create-custom-image-cursors.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert ASCII Character to Hex, Decimal and Binary Code</title>
		<link>http://www.ajaxblender.com/howto-convert-ascii-hex-binary-decimal.html</link>
		<comments>http://www.ajaxblender.com/howto-convert-ascii-hex-binary-decimal.html#comments</comments>
		<pubDate>Thu, 19 Nov 2009 17:38:19 +0000</pubDate>
		<dc:creator>ajaxBlender.com</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ascii]]></category>
		<category><![CDATA[beginner's guide]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.ajaxblender.com/?p=1085</guid>
		<description><![CDATA[This JavaScript tutorial explains how to convert ASCII Character to Hex, Decimal and Binary Code using JavaScript. 
Recently we were asked for a function code to convert user input to hex code which was intended to be used in a JavaScript remote terminal application. We decided to share this code and also added two more [...]]]></description>
			<content:encoded><![CDATA[<p>This JavaScript tutorial explains how to convert ASCII Character to Hex, Decimal and Binary Code using JavaScript. <span id="more-1085"></span><br />
Recently we were asked for a function code to convert user input to hex code which was intended to be used in a JavaScript remote terminal application. We decided to share this code and also added two more conversion methods to it. The methods are Character to Decimal, Character to Binary, and Decimal to Hex.</p>
<p>The below code object contains the implementation of the various methods. We hope it will be useful to others, and you may use this code in your projects without any limitations. The code can be downloaded it in a separate file <a href="http://www.ajaxblender.com/article-sources/jquery/ascii-functions/convfunctions.js" target="_blank">here</a>.</p>
<pre class="php">
<span class="phpKeyword">
var </span>Convert <span class="phpOperator">=</span> <span class="phpOperator">{</span>
     chars<span class="phpOperator">:</span> <span class="phpString">" <span class="phpOperator">!</span>\"</span>#$%&#038;amp<span class="phpText">;</span><span class="phpString">'<span class="phpOperator">(</span><span class="phpOperator">)</span>*<span class="phpOperator">+</span>'</span>-<span class="phpOperator">.</span>/0123456789<span class="phpOperator">:</span><span class="phpText">;</span><span class="phpOperator">&lt;</span><span class="phpOperator"><span class="phpOperator">=</span><span class="phpOperator">&gt;</span></span><span class="phpOperator">?</span>@ABCDEFGHIJKLMNOPQRSTUVWXYZ<span class="phpOperator">[</span>\\<span class="phpOperator">]</span>^_`abcdefghijklmnopqrstuvwxyz<span class="phpOperator">{</span><span class="phpOperator">|</span><span class="phpOperator">}</span>~<span class="phpString">",
     hex<span class="phpOperator">:</span> <span class="phpString">'0123456789ABCDEF'</span>, bin<span class="phpOperator">:</span> <span class="phpOperator">[</span><span class="phpString">'0000'</span>, <span class="phpString">'0001'</span>, <span class="phpString">'0010'</span>, <span class="phpString">'0011'</span>, <span class="phpString">'0100'</span>, <span class="phpString">'0101'</span>, <span class="phpString">'0110'</span>, <span class="phpString">'0111'</span>, <span class="phpString">'1000'</span>, <span class="phpString">'1001'</span>, <span class="phpString">'1010'</span>, <span class="phpString">'1011'</span>, <span class="phpString">'1100'</span>, <span class="phpString">'1101'</span>, <span class="phpString">'1110'</span>, <span class="phpString">'1111'</span><span class="phpOperator">]</span>,
     decToHex<span class="phpOperator">:</span> <span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span>d<span class="phpOperator">)</span><span class="phpOperator">{</span>
         <span class="phpKeyword"> return </span><span class="phpOperator">(</span>this<span class="phpOperator">.</span>hex<span class="phpOperator">.</span>charAt<span class="phpOperator">(</span><span class="phpOperator">(</span>d - d % 16<span class="phpOperator">)</span>/16<span class="phpOperator">)</span> <span class="phpOperator">+</span> this<span class="phpOperator">.</span>hex<span class="phpOperator">.</span>charAt<span class="phpOperator">(</span>d % 16<span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpText">;</span>
     <span class="phpOperator">}</span>,
     toBin<span class="phpOperator">:</span> <span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span>ch<span class="phpOperator">)</span><span class="phpOperator">{</span>
         <span class="phpKeyword"> var </span>d <span class="phpOperator">=</span> this<span class="phpOperator">.</span>toDec<span class="phpOperator">(</span>ch<span class="phpOperator">)</span><span class="phpText">;</span>
         <span class="phpKeyword"> var </span>l <span class="phpOperator">=</span> this<span class="phpOperator">.</span>hex<span class="phpOperator">.</span>charAt<span class="phpOperator">(</span>d % 16<span class="phpOperator">)</span><span class="phpText">;</span>
         <span class="phpKeyword"> var </span>h <span class="phpOperator">=</span> this<span class="phpOperator">.</span>hex<span class="phpOperator">.</span>charAt<span class="phpOperator">(</span><span class="phpOperator">(</span>d - d % 16<span class="phpOperator">)</span>/16<span class="phpOperator">)</span><span class="phpText">;</span>
         <span class="phpKeyword"> var </span>hhex <span class="phpOperator">=</span> "</span>ABCDEF&quot;<span class="phpText">;</span>
         <span class="phpKeyword"> var </span>lown <span class="phpOperator">=</span> l <span class="phpOperator">&lt;</span> 10 <span class="phpOperator">?</span> l <span class="phpOperator">:</span> <span class="phpOperator">(</span>10 <span class="phpOperator">+</span> hhex<span class="phpOperator">.</span>indexOf<span class="phpOperator">(</span>l<span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpText">;</span>
         <span class="phpKeyword"> var </span>highn <span class="phpOperator">=</span> h <span class="phpOperator">&lt;</span> 10 <span class="phpOperator">?</span> h <span class="phpOperator">:</span> <span class="phpOperator">(</span>10 <span class="phpOperator">+</span> hhex<span class="phpOperator">.</span>indexOf<span class="phpOperator">(</span>h<span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpText">;</span>
         <span class="phpKeyword"> return </span>this<span class="phpOperator">.</span>bin<span class="phpOperator">[</span>highn<span class="phpOperator">]</span> <span class="phpOperator">+</span> <span class="phpString">' '</span> <span class="phpOperator">+</span> this<span class="phpOperator">.</span>bin<span class="phpOperator">[</span>lown<span class="phpOperator">]</span><span class="phpText">;</span>
     <span class="phpOperator">}</span>,
     toHex<span class="phpOperator">:</span> <span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span>ch<span class="phpOperator">)</span><span class="phpOperator">{</span>
         <span class="phpKeyword"> return </span>this<span class="phpOperator">.</span>decToHex<span class="phpOperator">(</span>this<span class="phpOperator">.</span>toDec<span class="phpOperator">(</span>ch<span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpText">;</span>
     <span class="phpOperator">}</span>,
     toDec<span class="phpOperator">:</span> <span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span>ch<span class="phpOperator">)</span><span class="phpOperator">{</span>
         <span class="phpKeyword"> var </span>p <span class="phpOperator">=</span> this<span class="phpOperator">.</span>chars<span class="phpOperator">.</span>indexOf<span class="phpOperator">(</span>ch<span class="phpOperator">)</span><span class="phpText">;</span>
         <span class="phpKeyword"> return </span><span class="phpOperator">(</span>p <span class="phpOperator">&lt;</span><span class="phpOperator">=</span> -<span class="phpNumber">1</span><span class="phpOperator">)</span> <span class="phpOperator">?</span> <span class="phpNumber">0</span> <span class="phpOperator">:</span> <span class="phpOperator">(</span>p <span class="phpOperator">+</span> 32<span class="phpOperator">)</span><span class="phpText">;</span>
     <span class="phpOperator">}</span>
<span class="phpOperator">}</span><span class="phpText">;</span>
</pre>
<p>Here is how to call the above code:</p>
<pre class="php">
<span class="phpComment">//  Convert Character to Binary <span class="phpOperator">(</span>it will<span class="phpKeyword"> return </span>0100 0001<span class="phpOperator">)</span><span class="phpText">;</span>
</span>Convert.toBin<span class="phpOperator">(</span><span class="phpString">'A'</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpComment">//  Convert Character to Hex <span class="phpOperator">(</span>it will<span class="phpKeyword"> return </span>41<span class="phpOperator">)</span><span class="phpText">;</span>
</span>Convert.toHex<span class="phpOperator">(</span><span class="phpString">'A'</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpComment">//  Convert Character to Dec <span class="phpOperator">(</span>it will<span class="phpKeyword"> return </span>65<span class="phpOperator">)</span><span class="phpText">;</span>
</span>Convert.toDec<span class="phpOperator">(</span><span class="phpString">'A'</span><span class="phpOperator">)</span><span class="phpText">;</span>
</pre>
<p>That&#8217;s it ;) Click the <strong>Demo</strong> button to view it an action.</p>
<img src="http://www.ajaxblender.com/?ak_action=api_record_view&id=1085&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.ajaxblender.com/howto-convert-ascii-hex-binary-decimal.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>W3C Valid Replacement for target=&#8221;_blank&#8221;</title>
		<link>http://www.ajaxblender.com/open-links-new-window-w3c-valid-target-blank.html</link>
		<comments>http://www.ajaxblender.com/open-links-new-window-w3c-valid-target-blank.html#comments</comments>
		<pubDate>Tue, 17 Nov 2009 14:57:43 +0000</pubDate>
		<dc:creator>ajaxBlender.com</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[beginner's guide]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.ajaxblender.com/?p=1074</guid>
		<description><![CDATA[Using target=&#8221;_blank&#8221; for links in an HTML page will generate errors when running code through the W3C validator. Well, if you are using the older Transitional document type it would not, but errors will for sure be reported for Strict document types. An easy and quick solution is to create a JavaScript handler for your [...]]]></description>
			<content:encoded><![CDATA[<p>Using <strong>target=&#8221;_blank&#8221;</strong> for links in an HTML page will generate errors when running code through the <a title="W3C Validator" href="http://validator.w3.org/" target="_blank">W3C validator</a>. Well, if you are using the older Transitional document type it would not, but errors will for sure be reported for Strict document types. An easy and quick solution is to create a JavaScript handler for your links. This tutorials explains how to create an <strong>SEO-friendly</strong> (of course) <strong>W3С valid replacement for target=&#8221;_blank&#8221;</strong> by using only a few lines of jQuery code.<span id="more-1074"></span></p>
<p>Here are two easy solutions to solve the task. In both solutions we will walk through each link in a page and apply our handlers to them so they will open in a new window. You should use the code below in your <strong>&lt;head&gt;&#8230;&lt;/head&gt;</strong> tag, i.e.:</p>
<pre class="html">
<span class="htmlOtherTag">&lt;head&gt;</span>
...
     <span class="htmlScriptTag">&lt;script type=<span class="htmlAttributeValue">&quot;text/javascript&quot;</span>&gt;</span>
     //    Put the code here
     <span class="htmlScriptTag">&lt;/script&gt;</span>
<span class="htmlOtherTag">&lt;/head&gt;</span>
</pre>
<p>Or you may save it to a separate file and link it in the <strong>&lt;head&gt;&#8230;&lt;/head&gt;</strong> tag, i.e.:</p>
<pre class="html">
<span class="htmlOtherTag">&lt;head&gt;</span>
...
<span class="htmlScriptTag">&lt;script type=<span class="htmlAttributeValue">&quot;text/javascript&quot;</span> src=<span class="htmlAttributeValue">&quot;path-to-js-file.js&quot;</span>&gt;</span><span class="htmlScriptTag">&lt;/script&gt;</span>
<span class="htmlOtherTag">&lt;/head&gt;</span>
</pre>
<h3>Solution 1</h3>
<p>While the target attribute is depreciated by W3C Strict standards, it is available via the DOM object. For the first solution, you can apply <strong>target=&#8221;_blank&#8221;</strong> via JavaScript. It will open in a new window and still be W3C valid. Here is the code:</p>
<pre class="php">
     $<span class="phpOperator">(</span>document<span class="phpOperator">)</span>.ready<span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
          $<span class="phpOperator">(</span><span class="phpString">'A<span class="phpOperator">[</span>rel=<span class="phpString">"_blank"</span><span class="phpOperator">]</span>'</span><span class="phpOperator">)</span>.<span class="phpFunction">each</span><span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
               $<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.attr<span class="phpOperator">(</span><span class="phpString">'target'</span>, <span class="phpString">'_blank'</span><span class="phpOperator">)</span><span class="phpText">;</span>
          <span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
     <span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
</pre>
<h3>Solution 2</h3>
<p>While the first solution is to apply &#8216;_blank&#8217; value to a native link&#8217;s attribute &#8216;target&#8217; via JavaScript, the second solution is to handle the click on the link and open it in a new window. Please note that both alternative methods are absolutely SEO friendly and W3C valid. The code for the second solution is:</p>
<pre class="php">
     $<span class="phpOperator">(</span>document<span class="phpOperator">)</span>.ready<span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
          $<span class="phpOperator">(</span><span class="phpString">'A<span class="phpOperator">[</span>rel=<span class="phpString">"_blank"</span><span class="phpOperator">]</span>'</span><span class="phpOperator">)</span>.click<span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
               window<span class="phpOperator">.</span>open<span class="phpOperator">(</span>$<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.attr<span class="phpOperator">(</span><span class="phpString">'href'</span><span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpText">;</span>
              <span class="phpKeyword"> return </span>>false<span class="phpText">;</span>
          <span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
     <span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
</pre>
<p>That&#8217;s it ;) Click the <strong>Demo</strong> button to see it in action.</p>
<img src="http://www.ajaxblender.com/?ak_action=api_record_view&id=1074&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.ajaxblender.com/open-links-new-window-w3c-valid-target-blank.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Create Custom AJAX Tabs using jQuery</title>
		<link>http://www.ajaxblender.com/howto-create-custom-jquery-tabs.html</link>
		<comments>http://www.ajaxblender.com/howto-create-custom-jquery-tabs.html#comments</comments>
		<pubDate>Fri, 13 Nov 2009 18:56:29 +0000</pubDate>
		<dc:creator>ajaxBlender.com</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[beginner's guide]]></category>
		<category><![CDATA[tabs]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.ajaxblender.com/?p=1049</guid>
		<description><![CDATA[Today&#8217;s morning started a little hot here at ajaxBlender. We had some free time before starting the production meeting, and Mike (our lead developer guy) and Justin (newbie who joined us in November) started arguing about their respective abilities of creating cross-browser markup code (HTML, CSS, JS) by hand without mistakes, but also doing it [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s morning started a little hot here at ajaxBlender. We had some free time before starting the production meeting, and Mike (our lead developer guy) and Justin (newbie who joined us in November) started arguing about their respective abilities of creating cross-browser markup code (HTML, CSS, JS) by hand without mistakes, but also doing it really fast.<span id="more-1049"></span>The exchange went a little like this:</p>
<div class="user-email">
<p><strong>J: </strong>I am sure, there is no way you can create scripts from scratch fast. First thing is you integrate the 3rd party stuff. This is easy but when you have to create your custom code, it will require time for debugging, planning the structure, etc &#8211; even for small scripts.</p>
<p><strong>M:</strong> Ha, do you want to try me? ;) You select a script and I do it. If I do it you owe me a pizza and make me coffee each morning for a week, otherwise I will for you.</p>
<p><strong>J: </strong>Hm.. Sounds good. What about ajax tabs?</p>
<p><strong>M:</strong> No problem :) How much time?</p>
<p><strong>J:</strong> 10 minutes?</p>
<p><strong>M: </strong>Great!</div>
<p>As you see, resolution to the matter involved a little fun and a wager (pizza).</p>
<p>Experience took its part &#8211; Justin lost. We recorded the process for proof ;) and now we’re posting it with a quick tutorial. You can watch Mike “cook” the code in the time-lapse YouTube video below, and you can <a href="http://www.ajaxblender.com/article-sources/jquery/ajax-tabs-example/download/ajax-tabs-demo.zip">download his AJAX tabs here</a>.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/7A2E1ope4PM&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en&#038;feature=player_embedded&#038;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.youtube.com/v/7A2E1ope4PM&#038;color1=0xb1b1b1&#038;color2=0xcfcfcf&#038;hl=en&#038;feature=player_embedded&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344"></embed></object></p>
<p>That&#8217;s it ;) Click the <strong>Demo</strong> button to see it in action.</p>
<p>Here’s the code he created:</p>
<h3>HTML</h3>
<pre class="html">
<span class="htmlOtherTag">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span>
<span class="htmlOtherTag">&lt;html xmlns=<span class="htmlAttributeValue">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span>
<span class="htmlOtherTag">&lt;head&gt;</span>
     <span class="htmlOtherTag">&lt;meta http-equiv=<span class="htmlAttributeValue">&quot;Content-Type&quot;</span> content=<span class="htmlAttributeValue">&quot;text/html; charset=UTF-8&quot;</span> /&gt;</span>
     <span class="htmlOtherTag">&lt;title&gt;</span>Tabs Demo<span class="htmlOtherTag">&lt;/title&gt;</span>
     <span class="htmlOtherTag">&lt;link rel=<span class="htmlAttributeValue">&quot;stylesheet&quot;</span> href=<span class="htmlAttributeValue">&quot;./main.css&quot;</span> /&gt;</span>
     <span class="htmlScriptTag">&lt;script type=<span class="htmlAttributeValue">&quot;text/javascript&quot;</span> src=<span class="htmlAttributeValue">&quot;./jquery-1.3.2.min.js&quot;</span>&gt;</span><span class="htmlScriptTag">&lt;/script&gt;</span>
     <span class="htmlScriptTag">&lt;script type=<span class="htmlAttributeValue">&quot;text/javascript&quot;</span> src=<span class="htmlAttributeValue">&quot;./main.js&quot;</span>&gt;</span><span class="htmlScriptTag">&lt;/script&gt;</span>
<span class="htmlOtherTag">&lt;/head&gt;</span>
<span class="htmlOtherTag">&lt;body&gt;</span>
     <span class="htmlOtherTag">&lt;div id=<span class="htmlAttributeValue">&quot;page&quot;</span>&gt;</span>
          <span class="htmlOtherTag">&lt;ul id=<span class="htmlAttributeValue">&quot;tabs&quot;</span>&gt;</span>
               <span class="htmlOtherTag">&lt;li&gt;</span><span class="htmlAnchorTag">&lt;a href=<span class="htmlAttributeValue">&quot;./tabs/tab-1.html&quot;</span>&gt;</span>Tab 1<span class="htmlAnchorTag">&lt;/a&gt;</span><span class="htmlOtherTag">&lt;/li&gt;</span>
               <span class="htmlOtherTag">&lt;li&gt;</span><span class="htmlAnchorTag">&lt;a href=<span class="htmlAttributeValue">&quot;./tabs/tab-2.html&quot;</span>&gt;</span>Tab 2<span class="htmlAnchorTag">&lt;/a&gt;</span><span class="htmlOtherTag">&lt;/li&gt;</span>
               <span class="htmlOtherTag">&lt;li&gt;</span><span class="htmlAnchorTag">&lt;a href=<span class="htmlAttributeValue">&quot;./tabs/tab-3.html&quot;</span>&gt;</span>Tab 3<span class="htmlAnchorTag">&lt;/a&gt;</span><span class="htmlOtherTag">&lt;/li&gt;</span>
          <span class="htmlOtherTag">&lt;/ul&gt;</span>
          <span class="htmlOtherTag">&lt;div id=<span class="htmlAttributeValue">&quot;tabs-container&quot;</span>&gt;</span>
               Loading. Please Wait...
          <span class="htmlOtherTag">&lt;/div&gt;</span>
<span class="htmlOtherTag">&lt;/div&gt;</span>
<span class="htmlOtherTag">&lt;/body&gt;</span>
<span class="htmlOtherTag">&lt;/html&gt;</span>
</pre>
<h3>CSS</h3>
<pre class="css">
<span class="cssSelector">BODY {</span>
     <span class="cssProperty">margin</span><span class="cssRest">:</span><span class="cssValue"> 20px</span><span class="cssRest">;</span>
     <span class="cssProperty">padding</span><span class="cssRest">:</span><span class="cssValue"> 20px</span><span class="cssRest">;</span>
     <span class="cssProperty">font-family</span><span class="cssRest">:</span><span class="cssValue"> <span class="cssString">"Lucida Grande"</span>, Arial, Helvetica, sans-serif</span><span class="cssRest">;</span>
     <span class="cssProperty">font-size</span><span class="cssRest">:</span><span class="cssValue"> 12px</span><span class="cssRest">;</span>
     <span class="cssProperty">color</span><span class="cssRest">:</span><span class="cssValue"> #333333</span><span class="cssRest">;</span>
<span class="cssSelector">}</span>
<span class="cssSelector">#page {</span>
     <span class="cssProperty">margin</span><span class="cssRest">:</span><span class="cssValue"> auto</span><span class="cssRest">;</span>
     <span class="cssProperty">width</span><span class="cssRest">:</span><span class="cssValue"> 1000px</span><span class="cssRest">;</span>
<span class="cssSelector">}</span>
<span class="cssSelector">UL.mytabs {</span>
     <span class="cssProperty">position</span><span class="cssRest">:</span><span class="cssValue"> relative</span><span class="cssRest">;</span>
     <span class="cssProperty">z-index</span><span class="cssRest">:</span><span class="cssValue"> 2</span><span class="cssRest">;</span>
<span class="cssSelector">}</span>
<span class="cssSelector">UL.mytabs, UL.mytabs LI {</span>
     <span class="cssProperty">margin</span><span class="cssRest">:</span><span class="cssValue"> 0</span><span class="cssRest">;</span>
     <span class="cssProperty">padding</span><span class="cssRest">:</span><span class="cssValue"> 0</span><span class="cssRest">;</span>
     <span class="cssProperty">list-style</span><span class="cssRest">:</span><span class="cssValue"> none</span><span class="cssRest">;</span>
     <span class="cssProperty">float</span><span class="cssRest">:</span><span class="cssValue"> left</span><span class="cssRest">;</span>
<span class="cssSelector">}</span>
<span class="cssSelector">UL.mytabs LI {</span> <span class="cssProperty">padding</span><span class="cssRest">:</span><span class="cssValue"> 0 5px</span><span class="cssRest">;</span> <span class="cssSelector">}</span>
<span class="cssSelector">UL.mytabs LI A {</span>
     <span class="cssProperty">float</span><span class="cssRest">:</span><span class="cssValue"> left</span><span class="cssRest">;</span>
     <span class="cssProperty">padding</span><span class="cssRest">:</span><span class="cssValue"> 7px</span><span class="cssRest">;</span>
     <span class="cssProperty">border</span><span class="cssRest">:</span><span class="cssValue"> 1px solid #CCCCCC</span><span class="cssRest">;</span>
     <span class="cssProperty">border-bottom</span><span class="cssRest">:</span><span class="cssValue"> 1px solid #E0E0E0</span><span class="cssRest">;</span>
     <span class="cssProperty">background</span><span class="cssRest">:</span><span class="cssValue"> #F0F0F0</span><span class="cssRest">;</span>
     <span class="cssProperty">text-decoration</span><span class="cssRest">:</span><span class="cssValue"> none</span><span class="cssRest">;</span>
     <span class="cssProperty">color</span><span class="cssRest">:</span><span class="cssValue"> #333333</span><span class="cssRest">;</span>
     <span class="cssProperty">height</span><span class="cssRest">:</span><span class="cssValue"> 22px</span><span class="cssRest">;</span>
<span class="cssSelector">}</span>
<span class="cssSelector">UL.mytabs LI A:HOVER, UL.mytabs LI.current A {</span>
     <span class="cssProperty">background</span><span class="cssRest">:</span><span class="cssValue"> #FFFFFF</span><span class="cssRest">;</span>
<span class="cssSelector">}</span>
<span class="cssSelector">UL.mytabs LI.current A {</span>
     <span class="cssProperty">font-weight</span><span class="cssRest">:</span><span class="cssValue"> bold</span><span class="cssRest">;</span>
     <span class="cssProperty">font-size</span><span class="cssRest">:</span><span class="cssValue"> 14px</span><span class="cssRest">;</span>
     <span class="cssProperty">border-bottom</span><span class="cssRest">:</span><span class="cssValue"> 1px solid #FFFFFF</span><span class="cssRest">;</span>
<span class="cssSelector">}</span>
<span class="cssSelector">.mytabs-container {</span>
     <span class="cssProperty">position</span><span class="cssRest">:</span><span class="cssValue"> relative</span><span class="cssRest">;</span>
     <span class="cssProperty">z-index</span><span class="cssRest">:</span><span class="cssValue"> 1</span><span class="cssRest">;</span>
     <span class="cssProperty">clear</span><span class="cssRest">:</span><span class="cssValue"> both</span><span class="cssRest">;</span>
     <span class="cssProperty">border</span><span class="cssRest">:</span><span class="cssValue"> 1px solid #E0E0E0</span><span class="cssRest">;</span>
     <span class="cssProperty">padding</span><span class="cssRest">:</span><span class="cssValue"> 10px</span><span class="cssRest">;</span>
     <span class="cssProperty">top</span><span class="cssRest">:</span><span class="cssValue"> -1px</span><span class="cssRest">;</span>
<span class="cssSelector">}</span>
</pre>
<h3>JavaScript</h3>
<pre class="php">
<span class="phpKeyword">
var </span>containerId <span class="phpOperator">=</span> <span class="phpString">'#tabs-container'</span><span class="phpText">;</span>
<span class="phpKeyword">
var </span>tabsId <span class="phpOperator">=</span> <span class="phpString">'#tabs'</span><span class="phpText">;</span>
$<span class="phpOperator">(</span>document<span class="phpOperator">)</span>.ready<span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
     <span class="phpComment">// Preload tab on page load
</span>    <span class="phpKeyword"> if<span class="phpOperator">(</span></span>$<span class="phpOperator">(</span>tabsId <span class="phpOperator">+</span> <span class="phpString">' LI<span class="phpOperator">.</span>current A'</span><span class="phpOperator">)</span>.length <span class="phpOperator">&gt;</span> <span class="phpNumber">0</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
          loadTab<span class="phpOperator">(</span>$<span class="phpOperator">(</span>tabsId <span class="phpOperator">+</span> <span class="phpString">' LI<span class="phpOperator">.</span>current A'</span><span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpText">;</span>
     <span class="phpOperator">}</span>
     $<span class="phpOperator">(</span>tabsId <span class="phpOperator">+</span> <span class="phpString">' A'</span><span class="phpOperator">)</span>.click<span class="phpOperator">(</span><span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
         <span class="phpKeyword"> if<span class="phpOperator">(</span></span>$<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.parent<span class="phpOperator">(</span><span class="phpOperator">)</span>.hasClass<span class="phpOperator">(</span><span class="phpString">'current'</span><span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpOperator">{</span><span class="phpKeyword"> return </span>>false<span class="phpText">;</span> <span class="phpOperator">}</span>
          $<span class="phpOperator">(</span>tabsId <span class="phpOperator">+</span> <span class="phpString">' LI<span class="phpOperator">.</span>current'</span><span class="phpOperator">)</span>.removeClass<span class="phpOperator">(</span><span class="phpString">'current'</span><span class="phpOperator">)</span><span class="phpText">;</span>
          $<span class="phpOperator">(</span>this<span class="phpOperator">)</span>.parent<span class="phpOperator">(</span><span class="phpOperator">)</span>.addClass<span class="phpOperator">(</span><span class="phpString">'current'</span><span class="phpOperator">)</span><span class="phpText">;</span>
          loadTab<span class="phpOperator">(</span>$<span class="phpOperator">(</span>this<span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpText">;</span>
         <span class="phpKeyword"> return </span>>false<span class="phpText">;</span>
     <span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpFunctionKeyword">function</span> loadTab<span class="phpOperator">(</span>tabObj<span class="phpOperator">)</span><span class="phpOperator">{</span>
    <span class="phpKeyword"> if<span class="phpOperator">(</span></span><span class="phpOperator">!</span>tabObj <span class="phpOperator">|</span><span class="phpOperator">|</span> <span class="phpOperator">!</span>tabObj<span class="phpOperator">.</span>length<span class="phpOperator">)</span><span class="phpOperator">{</span><span class="phpKeyword"> return<span class="phpText">;</span></span> <span class="phpOperator">}</span>
     $<span class="phpOperator">(</span>containerId<span class="phpOperator">)</span>.addClass<span class="phpOperator">(</span><span class="phpString">'loading'</span><span class="phpOperator">)</span><span class="phpText">;</span>
     $<span class="phpOperator">(</span>containerId<span class="phpOperator">)</span>.fadeOut<span class="phpOperator">(</span><span class="phpString">'fast'</span><span class="phpOperator">)</span><span class="phpText">;</span>
     $<span class="phpOperator">(</span>containerId<span class="phpOperator">)</span>.load<span class="phpOperator">(</span>tabObj<span class="phpOperator">.</span>attr<span class="phpOperator">(</span><span class="phpString">'href'</span><span class="phpOperator">)</span>, <span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
          $<span class="phpOperator">(</span>containerId<span class="phpOperator">)</span>.removeClass<span class="phpOperator">(</span><span class="phpString">'loading'</span><span class="phpOperator">)</span><span class="phpText">;</span>
          $<span class="phpOperator">(</span>containerId<span class="phpOperator">)</span>.fadeIn<span class="phpOperator">(</span><span class="phpString">'fast'</span><span class="phpOperator">)</span><span class="phpText">;</span>
     <span class="phpOperator">}</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpOperator">}</span>
</pre>
<img src="http://www.ajaxblender.com/?ak_action=api_record_view&id=1049&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.ajaxblender.com/howto-create-custom-jquery-tabs.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>How to Resize Image Proportionally using JavaScript</title>
		<link>http://www.ajaxblender.com/howto-resize-image-proportionally-using-javascript.html</link>
		<comments>http://www.ajaxblender.com/howto-resize-image-proportionally-using-javascript.html#comments</comments>
		<pubDate>Tue, 10 Nov 2009 14:20:01 +0000</pubDate>
		<dc:creator>ajaxBlender.com</dc:creator>
				<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[beginner's guide]]></category>
		<category><![CDATA[image resize]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.ajaxblender.com/?p=1023</guid>
		<description><![CDATA[We&#8217;re continuing a series of &#8220;How-to’s&#8221; for JavaScript beginners. In this tutorial we will explain how to proportionally resize images. Most tutorials that we have written utilize JavaScript platforms other than MooTools, so we decided to create this one using Mootools, however the function which will resize image&#8217;s size can be used with any framework [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re continuing a series of &#8220;How-to’s&#8221; for JavaScript beginners. In this tutorial we will explain how to proportionally resize images. Most tutorials that we have written utilize JavaScript platforms other than MooTools, so we decided to create this one using Mootools, however the function which will resize image&#8217;s size can be used with any framework (i.e. jQuery, ExtJS, script.aculo.us or just plain JavaScript.)<span id="more-1023"></span></p>
<p>We will just use an <strong>&lt;img /&gt;</strong> tag to resize the images. The actual task of resizing an image proportionally is quite simple, but the most important thing is to calculate the size properly. At first, you should define the size of the bounding box (the maximum size of your image). Let&#8217;s say it will be 200&#215;200 pixels:</p>
<p><img class="alignnone size-full wp-image-1033" title="bounding-box" src="http://www.ajaxblender.com/wp-content/uploads/2009/11/bounding-box.gif" alt="bounding-box" width="235" height="235" /></p>
<p>And we have a photo with a size larger than the bounding box (size 500&#215;313 pixels):</p>
<p><img class="alignnone size-full wp-image-1025" title="sample-image" src="http://www.ajaxblender.com/wp-content/uploads/2009/11/sample-image.jpg" alt="sample-image" width="500" height="313" /></p>
<p>After the image resize we should get something like this:</p>
<p><img class="alignnone size-full wp-image-1034" title="resized-image" src="http://www.ajaxblender.com/wp-content/uploads/2009/11/resized-image.jpg" alt="resized-image" width="245" height="235" /></p>
<p>So that the width of the image will be 200 pixels and height will proportionally scale and become 125 pixels. The image will look smaller, but it keeps its proportions and will still look good.</p>
<p>Now let&#8217;s discuss how we will be implementing this in the code. Since we may want to reuse the code at some point in the future, it is best to create a function. First, it is smart to think of all the ways it could be used, how it will work, how you will call the function and also to determine input and output values. A little thought at this time will make the coding task simpler and ensure a more flexible product.</p>
<p>Input parameters of the function will be: <strong>maxW</strong>, <strong>maxH</strong> (these parameters will set the size of the bounding box) and <strong>currW</strong>, <strong>currH</strong> <em>(these parameters will contain current or original size of the image. In our sample it&#8217;s 500&#215;313 pixels)</em>. The function will calculate size and return an array containing two values. Usage of the function will be:</p>
<pre class="php">
<span class="phpKeyword">
var </span>newSize <span class="phpOperator">=</span> scaleSize<span class="phpOperator">(</span>200, 200, 500, 313<span class="phpOperator">)</span><span class="phpText">;</span>
alert<span class="phpOperator">(</span><span class="phpString">'New Width<span class="phpOperator">:</span> '</span> <span class="phpOperator">+</span> newSize<span class="phpOperator">[</span><span class="phpNumber">0</span><span class="phpOperator">]</span> <span class="phpOperator">+</span> <span class="phpString">', New Height<span class="phpOperator">:</span> '</span> <span class="phpOperator">+</span> newSize<span class="phpOperator">[</span><span class="phpNumber">1</span><span class="phpOperator">]</span><span class="phpOperator">)</span><span class="phpText">;</span>
</pre>
<p>Now let&#8217;s implement the algorithm of the <strong>scaleSize</strong> function. The logic is simple. You just determine the widest side <em>(for landscape photos it will be width and for portrait photos it will be height)</em>, then set the size of bounding box to it and calculate the size of the opposite side using the following formula:</p>
<p><strong>For width: </strong>currH / currH / currW;<br />
<strong>For height: </strong>currW * currH / currW;</p>
<p>You will notice that <strong>currH / currW</strong> expression repeats in both calculations. This is a ratio of height to width. So, here is the actual implementation of the function:</p>
<pre class="php">
<span class="phpFunctionKeyword">function</span> scaleSize<span class="phpOperator">(</span>maxW, maxH, currW, currH<span class="phpOperator">)</span><span class="phpOperator">{</span>
     <span class="phpKeyword"> var </span>ratio <span class="phpOperator">=</span> currH / currW<span class="phpText">;</span>
     <span class="phpKeyword"> if<span class="phpOperator">(</span></span>currW <span class="phpOperator">&gt;</span><span class="phpOperator">=</span> maxW<span class="phpOperator">)</span><span class="phpOperator">{</span>
            currW <span class="phpOperator">=</span> maxW<span class="phpText">;</span>
            currH <span class="phpOperator">=</span> currW * ratio;
      <span class="phpOperator">}</span><span class="phpKeyword"> else </span>>if<span class="phpOperator">(</span>currH <span class="phpOperator">&gt;</span><span class="phpOperator">=</span> maxH<span class="phpOperator">)</span><span class="phpOperator">{</span>
            currH <span class="phpOperator">=</span> maxH<span class="phpText">;</span>
            currW <span class="phpOperator">=</span> currH / ratio;
      <span class="phpOperator">}</span>
     <span class="phpKeyword"> return </span><span class="phpOperator">[</span>currW, currH<span class="phpOperator">]</span><span class="phpText">;</span>
<span class="phpOperator">}</span>
</pre>
<p>That&#8217;s it ;) Click the <strong>Demo</strong> button to view the code in action.</p>
<img src="http://www.ajaxblender.com/?ak_action=api_record_view&id=1023&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.ajaxblender.com/howto-resize-image-proportionally-using-javascript.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to Call setTimeout or setInterval function in an Object’s Method</title>
		<link>http://www.ajaxblender.com/howto-call-settimeout-setinterval-function-in-object.html</link>
		<comments>http://www.ajaxblender.com/howto-call-settimeout-setinterval-function-in-object.html#comments</comments>
		<pubDate>Mon, 09 Nov 2009 15:19:33 +0000</pubDate>
		<dc:creator>ajaxBlender.com</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[beginner's guide]]></category>

		<guid isPermaLink="false">http://www.ajaxblender.com/?p=1014</guid>
		<description><![CDATA[A common question from JavaScript beginners is how to call the setTimeout or setInterval function. This is an easy task, but can definitely be a headache for those who are new to JavaScript programming. We recently received this question from a user:
Hi guys,
I am starting to learn JS but I cant figure out how to [...]]]></description>
			<content:encoded><![CDATA[<p>A common question from JavaScript beginners is how to call the <strong>setTimeout </strong>or <strong>setInterval </strong>function. This is an easy task, but can definitely be a headache for those who are new to JavaScript programming.<span id="more-1014"></span> We recently received this question from a user:</p>
<div class="user-email">Hi guys,<br />
I am starting to learn JS but I cant figure out how to call<br />
settimeout inside of the javascript object I created.<br />
Here is my code:</p>
<p> function obj(){<br />
&nbsp;&nbsp;&nbsp;var duration = 3000;<br />
&nbsp;&nbsp;&nbsp;setTimeout(&#8221;exec()&#8221;, duration);<br />
&nbsp;&nbsp;&nbsp;function exec(){<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&#8221;exec&#8221;);<br />
&nbsp;&nbsp;&nbsp;}                <br />
 }<br />
 obj = new obj();</p>
<p>When I execute the code, I get this error:<br />
<img class="alignnone size-full wp-image-1015" title="jserror" src="http://www.ajaxblender.com/wp-content/uploads/2009/11/jserror.gif" alt="jserror" width="350" height="70" /><br />
&#8230;</div>
<p>There are a few ways to call the event, but the most efficient solution to execute setTimeout or setInterval functions in the above code would be to use a non-named function. Below is some quick code for this solution:</p>
<pre class="php">
<span class="phpOperator">.</span>.<span class="phpOperator">.</span>
    <span class="phpKeyword"> var </span>tmFunc <span class="phpOperator">=</span> <span class="phpFunctionKeyword">function</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span> <span class="phpFunction">exec</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpText">;</span> <span class="phpOperator">}</span><span class="phpText">;</span>
     setTimeout<span class="phpOperator">(</span>tmFunc, duration<span class="phpOperator">)</span><span class="phpText">;</span>
     <span class="phpFunctionKeyword">function</span> <span class="phpFunction">exec</span><span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpOperator">{</span>
          alert<span class="phpOperator">(</span><span class="phpString">"<span class="phpFunction">exec</span>"</span><span class="phpOperator">)</span><span class="phpText">;</span>
     <span class="phpOperator">}</span>
<span class="phpOperator">.</span>.<span class="phpOperator">.</span>
</pre>
<p>That&#8217;s it ;) Click the <strong>Demo</strong> button to view this solution in action.</p>
<img src="http://www.ajaxblender.com/?ak_action=api_record_view&id=1014&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.ajaxblender.com/howto-call-settimeout-setinterval-function-in-object.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
