<?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>Diego Pessoa &#187; Programming</title>
	<atom:link href="http://www.diegopessoa.com/lang/en/categories/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.diegopessoa.com</link>
	<description></description>
	<lastBuildDate>Thu, 07 Jan 2010 04:22:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Solving the problem of &#8220;back&#8221; button in Ajax applications</title>
		<link>http://www.diegopessoa.com/lang/en/2009/03/09/solving-the-problem-of-back-button-in-ajax-applications</link>
		<comments>http://www.diegopessoa.com/lang/en/2009/03/09/solving-the-problem-of-back-button-in-ajax-applications#comments</comments>
		<pubDate>Tue, 10 Mar 2009 00:18:27 +0000</pubDate>
		<dc:creator>Diego Pessoa</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[Web Standards]]></category>
		<category><![CDATA[Web developing]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Web Accessibility]]></category>

		<guid isPermaLink="false">http://www.diegopessoa.com/?p=102</guid>
		<description><![CDATA[














Who here has always dreamed in do Ajax applications that the user can freely navigate using the back and forward buttons, and furthermore, can bookmark specific sections? In theory, this isn’t possible, since the “Ajax” is used by most to reload just some page blocks, keeping active the main page and, consequently, precluding the back [...]]]></description>
			<content:encoded><![CDATA[














<p><span lang="en">Who here has always dreamed in do Ajax applications that the user can freely navigate using the back and forward buttons, and furthermore, can bookmark specific sections? In theory, this isn’t possible, since the “Ajax” is used by most to reload just some page blocks, keeping active the main page and, consequently, precluding the back button or bookmarks use. Otherwise we’d have the good old reload of the entire page.</span></p>
<p><span lang="en">But then, how the Gmail works? It’s totally in Ajax and yet you can navigate using the back button.  If you put a link like: http://mail.google.com/mail/#compose in the address bar, it will open the e-mail composition screen normally. The big secret is in the #anchors.<br />
Anchor Oriented Navigation</span></p>
<p><span lang="en">A very interesting thing of the anchors is that they allow you to use the back and forward button, for example, without generate no one full page request and without leaving that page, so, how could we do this?</span></p>
<p><span lang="en">The first step is create a Javascript file that will be every time verifying if some anchor is active, if so, it sends the Ajax request calling the specific section, based on anchor’s name, that will be loaded inside the main block. Simple, isn’t it?</span></p>
<p><span lang="en">As is usual for JavaScript today, we will use jQuery, so remember to include the library file in your application.</span></p>
<p><span lang="en">We would then have a file named &#8220;core.js&#8221;, thus:</span></p>
<div lang="en">
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* Loading the page, the timer is started to check if there is an active anchor to each 300ms. */</span></div>
</li>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">setInterval<span class="br0">&#40;</span><span class="st0">&#34;checkAnchor()&#34;</span>, <span class="nu0">300</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> currentAnchor = <span class="kw2">null</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* Method to check if there is some anchor change, if so, sends the Ajax request.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">*/</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw2">function</span> checkAnchor<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span>currentAnchor != document.<span class="me1">location</span>.<span class="me1">hash</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">currentAnchor = document.<span class="me1">location</span>.<span class="me1">hash</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* If doesn’t have no one active anchor, the default section is loaded</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span>!currentAnchor<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">query = <span class="st0">&#34;section=home&#34;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* Creates the result string. Converting the url: URL/#fotos&#38;amp;id=2 in URL/?section=fotos&#38;amp;id=2</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">* */</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> splits = currentAnchor.<span class="me1">substring</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">&#8216;&#38;amp;&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> section = splits<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw1">delete</span> splits<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> params = splits.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">&#8216;&#38;amp;&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> query = <span class="st0">&#34;section=&#34;</span> + section + params;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li2">
<div class="de2"><span class="coMULTI">* Sends the request</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">*/</span></div>
</li>
<li class="li1">
<div class="de1">$.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&#34;callbacks.php&#34;</span>,query, <span class="kw2">function</span><span class="br0">&#40;</span>data<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">$<span class="br0">&#40;</span><span class="st0">&#34;#main_block&#34;</span><span class="br0">&#41;</span>.<span class="me1">html</span><span class="br0">&#40;</span>data<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
</div>
<p><span lang="en">OK, the content will be loaded in th e element of ID “main_block” through the Ajax request result that being sent to the page “callbacks.php” in GET Querystring format.</span></p>
<p><span lang="en">To catch it, we would have something like this:</span></p>
<div lang="en">
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$section</span> = <a href="http://www.php.net/addslashes"><span class="kw3">addslashes</span></a><span class="br0">&#40;</span><a href="http://www.php.net/strip_tags"><span class="kw3">strip_tags</span></a><span class="br0">&#40;</span><span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#8217;section&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$page</span> = <span class="st0">&#34;pages/&#34;</span>.<span class="re0">$section</span>.<span class="st0">&#34;.php&#34;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/file_exists"><span class="kw3">file_exists</span></a><span class="br0">&#40;</span><span class="re0">$page</span><span class="br0">&#41;</span><span class="br0">&#41;</span>  <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">include</span><span class="br0">&#40;</span><span class="re0">$page</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
</div>
<p><span lang="en">Thus, we would need only a folder called “pages” containing the pages with the anchors’ names.</span></p>
<p><span lang="en">And to call each section, a simple html page with links like:</span></p>
<p><span lang="en">http://mysite.com/#photos</span></p>
<p><span lang="en">It would be detected by the Javascript method “checkAnchor()”, and will be call a php request loading the page named photos.php inside the directory “pages”. It will exhibited inside the block “#main_block” that is contained in the same page of the clicked link, and the best of all, you can back, forward and bookmark the sections you want.</span></p>
<p><span lang="en">To better illustrate the example, I made a blatant copy (haha) of the PHP-PB’s site, with the only difference of having Ajax navigation through anchors (the original has normal navigation). Access the link: <a href="http://www.diegopessoa.com/php-pb-ajax" target="_blank">http://www.diegopessoa.com/php-pb-ajax</a></span></p>
<p><span lang="en">If you want to download the working example, <a href="http://diegopessoa.com/php-pb-ajax/%5bdiegopessoa.com%5dAjaxBack.zip" target="_blank">click here</a>!﻿</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.diegopessoa.com/lang/en/2009/03/09/solving-the-problem-of-back-button-in-ajax-applications/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>If you still didn&#8217;t see</title>
		<link>http://www.diegopessoa.com/lang/en/2009/02/01/if-you-still-didnt-see</link>
		<comments>http://www.diegopessoa.com/lang/en/2009/02/01/if-you-still-didnt-see#comments</comments>
		<pubDate>Mon, 02 Feb 2009 02:44:48 +0000</pubDate>
		<dc:creator>Diego Pessoa</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[encontro php-pb]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.diegopessoa.com/?p=87</guid>
		<description><![CDATA[
In the last post before the &#8220;pause&#8221;, I announced the I PHP-PB Metting that was realized at Campina Grande in the end of November. Now, if you still didn&#8217;t see, I&#8217;m providing the slides of my presentation: &#8220;How to develop on MVC with Zend Framework&#8221;. Thanks to all who participated, and wait the the second [...]]]></description>
			<content:encoded><![CDATA[
<p><span lang="en">In the last post before the &#8220;pause&#8221;, I announced the I PHP-PB Metting that was realized at Campina Grande in the end of November. Now, if you still didn&#8217;t see, I&#8217;m providing the slides of my presentation: &#8220;How to develop on MVC with Zend Framework&#8221;. Thanks to all who participated, and wait the the second PHP-PB meeting, soon here at João Pessoa.</span></p>

<div style="width: 425px; text-align: left;"><span lang="en"><a title="Desenvolvimento MVC com Zend Framework" href="http://www.slideshare.net/felipernb/desenvolvimento-mvc-com-zend-framework-presentation?type=powerpoint">How to develop on MVC with Zend Framework (Brazilian Portuguese Version)</a></span></div>

]]></content:encoded>
			<wfw:commentRss>http://www.diegopessoa.com/lang/en/2009/02/01/if-you-still-didnt-see/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I PHP-PB Meeting</title>
		<link>http://www.diegopessoa.com/lang/en/2008/11/28/i-php-pb-meeting</link>
		<comments>http://www.diegopessoa.com/lang/en/2008/11/28/i-php-pb-meeting#comments</comments>
		<pubDate>Sat, 29 Nov 2008 02:19:04 +0000</pubDate>
		<dc:creator>Diego Pessoa</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.diegopessoa.com/?p=76</guid>
		<description><![CDATA[





Hi everybody, this saturday, November 5th 2008, will be performed at Campina Grande-PB in the FACISA auditorium, the first PHP-PB Meeting, below follows the event schedule:

Event Schedule




08:00 &#8211; 09:00
Accreditation



09:00 &#8211; 10:00
Joomla &#8211; Hugo Rabelo


10:00 &#8211; 11:00
PHP isn&#8217;t kids stuff! &#8211; Felipe Ribeiro


11:00 &#8211; 12:00
Smarty &#8211; Uncoupling view from model - Marcus Antonius








12:00 &#8211; 14:00
Stop for [...]]]></description>
			<content:encoded><![CDATA[





<p><span lang="en">Hi everybody, this saturday, November 5th 2008, will be performed at Campina Grande-PB in the FACISA auditorium, the first PHP-PB Meeting, below follows the event schedule:<br />
</span></p>
<h2><span lang="en">Event Schedule<br />
</span></h2>
<table style="height: 220px;" border="0" width="580">
<tbody>
<tr>
<td><span lang="en">08:00 &#8211; 09:00</span></td>
<td><span lang="en">Accreditation<br />
</span></td>
</tr>
<tr>
<td><span lang="en">09:00 &#8211; 10:00</span></td>
<td><span lang="en"><strong>Joomla</strong> &#8211; Hugo Rabelo</span></td>
</tr>
<tr>
<td><span lang="en">10:00 &#8211; 11:00</span></td>
<td><span lang="en"><strong>PHP isn&#8217;t kids stuff!</strong> &#8211; Felipe Ribeiro</span></td>
</tr>
<tr>
<td><span lang="en">11:00 &#8211; 12:00</span></td>
<td><span lang="en"><strong>Smarty &#8211; Uncoupling view from model </strong>- Marcus Antonius</span></td>
</tr>
<tr>
<td><span lang="en"><br />
</span></td>
<td><span lang="en"><br />
</span></td>
</tr>
<tr>
<td><span lang="en">12:00 &#8211; 14:00</span></td>
<td><span lang="en">Stop for launch<br />
</span></td>
</tr>

<tr>
<td><span lang="en">14:00 &#8211; 15:00</span></td>
<td><span lang="en"><strong>PHP Securiy (Segurança com PHP</strong>) &#8211; Theoziran Lima</span></td>
</tr>
<tr>
<td><span lang="en">15:00 &#8211; 16:00</span></td>
<td><span lang="en"><strong>MVC Development with Zend Framework </strong>- Diego Pessoa</span></td>
</tr>
<tr>
<td><span lang="en">16:00 &#8211; 17:00</span></td>
<td><span lang="en"><strong>Rich Interfaces with Flex and PHP </strong> &#8211; Alwin Garside</span></td>
</tr>
</tbody>
</table>
<p><span lang="en">I will post my presentation just after the lecture.<br />
</span></p>
<p><span lang="en">The event also will be live transmitted in:  <a href="http://www.php-pb.net" target="_blank">www.php-pb.net</a></span></p>
<p><span lang="en">See you later!</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.diegopessoa.com/lang/en/2008/11/28/i-php-pb-meeting/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
