<?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>Skull Jackpot &#187; plugin</title>
	<atom:link href="http://skulljackpot.com/tagged-as/plugin/feed/" rel="self" type="application/rss+xml" />
	<link>http://skulljackpot.com</link>
	<description>Various thoughts of minimal interest to others</description>
	<lastBuildDate>Fri, 25 Feb 2011 16:22:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Super CSS Selector Support with jQuery</title>
		<link>http://skulljackpot.com/2009/04/19/super-css-selector-support-with-jquery/</link>
		<comments>http://skulljackpot.com/2009/04/19/super-css-selector-support-with-jquery/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 22:18:47 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Under the hood]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[selector]]></category>

		<guid isPermaLink="false">http://skulljackpot.com/?p=61</guid>
		<description><![CDATA[Tired of having to add classes in your markup to work around lousy CSS selector support in legacy browsers? Try SuperSelectors - a jQuery plugin enabling great CSS selector support, even in IE6.]]></description>
			<content:encoded><![CDATA[<p>CSS provides a wide array of selectors to specify which elements should be subject to a particular style. CSS 2.1 gives web designers even more granularity when targeting specific elements. This is great in theory. But browser support for these selectors has lagged behind, and IE6 support is limited to only the most basic selectors. This has led to most folks working in the real world stashing the more advanced selectors away for rainy-day experimentation, or idle dreams about the eventual time when we can <em>use</em> these tools.</p>
<h2>Current State of Affairs</h2>
<p>Web folks are a clever bunch, though. If browser support for CSS won&#8217;t give us a way to target a particular element, a common solution is to make classes do the heavy lifting for us. Going through files to add <code>class="text"</code> to <strong>every</strong> text input is an all-too-common experience for web designers.</p>
<p>Adding the classes allows us to target elements on all browsers, but is labor-intensive and potentially error-prone. Moreover, if your site includes content (like comments or blog posts) which will entered by users, you have no easy way to ensure those classes are added appropriately.</p>
<h2>A Glimmer of Hope</h2>
<p>jQuery is one of several great javascript frameworks which have burst onto the scene in the past year or so. One of the reasons jQuery has gotten a lot of attention from web designers is the way it allows you to select elements &#8211; in many cases, jQuery selectors are <em>identical</em> to CSS selectors. jQuery is also extremely extensible. If there&#8217;s functionality you need which isn&#8217;t provided by the core framework, you can easily add it via a plugin (or by extending jQuery directly).</p>
<p>In the course of a recent project, I used jQuery to add a <code>first-child</code> class to some <code>&lt;li&gt;</code> elements in our top navigation, to shore up IE6 CSS support without having to alter the markup. After seeing how easy jQuery made that, I realized it&#8217;s be possible to write a plugin allowing <em>any</em> browser supported by jQuery capable of supporting <strong>all</strong> CSS 2.1 selectors. So I wrote SuperSelectors. It goes through your site&#8217;s stylesheets, dynamically adding classes to elements so that even IE6 can bask in the glow of properly supporting CSS selectors like <code>ul li:first-child li:nth-child(odd) a:hover</code>.</p>
<h2>Pencils out</h2>
<p>Before we can start to determine which elements ought to have classes added, we&#8217;ll need a way to access each stylesheet being used by a given page. Fortunately, the <code>document.styleSheets</code> array does exactly what we want. Unfortunately, we have to incur a little bit of overhead here. Since browsers will silently excise rules they don&#8217;t understand, we have to re-request the CSS files via javascript, and parse <em>those</em> for matches.</p>
<p>Now, the fact that jQuery supports CSS selector syntax comes in really handy. We can pass the matching CSS rules directly to jQuery, and add classes appropriately. Then, any browser supported by jQuery can properly target elements, even useful-but-not-broadly-supported CSS rules like <code>ul li:first</code>. All we need to do to have classes added to match any of the rules in our CSS is include jQuery and the SuperSelectors plugin, and add the following javascript:</p>
<pre>$(document).ready(function() {
  $(document).superSelectify();
});</pre>
<p>This is a great start, but some of us are maintaining sites with established conventions for element classnames. Maybe you&#8217;re working on an educational site, and the <code>child</code> is already reserved for another context. No problem. SuperSelectors will allow custom classes to be passed in, while still providing sensible defaults. You can override any (or all) of the default classnames. If you need to alter the class attached to child elements to be <code>child-element</code>, your javascript would just change to be:</p>
<pre>$(document).ready(function() {
  $(document).superSelectify({childClass: "child-element"});
});</pre>
<h2>Attribution needed</h2>
<p>What about special cases which fall outside the normal advanced selectors? Maybe we need to have styles applied conditionally, based on attributes. For example, maybe the links in your file download list should have an icon based on the extension of the file they&#8217;re pointing to. CSS 2.1 allows us to target elements based on attribute values &#8211; we can even match against substrings within the attribute value, which is a perfect fit for finding the file extensions of our links. The number of potential choices for attribute selectors alone is more than we can reasonably build into a single plugin, but fortunately SuperSelectors supports arbitrary selectors through the <code>additionalElementHash</code> attribute. This can be done with or without overriding the default classnames. A setup which addressed the file-type requirement mentioned above would look like this:</p>
<pre>$(document).ready(function() {
  $(document).superSelectify({additionalElementHash: {jpeg: 'a[href$=".jpg"]', pdf: 'a[href$=".pdf"]', doc: 'a[href$=".doc"]', gif: 'a[href$=".gif"]', xls: 'a[href$=".xls"]', png: 'a[href$=".png"]'}});
});</pre>
<p>A little more effort than the no-argument invocation, but that will enable matching almost any elements you can think of &#8211; you&#8217;re only limited by jQuery&#8217;s selector support, which is one of the best out there.</p>
<h2>Hovercraftiness</h2>
<p>It&#8217;s probably time to acknowledge the elephant in the room &#8211; specifically, the fact that IE6 only supports the <code>:hover</code> pseudo-selector for anchor tags. Through the years, there have been a variety of approaches to add this in, including Peter Nederlof&#8217;s <a href="http://www.xs4all.nl/~peterned/csshover.html">whatever:hover</a>. This is all well and good, but it&#8217;d be nice to be able to have one-stop shopping for all our CSS needs. Fortunately, jQuery makes it easy for us to add this functionality into Super Selectors. Declare your <code>:hover</code> rules normally, add an equivalent rule using the <code>hover</code> class, and SuperSelectors will take care of adding / removing the classnames from elements on mouseover.</p>
<h2>Faster, faster</h2>
<p>Things are really shaping up nicely. Any browser which jQuery supports can now use virtually any legitimate CSS selector, but we can still do better. If we know which advanced selectors our site will need to support, it seems wasteful to have to re-request all those CSS files, and then scan them for matches. In fact, on slow connections, or with sufficiently-large amount of CSS, users could see a page without the added classes for a fraction of a second, similar to the old <a href="http://en.wikipedia.org/wiki/Flash_of_unstyled_content">Flash of Unstyled Content</a> bug.</p>
<p>SuperSelectors makes it simple to avoid the unnecessary request/parsing overhead and display properly-classed markup right away. You just need to pass in all your selectors via the <code>manualSelectors</code> attribute, as a comma-delimited list. As with everything else, it can be used solo or in combination with any other arguments.:</p>
<pre>$(document).ready(function() {
  $(document).superSelectify({childClass: "child-element", manualSelectors: 'div.example > ul, ul.sample li:first, input[type="text"], input[type="password"]'}});
});</pre>
<p>For complex CSS needs, this may require a fair amount of work. However, this approach saves us from having to re-request and parse all the CSS files in use. Consequently, it will be <em>much</em> faster &#8211; especially for sites with large (or large numbers of) CSS files. <a href="http://sandbox.skulljackpot.com/superselectors/demo/">Check out the example</a>.</p>
<h2>One caveat</h2>
<p>SuperSelectors does a lot to help enable better CSS selector support across browsers, but it can&#8217;t do everything for us. We still need rules in our CSS which use the classes SuperSelectors will add.</p>
<p>Because Internet Explorer will discard the entire rule if it doesn&#8217;t understand one of the selectors, we do have to do a little duplication in our CSS. That means that, instead of</p>
<pre>div.example > ul,
div.example ul.child {
background: #0f0;
color: #f0f;
}</pre>
<p>You should write:</p>
<pre>div.example > ul {
background: #0f0;
color: #f0f;
}

div.example ul.child {
background: #0f0;
color: #f0f;
}</pre>
<h2>In Closing</h2>
<p>The goal of SuperSelectors is to make it possible for all of us to start using CSS 2.1 selectors in our everyday work. It doesn&#8217;t have CSS3 support (yet), but SuperSelectors will automatically benefit as jQuery adds support for CSS3 selectors.</p>
<p>You can download SuperSelectors as a <a href="http://github.com/chrispatterson/jquery-super-selectors/zipball/master">zip</a> or <a href="http://github.com/chrispatterson/jquery-super-selectors/tarball/master">tarball</a>. Github also hosts <a href="http://github.com/chrispatterson/jquery-super-selectors/tree/master">the official SuperSelectors repository</a>, if you&#8217;re interested in helping make SuperSelectors even better.</p>
]]></content:encoded>
			<wfw:commentRss>http://skulljackpot.com/2009/04/19/super-css-selector-support-with-jquery/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Inline Info</title>
		<link>http://skulljackpot.com/2008/11/24/inline-info/</link>
		<comments>http://skulljackpot.com/2008/11/24/inline-info/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 23:43:04 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Under the hood]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://skulljackpot.com/?p=29</guid>
		<description><![CDATA[<p>Making forms as usable and compact as possible is a fairly common goal in web design. Screen real estate is often at a premium, and finding ways to orient and provide information to users which doesn't require additional space can be a great asset.</p>
<p>I decided to write a jQuery plugin to help fill this need.</p>]]></description>
			<content:encoded><![CDATA[<p>Making forms as usable and compact as possible is a fairly common goal in web design. Screen real estate is often at a premium, and finding ways to orient and provide information to users which doesn&#8217;t require additional space can be a great asset.</p>
<p>One common solution is to use the approach written up at <a href="http://www.alistapart.com/articles/makingcompactformsmoreaccessible">A List Apart</a>, which involves using relative and absolute positioning to make labels appear on top of the associated text input. That approach can be brittle when it comes to more complex layouts, however.</p>
<p>Another common solution is to use inline javascript for onfocus and onblur attributes. This has the advantage of being robust in terms of layout, and is the technique currently in use on several of TOPP&#8217;s sites (including four instances on the <a href="http://www.livablestreets.com/projects">LivableStreets.com groups page</a>):</p>
<div class="thumbnail"><a href="http://skitch.com/dimmerswitch/hu8w/livable-streets-groups"><img src="http://img.skitch.com/20081124-ftdgys1pwhrusxwrnf3dcx2yhh.preview.jpg" alt="livable-streets-groups" /></a></div>
<p>This approach is not without drawbacks, though. Inline markup is never as elegant as listeners added via javascript, and  can pose maintainability problems. It&#8217;s easy for multiple instances of functionally-identical inline javascript within a site to diverge, as users make one-off tweaks to handle specific enhancement requests. Additionally, password fields are problematic, as Internet Explorer refuses to allow modification of the &#8220;type&#8221; attribute for input elements which have been added to the DOM.</p>
<p>I decided a while back to write a plugin to address these issues. My goals were to provide a tool which:</p>
<ul>
<li>Allowed informational text to be added to input elements</li>
<li>Was flexible enough to allow multiple ways to declare the text to be used, not just through referencing the relevant &lt;label&gt; element</li>
<li>Would be as robust as possible, in terms of avoiding layout problems</li>
<li>Would be easy for users to implement</li>
</ul>
<p>Things are finally far enough along that I feel comfortable sharing my latest jQuery plugin, <a href="http://github.com/chrispatterson/jquery-inline-info/tree/master">Inline Info</a>.</p>
<h2>Using the plugin</h2>
<p><strong>Note</strong>: this assumes that you&#8217;ve downloaded jQuery (<a href="http://docs.jquery.com/Downloading_jQuery">http://docs.jquery.com/Downloading_jQuery</a>) and the jQuery Inline Info plugin (<a href="http://github.com/chrispatterson/jquery-inline-info/tree/master">http://github.com/chrispatterson/jquery-inline-info/tree/master</a>). All examples can be used at the bottom of the page (immediately before the <code>&lt;/body&gt;</code> tag), or set to fire with <code>$(document).ready</code></p>
<p>When an element with inline info text loses focus, jquery-inline-info checks to see if the current value matches the info text, before resetting the value &amp; changing the class. This is not normally case-sensitive, but this behavior can be changes by passing in the <code>caseSensitiveMatch</code> parameter:</p>
<p><code>$('#ex-field').inlineInfoTextify({caseSensitiveMatch: "true"}); //default is "false"</code></p>
<p>By default, jquery-inline-info will use the <code>title</code> attribute of each input element as the info text. If no <code>title</code> is defined, it will instead use the value of the relevant <code>label</code> element. It&#8217;s also possible to specify the info text to use, by passing in the <code>inlineInfoText</code> parameter:</p>
<p><code>$('#ex-field').inlineInfoTextify({inlineInfoText: "Some very helpful text"});</code></p>
<p>jquery-inline-info also adds a class to input elements, when they are displaying info text. This class is also customizable, by passing in the <code>inlineInfoClass</code> parameter: </p>
<p><code>$('#ex-field').inlineInfoTextify({inlineInfoClass: "my-custom-class"});</code></p>
<p>You can also pass in multiple selectors in a single invocation:</p>
<p><code>$('#ex-field, #ex-field-2').inlineInfoTextify({inlineInfoClass: "my-custom-class"});</code></p>
<p>or selectors which match multiple elements:</p>
<p><code>$('#ex-form input[type="text"]').inlineInfoTextify({inlineInfoClass: "my-custom-class"});</code></p>
<p>The look and feel of the notice is totally customizable through CSS, and I&#8217;ve included a demo in the github repository to show various invocations in action.</p>
<p>Questions? Comments? Enhancement requests to make things more flexible? Put &#8216;em in the comments. I&#8217;m definitely interested in improving things, and about supporting stuff folks need.</p>
]]></content:encoded>
			<wfw:commentRss>http://skulljackpot.com/2008/11/24/inline-info/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Click to Clipboard</title>
		<link>http://skulljackpot.com/2008/10/06/click-to-clipboard/</link>
		<comments>http://skulljackpot.com/2008/10/06/click-to-clipboard/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 20:40:00 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Under the hood]]></category>
		<category><![CDATA[clipboard]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://skulljackpot.com/?p=10</guid>
		<description><![CDATA[<p>Our team uses <a href="http://skitch.com/">Skitch</a> a lot. It's a pretty invaluable tool for communicating visual information - you can easily annotate screenshots or comps. There's great communicative value in being able to point at something, and as a remote employee in my past two jobs, I can't imagine ever collaborating on web work without it.</p>
<p>Skitch does a lot of things well, but one bit of polish which always pops out at new users is the "Click to Clipboard" functionality. Skitch provides lots of ways for you to share your images, and when you click in the appropriate field, the site copies all the data to your computer's clipboard, and presents a nice confirmation that you're ready to paste that elsewhere.</p>]]></description>
			<content:encoded><![CDATA[<p>Our team uses <a href="http://skitch.com/">Skitch</a> a lot. It&#8217;s a pretty invaluable tool for communicating visual information &#8211; you can easily annotate screenshots or comps. There&#8217;s great communicative value in being able to point at something, and as a remote employee in my past two jobs, I can&#8217;t imagine ever collaborating on web work without it.</p>
<p><strong>Aside</strong>: Skitch is Mac-only, but I&#8217;ve heard good things about <a href="http://www.jingproject.com/">Jing</a> if you&#8217;re on Windows. I don&#8217;t know of an equivalent solution on Linux, unfortunately.</p>
<p>Skitch does a lot of things well, but one bit of polish which always pops out at new users is the &#8220;Click to Clipboard&#8221; functionality. Skitch provides lots of ways for you to share your images, and when you click in the appropriate field, the site copies all the data to your computer&#8217;s clipboard, and presents a nice confirmation that you&#8217;re ready to paste that elsewhere:</p>
<div class="thumbnail"><a href="http://skitch.com/dimmerswitch/a7n7/skitch-clipboard-popup"><img src="http://img.skitch.com/20081006-1riux9tfy8ibu8nfwg84ceuqqs.preview.jpg" alt="skitch-clipboard-popup" title="Using Skitch to illustrate a feature on Skitch - so very, very meta." /></a></div>
<p>I decided to create a workalike function in <a href="http://jquery.com/">jQuery</a>, my favorite javascript library. I got a rudimentary version up and running a while back, building on the approach Jeff Larson wrote up, over at <a href="http://www.jeffothy.com/weblog/clipboard-copy/">http://www.jeffothy.com/weblog/clipboard-copy/</a>.</p>
<p>Today, I was able to get my workalike polished up and turned into my first jQuery plugin &#8211; it&#8217;s available at <a href="http://github.com/chrispatterson/jquery-clipboard/tree/master">http://github.com/chrispatterson/jquery-clipboard/tree/master</a>. There are still some pieces of polish I&#8217;m planning to add, but I&#8217;m pretty happy with it so far.</p>
<h3>Using the plugin</h3>
<p><strong>Note</strong>: this assumes that you&#8217;ve downloaded jQuery (<a href="http://docs.jquery.com/Downloading_jQuery">http://docs.jquery.com/Downloading_jQuery</a>), the jQuery Flash plugin (<a href="http://jquery.lukelutman.com/plugins/flash/">http://jquery.lukelutman.com/plugins/flash/</a>), and the jQuery Clipboard plugin (<a href="http://github.com/chrispatterson/jquery-clipboard/tree/master">http://github.com/chrispatterson/jquery-clipboard/tree/master</a>). All examples can be used at the bottom of the page (immediately before the &lt;/body&gt; tag), or set to fire with <code>$(document).ready</code></p>
<p>To add &#8220;click to clipboard&#8221; behavior to the element with an id of <code>share-link</code>:</p>
<p><code>$('#share-link').clickToClipboard();</code></p>
<p>To add &#8220;click to clipboard&#8221; behavior to all elements with a class of <code>shareable</code>:</p>
<p><code>$('.shareable').clickToClipboard();</code></p>
<p>clickToClipboard allows you to customize how long it takes for the notice to fade out, as well as the message used (for cases where you don&#8217;t want to use an image).</p>
<p>To have a slower fade effect, starting 1.5 seconds after the target element loses focus:</p>
<p><code>$('#share-link').clickToClipboard( {fadeoutLength: 900, fadeoutTimer: 1500}););</code></p>
<p>To customize the notice text:</p>
<p><code>$('#share-link').clickToClipboard( {clipboardText: "You're ready to paste!"}););</code></p>
<p>The look and feel of the notice is totally customizable through CSS. I&#8217;ve included a demo in <a href="http://github.com/chrispatterson/jquery-inline-info/tree/master">the github repository</a>, which shows how it might look with a background image. This is my first jQuery plugin, so I&#8217;m definitely open to feedback on ways to structure things better, or enhancement requests on how it be more flexible about supporting stuff folks need.</p>
]]></content:encoded>
			<wfw:commentRss>http://skulljackpot.com/2008/10/06/click-to-clipboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.244 seconds -->

