<?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>Adventures in Japanese Programming &#187; programming</title>
	<atom:link href="http://blog.japanesetesting.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.japanesetesting.com</link>
	<description>Design and Programming of a mISV Site</description>
	<lastBuildDate>Fri, 23 Jul 2010 13:29:11 +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>Taking the pain out of CakePHP deployment: Batch Scripts and SVN</title>
		<link>http://blog.japanesetesting.com/2010/04/23/taking-the-pain-out-of-cakephp-deployment-batch-scripts-and-svn/</link>
		<comments>http://blog.japanesetesting.com/2010/04/23/taking-the-pain-out-of-cakephp-deployment-batch-scripts-and-svn/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 02:52:50 +0000</pubDate>
		<dc:creator>Harisenbon</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.japanesetesting.com/?p=148</guid>
		<description><![CDATA[If you take a look at the update rate of this blog, or the wait time on my email responses, or even the changelogs from my Subversion repository, you will notice one thing &#8212; I am a horrible procrastinator.
Well, not actually true. I&#8217;m a great procrastinator.
I found out a long time ago that something I [...]]]></description>
			<content:encoded><![CDATA[<p>If you take a look at the update rate of this blog, or the wait time on my email responses, or even the changelogs from my Subversion repository, you will notice one thing &#8212; I am a <strong>horrible </strong>procrastinator.</p>
<p>Well, not actually true. I&#8217;m a <strong>great </strong>procrastinator.</p>
<p>I found out a long time ago that something I think will take 10 minutes ends up taking an hour, and things I think will take an hour end up taking 10 minutes. The downside to this thought pattern is that it makes it hard for me to start anything I know that I can&#8217;t get done in 1 minute, unless I have a lot of time to kill on it.</p>
<p>The more steps there are to a process, the less likely I am to feel that I can get it done in the small amount of time I have allowed.</p>
<h2>What is the process for deploying a project with CakePHP?</h2>
<p>The process for deploying a cakePHP website is monotonous enough, but at the same time contains enough fiddly bits to be annoying to do more than once in a blue moon.</p>
<ol>
<li>Export the data from the SVN to the directory of your choice (dev or live in my case)</li>
<li>If you&#8217;re anal about keeping logs of what you exported (like me), write the version info to a file.</li>
<li>Update the config file so that your local version (which is probably running in debug 1 or 2) runs without debug info.</li>
<li>Remove all the old cache data in case you made any changes to your models</li>
<li>Done</li>
</ol>
<p>Kind of a pain in the rear.</p>
<p>And we all know what are great for repetitive tasks with lots of fiddly steps that are a pain in the rear:</p>
<h2>Enter the bash file</h2>
<p>I created a simple batch file that I can run directly on my <a title="SliceHost" href="http://slicehost.com" target="_blank">SliceHost</a> server. It allows me to deploy a specific folder from my SVN, pick whether to deploy to the dev site or the live site, clear the cache, and set the debug settings.</p>
<h3><span style="font-size: 15px;">Now let&#8217;s do it in one line</span></h3>
<pre class="brush: plain;">./deploy live app</pre>
<p><strong>Done</strong>.</p>
<p>Here&#8217;s what comes out the other end:</p>
<pre class="brush: plain;">
Setting LIVE
.....
Lots of SVN Export Data
.....
Reset Config File: [livesite]/app/config/core.php
Cleared out Cache
</pre>
<p>This gives me a sense of security when updating my site, because I know that I won&#8217;t have forgotten any of the tiny repetitive details, and can fill my deploy checklist with more important things (such as &#8220;Check that users can login&#8221;) instead of &#8220;Set Debug to 0.&#8221;</p>
<h2>Here&#8217;s the Code</h2>
<p>I know, I know. All you want is the code. Well here you go. Feel free to edit and use as you like, but be sure to set your svn and target paths.</p>
<pre class="brush: bash;">
#!/bin/sh
# usage: ./deploy TYPE DIR
# TYPE = live | (anything else)
#
# Be sure to edit the following:
# _MY_SVN_DIR_ -- the base SVN dir for this project
# _MY_LIVE_PATH_ ex: /home/ippatsu/japanesetesting.com/public
# _MY_DEV_PATH_ ex: /home/ippatsu/beta.japanesetesting.com/public

# Set as Life or Dev
if [ &quot;$1&quot; != &quot;live&quot; ]; then
echo &quot;Setting DEVsite&quot;
TARGETP=&quot;_MY_DEV_PATH_&quot;
else
echo &quot;Setting LIVE&quot;
TARGETP=&quot;_MY_LIVE_PATH_&quot;
fi

# Export Data
svn export --force svn://127.0.0.1/_MY_SVN_DIR_/$2  $TARGETP/$2

# Write Version to File
svn info svn://127.0.0.1/_MY_SVN_DIR_/$2 &gt; $TARGETP/version.txt
svn info svn://127.0.0.1/_MY_SVN_DIR_/$2

# Update Config File
OLD=&quot;Configure::write('debug', 2);&quot;
NEW=&quot;Configure::write('debug', 0);&quot;
CONFIGFILE=&quot;$TARGETP/app/config/core.php&quot;

sed -i &quot;s/$OLD/$NEW/g&quot; $CONFIGFILE
echo &quot;Reset Config File: $CONFIGFILE&quot;

# Clearout Cake Model Cache
rm $TARGETP/app/tmp/cache/models/cake*
rm $TARGETP/app/tmp/cache/persistent/cake*
rm $TARGETP/app/tmp/cache/views/cake*
echo &quot;Cleared out Cache&quot;

exit 0
</pre>
<p>Hope you enjoy it, and if you have any advice or questions, just leave them in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.japanesetesting.com/2010/04/23/taking-the-pain-out-of-cakephp-deployment-batch-scripts-and-svn/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>The Programmer&#8217;s Folly: Simple is best</title>
		<link>http://blog.japanesetesting.com/2009/11/24/the-programmers-folly-simple-is-best/</link>
		<comments>http://blog.japanesetesting.com/2009/11/24/the-programmers-folly-simple-is-best/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 02:44:38 +0000</pubDate>
		<dc:creator>Harisenbon</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[system design]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://blog.japanesetesting.com/?p=132</guid>
		<description><![CDATA[First, let me get this out in the open: I am not a marketer. I am not a content-organizer. I am a programmer. I like writing code, and I like creating new ways to do things. I like making things because it helps me see how they work &#8212; out-of-the-box-solutions bore me.
And that&#8217;s where I [...]]]></description>
			<content:encoded><![CDATA[<p>First, let me get this out in the open: I am not a marketer. I am not a content-organizer. I am a programmer. I like writing code, and I like creating new ways to do things. I like making things because it helps me see how they work &#8212; out-of-the-box-solutions bore me.</p>
<h2>And that&#8217;s where I screw up</h2>
<p>On Monday it was a national holiday here in Japan (勤労感謝の日) and I had about 4 hours to kill while the wife was out on her daily walk. I decided to work on my site &#8212; and what I needed more than anything was a nice heatmap to log user clicks.</p>
<p>I used the amazing <a href="http://www.labsmedia.com/clickheat/index.html" target="_blank">ClickHeat </a>which is a free heat-mapping application written in PHP. It works <strong>right out of the box</strong>, is amazingly configurable, and runs quickly thanks to it being written in clear PHP.</p>
<h2>Wouldn&#8217;t this be great as a CakePHP Plugin!</h2>
<p>This is where things start to get messy.</p>
<p>I love CakePHP. It makes development easy, is rather fast, and is highly extensible. So, I decided to wrap the ClickHeat application in a cake plugin, make it &#8220;<em>easy to integrate</em>&#8221; and put it in the <a href="http://bakery.cakephp.org" target="_blank">CakePHP Bakery</a>, instantly receiving fame, fortune and the accolades of my peers!</p>
<h2>4 hours later</h2>
<p>I had a mostly-working prototype that logged the data beautifully (although I couldn&#8217;t decide how to group the data on a dynamic site),  but didn&#8217;t have any of the nifty functions of the ClickHeat software such as sorting by date, admin panels, etc. because I hadn&#8217;t built those views yet. <strong>But I was hopeful!</strong></p>
<p>Then my wife came home and I stopped programming for the day.</p>
<h2>The next day, in 10 minutes</h2>
<p>I decided to install ClickHeat on one of my corporate sites at work.</p>
<ol>
<li>Copy ClickHeat folder</li>
<li>Set Cache &amp; Log permissions</li>
<li>Turn on Japanese Interface</li>
<li>Done</li>
</ol>
<p><strong>10 minutes</strong>. In ten minutes I had accomplished what I couldn&#8217;t complete in 4 hours, because I was prepared to use an out-of-the-box solution instead of trying the be the programming bad-ass and integrate it with CakePHP.</p>
<p>So this morning, I copied the folder to my CakePHP dir, made one change to the .htaccess file:</p>
<pre class="brush: plain;">
RewriteRule    clickheat/(.*)   -   [L]
</pre>
<p>And now I have working heatmaps on my site. (I also put them on my wordpress blog, so that you can see them in action for yourself).</p>
<p><a href="http://blog.japanesetesting.com/clickheat" target="_blank">See the amazing Japanese Programming Heatmaps</a>! (User: demo / Password: demo)</p>
<h1>The final Score</h1>
<p>So, what&#8217;s the final score?</p>
<h2>Being a &#8220;bad-ass&#8221; programmer</h2>
<ol>
<li><span style="color: #ff0000;">4 Hours Development</span></li>
<li><span style="color: #ff0000;">1 extra hour of planning before sleep</span></li>
<li><span style="color: #ff0000;">No Viewing Functionality</span></li>
<li><span style="color: #ff0000;">Installation NOT user friendly</span></li>
<li><span style="color: #ff0000;">Call time of 300ms per click for spinning up the cake processor<br />
</span></li>
<li><span style="color: #339966;">Logging Works</span></li>
</ol>
<h2>Being a smart programmer</h2>
<ol>
<li><span style="color: #339966;">1 Change in my htaccess file</span></li>
<li><span style="color: #339966;">10 minutes to install/configure</span></li>
<li><span style="color: #339966;">Call time of 150ms / click<br />
</span></li>
<li><span style="color: #ff0000;">Not following &#8220;best practices&#8221; for cakephp</span></li>
</ol>
<p>I think it&#8217;s pretty obvious what the best choice here is.</p>
<p>While I adore CakePHP and the things it lets you do simply by following convention &#8212; it&#8217;s very easy to get sucked into the &#8220;Best Practice&#8221; mindset, and waste a lot of time working on something that honestly doesn&#8217;t need to be tinkered with.</p>
<h2>Don&#8217;t re-invent the wheel</h2>
<p>It&#8217;s amazing how many times you can read that phrase and still find yourself re-inventing wheel after wheel after wheel. If you have a tool that does a job &#8212; <strong>use it</strong>. Do not worry about your fiddly code, and your &#8220;it&#8217;s not made here&#8221; mentality.</p>
<p>If the application is <strong>LACKING</strong> you can always edit it. But it makes no sense to start with something that does everything that you want, and then try to hack it apart just because you can. (Although I have to admit, it can be fun)</p>
<h2>With those four hours, I could have</h2>
<ul>
<li>written 1 article for my site,</li>
<li>uploaded around 10 flashcard packs</li>
<li>added 2 tests to the site</li>
<li>read a book</li>
<li>played a lot of video games</li>
<li>watched a movie</li>
<li>watched <strong>four</strong> (4) episodes of Doctor Who or The Green Wing.</li>
</ul>
<p>So Keith, this is a message to you:</p>
<ul>
<li>Don&#8217;t be a tool</li>
<li>Use your time wisely</li>
<li>If something works, do NOT break it just because you want to see how it works.</li>
<li>(Eat your veggies &#8212; love mom)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.japanesetesting.com/2009/11/24/the-programmers-folly-simple-is-best/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CakePHP DebugKit: Take Back your Debugging</title>
		<link>http://blog.japanesetesting.com/2009/11/12/cakephp-debugkit-take-back-your-debugging/</link>
		<comments>http://blog.japanesetesting.com/2009/11/12/cakephp-debugkit-take-back-your-debugging/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 03:48:47 +0000</pubDate>
		<dc:creator>Harisenbon</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://blog.japanesetesting.com/?p=115</guid>
		<description><![CDATA[Yet another foray into the WORD: The Subtitle blog posts; today we&#8217;re going to look at the amazing features of the CakePHP DebugKit.
The DebugKit is a standard plugin for CakePHP written by Mark Story. It provides a lot more information that the standard debugging features of cake (Errors, warnings, SQL Queries) and also keeps them [...]]]></description>
			<content:encoded><![CDATA[<p>Yet another foray into the <strong>WORD: The Subtitle</strong> blog posts; today we&#8217;re going to look at the amazing features of the CakePHP DebugKit.</p>
<p>The <a href="http://www.ohloh.net/p/cakephp-debugkit">DebugKit </a>is a standard plugin for CakePHP written by <a href="http://mark-story.com/">Mark Story</a>. It provides a lot more information that the standard debugging features of cake (Errors, warnings, SQL Queries) and also keeps them in a nice contained collapsible icon at the top of your page so you don&#8217;t have to have error messages and sql queries appearing all over the page.</p>
<h2>The Debug Kit Interface</h2>
<div id="attachment_120" class="wp-caption aligncenter" style="width: 206px"><img class="size-full wp-image-120 " title="debug_icon" src="http://blog.japanesetesting.com/wp-content/uploads/2009/11/debug_icon.jpg" alt="DebugKit Icon" width="196" height="81" /><p class="wp-caption-text">DebugKit Icon</p></div>
<p>Click the Cake icon at the top of your page, and it expands to all the tools you&#8217;ll need.</p>
<div id="attachment_119" class="wp-caption aligncenter" style="width: 412px"><img class="size-full wp-image-119" title="debug_expanded" src="http://blog.japanesetesting.com/wp-content/uploads/2009/11/debug_expanded.jpg" alt="DebugKit Expanded" width="402" height="35" /><p class="wp-caption-text">DebugKit Expanded</p></div>
<p>If you click any of the titles there, it shows you various debug information such as the current Session information, how the Request was processed, the SQL Log, a timer for all the functions that were called, currently accessible variables and the current memory usage.</p>
<div id="attachment_122" class="wp-caption aligncenter" style="width: 341px"><img class="size-full wp-image-122 " title="debug_variables" src="http://blog.japanesetesting.com/wp-content/uploads/2009/11/debug_variables.jpg" alt="DebugKit Variables View" width="331" height="186" /><p class="wp-caption-text">DebugKit Variables View</p></div>
<div id="attachment_121" class="wp-caption aligncenter" style="width: 341px"><img class="size-full wp-image-121" title="debug_timer" src="http://blog.japanesetesting.com/wp-content/uploads/2009/11/debug_timer.jpg" alt="DebugKit Timer View" width="331" height="277" /><p class="wp-caption-text">DebugKit Timer View</p></div>
<p>All in all, an amazing amount of information. And best of all? It stays out of the way so your designs don&#8217;t get cluttered with debug information while you&#8217;re testing.</p>
<h2>Installation</h2>
<p>Installation is easy.</p>
<h3>Download</h3>
<p>Download the debug kit from ohloh. <a href="http://www.ohloh.net/p/cakephp-debugkit" target="_blank">http://www.ohloh.net/p/cakephp-debugkit</a></p>
<h3>Install</h3>
<p>Place the DebugKig in the plugins folder of your application:</p>
<p>/app/plugins/debug_kit/[INSERT ME HERE]</p>
<h3>Connect</h3>
<p>Add the DebugKit Toolbar component to your app_controller, so it will be available to all your controllers.</p>
<pre class="brush: php;">

// app_controller.php
var $components = array('DebugKit.Toolbar');
</pre>
<p>Then set the debug mode to at least 1.</p>
<h2>Problems</h2>
<p>DebugKit isn&#8217;t a perfect system (or maybe my understanding of it isn&#8217;t quite perfect). In any case, these are some problems I&#8217;ve had with DebugKit, but even they&#8217;re not enough to really gripe about.</p>
<h3>Speed</h3>
<p>DebugKit does seem to take <strong>a lot</strong> more processing power to run it than the standard Debug functions of cake.</p>
<p>This is easy to understand, though, as with the timers, reporters and everything, it&#8217;s doing quite a bit more than the standard Debug functions, and gives you a lot more information. I&#8217;ve had my dev-laptop exceed the 30sec execution time limit quite a few times while running DebugKit, but nothing like that has ever happened on my dev-server, so I doubt it&#8217;s anything major. It does make navigation a bit slower though, so when testing user flow, I would recommend turning it off by setting the Debug level to 0 for the duration of the session.</p>
<p>And remember, if you switch your debug to 0, then the DebugKit isn&#8217;t run at all, so there&#8217;s no worries about it eating precious resources on your live server.</p>
<h3>Ajax Reporting</h3>
<div id="attachment_123" class="wp-caption alignright" style="width: 250px"><img class="size-full wp-image-123" title="debug_ajax" src="http://blog.japanesetesting.com/wp-content/uploads/2009/11/debug_ajax.jpg" alt="Ajax doesn't seem to be affected" width="240" height="187" /><p class="wp-caption-text">Ajax doesn&#39;t seem to be affected</p></div>
<p>When you make a request with Ajax, the DebugKit doesn&#8217;t seem to get spun up like it should &#8212; which results in it reverting to the standard CakePHP reporting, which (while not bad) is definitely a grade down compared to the glory of DebugKit. It would have been nice to have the reporting fed into another icon inside the div that displays the ajax result, or something to that effect. Perhaps there is a way, and I just haven&#8217;t found it yet. Always a possibility.</p>
<h2>Conclusion</h2>
<p>Really, there isn&#8217;t much else to say except: why are you waiting? <a href="http://www.ohloh.net/p/cakephp-debugkit" target="_blank">Go download this thing now!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.japanesetesting.com/2009/11/12/cakephp-debugkit-take-back-your-debugging/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Return of the FaceBox: Iframes!</title>
		<link>http://blog.japanesetesting.com/2009/10/19/return-of-the-facebox-iframes/</link>
		<comments>http://blog.japanesetesting.com/2009/10/19/return-of-the-facebox-iframes/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 07:27:36 +0000</pubDate>
		<dc:creator>Harisenbon</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[facebox]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://blog.japanesetesting.com/?p=106</guid>
		<description><![CDATA[This article is a follow-up to my (oddly?) popular article Simple Modal Boxes: FaceBox with Prototype which, as the name implies, talks about how to get FaceBox ( the amazingly cool JQuery Facebox-like modal window) to work with the Prototype framework, and then releases that code under the MIT license.
Where things went wrong: IFrames
I was [...]]]></description>
			<content:encoded><![CDATA[<p>This article is a follow-up to my (oddly?) popular article <a href="http://blog.japanesetesting.com/2009/08/28/simple-modal-boxes-facebox-with-prototype/" target="_blank">Simple Modal Boxes: FaceBox with Prototype</a> which, as the name implies, talks about how to get <a href="http://famspam.com/facebox" target="_blank">FaceBox </a>( the amazingly cool JQuery Facebox-like modal window) to work with the Prototype framework, and then releases that code under the MIT license.</p>
<div id="attachment_93" class="wp-caption aligncenter" style="width: 360px"><img class="size-full wp-image-93" title="ippatsu_facebox" src="http://blog.japanesetesting.com/wp-content/uploads/2009/08/ippatsu_facebox.jpg" alt="Ippatsu's Flashcard FaceBox" width="350" height="220" /><p class="wp-caption-text">Ippatsu&#39;s Flashcard FaceBox</p></div>
<h2>Where things went wrong: IFrames</h2>
<p>I was fairly forthcoming about it when I released version 1.1, but my FaceBox had a major problem: Loading full HTML pages <em>(as opposed to html snippets)</em> borked the system. It was a combination of the &lt;head&gt; and &lt;body&gt; tags along with all that excess Javascript and CSS being loaded into an inline div that pretty much did it in. IE6 would display it (poorly) while anything else just gave up and displayed an empty box.</p>
<p><strong>So I fixed it. </strong></p>
<p>Starting with version 1.2 you can set a facebox to load in an IFrame by simply adding the tag &#8220;iframe&#8221; to the rel tag of the link.</p>
<pre class="brush: xml;">
So
&lt;a rel=&quot;facebox&quot; href=&quot;mypage.html&quot;&gt;My Page!&lt;/a&gt;

becomes
&lt;a rel=&quot;facebox iframe&quot; href=&quot;http://google.com&quot;&gt;Google&lt;/a&gt;
</pre>
<p>and now you&#8217;re cooking with crisco. The page will be loaded in an IFrame, and any links will be self-contained within that iframe unless you specifically break out of it.</p>
<h2>Breaking backwards compatibility</h2>
<p>So, I am a big believer in backwards compatibility, but unfortunately adding the iframe option, along with my desire to adhere to better HTML coding practices has made me break backwards compatibility with version 1.1.</p>
<h3>But wait!</h3>
<p>It&#8217;s <strong>simple </strong>to change over, and you can change over almost all your code with a simple search/replace! <strong>So let&#8217;s get to it!</strong></p>
<h2>New way to handle classes</h2>
<p>The old way of handing classes was to simply put all the classes you wanted to use after a hyphen after the facebox tag, like so:</p>
<pre class="brush: xml;">
&lt;a href=&quot;mypage.html&quot; rel=&quot;facebox-class1 class2&quot;&gt;My Classy Page!&lt;/a&gt;
</pre>
<p>This brings about the problem that now &#8220;iframe&#8221; is just thought of as a class. (It&#8217;s also not very contained, and rather messy). So I changed to to be more self-contained by putting the classes in square brackets []:</p>
<p><strong>The new Code</strong></p>
<pre class="brush: xml;">
&lt;a href=&quot;mypage.html&quot; rel=&quot;facebox[class1 class2]&quot;&gt;My Classy Page!&lt;/a&gt;
</pre>
<p>Now you know exactly what is a class, and what is not, and it&#8217;s easier to use it in conjunction with the IFrames option above.</p>
<pre class="brush: xml;">
&lt;a href=&quot;http://google.com&quot; rel=&quot;facebox[class1 class2] iframe&quot;&gt;This loads google in its own classy iframe&lt;/a&gt;
</pre>
<p>Simple as pie.</p>
<h2>New way to handle styles</h2>
<p>Originally, my way to handle styles (useful for setting the height and width of a Facebox for a single message or page) was to put the data in the <strong>rev</strong> tag and just pass that through to the FaceBox. However, with the new class syntax, I had a chance to change the way that the styling works.</p>
<p><em>Also, the <strong>rev </strong>tag is used to describe how the <strong>current</strong> document applies to the link, so it really isn&#8217;t a good place to put the data syntactically. It&#8217;s much better to put it in the <strong>rel</strong> tag along with the class information.</em></p>
<h3>The new code</h3>
<pre class="brush: xml;">
So where you used to use the rev tag:
&lt;a href=&quot;mypage.html&quot; rel=&quot;facebox&quot; rev=&quot;width: 500px; height: 300px&quot;&gt;My Stylish Page!&lt;/a&gt;

You'll now use curly brackets in the rel tag:
&lt;a href=&quot;mypage.html&quot; rel=&quot;facebox{width: 500px; height: 300px}&quot;&gt;My Stylish Page!&lt;/a&gt;
</pre>
<p>And we can combine that with the iframes and classes above, to further customize our facebox</p>
<pre class="brush: xml;">
Class and Style
&lt;a href=&quot;mypage.html&quot; rel=&quot;facebox[class1 class2]{width: 500px; height: 300px}&quot;&gt;My Classy Stylish Page!&lt;/a&gt;

Iframe Class and Style
&lt;a href=&quot;http://google.com&quot; rel=&quot;facebox[class1 class2]{width: 500px; height: 300px} iframe&quot;&gt;This loads google in its own classy and stylish iframe&lt;/a&gt;
</pre>
<h2>Download the code</h2>
<p>You can download the code right here! It&#8217;s Open sourced under the MIT License.</p>
<p>If you find any problems or bugs, feel free to drop me a comment!</p>
<p>Download <a href="/download/facebox_1_2.zip">FaceBox v 1.2</a> (Open sourced under the MIT License)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.japanesetesting.com/2009/10/19/return-of-the-facebox-iframes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simple Modal Boxes: FaceBox with Prototype</title>
		<link>http://blog.japanesetesting.com/2009/08/28/simple-modal-boxes-facebox-with-prototype/</link>
		<comments>http://blog.japanesetesting.com/2009/08/28/simple-modal-boxes-facebox-with-prototype/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 01:33:56 +0000</pubDate>
		<dc:creator>Harisenbon</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[facebox]]></category>

		<guid isPermaLink="false">http://blog.japanesetesting.com/?p=36</guid>
		<description><![CDATA[I&#8217;ve updated my code with a newer version: Version 1.2 which includes such awesome things as full IFrame support and better support for classes and styles! You can check out the Article, or just download the code from here! The way the code is used has been changed, so be sure to read the README!

This [...]]]></description>
			<content:encoded><![CDATA[<div style="padding: 5px; border: 1px solid #616161; background: lightYellow;"><img class="alignleft size-full wp-image-112" style="margin-right: 10px;" title="alert" src="http://blog.japanesetesting.com/wp-content/uploads/2009/08/icon_notice_alert.png" alt="alert" width="79" height="73" />I&#8217;ve updated my code with a newer version: <a href="/download/facebox_1_2.zip">Version 1.2</a> which includes such awesome things as full IFrame support and better support for classes and styles! You can check out the <a href="http://blog.japanesetesting.com/2009/10/19/return-of-the-facebox-iframes/">Article</a>, or just <a href="/download/facebox_1_2.zip">download the code from here</a>! <strong>The way the code is used has been changed, so be sure to read the README!</strong>
</div>
<h2>This article will teach you how to:</h2>
<p>Open facebook-styled modal windows in both alert box and full ajax-styled version, using the FaceBox modal window script and Prototype.</p>
<p>I wanted my<a href="http://japanesetesting.com/news" target="_blank"> signup page for Ippatsu</a>, an online Japanese learning application, to use a modal window for the sign up dialog.  This allows me to use most of the visible area for copywriting, while not requiring a page transition to load the signup form.<br />
You can also create modal windows like these with Prototype and the<a href="/download/facebox_1_1.zip"> OSS code I&#8217;m releasing below.</a></p>
<div id="attachment_93" class="wp-caption aligncenter" style="width: 360px"><img class="size-full wp-image-93" title="ippatsu_facebox" src="http://blog.japanesetesting.com/wp-content/uploads/2009/08/ippatsu_facebox.jpg" alt="Ippatsu's Flashcard FaceBox" width="350" height="220" /><p class="wp-caption-text">Ippatsu&#39;s Flashcard FaceBox</p></div>
<h2>A little history</h2>
<p>Originally these modal boxes were used mainly for photogalleries and whatnot, and took up the entire screen with a cool faded out background and had a lot of animations. Probably the nicest and most well known was <a href="http://www.phatfusion.net/" target="_blank">PhatFusion&#8217;s</a> lightbox and multibox which are written on the MooTools javascript library.</p>
<p>As time went on, people wanted simpler boxes that did away with all the animation and crap and so extremely simple boxes like <a href="http://particletree.com/features/lightbox-gone-wild/">Particletree&#8217;s Lightbox Gone Wild </a>which is a simple box with no animation over a 70% black border. It&#8217;s small, simple and gives a rather nice effect.</p>
<h2>So what&#8217;s the problem?</h2>
<p>Well, the problem with animation should be obvious: It&#8217;s slow and can be jerky on certain browsers. Definately not something you want to use for a UI Element.</p>
<p>And the issue with the background is that when you have your entire site blacked out, while you gain focus on the window you&#8217;ve just put up, it&#8217;s not very useful for information that you want to give the user without preventing them from seeing the rest of your site. In other words, we want a <strong>Modal Window </strong>instead of a lightbox type thing.</p>
<h2>So Bring on the Modal Windows!</h2>
<p>As far as this discussion is concerned, I&#8217;m going to be ignoring the windows-like full modal windows that allow dragging and dropping and whatnot, and only focus on simple Modal Boxes that can be used to display data. In particular, FaceBox.</p>
<h2>Get to the Code Already</h2>
<p>Ok, so FaceBox is a JQuery based modal window that is pretty much copied from the facebook site where they use it to display small bits of ajax text. It is amazing. You can get it at <a href="http://famspam.com/facebox" target="_blank">http://famspam.com/facebox</a> . However, it only works with JQuery, whose existance I was not aware of at the time of creating my site, so I had to find a Prototype version.</p>
<p>FaceBox Prototype in google gave me a couple of good links, the most popular being <a href="http://blog.philburrows.com/articles/2008/05/05/porting-facebox-from-jquery-to-prototype/" target="_blank">Phill Burrows&#8217; blog</a> in which he ported FaceBox from JQuery to Prototype. Unfortunately, the post (and code) is rather old, and did not work on the newest version of Prototype that I was using (1.6.0.3).</p>
<p>Eventually I came to two guys who took Phill Burrow&#8217;s code and updated it: <a href="http://github.com/robertgaal/facebox-for-prototype/tree/master" target="_blank">Robert Gaal</a> and <a href="http://github.com/jetviper21/prototype-facebox/" target="_blank">Scott Davis</a>. Both seem very nice, but I was having some problems with the slightly older Robert Gaal version, and so decided to go with JetViper&#8217;s version, as it also proposed to have class support.</p>
<p>Unfortunately there were a few large problems with the FaceBox code as it as written:</p>
<ol>
<li>The code did not support class definitions of the FaceBox like it purported to (because of a coding error)</li>
<li>There was no way to set the size of the FaceBox from code</li>
<li>If the page being loaded was really long (such as having cakephp debug information) the window would stretch to fit all the contents height-wise, without scrolling</li>
<li>No iframe support, so loading a page with javascript borked the load.</li>
<li>No Close on Escape button</li>
</ol>
<p>So I dug into the code and made some changes, and was able to fix problems 1-3 and 5 (and am still working on 4). The entirety of the code can be downloaded at the bottom of this page.</p>
<h2>Fixing the classes</h2>
<p>Looking at the original .js (line 175), you can see that Scott&#8217;s code says that you can add a class to the FaceBox content by changing the rel tag in the link to &#8220;facebox[.my_class]&#8221;</p>
<pre class="brush: jscript;">
// support for rel=&quot;facebox[.inline_popup]&quot; syntax, to add a class
var klass = elem.rel.match(/facebox\[\.(\w+)\]/);
if (klass) klass = klass[1];
</pre>
<p>Unfortunately, due to the way that FaceBox searches for FaceBox-enabled links, it will not recognize &#8220;facebox[.my_class]&#8221; as a FaceBox, as it looks for a direct match with rel=facebox.</p>
<p>So, I fixed that bug by changing line 93 in the watchClickEvents from</p>
<pre class="brush: jscript;">$$('a[rel=facebox]').each .....</pre>
<p>to</p>
<pre class="brush: jscript;">$$('a[rel|=facebox]').each .....</pre>
<p>The |= selector is a CSS Selector (valid in prototype) that allows you to define that The attribute&#8217;s exact value is &#8220;facebox&#8221; or starts with the word &#8220;facebox&#8221; and is immediately followed by &#8220;-&#8221;, so it would be &#8220;facebox-&#8221;. You can read more about Attribute Selectors at <a href="http://www.smashingmagazine.com/2009/08/17/taming-advanced-css-selectors/" target="_blank">Smashing Magazine&#8217;s Taming Advanced CSS Selectors</a>. It&#8217;s an amazing read. You can also learn about ~= (whitespace seperated) ^= (starts with) $= (ends with) and *= (contains) all of which are valid types of CSS selectors.</p>
<p>But wait, you say! How does &#8220;facebox-&#8221; translated to &#8220;facebox[.my_class]&#8220;?!?</p>
<p>It doesn&#8217;t.</p>
<p>I find facebox[.my_class] to be really unwieldy, so I changed it to facebox-my_class. This way, you can also put additional rel data in the link if you need, as long as facebox comes first.<br />
All of these are valid:</p>
<pre class="brush: jscript;">rel=&quot;facebox-my_class help&quot;
rel=&quot;facebox-my_class&quot;
rel=&quot;facebox&quot;
</pre>
<p>So, in light of this, we have to change the regex match in the click_handler from:</p>
<pre class="brush: jscript;">
// support for rel=&quot;facebox[.inline_popup]&quot; syntax, to add a class
var klass = elem.rel.match(/facebox\[\.(\w+)\]/);
if (klass) klass = klass[1];
</pre>
<p>to</p>
<pre class="brush: jscript;">
// support for rel=&quot;facebox-inline_popup&quot; syntax, to add a class
 var klass = elem.rel.match(/facebox\-(\w+)/);
 if (klass) klass = klass[1];
</pre>
<p>And then in your CSS to use the class:</p>
<pre class="brush: css;">
#facebox_content.my_class{
 height: 300px;
 width: 500px;
 }
</pre>
<p>Done and done!</p>
<p>(As a smaller bug fix, I noticed that the original code never deletes previously added classes &#8212; only appends them, so I added this line to the reveal function to make sure that the classes were reset each time you opened a FaceBox</p>
<pre class="brush: jscript;">contentWrapper.className = 'content';</pre>
<h2>Stylize that Sucker!</h2>
<p>So, problem 2 is that FaceBox has no way to stylize the lightwindow contents on a per-link basis &#8212; you have to define a whole new class for each type of lightwindow that you want. This in itself is not so bad, but it would be nice to have that slight extra amount of customizable power.</p>
<p>So, what I did is just add a &#8220;style&#8221; variable to each of the reveal/ajax/etc function calls, and had it append that style to the facebox_content div.</p>
<pre class="brush: jscript;">
reveal    : function(data, klass, style){
....
//Set H/W or any other styles (also clears styles)
 contentWrapper.writeAttribute('style', style);
....
</pre>
<p>If you&#8217;re calling the lightbox from code, you just add whatever style attributes you want to the call</p>
<pre>facebox.ajax('mypage.html', 'my_class', 'height:300px;width:400px;'</pre>
<p>If you&#8217;re using the automatic calling from the rel tag, then you have to add a rev tag, and put your stylesheet in there. Anything you put in the rev tag will be copied to the style attribute of the contentWrapper</p>
<pre class="brush: xml;">&lt;a href=&quot;mypage.html&quot; rel=&quot;facebox-my_class&quot; rev=&quot;height:300px;width:400px&quot;&gt;Link&lt;/a&gt;</pre>
<p>Simple as that!</p>
<p>(It should be noted however, that the height and width of the content_window does not take into account the borders, padding and footer of the FaceBox, so be sure to leave yourself a little margin of error)</p>
<h2>No Scrollbars?!?</h2>
<p>You still with me? It&#8217;s been long, I know, but just hang with me a little more. This is the last point.</p>
<p>So, as I said earlier, there&#8217;s a problem(?) with FaceBox wherein long content just makes the FaceBox longer until all the content is shown. As this system is made for display quick banners and small ajax pages and what not, it&#8217;s understandable that it would be left out, but why not put it in when it&#8217;s so damn simple?</p>
<p>So how do you do it?</p>
<pre class="brush: css;">
//facebox.css
#facebox_content{
 overflow: auto;
 }
</pre>
<p>That&#8217;s it.</p>
<p>What this does is allows the FaceBox to extend to show all the content normally, but if you decided that the FaceBox needs a certain height (through a class or styling) then the FaceBox will be set to that height, and anything that goes over that height will be scrollable.</p>
<p>That Damn Simple.</p>
<h2>In Conclusion</h2>
<p>Not much of an &#8220;In Conclusion.&#8221; I&#8217;ve pretty much said all I want to say, so all there is left is to check out the codes~</p>
<p>If you find any problems or bugs, feel free to drop me a comment!</p>
<div style="padding: 5px; border: 1px solid #616161; background: lightYellow;"><img class="alignleft size-full wp-image-112" style="margin-right: 10px;" title="alert" src="http://blog.japanesetesting.com/wp-content/uploads/2009/08/icon_notice_alert.png" alt="alert" width="79" height="73" />I&#8217;ve updated my code with a newer version: <a href="/download/facebox_1_2.zip">Version 1.2</a> which includes such awesome things as full IFrame support and better support for classes and styles! You can check out the <a href="http://blog.japanesetesting.com/2009/10/19/return-of-the-facebox-iframes/">Article</a>, or just <a href="/download/facebox_1_2.zip">download the code from here</a>! <strong>The way the code is used has been changed, so be sure to read the README!</strong></div>
<p><span style="text-decoration: line-through;">Download <a href="/download/facebox_1_1.zip">FaceBox v 1.1</a> </span>(Open sourced under the MIT License)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.japanesetesting.com/2009/08/28/simple-modal-boxes-facebox-with-prototype/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
