<?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>The Why and The How &#187; jquery ui</title> <atom:link href="http://www.thewhyandthehow.com/tag/jquery-ui/feed/" rel="self" type="application/rss+xml" /><link>http://www.thewhyandthehow.com</link> <description>Just another WordPress weblog</description> <lastBuildDate>Fri, 09 Jul 2010 02:32:51 +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>jQuery date chooser</title><link>http://www.thewhyandthehow.com/jquery-date-chooser/</link> <comments>http://www.thewhyandthehow.com/jquery-date-chooser/#comments</comments> <pubDate>Tue, 12 May 2009 17:25:41 +0000</pubDate> <dc:creator>Blake Schwendiman</dc:creator> <category><![CDATA[Javascript]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[jquery ui]]></category><guid
isPermaLink="false">http://www.thewhyandthehow.com/?p=687</guid> <description><![CDATA[Providing a simple, consistent method for allowing your end-users to enter a date in a form is another great reason to use jQuery and jQuery UI. There have been many date selection tools created &#8212; you may have invented one yourself &#8212; but few are as great as the jQuery UI datepicker.
As with all things [...]]]></description> <content:encoded><![CDATA[<p>Providing a simple, consistent method for allowing your end-users to enter a date in a form is another great reason to use jQuery and jQuery UI. There have been many date selection tools created &#8212; you may have invented one yourself &#8212; but few are as great as the <a
href="http://jqueryui.com/demos/datepicker/">jQuery UI datepicker</a>.</p><p>As with all things jQuery, there is very little required. Just set up a form, add a quick call to jQuery and you&#8217;re done. By default, when the datepicker is bound to an edit input, all that is required is to click on the edit (or tab into it) and the calendar control will appear.</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p6873');">[<span
id="p6873_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p687code3'); return false;">View Code</a> JAVASCRIPT</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p6873"><td
class="code" id="p687code3"><pre class="javascript"><span style="color: #339933;">&lt;</span>form<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>fieldset<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>Select a date<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;the_date&quot;</span> <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;the_date&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>label<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>fieldset<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
  jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#the_date'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">datepicker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div><p>Here it is in action (click on the input field):</p><form
class="example"><fieldset><label>Select a date:<br
/> <input
type="text" id="the_date" name="the_date" /></label></fieldset></form><p><script type="text/javascript">jQuery('#the_date').datepicker();</script></p><p>Personally, I like a little more visual indication on date fields. Providing a calendar icon to the right of the input field has become a de facto standard on the web, so I&#8217;ll show how simple it is to add that to a jQuery UI datepicker.</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p6874');">[<span
id="p6874_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p687code4'); return false;">View Code</a> JAVASCRIPT</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p6874"><td
class="code" id="p687code4"><pre class="javascript"><span style="color: #339933;">&lt;</span>form<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>fieldset<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span>Select a date<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;the_date&quot;</span> <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;the_date&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>label<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>fieldset<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
  jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#the_date'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">datepicker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>showOn<span style="color: #339933;">:</span> <span style="color: #3366CC;">'both'</span><span style="color: #339933;">,</span> buttonImage<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/wp-content/themes/thesis/custom/images/ical.png'</span><span style="color: #339933;">,</span> buttonImageOnly<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div><p>As you can see, I added a small set of options to the <strong>datepicker()</strong> method. The showOn option indicates to show the calendar when the button is clicked and when the control has focus. The buttonImage option is the URL to the image and the buttonImageOnly option indicates to display the image alone, not as part of an actual button control. Visit the jQuery UI site for more <a
href="http://jqueryui.com/demos/datepicker/">datepicker control options</a>.</p><p>Here it is with the calendar button (<a
href="http://www.smashingmagazine.com/2009/01/23/friday-freebies-flavours-icon-set-and-cute-tweeters-icon-set/">download the button image here</a>):</p><form
class="example"><fieldset><label>Select a date:<br
/> <input
type="text" id="the_date2" name="the_date" /></label></fieldset></form><p><script type="text/javascript">jQuery('#the_date2').datepicker({showOn:'both',buttonImage:'/wp-content/themes/thesis/custom/images/ical_sm.png',buttonImageOnly:true});</script></p><p>The <a
href="http://jqueryui.com/demos/datepicker/">jQuery UI datepicker</a> provides a great deal of flexibility and control with a minimum required effort. Check it out for yourself!</p> ]]></content:encoded> <wfw:commentRss>http://www.thewhyandthehow.com/jquery-date-chooser/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>jQuery tabs</title><link>http://www.thewhyandthehow.com/jquery-tabs/</link> <comments>http://www.thewhyandthehow.com/jquery-tabs/#comments</comments> <pubDate>Thu, 30 Apr 2009 23:49:02 +0000</pubDate> <dc:creator>Blake Schwendiman</dc:creator> <category><![CDATA[Javascript]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[jquery ui]]></category> <category><![CDATA[tabs]]></category><guid
isPermaLink="false">http://www.thewhyandthehow.com/?p=632</guid> <description><![CDATA[I&#8217;ve finally had a chance to implement a solution with jQuery tabs and I was very pleased with the simplicity of creating a very simple tabbed interface. I&#8217;ve used several tab solutions before the jQuery UI solution, and I definitely prefer the jQuery solution (yet again).
To set up a basic tabbed layout, start with an [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve finally had a chance to implement a solution with jQuery tabs and I was very pleased with the simplicity of creating a very simple tabbed interface. I&#8217;ve used several tab solutions before the jQuery UI solution, and I definitely prefer the jQuery solution (yet again).</p><p>To set up a basic tabbed layout, start with an enclosing container followed immediately by an unordered list containing the tabs and then the containers for the actual tab content. For example:</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p6326');">[<span
id="p6326_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p632code6'); return false;">View Code</a> JAVASCRIPT</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p6326"><td
class="code" id="p632code6"><pre class="javascript"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;example_tabs&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#example_tab_1&quot;</span><span style="color: #339933;">&gt;</span>Tab <span style="color: #CC0000;">1</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#example_tab_2&quot;</span><span style="color: #339933;">&gt;</span>Tab <span style="color: #CC0000;">1</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#example_tab_3&quot;</span><span style="color: #339933;">&gt;</span>Tab <span style="color: #CC0000;">1</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;example_tab_1&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>Content <span style="color: #000066; font-weight: bold;">for</span> tab <span style="color: #CC0000;">1</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;example_tab_2&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>Content <span style="color: #000066; font-weight: bold;">for</span> tab <span style="color: #CC0000;">2</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;example_tab_3&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>Content <span style="color: #000066; font-weight: bold;">for</span> tab <span style="color: #CC0000;">3</span><span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
  jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#example_tabs'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">tabs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div><p>And here&#8217;s the result:</p><div
id="example_tabs"><ul><li><a
href="#example_tab_1">Tab 1</a></li><li><a
href="#example_tab_2">Tab 2</a></li><li><a
href="#example_tab_3">Tab 3</a></li></ul><div
id="example_tab_1"><p>Content for tab 1</p></p></div><div
id="example_tab_2"><p>Content for tab 2</p></p></div><div
id="example_tab_3"><p>Content for tab 3</p></p></div></div><p><script type="text/javascript">jQuery(document).ready(function(){jQuery('#example_tabs').tabs();});</script><br
/> Obvious styling issues notwithstanding, I can&#8217;t imagine an easier way to build a tabbed interface for a web page. As always, <a
href="http://docs.jquery.com/UI/Tabs">read the manual</a> for more information and enjoy!</p> ]]></content:encoded> <wfw:commentRss>http://www.thewhyandthehow.com/jquery-tabs/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>jQuery modal dialog</title><link>http://www.thewhyandthehow.com/jquery-modal-dialog/</link> <comments>http://www.thewhyandthehow.com/jquery-modal-dialog/#comments</comments> <pubDate>Thu, 09 Apr 2009 20:41:51 +0000</pubDate> <dc:creator>Blake Schwendiman</dc:creator> <category><![CDATA[Javascript]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[dialog]]></category> <category><![CDATA[jquery ui]]></category> <category><![CDATA[tooltip]]></category><guid
isPermaLink="false">http://www.thewhyandthehow.com/?p=473</guid> <description><![CDATA[Coming from the world of Windows software development, the concept of a modal dialog box is an absolute expectation. Most often such dialogs are used to gather required information from the user while ensuring that nothing is clicked or altered in the main application window. When moving to the web world, it&#8217;s a bit jarring [...]]]></description> <content:encoded><![CDATA[<p>Coming from the world of Windows software development, the concept of a modal dialog box is an absolute expectation. Most often such dialogs are used to gather required information from the user while ensuring that nothing is clicked or altered in the main application window. When moving to the web world, it&#8217;s a bit jarring to discover that there is no ubiquitous built-in modal dialog*.</p><p>jQuery and jQuery UI provide an overlay-based approach to solving this problem that is both visually appealing and functionally complete. And, as with all things jQuery, it is very simple to implement.</p><p><a
href="#" onclick="jQuery('#dialog').dialog('open'); return false">Click here to see the popup</a> (unless you&#8217;re reading this in a news reader, then you&#8217;ll need to <a
href="http://www.thewhyandthehow.com/jquery-modal-dialog/">view the post on site</a>).</p><p>This sample is very simple to code in HTML and jQuery. Basically I provide a hidden DIV element containing the message to display and then initiate the dialog on page load. The link for the popup is also shown:</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p4738');">[<span
id="p4738_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p473code8'); return false;">View Code</a> JAVASCRIPT</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p4738"><td
class="code" id="p473code8"><pre class="javascript"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;dialog&quot;</span> title<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Example dialog&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span>Some text that you want to display to the user.<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
  jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#dialog&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">dialog</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      bgiframe<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> autoOpen<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span> height<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> modal<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;#&quot;</span> onclick<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;jQuery('#dialog').dialog('open'); return false&quot;</span><span style="color: #339933;">&gt;</span>Click here to see the popup<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></td></tr></table></div><p>There are many more options describe on the <a
href="http://jqueryui.com/demos/dialog/">jQuery UI dialog</a> pages. One of the reasons that I prefer the jQuery UI dialog to any of the other overlay dialog/tooltip solutions is that the jQuery UI version is so easy to implement and has very good defaults. By default the dialog is draggable, sizeable and includes the appropriate control element for closing the dialog. Surprisingly many other solutions don&#8217;t have these features by default.</p><div
id="dialog" title="Example dialog"><p>Some text that you want to display to the user.</p></div><p
class="note"><em>*Footnote: Yes, IE does have a modal popup window option, I know. It&#8217;s extremely non-standard and only supported in IE, so it&#8217;s not a reasonable solution in most cases.</em></p><p><script type="text/javascript">jQuery(document).ready(function(){jQuery("#dialog").dialog({bgiframe:true,autoOpen:false,height:100,modal:true});});</script></p> ]]></content:encoded> <wfw:commentRss>http://www.thewhyandthehow.com/jquery-modal-dialog/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Learn CSS</title><link>http://www.thewhyandthehow.com/learn-css/</link> <comments>http://www.thewhyandthehow.com/learn-css/#comments</comments> <pubDate>Fri, 27 Mar 2009 16:53:36 +0000</pubDate> <dc:creator>Blake Schwendiman</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[Development]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[jquery ui]]></category><guid
isPermaLink="false">http://www.thewhyandthehow.com/?p=389</guid> <description><![CDATA[In yesterday&#8217;s post, Geeking out, I forgot to mention the most important concept for both web designers and web developers to learn: CSS. Designers probably already understand the advantages, but developers implementing any complex functionality for a web site really need to know CSS today because of the client-side Javascript libraries that depend on CSS.
More [...]]]></description> <content:encoded><![CDATA[<script type="text/javascript" src="/wp-content/themes/thesis/custom/js/learn_css.js"></script><p>In yesterday&#8217;s post, <a
href="http://www.thewhyandthehow.com/geeking-out/">Geeking out</a>, I forgot to mention the most important concept for both web designers and web developers to learn: <a
href="http://www.w3schools.com/css/">CSS</a>. Designers probably already understand the advantages, but developers implementing any complex functionality for a web site really need to know CSS today because of the client-side Javascript libraries that depend on CSS.</p><p>More than likely if you&#8217;re a web developer you&#8217;ve written at least some client-side Javascript. It&#8217;s only going to become more likely. It should be obvious that client-side code provides a great deal of richness and responsiveness to any web application. So if you&#8217;re a web developer that&#8217;s primarily been working on back-end code and you want to stay relevant, learn Javascript, CSS and jQuery. Let me give you one brief example.</p><p>Let&#8217;s say that you want to create a handy sortable list of elements so your end-users can reorder items on their view of a page. The design team wants the list to be displayed with alternating row colors so they are easy to read. Something like this:</p><ul
class="example-sortable"><li>This is item 1</li><li>This is item 2</li><li>This is item 3</li><li>This is item 4</li></ul><p>Assuming the list is dynamically generated from a database and you&#8217;re a PHP programmer, you&#8217;re probably thinking of doing something like this:</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p38911');">[<span
id="p38911_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p389code11'); return false;">View Code</a> PHP</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p38911"><td
class="code" id="p389code11"><pre class="php"><span style="color: #000033;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">'&lt;ul&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$items</span> <span style="color: #b1b100;">as</span> <span style="color: #000033;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">'&lt;li '</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$i</span><span style="color: #339933;">++</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'class=&quot;alt-row&quot;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000033;">$item</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<a href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>That&#8217;s great, but it&#8217;s only part of the solution. Since the list is sortable on the client side, the list will have to be re-striped every time an item is moved, otherwise it will look wrong. The sorting and the striping both need to occur on the client side, so simplify the PHP to just create the list with no alternating classes, then use jQuery to do the client-side heavy lifting.</p><p>The jQuery (and jQuery UI for sortable) solution looks like this:</p><div
id="wp_codebox_msgheader"><span
class="right"><a
href="javascript:;" onclick="toggle_collapse('p38912');">[<span
id="p38912_symbol">-</span>]</a><sup><a
href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span
style="color: #99cc00">?</span></a></sup></span><span
class="left"><a
href="javascript:;" onclick="javascript:showCodeTxt('p389code12'); return false;">View Code</a> JAVASCRIPT</span><div
class="codebox_clear"></div></div><div
id="wp_codebox"><table
width="100%" ><tr
id="p38912"><td
class="code" id="p389code12"><pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> learn_css_restripe<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul.example-sortable li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'alt-row'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul.example-sortable li:even'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'alt-row'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  learn_css_restripe<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// call the restripe function on page ready to set the initial stripes</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// make the list sortable</span>
  jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul.example-sortable'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">sortable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">// whenever the list order changes, restripe</span>
  jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul.example-sortable'</span><span style="color: #009900;">&#41;</span>.<span style="color: #006600;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'sortchange'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> ui<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>learn_css_restripe<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>Understanding CSS and the DOM of the document is what makes using jQuery so powerful. Notice that the restripe function, <em>learn_css_restripe</em> doesn&#8217;t do any looping or have any direct references to an DOM element ids. Instead the function simply removes the alternating row class from every element of any unordered list with the <em>example-sortable</em> class. Then some jQuery selector magic, <em>:even</em>, is used to add the alternating row class back to just the even elements of the lists.</p><p>Since this technique is so generic, it is possible to have more than one list on the same page without changing any of the code at all. Here&#8217;s another list with more elements as an example:</p><ul
class="example-sortable"><li>This is item A</li><li>This is item B</li><li>This is item C</li><li>This is item D</li><li>This is item E</li><li>This is item F</li><li>This is item G</li></ul><p>As you can see, CSS is not just for designers. Great web developers will work with great designers to simplify both the layout and the code at the same time using CSS.</p> ]]></content:encoded> <wfw:commentRss>http://www.thewhyandthehow.com/learn-css/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss><!--
This site's performance optimized by W3 Total Cache:

W3 Total Cache improves the user experience of your blog by caching
frequent operations, reducing the weight of various files and providing
transparent content delivery network integration.

Learn more about our WordPress Plugins: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached
Page Caching using memcached
Database Caching 3/15 queries in 0.008 seconds using memcached

Served from: a2.c0.354a.static.theplanet.com @ 2010-09-07 01:56:03 -->