<?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>Ninetynine.be &#187; Javascript</title>
	<atom:link href="http://ninetynine.be/blog/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://ninetynine.be/blog</link>
	<description>Just another blog with no useful content on it at all.</description>
	<lastBuildDate>Sun, 08 Jan 2012 10:39:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Thickbox: reinitialize Thickbox after change by Ajax</title>
		<link>http://ninetynine.be/blog/2009/03/thickbox-reinitialize-thickbox-after-change-by-ajax/</link>
		<comments>http://ninetynine.be/blog/2009/03/thickbox-reinitialize-thickbox-after-change-by-ajax/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 20:08:20 +0000</pubDate>
		<dc:creator>ruben</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[thickbox]]></category>

		<guid isPermaLink="false">http://ninetynine.be/blog/?p=52</guid>
		<description><![CDATA[Hi, Thickbox is a very nice javascript library based on jQuery (which is also a very neat library). It is used to show images and documents in a sort of popup like Lightbox does. Let me sketch the problem: 1) I load my page (also loading thickbox.js) 2) I change my content in one dom-element, [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p><a href="http://jquery.com/demo/thickbox/">Thickbox</a> is a very nice javascript library based on <a href="http://jquery.com/">jQuery</a> (which is also a very neat library). It is used to show images and documents in a sort of popup like <a href="http://www.huddletogether.com/projects/lightbox/">Lightbox</a> does.</p>
<p>Let me sketch the problem:</p>
<p>1) I load my page (also loading thickbox.js)<br />
2) I change my content in one dom-element, for example a div element, through Ajax.<br />
3) Then I want to call thickbox on an element in the new div.</p>
<p>You will that see nothing happens, because Thickbox hasn&#8217;t been able to register this object.</p>
<p>So basically we need to reinitialize Thickbox. <br/><br />
<span id="more-52"></span><br />
Notice that you should download &#8220;thickbox.js&#8221; and not &#8220;thickbox-compressed.js&#8221; for this feature.</p>
<p>In thickbox.js there is a function tb_init(). This is called when the script is being loaded to add the click-events to the elements which have &#8220;thickbox&#8221; as class.</p>
<p>Recalling this function alone is not enough! Because in some cases elements will have two or more same click-events. It is better to remove the click-events first.</p>
<p>Add this to your thickbox.js:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> tb_reinit<span style="color: #009900;">&#40;</span>domChunk<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span>domChunk<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	tb_init<span style="color: #009900;">&#40;</span>domChunk<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And call this function whenever you load new content through Ajax which can possibly contain new Thickbox elements.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">tb_reinit<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.thickbox, area.thickbox, input.thickbox'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Last but not least: Be careful when upgrading to a new version of thickbox, This was written for Thickbox version 3.1 .</p>
<p>And that&#8217;s it!</p>
<p>Hope this was useful.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://ninetynine.be/blog/2009/03/thickbox-reinitialize-thickbox-after-change-by-ajax/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

