<?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>Tudor Barbu&#039;s professional blog &#187; client side</title>
	<atom:link href="http://blog.motane.lu/tag/client-side/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.motane.lu</link>
	<description>Ramblings about software development</description>
	<lastBuildDate>Thu, 02 Feb 2012 17:38:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Working with dates in Javascript</title>
		<link>http://blog.motane.lu/2009/07/15/working-with-dates-in-javascript/</link>
		<comments>http://blog.motane.lu/2009/07/15/working-with-dates-in-javascript/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 08:12:40 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[client side]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=613</guid>
		<description><![CDATA[I have found a cool Javascript library for manipulating dates called datejs. It&#8217;s really simple to use and offers a lot of syntactic sugar (examples taken from their website) It saves a lot of headaches]]></description>
			<content:encoded><![CDATA[<p>I have found a cool Javascript library for manipulating dates called <a href="http://www.datejs.com/" title="Datejs javascript library" class="outgoing">datejs</a>. It&#8217;s really simple to use and offers a lot of syntactic sugar (examples taken from their website)</p>
<pre class="brush: jscript; title: ; notranslate">
// Add 3 days to Today
Date.today().add(3).days();

// Is today Friday?
Date.today().is().friday();

// Number fun
(3).days().ago();

// 6 months from now
var n = 6;
n.months().fromNow();
</pre>
<p>It saves a lot of headaches <img src='http://blog.motane.lu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2009/07/15/working-with-dates-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTTP headers and AJAX requests</title>
		<link>http://blog.motane.lu/2009/02/11/http-headers-and-ajax-requests/</link>
		<comments>http://blog.motane.lu/2009/02/11/http-headers-and-ajax-requests/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 22:32:12 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[client side]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=339</guid>
		<description><![CDATA[This post is about a quite common problem that I&#8217;ve encountered over and over again but didn&#8217;t look into it to find a proper answer to it. The problem is what happens when I request via AJAX a page that makes a HTTP redirect to another and how do I fix it to behave &#8220;normally&#8221;. [...]]]></description>
			<content:encoded><![CDATA[<p>This post is about a quite common problem that I&#8217;ve encountered over and over again but didn&#8217;t look into it to find a proper answer to it. The problem is what happens when I request via AJAX a page that makes a HTTP redirect to another and how do I fix it to behave &#8220;normally&#8221;. It&#8217;s quite common problem with pages that require authentication.</p>
<p>Let&#8217;s say we have the following PHP script: </p>
<pre class="brush: php; title: ; notranslate">
if( !is_user_allowed() ) {
    header( 'Location: ' . PATH_TO_LOGIN_PAGE );
    die();
}
</pre>
<p>Pretty simple and self explanatory. If the user isn&#8217;t logged in, he gets sent to the login form. But what happens if the request is made via AJAX? A simple AJAX request made using the prototype.js library looks like this:</p>
<pre class="brush: jscript; title: ; notranslate">
new Ajax.Request(
    'server_side.php',
    {
        onSuccess: function( t ) {
            $( 'container' ).update( t.responseText );
        }
    }
);
</pre>
<p>What happens if the user isn&#8217;t logged in? The browser makes two requests to the server, the second one to the page containing the login form. </p>
<p><img src="http://blog.motane.lu/wp-content/uploads/2009/02/requests.png" alt="requests" title="requests" width="450" height="150" class="size-full wp-image-434" />  </p>
<p>And the whole login page gets loaded into a small container on current page, ruining the design and confusing the user.</p>
<p>Although I&#8217;ve encountered this problem on several occasions, I didn&#8217;t give it much thought. I&#8217;ve used that very popular design pattern &#8220;I know it&#8217;s lame, but hey, it works&#8230;moving on&#8221;. The implementation on case was like this: add a token to the login page&#8217;s markup, something like <code><!-- login --></code> and check to see if this string is in the response text. Like this:</p>
<pre class="brush: jscript; title: ; notranslate">
new Ajax.Request(
    'server_side.php',
    {
        onSuccess: function( t ) {
            if( t.responseText.indexOf( '&lt;!--login--&gt;') != -1 ) {
                document.location = 'login.php';
            }
            else {
                $( 'container' ).update( t.responseText );
            }
        }
    }
);
</pre>
<p>Plain and simple. And lame. I admit it. But hey! It works <img src='http://blog.motane.lu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Still, I&#8217;ve found a better way of doing things, that relies on HTTP headers. First of all, in the login page, instead of a lame string message, I&#8217;ve added some custom headers to the response. </p>
<pre class="brush: php; title: ; notranslate">
header( 'HTTP/1.0 401 Authorization Required' );
header( 'Login-path: ' . PATH_TO_LOGIN_PAGE );
</pre>
<p>And then, I&#8217;ve altered the the javascript a little. Since a response served with a 401 header won&#8217;t trigger the onSuccess callback function, this script uses <a href="http://prototypejs.org/api/ajax/options" title="onComplete on prototype's API" class="outgoing">onComplete</a>.</p>
<pre class="brush: jscript; title: ; notranslate">
new Ajax.Request(
    'server_side.php',
    {
        onComplete: function( t ) {
            switch( t.status ) {
                case 200:
                    $( 'container' ).update( t.responseText );
                    break;
                case 401:
                    document.location = t.getHeader( 'Login-path' );
                    break;
            }
        }
    }
)
</pre>
<p>It works. And it&#8217;s not so lame. Mission accomplished&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2009/02/11/http-headers-and-ajax-requests/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Equal height divs</title>
		<link>http://blog.motane.lu/2008/12/28/equal-height-divs/</link>
		<comments>http://blog.motane.lu/2008/12/28/equal-height-divs/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 07:46:29 +0000</pubDate>
		<dc:creator>Tudor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[client side]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.motane.lu/?p=92</guid>
		<description><![CDATA[Today&#8217;s topic, equal height columns. Back in the old days, when everybody was using tables, creating equal height columns was a piece of cake. The height of a table row &#8211; &#60;tr&#62; &#8211; and its cells was automatically changed to accommodate any amount of content. Nowadays, in our brand new Web2.0 world, people don&#8217;t use [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s topic, <strong>equal height columns</strong>. Back in the old days, when everybody was using tables, creating equal height columns was a piece of cake. The height of a table row &#8211; &lt;tr&gt; &#8211; and its cells was automatically changed to accommodate any amount of content. Nowadays, in our brand new Web2.0 world, people don&#8217;t use tables to set up the layout of a page. Everybody goes for CSS now. But using only CSS is pretty hard (to be read &#8220;almost impossible&#8221;) to set up a page where multiple columns have the same height. And it becomes even harder to do so when a column changes size (some hidden content is displayed).  What then? Well, of course, javascript to the rescue.    <span id="more-92"></span></p>
<p>I&#8217;ve wrote a small script that computes the maximum height between several divs, and forces this height on the shorter divs. You can also add a listener to monitor if one of the divs changes height and if that happens, the script will act accordingly, making all the divs equal again.</p>
<p>It&#8217;s quite simple to use, just insert this script anywhere on your page:</p>
<pre class="brush: jscript; title: ; notranslate">
Event.observe(
	window,
	'load',
	function() {
		var e = new Equalizer( 'div1', 'div2', 'div3');
	},
	true
);
</pre>
<p>Where div1, div2 and div3 are the ids of the divs representing the columns. If you need to add some extra content in one of those divs, just start a <a href="http://www.prototypejs.org/api/periodicalExecuter" title="PeriodicalExecuter in prototype's API" class="outgoing">PeriodicalExecuter</a> to check if one of the divs changed size.</p>
<pre class="brush: jscript; title: ; notranslate">
Event.observe(
	window,
	'load',
	function() {
		var e = new Equalizer( 'div1', 'div2', 'div3');
		var pe = new PeriodicalExecuter(
			function() {
				Equalizer.keep( e );
			},
			1 // repeat each second
		);
	},
	true
);
</pre>
<p>Enough said, here is a <a href="http://demos.motane.lu/equal_height_divs/equal_height_divs.html" title="Equal height divs">working demo</a>. You can get just the <a href="http://downloads.motane.lu/equalizer.js" title="Download equalizer.js" class="download">js</a> file from here, note that the <a href="http://www.prototypejs.org/" title="Prototype Framework">prototype library</a> is required in order for the script to work.</p>
<p>This script was tested in many browsers, such as IE6 &amp; 7, Firefox, Opera, Safari (Windows version) and Flock and it worked, but experience taught me to always expect the unexpected, so things might go wrong at any time. When this happens, don&#8217;t panic, just a post a short message below, describing your error.</p>
<h2><span>Bugs I already know about</span></h2>
<p>Yes! I know that there are some problems with this script and I&#8217;m going to fix them. Or at least try to do so.</p>
<p>The first problem is that when additional content is added to a div, the rest of them stretch to the new height. But when the extra content is hidden, all the divs keep the new height. That&#8217;s because the <em>minHeight</em> attribute still holds the larger value that was set when the hidden content became visible. The approach I&#8217;ve tried so far was to compute the height of a div as the sum of all its visible children&#8217;s heights, rather then to use the div&#8217;s CSS defined height as it&#8217;s returned by the <a href="http://www.prototypejs.org/api/element#method-getheight" title="Element.getHeight() in prototype.js API">Element.getHeight()</a> method.</p>
<pre class="brush: jscript; title: ; notranslate">
/**
 * computes the height of a div as the sum
 * of its visible childrens' heights
 *
 * @param DOMObject div
 */
getComputedHeight = function( div ) {
	if ( div.hasChildNodes() ) {
		var height = 0;
		var child = null;
		div.childNodes.each(
			function( item ) {
				item = $( item );
				if( item.nodeName != '#text' &amp;&amp; item.visible() ) {
					height += item.getHeight();
				}
			}
		);
		return height;
	}
	return div.getHeight();
}
</pre>
<p>For some unknown reason, this doesn&#8217;t quite work as I expected <img src='http://blog.motane.lu/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  But I&#8217;m working on it!</p>
<p>The other problem I came across and I was unable to fix so far is the fact that the divs change height when the user changes the font size (CTRL+/CTRL-). Quite normal behaviour, but annoying in this case.</p>
<p>If you have any idea in how to solve these problems, please post a comment bellow or contact me. Credits will be given.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.motane.lu/2008/12/28/equal-height-divs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

