<?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>Intellectual Pirates &#187; JavaScript</title>
	<atom:link href="http://intellectualpirates.net/category/tutorials/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://intellectualpirates.net</link>
	<description>Web Development Courses, Rants, Tutorials and Hacks</description>
	<lastBuildDate>Wed, 07 Dec 2011 00:59:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Award Firework Alternative with jquery.imgExplosion</title>
		<link>http://intellectualpirates.net/award-firework-alternative-with-jquery-imgexplosion/</link>
		<comments>http://intellectualpirates.net/award-firework-alternative-with-jquery-imgexplosion/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 00:05:14 +0000</pubDate>
		<dc:creator>antic</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[award]]></category>
		<category><![CDATA[explode]]></category>
		<category><![CDATA[explosion]]></category>
		<category><![CDATA[fireworks]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://intellectualpirates.net/?p=1914</guid>
		<description><![CDATA[Don't ask me why, but I needed a way to explode some stars in a fancy animation on a page. At first I found Fireworks.js, which was kinda cool at first--but I quickly realized a few things: 1. It's using raw javascript, which is a pity if you are already loading the power of jquery [...]]]></description>
			<content:encoded><![CDATA[<p>Don't ask me why, but I needed a way to explode some stars in a fancy animation on a page. At first I found <a href="http://www.schillmania.com/projects/fireworks/">Fireworks.js</a>, which was kinda cool at first--but I quickly realized a few things:</p>
<p>1. It's using raw javascript, which is a pity if you are already loading the power of jquery and jquery.ui<br />
2. It wasn't what I really wanted. I wanted STARS!</p>
<p>So, I bring you, <a href="https://github.com/atomantic/jquery.imgExplosion">jquery.imgExplosion</a>:</p>
<p>Although, the default implementation uses a star graphic I whipped up in Illustrator:<br />
<img src="https://github.com/atomantic/jquery.imgExplosion/raw/master/star.png" /><br />
You can still attach the plugin to any image--either on the page or not. Soccer balls? Severed heads? I don't care what you do with it but <a href="https://github.com/atomantic/jquery.imgExplosion">FORK</a> the code if you've got improvement ideas.<br />
Check out the <a href="http://atomantic.github.com/jquery.imgExplosion/">Demos Page</a> for examples.</p>
<h2>Download/Fork on Github</h2>
<p><a href="https://github.com/atomantic/jquery.imgExplosion">https://github.com/atomantic/jquery.imgExplosion</a></p>
<h2>Demos</h2>
<p><a href="http://atomantic.github.com/jquery.imgExplosion/">http://atomantic.github.com/jquery.imgExplosion/</a></p>
<div class="plus-one-wrap"><g:plusone href="http://intellectualpirates.net/award-firework-alternative-with-jquery-imgexplosion/"></g:plusone></div><p><a href='http://www.twitter.com/antic' class='twitlink'>follow on Twitter</a></p>]]></content:encoded>
			<wfw:commentRss>http://intellectualpirates.net/award-firework-alternative-with-jquery-imgexplosion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Inline Code Assistance for Form Fields with jquery.codeassist</title>
		<link>http://intellectualpirates.net/inline-code-assistance-for-form-fields-with-jquery-codeassist/</link>
		<comments>http://intellectualpirates.net/inline-code-assistance-for-form-fields-with-jquery-codeassist/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 19:54:29 +0000</pubDate>
		<dc:creator>antic</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[assistance]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dynamic text]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[popup]]></category>
		<category><![CDATA[suggestions]]></category>

		<guid isPermaLink="false">http://intellectualpirates.net/?p=1845</guid>
		<description><![CDATA[I'm working on a project that required some apparently previously unexpected UI controls. One of them, I decided should be made into a jQuery plugin and get some feedback from the community. I call it jquery.codeassist. OK... so what the hell does it do? The plugin creates a code assist menu within textarea and input [...]]]></description>
			<content:encoded><![CDATA[<p>I'm working on a project that required some apparently previously unexpected UI controls. One of them, I decided should be made into a jQuery plugin and get some feedback from the community. I call it <a href="http://github.com/atomantic/jquery.codeassist">jquery.codeassist</a>.</p>
<h2>OK... so what the hell does it do?</h2>
<p>The plugin creates a code assist menu within textarea and input fields, which allows users to select from a list of suggested values. This effect is triggered by the entry of a key character such as %, $ or [</p>
<p>So far, only %, $ and [ (with an optional closing key of ]) are supported--though, with some tweaks, I know I can get it to accept any input.</p>
<h2>OK... but really, what the hell does it do?</h2>
<p>It was built for the purpose of allowing users to enter dynamically replaceable code bits into textareas and input fields. A use case example would be if you are allowing users to create a page template or message template that will need to be filtered for the audience or some other situation involving different values for different pieces of data at a time. A user can enter in the code bits, which you can replace behind the scenes in the template.</p>
<h2>OK... so is there a real world example?</h2>
<p>Since the impetus for this plugin comes from a proprietary and as of yet unseen stealthy startup, I'm not at liberty to show the awesome reason why I found it necessary to create this plugin. But here's a totally crappy and simple demo so you can see what the hell I'm actually talking about:<br />
<a href="http://atomantic.github.com/jquery.codeassist/">Crappy, Simple Demo</a></p>
<p>And you can download, fork and whatnot on github:<br />
<a href="http://github.com/atomantic/jquery.codeassist">Source on GitHub</a></p>
<h2>Issues I had with the implementation</h2>
<h3>Mouse position</h3>
<p>The thing that is bugging me most at the moment is that I wanted the menu to appear where the mouse is. Simple enough, right? Just take a look at the triggered event pageX and pageY, right? Well, that would work if I was attaching to a mouse event--but the trigger for the menu is a key event, which doesn't care about the position of the mouse. So to get around this, I've got a listener that's caching the mouse coordinates so we can look at it when we need to:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// this is stupid but I can't find a better way to get the current mouse position</span>
<span style="color: #006600; font-style: italic;">// since the key events don't contain the pageX and pageY </span>
<span style="color: #006600; font-style: italic;">// so following it arround and caching the position :(</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mousemove</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	codeassist.<span style="color: #660066;">pageX</span> <span style="color: #339933;">=</span> e.<span style="color: #660066;">pageX</span><span style="color: #339933;">;</span>
	codeassist.<span style="color: #660066;">pageY</span> <span style="color: #339933;">=</span> e.<span style="color: #660066;">pageY</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 am genuinely annoyed about this.</p>
<h3>Cursor position</h3>
<p>For sane browsers, you can simply access element.selectionStart to get the index that the cursor is positioned within the text. However, for IE, you have to hack up a nasty solution:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">... <span style="color: #006600; font-style: italic;">// up here, we've defined el as the input, v as the current value of the input, and t = $(this), etc..</span>
<span style="color: #003366; font-weight: bold;">var</span> before <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// text before cursor</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">selectionStart</span><span style="color: #339933;">!==</span>undefined<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// sane browser</span>
	before <span style="color: #339933;">=</span> v.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>el.<span style="color: #660066;">selectionStart</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;">else</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// IE</span>
	t.<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: #003366; font-weight: bold;">var</span> range <span style="color: #339933;">=</span> document.<span style="color: #660066;">selection</span>.<span style="color: #660066;">createRange</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	range.<span style="color: #660066;">moveStart</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'character'</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span>v.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	before <span style="color: #339933;">=</span> v.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>range.<span style="color: #660066;">text</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<div class="plus-one-wrap"><g:plusone href="http://intellectualpirates.net/inline-code-assistance-for-form-fields-with-jquery-codeassist/"></g:plusone></div><p><a href='http://www.twitter.com/antic' class='twitlink'>follow on Twitter</a></p>]]></content:encoded>
			<wfw:commentRss>http://intellectualpirates.net/inline-code-assistance-for-form-fields-with-jquery-codeassist/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

