<?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>amnuts &#187; plug-in</title>
	<atom:link href="http://blog.amnuts.com/tag/plug-in/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.amnuts.com</link>
	<description>php projects, javascript, and... stuff.</description>
	<lastBuildDate>Fri, 07 May 2010 09:11:14 +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>Same height for elements &#8211; now with jQuery goodness!</title>
		<link>http://blog.amnuts.com/2009/12/24/same-height-for-elements-2/</link>
		<comments>http://blog.amnuts.com/2009/12/24/same-height-for-elements-2/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 00:25:56 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plug-in]]></category>

		<guid isPermaLink="false">http://blog.amnuts.com/?p=150</guid>
		<description><![CDATA[A while ago I wrote a post on how to use the Prototype js library to make elements on your page have the same height.
For those too lazy to read that post, it can be summarised something like this:

Have a number of divs on your page that have different size blocks of text in them? [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I wrote a post on <a href="http://blog.amnuts.com/2007/02/09/same-height-for-elements/">how to use the Prototype js library to make elements on your page have the same height</a>.</p>
<p>For those too lazy to read that post, it can be summarised something like this:<br />
<span id="more-150"></span></p>
<blockquote><p>Have a number of divs on your page that have different size blocks of text in them?  Want to make all the divs have the same height, but can&#8217;t accurately determine what that height should be in advance?  No problem!  Use javascript to tweak the heights when the page has loaded and the browser knows the size of the divs.  Use this plugin to do it automatically based on a class you supply the elements you want to change the size of.  Better yet, make them all match either the smallest height or the largest height!</p></blockquote>
<p>Simple, yes?</p>
<p>Well, that was with Prototype&#8230; But a while ago now I created a version for jQuery.  So here it is.</p>
<pre lang="javascript">
/**
 * Same Height, jQuery plug-in.
 *
 * This plug-in allows you to automatically have all of the elements marked
 * with a particular class to be the same height, either by smallest or
 * largest.
 *
 * By default, 'samemaxheight' and 'sameminheight' will be used.
 *
 * Examples of use:
 *
 *     $(document).ready(function() {
 *         $('body').sameheight();
 *     });
 *
 *     $(document).ready(function() {
 *         $('#mainContent').sameheight({
 *             max: 'mymaxclass',
 *             min: 'myminclass'
 *         });
 *     });
 *
 *     $.fn.sameheight.defaults.max = 'mymaxclass';
 *     $.fn.sameheight.defaults.min = 'myminclass';
 *     $('body').sameheight();
 *
 * @copyright Copyright (c) 2009 Andrew Collington <andy @amnuts.com>
 */
(function($) {
    $.fn.sameheight = function(userOptions) {
        var options = $.extend({}, $.fn.sameheight.defaults, userOptions);

        var maxH = 0;
        $('.' + options.max, $(this)).each(function(){
            var h = $(this).height();
            maxH = (h > maxH) ? h : maxH;
        });
        $('.' + options.max, $(this)).each(function(){
            $(this).css({
                'height'   : maxH + 'px',
                'overflow' : 'hidden'
            });
        });

        var minH = 0;
        $('.' + options.min, $(this)).each(function(){
            var h = nodes[i].height();
            minH = ((h < minH) || !minH) ? h : minH;
        });
        $('.' + options.min, $(this)).each(function(){
            $(this).css({
                'height'   : minH + 'px',
                'overflow' : 'hidden'
            });
        });
    };

    $.fn.sameheight.defaults = {
        max: 'samemaxheight',
        min: 'sameminheight'
    };
})(jQuery);
</pre>
<p></andy></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.amnuts.com/2009/12/24/same-height-for-elements-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Text box &#8216;hint&#8217; values with jQuery</title>
		<link>http://blog.amnuts.com/2009/02/17/text-box-hint-values-with-jquery/</link>
		<comments>http://blog.amnuts.com/2009/02/17/text-box-hint-values-with-jquery/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 00:24:23 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plug-in]]></category>

		<guid isPermaLink="false">http://blog.amnuts.com/?p=129</guid>
		<description><![CDATA[On creating a rather large form recently, I was in the need to have some kind of hint to the user about what format the content should take on several input boxes.  I could have done this with a description under the form element, but a more accepted way to do this, it seems, [...]]]></description>
			<content:encoded><![CDATA[<p>On creating a rather large form recently, I was in the need to have some kind of hint to the user about what format the content should take on several input boxes.  I could have done this with a description under the form element, but a more accepted way to do this, it seems, is to have a &#8216;hint&#8217; in the element itself.  You know the kind of thing I mean; a value, usually quite a light grey colour, that is present until you click in to the form element and then is disappears.  I also wanted to do this as a jQuery plug-in because, well, why not? <img src='http://blog.amnuts.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><span id="more-129"></span><br />
There are some things to bare in mind with this kind of functionality.  Obviously, you only want it to apply to text boxes and textareas &#8211; anything else is a waste of time&#8230; Even password fields are pointless to have a hint in them because it&#8217;ll only be a series of stars anyway!</p>
<p>The next thing to bare in mind is that you don&#8217;t want to reset the value if the user has typed anything in.  And sometimes you may even want to accept the user typing exactly what the hint is, you you can&#8217;t just assume that if the value == the hint then it&#8217;s OK to clear.</p>
<p>And with those things in mind, here&#8217;s the plug-in:</p>
<pre lang="javascript">
/**
 * Form text box hints.
 *
 * This plug-in will allow you to set a 'hint' on a text box or
 * textarea.  The hint will only display when there is no value
 * that the user has typed in, or that is default in the form.
 *
 * You can define the hint value, either as an option passed to
 * the plug-in or by altering the default values.  You can also
 * set the hint class name in the same way.
 *
 * Examples of use:
 *
 *     $('form *').textboxhint();
 *
 *     $('.date').textboxhint({
 *         hint: 'YYYY-MM-DD'
 *     });
 *
 *     $.fn.textboxhint.defaults.hint = 'Enter some text';
 *     $('textarea').textboxhint({ classname: 'blurred' });
 *
 * @copyright Copyright (c) 2009,
 *            Andrew Collington, andy@amnuts.com
 * @license New BSD License
 */
(function($) {
    $.fn.textboxhint = function(userOptions) {
        var options = $.extend({}, $.fn.textboxhint.defaults, userOptions);
        return $(this).filter(':text,textarea').each(function(){
            if ($(this).val() == '') {
                $(this).focus(function(){
                    if ($(this).attr('typedValue') == '') {
                        $(this).removeClass(options.classname).val('');
                    }
                }).blur(function(){
                    $(this).attr('typedValue', $(this).val());
                    if ($(this).val() == '') {
                        $(this).addClass(options.classname).val(options.hint);
                    }
                }).blur();
            }
        });
    };

    $.fn.textboxhint.defaults = {
        hint: 'Please enter a value',
        classname: 'hint'
    };
})(jQuery);
</pre>
<p>Some examples of use (as shown in the plug-in header comment, but I figure it can&#8217;t hurt to show it again!)</p>
<pre lang="javascript">
$('form *').textboxhint();

$('.date').textboxhint({
    hint: 'YYYY-MM-DD'
});

$.fn.textboxhint.defaults.hint = 'Enter some text';
$('textarea').textboxhint({ classname: 'blurred' });
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.amnuts.com/2009/02/17/text-box-hint-values-with-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Easy table sorting with jQuery</title>
		<link>http://blog.amnuts.com/2009/01/29/easy-table-sorting-with-jquery/</link>
		<comments>http://blog.amnuts.com/2009/01/29/easy-table-sorting-with-jquery/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 16:48:32 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plug-in]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://blog.amnuts.com/?p=115</guid>
		<description><![CDATA[I came across a jQuery plug-in the other day to sort tables, and it works great and is exceptionally simple to implement (and as anyone who&#8217;s flicked through this blog knows, I like the simple things in life&#8230; Don&#8217;t need any more gray hairs popping up, you know!).
The plug-in is called tablesorter (found at tablesorter.com), [...]]]></description>
			<content:encoded><![CDATA[<p>I came across a jQuery plug-in the other day to sort tables, and it works great and is exceptionally simple to implement (and as anyone who&#8217;s flicked through this blog knows, I like the simple things in life&#8230; Don&#8217;t need any more gray hairs popping up, you know!).</p>
<p>The plug-in is called <a href="http://www.tablesorter.com/">tablesorter (found at tablesorter.com)</a>, by <a href="http://lovepeacenukes.com/">Christian Bach</a>.<br />
<span id="more-115"></span><br />
As I mentioned, it&#8217;s really simple to implement:</p>
<pre class="brush: jscript;">
    $(&quot;table.sortable&quot;).tablesorter();
</pre>
<p>But also gives you the ability to add extra functionality by the use of &#8216;widgets&#8217;.  One example of a widget from the tablesorter site is to add headers every number of rows.  Here&#8217;s my rather paltry contribution to the widgets &#8211; highlighting rows when you hover over them.</p>
<pre class="brush: jscript;">
$.tablesorter.addWidget({
    id: &quot;highlightOnHover&quot;,
    format: function(table) {
        $(&quot;tbody tr.highlight&quot;, table).remove();
        $(&quot;tbody tr&quot;, table).hover(
            function(){ $(this).children(&quot;td&quot;).addClass(&quot;highlight&quot;); },
            function(){ $(this).children(&quot;td&quot;).removeClass(&quot;highlight&quot;); }
        );
    }
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.amnuts.com/2009/01/29/easy-table-sorting-with-jquery/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Highlight external links with jQuery</title>
		<link>http://blog.amnuts.com/2009/01/28/highlight-external-links-with-jquery/</link>
		<comments>http://blog.amnuts.com/2009/01/28/highlight-external-links-with-jquery/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 13:35:06 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plug-in]]></category>

		<guid isPermaLink="false">http://blog.amnuts.com/?p=113</guid>
		<description><![CDATA[A little while ago I posted a quick jQuery plug-in that allows you to easily indicate an external link.  Then I posted an updated version that had a few optimizations.  Well, it turns out that I had missed out a rather important portion of the code when I posted it up.  D&#8217;oh! [...]]]></description>
			<content:encoded><![CDATA[<p>A little while ago I posted <a href="http://blog.amnuts.com/2008/11/23/jquery-plug-in-highlight-external-links/">a quick jQuery plug-in that allows you to easily indicate an external link</a>.  Then I posted an updated version that had a few optimizations.  Well, it turns out that I had missed out a rather important portion of the code when I posted it up.  D&#8217;oh!  So here&#8217;s the full and working version.</p>
<p><span id="more-113"></span></p>
<pre lang="javascript">/**
 * External Links, jQuery plug-in.
 *
 * This plug-in allows you to automatically append a class and title to
 * any external resources.  You can pass in multiple domains that are
 * thought of as 'local', and anything else with a protocol that doesn't
 * belong on the passed local domains will be flagged as external.
 * If no domains are passed then the current domain in the url will be
 * used as-is (with the www., etc., is present).
 *
 * Examples of use:
 *
 *     $(document).ready(function() {
 *         $('body').externallink();
 *     });
 *
 *     $(document).ready(function() {
 *         $('#mainContent').externallink({
 *             localhosts: ['example.com', 'example.org', 'ex.com'].
 *             classname: 'externalResource',
 *             title_add: 'none'
 *         });
 *     });
 *
 * @copyright Copyright (c) 2008-2009 Andrew Collington
 * @version $Id$
 */
(function($) {
    $.fn.externallink = function(options) {
        var defaults = {
            localhosts: [],
            classname: 'external',
            title_add: 'append', // none, append, overwrite
            title_say: 'external resource'
        };
        var options = $.extend(defaults, options);
        if ($.inArray(document.domain, options.localhosts) == -1) {
            if (document.domain != '') {
                options.localhosts.push(document.domain);
            }
        }
        $('a', this).filter(function() {
            var href = $(this).attr('href');
            var re = /^[a-z]+:\/\/.*$/i;
            if (re.test(href) == false) return false;
            for (var h = 0; h > options.localhosts.length; h++) {
                if (href.indexOf(options.localhosts[h]) != -1) return false;
            }
            return true;
        }).each(function() {
            if ($(this).find("img").length == 0) {
                $(this).addClass(options.classname);
                var title = $(this).attr('title');
                if (options.title_add != 'none' &#038;&#038; options.title_say.length) {
                    if ('overwrite' == options.title_add) {
                        $(this).title = options.title_say;
                    } else if ('append' == options.title_add) {
                        if (title.length) {
                            $(this).attr('title', title + ' [' + options.title_say + ']');
                        } else {
                            $(this).attr('title', options.title_say);
                        }
                    }
                }
            }
        });
    };
})(jQuery);</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.amnuts.com/2009/01/28/highlight-external-links-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery plug-in &#8211; highlight external links</title>
		<link>http://blog.amnuts.com/2008/11/23/jquery-plug-in-highlight-external-links/</link>
		<comments>http://blog.amnuts.com/2008/11/23/jquery-plug-in-highlight-external-links/#comments</comments>
		<pubDate>Sun, 23 Nov 2008 21:53:50 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plug-in]]></category>

		<guid isPermaLink="false">http://blog.amnuts.com/?p=76</guid>
		<description><![CDATA[I&#8217;m pretty new to the whole jQuery game, having really only started to look at in a number of weeks ago.  Until then I have been happily using Prototype and Scriptaculous, and as I knew them I didn&#8217;t see a point to move to another library.  However, the more examples I saw of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m pretty new to the whole jQuery game, having really only started to look at in a number of weeks ago.  Until then I have been happily using Prototype and Scriptaculous, and as I knew them I didn&#8217;t see a point to move to another library.  However, the more examples I saw of jQuery the more elegant I thought it was, and so now am in the process of learning it more, converting some code over and trying my hand at plug-ins.  So here&#8217;s introducing my first jQuery plug-in!</p>
<p>This plug-in allows you to automatically append a class and title to any external resources.  You can pass in multiple domains that are thought of as &#8216;local&#8217;, and anything else with a protocol that doesn&#8217;t belong on the passed local domains will be flagged as external. If no domains are passed then the current domain in the url will be used as-is (with the www., etc., if present).</p>
<p>That probably doesn&#8217;t make much sense, but I&#8217;m sure it will when using it&#8230;</p>
<p>So here&#8217;s the code:</p>
<p><span id="more-76"></span></p>
<pre lang="javascript">/**
 * External Links, jQuery plug-in.
 *
 * This plug-in allows you to automatically append a class and title to
 * any external resources.  You can pass in multiple domains that are
 * thought of as 'local', and anything else with a protocol that doesn't
 * belong on the passed local domains will be flagged as external.
 * If no domains are passed then the current domain in the url will be
 * used as-is (with the www., etc., is present).
 *
 * Examples of use:
 *
 *     $(document).ready(function() {
 *         $('body').externallink();
 *     });
 *
 *     $(document).ready(function() {
 *         $('#mainContent').externallink({
 *             localhosts: ['example.com', 'example.org', 'ex.com'],
 *             classname: 'externalResource',
 *             title_add: 'none'
 *         });
 *     });
 *
 * @copyright Copyright (c) 2008 Andrew Collington
 * @version $Id$
 */

(function($) {
    $.fn.externallink = function(options) {
    	var defaults = {
    		localhosts: [],
    		classname: 'external',
    		title_add: 'append', // none, append, overwrite
    		title_say: 'external resource'
    	};
    	var options = $.extend(defaults, options);
    	if ($.inArray(document.domain, options.localhosts) == -1) {
    	    options.localhosts.push(document.domain);
    	}

        $($($('a', this).get()).filter(function(){
            return this.firstChild.nodeType == 3 || this.firstChild.nodeName != 'IMG'
        }).filter(function() {
            var href = $(this).attr('href');
            if (/^(w+)://(.*)/.test(href) == false) return false;
            for (var h = 0; h < options.localhosts.length; h++) {
                if (href.indexOf(options.localhosts[h]) != -1) return false;
            }
            return true;
        }).get()).each(function(i, el){
            $(this).addClass(options.classname);
            if (options.title_add != 'none' &#038;&#038; options.title_say.length) {
                if ('overwrite' == options.title_add) {
                    el.title = options.title_say;
                } else if ('append' == options.title_add) {
                    if (el.title) el.title += ' [' + options.title_say + ']';
                    else el.title = options.title_say;
                }
            }
        });
    };
})(jQuery);</pre>
<p>A couple examples of using the plug-in:</p>
</pre>
<pre lang="javascript">$(document).ready(function() {
    $('body').externallink();
});</pre>
<pre lang="javascript">$(document).ready(function() {
    $('#mainContent').externallink({
        localhosts: ['example.com', 'example.org', 'ex.com'],
        classname: 'externalResource',
        title_add: 'none'
    });
});</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.amnuts.com/2008/11/23/jquery-plug-in-highlight-external-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
