<?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>A Twofer &#187; Mootools</title>
	<atom:link href="http://www.atwofer.com/category/mootools/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.atwofer.com</link>
	<description>A place to talk about Software Development (RoR, J2EE, J2ME, CSS, HTML, JavaScript, Objective-C, etc) and some other stuff</description>
	<lastBuildDate>Fri, 16 Jul 2010 14:56:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Prompt User About Unsaved Changes Using Mootools</title>
		<link>http://www.atwofer.com/2009/01/02/prompt-user-about-unsaved-changes-using-mootools/</link>
		<comments>http://www.atwofer.com/2009/01/02/prompt-user-about-unsaved-changes-using-mootools/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 21:41:16 +0000</pubDate>
		<dc:creator>Randy</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mootools]]></category>

		<guid isPermaLink="false">http://www.atwofer.com/?p=65</guid>
		<description><![CDATA[Mootools has a very useful method toQueryString on the Form element class.  In short, this method takes all the form fields and builds a query string generally used when sending form data to the server.  However, I found another use for this method that I thought I would share.
For our Episodic Video Publishing Web Application [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mootools.net/docs/" target="_blank">Mootools</a> has a very useful method <a href="http://mootools.net/docs/Element/Element#Element:toQueryString" target="_blank">toQueryString</a> on the Form element class.  In short, this method takes all the form fields and builds a query string generally used when sending form data to the server.  However, I found another use for this method that I thought I would share.</p>
<p>For our <a href="http://www.episodic.com/" target="_blank">Episodic Video Publishing Web Application</a> we have a number of pages that include a form.  If the user tries to navigate from a form that has unsaved changes then we want to prompt the user that they have unsaved changes and that these changes will be lost if they navigate away.  There are various ways that you can detect if the user has modified the page&#8217;s form but the easiest I&#8217;ve found is to make use of <a href="http://mootools.net/docs/Element/Element#Element:toQueryString" target="_blank">Form.toQueryString</a>.</p>
<p>First, create a function that stores the form state in a hidden input.</p>
<p><code>getOrCreateInitialFormState: function(form) {<br />
<span style="padding-left: 10px;">var formInitialState = null;</span>,<br />
<span style="padding-left: 10px;">var formInitialState = $('form_initial_state');</span><br />
<span style="padding-left: 10px;">if (!formInitialState)</span><br />
<span style="padding-left: 20px;">formInitialState = new Element('input', {</span><br />
<span style="padding-left: 20px;">id: 'form_initial_state',</span><br />
<span style="padding-left: 20px;">type: 'hidden',</span><br />
<span style="padding-left: 20px;">value: form.toQueryString()</span><br />
<span style="padding-left: 10px;">}).inject(form, 'before');</span><br />
<span style="padding-left: 10px;">return formInitialState;</span><br />
}</code></p>
<p>So when the page loads record the current form state and hook into the click event for any links on your page and check if the form state has changed.</p>
<p><code>window.addEvent('domready', function()<br />
{<br />
<span style="padding-left: 10px;">// Grab the form</span><br />
<span style="padding-left: 10px;">var form = $('my_form');</span></p>
<p><span style="padding-left: 10px;">// Store the form state in a hidden input</span><br />
<span style="padding-left: 10px;">getOrCreateInitialFormState(form);</span></p>
<p><span style="padding-left: 10px;">// Capture any clicks that would cause the user to navigate away</span><br />
<span style="padding-left: 10px;">$$('a').addEvent('click', function(e) {</span><br />
<span style="padding-left: 20px;">if (form.toQueryString() != getOrCreateInitialFormState(form) {</span><br />
<span style="padding-left: 30px;">e.stop();</span><br />
<span style="padding-left: 30px;">var result = confirm('You have unsaved changes.' +</span><br />
<span style="padding-left: 50px;">'  Are you sure you want to navigate away from this page?');</span><br />
<span style="padding-left: 30px;">if (result == true) {</span><br />
<span style="padding-left: 40px;">// The user wants to navigate</span><br />
<span style="padding-left: 40px;">window.location.href = a.get('href');</span><br />
<span style="padding-left: 30px;">}</span><br />
<span style="padding-left: 20px;">} </span><br />
<span style="padding-left: 10px;">});</span><br />
});<br />
</code></p>
<p>That&#8217;s it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.atwofer.com/2009/01/02/prompt-user-about-unsaved-changes-using-mootools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE7 Tricks</title>
		<link>http://www.atwofer.com/2008/12/10/ie7-tricks/</link>
		<comments>http://www.atwofer.com/2008/12/10/ie7-tricks/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 18:09:51 +0000</pubDate>
		<dc:creator>Randy</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[IE7]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mootools]]></category>

		<guid isPermaLink="false">http://www.atwofer.com/?p=10</guid>
		<description><![CDATA[Hey, my first post and I already spent an hour setting up wordpress so I&#8217;ll keep it short.  Recently, we did an overhaul of our video management web application at Episodic.  Like any sane web developer I did all my testing in Firefox and then found myself with one day left before pushing to production [...]]]></description>
			<content:encoded><![CDATA[<p>Hey, my first post and I already spent an hour setting up wordpress so I&#8217;ll keep it short.  Recently, we did an overhaul of our video management web application at <a href="http://www.episodic.com">Episodic</a>.  Like any sane web developer I did all my testing in Firefox and then found myself with one day left before pushing to production and I had yet to look at our site in IE7 (IE6 not supported).</p>
<p>So I RDC&#8217;d to our one Windows box and, uh oh, it don&#8217;t look so good and there are a bunch of JS errors.  Here were a few of the main problems that I had to solve for IE.</p>
<p><strong>Trailing Commas</strong></p>
<p>IE does not like trailing commas in things like object declarations.  For example, you will get a very general JS error that points to a line that has nothing to do with the problem if you have the following:</p>
<p><code>var myObject = {<br />
<span style="padding-left: 10px;">foo: 'bar'</span>,<br />
<span style="padding-left: 10px;">baz: anotherObject<span style="color: #800000;">,</span></span><br />
};</code></p>
<p><strong>Positioning and Z-Index</strong></p>
<p>Our site has a lot of fancy drop-down menus.  The menu is absolutely positioned within some relatively positioned element and then given a z-index so that it appears overtop of other elements on the page.  However, this was a problem on IE when I noticed that my menu would actually appear behind some elements on the page.  In particular, the menu would appear behind other elements that have &#8220;position:relative&#8221;.</p>
<p>This took a while for me to figure out.  Eventually it came down to this: If an absolutely positioned element has a z-index then it&#8217;s containing relatively positioned element must specify a z-index (z-index:1) in order for the absolutely positioned element to be able to appear on top of other relatively positioned elements.</p>
<p>I did not come up with this on my own but it did take me a while to find this excellent page called &#8220;<a href="http://css-class.com/test/css/visformatting/layers/z-index.htm">Z-Indexing with position relative and absolute</a>&#8220;.</p>
<p><strong>Mootools Events Targets</strong></p>
<p>I LOVE <a href="http://www.mootools.net">Mootools</a>.  Eventually I will do another post about some Mootools tricks I have picked up but for now I&#8217;ll stay within the context of this post.  I have a lot of JS code that looks like the following:</p>
<p><code>someElement.addEvent('click', function(event) {<br />
<span style="padding-left:10px">if (event.target.get('tag') == 'li'</span><br />
<span style="padding-left:20px">event.target.dispose();</span><br />
});</code></p>
<p>However, the Mootools documentation says that <span style="text-decoration: underline;">the event target, is not extended with $ for performance reasons</span> (which actually only seems to be true in IE and would result in JS errors).  Therefore, the above case should be written as:</p>
<p><code>someElement.addEvent('click', function(event) {<br />
<span style="padding-left:10px">if ($(event.target).get('tag') == 'li'</span><br />
<span style="padding-left:20px">$(event.target).dispose();</span><br />
});</code></p>
<p>To avoid writing code like this everywhere I extended the Event class as follows:</p>
<p><code>Event.implement({<br />
<span style="padding-left:10px">getTarget: function() {</span><br />
<span style="padding-left:20px">if (!this.extendedTarget)</span><br />
<span style="padding-left:30px">this.extendedTarget = $(this.target);</span><br />
<span style="padding-left:20px">return this.extendedTarget;</span><br />
});</code></p>
<p>This left me with:</p>
<p><code>someElement.addEvent('click', function(event) {<br />
<span style="padding-left:10px">if (event.getTarget().get('tag') == 'li'</span><br />
<span style="padding-left:20px">event.getTarget().dispose();</span><br />
});</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.atwofer.com/2008/12/10/ie7-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
