<?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>Kyle Schaeffer - Web Design and SharePoint Branding &#187; JavaScript</title>
	<atom:link href="http://kyleschaeffer.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://kyleschaeffer.com</link>
	<description>Web Design &#38; SharePoint Branding</description>
	<lastBuildDate>Wed, 01 Feb 2012 23:01:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>10 Things a Website Should Never, Ever Do</title>
		<link>http://kyleschaeffer.com/best-practices/10-things-a-website-should-never-ever-do/</link>
		<comments>http://kyleschaeffer.com/best-practices/10-things-a-website-should-never-ever-do/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 21:19:15 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Web Browsers]]></category>

		<guid isPermaLink="false">http://kyleschaeffer.com/?p=994</guid>
		<description><![CDATA[As a designer of the world wide web, you are armed with the power to amaze, enlighten, entice, and captivate. The web is an easel for your creative aspirations, and the content you design for is the foundation of your &#8230; <a href="http://kyleschaeffer.com/best-practices/10-things-a-website-should-never-ever-do/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As a designer of the world wide web, you are armed with the power to amaze, enlighten, entice, and captivate. The web is an easel for your creative aspirations, and the content you design for is the foundation of your creativity. With so much power at the tips of your fingers, you also possess the ability to deter, annoy, anger, and infuriate. Your users are yours to command, their emotions yours to pluck like the strings of a harp.<span id="more-994"></span></p>
<p>It&#8217;s the latter of these powers that we discuss today: your ability to destroy the desire for users to stay on your site. We&#8217;ll examine the causes of user strife on the web, and see clear examples of common mistakes that designers and developers all-too-often seem to make.</p>
<h2>1. Never interfere with the ability to scroll</h2>
<p>The browser window is a fairly simple application: an address/search bar, a few buttons, and a big window where users read, scroll, and click. Sure, most browsers have other bells and whistles, but it really boils down to these essential elements of the browsing experience. Rule number one: never, ever (ever, ever) interfere with these most basic features of the browser window.</p>
<h3>Example: Microsoft SharePoint 2010</h3>
<p><img class="alignright" title="Microsoft SharePoint 2010" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2011/09/sharepoint-2010.jpg" alt="Microsoft SharePoint 2010" width="300" height="175" />One of the most preposterous features of an interface that I&#8217;ve seen is SharePoint 2010&#8242;s new ribbon interface. The default SharePoint 2010 interface includes a simple CSS style that disables the scrollbar on the <code>&lt;body&gt;</code> element. Microsoft chooses to remedy this by adding a scrollbar to other division elements in the interface instead. This results in a fairly impressive &#8220;fixed&#8221; ribbon, but it has some infuriating side-effects.</p>
<ul>
<li>When a SharePoint 2010 page loads, users will not be able to scroll until all JavaScript has loaded.  On slow servers or on large pages, this can take up to 2-3 seconds, which can be quite infuriating.</li>
<li>Some devices don&#8217;t execute the JavaScript in the expected fashion, resulting in the complete inability to scroll on mobile devices and tablets.</li>
</ul>
<h3>An easy solution</h3>
<p>The truth is, creating a &#8220;fixed&#8221; element is a fairly simple CSS technique that has become extremely popular in the last few months. The complexity of Microsoft&#8217;s interface is it&#8217;s downfall. Always practice in simplicity, because fewer things can go wrong in the end. Build simple interfaces, and <em>never</em> disable the scroll bar. Do this, and you&#8217;ll know at least one person who doesn&#8217;t hate your guts.</p>
<h2>2. Never allow form resubmissions</h2>
<p>Forms are a fairly standard feature of the web. Users see them and use them all the time: to sign up, sign in, order, update, and the like. With so much familiarity, it&#8217;s a wonder that forms are one of the largest sources of frustration to users. Between data, validation, formatting, handling errors, and all the auxiliary things that seem to surround web forms, things can get pretty complex for designers and developers. All the while, you try to keep it simple for your users. It&#8217;s a tall order, to be sure, but there is at least one thing that you can do to help users stay calm.</p>
<h3>Example: The Form Resubmission Prompt</h3>
<p><img class="alignnone size-medium wp-image-1008" title="Form Resubmission" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2011/09/form-resubmission.jpg" alt="Form Resubmission" /></p>
<p>This is Google Chrome&#8217;s form resubmission prompt. Most browsers have something very similar. This appears when users click on the &#8220;Back&#8221; and &#8220;Forward&#8221; buttons in the browser, or when they &#8220;Refresh&#8221; a page on which they have submitted a form. As web junkies, we might know what this means, but it has a more elusive meaning to your every-day internet users. Most of the time, you&#8217;ll find that users simply click the default option (in this case, &#8220;Continue&#8221;), which can lead to duplication of orders, data, requests, and all sorts of things that would be better off if avoided. Also, it&#8217;s just another annoying prompt that users encounter while they&#8217;re using your site.</p>
<h3>A Simple Solution</h3>
<p>The solution to form resubmissions really depends on the platform your website runs on. In most cases, a simple fix is to separate the script that submits the form data, and the script that receives and processes that data. For example, if you&#8217;re using a PHP-based platform, you might have a form that looks like this:</p>
<pre>&lt;form action="submit.php"&gt;
  &lt;input type="text" name="user" required /&gt;
  &lt;input type="password" name="pass" required /&gt;
  &lt;input type="submit" value="Log in" /&gt;
&lt;/form&gt;</pre>
<p>To avoid the resubmission prompt, your <code>submit.php</code> script would <strong>forward</strong> to another page, rather than displaying a page in the browser.</p>
<pre>if(isset($_POST['user']) &amp;&amp; isset($_POST['pass'])){
  // do something with the form data
  <strong>header('Location:/login/form.php?success=true');</strong>
}</pre>
<p>This receiving script never actually displays anything in the browser window. Instead, it receives the form data, does something with it, and then forwards the user somewhere else. Using this technique, when users click on the &#8220;Back&#8221; or &#8220;Forward&#8221; button, the browser will skip the <code>submit.php</code> page completely, and never see the annoying form resubmission prompt.</p>
<h2>3. Never disable keyboard support</h2>
<p><img class="alignright size-full wp-image-1009" title="Sprint Sign-In" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2011/09/sprint-sign-in.jpg" alt="Sprint Sign-In" width="179" height="357" />While we&#8217;re on the topic of forms, let&#8217;s look at another deviation from web standards you&#8217;ll want to avoid. To the right, you&#8217;ll see a screenshot of the login form at <a href="http://mysprint.sprint.com">mysprint.sprint.com</a>. I have a Sprint mobile phone, and I occasionally use this login form to sign in and review my account, see my bill, or (more commonly) daydream about all the fancy new mobile phones that I don&#8217;t have.</p>
<h3>What went wrong</h3>
<p>The font sizes are a little small for my taste, but the appearance of this form is not the worst I&#8217;ve seen (yes, that was a compliment). Design and aesthetics aside, there&#8217;s one feature of this form that drives me absolutely crazy. It&#8217;s an extremely simple form, one that I&#8217;ve encountered on countless other websites before. As usual, I would expect to enter my username and password to sign in without a fuss.</p>
<p>Unfortunately, this is not the case. While focusing in either the username or password textbox, pressing the ENTER key does absolutely nothing. I&#8217;m not the type of user that wastes time after filling out a form by lifting my hand from the keyboard and finding the submit button with my mouse cursor. I&#8217;m all about speed: on most websites, it&#8217;s type, type, ENTER, and the form has been submitted. On Sprint&#8217;s website, however, they&#8217;ve removed this behavior, and thus they&#8217;ve earned a place on my list of don&#8217;t-do&#8217;s.</p>
<h2>4. Never fail to give feedback</h2>
<p><img class="alignright size-full wp-image-1016" title="Facebook - Add Favorite" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2011/09/facebook-add-favorites.jpg" alt="Facebook - Add Favorite" width="201" height="344" />Feedback is important, especially if you&#8217;re working with the awesomeness of AJAX. Traditionally, you knew what was going on in a web page, because any time you clicked on something, you had to wait while the next page loaded. There was a very apparent interaction period, and very obvious feedback from that interaction. With the introduction of new technology like AJAX, however, that feedback is not always so obvious. Today&#8217;s websites are much more interactive, and the result of those interactions (whether successful or not) needs to be communicated to the user.</p>
<h3>Example: Facebook</h3>
<p>There&#8217;s an easy way to test this: visit a web page, turn off your wireless adapter, and then click on things and see what happens. Obviously, because you&#8217;re not online, anything you do should be very obviously followed by a &#8220;no connection&#8221; message or some sort of indication that you&#8217;ve failed to do something. Facebook, a website that makes gratuitous use of AJAX for interaction, is not so good about warning users when things have failed.</p>
<p><strong>Editor&#8217;s note:</strong> yes, I am using pirate Facebook.</p>
<p>One particular example is the new &#8220;lists&#8221; feature that allows you to mark a list as &#8220;favorite.&#8221; Even when you&#8217;re offline, Facebook gives you no indication that the action has failed. Never assume that users will have a fast connection, or that AJAX requests will complete. You should always provide feedback if something fails, especially when no page loads are involved.</p>
<h2>5. Never disable keyboard navigation</h2>
<p>Different strokes for different folks. That&#8217;s a saying that I like to spew off at random times, usually in a failed attempt at humor, but the lesson of this silly quip is tried and true: everyone has their own way of doing things. This can also be applied to navigation on the internet. Some people prefer to use their cursor for absolutely everything, and only resort to keyboard use when absolutely necessary. Others use the keyboard almost entirely, tabbing, backspacing, and scrolling their way through the world of the world wide web. Others, still, use gestures and touch screens to flick and fly their way through the internet. As a crafter of the interactive, you must adhere to all of these people. Never detract from your users&#8217; ability to navigate in whatever way they damn well please.</p>
<h3>Example: No, I don&#8217;t want to search</h3>
<p><img class="alignright size-full wp-image-1027" title="eBay Auto-focus" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2011/09/ebay-search.jpg" alt="eBay Auto-focus" width="202" height="101" />I&#8217;m going to use eBay as an example, just because they&#8217;re so big, but many websites <em>out there</em> are guilty of this annoyance. Upon arriving at eBay&#8217;s website, they use JavaScript to auto-focus on the search bar. I guess they&#8217;ve already decided, before you even visit, that you want to search their website. For some users, however, this can be incredibly annoying. A common and simple way to scroll down the page, in all browsers, is to press the space key. Pressing this key will advance the screen about one page, so you can continue reading without having to worry about scroll bars and the like. If you&#8217;re auto-focused on a search box, however, it disables your ability to do this. Even if it&#8217;s only a minor annoyance, it can be incredibly frustrating to users who like to navigate in this fashion. Likewise, I often use the backspace key instead of the back button to go back when I didn&#8217;t find what I was looking for. With the focus on a search field, backspace navigation simply doesn&#8217;t work.</p>
<p>The fix for this one is easy: don&#8217;t do it. It&#8217;s annoying.</p>
<h2>6. Never move content without user interaction</h2>
<p>Websites can be so damn sneaky. I guess they need to make a buck, but who doesn&#8217;t? One thing that will drive your users bonkers is anything that moves without a prompt from the user. Yes, I&#8217;m talking about you, &#8220;auto-expanding-advertisement-that-plays-a-stupid-video-of-a-guy-who-walks-across-my-screen-when-I-just-want-to-read-the-damn-article&#8221; guy. I also dislike anything that happens on hover (including drop-down menus). Hover is so 2000&#8242;s, get with the times, people. The only time your website should &#8220;move&#8221; or &#8220;do something&#8221; is when users tell it to. Most simply, any time they click, drag, or scroll. That sounds simple and obvious, but not everyone adheres to this most basic of principles.</p>
<h3>Example: Digg.com</h3>
<p><img class="alignnone size-full wp-image-1028" title="Digg Advertisement" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2011/09/digg-advertisement.jpg" alt="Digg Advertisement" width="600" height="300" /></p>
<p>While the quality of Digg&#8217;s content is another concern, one thing that does drive me crazy is the sponsored links that appear in the rollup. Notice the promotion from NewEgg.com. This link does not actually appear on page load, but rather when users hover their mouse cursor into the rollup of popular stories. This means that if you&#8217;re a fast clicker (aren&#8217;t we all?), you will often accidentally click on the advertisement instead of the story you&#8217;re interested in. Good for Digg, bad for users. Stop being so shifty, internet.</p>
<h2>7. Never use fixed position without a fallback</h2>
<p>A &#8220;fixed&#8221; element in the browser window is one that stays on the screen, even as you scroll down the page. It&#8217;s a simple CSS technique, but it&#8217;s been amazingly popular in recent months. One thing I&#8217;ve noticed in all these fixed designs is the failure to provide a fallback for users who are on smaller screens. The truth of the matter is that the web isn&#8217;t just for desktops any more. Internet connectivity is coming in all sorts of shapes and sizes: desktops, laptops, mobiles, tablets, e-readers, gaming consoles, and even refrigerators (yes, even refrigerators). The future promises only more diversity in internet-connected devices, and that means you can&#8217;t assume users will have a large viewing area on which to see your website.</p>
<h3>Example: Pandora.com</h3>
<p><img class="alignright size-full wp-image-1035" title="Pandora Fixed" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2011/09/pandora-fixed-nav.jpg" alt="Pandora Fixed" width="403" height="269" />This is a screenshot of Pandora&#8217;s fancy new HTML5/CSS3 design. First of all, I&#8217;ll say that I love Pandora.  Maybe too much. It&#8217;s pretty awesome, and it even lets me give all of my radio stations quirky little names like &#8220;Harmonizatorasaurous&#8221; (eat that, spell-check).</p>
<p>Pandora&#8217;s new design includes a fixed header, like many new designs, but it seems the header does not provide a fallback for users on a smaller screen. When reducing the window width, it clips the player controls off the edge of the screen. If a fixed element is clipped, users can&#8217;t see it, even if they try to scroll to see more, which can be a huge problem.</p>
<h3>A simple solution</h3>
<p>An easy solution to this problem is to make the default behavior of your site&#8217;s header to maintain a static position, but when users have a large enough screen, you can make things fixed for a more impressive presentation.  The following jQuery snippet does the trick quite nicely:</p>
<pre>$(window).resize(function(){
  resizeUI();
}); 
$(document).ready(function(){
  resizeUI();
});

<strong>// resize on page load AND window resize</strong>
<strong>function resizeUI(){</strong>
<strong> if($(window).width() &gt; 500){</strong>
<strong> $('#header').css('position', 'fixed');</strong>
<strong> }</strong>
<strong> else{</strong>
<strong> $('#header').css('position', 'static');</strong>
<strong> }</strong>
<strong>} </strong></pre>
<p>This script runs both on page load AND as users resize the window, so no matter what happens, you can decide whether or not to use fixed elements. You&#8217;ll have to mess with the values that the script looks at (width and height) to determine what works best for your site&#8217;s design, but it&#8217;s a useful technique to use.</p>
<h2>8. Never use pop-up windows</h2>
<p>Do I really even have to mention this one? I thought that pop-ups were notorious for the infuriating behavior that have on users, but I still see them &#8220;pop up&#8221; from time to time (pun <em>intended</em>).</p>
<h3>Example: TinyMCE</h3>
<p><img class="alignright size-full wp-image-1036" title="TinyMCE" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2011/09/tinymce.jpg" alt="TinyMCE" width="185" height="98" />I never use pop-ups. I always recommend against them. A common excuse is that <em>your</em> site should stay open, in it&#8217;s own tab, even if users click a link that takes them away from your site. I&#8217;ve got a simple response to that: wrong! Don&#8217;t let your head grow so big that you think your website is god&#8217;s gift to the internet. Users have gotten pretty comfortable with the idea of tabbed browsing, and they know how to manage their windows. Unless you&#8217;re Google, you&#8217;re not allowed to use pop-ups. It&#8217;s that simple.</p>
<p>Imagine my surprise when I attempted to implement the TinyMCE JavaScript editor into a web application I was building, and realized it still used pop-up windows for things like links and images. I am building a PHP application, and I have had stars in my eyes for WordPress the entire time, so TinyMCE was the obvious choice. I was so taken aback by this behavior that I ended up switching to CKEditor, another popular editor that has recognized the need to rid the world of these annoying little boxes, and I&#8217;m all the happier for it.</p>
<h2>9. Never get quirky (well, not <em>too</em> quirky)</h2>
<p>I love websites that are different, but not <em>too</em> different. There&#8217;s a fine balance to be made between adhering to expectations, and getting so weird that users have no idea what&#8217;s going on. As with most users, if I visit a website and am prompted to &#8220;explore this insanely huge image of nonsense to learn how to navigate our site,&#8221; I&#8217;m going to leave and never return. I&#8217;ve never been a proponent of Flash, for this very reason, but I also recognize that it has it&#8217;s place. Flash can enhance a website&#8217;s content with some awesome features, but it should never be used to present content in its entirety.</p>
<h3>Example: Sony.com</h3>
<p><img class="alignright size-full wp-image-1038" title="Sony" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2011/09/sony.jpg" alt="Sony" width="305" height="133" />Check out <a href="http://www.sony.com">Sony.com</a>, and you&#8217;ll realize that a full 5-8 seconds will go by before you actually see anything on the screen that you can click on. Almost the entire site is in Flash, and it breaks about five of the ten &#8220;don&#8217;t do&#8217;s&#8221; that I&#8217;ve described in this article. All that aside, Sony has provided a non-Flash version of their site, which also subsequently presents a loading spinner for about 2-3 seconds that covers all of the content on the page. I&#8217;m not entirely sure why the designer who created the Sony website was so fond of things that come between users and consuming the content they came to read, but I do know this: it&#8217;s annoying. Don&#8217;t do it.</p>
<h2>10. Never do THIS&#8230;</h2>
<p>Okay, this last one is really just for fun, but never do THIS&#8230;</p>
<pre>body * {
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  transition: all 0.5s ease;
}
body *:hover {
  -webkit-transform: rotate(180deg);
  -moz-transform: rotate(180deg);
  -o-transform: rotate(180deg);
  transform: rotate(180deg);
}</pre>
<p>Try it out by clicking on this button (you&#8217;ve been warned):</p>
<input id="crazy-button" type="button" value="Let's get crazy" />
<script src="/wordpress/wp-content/themes/shakefive/js/crazy.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/best-practices/10-things-a-website-should-never-ever-do/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>WP Tabify: Transform a SharePoint Web Part Zone into Tabs</title>
		<link>http://kyleschaeffer.com/sharepoint/wp-tabify/</link>
		<comments>http://kyleschaeffer.com/sharepoint/wp-tabify/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 16:01:22 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tabs]]></category>

		<guid isPermaLink="false">http://kyleschaeffer.com/?p=651</guid>
		<description><![CDATA[I do quite a bit of design and implementation on the SharePoint platform. Today, I created a very handy little script that I think might be something worth sharing. I don&#8217;t often post anything so specific on my blog, but &#8230; <a href="http://kyleschaeffer.com/sharepoint/wp-tabify/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I do quite a bit of design and implementation on the SharePoint platform. Today, I created a very handy little script that I think might be something worth sharing. I don&#8217;t often post anything so specific on my blog, but I found this to be extremely useful, and I hope you do too.<span id="more-651"></span></p>
<h2>What is it?</h2>
<p>This all started with a great idea from the mind of <a href="http://www.thesug.org/Blogs/matthew_koon/">Matthew Koon</a>. If you&#8217;re not familiar with SharePoint, one thing you can do in the platform is place <strong>web parts</strong> on a page, which are akin to sidebar widgets in WordPress or other CMS platforms. Web parts have a lot of nifty drag-and-drop functionality, but the appearance of them is pretty much limited to what you can do with a bit of CSS and maybe some background images. The script that I created transforms a particular &#8220;web part zone,&#8221; which contains individual web parts, into a jQuery UI tab control. For each web part in the zone, you see an interactive &#8220;tab&#8221; instead of a boring static box. The contents of each tab is the contents of the web part, itself.</p>
<h2>What does it do?</h2>
<p>When you&#8217;re editing a page, you&#8217;ll see this:</p>
<p><a href="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/10/wptabify-edit-mode.png"><img src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/10/wptabify-edit-mode-300x300.png" alt="" title="WPTabify in Edit Mode" width="300" height="300" class="alignnone size-medium wp-image-653" /></a></p>
<p>When you publish the page, you&#8217;ll see this:</p>
<p><a href="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/10/wptabify-display-mode.png"><img src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/10/wptabify-display-mode-300x77.png" alt="" title="WPTabify (Display Mode)" width="300" height="77" class="alignnone size-medium wp-image-652" /></a></p>
<h2>1. Attach Required Scripts</h2>
<p>You&#8217;ll need both jQuery 1.4.2 and jQuery UI 1.8.5 (or later).</p>
<pre>&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js&quot;&gt;&lt;/script&gt;</pre>
<h2>2. Attach the Script</h2>
<p>Paste this into an attached JavaScript file:</p>
<pre>(function($){
  $.fn.wpTabify = function(){
    if($('.ms-WPAddButton').size() == 0){
      return this.each(function(i){
        var tabList = $('&lt;ul class=&quot;wpt-ui-tabs-nav&quot;/&gt;');
        var panels = $('&lt;div class=&quot;wpt-ui-tabs-wrapper&quot;/&gt;');
        $(this).find('.s4-wpTopTable,td[id^=&quot;MSOZoneCell_&quot;] &gt; table').each(function(j){
          $(tabList).append('&lt;li&gt;&lt;a href=&quot;#ui-tab-panel' + i + j + '&quot;&gt;' + $(this).find('h3.ms-WPTitle').text() + '&lt;/a&gt;&lt;/li&gt;');
          var thisPanel = $('&lt;div id=&quot;ui-tab-panel' + i + j + '&quot; class=&quot;wpt-ui-tabs-panel&quot;/&gt;');
          var panelContents = $(this).detach();
          $(thisPanel).append($(panelContents).find('.ms-WPBody').html());
          $(panels).append(thisPanel);
        });
        if($(tabList).find('li').size() &gt; 0){
          $(this).prepend(panels);
          $(this).prepend(tabList);
          $(this).tabs();
        }
      });
    }
    else{
      return false;
    }
  };
})(jQuery);</pre>
<h2>3. Wrap Your Web Part Zone</h2>
<p>In your custom page layout, place a <code>&lt;div/&gt;</code> tag around a web part zone, and give it a class name or ID of your choosing.</p>
<pre>&lt;div class=&quot;<strong>my-web-part-tabs</strong>&quot;&gt;
  &lt;WebPartPages:WebPartZone id=&quot;zone1&quot; runat=&quot;server&quot; title=&quot;Tabs Zone&quot;&gt;&lt;ZoneTemplate&gt;&lt;/ZoneTemplate&gt;&lt;/WebPartPages:WebPartZone&gt;
&lt;/div&gt;</pre>
<h2>4. Run the Script</h2>
<p>Now that you&#8217;ve attached the script, run it using a jQuery selector that matches the <code>&lt;div&gt;</code> you created in step three (above). This code also goes in an attached JavaScript file.</p>
<pre>$(document).ready(function(){
  $('<strong>.my-web-part-tabs</strong>').wpTabify();
});</pre>
<h2>5. Add Some Style (Optional)</h2>
<p>You may choose to add a bit of style to your newly tabified web parts (this is not specific to this plug-in, these are just some generic jQuery tabs styles):</p>
<pre>.ui-tabs-nav {
    margin: 0;
    padding: 0;
}
.ui-tabs-nav li {
  list-style: none;
  margin: 0 1px 0 0;
  padding: 0;
  float: left;
}
.ui-tabs-nav a {
  position: relative;
  top: 1px;
  display: block;
  padding: 10px 8px;
  border: solid #e1e0dc;
  border-width: 1px 1px 0 1px;
  background: #d6d6d6;
  color: #999;
  text-decoration: none;
  -webkit-border-top-left-radius: 5px;
  -webkit-border-top-right-radius: 5px;
  -moz-border-radius-topleft: 5px;
  -moz-border-radius-topright: 5px;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}
.ui-tabs-nav li.ui-tabs-selected a {
  color: #c70d37;
  background: #fff;
}
.ui-tabs-panel {
  clear: both;
  padding: 20px;
  background: #fff;
  border: 1px solid #e1e0dc;
}
.ui-tabs-hide {
  display: none;
}</pre>
<h2>Compatibility</h2>
<p>This has been tested in SharePoint 2007 and SharePoint 2010. <strong>Make sure to set your web part chrome to anything other than <em>None</em></strong>, as my script relies on the web part title to display the tab title. Please let me know if you have any issues, as I will continue to update the script as needed. Good luck, and happy tabbing!</p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/sharepoint/wp-tabify/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Input Prompt Text:  A Better Way</title>
		<link>http://kyleschaeffer.com/best-practices/input-prompt-text/</link>
		<comments>http://kyleschaeffer.com/best-practices/input-prompt-text/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 02:43:37 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Text]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.kyleschaeffer.com/?p=565</guid>
		<description><![CDATA[It&#8217;s a very cool feature to have a form field that has prompt text such as Enter search keywords&#8230; right inside the input box, itself. It looks good, it makes sense to users, and it can save a lot of &#8230; <a href="http://kyleschaeffer.com/best-practices/input-prompt-text/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a very cool feature to have a form field that has prompt text such as <em>Enter search keywords&#8230;</em> right inside the input box, itself. It looks good, it makes sense to users, and it can save a lot of real estate in your design by negating the need for field labels. The problem, however, is that there are about one hundred ways to implement prompt text, and ninety-nine of them are wrong. Let&#8217;s look at this thing from all angles and come up with a fantastically simple and reliable way to make this work.<span id="more-565"></span></p>
<h2>What is input prompt text?</h2>
<p>You&#8217;re probably familiar with the concept, even if you don&#8217;t know what I&#8217;m talking about. Here&#8217;s an example:</p>
<p>
<input type="text" style="color: #999; font-style: italic; width: 250px;" value="Enter search keywords..." />
<input type="button" value="Search" /></p>
<p>The <em>prompt text</em> appears inside the form field as soon as the page loads, so users immediately know what it&#8217;s for. Simple, right?</p>
<h2>Why it Doesn&#8217;t Work</h2>
<p>There are a number of problems you&#8217;ll encounter while implementing prompt text into your forms. Watch out for these caveats when you&#8217;re developing your own solution.</p>
<ol>
<li><strong>Input validation</strong> &mdash; if someone submits the form without first removing the prompt text, your prompt text is submitted in lieu of real data. Fixing this is a pain. Avoiding this entirely is recommended.</li>
<li><strong>Prompt style</strong> &mdash; it&#8217;s best to style the prompt text so that it doesn&#8217;t look like real form data. Creativity is a virtue, but generally web users will expect light (gray) text and italics. This can be problematic because you&#8217;ll have to swap the input style back and forth using JavaScript.</li>
<li><strong>Losing focus</strong> &mdash; when users focus on a form field, don&#8217;t type anything, and then click somewhere else, you should always add the prompt text <em>back into the input box</em>.  Otherwise, users could miss the intent of the form field entirely.  Again, you&#8217;ll have to do this with JavaScript, which can be a little tricky.</li>
<li><strong>Progressive enhancement</strong> &mdash; always make sure that users without JavaScript can still understand and interact with your form fields. This is progressive enhancement at its finest.</li>
</ol>
<h2>The Solution</h2>
<p>Almost everything related to the problems listed above originates from one basic fact: you&#8217;re trying to create both a <strong>field</strong> and a <strong>label</strong> using a single HTML element. When you take a step back and think about that, it really doesn&#8217;t make much sense, does it? The solution lies in separating the form field from the label entirely. We&#8217;ll use a little bit of jQuery to create an elegant solution that dynamically creates these labels and places them over our form fields. Because we&#8217;re creating two separate elements, we can use CSS to style them independently. Perfect!</p>
<p><strong>The jQuery:</strong></p>
<pre>$(document).ready(function(){
  $('input[type=text][title],input[type=password][title],textarea[title]').each(function(i){
    $(this).addClass('input-prompt-' + i);
    var promptSpan = $('&lt;span class=&quot;input-prompt&quot;/&gt;');
    $(promptSpan).attr('id', 'input-prompt-' + i);
    $(promptSpan).append($(this).attr('title'));
    $(promptSpan).click(function(){
      $(this).hide();
      $('.' + $(this).attr('id')).focus();
    });
    if($(this).val() != ''){
      $(promptSpan).hide();
    }
    $(this).before(promptSpan);
    $(this).focus(function(){
      $('#input-prompt-' + i).hide();
    });
    $(this).blur(function(){
      if($(this).val() == ''){
        $('#input-prompt-' + i).show();
      }
    });
  });
});</pre>
<p><strong>The CSS:</strong></p>
<pre>.input-prompt {
  position: absolute;
  font-style: italic;
  color: #aaa;
  margin: 0.2em 0 0 0.5em;
}</pre>
<p><strong>The HTML:</strong></p>
<pre>&lt;input type=&quot;text&quot; <strong>title=&quot;Enter search keywords...&quot;</strong> /&gt;</pre>
<p>Basically, this script finds any <code>&lt;input&gt;</code> tags that have a <code>title</code> attribute (i.e. <code>&lt;input title=&quot;Enter search keywords...&quot; /&gt;</code>). For each of these form fields, it takes the <code>title</code> and creates a little <code>&lt;span&gt;</code> tag next to it. The CSS positions the <code>&lt;span&gt;</code> tag so that it appears <em>on top</em> of the form field. The rest is just a little bit of scripting that makes sure to hide and show the labels based on what the user is doing with the input box.</p>
<h2>The Result</h2>
<p>Here is a demo of the code shown above:</p>
<p><script type="text/javascript">jQuery(document).ready(function(){
  jQuery('input#demo').each(function(i){
    jQuery(this).addClass('input-prompt-' + i);
    var promptSpan = jQuery('<span class="input-prompt"/>');
    jQuery(promptSpan).attr('id', 'input-prompt-' + i);
    jQuery(promptSpan).append(jQuery(this).attr('title'));
    jQuery(promptSpan).click(function(){
      jQuery(this).hide();
      jQuery('.' + jQuery(this).attr('id')).focus();
    });
    if(jQuery(this).val() != ''){
      jQuery(promptSpan).hide();
    }
    jQuery(this).before(promptSpan);
    jQuery(this).focus(function(){
      jQuery('#input-prompt-' + i).hide();
    });
    jQuery(this).blur(function(){
      if(jQuery(this).val() == ''){
        jQuery('#input-prompt-' + i).show();
      }
    });
  });
});</script><br />
<style type="text/css">.input-prompt { position: absolute; font-style: italic; color: #aaa; margin: 0.7em 0 0 1em; }</style>
<input id="demo" type="text" title="Enter search keywords..." size="50" style="padding: 0.5em;" />
<p>Users without JavaScript enabled will see the normal title tool tips when they hover their mouse cursor over the form field.  Please note that you&#8217;ll probably have to adjust the <code>margin</code> a bit in the CSS to make sure the labels fit the size of your input boxes. For more information on jQuery and all the great things it can do, visit <a href="http://jquery.com/">jQuery.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/best-practices/input-prompt-text/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>The Perfect jQuery AJAX Request</title>
		<link>http://kyleschaeffer.com/best-practices/the-perfect-jquery-ajax-request/</link>
		<comments>http://kyleschaeffer.com/best-practices/the-perfect-jquery-ajax-request/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 14:10:41 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kyleschaeffer.com/?p=538</guid>
		<description><![CDATA[If you&#8217;re into client-scripting, then jQuery AJAX is probably your thing (if it&#8217;s not, perhaps it should be!). jQuery has some fantastic support for AJAX, and implementing it into your web application is so easy it&#8217;s stupid. The AJAX functionality &#8230; <a href="http://kyleschaeffer.com/best-practices/the-perfect-jquery-ajax-request/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re into client-scripting, then <a href="http://api.jquery.com/category/ajax/">jQuery AJAX</a> is probably <em>your thing</em> (if it&#8217;s not, perhaps it should be!). jQuery has some fantastic support for AJAX, and implementing it into your web application is so easy it&#8217;s stupid.  The AJAX functionality in the AJAX library is so flexible, sometimes it&#8217;s easy to get lost when you&#8217;re trying to do something very simple.  I&#8217;ve come up with a very basic jQuery AJAX template that I use for just about everything I do, and I thought it might be useful to share.<span id="more-538"></span></p>
<h2>The Old Way</h2>
<p>Did you work with AJAX <em>way back when</em>, when it first came out?  You might remember that an AJAX request looked a little like this.</p>
<pre>var xmlhttp;
xmlhttp = GetXmlHttpObject();
if(xmlhttp == null){
  alert(&quot;Boo! Your browser doesn't support AJAX!&quot;);
  return;
}
xmlhttp.onreadystatechange = stateChanged;
xmlhttp.open(&quot;GET&quot;, &quot;http://www.google.com&quot;, true);
xmlhttp.send(null);

function stateChanged(){
  if(xmlhttp.readyState == 4){
    // do something with the response text
    alert(xmlhttp.responseText);
  }
}
function GetXmlHttpObject(){
  // IE7+, Firefox, Chrome, Opera, Safari
  if(window.XMLHttpRequest){
    return new XMLHttpRequest();
  }

  //IE5, IE6
  if(window.ActiveXObject){
    return new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
  }
  return null;
}</pre>
<p>In a nutshell, that sucks!  All of that code to simply request the contents of Google&#8217;s home page, and then alert in the window.  That&#8217;s not very helpful at all.  Alternatively, here is the exact same function written in jQuery:</p>
<pre>$.ajax({
  url: 'http://www.google.com',
  success:function(data){
    alert(data);
  }
});</pre>
<p>As you can plainly see, the jQuery AJAX method is much easier to wrap your mind around.  You give it a URL to request, and then you give it a set of instructions if a successful request is made.  Easy!</p>
<p>I understand that it&#8217;s not very useful to request the contents of a web page and alert it to your users (in fact, that&#8217;s probably pretty annoying), so let&#8217;s take it up a notch.  jQuery AJAX features a ridiculous amount of customization options, events, and the like to give you a huge amount of flexibility, and it can be hard to find a good place to start.  I&#8217;ll help you find the starting line, and you can take it from there.</p>
<h2>The Perfect AJAX Request</h2>
<p>I&#8217;m fairly positive that by using the term <em>perfect</em>, I&#8217;m going to get a good amount of nay-sayers telling me why jQuery AJAX sucks, but that&#8217;s not what I&#8217;m getting at.  This jQuery function is <em>perfect</em> in the sense that it handles 99% of all the AJAX requests you&#8217;ll ever need to make, it includes a success and failure function to ensure that users get the proper feedback they need, and you&#8217;ll get a spinning loading image while the request is being processed to boot.  Throw on top of that the fact that it&#8217;s extremely easy to use, and I&#8217;d say you have something that&#8217;s pretty damned close to perfect, at least in my book.  Here is the template:</p>
<pre>$.ajax({
  type: 'POST',
  url: '<strong>http://kyleschaeffer.com/feed/</strong>',
  data: { <strong>postVar1: 'theValue1', postVar2: 'theValue2'</strong> },
  beforeSend:function(){
    // this is where we append a loading image
    $('#ajax-panel').html('&lt;div class=&quot;loading&quot;&gt;&lt;img src=&quot;<strong>/images/loading.gif</strong>&quot; alt=&quot;Loading...&quot; /&gt;&lt;/div&gt;');
  },
  success:function(data){
    // successful request; do something with the data
    $('#ajax-panel').empty();
    $(data).find('item').each(function(i){
      $('#ajax-panel').append('<strong>&lt;h4&gt;' + $(this).find('title').text() + '&lt;/h4&gt;&lt;p&gt;' + $(this).find('link').text() + '&lt;/p&gt;</strong>');
    });
  },
  error:function(){
    // failed request; give feedback to user
    $('#ajax-panel').html('&lt;p class=&quot;error&quot;&gt;&lt;strong&gt;Oops!&lt;/strong&gt; Try that again in a few moments.&lt;/p&gt;');
  }
});</pre>
<p>In this case, I&#8217;m loading my site&#8217;s RSS feed into a <code>&lt;div/&gt;</code> with an ID of <code>ajax-panel</code>.  What does it look like exactly, you ask?  Let&#8217;s try it out.</p>
<style type="text/css">#ajax-panel { background: #f5f5f5; border: 1px #ddd solid; padding: 20px; margin: 0 0 5px 0; } .loading { padding: 50px 0; text-align: center; }</style>
<div id="ajax-panel"></div>
<div class="ajax-panel-actions">
<input id="load-feed" type="button" value="Load the RSS feed now!" />
<input id="load-feed-fail" type="button" value="Try a FAILED AJAX Request" /></div>
<p><script type="text/javascript" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/04/the-perfect-ajax.js"></script></p>
<h3>Data Types</h3>
<p>We&#8217;re loading an RSS feed in this example, so the AJAX function is designed to interpret XML data. jQuery AJAX also understands a number of other data formats, such as HTML, plain text, and even JSON. Find out more about data types at the <a href="http://api.jquery.com/jQuery.ajax/">jQuery AJAX documentation page</a>.</p>
<h3>Loading Image</h3>
<p>Did you notice the spinning loading image? In the <code>beforeSend</code> function, we&#8217;re appending a loading image to our AJAX panel, and we&#8217;re then taking it out when a request has completed.  If you&#8217;re not already aware, be sure to check out the very handy website, <a href="http://www.ajaxload.info/">Ajaxload</a>.  This site allows you to quickly create <em>spinner</em> images of any size and color. They have an impressive array of bars, circles, flowers, and the like, so all your design needs should be satiated by the array of options they provide.  It&#8217;s always a good idea to include a loading image when working with AJAX requests &mdash; depending on the client&#8217;s connection speed and a number of other variables, the time it takes to complete a request can vary.  Don&#8217;t assume it will be lickity-split and lightning fast every time.  Give your users some feedback to let them know that you&#8217;re working on it.</p>
<h3>POST Data</h3>
<p>You may have noticed that we&#8217;re using <code>POST</code> as the request type.  <code>POST</code> requests works just like <code>GET</code> requests, except you get the added flexibility to also send data and other variables along with your request.  We sent some dummy data that isn&#8217;t used by the RSS feed (<code>data: { postVar1: 'theValue1', postVar2: 'theValue2' }</code>), so feel free to change or omit this line of code in order to customize your AJAX request function. As an example, you could send a variable like <code>userId: '45'</code> to a custom PHP script that in return sends you information about a particular user. The possibilities are endless!</p>
<h2>Remember the Search</h2>
<p>Take what you&#8217;ve learned and venture into the wide world of web development armed with the knowledge you now possess.  Destroy post-backs wherever they may live, and always remember that Google hates AJAX and won&#8217;t interpret anything on your page that&#8217;s loaded via script!  Good luck, and happy styling.</p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/best-practices/the-perfect-jquery-ajax-request/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Create a Lightbox with jQuery and CSS</title>
		<link>http://kyleschaeffer.com/tutorials/lightbox-jquery-css/</link>
		<comments>http://kyleschaeffer.com/tutorials/lightbox-jquery-css/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 21:37:05 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kyleschaeffer.com/?p=488</guid>
		<description><![CDATA[The &#8220;lightbox&#8221; is a unique and useful design tool when used properly. It allows designers to present information that is totally independent from the site theme, and it is especially useful when displaying information that is loaded via AJAX requests &#8230; <a href="http://kyleschaeffer.com/tutorials/lightbox-jquery-css/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The &#8220;lightbox&#8221; is a unique and useful design tool when used properly. It allows designers to present information that is totally independent from the site theme, and it is especially useful when displaying information that is loaded via AJAX requests (often negating the need for additional post-backs on your pages). There are countless ways to implement lightbox functionality into your site, and almost every option I&#8217;ve ever seen is weighed down by extraneous functionality or useless transition animations. It&#8217;s quite easy to create your own lightboxes with minimal effort. This tutorial can serve as a quick and easy template to get you started.<span id="more-488"></span></p>
<h2>The CSS Style</h2>
<p>There are <em>two</em> elements you&#8217;ll have to implement into your design in order to create a lightbox — CSS and Javascript. We&#8217;ll take care of the CSS style first, as it&#8217;s the most simple to implement. On your page or in an attached style sheet, add the following CSS styles:</p>
<pre>#lightbox {
	position: absolute;
	top: 0;
	left: 50%;
	width: 500px;
	margin-left: -250px;
	background: #fff;
	z-index: 1001;
	display: none;
}
#lightbox-shadow {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: #000;
	filter: alpha(opacity=75);
	-moz-opacity: 0.75;
	-khtml-opacity: 0.75;
	opacity: 0.75;
	z-index: 1000;
	display: none;
}</pre>
<p><strong>What we just did:</strong> we established two styles. One style is for the lightbox that actually appears on the page (<code>#lightbox</code>). The second style is for lightbox background (<code>#lightbox-shadow</code>). We have made this background dark and semi-transparent in order to dim the site&#8217;s content as it appears behind the lightbox.</p>
<h2>The jQuery Script</h2>
<p>The real work is done via our simple jQuery script. We have two JavaScript functions that will handle displaying and hiding our lightbox. First, make sure you have attached the jQuery library to your page:</p>
<pre>&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;</pre>
<p>Now, in an attached <code>.js</code> file, add the following script code.</p>
<pre>/****************************************
	Barebones Lightbox Template
	by Kyle Schaeffer
	kyleschaeffer.com
	* requires jQuery
****************************************/

// display the lightbox
function lightbox(insertContent, ajaxContentUrl){

	// add lightbox/shadow &lt;div/&gt;'s if not previously added
	if($('#lightbox').size() == 0){
		var theLightbox = $('&lt;div id=&quot;lightbox&quot;/&gt;');
		var theShadow = $('&lt;div id=&quot;lightbox-shadow&quot;/&gt;');
		$(theShadow).click(function(e){
			closeLightbox();
		});
		$('body').append(theShadow);
		$('body').append(theLightbox);
	}

	// remove any previously added content
	$('#lightbox').empty();

	// insert HTML content
	if(insertContent != null){
		$('#lightbox').append(insertContent);
	}

	// insert AJAX content
	if(ajaxContentUrl != null){
		// temporarily add a &quot;Loading...&quot; message in the lightbox
		$('#lightbox').append('&lt;p class=&quot;loading&quot;&gt;Loading...&lt;/p&gt;');

		// request AJAX content
		$.ajax({
			type: 'GET',
			url: ajaxContentUrl,
			success:function(data){
				// remove &quot;Loading...&quot; message and append AJAX content
				$('#lightbox').empty();
				$('#lightbox').append(data);
			},
			error:function(){
				alert('AJAX Failure!');
			}
		});
	}

	// move the lightbox to the current window top + 100px
	$('#lightbox').css('top', $(window).scrollTop() + 100 + 'px');

	// display the lightbox
	$('#lightbox').show();
	$('#lightbox-shadow').show();

}

// close the lightbox
function closeLightbox(){

	// hide lightbox and shadow &lt;div/&gt;'s
	$('#lightbox').hide();
	$('#lightbox-shadow').hide();

	// remove contents of lightbox in case a video or other content is actively playing
	$('#lightbox').empty();
}</pre>
<link rel="stylesheet" type="text/css" href="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/03/lightbox.css" />
<style type="text/css">#lightbox-shadow { position: fixed; } #lightbox { font-size: 2em; padding: 20px; margin-left: -270px; }</style>
<p><script type="text/javascript" src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/03/lightbox.js"></script><br />
<h2>Ready for Lightboxing</h2>
<p>Once you have the CSS and script into place, you can call your new <code>lightbox();</code> function from anywhere within your design. It&#8217;s as easy as calling the lightbox from an <code>anchor</code> tag:</p>
<pre>&lt;a href=&quot;javascript:lightbox('Hello!');&quot;&gt;Show me the lightbox&lt;/a&gt;</pre>
<p>Remember, clicking anywhere on the &#8220;shadow&#8221; <code>&lt;div/&gt;</code> will hide the lightbox &mdash; you could easily add a &#8220;close&#8221; button to your lightbox by connecting it to the <code>closeLightbox();</code> JavaScript function.</p>
<p>Similarly, you can insert HTML (or even a jQuery DOM object) into the lightbox. Like so:</p>
<pre>&lt;a href=&quot;javascript:lightbox('&lt;p&gt;&lt;strong&gt;Rich&lt;/strong&gt; content works too!&lt;/p&gt;');&quot;&gt;Show me the lightbox&lt;/a&gt;</pre>
<p>Finally, you can even use this simple lightbox function to insert AJAX content. Please keep in mind that my JavaScript function simply inserts the entire result into the <code>#lightbox</code> element &mdash; if you&#8217;re trying to request a website or HTML page, you&#8217;ll probably have to remove the <code>&lt;html/&gt;</code> and <code>&lt;body/&gt;</code> tags before inserting content into your lightbox window, else the lightbox would simply disappear. An AJAX lightbox request looks a little like this:</p>
<pre>&lt;a href=&quot;javascript:lightbox(null, 'http://foo.com/readme.txt');&quot;&gt;Show me the lightbox&lt;/a&gt;</pre>
<h2>The Demo</h2>
<ul>
<li><strong>Try it out:</strong> <a href="javascript:lightbox('How elegantly simple! This is a barebones lightbox if I ever saw one. Click on the dark shaded background to close the lightbox.');">Show me the lightbox</a></li>
<li><strong>Let&#8217;s load some AJAX content:</strong> <a href="javascript:lightbox(null, 'http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/03/lightbox.css');">Load the CSS file for this tutorial into a lightbox</a></li>
</ul>
<p>If you&#8217;re on a fast connection, you may not notice, but the AJAX link actually reads &#8220;Loading&#8230;&#8221; in the lightbox a split-second before the content actually appears.  This can be useful to give users feedback while the AJAX request is processing. Please note that I&#8217;ve added a bit of styling to my demo (namely padding on the lightbox to make it appear less cluttered).</p>
<h2>Make it Shine</h2>
<p>You&#8217;ll probably want to modify the CSS and other elements of this lightbox in order to suit your site&#8217;s design and style. If you&#8217;re working with a lot of AJAX content, you may want to even replace the temporary <code>loading</code> element with an animated spinner image, or something of the like.</p>
<p>To help you get started, you can download the CSS and JavaScript referenced in this tutorial here:</p>
<ul>
<li><a href="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/03/lightbox.css">lightbox.css</a></li>
<li><a href="http://kyleschaeffer.com/wordpress/wp-content/uploads/2010/03/lightbox.js">lightbox.js</a></li>
</ul>
<p>Good luck, and happy styling!</p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/tutorials/lightbox-jquery-css/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>IE Corner Inserts via jQuery</title>
		<link>http://kyleschaeffer.com/tutorials/ie-corner-inserts-via-jquery/</link>
		<comments>http://kyleschaeffer.com/tutorials/ie-corner-inserts-via-jquery/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 22:51:43 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Corners]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kyleschaeffer.com/?p=422</guid>
		<description><![CDATA[I recently had a client whose design demanded rounded corners in a lot of different areas of their site. As I looked through the design documentation, the variety and color of these rounded widgets really started to add up. I &#8230; <a href="http://kyleschaeffer.com/tutorials/ie-corner-inserts-via-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently had a client whose design demanded rounded corners in a lot of different areas of their site. As I looked through the design documentation, the variety and color of these rounded widgets really started to add up. I quickly decided that <a href="http://www.kyleschaeffer.com/best-practices/rounded-corners-in-mozilla-and-safari/">pure CSS corners</a> were the best choice for their design. Most users can utilize <code>border-radius</code> to apply the rounded effect without any overhead (the browser does the work), and the remaining users can be handled by a quick and easy bit of jQuery.<span id="more-422"></span></p>
<h2>For the (better) browsers&#8230;</h2>
<p>It&#8217;s easy to add corners to your design in most browsers. In a previous post, I talked about the different ways to apply CSS corners within your design. Here&#8217;s what I used for this particular client.</p>
<div id="the-css">
<pre>.corners {
	-moz-border-radius: 12px;
	-webkit-border-radius: 12px;
}
.noTL {
	-moz-border-radius-topleft: 0;
	-webkit-border-top-left-radius: 0;
}
.noTR {
	-moz-border-radius-topright: 0;
	-webkit-border-top-right-radius: 0;
}
.noBL {
	-moz-border-radius-bottomleft: 0;
	-webkit-border-bottom-left-radius: 0;
}
.noBR {
	-moz-border-radius-bottomright: 0;
	-webkit-border-bottom-right-radius: 0;
}</pre>
</div>
<p>This made it extremely easy to add corners to the elements in my design. In most cases, I could simply add <code>&lt;div class=&quot;myDivClass <strong>corners</strong>&quot;/&gt;</code>, and the CSS does the rest. If I don&#8217;t want a rounded edge on a particular corner, I can just add <code>noTR</code>, <code>noBL</code>, etc. to my class list. Easy.</p>
<h2>For the other (not-so-better) browser&#8230;</h2>
<p><strong>Disclaimer:</strong> this really doesn&#8217;t do anything entirely too amazing. It&#8217;s not auto-magically generating corner images, and it&#8217;s not inserting a ton of HTML to simulate corner images (I just hate when scripts do that). This is a script I have been using for a while to add corners for IE users; basically, it builds a custom image path for each style of widget in your design marked with the <code>corners</code> CSS class. For each corners widget that my script finds, it will trace up through your HTML until it finds a parent element with a <code>background-color</code>. It then creates four <code>&lt;div/&gt;</code> tags inside your widget and positions them at the outer corners of the widget. The background-image for these <code>&lt;div/&gt;</code> tags is set to something like <strong>corners-12-ffffff.png</strong> or <strong>corners-12-ffaa10-border</strong> (if your widget has a border-width associated with it). The <code>12</code> is the radius of your corner, and <code>ffffff</code> is the background color that appears behind your widget. You&#8217;ll have to create the images yourself (and put them in the right place), but my script will handle inserting the HTML and CSS in the right place. If you create the images <a href="http://www.kyleschaeffer.com/best-practices/reusable-transparent-css-rounded-corners/">a little like this</a>, then you&#8217;ll find that your IE corners will be in place in no time at all.</p>
<p>It&#8217;s certainly not ground-breaking stuff, but it makes it very easy to reduce the overhead in your design for most users. In addition, the script is fairly small, and you&#8217;ll find it&#8217;s really not much overhead for IE users as well. Here&#8217;s how to add it to your site:</p>
<ol>
<li>You&#8217;ll need <a href="http://jquery.com/">jQuery 1.3.2</a> or later linked to your page</li>
<li>Add the <a href="#the-css">CSS (above)</a> to your style sheet. This takes care of everyone except for IE.</li>
<li>Create a new JavaScript file with the following contents:
<pre>/*******************************************

	IE Corner Inserts v1.0

	by Kyle Schaeffer

http://www.kyleschaeffer.com

	* requires jQuery 1.3.2 or later

*******************************************/

// change this path to match the path to your corner image files
var cornerImagePathPrefix = '/designImages/';

// default file extension for corner images is PNG
var cornerImageFileExtension = '.png';

// default corner radius
var cornerRadius = '12';

$(document).ready(function(){
	$('.corners').each(function(i){
		var parentDiv = $(this).parent();
		var cornerColor = null;

		// find parent background color (trace up through DOM)
		while(cornerColor == null &amp;&amp; parentDiv != null){
			if($(parentDiv).css('background-color') != 'transparent'){
				cornerColor = $(parentDiv).css('background-color');
				cornerColor = cornerColor.substr(1);
			}
			else if($(parentDiv).hasClass('bodyWrapper')){
				cornerColor = '6f98ae';
			}
			else{
				parentDiv = $(parentDiv).parent().get(0);
			}
		}

		// apply corner &lt;div/&gt; tags to elements
		if(cornerColor != null){
			// find border offsets
			var offsetTop = parseInt($(this).css('border-top-width')) || 0;
			var offsetRight = parseInt($(this).css('border-right-width')) || 0;
			var offsetBottom = parseInt($(this).css('border-bottom-width')) || 0;
			var offsetLeft = parseInt($(this).css('border-left-width')) || 0;

			// add &quot;-border&quot; to any image path (for border-only corners)
			var borderImageText = '';
			if(offsetTop &gt; 0 &amp;&amp; offsetRight &gt; 0 &amp;&amp; offsetBottom &gt; 0 &amp;&amp; offsetLeft &gt; 0){
				borderImageText = '-border';
			}

			// change color values like &quot;#fff&quot; to &quot;#ffffff&quot;
			if(cornerColor.length == 3){
				cornerColor += cornerColor;
			}

			// set position to relative (if not already set)
			if($(this).css('position') != 'absolute' &amp;&amp; $(this).css('position') != 'relative'){
				$(this).css('position','relative');
			}

			// corner image filename
			var cornerImage = 'corners-' + cornerRadius + '-' + cornerColor + borderImageText + cornerImageFileExtension;

			// add corners
			if(!$(this).hasClass('noTL')){
				var cornerDiv = $('&lt;div style=&quot;position: absolute; height: ' + cornerRadius + 'px; width: ' + cornerRadius + 'px; background: url(' + cornerImagePathPrefix + cornerImage + ') top left no-repeat;&quot;/&gt;');
				$(cornerDiv).css('top',(offsetTop * -1) + 'px');
				$(cornerDiv).css('left',(offsetLeft * -1) + 'px');
				$(this).append(cornerDiv);
			}
			if(!$(this).hasClass('noTR')){
				var cornerDiv = $('&lt;div style=&quot;position: absolute; height: ' + cornerRadius + 'px; width: ' + cornerRadius + 'px; background: url(' + cornerImagePathPrefix + cornerImage + ') top right no-repeat;&quot;/&gt;');
				$(cornerDiv).css('top',(offsetTop * -1) + 'px');
				$(cornerDiv).css('right',(offsetRight * -1) + 'px');
				$(this).append(cornerDiv);
			}
			if(!$(this).hasClass('noBL')){
				var cornerDiv = $('&lt;div style=&quot;position: absolute; height: ' + cornerRadius + 'px; width: ' + cornerRadius + 'px; background: url(' + cornerImagePathPrefix + cornerImage + ') bottom left no-repeat;&quot;/&gt;');
				$(cornerDiv).css('bottom',(offsetBottom * -1) + 'px');
				$(cornerDiv).css('left',(offsetLeft * -1) + 'px');
				$(this).append(cornerDiv);
			}
			if(!$(this).hasClass('noBR')){
				var cornerDiv = $('&lt;div style=&quot;position: absolute; height: ' + cornerRadius + 'px; width: ' + cornerRadius + 'px; background: url(' + cornerImagePathPrefix + cornerImage + ') bottom right no-repeat;&quot;/&gt;');
				$(cornerDiv).css('bottom',(offsetBottom * -1) + 'px');
				$(cornerDiv).css('right',(offsetRight * -1) + 'px');
				$(this).append(cornerDiv);
			}
		}
	});
});

String.prototype.endsWith = function(str){
	return(this.match(str+&quot;$&quot;)==str);
}</pre>
</li>
<li>Take a look at the configuration variables near the top of the script and update if needed</li>
<li>Link to your new JS file, but make sure only IE users are loading the file:
<pre>&lt;!--[if lte IE 8]&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;/path/to/IE-Corner-Inserts.js&quot;&gt;&lt;/script&gt;
&lt;![endif]--&gt;</pre>
</li>
<li>Create your corner images and place them in the correct path on your web server. I recently made available <a href="http://www.kyleschaeffer.com/best-practices/reusable-transparent-css-rounded-corners/">a corner images Photoshop template</a> if you need help getting started.</li>
</ol>
<p>That&#8217;s it! If all goes well, you should hopefully see image-based rounded corners in Internet Explorer, as well as the more simplistic CSS-powered corners in all other browsers.</p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/tutorials/ie-corner-inserts-via-jquery/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>A Simple jQuery Tabs Template</title>
		<link>http://kyleschaeffer.com/web-controls/simple-jquery-tabs-template/</link>
		<comments>http://kyleschaeffer.com/web-controls/simple-jquery-tabs-template/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 14:47:28 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Web Controls]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tabs]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.kyleschaeffer.com/?p=348</guid>
		<description><![CDATA[I love jQuery; I use it all the time. I also love the great UI controls that come with the jQuery UI library. Unfortunately, I&#8217;ve found that a lot of these controls can be a little heavy in terms of &#8230; <a href="http://kyleschaeffer.com/web-controls/simple-jquery-tabs-template/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I love <a href="http://jquery.com/">jQuery</a>; I use it all the time. I also love the great UI controls that come with the <a href="http://jqueryui.com/">jQuery UI</a> library. Unfortunately, I&#8217;ve found that a lot of these controls can be a little heavy in terms of required JS/CSS files that your clients will have to download in order to use these controls. Being the minimalist that I am, I really want to drop a small amount of CSS and HTML into my site and quickly get myself up and running with a tab structure that&#8217;s both flexible and accessible.<span id="more-348"></span></p>
<h2>Adding jQuery is Easy</h2>
<p>You&#8217;ll need to include a few JavaScript libraries in order to use jQuery tabs at all. These libraries can be somewhat cumbersome for users on slower connections to download, and it&#8217;s definitely the major disadvantage of using a library like jQuery to add this sort of functionality to your site. The best things we can do in this case is try to minimize the effect of serving this JS library to our clients. First of all, I would recommend always using the &#8220;minified&#8221; version of the jQuery script. It&#8217;s much smaller in size than the standard version, which obviously will reduce the amount of time needed to load your site when users first visit it. The only difference between the minified and the standard library is that the good folks at jQuery have removed all sorts of characters in the document, which makes it less readable, but makes the file size much smaller. If you want to delve into the depths of the jQuery library, you can download the standard version and take a gander offline, but don&#8217;t force your users to download the full version if you don&#8217;t have to.</p>
<p>Additionally, Google (<a href="http://code.google.com/apis/ajaxlibs/documentation/#jquery">here</a>) and Microsoft (<a href="http://www.asp.net/ajax/CDN/">here</a>) have both set up distribution networks to serve these libraries to your users. Don&#8217;t waste bandwidth and your clients&#8217; time by forcing users to download these libraries from your servers! Chances are, Google/Microsoft have the resources to serve these files to you users faster and more reliably than you can, so please utilize these free services. Additionally, users have a much greater chance of already having a cached version of these files when you used the shared location. Sweet!</p>
<p>Add the library references to your <code>&lt;head/&gt;</code> to get started.</p>
<pre>&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://jqueryui.com/latest/ui/ui.tabs.js&quot;&gt;&lt;/script&gt;</pre>
<h2>The Tabs Markup</h2>
<p>What&#8217;s so wonderfully beautiful about jQuery tabs is the simplicity of the HTML. Even more, users who aren&#8217;t using JavaScript will visit your site and see a perfectly formatted and functioning page. Use this as a template for your tabs HTML:</p>
<pre>&lt;div class=&quot;ui-tabs&quot;&gt;
	&lt;ul class=&quot;ui-tabs-nav&quot;&gt;
		&lt;li&gt;&lt;a href=&quot;#tabs-1&quot;&gt;Tab One&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#tabs-2&quot;&gt;Tab Two&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#tabs-3&quot;&gt;Tab Three&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;div id=&quot;tabs-1&quot; class=&quot;ui-tabs-panel&quot;&gt;
		&lt;p&gt;Content one.&lt;/p&gt;
	&lt;/div&gt;
	&lt;div id=&quot;tabs-2&quot; class=&quot;ui-tabs-panel&quot;&gt;
		&lt;p&gt;Content two.&lt;/p&gt;
	&lt;/div&gt;
	&lt;div id=&quot;tabs-3&quot; class=&quot;ui-tabs-panel&quot;&gt;
		&lt;p&gt;Content three.&lt;/p&gt;
	&lt;/div&gt;
&lt;/div&gt;</pre>
<h2>Add Some Style</h2>
<p>This is where my template really starts to differ from jQuery&#8217;s version. The CSS jQuery would have you use is not simple enough for me, so I created my own version of the CSS that will give you a very basic frame onto which you can apply your own design. Here&#8217;s what I like to start with:</p>
<pre>.ui-tabs {
	zoom: 1;
}
.ui-tabs .ui-tabs-nav {
	list-style: none;
	position: relative;
	padding: 0;
	margin: 0;
}
.ui-tabs .ui-tabs-nav li {
	position: relative;
	float: left;
	margin: 0 3px -2px 0;
	padding: 0;
}
.ui-tabs .ui-tabs-nav li a {
	display: block;
	padding: 10px 20px;
	background: #f0f0f0;
	border: 2px #ccc solid;
	border-bottom-color: #ccc;
	outline: none;
}
.ui-tabs .ui-tabs-nav li.ui-tabs-selected a {
	padding: 10px 20px 12px 20px;
	background: #fff;
	border-bottom-style: none;
}
.ui-tabs .ui-tabs-nav li.ui-tabs-selected a,
.ui-tabs .ui-tabs-nav li.ui-state-disabled a,
.ui-tabs .ui-tabs-nav li.ui-state-processing a {
	cursor: default;
}
.ui-tabs .ui-tabs-nav li a,
.ui-tabs.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-selected a {
	cursor: pointer;
}
.ui-tabs .ui-tabs-panel {
	display: block;
	clear: both;
	border: 2px #ccc solid;
	padding: 10px;
}
.ui-tabs .ui-tabs-hide {
	display: none;
}</pre>
<h2>Now Make it Do Something</h2>
<p>Now that you have your tabs there, you&#8217;ll have to initialize them with a simple jQuery statement in order for them to work. Just add this line of JavaScript anywhere on your page.</p>
<pre>&lt;script type=&quot;text/javascript&quot;&gt;
	$(document).ready(function(){
		$(&quot;.ui-tabs&quot;).tabs();
	});
&lt;/script&gt;</pre>
<h2>The Result</h2>
<p>Once you&#8217;ve added each of these elements to your page, you should get a very simple tab structure that awaits your styling genius. Just modify the CSS to apply your own design!</p>
<div class="ui-tabs">
<ul class="ui-tabs-nav">
<li><a href="#tabs-1">Tab One</a></li>
<li><a href="#tabs-2">Tab Two</a></li>
<li><a href="#tabs-3">Tab Three</a></li>
</ul>
<div id="tabs-1" class="ui-tabs-panel">
<p>Content one.</p>
</div>
<div id="tabs-2" class="ui-tabs-panel">
<p>Content two.</p>
</div>
<div id="tabs-3" class="ui-tabs-panel">
<p>Content three.</p>
</div>
</div>
<p><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script><script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.tabs.js"></script><script type="text/javascript">$(document).ready(function(){$(".ui-tabs").tabs();});</script><br />
<style type="text/css">#content .ui-tabs { zoom: 1; }
#content .ui-tabs .ui-tabs-nav { list-style: none; position: relative; padding: 0; margin: 0; }
#content .ui-tabs .ui-tabs-nav li { list-style: none; position: relative; float: left; margin: 0 3px -2px 0; padding: 0; }
#content .ui-tabs .ui-tabs-nav li a { display: block; padding: 10px 20px; background: #f0f0f0; border: 2px #ccc solid; border-bottom-color: #ccc; outline: none; }
#content .ui-tabs .ui-tabs-nav li.ui-tabs-selected a { padding: 10px 20px 12px 20px; background: #fff; border-bottom-style: none; }
#content .ui-tabs .ui-tabs-nav li.ui-tabs-selected a, .ui-tabs .ui-tabs-nav li.ui-state-disabled a, .ui-tabs .ui-tabs-nav li.ui-state-processing a { cursor: default; }
#content .ui-tabs .ui-tabs-nav li a, .ui-tabs.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-selected a { cursor: pointer; }
#content .ui-tabs .ui-tabs-panel { display: block; clear: both; border: 2px #ccc solid; padding: 10px; }
#content .ui-tabs .ui-tabs-hide { display: none; }</style>
<p>Now you&#8217;ve got it. Good luck, and happy styling.</p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/web-controls/simple-jquery-tabs-template/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Create a DHTML Tab Strip</title>
		<link>http://kyleschaeffer.com/tutorials/create-a-dhtml-tab-strip/</link>
		<comments>http://kyleschaeffer.com/tutorials/create-a-dhtml-tab-strip/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 18:18:23 +0000</pubDate>
		<dc:creator>Kyle</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Controls]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tabs]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://www.kyleschaeffer.com/?p=107</guid>
		<description><![CDATA[Tab strips are commonplace throughout the web, and they&#8217;re utilized in a wide variety of ways, such as in site navigation or form wizards. Organizing links in a tabbed format can add quite a bit of style and functionality to &#8230; <a href="http://kyleschaeffer.com/tutorials/create-a-dhtml-tab-strip/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Tab strips are commonplace throughout the web, and they&#8217;re utilized in a wide variety of ways, such as in site navigation or form wizards.  Organizing links in a tabbed format can add quite a bit of style and functionality to your site, as many visitors are already familiar and comfortable with using tabs on other websites and even on other platforms such as their operating system.  This tutorial shows you how to create a simple DHTML tab strip using HTML, CSS, and a small bit of JavaScript.<span id="more-107"></span></p>
<p>When I use the term &#8220;DHTML,&#8221; I am referring to &#8220;Dynamic HTML.&#8221;  This is an endearing term that many web designers use to describe the fusion of HTML with other web technologies, such as JavaScript and CSS.  By using various technologies in tandem, we can create dynamic controls that allow website visitors to interact with content directly on the page without the need to refresh the site with every subsequent click.</p>
<h2>The HTML</h2>
<p>As you will soon see, the tab strip is a prime example of a DHTML control.  Before we delve into every aspect of the tab strip, let&#8217;s first start with the HTML:</p>
<pre>&lt;div class=&quot;tabStrip&quot;&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href=&quot;javascript:openTab(1);&quot; class=&quot;tabLinkActive&quot; id=&quot;tabLink1&quot;&gt;TabOne&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;javascript:openTab(2);&quot; class=&quot;tabLink&quot; id=&quot;tabLink2&quot;&gt;TabTwo&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;javascript:openTab(3);&quot; class=&quot;tabLink&quot; id=&quot;tabLink3&quot;&gt;TabThree&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;tabContentActive&quot; id=&quot;tabContent1&quot;&gt;
	This is sample tab content (1).
&lt;/div&gt;
&lt;div class=&quot;tabContent&quot; id=&quot;tabContent2&quot;&gt;
	This is sample tab content (2).
&lt;/div&gt;
&lt;div class=&quot;tabContent&quot; id=&quot;tabContent3&quot;&gt;
	This is sample tab content (3).
&lt;/div&gt;</pre>
<p>The HTML is relatively simple. We are using an unordered list (<code>&lt;ul/&gt;</code>) for our tabs, and we are using <code>&lt;div/&gt;</code> tags for our tab content. As you can see, I am giving a unique <code>id</code> attribute to each tab link and to each tab content <code>&lt;div/&gt;</code>.  This is important, as we&#8217;ll need unique <code>id</code>&#8216;s in order to access these elements with JavaScript.</p>
<h2>The JavaScript</h2>
<p>We are using only one small JavaScript function for the tab control.  Here is the code:</p>
<pre>&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;
	var activeTab = 1;
	function openTab(tabId) {
		// reset old tab and content
		document.getElementById(&quot;tabLink&quot;+activeTab).className = &quot;tabLink&quot;;
		document.getElementById(&quot;tabContent&quot;+activeTab).className = &quot;tabContent&quot;;
		// set new tab and content
		document.getElementById(&quot;tabLink&quot;+tabId).className = &quot;tabLinkActive&quot;;
		document.getElementById(&quot;tabContent&quot;+tabId).className = &quot;tabContentActive&quot;;
		activeTab = tabId;
	}
&lt;/script&gt;</pre>
<h2>The CSS:</h2>
<p>This CSS is a very basic example of what you can do to style your tabs. You can add colors, gradients, and background images to give the control even more design flare.</p>
<pre>.tabStrip ul {
	margin: 0;
	padding: 0;
	list-style-type: none;
}
.tabStrip li {
	margin: 0 2px 0 0;
	list-style-type: none;
	float: left;
}
.tabLink {
	display: block;
	text-decoration: none;
	padding: 5px;
	background: #e8e8e8;
	border: #dadada solid;
	border-width: 1px 1px 0 1px;
	color: #8a8a8a;
}
.tabLinkActive {
	display: block;
	text-decoration: none;
	padding: 5px;
	background: #e0e0e0;
	border: #c0c0c0 solid;
	border-width: 1px 1px 0 1px;
	color: #0066ff;
}
.tabContent {
	display: none;
}
.tabContentActive {
	display: block;
	clear: both;
	background: #f0f0f0;
	border: 1px #dedede solid;
	padding: 10px;
}</pre>
<h2>The Result:</h2>
<p>In true DHTML fashion, we have combined HTML, JavaScript, and CSS to create a fully dynamic user control that can appear anywhere on the web. I have taken the fundamentals learned in this tutorial and have created a more visually appealing example of this code.  Click on the image below to see the demo.</p>
<p><a href="http://www.kyleschaeffer.com/tabstrip/"><img src="http://kyleschaeffer.com/wordpress/wp-content/uploads/2008/11/tabs.jpg" alt="Tab Strip Demo" /></a></p>
<p>Note that the demo also utilizes Karate Corners to create rounded edges on the tabs.  <a href="http://www.kyleschaeffer.com/tutorials/karate-corners-easy-rounded-corners-xhtml-no-script/">Learn more about Karate corners here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kyleschaeffer.com/tutorials/create-a-dhtml-tab-strip/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

