<?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>jek2kdotcom &#187; Web Development</title>
	<atom:link href="http://www.jek2k.com/wp/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jek2k.com/wp</link>
	<description>still awake at night?</description>
	<lastBuildDate>Tue, 12 Jan 2010 14:52:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A simple RSS Reader with PHP</title>
		<link>http://www.jek2k.com/wp/2009/05/31/a-simple-rss-reader-with-php/</link>
		<comments>http://www.jek2k.com/wp/2009/05/31/a-simple-rss-reader-with-php/#comments</comments>
		<pubDate>Sun, 31 May 2009 16:43:38 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/?p=269</guid>
		<description><![CDATA[In the last couple of days, I had the need of creating a simple RSS widget for a project, aggregating several RSS feeds from different sources. As this might be a pretty common request and you might need this in your projects, I&#8217;m sharing my script below.
The whole thing is based on the MagpieRSS PHP [...]]]></description>
			<content:encoded><![CDATA[<p>In the last couple of days, I had the need of creating a simple RSS widget for a project, aggregating several RSS feeds from different sources. As this might be a pretty common request and you might need this in your projects, I&#8217;m sharing my script below.<br />
The whole thing is based on the <a href="http://magpierss.sourceforge.net/">MagpieRSS</a> PHP parser.</p>
<p><strong>1. The simple version</strong></p>
<p>This first version simply reads the RSS feeds from different websites and lists the latest posts for each website.<br />
Feed URIs are defined in an array, so you can easily add as many as you want.<br />
Number of posts per website is also easily editable.</p>
<p>This has support for languages different from English, using UTF-8 encoding, and uses <strong>relative dates</strong>.</p>
<p>You can see <a href="http://playground.gnvpartners.net/ex/rss/rss.php">a working example here</a>.<span id="more-269"></span></p>
<p><strong>Source code:</strong></p>
<pre class="brush: php;">

&lt;?php

/* feed URIs */
$urls = array('http://webdesignerwall.com/feed/', 'http://gigaom.com/feed/', 'http://techcrunch.com/feed/', 'http://wordpress.org/development/feed/');

/* number of items for each feed */
$num_items = 5;

@require_once('rss_fetch.inc');
define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
$posts = array();

foreach($urls as $url) {
$rss = fetch_rss($url);

if($rss) {
$items = array_slice($rss-&gt;items, 0, $num_items);
foreach($items as $item) {
$posts[] = array('title' =&gt; $item['title'], 'link' =&gt; $item['link'], 'date' =&gt; $item['pubdate'], 'source' =&gt; $rss-&gt;channel['title']);
}
}
else {
echo &quot;An error occured!&lt;br /&gt;Error Message: &quot;.magpie_error();
}
}
usort($posts, 'sortdates');
echo &quot;&lt;ul&gt;&quot;;
foreach($posts as $post) {
$title = $post['title'];
$url = $post['link'];
$date = $post['date'];
$source = $post['source'];
echo &quot;&lt;li&gt;&lt;a href='&quot;.$url.&quot;'&gt;&quot;.$title.&quot;&lt;/a&gt; from &lt;strong&gt;&quot;.$source.&quot;&lt;/strong&gt;, &quot;.getrelativetime($date).&quot;&lt;/li&gt;&quot;;
}
echo &quot;&lt;/ul&gt;&quot;;

function sortdates($a, $b) {
if(strtotime($a['date']) &gt; strtotime($b['date'])) {
return -1;
} elseif( strtotime($a['date']) == strtotime($b['date'])) {
return 0;
} elseif( strtotime($a['date']) &lt; strtotime($b['date'])) {
return 1;
}
}

function getrelativetime($date) {
// Credit: http://snipplr.com/view/4912/relative-time/ and http://twitter.pbwiki.com/RelativeTimeScripts
$gap = time() - strtotime($date);
if ($gap&lt;5) {
return 'less than 5 seconds ago';
} else if ($gap&lt;10) {
return 'less than 10 seconds ago';
} else if ($gap&lt;20) {
return 'less than 20 seconds ago';
} else if ($gap&lt;40) {
return 'half a minute ago';
} else if ($gap&lt;60) {
return 'less than a minute ago';
}
$gap = round($gap/60);
if ($gap &lt; 60)
return $gap.' minute'.($gap &gt; 1 ? 's' : '').' ago';
$gap = round($gap/60);
if ($gap &lt; 24)
return $gap.' hour'.($gap &gt; 1 ? 's' : '').' ago';
$gap = round($gap/24);
if ($gap&lt;7)
return $gap.' day'.($gap &gt; 1 ? 's' : '').' ago';
$gap = round($gap/7);
if ($gap&lt;4)
return $gap.' week'.($gap &gt; 1 ? 's' : '').' ago';

return date(&quot;F jS, Y @h:i&quot;, strtotime($date));
}
?&gt;
</pre>
<p><strong>2. The more complex version</strong></p>
<p>Same thing as above, but this version output a list af the most recent posts &#8211; source websites are displayed next to titles. This is definitely more useful if you mean to display recent content from mixed sources.</p>
<p>You can see <a href="http://playground.gnvpartners.net/ex/rss/rss.mixed.php">a working example here</a>.</p>
<p><strong>Source code:</strong></p>
<pre class="brush: php;">

&lt;?php

/* feed URIs */
$urls = array('http://webdesignerwall.com/feed/', 'http://gigaom.com/feed/', 'http://techcrunch.com/feed/', 'http://wordpress.org/development/feed/');

/* number of items for each feed */
$num_items = 5;

@require_once('rss_fetch.inc');
define('MAGPIE_OUTPUT_ENCODING', 'UTF-8');
$posts = array();

foreach($urls as $url) {
$rss = fetch_rss($url);

if($rss) {
$items = array_slice($rss-&gt;items, 0, $num_items);
foreach($items as $item) {
$posts[] = array('title' =&gt; $item['title'], 'link' =&gt; $item['link'], 'date' =&gt; $item['pubdate'], 'source' =&gt; $rss-&gt;channel['title']);
}
}
else {
echo &quot;An error occured!&lt;br /&gt;Error Message: &quot;.magpie_error();
}
}
usort($posts, 'sortdates');
echo &quot;&lt;ul&gt;&quot;;
foreach($posts as $post) {
$title = $post['title'];
$url = $post['link'];
$date = $post['date'];
$source = $post['source'];
echo &quot;&lt;li&gt;&lt;a href='&quot;.$url.&quot;'&gt;&quot;.$title.&quot;&lt;/a&gt; from &lt;strong&gt;&quot;.$source.&quot;&lt;/strong&gt;, &quot;.getrelativetime($date).&quot;&lt;/li&gt;&quot;;
}
echo &quot;&lt;/ul&gt;&quot;;

function sortdates($a, $b) {
if(strtotime($a['date']) &gt; strtotime($b['date'])) {
return -1;
} elseif( strtotime($a['date']) == strtotime($b['date'])) {
return 0;
} elseif( strtotime($a['date']) &lt; strtotime($b['date'])) {
return 1;
}
}

function getrelativetime($date) {
// Credit: http://snipplr.com/view/4912/relative-time/ and http://twitter.pbwiki.com/RelativeTimeScripts
$gap = time() - strtotime($date);
if ($gap&lt;5) {
return 'less than 5 seconds ago';
} else if ($gap&lt;10) {
return 'less than 10 seconds ago';
} else if ($gap&lt;20) {
return 'less than 20 seconds ago';
} else if ($gap&lt;40) {
return 'half a minute ago';
} else if ($gap&lt;60) {
return 'less than a minute ago';
}
$gap = round($gap/60);
if ($gap &lt; 60)
return $gap.' minute'.($gap &gt; 1 ? 's' : '').' ago';
$gap = round($gap/60);
if ($gap &lt; 24)
return $gap.' hour'.($gap &gt; 1 ? 's' : '').' ago';
$gap = round($gap/24);
if ($gap&lt;7)
return $gap.' day'.($gap &gt; 1 ? 's' : '').' ago';
$gap = round($gap/7);
if ($gap&lt;4)
return $gap.' week'.($gap &gt; 1 ? 's' : '').' ago';

return date(&quot;F jS, Y @h:i&quot;, strtotime($date));
}
?&gt;
</pre>
<p><a href="http://playground.gnvpartners.net/ex/rss/rss_reader.zip">Download the source code</a> for both scripts (24k ZIP)</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2009/05/31/a-simple-rss-reader-with-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MooTools icons scroller</title>
		<link>http://www.jek2k.com/wp/2009/02/13/mootools-icons-scroller/</link>
		<comments>http://www.jek2k.com/wp/2009/02/13/mootools-icons-scroller/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 10:30:52 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/?p=216</guid>
		<description><![CDATA[
Some time ago I was trying to make a project/icons scroller, to refresh our online portfolio. The idea was having two rows of icons to scroll with a little delay and an elastic effect. Of course, I didn&#8217;t want to use Flash for this, so I went for MooTools.

I&#8217;ve never implemented this script on our [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-217" title="project_matrix" src="http://www.jek2k.com/wp/wp-content/uploads/2009/01/project_matrix.jpg" alt="project_matrix" width="480" height="230" /></p>
<p>Some time ago I was trying to make a project/icons scroller, to refresh our online portfolio. The idea was having two rows of icons to scroll with a little delay and an elastic effect. Of course, I didn&#8217;t want to use Flash for this, so I went for MooTools.<br />
<span id="more-216"></span><br />
I&#8217;ve never implemented this script on our site and the script itself it quite basic and unoptimized. However I thought of sharing it here, with the hope it might be helpful to someone out there.</p>
<p><a href="http://playground.gnvpartners.net/ex/project_scroller/">See a working example</a></p>
<p><a href="http://playground.gnvpartners.net/ex/project_scroller/project_scroller.zip">Download the source code</a> (51k ZIP)</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2009/02/13/mootools-icons-scroller/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Building a custom Skype-me button with status icon</title>
		<link>http://www.jek2k.com/wp/2008/02/08/building-a-custom-skype-me-button-with-status-icon/</link>
		<comments>http://www.jek2k.com/wp/2008/02/08/building-a-custom-skype-me-button-with-status-icon/#comments</comments>
		<pubDate>Thu, 07 Feb 2008 23:25:55 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2008/02/08/building-a-custom-skype-me-button-with-status-icon/</guid>
		<description><![CDATA[I&#8217;m not a big fan of Skype and I usually don&#8217;t use it. However, in a recent project, I was asked to add a &#8220;Skype Me&#8221; button in the contacts section of a client&#8217;s website.
I guess you all know Skype provides a bunch of free buttons and even an online wizard to build custom buttons. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not a big fan of Skype and I usually don&#8217;t use it. However, in a recent project, I was asked to add a &#8220;Skype Me&#8221; button in the contacts section of a client&#8217;s website.<br />
I guess you all know Skype provides a bunch of free buttons and even an online wizard to build custom buttons. This works pretty good, except it only allows to use the default Skype buttons and icons and images are PNGs.</p>
<p>What to do then if you need to use custom-designed buttons? Or if you&#8217;re targeting IE6 and have no transparent-PNGs support? I scored 2 on 2, having both those problems.</p>
<p>So I decided to search for some Skype documentation and build a script myself.<br />
Some basic information on creating custom Skype buttons and links <a href="http://www.skype.com/share/buttons/advanced.html">can be found here</a>. This explains how to code links, but still doesn&#8217;t address my problem. Then I found some more in-depth documentation on building web-services and apps interacting with Skype, that <a href="https://developer.skype.com/Docs/Web">can be downloaded from here</a>.</p>
<p>This way I found out that you can call a remote Skype URL, passing in your username and some parameters, to retrieve a status <a href="http://mystatus.skype.com/nicolovolpato">button</a>, a status <a href="http://mystatus.skype.com/nicolovolpato">code</a> or a status <a href="http://mystatus.skype.com/nicolovolpato.txt">string</a>.</p>
<p>The numeric status code is easier to use. Here&#8217;s a short list of numeric codes and their meaning:</p>
<ul>
<li><strong>0</strong> &#8211; unknown</li>
<li><strong>1</strong> &#8211; offline</li>
<li><strong>2</strong> &#8211; online</li>
<li><strong>3</strong> &#8211; away</li>
<li><strong>4</strong> &#8211; not available</li>
<li><strong>5</strong> &#8211; do not disturb</li>
<li><strong>6</strong> &#8211; invisible</li>
<li><strong>7</strong> &#8211; skype me</li>
</ul>
<p>Then I coded a short PHP script to take advantage of this function and retrieve the status code for a given Skype username.</p>
<pre class="brush: php;">
function getSkypeStatus($username) {
	$remote_status = fopen ('http://mystatus.skype.com/'.$username.'.num', 'r');
	if (!$remote_status) {
	    return '0';
	    exit;
	}
	while (!feof ($remote_status)) {
	    $value = fgets ($remote_status, 1024);
	    return trim($value);
	}
	fclose($remote_status);
}
</pre>
<p>Half of the job was done. Now I needed to link each code to a custom-designed status icon.</p>
<pre class="brush: php;">
function getSkypeStatusIcon($username) {
	$status = getSkypeStatus($username);
	// change the path of the icons folder to match your site
	echo '&lt;img src=&quot;/skype-icons/'.$status.'.jpg&quot; alt=&quot;call '.$username.'&quot; /&gt;';
}
</pre>
<p>So that calling the PHP function with the desired username&#8230;</p>
<pre class="brush: php;">
getSkypeStatusIcon('nicolovolpato');
</pre>
<p>&#8230;returns the necessary HTML code for the icon image.</p>
<pre class="brush: php;">
&lt;img src=&quot;/skype-icons/1.jpg&quot; alt=&quot;call nicolovolpato&quot; /&gt;
</pre>
<p>Of course I had then to go back to Photoshop and design my custom icons. I simply named the files like the status codes, where 1.jpg is the icon for offline, 2.jpg is the icon for online and so on.</p>
<p>I&#8217;ve tested this script using my Skype account and other accounts and seems pretty reliable. This is not the only method and I&#8217;m pretty sure this is not even the best method available, but it&#8217;s just the solution I have found to this problem and wanted to share it.</p>
<p><a rel="attachment" href="http://www.jek2k.com/wp//wp/wp-content/uploads/2008/02/skype.php.zip" title="Download skype.php.zip">Download the source code</a> (4k ZIP)</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2008/02/08/building-a-custom-skype-me-button-with-status-icon/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Timed based CSS stylesheet with PHP</title>
		<link>http://www.jek2k.com/wp/2007/05/03/timed-based-css-stylesheet-with-php/</link>
		<comments>http://www.jek2k.com/wp/2007/05/03/timed-based-css-stylesheet-with-php/#comments</comments>
		<pubDate>Thu, 03 May 2007 21:41:00 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2007/05/03/timed-based-css-stylesheet-with-php/</guid>
		<description><![CDATA[It&#8217;s been quite a long time since I last posted an article here at Jek2k.com.
On my company&#8217;s web site I&#8217;ve made a little PHP script to change the CSS stylesheet depending on the time of the day. We have a bright white theme for day time and a dark black one for night time and [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been quite a long time since I last posted an article here at Jek2k.com.</p>
<p>On <a href="http://www.gnvpartners.com/web/">my company&#8217;s web site</a> I&#8217;ve made a little PHP script to change the CSS stylesheet depending on the time of the day. We have a bright white theme for day time and a dark black one for night time and Sundays (when we are closed). This script was initially inspired by the beautiful <a href="http://www.radiantmars.com/">Radiant Mars website</a>. </p>
<p>Some of you have asked me how I made it, so here is the code: </p>
<p><pre><pre>
&lt;?php 
// time based Css Swicth
$time = date(&quot;H&quot;);
$date = date(&quot;w&quot;);
if (!isset($_GET[&#039;css&#039;])) {
if ($time &gt;= 9 &amp;&amp; $time &lt; 18 &amp;&amp; $date != 0) { ?&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php bloginfo(&#039;stylesheet_directory&#039;); ?&gt;/styles/day.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;? } else { ?&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php bloginfo(&#039;stylesheet_directory&#039;); ?&gt;/styles/night.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;? }; 
} else { ?&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php bloginfo(&#039;stylesheet_directory&#039;); ?&gt;/styles/&lt;?php echo $_GET[&#039;css&#039;]; ?&gt;.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;? }; ?&gt;
</pre></pre></p>
<p>Looks easy, doesn&#8217;t it? </p>
<p><strong>Let&#8217;s see it in detail</strong>.<br />
  First I&#8217;ve set up two variables to read the current time (hour) of the day and the current day (number, 0 = Sunday) of the week.</p>
<p><pre><pre>
$time = date(&quot;H&quot;);
$date = date(&quot;w&quot;);
</pre></pre></p>
<p>For more information about handling date and time with PHP, please <a href="http://it.php.net/date">see the PHP documentation</a>. </p>
<p>Then we have a pretty simple IF clause to check if the current time is between 9AM and 6PM and today is not Sunday.<br />
  According to this clause, the correct CSS stylesheet is loaded. </p>
<p><pre><pre>if ($time &gt;= 9 &amp;&amp; $time &lt; 18 &amp;&amp; $date != 0) { ?&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php bloginfo(&#039;stylesheet_directory&#039;); ?&gt;/styles/day.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;? } else { ?&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;&lt;?php bloginfo(&#039;stylesheet_directory&#039;); ?&gt;/styles/night.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;? }; 
</pre></pre></p>
<p>The last part is another IF clause, mainly for debug reasons.<br />
  It checks if we have added a variable to the page&#8217;s URL, ie. pagename.php?css=day. This way we can override the time check and load the desired CSS stylesheet directly. This is useful to test your CSS files without waiting for it to change. </p>
<p>That&#8217;s it. Pretty basic, but remember I&#8217;m just a designer!</p>
<p>Use the <a href="http://it.php.net/date">PHP  date function</a> to read other parameters and modify this script to change the CSS stylesheet according to seasons, holidays, day of the week or whatever you like. </p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2007/05/03/timed-based-css-stylesheet-with-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Multiple drop-downs</title>
		<link>http://www.jek2k.com/wp/2006/12/20/multiple-drop-downs/</link>
		<comments>http://www.jek2k.com/wp/2006/12/20/multiple-drop-downs/#comments</comments>
		<pubDate>Wed, 20 Dec 2006 21:16:52 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2006/12/20/multiple-drop-downs/</guid>
		<description><![CDATA[This is a followup to my previous JavaScript tutorial (Italian version can be found here).
Many people asked for multiple drop-downs panels within one page or multiple links to open/close a single drop-down panel.
I made a little variation to the original script to cover both cases.
Hope this helps.
Download the Source Code (28k ZIP).
This tutorial is provided [...]]]></description>
			<content:encoded><![CDATA[<p>This is a followup to <a href="http://www.jek2k.com/wp/index.php/2006/07/14/drop-down-with-javascript/">my previous JavaScript tutorial</a> (Italian version can be found <a href="http://www.jek2k.com/wp/index.php/2006/06/10/drop-down-con-javascript/">here</a>).</p>
<p>Many people asked for multiple drop-downs panels within one page or multiple links to open/close a single drop-down panel.</p>
<p>I made a little variation to the original script to cover both cases.<br />
Hope this helps.</p>
<p><a href="http://www.jek2k.com/wp//wp/wp-content/uploads/2006/12/multiple_drop_down_js.zip">Download the Source Code</a> (28k ZIP).</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2006/12/20/multiple-drop-downs/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A PHP Css stylesheet switcher</title>
		<link>http://www.jek2k.com/wp/2006/08/01/a-php-css-stylesheet-switcher/</link>
		<comments>http://www.jek2k.com/wp/2006/08/01/a-php-css-stylesheet-switcher/#comments</comments>
		<pubDate>Tue, 01 Aug 2006 00:47:42 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2006/08/01/a-php-css-stylesheet-switcher/</guid>
		<description><![CDATA[This is an English translation of the original  tutorial.
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-
Following my previous article, I keep on publishing the &#8220;secrets&#8221; behind Jek2k.com.
Today we&#8217;ll see how to create a Css stylesheet switcher using PHP, to change your Css on-the-fly.
There are many techniques to do that.
First, using Javascript.
On A List Apart you can find a very well written [...]]]></description>
			<content:encoded><![CDATA[<p>This is an English translation of <a href="http://www.jek2k.com/wp/index.php/2006/06/18/css-switch-con-php/">the original  tutorial</a>.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Following <a href="http://www.jek2k.com/wp/index.php/2006/06/10/drop-down-con-javascript/">my previous article</a>, I keep on publishing the &#8220;secrets&#8221; behind Jek2k.com.<br />
Today we&#8217;ll see how to create a Css stylesheet switcher using PHP, to change your Css on-the-fly.</p>
<p>There are many techniques to do that.<br />
First, using Javascript.<br />
On <a href="http://www.alistapart.com/articles/alternate/" target="_blank">A List Apart</a> you can find a very well written tutorial to create a Css switcher with JS, using a cookie to keep the user&#8217;s preference.<br />
And the obtained page also conforms to W3C standards.</p>
<p>The main problem of this method is that, being Javascript, it runs on the client, so it depends on the browser and requires the user to have JS enabled.<br />
<em>The validity of this technique depends on your site&#8217;s target. No problem if you have a tech-savvy users target, with modern browsers and smart enough to not disable Javascript!</em></p>
<p>I chose to use another method, using PHP, not because of my users, but because I use WordPress, which is written in PHP.<br />
Aside from this, PHP runs on the server, so it is browser-independent.<br />
<a href="http://www.alistapart.com/articles/phpswitch/" target="_blank">A List Apart</a> has a very good tutorial which covers this method too.<br />
A very easy, step-by-step tutorial.</p>
<p>I&#8217;d add just a couple of suggestions, to make it even smoother.</p>
<p>First:<br />
the cookie duration.<br />
Do you really want to keep the cookie for a year??!!? I think it is really too long.</p>
<p>So, in the following piece of code<br />
<pre><pre>
&lt;?php
setcookie (&#039;sitestyle&#039;, $set, time()+31536000, &#039;/&#039;, &#039;yourdomain.com&#039;, &#039;0&#039;);
header(&quot;Location: $HTTP_REFERER&quot;);
?&gt;
</pre></pre><br />
change the value <strong>31536000</strong> (duration of the cookie, in seconds).<br />
to <strong>2592000</strong> to set a monthly cookie, or <strong>604800</strong> to set a weekly one</p>
<p>Second:<br />
the code that reads the cookie. Change the following<br />
<pre><pre>
&lt;?php echo (!$sitestyle)?&#039;defaultstyle&#039;:$sitestyle ?&gt;
</pre></pre><br />
to<br />
<pre><pre>
&lt;?php echo (!$_COOKIE[&#039;sitestyle&#039;])?&#039;defaultstyle&#039;:$_COOKIE[&#039;sitestyle&#039;] ?&gt;
</pre></pre><br />
which seems to work better (at least, it does work better for me). </p>
<p>&nbsp;</p>
<p>Well, that&#8217;s all folks!<br />
I hope this can be useful to someone.</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2006/08/01/a-php-css-stylesheet-switcher/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Drop down with Javascript (EN)</title>
		<link>http://www.jek2k.com/wp/2006/07/14/drop-down-with-javascript/</link>
		<comments>http://www.jek2k.com/wp/2006/07/14/drop-down-with-javascript/#comments</comments>
		<pubDate>Fri, 14 Jul 2006 20:58:59 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2006/07/14/drop-down-with-javascript/</guid>
		<description><![CDATA[*Can* asked me to translate my previous tutorial. So here it is!
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
How the heck did I make the drop down panel above?
Ok, maybe it&#8217;s a kids game for some of you, but I guess  there&#8217;s someone out there who might be interested. For these (few) people, here&#8217;s the tute.
This is all web standards compliant, [...]]]></description>
			<content:encoded><![CDATA[<p>*Can* asked me to translate my previous tutorial. So here it is!<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>How the heck did I make the drop down panel above?<br />
Ok, maybe it&#8217;s a kids game for some of you, but I guess  there&#8217;s someone out there who might be interested. For these (few) people, here&#8217;s the tute.</p>
<p>This is all <em>web standards compliant</em>, keeping my Xhtml clean and valid, and so my Css stylesheet.<br />
The interaction is built using some very useful (and yet very well-knowed)  free Javascript libraries, released under a GPL license.<br />
To be specific, you will need the following libraries:</p>
<ul>
<li><a href="http://prototype.conio.net/">Prototype</a></li>
<li><a href="http://script.aculo.us/">Script.aculo.us</a></li>
<li><a href="http://bennolan.com/behaviour/">Behaviour</a></li>
</ul>
<p>that you can download from their respective web sites.<br />
<span id="more-45"></span><br />
So, now that we got the libraries, let&#8217;s include them in our Html document, this way:<br />
<pre><pre>
&lt;script type=&quot;text/javascript&quot; src=&quot;/js/prototype.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/js/scriptaculous.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/js/behaviour.js&quot;&gt;&lt;/script&gt;
</pre></pre><br />
Obviously, you have to modify the paths to match your site/server strcture. Then, we have to set up the 2 elements involved in the interaction: the link that activates/deactivates the drop down animation and the Div with the drop down content.</p>
<p>Let&#8217;s start with the link:<br />
<pre><pre>
&lt;a id=&quot;open&quot; href=&quot;javascript:void(0);&quot; &gt;Open&lt;/a&gt; 
&lt;a id=&quot;close&quot; href=&quot;javascript:void(0);&quot; style=&quot;display:none;&quot;&gt;Close&lt;/a&gt; 
</pre></pre><br />
Elements IDs are very important, we&#8217;ll discover why very soon.<br />
Now let&#8217;s create the Div with the content and call it <strong>contents</strong>:<br />
<pre><pre>
&lt;div id=&quot;contents&quot; style=&quot;display:none;&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp; bla bla bla bla bla bla
&lt;/div&gt; 
</pre></pre></p>
<p>Now, normally, to give a link a Javascript behaviour you would use the <strong>onclick</strong> tag attribute.<br />
However, it&#8217;s a old and dirty way to manage Javascript behaviours, which might also cause validation problems.<br />
So, we&#8217;re not gonna use it anymore!</p>
<p><a href="http://bennolan.com/behaviour/">Behaviour</a> comes in our help, giving us a clean method to add Javascript behaviours to Html elements, using Css selectors.<br />
We have to define some rules, as follows:<br />
<pre><pre>
// Rules
var myrules = {
&nbsp;&nbsp;&#039;#open&#039; : function(element){
&nbsp;&nbsp;&nbsp;&nbsp;element.onclick = function(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var targetDiv = $(&#039;contents&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Effect.BlindDown(targetDiv,{duration: 0.5});
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Effect.Fade(this);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Effect.Appear(&#039;close&#039;, {delay: 1});
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;},
&nbsp;&nbsp;&#039;#close&#039; : function(element){
&nbsp;&nbsp;&nbsp;&nbsp;element.onclick = function(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var targetDiv = $(&#039;contents&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Effect.BlindUp(targetDiv,{duration: 0.5});
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Effect.Fade(this); 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Effect.Appear(&#039;open&#039;, {delay: 1});
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
};
</pre></pre><br />
Save this JS to a file named <strong>rules.js</strong> and include it in the Html document.<br />
<pre><pre>
&lt;script type=&quot;text/javascript&quot; src=&quot;/js/rules.js&quot;&gt;&lt;/script&gt;
</pre></pre><br />
The code uses also the libraries from <a href="http://script.aculo.us/">Script.aculo.us</a> for animation effects and from <a href="http://prototype.conio.net/">Prototype</a> for DOM manipulation and control.<br />
Further and in depht explanation of these two libraries can be found on their respective websites, where you can find wikis and commented examples.</p>
<p>Now, Behaviour requires us to insert the following code, in order to run correctly and apply the rules:<br />
<pre><pre>
&nbsp;&nbsp;&lt;script type=&quot;text/javascript&quot;&gt;
&nbsp;&nbsp; // &lt;![CDATA[
&nbsp;&nbsp;&nbsp;&nbsp; // Behaviour Rules
&nbsp;&nbsp;&nbsp;&nbsp;Behaviour.register(myrules);
&nbsp;&nbsp; // ]]&gt;
&nbsp;&nbsp; &lt;/script&gt;
</pre></pre><br />
I usually add the code at the end of my document, just before closing the <strong>body</strong> tag.<br />
Now, open up a browser window and test.<br />
Please, do yourself a favor: do not use Internet Explorer for testing! Never!</p>
<p>So, is it working?</p>
<p align="center"><img title="Drop Down Screenshot" alt="Drop Down Screenshot" src="http://www.jek2k.com/wp/wp-content/uploads/2006/06/screenshot_drop_down.jpg" /></p>
<p>The result should look like the drop down above (obviously, you have to add you own Css to spice it up and make it look cool!!).</p>
<p>Well, you&#8217;ve seen how a bunch of lines of code can help you create very nice effects, easiliy and in a standard compliant way (you don&#8217;t always need Flash).</p>
<p>Good coding to all of you!!</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
<strong>Updated 16.07.2006:</strong><br />
<a href="http://www.jek2k.com/wp/wp/wp-content/uploads/2006/07/drop_down_js.zip">Download the Source Code</a> (28k ZIP).</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
<strong>Updated 20.12.2006:</strong></p>
<p>Many people asked for multiple drop-downs panels within one page or multiple links to open/close a single drop-down panel.</p>
<p>I made a little variation to the original script to cover both cases.<br />
Hope this helps.<br />
<a href="http://www.jek2k.com/wp//wp/wp-content/uploads/2006/12/multiple_drop_down_js.zip">Download the Source Code</a> (28k ZIP).</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2006/07/14/drop-down-with-javascript/feed/</wfw:commentRss>
		<slash:comments>56</slash:comments>
		</item>
		<item>
		<title>Slideshow JS</title>
		<link>http://www.jek2k.com/wp/2006/07/12/slideshow-js/</link>
		<comments>http://www.jek2k.com/wp/2006/07/12/slideshow-js/#comments</comments>
		<pubDate>Wed, 12 Jul 2006 18:19:53 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2006/07/12/slideshow-js/</guid>
		<description><![CDATA[Link diretto alla risorsa: http://www.jek2k.com/slideshow_js/. 
Circa due o tre settimane fa, ho scritto un piccolo script Javascript per realizzare slideshow di immagini, senza ricorrere a Flash.
Le ragioni, e i vantaggi, sono molteplici: dimensioni ridotte, conformità agli standard xhtml e css, funziona senza alcun plugin, facile da modificare al volo, integrabile in siti html esistenti, ecc&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>Link diretto alla risorsa: <a href="http://www.jek2k.com/slideshow_js/">http://www.jek2k.com/slideshow_js/</a>. </p>
<p>Circa due o tre settimane fa, ho scritto un piccolo script Javascript per realizzare slideshow di immagini, senza ricorrere a Flash.<br />
Le ragioni, e i vantaggi, sono molteplici: dimensioni ridotte, conformità agli standard xhtml e css, funziona senza alcun plugin, facile da modificare al volo, integrabile in siti html esistenti, ecc&#8230; </p>
<p>Dopodiché, me ne sono dimenticato e ho lasciato i files lì da qualche parte sul server.</p>
<p>Oggi, spinto dalla richiesta di un cliente, ho rispolverato quello script e, visto che avevo un&#8217;oretta da spendere, l&#8217;ho messo a posto, commentando il codice e ripulendolo un po&#8217;.</p>
<p>Dato che lo trovo abbastanza utile, ho deciso di dargli un nome, di confezionarlo e distribuirlo su Jek2k.com, nella speranza (o illusione) che possa essere utile anche a qualcuno di voi là fuori.</p>
<p>Ho anche pubblicato online <a href="http://www.jek2k.com/slideshow_js/">una demo e una paginetta dedicata</a>, da cui è possibile scaricare i files.<br />
<img src="http://www.jek2k.com/wp//wp/wp-content/uploads/2006/07/slideshow_js_thumb.jpg" alt="Slideshow JS" /></p>
<p>E&#8217; certamente perfezionabile, magari ha anche qualche bug, ma lo scopo è semplicemente condividere una cosa su cui ho speso del tempo, perché possiate trarne beneficio e da lì sviluppare quacosa di vostro. E  magari anche migliore.<br />
Spero che vorrete condividere con me le vostre creazioni&#8230;</p>
<p>ciao</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2006/07/12/slideshow-js/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Css switch con PHP</title>
		<link>http://www.jek2k.com/wp/2006/06/18/css-switch-con-php/</link>
		<comments>http://www.jek2k.com/wp/2006/06/18/css-switch-con-php/#comments</comments>
		<pubDate>Sun, 18 Jun 2006 10:54:05 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2006/06/18/css-switch-con-php/</guid>
		<description><![CDATA[Dopo il precedente tutorial, proseguo nello svelare le varie tecniche utilizzate per realizzare questo sito.
Oggi vediamo come ho realizzato lo switch Css, per cambiare il foglio di stile al volo.
Innanzitutto, esistono diversi modi per realizzarlo.
Il primo è farlo tramite Javascript.
Su A List Apart potete trovare un tutorial molto ben fatto per cambiare foglio di stile [...]]]></description>
			<content:encoded><![CDATA[<p>Dopo il <a href="http://www.jek2k.com/wp/index.php/2006/06/10/drop-down-con-javascript/">precedente tutorial</a>, proseguo nello svelare le varie tecniche utilizzate per realizzare questo sito.<br />
Oggi vediamo come ho realizzato lo switch Css, per cambiare il foglio di stile al volo.</p>
<p>Innanzitutto, esistono diversi modi per realizzarlo.<br />
Il primo è farlo tramite Javascript.<br />
Su <a href="http://www.alistapart.com/articles/alternate/" target="_blank">A List Apart</a> potete trovare un tutorial molto ben fatto per cambiare foglio di stile Css al volo con Javascript, memorizzando la preferenza in un cookie.<br />
Il tutto in conformità agli standard W3C.</p>
<p>Il principale problema di questa tecnica è che, in quanto Javascript, viene eseguita sul client, quindi può dare problemi su browser obsoleti o nel caso in cui l&#8217;utente abbia disabilitato l&#8217;esecuzione degli script JS.<br />
<em>La valutazione sull&#8217;adeguatezza o meno della tecnica Javascript va fatta in base al target di utenza del proprio sito.<br />
E&#8217; ovvio che il problema non si pone nel caso in cui il profilo medio dei vostri utenti sia elevato, quindi dotati di browser recenti e di abbastanza buon senso da non disabilitare Javascript!</em></p>
<p>Io, da parte mia, ho preferito seguire un&#8217;altra strada, non tanto per il profilo dei visitatori, ma perché, utilizzando WordPress (scritto in PHP, ndr.) mi era più congeniale e più veloce realizzare lo switch Css direttamente in PHP.<br />
Oltre a questa possibilità di integrazione, il PHP viene eseguito sul server, quindi è del tutto indipendente dal browser utilizzato dall&#8217;utente.<br />
Anche in questo caso, <a href="http://www.alistapart.com/articles/phpswitch/" target="_blank">A List Apart</a> ci viene incontro, con un ottimo tutorial.<br />
Il tutorial è ben scritto e facile da seguire.</p>
<p>Solo un paio di semplici suggerimenti, per rendere la cosa ancora più immediata.</p>
<p>Primo:<br />
la durata del cookie.<br />
Non credo che siate interessati a creare un cookie annuale. Mi sembra esagerato per memorizzare un dato banale come il foglio di stile preferito dall&#8217;utente.</p>
<p>Quindi, nel blocco di codice<br />
<pre><pre>
&lt;?php
setcookie (&#039;sitestyle&#039;, $set, time()+31536000, &#039;/&#039;, &#039;yourdomain.com&#039;, &#039;0&#039;);
header(&quot;Location: $HTTP_REFERER&quot;);
?&gt;
</pre></pre><br />
modificate il valore <strong>31536000</strong> (durata in secondi del cookie).<br />
Potete inserire <strong>2592000</strong> per creare un cookie mensile, <strong>604800</strong> per crearlo settimanale.</p>
<p>Secondo:<br />
il blocco di lettura del cookie<br />
<pre><pre>
&lt;?php echo (!$sitestyle)?&#039;defaultstyle&#039;:$sitestyle ?&gt;
</pre></pre><br />
può essere modificato in<br />
<pre><pre>
&lt;?php echo (!$_COOKIE[&#039;sitestyle&#039;])?&#039;defaultstyle&#039;:$_COOKIE[&#039;sitestyle&#039;] ?&gt;
</pre></pre><br />
che, almeno per quanto riguarda la mia esperienza, sembra funzionare meglio.</p>
<p>&nbsp;</p>
<p>Beh, siamo arrivati alla fine.<br />
Spero che vi sia utile.</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2006/06/18/css-switch-con-php/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Drop down con Javascript</title>
		<link>http://www.jek2k.com/wp/2006/06/10/drop-down-con-javascript/</link>
		<comments>http://www.jek2k.com/wp/2006/06/10/drop-down-con-javascript/#comments</comments>
		<pubDate>Fri, 09 Jun 2006 22:17:33 +0000</pubDate>
		<dc:creator>Nicolò</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.jek2k.com/wp/index.php/2006/06/10/drop-down-con-javascript/</guid>
		<description><![CDATA[Come ho realizzato il menù a discesa animato qui sopra?
Ok, magari per molti di voi è una banalità, ma sono sicuro che a qualcuno invece interesserà saperlo. Per queste (poche) persone, ecco un breve tutorial.
Innanzitutto ho sfruttato esclusivamente gli standard, mantenendo il mio codice Xhtml pulito e valido, così come il mio Css.
L&#8217;interazione è stata [...]]]></description>
			<content:encoded><![CDATA[<p>Come ho realizzato il menù a discesa animato qui sopra?<br />
Ok, magari per molti di voi è una banalità, ma sono sicuro che a qualcuno invece interesserà saperlo. Per queste (poche) persone, ecco un breve tutorial.</p>
<p>Innanzitutto ho sfruttato <em>esclusivamente gli standard</em>, mantenendo il mio codice Xhtml pulito e valido, così come il mio Css.<br />
L&#8217;interazione è stata realizzata sfruttando alcune (ormai molto note) librerie Javascript gratuite e distribuite sotto licenze di tipo GPL.<br />
In particolare, vi serviranno le librerie di:</p>
<ul>
<li><a href="http://prototype.conio.net/">Prototype</a></li>
<li><a href="http://script.aculo.us/">Script.aculo.us</a></li>
<li><a href="http://bennolan.com/behaviour/">Behaviour</a></li>
</ul>
<p>che potete tranquillamente scaricare dai rispettivi siti web.<br />
<span id="more-7"></span><br />
Prima di tutto, ora che abbiamo le librerie, includiamole nel nostro documento Html, così:<br />
<pre><pre>
&lt;script type=&quot;text/javascript&quot; src=&quot;/js/prototype.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/js/scriptaculous.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/js/behaviour.js&quot;&gt;&lt;/script&gt;
</pre></pre><br />
Ovviamente adattate i percorsi dei file in base alla struttura del vostro sito.Dopodiché, dobbiamo creare i due elementi coinvolti nell&#8217;interazione, rispettivamente il link che attiva/disattiva l&#8217;animazione e il Div con i contenuti a scomparsa.</p>
<p>Partiamo dal link:<br />
<pre><pre>
&lt;a id=&quot;open&quot; href=&quot;javascript:void(0);&quot; &gt;Open&lt;/a&gt; 
&lt;a id=&quot;close&quot; href=&quot;javascript:void(0);&quot; style=&quot;display:none;&quot;&gt;Close&lt;/a&gt; 
</pre></pre><br />
E&#8217; importante impostare gli ID degli elementi, ci verrano utili tra poco.<br />
Poi creiamo un Div con i contenuti: Lo chiamiamo <strong>contents</strong>:<br />
<pre><pre>
&lt;div id=&quot;contents&quot; style=&quot;display:none;&quot;&gt;
&nbsp;&nbsp;&nbsp;&nbsp; bla bla bla bla bla bla
&lt;/div&gt; 
</pre></pre></p>
<p>Ora, normalemente, per associare un comportamento Javascript ad un link si userebbe l&#8217;attributo <strong>onclick</strong> del tag <strong>a</strong>.<br />
Tuttavia si tratta di un attributo &#8220;sporco&#8221;, che esula dalle iniziale specifiche html e xhtml, ed è stato introdotto al solo scopo di supportare le funzionalità JS citate, imponendosi come standard de facto.<br />
Giustamente, la specifica Xhtml Strict non lo prevede. Quindi noi non lo useremo.</p>
<p>Qui ci viene in aiuto <a href="http://bennolan.com/behaviour/">Behaviour</a>, che ci dà la possibilità di abbinare dei comportamenti (appunto) agli elementi Html utilizzando i selettori Css, attraverso la definizione di regole (rules).In questo caso le nostre regole saranno:<br />
<pre><pre>
// Rules
var myrules = {
&nbsp;&nbsp;&#039;#open&#039; : function(element){
&nbsp;&nbsp;&nbsp;&nbsp;element.onclick = function(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var targetDiv = $(&#039;contents&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Effect.BlindDown(targetDiv,{duration: 0.5});
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;},
&nbsp;&nbsp;&#039;#close : function(element){
&nbsp;&nbsp;&nbsp;&nbsp;element.onclick = function(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var targetDiv = $(&#039;contents&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Effect.BlindUp(targetDiv,{duration: 0.5});
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
};
</pre></pre><br />
Salviamo questo JS in un file rules.js e includiamolo nel nostro documento Html.<br />
<pre><pre>
&lt;script type=&quot;text/javascript&quot; src=&quot;/js/rules.js&quot;&gt;&lt;/script&gt;
</pre></pre><br />
Il codice sfrutta le librerie di <a href="http://script.aculo.us/">Script.aculo.us</a> per gli effetti animati e quella di <a href="http://prototype.conio.net/">Prototype</a> per la manipolazione e l&#8217;identificazione degli elementi Html.<br />
Delego spiegazioni più approfondite circa il funzionamento di tali librerie ad un altro post, o ai siti dei singoli script.</p>
<p>Ora, Behaviour richiede che venga inserito il seguente codice, affinché le regole scritte in precedenza vengano applicate:<br />
<pre><pre>
&nbsp;&nbsp;&lt;script type=&quot;text/javascript&quot;&gt;
&nbsp;&nbsp; // &lt;![CDATA[
&nbsp;&nbsp;&nbsp;&nbsp; // Behaviour Rules per interazine javascript
&nbsp;&nbsp;&nbsp;&nbsp;Behaviour.register(myrules);
&nbsp;&nbsp; // ]]&gt;
&nbsp;&nbsp; &lt;/script&gt;
</pre></pre><br />
Il mio consiglio è di inserire questo JS alla fine della pagina, subito prima della chiusura del tag <strong>body</strong>.<br />
A questo punto aprite un browser e testate.<br />
Per fare un favore a me e a voi stessi, non usate Internet Explorer per questo genere di cose. Mai.<br />
Funziona?</p>
<p align="center"><img title="Drop Down Screenshot" alt="Drop Down Screenshot" src="http://www.jek2k.com/wp/wp-content/uploads/2006/06/screenshot_drop_down.jpg" /></p>
<p>Il risultato dovrebbe essere simile al drop down che vedete su questo sito (ovviamente dopo dovrete metterci del vostro e aggiungere un po&#8217; di Css!!).</p>
<p>Beh, è evidente che con queste poche righe di codice potete realizzare effetti molto gradevoli e dare un po&#8217; di pepe alle vostre pagine Html (Flash non è sempre l&#8217;unica soluzione&#8230;).</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
<strong>Updated 16.06.2006:</strong><br />
<a href="http://www.jek2k.com/wp/wp/wp-content/uploads/2006/07/drop_down_js.zip">Scarica il sorgente</a> (28k ZIP).</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
<strong>Updated 20.12.2006:</strong></p>
<p>In molti avete chiesto come fare per inserire più drop-down nella stessa pagina o come fare per avere più link che &#8220;comandano&#8221; lo stesso drop-down.</p>
<p>Ho fatto una variante dello script originale per coprire entrambe le esigenze.<br />
Spero che vi sia di aiuto.</p>
<p><a href="http://www.jek2k.com/wp//wp/wp-content/uploads/2006/12/multiple_drop_down_js.zip">Scarica il sorgente</a> (28k ZIP).</p>
<p class="note">This tutorial is provided as is. Please do not email me questions or support requests about the scripts contained in this page. Use the comments below instead. Thank you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jek2k.com/wp/2006/06/10/drop-down-con-javascript/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
	</channel>
</rss>
