<?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 &#187; Javascript</title>
	<atom:link href="http://harrybailey.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://harrybailey.com</link>
	<description>just a little bit geeky</description>
	<lastBuildDate>Tue, 24 Aug 2010 12:15:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fancybox left and right key problem</title>
		<link>http://harrybailey.com/2010/06/fancybox-left-and-right-key-problem/</link>
		<comments>http://harrybailey.com/2010/06/fancybox-left-and-right-key-problem/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 11:40:04 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=452</guid>
		<description><![CDATA[When you use fancybox, it automatically adds listeners which stop any other use of the Esc, Left and Right keys on your keyboard. The just don&#8217;t work in forms etc inside Fancybox.
This isn&#8217;t such an issue with the escape key, but not being able to use the left and right, for example in text inputs, [...]]]></description>
			<content:encoded><![CDATA[<p>When you use fancybox, it automatically adds listeners which stop any other use of the Esc, Left and Right keys on your keyboard. The just don&#8217;t work in forms etc inside Fancybox.</p>
<p>This isn&#8217;t such an issue with the escape key, but not being able to use the left and right, for example in text inputs, is a pain.</p>
<p>The changes below add an additional option to Fancybox called <strong>useNextPrev</strong> which you can set to false to stop Fancybox adding listeners to these keys. I haven&#8217;t included the escape key as I think it&#8217;s far less of an issue. <span id="more-452"></span></p>
<p>The call to Fancybox after these changes would look something like this:</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;">'a.fancybox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fancybox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>useNextPrev<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Changes needed to the fancybox javascript file:</p>
<p>replace:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">37</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
	$.<span style="color: #660066;">fancybox</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">39</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
	$.<span style="color: #660066;">fancybox</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>with:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>currentOpts.<span style="color: #660066;">useNextPrev</span> <span style="color: #339933;">&amp;&amp;</span> e.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">37</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
	$.<span style="color: #660066;">fancybox</span>.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>currentOpts.<span style="color: #660066;">useNextPrev</span> <span style="color: #339933;">&amp;&amp;</span> e.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">39</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
	$.<span style="color: #660066;">fancybox</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>replace:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">	$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">fancybox</span>.<span style="color: #660066;">defaults</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		padding				<span style="color: #339933;">:</span>	<span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>
		margin				<span style="color: #339933;">:</span>	<span style="color: #CC0000;">20</span><span style="color: #339933;">,</span></pre></div></div>

<p>with:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">	$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">fancybox</span>.<span style="color: #660066;">defaults</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		padding				<span style="color: #339933;">:</span>	<span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>
		margin				<span style="color: #339933;">:</span>	<span style="color: #CC0000;">20</span><span style="color: #339933;">,</span>
		useNextPrev			<span style="color: #339933;">:</span>	<span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span></pre></div></div>

<p>And there you have it. By default Fancybox <strong>will</strong> use the left and right keys, but you now have the choice to stop it.</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2010/06/fancybox-left-and-right-key-problem/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pimping Fancybox jQuery Lightbox</title>
		<link>http://harrybailey.com/2010/05/pimping-fancybox/</link>
		<comments>http://harrybailey.com/2010/05/pimping-fancybox/#comments</comments>
		<pubDate>Thu, 13 May 2010 00:10:14 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=440</guid>
		<description><![CDATA[I love fancybox. It&#8217;s a great and flexible jQuery lightbox, but I decided there were a couple of things I needed it to do that it doesn&#8217;t, so I dived into the code head first and added a couple of features. Be warned that you need to edit the file jquery.fancybox-1.3.1.js to implement them.
Combined add [...]]]></description>
			<content:encoded><![CDATA[<p>I love <a href="http://fancybox.net/">fancybox</a>. It&#8217;s a great and flexible jQuery lightbox, but I decided there were a couple of things I needed it to do that it doesn&#8217;t, so I dived into the code head first and added a couple of features. Be warned that you need to edit the file jquery.fancybox-1.3.1.js to implement them.</p>
<p><strong>Combined add and fire / show / open</strong><br />
Yes I know you can do this with $.fancybox(content, options)</p>
<p>It&#8217;s tough to add the fancybox listener and fire it at the same time, for example onclick or using a live event. That annoyed me in some circumstances. Previously I have resorted to adding fancybox to anchors on hover so it could fire onclick:<span id="more-440"></span></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;">'a.fancybox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mouseover</span><span style="color: #009900;">&#40;</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>
    $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fancybox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>But that&#8217;s not cool. So I added the option to the core.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">// replace</span>
	$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">fancybox</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// with</span>
	$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">fancybox</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<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>options <span style="color: #339933;">===</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			options <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>now<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span>;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>and</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">// replace</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: #000066; font-weight: bold;">this</span>;
	<span style="color: #009900;">&#125;</span>;
&nbsp;
	$.<span style="color: #660066;">fancybox</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// with</span>
&nbsp;
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">now</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>;
	<span style="color: #009900;">&#125;</span>;
&nbsp;
	$.<span style="color: #660066;">fancybox</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></div></div>

<p>You can fire it in two ways. If you are also including options then fire it on add by including now:true as an option like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fancybox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    now<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
    showCloseButton <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
    enableEscapeButton <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>or if you are not setting options then fire it on add like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">// note the (1)</span>
$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fancybox</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Either way, fancybox should now open / fire / show as soon as you attach it to an element.</p>
<p>And for my next trick&#8230;.</p>
<p><strong>Stop lightbox vertical movement</strong></p>
<p>The default behavour is for fancybox to centre itself on vertical or horizontal scroll or window resize. I needed (see the final tweak) the box to stay still vertically even if I scrolled, but stay centre horizontally.</p>
<p>To implement this I made this change:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">// replace</span>
&nbsp;
		to.<span style="color: #660066;">top</span>	<span style="color: #339933;">=</span> view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>wrap.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> titleh<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>shadow <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.5</span><span style="color: #009900;">&#41;</span>;
		to.<span style="color: #660066;">left</span>	<span style="color: #339933;">=</span> view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>wrap.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>shadow <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.5</span><span style="color: #009900;">&#41;</span>;
&nbsp;
		to.<span style="color: #660066;">top</span>	<span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> margin<span style="color: #339933;">,</span> to.<span style="color: #660066;">top</span><span style="color: #009900;">&#41;</span>;
		to.<span style="color: #660066;">left</span>	<span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> margin<span style="color: #339933;">,</span> to.<span style="color: #660066;">left</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #006600; font-style: italic;">// with</span>
&nbsp;
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>currentOpts.<span style="color: #660066;">centerTopOnScroll</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
		    to.<span style="color: #660066;">top</span>	<span style="color: #339933;">=</span> view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>wrap.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> titleh<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>shadow <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.5</span><span style="color: #009900;">&#41;</span>;
		    to.<span style="color: #660066;">top</span>	<span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> margin<span style="color: #339933;">,</span> to.<span style="color: #660066;">top</span><span style="color: #009900;">&#41;</span>;
                <span style="color: #009900;">&#125;</span>
&nbsp;
		to.<span style="color: #660066;">left</span>	<span style="color: #339933;">=</span> view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>wrap.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>shadow <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.5</span><span style="color: #009900;">&#41;</span>;
		to.<span style="color: #660066;">left</span>	<span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> margin<span style="color: #339933;">,</span> to.<span style="color: #660066;">left</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>and then add that new option to the defaults:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">// replace</span>
&nbsp;
		centerOnScroll		<span style="color: #339933;">:</span>	<span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// with</span>
&nbsp;
		centerOnScroll		<span style="color: #339933;">:</span>	<span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
		centerTopOnScroll	<span style="color: #339933;">:</span>	<span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span></pre></div></div>

<p>You can then include the new option centerTopOnScroll:false to keep the top position static even on horizontal scroll.</p>
<p>The final change I have made is:</p>
<p><strong>Clone the position and dimensions of an element</strong></p>
<p>This tweak allows you to specify an element to clone. The <strong>original</strong> lightbox created will then be in the position and have the dimensions of the specified element. I bolded original because you can then alter the dimensions and positions yourself using jquery or by updating the content.</p>
<p>To implement this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">// replace</span>
&nbsp;
			final_pos <span style="color: #339933;">=</span> fancybox_get_zoom_to<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
			fancybox_process_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #006600; font-style: italic;">// with</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>currentOpts.<span style="color: #660066;">clonePosition</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #006600; font-style: italic;">// get final_pos from the element we are cloning</span>
				<span style="color: #003366; font-weight: bold;">var</span> pos <span style="color: #339933;">=</span> currentOpts.<span style="color: #660066;">elementToClone</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
				final_pos <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
								height<span style="color: #339933;">:</span>currentOpts.<span style="color: #660066;">elementToClone</span>.<span style="color: #660066;">outerHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
								width<span style="color: #339933;">:</span>currentOpts.<span style="color: #660066;">elementToClone</span>.<span style="color: #660066;">outerWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
								left<span style="color: #339933;">:</span>pos.<span style="color: #660066;">left</span><span style="color: #339933;">,</span>
								top<span style="color: #339933;">:</span>pos.<span style="color: #660066;">top</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>
				final_pos <span style="color: #339933;">=</span> fancybox_get_zoom_to<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span>
&nbsp;
			fancybox_process_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>and</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #006600; font-style: italic;">// replace (after the previous change for vertical scroll)</span>
&nbsp;
to.<span style="color: #660066;">left</span>	<span style="color: #339933;">=</span> view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>wrap.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>shadow <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.5</span><span style="color: #009900;">&#41;</span>;
to.<span style="color: #660066;">left</span>	<span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> margin<span style="color: #339933;">,</span> to.<span style="color: #660066;">left</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #006600; font-style: italic;">// with</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>currentOpts.<span style="color: #660066;">clonePosition</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	to.<span style="color: #660066;">left</span> <span style="color: #339933;">=</span> currentOpts.<span style="color: #660066;">elementToClone</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">left</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span>
<span style="color: #009900;">&#123;</span>
	to.<span style="color: #660066;">left</span>	<span style="color: #339933;">=</span> view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>wrap.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>shadow <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">0.5</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
to.<span style="color: #660066;">left</span>	<span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span>view<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> margin<span style="color: #339933;">,</span> to.<span style="color: #660066;">left</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>You then have the choice of including new options:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
clonePosition<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span>
elementToClone<span style="color: #339933;">:</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#element'</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// a jquery element</span></pre></div></div>

<p>So there you have it.</p>
<p>Combined add and fire / show / open<br />
Stop lightbox vertical movement<br />
Clone the position and dimensions of an element</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2010/05/pimping-fancybox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validation of html within inline javascript</title>
		<link>http://harrybailey.com/2010/04/validation-html-inline-javascript/</link>
		<comments>http://harrybailey.com/2010/04/validation-html-inline-javascript/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 13:43:36 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[The Web]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=432</guid>
		<description><![CDATA[If you are finding you need to use javascript inside an html or xhtml file and it won&#8217;t validate, then here is a little tip for you.
If you surround all your javascript with &#60;![CDATA[ and  ]]&#62; tags, all will come good.
The CDATA is seen by the validator as data which doesn&#8217;t need checking. So [...]]]></description>
			<content:encoded><![CDATA[<p>If you are finding you need to use javascript inside an html or xhtml file and it won&#8217;t validate, then here is a little tip for you.</p>
<p>If you surround all your javascript with &lt;![CDATA[ and  ]]&gt; tags, all will come good.</p>
<p>The CDATA is seen by the validator as data which doesn&#8217;t need checking. So this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;p&gt;hello&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>becomes this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;!</span><span style="color: #009900;">&#91;</span>CDATA<span style="color: #009900;">&#91;</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;p&gt;hello&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Another option is to escape < and > characters server-side / in the file and then unescape with javascript</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&amp;lt;p&amp;gt;hello&amp;lt;/p&amp;gt;'</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/&amp;lt;/'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'&lt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/&amp;gt;/'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2010/04/validation-html-inline-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More powerful jQuery getScript with cache control</title>
		<link>http://harrybailey.com/2010/03/more-powerful-jquery-getscript-with-cache-control/</link>
		<comments>http://harrybailey.com/2010/03/more-powerful-jquery-getscript-with-cache-control/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 09:09:16 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=425</guid>
		<description><![CDATA[If you love getScript as a shortcut method in jQuery but you hate not being able to control whether the script calls from the browsers cache or not then you can override the build in function with a new one which is backwards compatable, so it won&#8217;t break any of your old code, and allows [...]]]></description>
			<content:encoded><![CDATA[<p>If you love getScript as a shortcut method in jQuery but you hate not being able to control whether the script calls from the browsers cache or not then you can override the build in function with a new one which is backwards compatable, so it won&#8217;t break any of your old code, and allows you to choose true or false to caching.</p>
<p><a href="http://jamazon.co.uk/web/2008/07/21/jquerygetscript-does-not-cache/">Read the original post by Jamie Thompson</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #009900;">&#40;</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>
$.<span style="color: #660066;">getScript</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span> callback<span style="color: #339933;">,</span> cache<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
			url<span style="color: #339933;">:</span> url<span style="color: #339933;">,</span>
			success<span style="color: #339933;">:</span> callback<span style="color: #339933;">,</span>
			dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;script&quot;</span><span style="color: #339933;">,</span>
			cache<span style="color: #339933;">:</span> cache
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2010/03/more-powerful-jquery-getscript-with-cache-control/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Twitter &#8216;patch&#8217; the &#8220;don&#8217;t click&#8221; virus with one line of code</title>
		<link>http://harrybailey.com/2009/02/twitter-spoil-the-dont-click-fun-with-one-line-of-code/</link>
		<comments>http://harrybailey.com/2009/02/twitter-spoil-the-dont-click-fun-with-one-line-of-code/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 19:41:46 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[The Web]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=155</guid>
		<description><![CDATA[Before I get started, I would just like to confirm there is absolutely no reason to change your Twitter password. That&#8217;s right. Your password is safe even if you fell for the don&#8217;t click scam.
A harmless virus has been seen on Twitter over the last couple of weeks. It manifests itself as a tweet from [...]]]></description>
			<content:encoded><![CDATA[<p>Before I get started, I would just like to confirm <strong>there is absolutely no reason to change your Twitter password</strong>. That&#8217;s right. Your password is safe even if you fell for the don&#8217;t click scam.</p>
<p>A harmless virus has been seen on Twitter over the last couple of weeks. It manifests itself as a tweet from someone which simply reads &#8216;Don&#8217;t click {link}&#8217;<br />
If you are logged into twitter and you click the link, followed by a link on the following page which also reads &#8216;Don&#8217;t click&#8217; then an identical message is posted without your knowledge to your own feed.</p>
<p><span id="more-155"></span></p>
<p>How? I hear you ask.<br />
Well the simple way to put it is that the site you are taken to, hides your twitter home page over the top of it&#8217;s own content. They then prefil the tweet form with some text and position the &#8216;Don&#8217;t click&#8217; button in exactly the same place as the &#8216;update&#8217; button on twitter. Put simply you post to your own feed without even knowing.</p>
<p>The geeky version is that they hide your twitter home page in a hidden iframe and prepopulate your tweet box. They then match up the two buttons so that when you click &#8216;Don&#8217;t click&#8217;, you are actually clicking to update your feed.</p>
<p>So what have twitter done to stop it?<br />
Well on the <a href="http://blog.twitter.com/2009/02/clickjacking-blocked.html">twitter blog</a> they say &#8220;this morning we submitted an update which blocks this clickjacking technique&#8221;. What they have actually done is just made it harder for other sites to include twitter within their own site. They implemented a fix using javascript, which 95%+ of internet users have enabled. The actual code twitter used is:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">top</span> <span style="color: #339933;">!==</span> window.<span style="color: #660066;">self</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> window.<span style="color: #660066;">top</span>.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span> <span style="color: #339933;">=</span> window.<span style="color: #660066;">self</span>.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span>; <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Which basically says: If twitter is in a frame, redirect so twitter is on top and isn&#8217;t in a frame.</p>
<p>So not only are there still 1000&#8217;s of vunerable sites. The problem is that using the same code Twitter have will stop plenty of fair and helpful uses of frame based sites.</p>
<p>Oh, and for once if you have javascript <strong>disabled</strong>, you are still vunerable. Now there is a refreshing change.</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2009/02/twitter-spoil-the-dont-click-fun-with-one-line-of-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Hover Listener Unbinding</title>
		<link>http://harrybailey.com/2008/11/jquery-hover-and-unbinding/</link>
		<comments>http://harrybailey.com/2008/11/jquery-hover-and-unbinding/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 18:52:36 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=88</guid>
		<description><![CDATA[jQuery has a great helper function called hover which takes two functions as it&#8217;s values.

$&#40;'#hover_div'&#41;.hover&#40;function&#40;&#41;
&#123;
/* something to do on mouseenter */
&#125;,
function&#40;&#41;
&#123;
/* something to do on mouseleave */
&#125;&#41;;

Great when you want a simple way of doing something when your mouse enters or leaves the selected element(s).

But then I needed to unbind the listener from the elements [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jquery.com">jQuery</a> has a great helper function called hover which takes two functions as it&#8217;s values.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="">'#hover_div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>hover<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/* something to do on mouseenter */</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/* something to do on mouseleave */</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Great when you want a simple way of doing something when your mouse enters or leaves the selected element(s).</p>
<p><span id="more-88"></span></p>
<p>But then I needed to unbind the listener from the elements and I couldn&#8217;t for the life of me work out how.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* WRONG */</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#hover_div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hover'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #009966; font-style: italic;">/* WRONG */</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#hover_div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseover'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseout'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #009966; font-style: italic;">/* update 2: WRONG - but hopefully in the next release */</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#hover_div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseenter mouseleave'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #009966; font-style: italic;">/* CORRECT */</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#hover_div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseenter'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseleave'</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>So there you go. That&#8217;s how to unbind hover().</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2008/11/jquery-hover-and-unbinding/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Disable Select Options in Internet Explorer</title>
		<link>http://harrybailey.com/2008/11/disabling-select-options-in-internet-explorer/</link>
		<comments>http://harrybailey.com/2008/11/disabling-select-options-in-internet-explorer/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 15:15:42 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=38</guid>
		<description><![CDATA[Put your hands up if you hate developing for Internet explorer&#8230;.
That would be most of you then.
I can&#8217;t stand its special ways of doing things, so when I find an easy work around it makes me happy.
The latest one I have had to find and put into practice is a method for disabling some Select [...]]]></description>
			<content:encoded><![CDATA[<p>Put your hands up if you hate developing for Internet explorer&#8230;.</p>
<p>That would be most of you then.</p>
<p>I can&#8217;t stand its special ways of doing things, so when I find an easy work around it makes me happy.</p>
<p>The latest one I have had to find and put into practice is a method for disabling some Select dropdown options in a form. Internet explorer doesn&#8217;t support the disabled attribute on option elements. The following code will only work in standards complaint browsers (not in IE 6 or 7):</p>
<p><span id="more-38"></span></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;select id=&quot;select_1&quot; name=&quot;a_select&quot;&gt;
	&lt;option&gt;Please select...&lt;/option&gt;
	&lt;option disabled=&quot;disabled&quot;&gt;----------&lt;/option&gt;
	&lt;option&gt;One&lt;/option&gt;
	&lt;option disabled=&quot;disabled&quot;&gt;Two&lt;/option&gt;
	&lt;option&gt;Three&lt;/option&gt;
&lt;/select&gt;</pre></div></div>

<p>But there is a simple(ish) workaround we can use. Replace the disabled option elements with empty optgroup elements. This looks good in all browsers except for Safari which won&#8217;t show the option using the below code:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;select id=&quot;select_1&quot; name=&quot;a_select&quot;&gt;
	&lt;option&gt;Please select...&lt;/option&gt;
	&lt;optgroup label=&quot;----------&quot;&gt;&lt;/optgroup&gt;
	&lt;option&gt;One&lt;/option&gt;
	&lt;optgroup label=&quot;Two&quot;&gt;&lt;/optgroup&gt;
	&lt;option&gt;Three&lt;/option&gt;
&lt;/select&gt;</pre></div></div>

<p>By adding a little css styling magic and you end up with an identical outcome in all other modern browsers.</p>
<p>You can then enable and disable using javascript. Many people have written code which makes an option look like it&#8217;s disabled, waits for a click on the option element and then bluring it or focusing the next / previously selected option to make it act like it&#8217;s disabled.</p>
<p>I have come up with functions used with <a href="http://jquery.com">jQuery</a> to disable / enable a select option by <strong>converting it to an optgroup</strong> and back. It is tested in firefox 2 &amp; 3, safari 3, ie 6 + 7, and it works in Opera 9 (although the opgroups jump to the bottom)</p>
<h2>The code</h2>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</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>
	$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>
	<span style="color: #009900;">&#123;</span>
		optionDisable<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>
			<span style="color: #003366; font-weight: bold;">var</span> ths <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>ths.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tagName'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'option'</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				ths.<span style="color: #660066;">before</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;optgroup&gt;&amp;nbsp;&lt;/optgroup&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span><span style="color: #3366CC;">'#ccc'</span><span style="color: #339933;">,</span>height<span style="color: #339933;">:</span>ths.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</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>id<span style="color: #339933;">:</span>ths.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>label<span style="color: #339933;">:</span>ths.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">return</span> ths;
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		optionEnable<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>
			<span style="color: #003366; font-weight: bold;">var</span> ths <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #003366; font-weight: bold;">var</span> tag <span style="color: #339933;">=</span> ths.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tagName'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>tag <span style="color: #339933;">==</span> <span style="color: #3366CC;">'option'</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				ths.<span style="color: #660066;">removeAttr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'disabled'</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>tag <span style="color: #339933;">==</span> <span style="color: #3366CC;">'optgroup'</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				ths.<span style="color: #660066;">before</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;option /&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>value<span style="color: #339933;">:</span>ths.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>ths.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'label'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">return</span> ths;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<h2>Fixes and explainations</h2>
<p>Safari requires a &amp;nbsp; in the optgroup tag to make it visible, and because of this Firefox 2 then required the height:ths.height() to stop it showing a blank line below the optgroup.<br />
Two small fixes.</p>
<p>Additionally (as kindly pointed out by Luenyar below) this will not work if the options you are playing around with are already in an optgroup. That said, it will work but will create unwanted optgroups.</p>
<p>I almost forgot to mention that the functions are chainable!</p>
<h2>Example</h2>
<p>And to put it into practice you could use the following code snippets:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* a specific option */</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#a_select'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':eq(2)'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">optionDisable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #009966; font-style: italic;">/* the selected option */</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#a_select option:selected'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">optionDisable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'I am a disabled option!'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #009966; font-style: italic;">/* enable all options in a select */</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#a_select'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">optionEnable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p><strong>Update:</strong> Be sure to read all the excellent comments for further thoughts and improvements</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2008/11/disabling-select-options-in-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Total all items on an ebay users sales page</title>
		<link>http://harrybailey.com/2008/11/total-all-items-on-an-ebay-users-sales-page/</link>
		<comments>http://harrybailey.com/2008/11/total-all-items-on-an-ebay-users-sales-page/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 14:12:09 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=36</guid>
		<description><![CDATA[A little bit of a strange one I know.
But recently I needed to be able to get the total of all items that another ebay user had for sale. By default they can see it but another user cannot.
So using the console of firebug in firefox paste the following javascript and off you go.


var elms [...]]]></description>
			<content:encoded><![CDATA[<p>A little bit of a strange one I know.<br />
But recently I needed to be able to get the total of all items that another ebay user had for sale. By default they can see it but another user cannot.</p>
<p>So using the console of <a href="http://www.getfirebug.com">firebug</a> in <a href="http://www.getfirefox.com">firefox</a> paste the following javascript and off you go.</p>
<p><span id="more-36"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> elms <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'v4-45'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'td'</span><span style="color: #009900;">&#41;</span>;
i <span style="color: #339933;">=</span> elms.<span style="color: #660066;">length</span>;
ttl <span style="color: #339933;">=</span> 0;
str <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span>;
<span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">--</span><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>mtch <span style="color: #339933;">=</span> elms<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">innerHTML</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/£([0-9]+.[0-9][0-9])/</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        ttl <span style="color: #339933;">+=</span> parseInt<span style="color: #009900;">&#40;</span>mtch<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
        str <span style="color: #339933;">+=</span> mtch<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' - '</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>str <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'£'</span><span style="color: #339933;">+</span>ttl<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Of course if they change the id of any of the elements involved this will stop working. But hey, if you can handle that javascript and firebug then you probably keep it up to date yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2008/11/total-all-items-on-an-ebay-users-sales-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Commenting out large amounts of a script</title>
		<link>http://harrybailey.com/2008/11/commenting-out-large-amounts-of-a-script/</link>
		<comments>http://harrybailey.com/2008/11/commenting-out-large-amounts-of-a-script/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 16:29:00 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=32</guid>
		<description><![CDATA[Every tried to comment out a large part of a script only to find that your /* multiline comments */ don&#8217;t work because somewhere in that file you already used /* multiline */ type comments?
Well never fear. A solution for php, Javascript and plenty of other languages is simply to use

if(0)
{
... lots of code ...
}

Simple [...]]]></description>
			<content:encoded><![CDATA[<p>Every tried to comment out a large part of a script only to find that your /* multiline comments */ don&#8217;t work because somewhere in that file you already used /* multiline */ type comments?</p>
<p>Well never fear. A solution for php, Javascript and plenty of other languages is simply to use<br />
<code><br />
if(0)<br />
{<br />
... lots of code ...<br />
}<br />
</code></p>
<p>Simple and quick</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2008/11/commenting-out-large-amounts-of-a-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uppercase First letters with javascript</title>
		<link>http://harrybailey.com/2008/11/first-letters-to-uppercase-with-javascript/</link>
		<comments>http://harrybailey.com/2008/11/first-letters-to-uppercase-with-javascript/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 22:12:34 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://harrybailey.com/?p=15</guid>
		<description><![CDATA[If you have a string in javascript and you want to the first letter to be uppercase / a capital then this line of code will do that for you:

str = str.slice&#40;0,1&#41;.toUpperCase&#40;&#41; + str.slice&#40;1&#41;;

If you want to convert more than one letter then you might want to use the following. As examples if you wanted [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a string in javascript and you want to the first letter to be uppercase / a capital then this line of code will do that for you:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">str <span style="color: #339933;">=</span> str.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span>0<span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> str.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>If you want to convert more than one letter then you might want to use the following. As examples if you wanted the first 4 characters uppercase use (0,3) and then (4) and if you wanted the first 2 uppercase you would use (0,1) and then (2)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">str <span style="color: #339933;">=</span> str.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span>0<span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toUpperCase</span> <span style="color: #339933;">+</span> str.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Remember that an array starts at zero so always take one from the numbers you want.</p>
]]></content:encoded>
			<wfw:commentRss>http://harrybailey.com/2008/11/first-letters-to-uppercase-with-javascript/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
