<?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>Jon Rohan &#187; JavaScript</title>
	<atom:link href="http://www.dinnermint.org/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dinnermint.org</link>
	<description>I&#039;m a freelance web developer living in San Francisco. This is my portfolio where I share my work, thoughts, and whatever else.</description>
	<lastBuildDate>Sat, 24 Apr 2010 17:01:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<cloud domain='www.dinnermint.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>JavaScript Classes and Inheritance</title>
		<link>http://www.dinnermint.org/javascript/javascript-classes-and-inheritance/</link>
		<comments>http://www.dinnermint.org/javascript/javascript-classes-and-inheritance/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 17:30:19 +0000</pubDate>
		<dc:creator>Jon Rohan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[javascript basics]]></category>
		<category><![CDATA[object oriented programming]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://www.dinnermint.org/?p=2295</guid>
		<description><![CDATA[Object oriented JavaScript is everywhere today, and its the type of thing that takes a developer from someone tinkering with JavaScript on the path to becoming a JavaScript ninja. In this post I&#8217;m gonna discuss the basics of creating a JavaScript class, and a subclass which inherits methods from the superclass. A JavaScript Class Let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Object oriented JavaScript is everywhere today, and its the type of thing that takes a developer from someone tinkering with JavaScript on the path to becoming a JavaScript ninja. In this post I&#8217;m gonna discuss the basics of creating a JavaScript class, and a subclass which inherits methods from the superclass.</p>
<h3>A JavaScript Class</h3>
<p>Let&#8217;s start out with a basic class. The Person class has one method getName, when you create a new instance of the Person class you will pass in the Person&#8217;s name. </p>
<h4>The Person class</h4>
<p><pre><code>function Person(name) {
&nbsp;&nbsp;this.name = name;
}
Person.prototype.getName = function() {
&nbsp;&nbsp;return this.name;
}
</code></pre></p>
<p>So in the above example I created a Person class with a name attribute and a function to retrieve the name. Now I&#8217;ll create a new person, &#8220;Jon Rohan&#8221;. </p>
<p><pre><code>var p = new Person(&quot;Jon Rohan&quot;);
// output: Jon Rohan
console.log(p.getName());
</code></pre></p>
<p>The <code>p</code> is a new Person with the name &#8220;Jon Rohan&#8221;, when I log to the console the result of p.getName() it returns &#8220;Jon Rohan&#8221;.</p>
<h3>Prototype Chain</h3>
<p>Now we bring in the prototype chain. The chain is like an inheritance chain. Developer inherits &rarr; from Person. So we are defining a Developer as a Person, cause developers are people too. ;-) The developer takes the name attribute like Person, and an array of skills. The first line of the Developer class is to <code>call</code> the Person class. This calls the Person&#8217;s constructor. The Developer class also has a new method getSkills, because a Person is too general to have skills, but as a Developer, there are skills that they have. </p>
<p>We also need to set Developer.prototype to the Person&#8217;s prototype, by creating a new Person. Now we set the Developer&#8217;s constructor to the Developer. And we have successfully created a prototype chain from Developer to Person.</p>
<h4>The Developer Class</h4>
<p><pre><code>function Developer(name, skills) {
&nbsp;&nbsp;Person.call(this, name); // we call the Person constructor since it&#039;s the superclass
&nbsp;&nbsp;this.skills = skills;
&nbsp;&nbsp;this.getSkills = function() {
&nbsp;&nbsp;&nbsp;&nbsp;return this.skills;
&nbsp;&nbsp;};
}
Developer.prototype = new Person();
Developer.prototype.constructor = Developer;
</code></pre></p>
<p>Now we&#8217;ll create a new Developer, with the name &#8220;Jon Rohan&#8221; and skills ["Javascript", "HTML", "CSS"]. When we create the new developer, he&#8217;ll also have the getName method inherited from the Person class, and the getSkills method from the Developer class.</p>
<p><pre><code>var d = new Developer(&quot;Jon Rohan&quot;,[&quot;Javascript&quot;, &quot;HTML&quot;, &quot;CSS&quot;]);
// output: Jon Rohan
console.log(d.getName());
// output: Javascript, HTML, CSS
console.log(d.getSkills().join(&quot;, &quot;)); 
</code></pre></p>
<p>This is the basic ideas behind Object Oriented Programming in JavaScript, I&#8217;ve only really scratched the surface in JavaScript OOP. Check my <a href="http://www.dinnermint.org/feed/">RSS</a> or <a href="http://www.twitter.com/jonrohan">Twitter</a> for new posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dinnermint.org/javascript/javascript-classes-and-inheritance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Geolocation API</title>
		<link>http://www.dinnermint.org/javascript/javascript-geolocation-api/</link>
		<comments>http://www.dinnermint.org/javascript/javascript-geolocation-api/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 00:06:42 +0000</pubDate>
		<dc:creator>Jon Rohan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobile web]]></category>
		<category><![CDATA[safari]]></category>

		<guid isPermaLink="false">http://www.dinnermint.org/?p=2131</guid>
		<description><![CDATA[More and more devices today are connected, to the web and to your location. Some of the most recent browsers and OS&#8217;s have location built in, (eg. mobile safari, snow leopard, FF 3.5, &#8230;). The API doesn&#8217;t care what is updating the location, it just grabs the location from the navigator.geolocation object. Here&#8217;s a closer [...]]]></description>
			<content:encoded><![CDATA[<p>More and more devices today are connected, to the web and to your location. Some of the most recent browsers and OS&#8217;s have location built in, (eg. mobile safari, snow leopard, FF 3.5, &#8230;). </p>
<p>The API doesn&#8217;t care what is updating the location, it just grabs the location from the navigator.geolocation object. Here&#8217;s a closer look at the interface.</p>
<h3>Geolocation interface</h3>
<p><pre><code>interface Geolocation { 
&nbsp;&nbsp;&nbsp;&nbsp;void getCurrentPosition(in PositionCallback successCallback, [Optional] in PositionErrorCallback errorCallback, [Optional] in PositionOptions options);

&nbsp;&nbsp;&nbsp;&nbsp;long watchPosition(in PositionCallback successCallback, [Optional] in PositionErrorCallback errorCallback, [Optional] in PositionOptions options);

&nbsp;&nbsp;&nbsp;&nbsp;void clearWatch(in int watchId);
&nbsp;&nbsp;};

&nbsp;&nbsp;[Callback=FunctionOnly, NoInterfaceObject]
&nbsp;&nbsp;interface PositionCallback {
&nbsp;&nbsp;&nbsp;&nbsp;void handleEvent(in Position position);
&nbsp;&nbsp;};

&nbsp;&nbsp;[Callback=FunctionOnly, NoInterfaceObject]
&nbsp;&nbsp;interface PositionErrorCallback {
&nbsp;&nbsp;&nbsp;&nbsp;void handleEvent(in PositionError error);
&nbsp;&nbsp;};
</code></pre></p>
<p><strong>getCurrentPosition()</strong> &#8211; takes three arguments. The first (required) is the <code>successCallback</code> function which you define to handle the asynchronous call. The second (optional) is the <code>errorCallback</code> function, for when you can&#8217;t be found. The last is <code>PositionOptions</code> object which you can specify <code>Boolean enableHighAccuracy</code>, <code>long timeout</code> and <code>long maximumAge</code>. The function will get the position and pass it to the successCallback function as a position object. </p>
<p><strong>watchPosition()</strong> &#8211; takes the same three arguments as <code>getCurrentPosition</code>. And on the surface it does the same thing as it, with one big exception. <code>watchPosition</code> will call the successCallback every time the position changes. So if you wanted to create a mobile app that follows you walking down the street, this would be the function to use. When called the function returns a unique identifier, which you use to call the last function.</p>
<p><strong>clearWatch()</strong> &#8211; takes one argument, the unique identifier from the watchPosition method. This method will clear the watch timer.</p>
<h3>Demo</h3>
<p>I wrote a small example that will get your lat, long and display it.</p>
<p><pre><code>function getLocation() {
&nbsp;&nbsp;if(navigator.geolocation) {
&nbsp;&nbsp;&nbsp;&nbsp;navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
&nbsp;&nbsp;} else {
&nbsp;&nbsp;&nbsp;&nbsp;noLocation();
&nbsp;&nbsp;}
}

function foundLocation(position) {
&nbsp;&nbsp;var lat = position.coords.latitude;
&nbsp;&nbsp;var long = position.coords.longitude;
&nbsp;&nbsp;$(&quot;#current-location&quot;).replaceWith(&#039;&lt;a id=&quot;current-location&quot; href=&quot;http://maps.google.com/?q=&#039; + lat + &#039;,&#039; + long + &#039;&quot; target=&quot;_blank&quot;&gt;&#039; + lat + &#039;, &#039; + long + &#039;&lt;/a&gt;&#039;);
}

function noLocation() {
&nbsp;&nbsp;$(&quot;#current-location&quot;).text(&#039;Could not find location&#039;);
}
$(&quot;#get-location&quot;).click(getLocation);</code></pre></p>
<p>Disclaimer: I&#8217;ve tested this in Firefox 3.5 on my Mac, and my iPhone mobile Safari.</p>
<p><strong>Coordinates: </strong><span id="current-location">Check location by clicking the button.</span></p>
<p><button id="get-location" type="button">Check My Location</button></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dinnermint.org/javascript/javascript-geolocation-api/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jQuery Auto-growing Textarea Plugin</title>
		<link>http://www.dinnermint.org/javascript/jquery-growing-textbox-plugin/</link>
		<comments>http://www.dinnermint.org/javascript/jquery-growing-textbox-plugin/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 16:56:59 +0000</pubDate>
		<dc:creator>Jon Rohan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.dinnermint.org/?p=2054</guid>
		<description><![CDATA[This is a ui element I created which takes inspiration from facebook's excellent growing textarea. Or at least I believe facebook was one of the first to create this. How it works is when text in typed into the textarea and it becomes longer than the textarea height, then the textarea will grow.]]></description>
			<content:encoded><![CDATA[<p>This is a ui element I created which takes inspiration from facebook&#8217;s excellent growing textarea. Or at least I believe facebook was one of the first to create this.</p>
<p>How it works is when text is typed into the textarea and it becomes longer than the textarea height, then the textarea will grow. I&#8217;m keeping this plugin in a github repository, fork it, clone it <a href="http://github.com/JonRohan/javascript/blob/9260a2bfd422aad895b3bec8444ae32eca0a512e/src/jquery/plugins/jquery.growing-textarea.js">My Javascript Git Repository</a>.</p>
<h3>Demo</h3>
<p><textarea class="ghost_text" placeholder="Type in me and watch me grow..." style="width:750px;"></textarea></p>
<p>The key to making something like this work, is you need to create div element that copies the text from the textarea to the div. The div naturally will grow when it has more text in it. When it does, you get the height of the div element and apply it to the textarea. </p>
<p>Here&#8217;s how you would init the growing text box.</p>
<pre><code>$(&quot;textarea&quot;).growing();</code></pre>
<p>I&#8217;ve also added some options you can pass in, growning({maxHeight:300,minHeight:40,buffer:20}) the max and min height are pretty self explainitory. The buffer is the space below the text in the textarea, if you want an extra line below the currently typing line.</p>
<h3>The Code</h3>
<p>Currently I&#8217;m adding a class to the div called faketextarea so I can style it the same as the textarea. This is important becuase if one element has more padding than the other, then the heights will be messed up. and this plugin won&#8217;t work exactly right.</p>
<p><pre><code>.faketextarea, textarea {
&nbsp;&nbsp;padding: 5px;
&nbsp;&nbsp;border: 1px solid #efefef;
}</code></pre></p>
<p><pre><code>/* Copyright (c) 2009 Jon Rohan (http://dinnermint.org)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Version: 1.0.0
 * Written with jQuery 1.3.2
 */
(function($){
&nbsp;&nbsp;$.fn.growing = function(options){
&nbsp;&nbsp;&nbsp;&nbsp;var settings = $.extend({
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maxHeight: 400,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; minHeight: 40,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buffer: 0
&nbsp;&nbsp;&nbsp;&nbsp;}, options);
&nbsp;&nbsp;&nbsp;&nbsp;return this.each(function(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var textarea = $(this); //cache the textarea
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var minh = textarea.height()&gt;settings.minHeight?textarea.height():settings.minHeight;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var w = parseInt(textarea.width()||textarea.css(&quot;width&quot;)); //get the width of the textarea
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var div = $(&quot;&lt;div class=&#039;faketextarea&#039; style=&#039;position:absolute;left:-10000px;width:&quot; + w + &quot;px;padding:&quot; + textarea.css(&quot;padding&quot;) +&quot;;border:&quot; + textarea.css(&quot;border&quot;) + &quot;;&#039;&gt;&lt;/div&gt;&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;textarea.after(div);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var resizeBox = function(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var html = textarea.val().replace(/(&lt;|&gt;)/g, &#039;&#039;).replace(/n/g,&quot;&lt;br&gt;|&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(html!=div.html()) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;div.html(html);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var h = div.height();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prevh = textarea.height();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var newh = h&lt;=minh?minh:(h&gt;settings.maxHeight?settings.maxHeight:h);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newh += settings.buffer;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(newh&gt;=settings.maxHeight) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;textarea.css(&quot;overflow&quot;,&quot;auto&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;textarea.css(&quot;overflow&quot;,&quot;hidden&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;textarea.css({&quot;height&quot;:newh+&quot;px&quot;});
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;textarea.keydown(resizeBox);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;textarea.keyup(resizeBox);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resizeBox();
&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;};
})(jQuery);</code></pre></p>
<p>Again if you want to keep up with an updated version of this plugin check it out in <a href="http://github.com/JonRohan/javascript/blob/9260a2bfd422aad895b3bec8444ae32eca0a512e/src/jquery/plugins/jquery.growing-textarea.js">My Javascript Git Repository</a>.</p>


<p>Related posts:<ol><li><a href='http://www.dinnermint.org/share/jquery-ghost-text-plugin/' rel='bookmark' title='Permanent Link: jQuery Ghost Textbox plugin'>jQuery Ghost Textbox plugin</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.dinnermint.org/javascript/jquery-growing-textbox-plugin/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>jQuery Ghost Textbox plugin</title>
		<link>http://www.dinnermint.org/share/jquery-ghost-text-plugin/</link>
		<comments>http://www.dinnermint.org/share/jquery-ghost-text-plugin/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 04:55:53 +0000</pubDate>
		<dc:creator>Jon Rohan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Share]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[invisible text]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.dinnermint.org/?p=1794</guid>
		<description><![CDATA[I often work on sites now-a-days that call for "ghost text boxes". This is when a text box is already populated with words when the page loads. And then when the textbox is given focus the text goes away.]]></description>
			<content:encoded><![CDATA[<p>I often work on sites that call for &#8220;ghost text boxes&#8221;. This is when a text box is already populated with words when the page loads. And then when the textbox is given focus the text goes away. Like This</p>
<div style="margin:15px 0;">
<input type="text" class="ghost_text" placeholder="This is Ghost Text"/></div>
<p>I&#8217;ve seen a few ways to do this, explicitly writing a function that switches text, but this is too specific. This means that I&#8217;ll need to re-write this for every ghost text box on the site. Some people will add the functions in the onfocus and onblur attributes on the <code>&lt;input&gt;</code> tag. Same deal&#8230;</p>
<p>So I wrote this plugin to make my life simpler. How it works is, anytime you want a textbox to have ghost text you give it a placeholder attribute and put the ghost text inside. like so</p>
<pre><code>&lt;input type=&quot;text&quot; class=&quot;ghost_text&quot; placeholder=&quot;This is Ghost Text&quot;/&gt;</code></pre>
<p>Then I just setup the ghost text globally.</p>
<pre><code>$(&quot;.ghost_text&quot;).ghostText();</code></pre>
<p>And we&#8217;re done! That was easy.</p>
<p>Here&#8217;s the plugin. It&#8217;s may not be perfect, and there are most likely hundreds of these on the net. But here is my implementation.<br />
<pre><code>/* Copyright (c) 2009 Jon Rohan (http://dinnermint.org)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Version: 1.0.0
 * Written with jQuery 1.3.2
 */
(function($){$.fn.ghostText = function() {
&nbsp;&nbsp;return this.each(function(){
&nbsp;&nbsp;&nbsp;&nbsp;var text = $(this).attr(&quot;placeholder&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;if(text!=&quot;&quot;&amp;&amp;($(this).val()==&quot;&quot;||$(this).val()==text)) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(this).addClass(&quot;disabled&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(this).val(text);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(this).focus(function(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(this).removeClass(&quot;disabled&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($(this).val()==text) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(this).val(&quot;&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(this).blur(function(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($(this).val()==&quot;&quot;) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(this).val(text);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(this).addClass(&quot;disabled&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;});
};})(jQuery)
</code></pre></p>


<p>Related posts:<ol><li><a href='http://www.dinnermint.org/javascript/jquery-growing-textbox-plugin/' rel='bookmark' title='Permanent Link: jQuery Auto-growing Textarea Plugin'>jQuery Auto-growing Textarea Plugin</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.dinnermint.org/share/jquery-ghost-text-plugin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Array.prototype.move2Back</title>
		<link>http://www.dinnermint.org/share/array-prototype-move2back/</link>
		<comments>http://www.dinnermint.org/share/array-prototype-move2back/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 07:03:50 +0000</pubDate>
		<dc:creator>Jon Rohan</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Share]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.dinnermint.org/?p=1715</guid>
		<description><![CDATA[I decided to write a javascript prototype function for the Array class called move2Back. This will move the nth object in the array to the back of the array. For example when I do this. var arr = [1,2,&#34;A&#34;,4,5]; arr.move2Back(2); Then the array becomes: [1,2,4,5,&#34;A&#34;] This is the small javascript function that accomplishes the task. [...]]]></description>
			<content:encoded><![CDATA[<p>I decided to write a javascript prototype function for the Array class called move2Back. This will move the nth object in the array to the back of the array. For example when I do this.<br />
<pre><code>var arr = [1,2,&quot;A&quot;,4,5];
arr.move2Back(2);
</code></pre></p>
<p>Then the array becomes:</p>
<p><code>[1,2,4,5,&quot;A&quot;]</code></p>
<p>This is the small javascript function that accomplishes the task.<br />
<pre><code>/*
 * This function moves the nth member of the array to the end
 */
Array.prototype.move2Back = function(n) {
&nbsp;&nbsp;this.push(this.splice(n,1).pop());
&nbsp;&nbsp;return this;
}
var arr = [&quot;Jani&quot;,&quot;Hege&quot;,&quot;Stale&quot;,&quot;Kai Jim&quot;,&quot;Borge&quot;,&quot;Tove&quot;];
console.log(arr.move2Back(3));
</code></pre></p>


<p>Related posts:<ol><li><a href='http://www.dinnermint.org/share/submit-to-digg/' rel='bookmark' title='Permanent Link: Submit to Digg Bookmarklet'>Submit to Digg Bookmarklet</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.dinnermint.org/share/array-prototype-move2back/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
