<?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>Harry Bailey</title>
	<atom:link href="http://harrybailey.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://harrybailey.com</link>
	<description>just a little bit geeky</description>
	<lastBuildDate>Fri, 05 Apr 2013 12:15:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Chrome browser masking PHP errors</title>
		<link>http://harrybailey.com/2013/04/chrome-browser-masking-php-errors/</link>
		<comments>http://harrybailey.com/2013/04/chrome-browser-masking-php-errors/#comments</comments>
		<pubDate>Fri, 05 Apr 2013 12:04:16 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=788</guid>
		<description><![CDATA[I thought I was going mad for a while, but it turns out that sometimes spotting php error messages which come back from the server to the Google Chrome browser can be really tough. If the error is inside an html element or attribute of an html element you&#8217;re going to struggle to see it [...]]]></description>
				<content:encoded><![CDATA[<p>I thought I was going mad for a while, but it turns out that sometimes spotting php error messages which come back from the server to the Google Chrome browser can be really tough.</p>
<p>If the error is inside an html element or attribute of an html element you&#8217;re going to struggle to see it in Google Chrome&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fakeFunction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;link&lt;/a&gt;</pre></div></div>

<p>If $Model doesn&#8217;t have a method called fakeFunction then php will spit a &#8220;Fatal error: Call to a member function&#8221; error. The page that is displayed in Chrome won&#8217;t show you the error and viewing the source will also hide it from you.</p>
<p>Even the elements tab in Chrome Developer Tools won&#8217;t show it.</p>
<p>There only way I&#8217;ve been able to find the error content is to look at the network tab in Chrome and view the raw response of the document back from the server.</p>
<p>A few hours lost on this one!</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2013/04/chrome-browser-masking-php-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add global Twitter Bootstrap modal listeners</title>
		<link>http://harrybailey.com/2012/12/add-global-twitter-bootstrap-modal-listeners/</link>
		<comments>http://harrybailey.com/2012/12/add-global-twitter-bootstrap-modal-listeners/#comments</comments>
		<pubDate>Sat, 08 Dec 2012 20:49:11 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=768</guid>
		<description><![CDATA[If you&#8217;re ever browsed the Twitter Bootstrap javascript documentation then you&#8217;ll know that the modal parts of the Bootstrap library require some javascript to show and hide them. Part of the javascript is related to events which you can attach listeners to so you know when your modal shown and hidden. What they don&#8217;t tell [...]]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;re ever browsed the Twitter Bootstrap javascript documentation then you&#8217;ll know that the modal parts of the Bootstrap library require some javascript to show and hide them.</p>
<p>Part of the javascript is related to events which you can attach listeners to so you know when your modal shown and hidden.</p>
<p>What they don&#8217;t tell you is that you can add a single global (or semi global if you want) listener to all modal events which will fire when any modal is shown or hidden.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">on</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'shown'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'.modal'</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;
	console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'we have shown a modal'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>For example the above will console log &#8220;we have shown a modal&#8221; when any modal is shown. You can switch the shown event to be show, shown, hide or hidden.</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2012/12/add-global-twitter-bootstrap-modal-listeners/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cloning a github project</title>
		<link>http://harrybailey.com/2012/09/cloning-a-github-project/</link>
		<comments>http://harrybailey.com/2012/09/cloning-a-github-project/#comments</comments>
		<pubDate>Sat, 29 Sep 2012 07:59:02 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Git]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=759</guid>
		<description><![CDATA[When you first start on a new web project amongst a group of people someone is likely to create a github project. Rather than then all individually creating a new project on your machine you can do the following&#8230; 1) Browse to your sites folder in Terminal. We&#8217;ll create a new folder for this new [...]]]></description>
				<content:encoded><![CDATA[<p>When you first start on a new web project amongst a group of people someone is likely to create a github project. Rather than then all individually creating a new project on your machine you can do the following&#8230;</p>
<p>1) Browse to your sites folder in Terminal. We&#8217;ll create a new folder for this new project in the next step.</p>
<p>2) use the command <code>git clone git@github.com:whatever folder-name</code> to not only clone the existing github repo, but also to create the folder you want it in</p>
<p>3) <code>cd folder-name</code> to navigate to that folder</p>
<p>4) <code>git add remote remote-name git@github.com:whatever</code> to add a new remote</p>
<p>And you&#8217;re done.</p>
<p>As an added option, if you have already created the folder you would like then you can replace 2) above with navigating to that folder, then&#8230;</p>
<p><code>git clone git@github.com:whatever .</code> note the . character to define &#8216;current folder&#8217;</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2012/09/cloning-a-github-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fix apache after upgrading to Mountain Lion</title>
		<link>http://harrybailey.com/2012/09/day-14-fix-apache-after-upgrading-to-mountain-lion/</link>
		<comments>http://harrybailey.com/2012/09/day-14-fix-apache-after-upgrading-to-mountain-lion/#comments</comments>
		<pubDate>Thu, 20 Sep 2012 10:45:49 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Mac]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=750</guid>
		<description><![CDATA[Every time I upgrade OS X something breaks with apache or php or both. The steps for me to fix it this time was&#8230; * Open your httpd.conf file * uncomment the Load php5 module * uncomment the load vhosts module in etc/apache2/users * duplicate Guest.conf to harrybailey.conf &#8211; replace harrybailey with your username obviously [...]]]></description>
				<content:encoded><![CDATA[<p>Every time I upgrade OS X something breaks with apache or php or both.</p>
<p>The steps for me to fix it this time was&#8230;</p>
<p>* Open your httpd.conf file<br />
* uncomment the Load php5 module<br />
* uncomment the load vhosts module</p>
<p>in etc/apache2/users</p>
<p>* duplicate Guest.conf to harrybailey.conf &#8211; replace harrybailey with your username obviously<br />
* edit harrybailey.conf to read:</p>
<pre>
&lt;Directory "/Users/harrybailey/Sites/"&gt;
    Options Indexes MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
&lt;/Directory&gt;
</pre>
<p><strong>Note:</strong> as Michal mentions below you may want to add +FollowSymLinks to your options too. This allows the system to follow any symbolic links you have set up.</p>
<p>AGAIN &#8211; replace harrybailey with your username.</p>
<p>* save the file</p>
<p>You may also get a php error which includes&#8230;</p>
<p>&#8220;It is not safe to rely on the system&#8217;s timezone settings&#8221;</p>
<p>The fix for that is<br />
* navigate to /etc/ and rename php.ini.default to php.ini<br />
* edit your new php.ini file &#8211; find &#8220;;date.timezone = &#8221; (no brackets)<br />
* update it to read &#8220;date.timezone = Europe/London&#8221; (no brackets) &#8211; if you aren&#8217;t on GMT then find your relevant timezone string and use that<br />
* save the file</p>
<p>* open terminal<br />
* submit the line:<br />
sudo apachectl restart</p>
<p>That did it for me. Hopefully it will do it for you too.</p>
<p>I was first seeing the default html file in the /Library/Webserver/Documents folder<br />
I was then seeing 403 errors for all vhosts that I has setup<br />
Personally I saw these problems after upgrading from Lion (10.7) to Mountain Lion (10.8)</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2012/09/day-14-fix-apache-after-upgrading-to-mountain-lion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Export structure and data from Navicat Premium as SQL</title>
		<link>http://harrybailey.com/2012/09/day-12-export-structure-and-data-from-navicat-premium-as-sql/</link>
		<comments>http://harrybailey.com/2012/09/day-12-export-structure-and-data-from-navicat-premium-as-sql/#comments</comments>
		<pubDate>Tue, 18 Sep 2012 10:56:23 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[apps]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=744</guid>
		<description><![CDATA[I was trying to find the quickest way to export both structure and data from all tables of a database from Navicat Premium and came up with these steps: * Use the backup tool to create a backup of your database * Right click the backup and select to Extract SQL&#8230; * Save to wherever [...]]]></description>
				<content:encoded><![CDATA[<p>I was trying to find the quickest way to export both structure and data from all tables of a database from Navicat Premium and came up with these steps:</p>
<p>* Use the backup tool to create a backup of your database<br />
* Right click the backup and select to Extract SQL&#8230;<br />
* Save to wherever you like</p>
<p>You can now use that .sql file to create a new database wherever you like.</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2012/09/day-12-export-structure-and-data-from-navicat-premium-as-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cloning rows in a mysql table</title>
		<link>http://harrybailey.com/2012/09/day-11-cloning-rows-in-a-mysql-table/</link>
		<comments>http://harrybailey.com/2012/09/day-11-cloning-rows-in-a-mysql-table/#comments</comments>
		<pubDate>Thu, 13 Sep 2012 06:58:51 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=741</guid>
		<description><![CDATA[If you have a lot of data in a mysql table and you&#8217;d like to duplicate some of the rows &#8211; maybe with a change or two as well &#8211; then here is the sql you&#8217;ll need&#8230; INSERT INTO table (column1, column2,column3, column4) SELECT column1, 234, column4, NOW() FROM table WHERE id IN (6,7) You [...]]]></description>
				<content:encoded><![CDATA[<p>If you have a lot of data in a mysql table and you&#8217;d like to duplicate some of the rows &#8211; maybe with a change or two as well &#8211; then here is the sql you&#8217;ll need&#8230;</p>
<pre>
INSERT INTO table (column1, column2,column3, column4)
SELECT column1, 234, column4, NOW()
FROM table
WHERE id IN (6,7)
</pre>
<p>You have some choices&#8230;<br />
You can copy or clone from one table to another by changing the table names above.<br />
You can define your own values. Examples of 234 and NOW() are above.<br />
You can include or drop the WHERE clause to choose which (if not all) rows to clone</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2012/09/day-11-cloning-rows-in-a-mysql-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ping a url or script using IFTTT (with no repercussions)</title>
		<link>http://harrybailey.com/2012/09/ping-a-url-or-script-using-ifttt-with-no-repercussions/</link>
		<comments>http://harrybailey.com/2012/09/ping-a-url-or-script-using-ifttt-with-no-repercussions/#comments</comments>
		<pubDate>Mon, 10 Sep 2012 13:32:45 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[ifttt]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[The Web]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=730</guid>
		<description><![CDATA[Update: This actually doesn&#8217;t work as I&#8217;d hoped. Because flickr reports an error each time, eventually IFTTT disables the recipe after a few hours of calls. Back to the drawing board. I&#8217;ve been trying to get IFTTT (if this then that) to send a call to a php script file when a trigger goes off [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Update:</strong> This actually doesn&#8217;t work as I&#8217;d hoped. Because flickr reports an error each time, eventually IFTTT disables the recipe after a few hours of calls. Back to the drawing board.</p>
<p>I&#8217;ve been trying to get <a href="http://ifttt.com">IFTTT</a> (if this then that) to send a call to a php script file when a trigger goes off for months. The problem wasn&#8217;t getting it to work in the first place, but for it not to leave any artifacts hanging around, or repercussions as I call them. I wanted the script to be triggered and that to be the end of it, with no files being created or errors being recorded.</p>
<p>An example of the problem would be the IFTTT Google Docs channel. You can upload a file to google docs from a url. You can define that url to be your php script and then tell your script to return a 404 (after it&#8217;s done its coding goodness) but when you view Google Docs a new file has still been created. If you want to use this for a large number of pings, you&#8217;re going to end up with a folder full of pointless files and a waste of your disc space. The Evernote and WordPress channels are a similar story. Even when you attempt to fail the call to your url (with a 404 or 503) they still create a note or post.</p>
<p><span id="more-730"></span></p>
<p>After plenty of trial and error I finally came up with the solution. In my case the IFTTT recipe is listening out for a Twitter search, but the trigger is not what matters and you can have that set to whatever you like. It&#8217;s the action that I&#8217;ll tell you about.</p>
<p>Flickr is a winner here. The Flickr upload from url action to be exact.</p>
<p>My php script ( you can use any server language that can return a fake txt file ) does the stuff I need it to do and then I use the following lines to pretend I&#8217;m returning a text file&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="">'HTTP/1.1 200 OK'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="">'Content-type: text/plain'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="">'Content-disposition: attachment; filename=to-delete.txt'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #990000;">echo</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;l&quot;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>IFTTT seems happy about this, but Flickr doesn&#8217;t like it and fails to create an image file in your photo stream. Just what we want. Our script gets called, but we don&#8217;t have to deal with files or errors anywhere, no matter how many times the trigger fires.</p>
<p>So from start to finish&#8230;</p>
<p>* Add the flickr channel to your IFTTT. You may need to create a flickr account if you don&#8217;t have one yet.<br />
* Create a new recipe with your chosen trigger.<br />
* Add the flick &#8216;upload public photo from url&#8217; action as the output<br />
* Set the photo url to be the url to your script<br />
* Set the title to be anything you like. &#8216;blah&#8217; for example.<br />
* Save the recipe</p>
<p>You should now have IFTTT pinging your script each time your selected trigger fires. You can even choose which data to send to it from the trigger in the url using IFTTT ingredients.</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2012/09/ping-a-url-or-script-using-ifttt-with-no-repercussions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Yii wildcard / catch all url rules</title>
		<link>http://harrybailey.com/2012/08/yii-wildcard-catch-all-url-rules/</link>
		<comments>http://harrybailey.com/2012/08/yii-wildcard-catch-all-url-rules/#comments</comments>
		<pubDate>Wed, 22 Aug 2012 16:01:06 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Yii]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=727</guid>
		<description><![CDATA[Sometimes you might want to do various checks of the url in yii config main and then send every other request to a particular controller. The rule you need to add last to the urlManager is&#8230; '(.*)' => 'controller/action', &#8230; and now any rule that isn&#8217;t matched previously will end up being sent to your [...]]]></description>
				<content:encoded><![CDATA[<p>Sometimes you might want to do various checks of the url in yii config main and then send every other request to a particular controller.</p>
<p>The rule you need to add last to the urlManager is&#8230;</p>
<p><code>'(.*)' => 'controller/action',</code></p>
<p>&#8230; and now any rule that isn&#8217;t matched previously will end up being sent to your defined controller and action.</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2012/08/yii-wildcard-catch-all-url-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hide the Fancy Force Login Prompt</title>
		<link>http://harrybailey.com/2012/07/day-8-hide-the-fancy-force-login-prompt/</link>
		<comments>http://harrybailey.com/2012/07/day-8-hide-the-fancy-force-login-prompt/#comments</comments>
		<pubDate>Mon, 16 Jul 2012 10:02:56 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[The Web]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=717</guid>
		<description><![CDATA[It really annoys me that Fancy force you to login before you can see that page you&#8217;ve click the link to view. Here is a bookmarklet you can drag to your bookmarks bar. Then when they try to force you to log in, click it to hide the login prompt and view the page as [...]]]></description>
				<content:encoded><![CDATA[<p>It really annoys me that Fancy force you to login before you can see that page you&#8217;ve click the link to view.</p>
<p>Here is a bookmarklet you can drag to your bookmarks bar. Then when they try to force you to log in, click it to hide the login prompt and view the page as normal.</p>
<p>Drag the following to your bookmark bar:</p>
<p><script>
document.write("<a href=\"javascript:(function(){$('#require_login_overaly_container').remove()})();\" onclick=\"return false;\">Fancy View</a>");
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2012/07/day-8-hide-the-fancy-force-login-prompt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending jQuery selectors and understanding the options</title>
		<link>http://harrybailey.com/2012/07/day-7-extending-jquery-selectors-and-understanding-the-options/</link>
		<comments>http://harrybailey.com/2012/07/day-7-extending-jquery-selectors-and-understanding-the-options/#comments</comments>
		<pubDate>Sat, 07 Jul 2012 17:51:09 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=709</guid>
		<description><![CDATA[There are tons of posts around which bang on about how to extend jQuery to include your own selectors, but to find one that actually explains your options is a pain, hence this post. jQuery has an extend function baked in which looks something like $.extend(target, object1, object2); and will extend target (which should be [...]]]></description>
				<content:encoded><![CDATA[<p>There are tons of posts around which bang on about how to extend jQuery to include your own selectors, but to find one that actually explains your options is a pain, hence this post.</p>
<p>jQuery has an <a href="http://api.jquery.com/jQuery.extend/">extend function</a> baked in which looks something like $.extend(target, object1, object2); and will extend target (which should be an object) with the properties and methods of object1 and object2. You can add as many additional objects (think object3, object4 and object5) to the end as you like.</p>
<p>What we want to do it extend a very specific part of jQuery itself. The $.expr[':'] object which stores the built in selectors and any we add.</p>
<p>Indeed when you console.log($.expre[':']) you see a full list of the selectors available in the version of jQuery you are using:</p>
<p>animated<br />
button<br />
checkbox<br />
checked<br />
data<br />
disabled<br />
empty<br />
enabled<br />
file<br />
focus<br />
focusable<br />
has<br />
header<br />
hidden<br />
image<br />
input<br />
onbranch<br />
parent<br />
password<br />
radio<br />
reset<br />
selected<br />
submit<br />
tabbable<br />
text<br />
visible</p>
<p>NB: I&#8217;ve removed the ui- selectors to avoid confusion.</p>
<p>So now you know what not to call your selector (unless you want to replace a built in one), we can define our own&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">$.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">expr</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">':'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
	block<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span>i<span style="color: #339933;">,</span>m<span style="color: #339933;">,</span>s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'block'</span>;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>The first thing you will notice about the above is that the selector function takes up to (although may need fewer) four argument; e, i, m and s.</p>
<p>e is the element currently being checked.<br />
i is the index of that elements within all elements being checked (starts at zero)<br />
m stands for match and is additional information that we can use in our function.<br />
s stands for stack and is all elements in the current selection or stack</p>
<p>so $(e) makes the current element e into a jQuery object<br />
i allows us to check for the 3rd, 6th, 23rd thing<br />
m contains the following:</p>
<p>[0] is the actual selector called. For example :anyof(&#8220;div,4,hr,10&#8243;)<br />
[1] is just the selector name. For example: anyof<br />
[2] is the type of quotes used (if any) in the selector. So &#8221; would be returned for :anyof(&#8220;div,4,hr,10&#8243;)<br />
[3] is any parameters used in the form of a string so &#8220;div,4,hr,10&#8243; from above</p>
<p>and s contains an array of one or more html elements.</p>
<p>So now we know what is actually returned we can write a cleverer selector&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">$.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">expr</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">':'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
	anyof<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span>i<span style="color: #339933;">,</span>m<span style="color: #339933;">,</span>s<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>m<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span>m<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i2<span style="color: #339933;">,</span>e2<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>parseInt<span style="color: #009900;">&#40;</span>e2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #006600; font-style: italic;">// correct index?</span>
					<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>parseInt<span style="color: #009900;">&#40;</span>e2<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> i<span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000066; font-weight: bold;">else</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #006600; font-style: italic;">// match selector</span>
					<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span>e2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span>;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>or if we wanted to check for the unique items in the stack:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">$.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">expr</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">':'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
	isunique<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span>i<span style="color: #339933;">,</span>m<span style="color: #339933;">,</span>s<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i2<span style="color: #339933;">,</span>e2<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>e2<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prop</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tagName'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> $<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prop</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tagName'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span>;
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>NB: Since jQuery 1.6 you should use .prop() for tagName not attr()</p>
<p>The above selector will check all other elements in the stack and return only those with a unique tag. We could expand it to check other things about the element to see if it is truly unique such as it&#8217;s classes or styles.</p>
<p>NB: I haven&#8217;t checked all the code above and certainly haven&#8217;t optimised it, but it is likely to work as is or with a small number of fixes.</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2012/07/day-7-extending-jquery-selectors-and-understanding-the-options/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
