<?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>Latent Motion &#187; jQuery</title>
	<atom:link href="http://www.latentmotion.com/category/web-programming/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.latentmotion.com</link>
	<description>Usability, Design and Front-Side Programming</description>
	<lastBuildDate>Tue, 27 Jul 2010 05:40:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Create a jQuery Bookmarklet</title>
		<link>http://www.latentmotion.com/how-to-create-a-jquery-bookmarklet/</link>
		<comments>http://www.latentmotion.com/how-to-create-a-jquery-bookmarklet/#comments</comments>
		<pubDate>Thu, 20 May 2010 16:00:15 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[favelet]]></category>
		<category><![CDATA[javascript bookmarklet]]></category>
		<category><![CDATA[jquery bookmarklet]]></category>

		<guid isPermaLink="false">http://www.latentmotion.com/?p=475</guid>
		<description><![CDATA[
I suspect many of my readers have written at least one jQuery Plugin / Script. In this post, I&#8217;d like to show you how to get the most out of that script by also releasing it as a jQuery Bookmarklet. Below, you&#8217;ll find two examples of utilities that are ripe for bookmarkleting, as well as [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; padding-top: 5px;"><a class="trans80" style="margin: 0px 10px 20px 20px;" href="http://www.latentmotion.com/downloads/blank-bookmarklet-v1.js"><img style="border: none;" src="http://www.latentmotion.com/wp-content/themes/barecity_1.5/images/download-script.png" alt="" /></a></div>
<p>I suspect many of my readers have written at least one jQuery Plugin / Script. In this post, I&#8217;d like to show you how to get the most out of that script by also releasing it as a jQuery Bookmarklet. Below, you&#8217;ll find two examples of utilities that are ripe for bookmarkleting, as well as a prepared jQuery Bookmarklet file that you can easily modify for the purpose.</p>
<p><em>Note: Even if you haven&#8217;t written a jQuery plugin before, you&#8217;ll find bookmarkleting someone else&#8217;s plugin as easy as using it on a site.</em></p>
<p>Before I get to the code though &#8211; take a look at the payload. You can add the following links as bookmarklets by right-clicking and selecting &#8220;Add to bookmarks / favorites&#8221; (in Chrome, you press &#8220;ctrl+shift+b&#8221; to open the bookmark manager, and drag them over). You can try them before you bookmark them by simply clicking the links on this page too.</p>
<p><strong>Example One:<br />
<script type="text/javascript">// <![CDATA[
var linkster = "javascript:(function(){var head=document.getElementsByTagName('head')[0],script=document.createElement('script');script.type='text/javascript';script.src='http://www.latentmotion.com/downloads/tablesorter-bookmarklet-v1.js?' + Math.floor(Math.random()*99999);head.appendChild(script);})(); void 0";
linkster = '<a href="' + linkster + '">Table Column Sorter Bookmarklet</a>';
document.write(linkster);
// ]]&gt;</script></strong><br />
<a></a><br />
Clicking the above link will  add the <a href="http://tablesorter.com/docs/">table sorter jquery plugin</a> to the page, including its stylesheet, and it will apply the script to all tables on the page. Once it&#8217;s loaded, you can click on any of the table column headers to sort the rows by column values.</p>
<p><strong>Example Two:<br />
<script type="text/javascript">// <![CDATA[
var linkster = "javascript:(function(){var head=document.getElementsByTagName('head')[0],script=document.createElement('script');script.type='text/javascript';script.src='http://www.latentmotion.com/downloads/visualizer-bookmarklet-v1.js?' + Math.floor(Math.random()*99999);head.appendChild(script);})(); void 0";
linkster = '<a href="' + linkster + '">Table Visualizer Bookmarklet</a>';
document.write(linkster);
// ]]&gt;</script></strong><br />
<a></a></p>
<p>The visualizer bookmarklet will add graphical representations of the data in the table. As with the table sorter, this bookmarklet was adapted from a pre-existing plugin, Filament&#8217;s <a href="http://www.filamentgroup.com/lab/update_to_jquery_visualize_accessible_charts_with_html5_from_designing_with/">jQuery Visualize</a>.</p>
<table style="margin: 10px;">
<caption>2009 Employee Sales by Department</caption>
<thead>
<tr>
<td></td>
<th scope="col">food</th>
<th scope="col">auto</th>
<th scope="col">household</th>
<th scope="col">furniture</th>
<th scope="col">kitchen</th>
<th scope="col">bath</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Mary</th>
<td>190</td>
<td>160</td>
<td>40</td>
<td>120</td>
<td>30</td>
<td>70</td>
</tr>
<tr>
<th scope="row">Tom</th>
<td>3</td>
<td>40</td>
<td>30</td>
<td>45</td>
<td>35</td>
<td>49</td>
</tr>
<tr>
<th scope="row">Brad</th>
<td>10</td>
<td>180</td>
<td>10</td>
<td>85</td>
<td>25</td>
<td>79</td>
</tr>
<tr>
<th scope="row">Kate</th>
<td>40</td>
<td>80</td>
<td>90</td>
<td>25</td>
<td>15</td>
<td>119</td>
</tr>
</tbody>
</table>
<p><span id="more-475"></span></p>
<p>Cool stuff, right? Let&#8217;s get to how it works then &#8211; starting with the prepared jQuery Bookmarklet template. This is what I recommend you use when writing your own bookmarklets:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
 * jQuery Bookmarklet - version 1.0
 * Originally written by: Brett Barros
 * With modifications by: Paul Irish
 *
 * If you use this script, please link back to the source
 *
 * Copyright (c) 2010 Latent Motion (http://latentmotion.com/how-to-create-a-jquery-bookmarklet/)
 * Released under the Creative Commons Attribution 3.0 Unported License,
 * as defined here: http://creativecommons.org/licenses/by/3.0/
 *
 */</span>
&nbsp;
window.<span style="color: #660066;">bookmarklet</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>opts<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>fullFunc<span style="color: #009900;">&#40;</span>opts<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// These are the styles, scripts and callbacks we include in our bookmarklet:</span>
window.<span style="color: #660066;">bookmarklet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    css <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'http://www.site.com/your.css'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    js  <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'http://www.site.com/your.js'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>    
<span style="color: #006600; font-style: italic;">//	jqpath : 'myCustomjQueryPath.js', &lt;-- option to include your own path to jquery</span>
    ready <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>
&nbsp;
		<span style="color: #006600; font-style: italic;">// The meat of your jQuery code goes here</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hello World&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   	    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> fullFunc<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">function</span> d<span style="color: #009900;">&#40;</span>b<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>b.<span style="color: #660066;">length</span><span style="color: #339933;">===</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>a.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>return <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span>$.<span style="color: #660066;">getScript</span><span style="color: #009900;">&#40;</span>b<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: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>d<span style="color: #009900;">&#40;</span>b.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #003366; font-weight: bold;">function</span> e<span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>b<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>c<span style="color: #339933;">,</span>f<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;link&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>href<span style="color: #339933;">:</span>f<span style="color: #339933;">,</span>rel<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;stylesheet&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;head&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>a.<span style="color: #660066;">jqpath</span><span style="color: #339933;">=</span>a.<span style="color: #660066;">jqpath</span><span style="color: #339933;">||</span><span style="color: #3366CC;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span><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>b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">var</span> c<span style="color: #339933;">=</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;script&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>c.<span style="color: #660066;">type</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">;</span>c.<span style="color: #660066;">src</span><span style="color: #339933;">=</span>b<span style="color: #339933;">;</span>c.<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>e<span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">css</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>d<span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">js</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">jqpath</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>From top to bottom, what the <a href="http://www.latentmotion.com/downloads/blank-bookmarklet-v1.js">jQuery Bookmarklet Template</a> does is:</p>
<ol>
<li>Prepare the full bookmarklet function. This is the call to the minified code in the last line of the js file. It is in an uncompressed format at the bottom of this post for those interested, but most will never need to see it..</li>
<li>Create the configurations, including arrays to your CSS and JS files. You can load as many as you see fit, and the JS files will load asynchronously, ensuring that each file can reliably depend on the file before it.</li>
<li>Provides the callback function for your editing. Place whatever jQuery code you like here.</li>
</ol>
<p>In order to use that script, though, you&#8217;ll need to create a link that calls it. Here&#8217;s the code for that link:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;javascript:(function(){var head=document.getElementsByTagName('head')[0],script=document.createElement('script');script.type='text/javascript';script.src='http://www.site.com/your-javascript.js?' + Math.floor(Math.random()*99999);head.appendChild(script);})(); void 0&quot;&gt;Your Bookmarklet Name&lt;/a&gt;</pre></div></div>

<p>To some that might look like a handful, but don&#8217;t worry, the hard work is already done. All you need to do is change the url in that link to point to your javascript file, and add a little regular-ol-jQuery to that javascript file.</p>
<p>Ok, still with me? Great! Now let&#8217;s look at one of the actual live examples we used earlier on the page. Here&#8217;s how I included table sorter, which requires both a JS and CSS  file:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
 * jQuery Bookmarklet - version 1.0
 * Originally written by: Brett Barros
 * With modifications by: Paul Irish
 *
 * If you use this script, please link back to the source
 *
 * Copyright (c) 2010 Latent Motion (http://latentmotion.com/how-to-create-a-jquery-bookmarklet/)
 * Released under the Creative Commons Attribution 3.0 Unported License,
 * as defined here: http://creativecommons.org/licenses/by/3.0/
 *
 */</span>
&nbsp;
window.<span style="color: #660066;">bookmarklet</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>opts<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>fullFunc<span style="color: #009900;">&#40;</span>opts<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// These are the styles, scripts and callbacks we include in our bookmarklet:</span>
window.<span style="color: #660066;">bookmarklet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    css <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'http://tablesorter.com/themes/blue/style.css'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    js  <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'http://tablesorter.com/jquery.tablesorter.js'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>    
<span style="color: #006600; font-style: italic;">//	jqpath : 'myCustomjQueryPath.js', &lt;-- option to include your own path to jquery</span>
    ready <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>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Initiate table sorter</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;table&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">tablesorter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tablesorter&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 	
&nbsp;
   	    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> fullFunc<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">function</span> d<span style="color: #009900;">&#40;</span>b<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>b.<span style="color: #660066;">length</span><span style="color: #339933;">===</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>a.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>return <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span>$.<span style="color: #660066;">getScript</span><span style="color: #009900;">&#40;</span>b<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: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>d<span style="color: #009900;">&#40;</span>b.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #003366; font-weight: bold;">function</span> e<span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>b<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>c<span style="color: #339933;">,</span>f<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;link&gt;&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>href<span style="color: #339933;">:</span>f<span style="color: #339933;">,</span>rel<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;stylesheet&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;head&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>a.<span style="color: #660066;">jqpath</span><span style="color: #339933;">=</span>a.<span style="color: #660066;">jqpath</span><span style="color: #339933;">||</span><span style="color: #3366CC;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span><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>b<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">var</span> c<span style="color: #339933;">=</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;script&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>c.<span style="color: #660066;">type</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">;</span>c.<span style="color: #660066;">src</span><span style="color: #339933;">=</span>b<span style="color: #339933;">;</span>c.<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>e<span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">css</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>d<span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">js</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">jqpath</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>For your convenience, you can also <a href="http://www.latentmotion.com/jquery-bookmarklet/tablesorter-bookmarklet.js">download the script as a JS file</a>.</p>
<p>And that&#8217;s about it! Sorta, anyway. Here&#8217;re some bonus thoughts for the real enthusiasts:</p>
<ol>
<li>Bookmarklets leverage caching, big time. When developing, I found this to be a major frustration, so I added a large random number at the end of the js call, which effectively forces a reload each time the javascript is called. Upon deployment &#8211; you may choose to remove it, but keep it in mind next time you make a change and don&#8217;t see the effects.</li>
<li>Another reason I force refreshing of my js file is because I want to be able to update my scripts without forcing my users to re-bookmark them.</li>
<li>If you create your own bookmarklet and want to post about it in wordpress, you&#8217;ll quickly learn you need a workaround. The first one I used was hardcoding the links in an external page, and displaying them through an iframe. It worked, but was lame. Now I&#8217;m using javascript to store the desired a href as a variable, then I wrap that variable with the tags, and finally I document.write it. If you have a better idea, let me know.</li>
<li>The table examples that I&#8217;ve provided on this page are based on pre-existing jQuery plugins. Those plugins assume that tables are correctly formatted, with table headers etc. If a website&#8217;s layout was built in the 90s and still uses tables for page structure, the results won&#8217;t be pretty. </li>
<li>Sadly, Disqus (the host service for my comments below) uses tables. This of course conflicts with the specific table examples I used above, and can be resolved by refreshing. I&#8217;m sure it&#8217;s possible to set the bookmarklet to listen for a click of a table, but that&#8217;s beyond the scope of the current script/lesson.</li>
</ol>
<p>And here&#8217;s some extra credit reading:</p>
<ul>
<li><a href="http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet">Learning jQuery</a> made me realize that loading jQuery dynamically is possible. Almost ironically, Paul Irish helped with some modifications over there too.</li>
<li>After writing this article, I was informed <a href="http://benalman.com/projects/run-jquery-code-bookmarklet/">Ben Alman</a> had already written a similar script. His actually includes a &#8220;generator&#8221; that will use your jquery code and embed it for you, which is cool. It doesn&#8217;t include a loop to first include javascript / css files, but he probably figured it was easy enough to add yourself.</li>
<li><a href="http://iamnotagoodartist.com/">Tommy</a>, at <a href="http://www.smashingmagazine.com/2010/05/23/make-your-own-bookmarklets-with-jquery/">Smashing Magazine</a>, wrote a much more in-depth article about the details and options when writing a jQuery bookmarklet. Although it was posted a few days after I posted mine, he had submitted it months in advance. Smart guy <img src='http://www.latentmotion.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
<li><a href="http://marklets.com">Marklets</a> is a pretty nifty bookmark database that gives you searchable access to triggering any script in the arsenal. The creator and I are discussing a joint bookmarkleting project. Contact me if you&#8217;re interested in making bookmarklets kick ass again.</li>
</ul>
<p>If you have any ideas, questions, or musings, I&#8217;d love to hear &#8216;em! Please add your comment below.</p>
<p><em><strong>Update:</strong> <a href="http://paulirish.com/">Paul Irish</a> was kind enough to help improve this script and teach me a couple things along the way. The following is the unminified version of what I&#8217;ve listed above, and includes his structural changes.</em></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
 * jQuery Bookmarklet - version 1.0
 * Originally written by: Brett Barros
 * Heavily modified by: Paul Irish
 *
 * If you use this script, please link back to the source
 *
 * Copyright (c) 2010 Latent Motion (http://latentmotion.com/how-to-create-a-jquery-bookmarklet/)
 * Released under the Creative Commons Attribution 3.0 Unported License,
 * as defined here: http://creativecommons.org/licenses/by/3.0/
 *
 */</span>
&nbsp;
window.<span style="color: #660066;">bookmarklet</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>opts<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>fullFunc<span style="color: #009900;">&#40;</span>opts<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// These are the styles, scripts and callbacks we include in our bookmarklet:</span>
window.<span style="color: #660066;">bookmarklet</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    css <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'http://tablesorter.com/themes/blue/style.css'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    js  <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'http://tablesorter.com/jquery.tablesorter.js'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>    
<span style="color: #006600; font-style: italic;">//	jqpath : 'myCustomjQueryPath.js', &lt;-- option to include your own jquery</span>
    ready <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>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Initiate table sorter</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;table&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">tablesorter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tablesorter&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 	
&nbsp;
   	    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> fullFunc<span style="color: #009900;">&#40;</span>opts<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// User doesn't have to set jquery, we have a default.</span>
    opts.<span style="color: #660066;">jqpath</span> <span style="color: #339933;">=</span> opts.<span style="color: #660066;">jqpath</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">function</span> getJS<span style="color: #009900;">&#40;</span>jsfiles<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Check if we've processed all of the JS files (or if there are none)</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>jsfiles.<span style="color: #660066;">length</span> <span style="color: #339933;">===</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		opts.<span style="color: #660066;">ready</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>
&nbsp;
        <span style="color: #006600; font-style: italic;">// Load the first js file in the array</span>
        $.<span style="color: #660066;">getScript</span><span style="color: #009900;">&#40;</span>jsfiles<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: #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: #006600; font-style: italic;">// When it's done loading, remove it from the queue and call the function again    </span>
            getJS<span style="color: #009900;">&#40;</span>jsfiles.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Synchronous loop for css files</span>
    <span style="color: #003366; font-weight: bold;">function</span> getCSS<span style="color: #009900;">&#40;</span>csfiles<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>csfiles<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> val<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;link&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                    href<span style="color: #339933;">:</span> val<span style="color: #339933;">,</span>
                    rel<span style="color: #339933;">:</span> <span style="color: #3366CC;">'stylesheet'</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'head'</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>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> getjQuery<span style="color: #009900;">&#40;</span>filename<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Create jQuery script element</span>
		<span style="color: #003366; font-weight: bold;">var</span> fileref <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>
		fileref.<span style="color: #660066;">type</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'text/javascript'</span><span style="color: #339933;">;</span>
		fileref.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span>  filename<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Once loaded, trigger other scripts and styles</span>
		fileref.<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>
&nbsp;
			getCSS<span style="color: #009900;">&#40;</span>opts.<span style="color: #660066;">css</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// load CSS files</span>
			getJS<span style="color: #009900;">&#40;</span>opts.<span style="color: #660066;">js</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// load JS files</span>
&nbsp;
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>fileref<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	getjQuery<span style="color: #009900;">&#40;</span>opts.<span style="color: #660066;">jqpath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// kick it off</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// end of bookmarklet();</span></pre></div></div>





	<a rel="nofollow" class="digg" target="_blank" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fhow-to-create-a-jquery-bookmarklet%252F%26amp%3Btitle%3DHow%2520to%2520Create%2520a%2520jQuery%2520Bookmarklet%26amp%3Bbodytext%3D%250D%250AI%2520suspect%2520many%2520of%2520my%2520readers%2520have%2520written%2520at%2520least%2520one%2520jQuery%2520Plugin%2520%252F%2520Script.%2520In%2520this%2520post%252C%2520I%2527d%2520like%2520to%2520show%2520you%2520how%2520to%2520get%2520the%2520most%2520out%2520of%2520that%2520script%2520by%2520also%2520releasing%2520it%2520as%2520a%2520jQuery%2520Bookmarklet.%2520Below%252C%2520you%2527ll%2520find%2520two%2520examples%2520of%2520utilities%2520that';" title="Digg"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" class="sphinn" target="_blank" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fhow-to-create-a-jquery-bookmarklet%252F';" title="Sphinn"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" class="del.icio.us" target="_blank" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fhow-to-create-a-jquery-bookmarklet%252F%26amp%3Btitle%3DHow%2520to%2520Create%2520a%2520jQuery%2520Bookmarklet%26amp%3Bnotes%3D%250D%250AI%2520suspect%2520many%2520of%2520my%2520readers%2520have%2520written%2520at%2520least%2520one%2520jQuery%2520Plugin%2520%252F%2520Script.%2520In%2520this%2520post%252C%2520I%2527d%2520like%2520to%2520show%2520you%2520how%2520to%2520get%2520the%2520most%2520out%2520of%2520that%2520script%2520by%2520also%2520releasing%2520it%2520as%2520a%2520jQuery%2520Bookmarklet.%2520Below%252C%2520you%2527ll%2520find%2520two%2520examples%2520of%2520utilities%2520that';" title="del.icio.us"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" class="rss" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.latentmotion.com%2Ffeed%2F';" title="RSS"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow" class="twitter" target="_blank" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DHow%2520to%2520Create%2520a%2520jQuery%2520Bookmarklet%2520-%2520http%253A%252F%252Fwww.latentmotion.com%252Fhow-to-create-a-jquery-bookmarklet%252F';" title="Twitter"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.latentmotion.com/how-to-create-a-jquery-bookmarklet/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>The Best Viral Marketing Text Citation (jQuery / WordPress) Plugin</title>
		<link>http://www.latentmotion.com/the-best-link-bait-citation-plugin/</link>
		<comments>http://www.latentmotion.com/the-best-link-bait-citation-plugin/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 15:20:15 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[SEO (Organic)]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.latentmotion.com/?p=199</guid>
		<description><![CDATA[
Everyone&#8217;s seen social bookmarks, and yeah, they&#8217;re great. But even with them, your visitor has to specifically seek out promoting you. On the other hand, when you highlight and copy text from politico.com, it will automatically embed the URL.
Holy crap that&#8217;s cool!
Naturally, I wanted to do it too. But soon after beginning, I realized that [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right; margin-top:-40px;"><a href="http://www.latentmotion.com/downloads/search-and-share-0.9.3-jquery.zip" style="margin:0 0 20px 30px;" ><img src="http://www.latentmotion.com/wp-content/themes/barecity_1.5/images/download-script.png" style="border:none;" class="trans80" /></a><a href="http://www.latentmotion.com/downloads/search-and-share-0.9.3-wordpress.zip" style="margin:0 0 20px 30px;"><img src="http://www.latentmotion.com/wp-content/themes/barecity_1.5/images/download-plugin.png" style="border:none;" class="trans80" /></a></div>
<p>Everyone&#8217;s seen social bookmarks, and yeah, they&#8217;re great. But even with them, your visitor has to specifically seek out promoting you. On the other hand, <strong>when you highlight and copy text from politico.com, it will automatically embed the URL.</strong></p>
<p><em>Holy crap that&#8217;s cool!</em></p>
<p>Naturally, I wanted to do it too. But soon after beginning, I realized that there was still so much more to do. What is it that people wanted to do with the copied text? If the selection is long, perhaps it&#8217;s email or twitter. If it&#8217;s short (like a name or place), I&#8217;d bet it&#8217;s a search. <strong>My plugin takes Politico&#8217;s brilliant idea and gives it what Barry Bonds got.</strong></p>
<p>To see the script in action, <strong>try highlighting any text on this page.</strong> For email or copy/paste credit, select 40+ characters of text. For specific search-worthy examples, try:</p>
<ul>
<li><strong>Wiki: </strong>Machiavelli</li>
<li><strong>Google:</strong> World Trade Center, NY</li>
<li><strong>Facts (Wolfram):</strong> Hamburgers</li>
<li><strong>Amazon:</strong> 1984 by George Orwell</li>
<li><strong>Ebay:</strong> XBOX 360</li>
</ul>
<p>For more information about this plugin, visit the official <strong><a href="http://www.latentmotion.com/search-and-share/">Search and Share</a></strong> page. If you like it, I&#8217;d really appreciate you bumping me up on the social network of your choice. Thanks for the love!</p>
<p>PS: In case you missed the links the first time around, you can <a href="http://www.latentmotion.com/downloads/SearchAndSharePlugin-0.9.zip">download the standalone jQuery version here</a>, and you can <a href="http://www.latentmotion.com/downloads/SearchAndShareScript-0.9.zip">download the wordpress version here</a>.</p>




	<a rel="nofollow" class="digg" target="_blank" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fthe-best-link-bait-citation-plugin%252F%26amp%3Btitle%3DThe%2520Best%2520Viral%2520Marketing%2520Text%2520Citation%2520%2528jQuery%2520%252F%2520WordPress%2529%2520Plugin%26amp%3Bbodytext%3DEveryone%2527s%2520seen%2520social%2520bookmarks%252C%2520and%2520yeah%252C%2520they%2527re%2520great.%2520But%2520even%2520with%2520them%252C%2520your%2520visitor%2520has%2520to%2520specifically%2520seek%2520out%2520promoting%2520you.%2520On%2520the%2520other%2520hand%252C%2520when%2520you%2520highlight%2520and%2520copy%2520text%2520from%2520politico.com%252C%2520it%2520will%2520automatically%2520embed%2520the%2520URL.%250D%250A%250D%250AHol';" title="Digg"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" class="sphinn" target="_blank" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fthe-best-link-bait-citation-plugin%252F';" title="Sphinn"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" class="del.icio.us" target="_blank" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fthe-best-link-bait-citation-plugin%252F%26amp%3Btitle%3DThe%2520Best%2520Viral%2520Marketing%2520Text%2520Citation%2520%2528jQuery%2520%252F%2520WordPress%2529%2520Plugin%26amp%3Bnotes%3DEveryone%2527s%2520seen%2520social%2520bookmarks%252C%2520and%2520yeah%252C%2520they%2527re%2520great.%2520But%2520even%2520with%2520them%252C%2520your%2520visitor%2520has%2520to%2520specifically%2520seek%2520out%2520promoting%2520you.%2520On%2520the%2520other%2520hand%252C%2520when%2520you%2520highlight%2520and%2520copy%2520text%2520from%2520politico.com%252C%2520it%2520will%2520automatically%2520embed%2520the%2520URL.%250D%250A%250D%250AHol';" title="del.icio.us"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" class="rss" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.latentmotion.com%2Ffeed%2F';" title="RSS"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow" class="twitter" target="_blank" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DThe%2520Best%2520Viral%2520Marketing%2520Text%2520Citation%2520%2528jQuery%2520%252F%2520WordPress%2529%2520Plugin%2520-%2520http%253A%252F%252Fwww.latentmotion.com%252Fthe-best-link-bait-citation-plugin%252F';" title="Twitter"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.latentmotion.com/the-best-link-bait-citation-plugin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using jQuery Clone to Add Dynamic Data</title>
		<link>http://www.latentmotion.com/using-jquery-clone-to-add-dynamic-data/</link>
		<comments>http://www.latentmotion.com/using-jquery-clone-to-add-dynamic-data/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 16:00:02 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[delicious feed]]></category>
		<category><![CDATA[dynamic data]]></category>
		<category><![CDATA[jquery clone]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[rolling delicious]]></category>

		<guid isPermaLink="false">http://www.latentmotion.com/?p=319</guid>
		<description><![CDATA[As a User Interface Expert first and Programmer second, I put a lot of consideration into how I code. With every step, I do my best to ensure that designers with less programming experience will be able to accomplish what they&#8217;d like. This distinction in programming methods is most clear in how I place dynamic [...]]]></description>
			<content:encoded><![CDATA[<p>As a User Interface Expert first and Programmer second, I put a lot of consideration into how I code. With every step, I do my best to ensure that designers with less programming experience will be able to accomplish what they&#8217;d like. This distinction in programming methods is most clear in how I place dynamic data onto the page.</p>
<p>Whereas many scripts embed the html markup into their javascript, I much prefer to leave it on the page. More specifically, I prefer to leave a <strong><em>model</em></strong> of the html on the page, and to inject the dynamic data using that model. As my example, I&#8217;ll continue <a href="http://www.latentmotion.com/calling-remote-json-files-via-javascript-jquery">yesterday&#8217;s post on a rolling delicious feed</a>.</p>
<p>If you&#8217;d like to skip ahead, you can <a href="http://www.latentmotion.com/downloads/dynamic-cloning.html">view the demo here</a>, or scroll down to view the whole block of code.</p>
<p>But I prefer to break things down first. Let&#8217;s look at my so-called <strong><em>model</em></strong>:</p>
<pre><pre class="brush: xml;">
&lt;div id=&quot;deliciousList&quot;&gt;
    &lt;div id=&quot;deliciousModel&quot; class=&quot;model item&quot;&gt;
        &lt;p&gt;&lt;a class=&quot;url&quot;&gt;&lt;span class=&quot;title&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
        &lt;p&gt;Posted by: &lt;span class=&quot;author&quot;&gt;&lt;/span&gt;&lt;/p&gt;
		&lt;p&gt;Tags: &lt;span class=&quot;tags&quot;&gt;&lt;/span&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;
</pre></pre>
<p>Notice that it creates the delicious list, and that inside it is an &#8220;item&#8221;. We&#8217;ll be identifying this model, and duplicating it as many times as we need to. When it&#8217;s duplicated, we&#8217;ll simply find the spans with the appropriate classes, and insert content. It&#8217;s easy and processor efficient, see for yourself:</p>
<pre><pre class="brush: jscript;">
// Clone duplicates the model (with bindings), strips model class/id, gives a unique id, and then adds it before the model
 $(&quot;#deliciousModel&quot;).clone(true).removeAttr(&quot;id&quot;) .removeClass(&quot;model&quot;).attr(&quot;id&quot;, &quot;del&quot; + i).insertBefore(&quot;#deliciousModel&quot;)

 // The finds get each class from within the model and replace it with values from the feed.
 .find(&quot;.url&quot;).attr(&quot;href&quot;, entry.u).end()
 .find(&quot;.author&quot;).html(entry.a).end()
 .find(&quot;.tags&quot;).html(processedTags).end()
 .find(&quot;.title&quot;).html(entry.d);
</pre></pre>
<p>The first line does the cloning, removes the identifying attributes (and class model causes a display:hide;), and inserts the new block.</p>
<p>The subsequent lines insert the appropriate data. Each &#8220;find&#8221; and &#8220;end&#8221; here is really important. By chaining the javascript, we&#8217;re preventing the code from constantly searching the entire document, and we&#8217;re containing the modifications to the model itself.</p>
<p>For the entire block of code, view below:</p>
<pre><pre class="brush: xml;">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Delicious Feed&lt;/title&gt;
&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'&gt;&lt;/script&gt;
&lt;script type=&quot;application/javascript&quot;&gt;
    $(document).ready(function(){
// DELICIOUS JSON -- http://feeds.delicious.com/v2/json/tag/hyperstudio
$.getJSON('delicious-json.php', function(data){
$.each(data, function(i, entry) {

tags = entry.t;
tagLength = tags.length;
processedTags = '';

jQuery.each(tags, function(i, val) {
processedTags += ' ' + val;
if (i &lt; tagLength - 1) processedTags += ',';
});

// Clone duplicates the model (with bindings), strips model class/id, gives a unique id, and then adds it before the model
$(&quot;#deliciousModel&quot;).clone(true).removeAttr(&quot;id&quot;) .removeClass(&quot;model&quot;).attr(&quot;id&quot;, &quot;del&quot; + i).insertBefore(&quot;#deliciousModel&quot;)

// The finds get each class from within the model and replace it with values from the feed.
.find(&quot;.url&quot;).attr(&quot;href&quot;, entry.u).end()
.find(&quot;.author&quot;).html(entry.a).end()
.find(&quot;.tags&quot;).html(processedTags).end()
.find(&quot;.title&quot;).html(entry.d);

if ( i == 10 )  return false; // Limit to 10 entries

});
});
    });
&lt;/script&gt;
&lt;style type=&quot;text/css&quot;&gt;
html { font-size:10px; font-family:Arial, Helvetica, sans-serif;}
a {color:#066; font-size:12px;}
p {margin:0; padding:0;}
a:hover {color:#099;}
#deliciousList {border:1px solid #333; width:400px; margin:0 auto; padding:0 10px;}
.item {margin:10px 0;}
.clear {clear:both;}
.model {display:none;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;deliciousList&quot;&gt;
    &lt;div id=&quot;deliciousModel&quot; class=&quot;model item&quot;&gt;
        &lt;p&gt;&lt;a class=&quot;url&quot;&gt;&lt;span class=&quot;title&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
        &lt;p&gt;Posted by: &lt;span class=&quot;author&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Tags: &lt;span class=&quot;tags&quot;&gt;&lt;/span&gt;&lt;/p&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre></pre>




	<a rel="nofollow" class="digg" target="_blank" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fusing-jquery-clone-to-add-dynamic-data%252F%26amp%3Btitle%3DUsing%2520jQuery%2520Clone%2520to%2520Add%2520Dynamic%2520Data%26amp%3Bbodytext%3DAs%2520a%2520User%2520Interface%2520Expert%2520first%2520and%2520Programmer%2520second%252C%2520I%2520put%2520a%2520lot%2520of%2520consideration%2520into%2520how%2520I%2520code.%2520With%2520every%2520step%252C%2520I%2520do%2520my%2520best%2520to%2520ensure%2520that%2520designers%2520with%2520less%2520programming%2520experience%2520will%2520be%2520able%2520to%2520accomplish%2520what%2520they%2527d%2520like.%2520This%2520distinctio';" title="Digg"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" class="sphinn" target="_blank" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fusing-jquery-clone-to-add-dynamic-data%252F';" title="Sphinn"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" class="del.icio.us" target="_blank" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fusing-jquery-clone-to-add-dynamic-data%252F%26amp%3Btitle%3DUsing%2520jQuery%2520Clone%2520to%2520Add%2520Dynamic%2520Data%26amp%3Bnotes%3DAs%2520a%2520User%2520Interface%2520Expert%2520first%2520and%2520Programmer%2520second%252C%2520I%2520put%2520a%2520lot%2520of%2520consideration%2520into%2520how%2520I%2520code.%2520With%2520every%2520step%252C%2520I%2520do%2520my%2520best%2520to%2520ensure%2520that%2520designers%2520with%2520less%2520programming%2520experience%2520will%2520be%2520able%2520to%2520accomplish%2520what%2520they%2527d%2520like.%2520This%2520distinctio';" title="del.icio.us"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" class="rss" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.latentmotion.com%2Ffeed%2F';" title="RSS"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow" class="twitter" target="_blank" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DUsing%2520jQuery%2520Clone%2520to%2520Add%2520Dynamic%2520Data%2520-%2520http%253A%252F%252Fwww.latentmotion.com%252Fusing-jquery-clone-to-add-dynamic-data%252F';" title="Twitter"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.latentmotion.com/using-jquery-clone-to-add-dynamic-data/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Calling Remote JSON Files via Javascript / jQuery</title>
		<link>http://www.latentmotion.com/calling-remote-json-files-via-javascript-jquery/</link>
		<comments>http://www.latentmotion.com/calling-remote-json-files-via-javascript-jquery/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 16:00:10 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[data feeds]]></category>
		<category><![CDATA[delicious]]></category>
		<category><![CDATA[getjson]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.latentmotion.com/?p=310</guid>
		<description><![CDATA[Not too long ago, I was asked to create a rolling delicious feed using their JSON data. It took me quite a while to realize what was going wrong &#8211; but the solution was obvious as soon as the problem became clear. If you&#8217;re going down the same path, maybe this bit of advice will [...]]]></description>
			<content:encoded><![CDATA[<p>Not too long ago, I was asked to create a rolling delicious feed using their JSON data. It took me quite a while to realize what was going wrong &#8211; but the solution was obvious as soon as the problem became clear. If you&#8217;re going down the same path, maybe this bit of advice will help.</p>
<p>Firstly, you have to create a local reference of the JSON data. As I understand it, this has to do with the <a href="http://en.wikipedia.org/wiki/JSON#Security_issues">JSON server settings and security</a>. In any event, it&#8217;s easy enough to do. Create a file, such as my delicious-json.php. All you need to put in it is this:</p>
<pre><pre class="brush: php;">

&lt;?php
echo file_get_contents(&quot;http://feeds.delicious.com/v2/json/tag/hyperstudio&quot;);
?&gt;

</pre></pre>
<p>Easy peasy. Now you can reference it via jQuery, like so:</p>
<pre><pre class="brush: jscript;">
&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'&gt;&lt;/script&gt;
$(document).ready(function(){
// DELICIOUS JSON -- http://feeds.delicious.com/v2/json/tag/hyperstudio
  $.getJSON('delicious-json.php', function(data){
    $.each(data, function(i, entry) {
      // Process your data here
    });
  });
});
</pre></pre>
<p>How you use the JSON is up to you. In tomorrow&#8217;s post, I&#8217;ll describe my preferred method &#8211; cloning a model. Doing so has a lot of speed benefits, but more importantly, it separates the html from the javascript. As a consequence, any web designer can easily step in and modify the aesthetics without touching code. This facilitates the very important separation of concerns.</p>




	<a rel="nofollow" class="digg" target="_blank" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fcalling-remote-json-files-via-javascript-jquery%252F%26amp%3Btitle%3DCalling%2520Remote%2520JSON%2520Files%2520via%2520Javascript%2520%252F%2520jQuery%26amp%3Bbodytext%3DNot%2520too%2520long%2520ago%252C%2520I%2520was%2520asked%2520to%2520create%2520a%2520rolling%2520delicious%2520feed%2520using%2520their%2520JSON%2520data.%2520It%2520took%2520me%2520quite%2520a%2520while%2520to%2520realize%2520what%2520was%2520going%2520wrong%2520-%2520but%2520the%2520solution%2520was%2520obvious%2520as%2520soon%2520as%2520the%2520problem%2520became%2520clear.%2520If%2520you%2527re%2520going%2520down%2520the%2520same%2520path%252C%2520m';" title="Digg"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" class="sphinn" target="_blank" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fcalling-remote-json-files-via-javascript-jquery%252F';" title="Sphinn"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" class="del.icio.us" target="_blank" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fcalling-remote-json-files-via-javascript-jquery%252F%26amp%3Btitle%3DCalling%2520Remote%2520JSON%2520Files%2520via%2520Javascript%2520%252F%2520jQuery%26amp%3Bnotes%3DNot%2520too%2520long%2520ago%252C%2520I%2520was%2520asked%2520to%2520create%2520a%2520rolling%2520delicious%2520feed%2520using%2520their%2520JSON%2520data.%2520It%2520took%2520me%2520quite%2520a%2520while%2520to%2520realize%2520what%2520was%2520going%2520wrong%2520-%2520but%2520the%2520solution%2520was%2520obvious%2520as%2520soon%2520as%2520the%2520problem%2520became%2520clear.%2520If%2520you%2527re%2520going%2520down%2520the%2520same%2520path%252C%2520m';" title="del.icio.us"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" class="rss" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.latentmotion.com%2Ffeed%2F';" title="RSS"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow" class="twitter" target="_blank" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DCalling%2520Remote%2520JSON%2520Files%2520via%2520Javascript%2520%252F%2520jQuery%2520-%2520http%253A%252F%252Fwww.latentmotion.com%252Fcalling-remote-json-files-via-javascript-jquery%252F';" title="Twitter"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.latentmotion.com/calling-remote-json-files-via-javascript-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Div Class Clear &#8211; Without the Markup</title>
		<link>http://www.latentmotion.com/div-class-clear-without-the-markup/</link>
		<comments>http://www.latentmotion.com/div-class-clear-without-the-markup/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 16:00:00 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[background bugs]]></category>
		<category><![CDATA[background fix]]></category>
		<category><![CDATA[background stretching]]></category>
		<category><![CDATA[browser bugs]]></category>
		<category><![CDATA[clear]]></category>
		<category><![CDATA[div class clear]]></category>
		<category><![CDATA[div clear]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[float nearly everything]]></category>

		<guid isPermaLink="false">http://www.latentmotion.com/?p=302</guid>
		<description><![CDATA[The Div Class Clear is an old trick for getting container backgrounds to stretch down to the bottom of its contents. Although there has since been a push for the &#8220;float nearly everything&#8221; technique, I&#8217;m not convinced that constantly setting floats and widths across all elements is a sustainable method. Instead, let&#8217;s address the only [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.positioniseverything.net/easyclearing.html">Div Class Clear</a> is an old trick for getting container backgrounds to stretch down to the bottom of its contents. Although there has since been a push for the &#8220;<a href="http://orderedlist.com/articles/clearing-floats-the-fne-method">float nearly everything</a>&#8221; technique, I&#8217;m not convinced that constantly setting floats and widths across all elements is a sustainable method. Instead, let&#8217;s address the only problem people have with the Div Class Clear method &#8211; the added markup.</p>
<p>We can remove this markup quite simply with jQuery. Rather than mess with the actual on-page elements, why not insert it dynamically? Check out the code:</p>
<pre><pre class="brush: jscript;">
&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
    $(document).ready(function(){
$(&quot;*:last-child&quot;).filter(function() {
return $(this).css('float') != 'none';
}).parent().append(&quot;&lt;div class='clear'&gt;&lt;/div&gt;&quot;);
    });
&lt;/script&gt;
&lt;style&gt;
.clear {clear:both;}
&lt;/style&gt;
</pre></pre>
<p>Note: As you may imagine, this method assumes that the viewer has javascript enabled. Given that the downside is a matter of background stretching, and considering all the numerous other things that break when javascript isn&#8217;t enabled, I (generally) readily accept this sacrifice. After all, it&#8217;s not like Flash, where they get no content at all.</p>




	<a rel="nofollow" class="digg" target="_blank" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fdiv-class-clear-without-the-markup%252F%26amp%3Btitle%3DDiv%2520Class%2520Clear%2520-%2520Without%2520the%2520Markup%26amp%3Bbodytext%3DThe%2520Div%2520Class%2520Clear%2520is%2520an%2520old%2520trick%2520for%2520getting%2520container%2520backgrounds%2520to%2520stretch%2520down%2520to%2520the%2520bottom%2520of%2520its%2520contents.%2520Although%2520there%2520has%2520since%2520been%2520a%2520push%2520for%2520the%2520%2522float%2520nearly%2520everything%2522%2520technique%252C%2520I%2527m%2520not%2520convinced%2520that%2520constantly%2520setting%2520floats%2520an';" title="Digg"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" class="sphinn" target="_blank" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fdiv-class-clear-without-the-markup%252F';" title="Sphinn"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" class="del.icio.us" target="_blank" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fdiv-class-clear-without-the-markup%252F%26amp%3Btitle%3DDiv%2520Class%2520Clear%2520-%2520Without%2520the%2520Markup%26amp%3Bnotes%3DThe%2520Div%2520Class%2520Clear%2520is%2520an%2520old%2520trick%2520for%2520getting%2520container%2520backgrounds%2520to%2520stretch%2520down%2520to%2520the%2520bottom%2520of%2520its%2520contents.%2520Although%2520there%2520has%2520since%2520been%2520a%2520push%2520for%2520the%2520%2522float%2520nearly%2520everything%2522%2520technique%252C%2520I%2527m%2520not%2520convinced%2520that%2520constantly%2520setting%2520floats%2520an';" title="del.icio.us"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" class="rss" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.latentmotion.com%2Ffeed%2F';" title="RSS"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow" class="twitter" target="_blank" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DDiv%2520Class%2520Clear%2520-%2520Without%2520the%2520Markup%2520-%2520http%253A%252F%252Fwww.latentmotion.com%252Fdiv-class-clear-without-the-markup%252F';" title="Twitter"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.latentmotion.com/div-class-clear-without-the-markup/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Make Enter Key Tab in Forms</title>
		<link>http://www.latentmotion.com/make-enter-key-tab-in-forms/</link>
		<comments>http://www.latentmotion.com/make-enter-key-tab-in-forms/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 16:00:52 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[User Interface]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[enter]]></category>
		<category><![CDATA[enter to tab]]></category>
		<category><![CDATA[form usability]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[tab]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://www.latentmotion.com/?p=294</guid>
		<description><![CDATA[Sometimes, web browsers really suck. Default form behaviors are a major cause for suckage &#8211; but  good UI developers can override them. Heck, if you know how to copy and paste, you&#8217;re halfway there. I&#8217;ve patched together the following script, which converts the enter tab into a tab click when a form input is focused. [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, web browsers really <strong>suck.</strong> Default form behaviors are a major cause for suckage &#8211; but  good UI developers can override them. Heck, if you know how to copy and paste, you&#8217;re halfway there. I&#8217;ve patched together the following script, which converts the enter tab into a tab click when a form input is focused. Try it for yourself by copying it into the header of your page:</p>
<pre><pre class="brush: jscript;">
&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
    $(document).ready(function(){
$(&quot;input&quot;).not( $(&quot;:button&quot;) ).keypress(function (evt) {
if (evt.keyCode == 13) {
iname = $(this).val();
if (iname !== 'Submit'){
var fields = $(this).parents('form:eq(0),body').find('button, input, textarea, select');
var index = fields.index( this );
if ( index &gt; -1 &amp;&amp; ( index + 1 ) &lt; fields.length ) {
fields.eq( index + 1 ).focus();
}
return false;
}
}
});
    });
&lt;/script&gt;
</pre></pre>
<p>If you need some html code to test it with, you can use:</p>
<pre><pre class="brush: xml;">

&lt;form id=&quot;form1&quot; name=&quot;form1&quot; method=&quot;post&quot; action=&quot;http://www.disney.com&quot;&gt;

&lt;label&gt;
&lt;input type=&quot;text&quot; name=&quot;textfield&quot; id=&quot;textfield&quot; /&gt;
&lt;/label&gt;
&lt;label&gt;
&lt;input type=&quot;text&quot; name=&quot;textfield2&quot; id=&quot;textfield2&quot; /&gt;
&lt;/label&gt;
&lt;label&gt;
&lt;input type=&quot;text&quot; name=&quot;textfield3&quot; id=&quot;textfield3&quot; /&gt;
&lt;/label&gt;

&lt;label&gt;
&lt;input type=&quot;submit&quot; name=&quot;button&quot; id=&quot;button&quot; value=&quot;Submit&quot; /&gt;
&lt;/label&gt;
&lt;/form&gt;

</pre></pre>
<p>If you&#8217;d prefer, you can try a live demo of the <a href="/downloads/enter-to-tab.html">Enter to Tab</a> on this site.</p>




	<a rel="nofollow" class="digg" target="_blank" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fmake-enter-key-tab-in-forms%252F%26amp%3Btitle%3DMake%2520Enter%2520Key%2520Tab%2520in%2520Forms%26amp%3Bbodytext%3DSometimes%252C%2520web%2520browsers%2520really%2520suck.%2520Default%2520form%2520behaviors%2520are%2520a%2520major%2520cause%2520for%2520suckage%2520-%2520but%25C2%25A0%2520good%2520UI%2520developers%2520can%2520override%2520them.%2520Heck%252C%2520if%2520you%2520know%2520how%2520to%2520copy%2520and%2520paste%252C%2520you%2527re%2520halfway%2520there.%2520I%2527ve%2520patched%2520together%2520the%2520following%2520script%252C%2520which%2520c';" title="Digg"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" class="sphinn" target="_blank" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fmake-enter-key-tab-in-forms%252F';" title="Sphinn"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" class="del.icio.us" target="_blank" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fmake-enter-key-tab-in-forms%252F%26amp%3Btitle%3DMake%2520Enter%2520Key%2520Tab%2520in%2520Forms%26amp%3Bnotes%3DSometimes%252C%2520web%2520browsers%2520really%2520suck.%2520Default%2520form%2520behaviors%2520are%2520a%2520major%2520cause%2520for%2520suckage%2520-%2520but%25C2%25A0%2520good%2520UI%2520developers%2520can%2520override%2520them.%2520Heck%252C%2520if%2520you%2520know%2520how%2520to%2520copy%2520and%2520paste%252C%2520you%2527re%2520halfway%2520there.%2520I%2527ve%2520patched%2520together%2520the%2520following%2520script%252C%2520which%2520c';" title="del.icio.us"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" class="rss" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.latentmotion.com%2Ffeed%2F';" title="RSS"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow" class="twitter" target="_blank" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DMake%2520Enter%2520Key%2520Tab%2520in%2520Forms%2520-%2520http%253A%252F%252Fwww.latentmotion.com%252Fmake-enter-key-tab-in-forms%252F';" title="Twitter"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.latentmotion.com/make-enter-key-tab-in-forms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Separating jQuery Functions into External Files (without selectors!)</title>
		<link>http://www.latentmotion.com/separating-jquery-functions-into-external-files-without-selectors/</link>
		<comments>http://www.latentmotion.com/separating-jquery-functions-into-external-files-without-selectors/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 13:00:54 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[external javascript]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[javascript files]]></category>
		<category><![CDATA[javascript function]]></category>
		<category><![CDATA[jquery function]]></category>
		<category><![CDATA[separating javascript]]></category>

		<guid isPermaLink="false">http://www.latentmotion.com/?p=336</guid>
		<description><![CDATA[In javascript, writing reusable blocks of code is easy. You simply enter something like: &#8220;function myFunction() { &#8230; }&#8221;, and then you later call it by simply writing &#8220;myFunction();&#8221;. Consequently, when I write jQuery, I often use this javascript shorthand within my jQuery ready tags. As long as all the code stays in a single [...]]]></description>
			<content:encoded><![CDATA[<p>In javascript, writing reusable blocks of code is easy. You simply enter something like: &#8220;function myFunction() { &#8230; }&#8221;, and then you later call it by simply writing &#8220;myFunction();&#8221;. Consequently, when I write jQuery, I often use this javascript shorthand within my jQuery ready tags. As long as all the code stays in a single file, things go smoothly.</p>
<p>But sometimes code grows, and when it does, you&#8217;ve got to separate your logic into separate external js files. That&#8217;s when things break. You see, in each of these external files, you now have to separately reiterate the jQuery ready tags, and when you do, you&#8217;ve buried your functions in a (jQuery) function, rendering it hidden. Out of scope. Or as the error console will tell you, &#8220;Missing&#8221;.</p>
<p>The trick is to create a jQuery function. There are articles all over the place that tell you how to do this. But every one that I&#8217;ve found seems to assume that you want your function to act on a selector. What I needed (and you may as well), was a function that acted just like that regular old javascript function (with jQuery syntax enabled). Believe it or not, all it takes is a minor tweek. Check it out:</p>
<p>External File (tilex.js):</p>
<pre><pre class="brush: jscript;">
  (function($){
    tile = function() {
      $(&quot;body&quot;).append('See? It works.');
    };
  })(jQuery);
</pre></pre>
<p>Inline HTML:</p>
<pre><pre class="brush: xml;">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;HyperStudio Timeline&lt;/title&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;js/tilex.js&quot;&gt;&lt;/script&gt;

  &lt;script type=&quot;text/javascript&quot;&gt;
   $(document).ready(function(){
      tile();
    });
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre></pre>




	<a rel="nofollow" class="digg" target="_blank" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fseparating-jquery-functions-into-external-files-without-selectors%252F%26amp%3Btitle%3DSeparating%2520jQuery%2520Functions%2520into%2520External%2520Files%2520%2528without%2520selectors%2521%2529%26amp%3Bbodytext%3DIn%2520javascript%252C%2520writing%2520reusable%2520blocks%2520of%2520code%2520is%2520easy.%2520You%2520simply%2520enter%2520something%2520like%253A%2520%2522function%2520myFunction%2528%2529%2520%257B%2520...%2520%257D%2522%252C%2520and%2520then%2520you%2520later%2520call%2520it%2520by%2520simply%2520writing%2520%2522myFunction%2528%2529%253B%2522.%2520Consequently%252C%2520when%2520I%2520write%2520jQuery%252C%2520I%2520often%2520use%2520this%2520javascript%2520sho';" title="Digg"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" class="sphinn" target="_blank" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fseparating-jquery-functions-into-external-files-without-selectors%252F';" title="Sphinn"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" class="del.icio.us" target="_blank" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fseparating-jquery-functions-into-external-files-without-selectors%252F%26amp%3Btitle%3DSeparating%2520jQuery%2520Functions%2520into%2520External%2520Files%2520%2528without%2520selectors%2521%2529%26amp%3Bnotes%3DIn%2520javascript%252C%2520writing%2520reusable%2520blocks%2520of%2520code%2520is%2520easy.%2520You%2520simply%2520enter%2520something%2520like%253A%2520%2522function%2520myFunction%2528%2529%2520%257B%2520...%2520%257D%2522%252C%2520and%2520then%2520you%2520later%2520call%2520it%2520by%2520simply%2520writing%2520%2522myFunction%2528%2529%253B%2522.%2520Consequently%252C%2520when%2520I%2520write%2520jQuery%252C%2520I%2520often%2520use%2520this%2520javascript%2520sho';" title="del.icio.us"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" class="rss" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.latentmotion.com%2Ffeed%2F';" title="RSS"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow" class="twitter" target="_blank" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DSeparating%2520jQuery%2520Functions%2520into%2520External%2520Files%2520%2528without%2520selectors%2521%2529%2520-%2520http%253A%252F%252Fwww.latentmotion.com%252Fseparating-jquery-functions-into-external-files-without-selectors%252F';" title="Twitter"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.latentmotion.com/separating-jquery-functions-into-external-files-without-selectors/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Browsers Trim Pixel Decimals</title>
		<link>http://www.latentmotion.com/browsers-trim-pixel-decimals/</link>
		<comments>http://www.latentmotion.com/browsers-trim-pixel-decimals/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 16:00:12 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[browser bug]]></category>
		<category><![CDATA[chrome bug]]></category>
		<category><![CDATA[pixel decimals]]></category>
		<category><![CDATA[pixels]]></category>
		<category><![CDATA[safari bug]]></category>

		<guid isPermaLink="false">http://www.latentmotion.com/?p=272</guid>
		<description><![CDATA[In all browsers but FireFox, if you have 3 equal-height divs stacked that together should equal 100px in height, you&#8217;ll end up with 99px. And if you have 30 divs stacked that together should equal 1000px, you guessed it, they&#8217;ll only reach 990px high. This is because all 33.33~px height divs will be rounded down [...]]]></description>
			<content:encoded><![CDATA[<p>In all browsers but FireFox, if you have 3 equal-height divs stacked that together should equal 100px in height, you&#8217;ll end up with 99px. And if you have 30 divs stacked that together should equal 1000px, you guessed it, they&#8217;ll only reach 990px high. This is because all 33.33~px height divs will be rounded down to 33px, and the remainder is lost.</p>
<p>The best solution to this problem is to save and carry over the decimal point via javascript. Setting each div to be absolutely positioned might work, but is pretty heavy on the browser, and less than ideal for layout. Here&#8217;s what the code change that I&#8217;ve written looks like:</p>
<p><strong>Where my code began as:</strong></p>
<pre><pre class="brush: jscript;">$(&quot;.oneYear li&quot;).css(&quot;height&quot;, someFraction);</pre></pre>
<p><strong>My code became:</strong></p>
<pre><pre class="brush: jscript;">$(&quot;.oneYear li&quot;).each(function(i){
    decFix = (fixSomeFraction%1); // get the decimal value
    fixNewSmallUnitSize = parseInt(fixSomeFraction); // set fix size to an integer
    $(this).css(&quot;height&quot;, fixSomeFraction); // assign height to the fix size
    fixSomeFraction= someFraction + decFix; // add the decimal remainder to the unit size for next time
  });</pre></pre>
<p>First I store the remainder by dividing the fraction by one (in other words, just the stuff after the decimal). Second, I convert the number to an integer, which strips everything after the decimal. I then assign this whole number to the div&#8217;s height. And finally, I add the stored decimal value to the next div, which may or may not be bumped up by one pixel consequently.</p>
<p>What you see happening here is essentially just a slight modification of the loop that jQuery has to make to all the &#8220;.oneYear li&#8221; elements anyway. Although it&#8217;s easy to forget that jQuery performs this work behind the scenes, it does, and knowing that will allow you to most efficiently redefine the process for your own purposes.</p>




	<a rel="nofollow" class="digg" target="_blank" href="javascript:window.location='http%3A%2F%2Fdigg.com%2Fsubmit%3Fphase%3D2%26amp%3Burl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fbrowsers-trim-pixel-decimals%252F%26amp%3Btitle%3DBrowsers%2520Trim%2520Pixel%2520Decimals%26amp%3Bbodytext%3DIn%2520all%2520browsers%2520but%2520FireFox%252C%2520if%2520you%2520have%25203%2520equal-height%2520divs%2520stacked%2520that%2520together%2520should%2520equal%2520100px%2520in%2520height%252C%2520you%2527ll%2520end%2520up%2520with%252099px.%2520And%2520if%2520you%2520have%252030%2520divs%2520stacked%2520that%2520together%2520should%2520equal%25201000px%252C%2520you%2520guessed%2520it%252C%2520they%2527ll%2520only%2520reach%2520990px%2520high';" title="Digg"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" class="sphinn" target="_blank" href="javascript:window.location='http%3A%2F%2Fsphinn.com%2Findex.php%3Fc%3Dpost%26m%3Dsubmit%26link%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fbrowsers-trim-pixel-decimals%252F';" title="Sphinn"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/sphinn.png" title="Sphinn" alt="Sphinn" class="sociable-hovers" /></a>
	<a rel="nofollow" class="del.icio.us" target="_blank" href="javascript:window.location='http%3A%2F%2Fdelicious.com%2Fpost%3Furl%3Dhttp%253A%252F%252Fwww.latentmotion.com%252Fbrowsers-trim-pixel-decimals%252F%26amp%3Btitle%3DBrowsers%2520Trim%2520Pixel%2520Decimals%26amp%3Bnotes%3DIn%2520all%2520browsers%2520but%2520FireFox%252C%2520if%2520you%2520have%25203%2520equal-height%2520divs%2520stacked%2520that%2520together%2520should%2520equal%2520100px%2520in%2520height%252C%2520you%2527ll%2520end%2520up%2520with%252099px.%2520And%2520if%2520you%2520have%252030%2520divs%2520stacked%2520that%2520together%2520should%2520equal%25201000px%252C%2520you%2520guessed%2520it%252C%2520they%2527ll%2520only%2520reach%2520990px%2520high';" title="del.icio.us"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" class="rss" target="_blank" href="javascript:window.location='http%3A%2F%2Fwww.latentmotion.com%2Ffeed%2F';" title="RSS"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow" class="twitter" target="_blank" href="javascript:window.location='http%3A%2F%2Ftwitter.com%2Fhome%3Fstatus%3DBrowsers%2520Trim%2520Pixel%2520Decimals%2520-%2520http%253A%252F%252Fwww.latentmotion.com%252Fbrowsers-trim-pixel-decimals%252F';" title="Twitter"><img src="http://www.latentmotion.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.latentmotion.com/browsers-trim-pixel-decimals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
