<?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>onemoretake &#187; jQuery</title>
	<atom:link href="http://www.onemoretake.com/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.onemoretake.com</link>
	<description></description>
	<lastBuildDate>Fri, 28 Oct 2011 11:39:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A JQuery UI Dropdown List</title>
		<link>http://www.onemoretake.com/2011/04/17/a-better-jquery-ui-combo-box/</link>
		<comments>http://www.onemoretake.com/2011/04/17/a-better-jquery-ui-combo-box/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 06:22:08 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[combobox]]></category>
		<category><![CDATA[jquery ui]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=363</guid>
		<description><![CDATA[In a recent iteration of find.ly that I have been working on, I was asked to create a form that is far removed from the look of standard browser form controls. In particular, the dropdown lists look nothing like the native control and could not be reproduced using only css. This led me to the [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent iteration of <a href="http://find.ly">find.ly</a> that I have been working on, I was asked to create a form that is far removed from the look of standard browser form controls. In particular, the dropdown lists look nothing like the native control and could not be reproduced using only css.</p>
<p>This led me to the <a href="http://jqueryui.com/demos/autocomplete/#combobox">jQuery UI combox</a> which uses the jQuery UI autocomplete control. This worked very nicely except that it is not a dropdown list that users are most used to seeing. As soon as the new form entered QA, I was pinged with a message saying that it was a bit awkward to use and would probably be difficult for users. I couldn&#8217;t disagree with that and this motivated me to try and see if I could make it more like a dropdown list.</p>
<p>After a few hours of head scratching, I am ready to present the first version of my control, which I would say is about 90% faithful to the feel of native control. There are a few things it does not do but I feel I am close enough to release it to the world for criticism. </p>
<p><a href="http://www.onemoretake.com/wp-content/uploads/2011/04/combodemo.htm" target="_blank">Try the demo</a></p>
<p>Here is the code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">widget</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ui.combobox&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        _create<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> self <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span>
				select <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">element</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				selected <span style="color: #339933;">=</span> select.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:selected&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				value <span style="color: #339933;">=</span> selected.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> selected.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span>
				regSearch <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/^[^a-zA-Z0-9]*([a-zA-Z0-9])/i</span><span style="color: #339933;">,</span>
				comboData <span style="color: #339933;">=</span> select.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;option&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #003366; font-weight: bold;">var</span> text <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
							labelHtml <span style="color: #339933;">=</span> self.<span style="color: #660066;">options</span>.<span style="color: #660066;">label</span> <span style="color: #339933;">?</span> self.<span style="color: #660066;">options</span>.<span style="color: #660066;">label</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> text<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//allows list customization</span>
&nbsp;
						<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
							label<span style="color: #339933;">:</span> labelHtml<span style="color: #339933;">,</span>
							value<span style="color: #339933;">:</span> text<span style="color: #339933;">,</span>
							option<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>
						<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #003366; font-weight: bold;">var</span> input <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">input</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;input type='text' /&gt;&quot;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span>select<span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">keydown</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> event <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							<span style="color: #003366; font-weight: bold;">var</span> keyCode <span style="color: #339933;">=</span> $.<span style="color: #660066;">ui</span>.<span style="color: #660066;">keyCode</span><span style="color: #339933;">;</span>
							<span style="color: #000066; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span> event.<span style="color: #660066;">keyCode</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
								<span style="color: #000066; font-weight: bold;">case</span> keyCode.<span style="color: #660066;">PAGE_UP</span><span style="color: #339933;">:</span>
								<span style="color: #000066; font-weight: bold;">case</span> keyCode.<span style="color: #660066;">PAGE_DOWN</span><span style="color: #339933;">:</span>
								<span style="color: #000066; font-weight: bold;">case</span> keyCode.<span style="color: #660066;">UP</span><span style="color: #339933;">:</span>
								<span style="color: #000066; font-weight: bold;">case</span> keyCode.<span style="color: #660066;">DOWN</span><span style="color: #339933;">:</span>
								<span style="color: #000066; font-weight: bold;">case</span> keyCode.<span style="color: #660066;">ENTER</span><span style="color: #339933;">:</span>
								<span style="color: #000066; font-weight: bold;">case</span> keyCode.<span style="color: #660066;">NUMPAD_ENTER</span><span style="color: #339933;">:</span>
								<span style="color: #000066; font-weight: bold;">case</span> keyCode.<span style="color: #660066;">TAB</span><span style="color: #339933;">:</span>
								<span style="color: #000066; font-weight: bold;">case</span> keyCode.<span style="color: #660066;">ESCAPE</span><span style="color: #339933;">:</span>
									<span style="color: #006600; font-style: italic;">//let autocomplete handle these</span>
									<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
								<span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
									<span style="color: #006600; font-style: italic;">//prevent autocomplete doing anything</span>
									event.<span style="color: #660066;">stopImmediatePropagation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
									<span style="color: #006600; font-style: italic;">//only react to [a-zA-Z0-9]</span>
									<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">91</span> <span style="color: #339933;">&amp;&amp;</span> event.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">59</span><span style="color: #009900;">&#41;</span>
										<span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">58</span> <span style="color: #339933;">&amp;&amp;</span> event.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">47</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
										<span style="color: #003366; font-weight: bold;">var</span> str <span style="color: #339933;">=</span> String.<span style="color: #660066;">fromCharCode</span><span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">keyCode</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> currVal <span style="color: #339933;">=</span> input.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> opt<span style="color: #339933;">;</span>
&nbsp;
										<span style="color: #006600; font-style: italic;">//find all options whose first alpha character matches that pressed</span>
										<span style="color: #003366; font-weight: bold;">var</span> matchOpt <span style="color: #339933;">=</span> select.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
											<span style="color: #003366; font-weight: bold;">var</span> test <span style="color: #339933;">=</span> regSearch.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
											<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>test <span style="color: #339933;">&amp;&amp;</span> test.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">&amp;&amp;</span> test<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
										<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
										<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>matchOpt.<span style="color: #660066;">length</span> <span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
										<span style="color: #006600; font-style: italic;">//if there is something selected we need to find the next in the list</span>
										<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>currVal.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
											<span style="color: #003366; font-weight: bold;">var</span> test <span style="color: #339933;">=</span> regSearch.<span style="color: #660066;">exec</span><span style="color: #009900;">&#40;</span>currVal<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
											<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>test <span style="color: #339933;">&amp;&amp;</span> test.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">&amp;&amp;</span> test<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
												<span style="color: #006600; font-style: italic;">//the next one that begins with that letter</span>
												matchOpt.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ix<span style="color: #339933;">,</span> el<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
													<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">selected</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
														<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ix <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;=</span> matchOpt.<span style="color: #660066;">length</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
															opt <span style="color: #339933;">=</span> matchOpt<span style="color: #009900;">&#91;</span>ix <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
														<span style="color: #009900;">&#125;</span>
														<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
													<span style="color: #009900;">&#125;</span>
												<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
											<span style="color: #009900;">&#125;</span>
										<span style="color: #009900;">&#125;</span> 
&nbsp;
										<span style="color: #006600; font-style: italic;">//fallback to the first one that begins with that character</span>
										<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>opt<span style="color: #009900;">&#41;</span>
											opt <span style="color: #339933;">=</span> matchOpt<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
										<span style="color: #006600; font-style: italic;">//select that item</span>
										opt.<span style="color: #660066;">selected</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
										input.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>opt.<span style="color: #660066;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
										<span style="color: #006600; font-style: italic;">//if the dropdown is open, find it in the list</span>
										<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>input.<span style="color: #660066;">autocomplete</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;widget&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:visible&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
											input.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;autocomplete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">widget</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>		
												<span style="color: #003366; font-weight: bold;">var</span> $li <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
												<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$li.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;item.autocomplete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">option</span> <span style="color: #339933;">==</span> opt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
													input.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;autocomplete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">menu</span>.<span style="color: #660066;">activate</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span>$li<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
													<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
												<span style="color: #009900;">&#125;</span>
											<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
										<span style="color: #009900;">&#125;</span>
									<span style="color: #009900;">&#125;</span>
									<span style="color: #006600; font-style: italic;">//ignore all other keystrokes</span>
									<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
									<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
								<span style="color: #009900;">&#125;</span>
					  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">autocomplete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
					    delay<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
					    minLength<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
					    source<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>request<span style="color: #339933;">,</span> response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> response<span style="color: #009900;">&#40;</span>comboData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
					    select<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> ui<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					        ui.<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">option</span>.<span style="color: #660066;">selected</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
					        self._trigger<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;selected&quot;</span><span style="color: #339933;">,</span> event<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
					            <span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">:</span> ui.<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">option</span>
					        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
					    change<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> ui<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>ui.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>					
								<span style="color: #003366; font-weight: bold;">var</span> matcher <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;^&quot;</span> <span style="color: #339933;">+</span> $.<span style="color: #660066;">ui</span>.<span style="color: #660066;">autocomplete</span>.<span style="color: #660066;">escapeRegex</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;$&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;i&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
									valid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
								select.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;option&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
									<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span>matcher<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
										<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">selected</span> <span style="color: #339933;">=</span> valid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
										<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
									<span style="color: #009900;">&#125;</span>
								<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
								<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>valid<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
									<span style="color: #006600; font-style: italic;">// remove invalid value, as it didn't match anything</span>
									$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
									select.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
									input.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;autocomplete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">term</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
									<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
								<span style="color: #009900;">&#125;</span>
							<span style="color: #009900;">&#125;</span>
					    <span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ui-widget ui-widget-content ui-corner-left&quot;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> self.<span style="color: #660066;">button</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;autocompleteopen&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> ui<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						<span style="color: #006600; font-style: italic;">//find the currently selected item and highlight it in the list</span>
						<span style="color: #003366; font-weight: bold;">var</span> opt <span style="color: #339933;">=</span> select.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:selected&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
						input.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;autocomplete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">widget</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>		
							<span style="color: #003366; font-weight: bold;">var</span> $li <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
							<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$li.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;item.autocomplete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">option</span> <span style="color: #339933;">==</span> opt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
								input.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;autocomplete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">menu</span>.<span style="color: #660066;">activate</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span>$li<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
								<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
							<span style="color: #009900;">&#125;</span>
						<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            input.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;autocomplete&quot;</span><span style="color: #009900;">&#41;</span>._renderItem <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>ul<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;li&gt;&lt;/li&gt;&quot;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;item.autocomplete&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;a href='#'&gt;&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">label</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/a&gt;&quot;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>ul<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">button</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;button type='button'&gt;&amp;nbsp;&lt;/button&gt;&quot;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tabIndex&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;title&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;Show All Items&quot;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span>input<span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">button</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
					    icons<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
					        primary<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;ui-icon-triangle-1-s&quot;</span>
					    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
					    text<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
					<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ui-corner-all&quot;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ui-corner-right ui-button-icon&quot;</span><span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					    <span style="color: #006600; font-style: italic;">// close if already visible</span>
					    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>input.<span style="color: #660066;">autocomplete</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;widget&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:visible&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					        input.<span style="color: #660066;">autocomplete</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;close&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					        <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
					    <span style="color: #009900;">&#125;</span>
&nbsp;
					    <span style="color: #006600; font-style: italic;">// pass empty string as value to search for, displaying all results</span>
					    input.<span style="color: #660066;">autocomplete</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;search&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					    input.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//allows programmatic selection of combo using the option value</span>
        setValue<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> $input <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">input</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;option&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">element</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">selected</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                    $input.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
        destroy<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">input</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">button</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">element</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $.<span style="color: #660066;">Widget</span>.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">destroy</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The particular functions I tried to add are:</p>
<ul>
<li>Removal of any standard textbox typing characteristics</li>
<li>Typing in the textbox jumps to the item begining with that letter</li>
<li>Hitting the same letter continuously cycles through the items beginning with that letter</li>
<li>Programatically select an item using the value</li>
<li>Retain navigation through list via arrow keys/paging</li>
<li>Opening the list jumps to the selected item</li>
</ul>
<p>Feel free to take it and use it but I am very keen on any improvements that can be made, so please let me know what you think. </p>
<p>I know that performance is a bit of a problem with large lists but stopping autocomplete from rebuilding the list each time it is displayed is a little tricky and would mean changing more of it&#8217;s private functions &#8211; something I was hoping to avoid. Suggestions welcome.</p>
<p>*Edit: I totally had my terminology messed up. I was calling my control a combobox which it absolutely isnt. It is a dropdown list, so I have updated the post to reflect that. *places dunce hat on*</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2011/04/17/a-better-jquery-ui-combo-box/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>AjaxQueue and jQuery 1.3</title>
		<link>http://www.onemoretake.com/2009/10/11/ajaxqueue-and-jquery-1-3/</link>
		<comments>http://www.onemoretake.com/2009/10/11/ajaxqueue-and-jquery-1-3/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 07:43:23 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajaxqueue]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=291</guid>
		<description><![CDATA[The website that I work on for the majority of my time had been running on the rather out of date jQuery 1.2 for quite some time. I recently found myself with a little bit of downtime and decided it was a good time to see if we could upgrade and take advantage of all [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.onemoretake.com/wp-content/uploads/2009/10/800pxQueue_algorithmn.jpg"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 25px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="800px-Queue_algorithmn" border="0" alt="800px-Queue_algorithmn" align="left" src="http://www.onemoretake.com/wp-content/uploads/2009/10/800pxQueue_algorithmn_thumb.jpg" width="244" height="106" /></a> The website that I work on for the majority of my time had been running on the rather out of date jQuery 1.2 for quite some time. I recently found myself with a little bit of downtime and decided it was a good time to see if we could upgrade and take advantage of all the speed improvements that the latest version gives us.</p>
<p>On the most part, the upgrade was fairly painless. Most things worked without change but one particular plug-in did not &#8211; <a href="http://plugins.jquery.com/project/ajaxqueue" target="_blank">AjaxQueue</a>. This is a great little control that acts as an add-on to the <a href="http://docs.jquery.com/Ajax" target="_blank">ajax method of jQuery</a>, allowing a little more control over how concurrent calls are processed. It gives three modes of operation but for us, the most useful of these are abort and queue and from the names it is fairly obvious what they do.</p>
<p>After I upgraded to jQuery 1.3, it did not take me long to realise that the queue mode was broken. I briefly looked around for an alternative plug-in but found that all of them would require too much change to our existing controls. There was no alternative, I had to open up the hood of AjaxQueue and see what had gone wrong.</p>
<p>What I found was that there must of been a change to a method that the plug-in relied on – a method that it seemed, only became publicly available in version 1.3 – <a href="http://docs.jquery.com/Core/queue" target="_blank">queue</a>. Although the function was similar, the conclusion that I came to was that prior to version 1.3, the queue function automatically de-queued any function added and processed it. When using the latest jQuery, the ajax calls were queued but there was no code to start the processing of the queue. </p>
<p>It was slightly more complex I thought it would be to get it going &#8211; I had to ensure the queue was only started once. I finally came up with a solution and a newly revived plug-in, the code of which is below. As the original plugin has not been touched for quite some time (2007), I thought it ok to post my modified version here.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> ajax <span style="color: #339933;">=</span> $.<span style="color: #660066;">ajax</span><span style="color: #339933;">,</span>
        pendingRequests <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
        synced <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        syncedData <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
        ajaxRunning <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    $.<span style="color: #660066;">ajax</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>settings<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// create settings for compatibility with ajaxSetup</span>
        settings <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>settings<span style="color: #339933;">,</span> jQuery.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> jQuery.<span style="color: #660066;">ajaxSettings</span><span style="color: #339933;">,</span> settings<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> port <span style="color: #339933;">=</span> settings.<span style="color: #660066;">port</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>settings.<span style="color: #660066;">mode</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;abort&quot;</span><span style="color: #339933;">:</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pendingRequests<span style="color: #009900;">&#91;</span>port<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    pendingRequests<span style="color: #009900;">&#91;</span>port<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">abort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">return</span> pendingRequests<span style="color: #009900;">&#91;</span>port<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> ajax.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;queue&quot;</span><span style="color: #339933;">:</span>
                <span style="color: #003366; font-weight: bold;">var</span> _old <span style="color: #339933;">=</span> settings.<span style="color: #660066;">complete</span><span style="color: #339933;">;</span>
                settings.<span style="color: #660066;">complete</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>_old<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        _old.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>ajax<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">queue</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajax&quot;</span> <span style="color: #339933;">+</span> port<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        jQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>ajax<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dequeue</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajax&quot;</span> <span style="color: #339933;">+</span> port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                        ajaxRunning<span style="color: #009900;">&#91;</span>port<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
                jQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>ajax<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">queue</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajax&quot;</span> <span style="color: #339933;">+</span> port<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    ajax<span style="color: #009900;">&#40;</span>settings<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>ajax<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">queue</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajax&quot;</span> <span style="color: #339933;">+</span> port<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>ajaxRunning<span style="color: #009900;">&#91;</span>port<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    ajaxRunning<span style="color: #009900;">&#91;</span>port<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                    jQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>ajax<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dequeue</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajax&quot;</span> <span style="color: #339933;">+</span> port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
                <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;sync&quot;</span><span style="color: #339933;">:</span>
                <span style="color: #003366; font-weight: bold;">var</span> pos <span style="color: #339933;">=</span> synced.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
&nbsp;
                synced<span style="color: #009900;">&#91;</span>pos<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                    error<span style="color: #339933;">:</span> settings.<span style="color: #660066;">error</span><span style="color: #339933;">,</span>
                    success<span style="color: #339933;">:</span> settings.<span style="color: #660066;">success</span><span style="color: #339933;">,</span>
                    complete<span style="color: #339933;">:</span> settings.<span style="color: #660066;">complete</span><span style="color: #339933;">,</span>
                    done<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
                <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
                syncedData<span style="color: #009900;">&#91;</span>pos<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                    error<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
                    success<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
                    complete<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
                settings.<span style="color: #660066;">error</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> syncedData<span style="color: #009900;">&#91;</span>pos<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">error</span> <span style="color: #339933;">=</span> arguments<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
                settings.<span style="color: #660066;">success</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> syncedData<span style="color: #009900;">&#91;</span>pos<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">success</span> <span style="color: #339933;">=</span> arguments<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
                settings.<span style="color: #660066;">complete</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    syncedData<span style="color: #009900;">&#91;</span>pos<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">complete</span> <span style="color: #339933;">=</span> arguments<span style="color: #339933;">;</span>
                    synced<span style="color: #009900;">&#91;</span>pos<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">done</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pos <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>synced<span style="color: #009900;">&#91;</span>pos <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
                        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> pos<span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> synced.<span style="color: #660066;">length</span> <span style="color: #339933;">&amp;&amp;</span> synced<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">done</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>synced<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">error</span><span style="color: #009900;">&#41;</span> synced<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">error</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #339933;">,</span> syncedData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>synced<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">success</span><span style="color: #009900;">&#41;</span> synced<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">success</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #339933;">,</span> syncedData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">success</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>synced<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">complete</span><span style="color: #009900;">&#41;</span> synced<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">complete</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #339933;">,</span> syncedData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">complete</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                        synced<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
                        syncedData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> ajax.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/10/11/ajaxqueue-and-jquery-1-3/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Cuesheet Maker Bookmarklet for Discogs.com</title>
		<link>http://www.onemoretake.com/2009/09/18/cuesheet-maker-bookmarklet-for-discogs-com/</link>
		<comments>http://www.onemoretake.com/2009/09/18/cuesheet-maker-bookmarklet-for-discogs-com/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 01:52:30 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=268</guid>
		<description><![CDATA[Yesterday I discovered I had a few albums that had been ripped as a single track. I prefer having individual tracks and usually head on over to cuesheet heaven to look for the appropriate file that allows me to split them up with the awesome Medieval Cue Splitter. However I had a few tracks that [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I discovered I had a few albums that had been ripped as a single track. I prefer having individual tracks and usually head on over to <a href="http://www.regeert.nl/cuesheet/" target="_blank">cuesheet heaven</a> to look for the appropriate file that allows me to split them up with the awesome <a href="http://www.medieval.it/content/view/28/70/" target="_blank">Medieval Cue Splitter</a>. However I had a few tracks that had I could not find the appropriate cuesheet file for. I find myself in this situation fairly regularly and have also noticed that these albums usually have an entry at <a href="http://www.discogs.com/" target="_blank">discogs.com</a>, which has all the details including track lengths.</p>
<p>This got me thinking that it would be awesome to be able to create cue files from discogs.com. So I created the following – a bookmarklet to do just that.</p>
<p><strong>Disclaimer:</strong> it is pretty rough and I cannot guarantee that it will work with all discogs.com entries and there is hardly any error checking. I have only used this in Firefox so I cannot guarantee it will work in any other browser. It only pops up a dialogue with the cuesheet contents on it but that was adequate for me to copy and paste it into a text file and tweak it so that it was a valid cuesheet.</p>
<p>The important thing is that it gathers the track names and artists and works out the index times. It also attempts to cope with double cds and also single tracks that are two different records playing at once (common with DJ mixes). Here is the bookmarklet (drag it into your bookmarks tookbar), followed by the code itself:</p>
<p>Drag this to your bookmark toolbar: <a href="javascript:(function(){var a=document.createElement(%27SCRIPT%27);a.type=%27text/javascript%27;a.src=%27http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js%27;a.onload=function(){var h=jQuery.trim(jQuery(%27div.profile h1%27).text()),g=jQuery.trim(h.substring(0,h.indexOf(%27-%27))),d=h+%27.mp3%27,i=0,b=0,e=[],j=1;h=jQuery.trim(h.substring(h.indexOf(%27-%27)+1));tracks=[];jQuery(%27div.tracklist .section_content > table tr%27).each(function(n,p){var q=jQuery.trim(jQuery(%27td.track_pos%27,this).text());if(q&#038;&#038;q!=%27%27){var m={},l=[],o=false;q=q.split(%27-%27);if(q.length>1){if(jQuery.trim(q[0])!=j){k();j=q[0]}else{if(parseInt(q[1])==b){o=true}}}if(!o){b+=1;m.trackno=b;m.artist=jQuery.trim(jQuery(%27td.track_artists%27,this).text()).replace(/\s-$/g,%27%27).replace(/\n/g,%27%27).replace(/\s+/g,%27 %27);m.artist=jQuery.trim(m.artist);m.artist=(m.artist==%27%27)?g:m.artist;m.title=jQuery.trim(jQuery(%27td.track%27,this).text());l=jQuery.trim(jQuery(%27td.track_duration%27,this).text()).split(%27:%27);m.index=f(i);i+=(l[0]*60)+(l[1]*1);tracks[tracks.length]=m}}});k();var c=%27%27;jQuery.each(e,function(m,l){c+=l+%27\n\n\n%27});alert(c);function k(){var m=unescape(%27%22%27),l=%27TITLE %27+m+h+m+%27\n%27;l+=%27PERFORMER %27+m+g+m+%27\n%27;l+=%27FILE %27+m+d+m+%27 MP3\n%27;jQuery.each(tracks,function(o,n){l+=%27  TRACK %27+n.trackno+%27 AUDIO\n%27;l+=%27    TITLE %27+m+n.title+m+%27\n%27;l+=%27    PERFORMER %27+m+n.artist+m+%27\n%27;l+=%27    INDEX 01 %27+m+n.index+m+%27\n%27});e[e.length]=l;i=0;b=0;tracks=[]}function f(l){var m=Math.floor(l/60),n=(l-(m*60));if(m<10){m=%270%27+m.toString()}if(n<10){n=%270%27+n.toString()}return m.toString()+%27:%27+n.toString()+%27:00%27}};document.getElementsByTagName(%27head%27)[0].appendChild(a)})();">Create Cue</a>
<p>The code itself:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">var</span> s<span style="color: #339933;">=</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'SCRIPT'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
s.<span style="color: #660066;">type</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">;</span>
s.<span style="color: #660066;">src</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js'</span><span style="color: #339933;">;</span>
s.<span style="color: #000066;">onload</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> title <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.profile h1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		performer <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span>title.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>title.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		file <span style="color: #339933;">=</span> title <span style="color: #339933;">+</span> <span style="color: #3366CC;">'.mp3'</span><span style="color: #339933;">,</span> secCount <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> trkCount <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> cues <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> cdNo <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
	title <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span>title.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>title.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	tracks <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.tracklist .section_content &gt; table tr'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ix<span style="color: #339933;">,</span> el<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> trackCd <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'td.track_pos'</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>trackCd <span style="color: #339933;">&amp;&amp;</span> trackCd <span style="color: #339933;">!=</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> track <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> tracktime <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> isDouble <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			trackCd <span style="color: #339933;">=</span> trackCd.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>trackCd.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>jQuery.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span>trackCd<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> cdNo<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					createCue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					cdNo <span style="color: #339933;">=</span> trackCd<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>parseInt<span style="color: #009900;">&#40;</span>trackCd<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> trkCount<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						isDouble <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isDouble<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				trkCount<span style="color: #339933;">+=</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
				track<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'trackno'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> trkCount<span style="color: #339933;">;</span>
				track<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'artist'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'td.track_artists'</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\s-$/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\n/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\s+/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				track<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'artist'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span>track<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'artist'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				track<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'artist'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>track<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'artist'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> performer <span style="color: #339933;">:</span> track<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'artist'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				track<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'td.track'</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
				tracktime <span style="color: #339933;">=</span>jQuery.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'td.track_duration'</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
				track<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'index'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> secondsToMinSec<span style="color: #009900;">&#40;</span>secCount<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				secCount <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>tracktime<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>tracktime<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				tracks<span style="color: #009900;">&#91;</span>tracks.<span style="color: #660066;">length</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> track<span style="color: #339933;">;</span>	
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	createCue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//print it out</span>
	<span style="color: #003366; font-weight: bold;">var</span> output <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	jQuery.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>cues<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ix<span style="color: #339933;">,</span> cue<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		output <span style="color: #339933;">+=</span> cue <span style="color: #339933;">+</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> createCue<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> quo <span style="color: #339933;">=</span> unescape<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'%22'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			cue <span style="color: #339933;">=</span> <span style="color: #3366CC;">'TITLE '</span><span style="color: #339933;">+</span>quo<span style="color: #339933;">+</span>title<span style="color: #339933;">+</span>quo<span style="color: #339933;">+</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
		cue <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'PERFORMER '</span><span style="color: #339933;">+</span>quo<span style="color: #339933;">+</span>performer<span style="color: #339933;">+</span>quo<span style="color: #339933;">+</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
		cue <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'FILE '</span><span style="color: #339933;">+</span>quo<span style="color: #339933;">+</span>file<span style="color: #339933;">+</span>quo<span style="color: #339933;">+</span><span style="color: #3366CC;">' MP3<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
		jQuery.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>tracks<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>ix<span style="color: #339933;">,</span> track<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			cue <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'  TRACK '</span><span style="color: #339933;">+</span>track.<span style="color: #660066;">trackno</span><span style="color: #339933;">+</span><span style="color: #3366CC;">' AUDIO<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
			cue <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'    TITLE '</span><span style="color: #339933;">+</span>quo<span style="color: #339933;">+</span>track.<span style="color: #660066;">title</span><span style="color: #339933;">+</span>quo<span style="color: #339933;">+</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
			cue <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'    PERFORMER '</span><span style="color: #339933;">+</span>quo<span style="color: #339933;">+</span>track.<span style="color: #660066;">artist</span><span style="color: #339933;">+</span>quo<span style="color: #339933;">+</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
			cue <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'    INDEX 01 '</span><span style="color: #339933;">+</span>quo<span style="color: #339933;">+</span>track.<span style="color: #660066;">index</span><span style="color: #339933;">+</span>quo<span style="color: #339933;">+</span><span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		cues<span style="color: #009900;">&#91;</span>cues.<span style="color: #660066;">length</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> cue<span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">//reset</span>
		secCount <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> trkCount <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> tracks <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> secondsToMinSec<span style="color: #009900;">&#40;</span>totsec<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> min <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>totsec <span style="color: #339933;">/</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
			sec <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>totsec <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>min <span style="color: #339933;">*</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>min <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			min <span style="color: #339933;">=</span> <span style="color: #3366CC;">'0'</span> <span style="color: #339933;">+</span> min.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sec <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			sec <span style="color: #339933;">=</span> <span style="color: #3366CC;">'0'</span> <span style="color: #339933;">+</span> sec.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">return</span> min.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">':'</span> <span style="color: #339933;">+</span> sec.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">':00'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'head'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I hope this helps some people, as it has me. Feel free to improve on it but if you make any changes, please let me know so that I can improve my version too.</p>
<p>Enjoy</p>
<p><strong>Edit:</strong> Well it was not long until discogs changed their layout. I have update the code to reflect this. All should be well again.</p>
<p><strong>Edit2:</strong> Bjørn Tore pointed out the titles were not being picked up. I have fixed this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/09/18/cuesheet-maker-bookmarklet-for-discogs-com/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Facebook-Style Expanding Textboxes With jQuery</title>
		<link>http://www.onemoretake.com/2009/05/29/facebook-style-expanding-textboxes-with-jquery/</link>
		<comments>http://www.onemoretake.com/2009/05/29/facebook-style-expanding-textboxes-with-jquery/#comments</comments>
		<pubDate>Sat, 30 May 2009 00:03:44 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javacript]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=257</guid>
		<description><![CDATA[I was recently asked to create a textbox that would vertically expand depending on how much was written in it. This style of text box can be seen in the Facebook news feed for writing comments under peoples feed items. When I receive this type of request, I usually begin by researching what existing systems [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.onemoretake.com/wp-content/uploads/2009/05/characters.png"><img title="Characters" style="border-right: 0px; border-top: 0px; display: inline; margin: 0px 15px 10px 0px; border-left: 0px; border-bottom: 0px" height="123" alt="Characters" src="http://www.onemoretake.com/wp-content/uploads/2009/05/characters-thumb.png" width="186" align="left" border="0" /></a> I was recently asked to create a textbox that would vertically expand depending on how much was written in it. This style of text box can be seen in the Facebook news feed for writing comments under peoples feed items. When I receive this type of request, I usually begin by researching what existing systems and plug-ins are out there, investigate the different approaches people take and then write my own based on which way I think best. </p>
<p>Firstly, a textbox (input type=text) is the wrong element to be using. It cannot be any larger than a single line, so a text area element needs to be used. As a text area element will not automatically expand by itself, the general approach to this problem is to use a hidden ‘staging’ element placed way off the viewable screen. The text entered into the text area is copied across to the staging element, which expands as needed and the resulting height used to resize the text area. It is not a difficult thing to achieve with <a href="http://www.jquery.com" target="_blank">jQuery</a> and the basic structure of the plug-in can be made in relatively few lines of code.</p>
<p>There are a few things to watch out for however. Firstly, because we are taking the contents of a text area and placing it in a div, we need to watch out for special characters that need encoding before they will render correctly. Primarily the newline character but we also have to watch out for the other special characters that can cause issues. Nothing that cannot be fixed with regular expressions. The other thing that we need to be careful of is the CSS styles that have been applied to the text area. We require that the hidden element perfectly mimic the text area and that the text wraps at the same point. If it does not, we will incorrectly predict when the text area needs to grow. The font size and family, line height and padding need to be copied.</p>
<p>This would normally be the point that I post the code, but after I started writing the plug-in, I stumbled across an existing one that I could just not improve upon and decided to use it in it’s entirety. Its by a guy called <a href="http://onehackoranother.com/" target="_blank">Jason Frame</a> and his plug-in can be found on <a href="http://github.com/jaz303/jquery-grab-bag/blob/master/javascripts/jquery.autogrow-textarea.js" target="_blank">github</a>. For my particular implementation, I added the facility to have watermark text in it by utilising the great <a href="http://digitalbush.com/projects/watermark-input-plugin/" target="_blank">plugin over on digital bush</a> and I also added some text parsing requirements that were required for the particular project.</p>
<p>Now for a word of warning. There are some problems with this approach, which I have not managed to solve (and incidentally, nor have Facebook). The text area element renders it’s content slightly differently in every browser. In the hidden element, the text will sit up directly against the edge of the div but in a text area it may not. I suspect this gap also varies from operating system to operating system but as far as I can tell, you cannot eliminate it with styles. The consequence of this is that predicting precisely when the text area needs resizing becomes very difficult. The only thing to do is to accommodate this margin of error. This can be done by making the text area display slightly taller than a single line and to always have an extra line available. That way, if things go slightly off, it is still usable. You can see this problem if you put a significant amount of dummy text into the text area and watch when it expands as you type. Instead of expanding when you reach a new line it happens at a different place. If any one manages to figure out how to completely eliminate this problem I am eager to hear how.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/05/29/facebook-style-expanding-textboxes-with-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Importance of a Good jQuery Selector</title>
		<link>http://www.onemoretake.com/2009/03/18/the-importance-of-a-good-jquery-selector/</link>
		<comments>http://www.onemoretake.com/2009/03/18/the-importance-of-a-good-jquery-selector/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 06:36:13 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[javacript]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=168</guid>
		<description><![CDATA[As a technical lead and working in a company that has had rapid expansion in the last six months or so, I have had the job of being a mentor to some of the new employees. I don&#8217;t think any of them had used jQuery before and so for every person that arrived, I needed [...]]]></description>
			<content:encoded><![CDATA[<p>As a technical lead and working in a company that has had rapid expansion in the last six months or so, I have had the job of being a mentor to some of the new employees. I don&#8217;t think any of them had used jQuery before and so for every person that arrived, I needed to give a crash course on the subject. The jQuery selector is always one of the first things I describe and it is usually met with nods of understanding, as it is not a difficult concept to grasp when most developers are familiar with css and the DOM.</p>
<p>There have been two incidents recently however, that have made me realise that my crash course on jQuery selectors has been missing something vital. The first was when I found some time to explore the options of profiling some of our javascript code. When I first started this, the only option I could see was <a href="http://ejohn.org/blog/deep-profiling-jquery-apps/">John Resig&#8217;s deep profiling script</a> that injected the statistics at the bottom of the page. This had some limitations however, and I was very happy to open my news feeds soon after and find that he had added a couple of extra methods to <a href="http://fireunit.org/">FireUnit</a> that enabled you to <a href="http://ejohn.org/blog/function-call-profiling/">profile javascript function calls</a>.</p>
<p>What I noticed straight away was that there were a lot of seemingly simple calls in our code that took a long time to execute. The reason for this was that the selectors were vague:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.myclass'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">somefunction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In order to find all the matches, even if there is only one, jQuery needs to traverse the entire DOM looking for any element that might have the matching class, and that takes time. By narrowing down the selector using, for instance, the type, jQuery can very quickly eliminate all other types. This speeds things up a lot.</p>
<p>The second incident was due to another &#8216;benefit&#8217; of being a tech lead. I tend to get passed the most peculiar and hard to diagnose bugs. The bug in question was on a page that contained two autocomplete text boxes, one of which was part of a compound control. The bug manifested itself by not being able to select an item from the second autocomplete text box properly. I was handed the bug with the information that it seemed to happen only when you selected from the first autocomplete control first. Needless to say, there was a lot of poking around in the code of both the autocomplete and the compound control, which is particularly complex given the nature of the control.</p>
<p>Thanks to <a href="http://www.getfirebug.com/">firebug</a>&#8216;s great console logging, I discovered that the variable that contained all the autocomplete list items seemed to be a combination of both controls. It was not too long before i discovered the code that caused the problem:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">    listitems <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.auto'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>There was nothing mysterious going on at all, jQuery was asked to select all of list items in both controls, so it did.</p>
<p>What had happened in both of these incidents is that I had failed to mention the importance of an accurate selector in jQuery during my crash course. The new developers were blissfully unaware of the consequences of not specifying <strong>exactly</strong> which elements you want jQuery to select. What I had also failed to emphasise was another way of narrowing down and speeding up the jQuery selection &#8211; by use of the elements that you already have. In the case of the autocomplete, we already had a reference to the list itself, so it was simple:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">   listitems <span style="color: #339933;">=</span> thelist.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This not only eliminated the cross-contamination of the two controls but seeded things up. So the rules to keep things fast and to save me headaches are simple:</p>
<ul>
<li>Use a selector that very accurately matches the elements you require</li>
<li>Utilise references to elements you already have</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/03/18/the-importance-of-a-good-jquery-selector/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery Plugin Callbacks and Events</title>
		<link>http://www.onemoretake.com/2009/03/04/jquery-plugin-callbacks-and-events/</link>
		<comments>http://www.onemoretake.com/2009/03/04/jquery-plugin-callbacks-and-events/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 22:33:12 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javacript]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=127</guid>
		<description><![CDATA[I have written a fair few plugins for jQuery for both work and side projects. As any developer should, I am always trying to improve my techniques for creating them so that they are as efficient and maintainable as possible. Up until recently, my usual technique for callbacks and events would be to include the [...]]]></description>
			<content:encoded><![CDATA[<p>I have written a fair few plugins for jQuery for both work and side projects. As any developer should, I am always trying to improve my techniques for creating them so that they are as efficient and maintainable as possible.<br />
Up until recently, my usual technique for callbacks and events would be to include the function in the options that you pass in. For instance, you would setup you plugin as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">myPlugin</span><span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> settings <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            setting1<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
            setting2<span style="color: #339933;">:</span> <span style="color: #3366CC;">''</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">//overload default settings</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> jQuery.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>settings<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        .....</pre></td></tr></table></div>

<p>This would allow you to pass in any number of settings, including callbacks to utilise at runtime:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#myselector'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">myPlugin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> 
        setting1<span style="color: #339933;">:</span><span style="color: #CC0000;">1234</span><span style="color: #339933;">,</span> 
        setting2<span style="color: #339933;">:</span><span style="color: #3366CC;">'somesetting'</span><span style="color: #339933;">,</span>
        callback1<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Yesterday it occurred to me that jQuery had a neat feature that is much better than doing this &#8211; custom event binding. jQuery not only allows you to bind the DOM events to elements such as click, focus, keydown etc but because of the way it stores all the bindings, you can bind any number of custom events as well. This means that you can set your events for the plugin as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#myselector'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">myPlugin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> 
        setting1<span style="color: #339933;">:</span><span style="color: #CC0000;">1234</span><span style="color: #339933;">,</span> 
        setting2<span style="color: #339933;">:</span><span style="color: #3366CC;">'somesetting'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;mycallbackevent&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>...<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Within your plugin you would need to trigger that event like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">trigger</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;mycallbackevent&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>somedata<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This technique also provides a neater alternative to public functions on your plugin. Say you wanted to initialise the plugin when a link is clicked. I would have previously setup a public function in the plugin to do this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">init</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> .. <span style="color: #009900;">&#125;</span></pre></div></div>

<p>and then run it as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'pluginselector'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>With custom events you would setup the event inside the plugin as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'init'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> .. <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>and run as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'pluginselector'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">trigger</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'init'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Perhaps I have just been writing plugins incorrectly all this time but that seems much better to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/03/04/jquery-plugin-callbacks-and-events/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery Inline Confirm</title>
		<link>http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/</link>
		<comments>http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 02:58:58 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javacript]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=111</guid>
		<description><![CDATA[I have been using Delicious social bookmarking service ever since Blinklist degraded and finally lost the plot with their new design. When I first started using Delicious, a feature of their interface really leapt out at me and I could not wait to include it into a project. The feature I am talking about is [...]]]></description>
			<content:encoded><![CDATA[<p>I have been using <a href="http://www.delicious.com/">Delicious</a> social bookmarking service ever since <a href="http://www.blinklist.com/">Blinklist </a> degraded and finally lost the plot with their new design. When I first started using Delicious, a feature of their interface really leapt out at me and I could not wait to include it into a project.<br />
The feature I am talking about is their inline confirmation. That is, when you, for instance, delete a bookmark by clicking on the delete link, the link is replaced with an &#8216;Are You Sure? Yes/Cancel&#8217; message. </p>
<p><img src="http://www.onemoretake.com/wp-content/uploads/2009/03/inlineconfirmbefore.jpg" alt="Inline Confirm - Before" title="Inline Confirm - Before" width="366" height="49" class="size-full wp-image-116" /></p>
<p><img src="http://www.onemoretake.com/wp-content/uploads/2009/03/inlineconfirmafter.jpg" alt="Inline Confirm - After" title="Inline Confirm - After" width="367" height="46" class="size-full wp-image-115" /></p>
<p>I really liked this as there was no page refresh for the confirmation message and it was not a modal popup, which is a little obtrusive at best. It also occurred to me that something like that would not require a huge amount of code either. This is what I came up with:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">inlineconfirm</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span> callback<span style="color: #339933;">,</span> parentSel<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> hideEl <span style="color: #339933;">=</span> parentSel <span style="color: #339933;">?</span> $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span>parentSel<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        hideEl.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;confirm&quot;&gt;Are you sure? &lt;a class=&quot;confirmyes&quot; href=&quot;#&quot;&gt;Yes&lt;/a&gt; &lt;span&gt;|&lt;/span&gt; &lt;a class=&quot;confirmcancel&quot; href=&quot;#&quot;&gt;Cancel&lt;/a&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.confirmyes'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> callback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> hideEl.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.confirm:first'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.confirmcancel'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> hideEl.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.confirm:first'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #660066;">insertAfter</span><span style="color: #009900;">&#40;</span>hideEl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>I decided on using just a function rather than a plugin, as I wanted asp.net control compatibility (see later).  The function just swaps out the element(s) for the confirmation message and puts them back if cancel is pressed, otherwise it runs the callback. It utilises three parameters: </p>
<ul>
<li><strong>el</strong> &#8211; The element which initiates the inline confirm. i.e. The link</li>
<li><strong>callback</strong> &#8211; A function to run if the answer is Yes</li>
<li><strong>parentSel</strong> &#8211; (optional) This is a jquery selector that identifies a parent element of <strong>el</strong> that will be replaced with the prompt. This is so that you could for instance hide an entire section of html with the &#8216;are you sure?&#8217; prompt. Particularly useful to keep layouts consistent.</li>
</ul>
<p>This is a nice easy function to use in most web development language, however, if you are using asp.net, it becomes difficult to use it with the asp controls like &lt;asp:Button /&gt; or &lt;asp:LinkButton /&gt;. This is because ASP.NET likes to take control of the click events of these so that it can create its event model at the server. There is the onClientClick property which allows us to have some control over the click event but we need to pass a callback function. After a little investigating, I discovered the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.getpostbackeventreference(VS.80).aspx">GetPostBackEventReference</a> function:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">mylinkbutton.<span style="color: #0000FF;">OnClientClick</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;$.inlineconfirm(this,function() {&quot;</span> <span style="color: #008000;">&amp;</span> ClientScript.<span style="color: #0000FF;">GetPostBackEventReference</span><span style="color: #000000;">&#40;</span>mylinkbutton, <span style="color: #808080;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;;});return false;&quot;</span></pre></div></div>

<p>The GetPostBackEventReference returns a string of the function that will be used to invoke the postback. Just what we needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/03/02/jquery-inline-confirm/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The Technical Debt</title>
		<link>http://www.onemoretake.com/2009/02/26/the-technical-debt/</link>
		<comments>http://www.onemoretake.com/2009/02/26/the-technical-debt/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 20:39:47 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[refactoring]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=16</guid>
		<description><![CDATA[I have spent the last few days at work doing some intense refactoring of a seemingly complex jQuery plug-in. I managed to cut it down by 140 lines and speed it up immensely. Whilst it would have saved time if I had written the plug-in myself in the first place, I cannot be expected to [...]]]></description>
			<content:encoded><![CDATA[<p>I have spent the last few days at work doing some intense refactoring of a seemingly complex jQuery plug-in. I managed to cut it down by 140 lines and speed it up immensely. Whilst it would have saved time if I had written the plug-in myself in the first place, I cannot be expected to do everything and nobody else at work would improve their jQuery and javascript writing skills if I did so. I therefore label my time spent as paying of some of the technical debt that we create, in the process of releasing the software as quickly as we can. If you have not come across this metaphor before, here it is:</p>
<p><a href="http://www.youtube.com/watch?v=pqeJFYwnkjE">www.youtube.com/watch?v=pqeJFYwnkjE</a></p>
<p>It really nails the reason that as developers, we try to refactor regularly. Unfortunately refactoring is not something that people outside of the development community tend to understand and it is considered a waste of time all too often. I think use of this metaphor may just help those people understand.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/02/26/the-technical-debt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorting Elements with jQuery</title>
		<link>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/</link>
		<comments>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 23:32:59 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sorting]]></category>

		<guid isPermaLink="false">http://www.onemoretake.com/?p=11</guid>
		<description><![CDATA[Whilst refactoring a jQuery plugin today, I came across a method that placed a list item into an unordered list at a specific point, so that all the items remained in alphabetic order. This long method seemed completely convoluted and slow to me and I decided that there must be an easier way to keep [...]]]></description>
			<content:encoded><![CDATA[<p>Whilst refactoring a jQuery plugin today, I came across a method that placed a list item into an unordered list at a specific point, so that all the items remained in alphabetic order. This long method seemed completely convoluted and slow to me and I decided that there must be an easier way to keep the list in alphabetical order.</p>
<p>There are <a href="http://plugins.jquery.com/project/TinySort" target="_blank">existing plugins for sorting elements</a> but I never like to just pile on the 3rd party plugins as that means more javascript files to include in a page. Besides, I was sure it should not be difficult.</p>
<p>It soon occured to me that jQuery has the built-in ability to return the elements as an array, using the .get() method and from there, it was not too long before I had my streamlined code to sort the list element alphabetically:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> mylist <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> listitems <span style="color: #339933;">=</span> mylist.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
listitems.<span style="color: #660066;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> compA <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> compB <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>compA <span style="color: #339933;">&lt;</span> compB<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span>compA <span style="color: #339933;">&gt;</span> compB<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>listitems<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>idx<span style="color: #339933;">,</span> itm<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> mylist.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>itm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I utilise the javascript array.sort method to sort the elements in the array and then using the jQuery append() method,  reorder them in the actual list element.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.onemoretake.com/2009/02/25/sorting-elements-with-jquery/feed/</wfw:commentRss>
		<slash:comments>49</slash:comments>
		</item>
	</channel>
</rss>

