<?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>PoundBangWhack.com &#187; JavaScript Scripts</title>
	<atom:link href="http://www.poundbangwhack.com/category/development/javascript-scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.poundbangwhack.com</link>
	<description>A web development/programming blog providing info, tips, and tricks on programming languages, scripting, Linux, MySQL and more</description>
	<lastBuildDate>Sat, 17 Jul 2010 05:17:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jQuery tabbed content switcher</title>
		<link>http://www.poundbangwhack.com/2010/06/27/jquery-tabbed-content-switcher/</link>
		<comments>http://www.poundbangwhack.com/2010/06/27/jquery-tabbed-content-switcher/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 05:08:13 +0000</pubDate>
		<dc:creator>Mark Stoecker</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[JavaScript Scripts]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Content Switcher]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tabs]]></category>

		<guid isPermaLink="false">http://www.poundbangwhack.com/?p=1304</guid>
		<description><![CDATA[I was working on a new web design <del>last night</del> early this morning I found myself struggling (probably more than I should have been) with creating tabbed content switcher (hover over one element changes the content of another).  I knew <a href="http://jquery.com" target="_blank">the right way to go was jQuery</a>, and I wanted to avoid downloading a plugin as that would likely end up with more code and another HTTP request to the server.  As I was working on the content switcher, I had one of those "Let's try this and see if it works" moments (those tend to work all to often for me).  It turned out that it did half of what I needed, so I removed another line and voila! I had my content switcher.]]></description>
			<content:encoded><![CDATA[<p>Eat your heart out <a href="http://en.wikipedia.org/wiki/Alexander_Fleming" target="_blank">Sir Alexander Fleming</a>!  While my accidental invention of a <strong>jQuery tabbed content switcher</strong> may not be up there with <a href="http://popularemails.com/accidentalinventions.htm">penicillin, the pacemaker, and post-it notes</a>, it sure did wonders for my latest web design project.<br />
<span id="more-1304"></span></p>
<p>I was working on a new web design <del>last night</del> early this morning I found myself struggling (probably more than I should have been) with creating tabbed content switcher (hover over one element changes the content of another).  I knew <a href="http://jquery.com" target="_blank">the right way to go was jQuery</a>, and I wanted to avoid downloading a plugin as that would likely end up with more code and another HTTP request to the server.  As I was working on the content switcher, I had one of those &#8220;Let&#8217;s try this and see what it does&#8221; moments (those tend to work all to often for me).  It turned out that it did half of what I needed, so I removed another line and voila! I had my content switcher.  So without further ado, here it is.</p>
<h3>The Story</h3>
<p>This project was a site I took over from another developer.  My responsibilities were to finish the project and clean things up.  The previous developer went 95 yards, I needed to put the ball in the end zone.  For legal reasons, I can not show a screenshot of the full comp unfortunately. I initially was just going to clean up code and fix validation, CSS, and jQuery.  However, I quickly realized that would end up making it harder.  So I decided to rewrite the HTML and CSS and duplicate the look and feel of the previous version.  An added benefit to rewriting the code my own way, in addition to being more familiar with the code and all the CSS hooks, is that I could focus on reducing code bloat and cut down on the amount of images being used to help deliver a better performing site to the client.  Here is a look at the tabs themselves.  Hovering over each tab changes the content below:</p>
<p><img src="http://www.poundbangwhack.com/wp-content/uploads/tabbed_content.jpg" alt="" title="tabbed_content" width="547" height="197" class="aligncenter size-full wp-image-1307" /></p>
<h3>The HTML</h3>
<p>My first goal was to create the tabs and still make them SEO friendly by having all the content actually in the markup, and not added/removed as needed.  The markup for the tabs are as follows:</p>
<pre name="code" class="html">
     &lt;div id="main_middle">
      &lt;ul>
       &lt;li id="tab-1">&lt;a href="#" class="active_tab">Tab 1&lt;/a>&lt;/li>
       &lt;li id="tab-2">&lt;a href="#">Tab 2&lt;/a>&lt;/li>
       &lt;li id="tab-3">&lt;a href="#">Tab 3&lt;/a>&lt;/li>
       &lt;li id="tab-4">&lt;a href="#">Tab 4&lt;/a>&lt;/li>
       &lt;li id="tab-5">&lt;a href="#">Tab 5&lt;/a>&lt;/li>
      &lt;/ul>
      &lt;p class="active_tab_content">Content 1 - Lorem ipsum dolor sit amet, consectetur adipiscing elit.&lt;/p>
      &lt;p>Content 2 - Mauris ornare suscipit lacus eget lobortis. Vestibulum quis purus metus, sed condimentum magna.&lt;/p>
      &lt;p>Content 3 - Nunc et turpis laoreet mi dapibus pulvinar. Nunc a facilisis mauris. Nulla facilisi. Morbi sed volutpat elit. Cras varius sollicitudin mi at imperdiet.&lt;/p>
      &lt;p>Content 4 - Ut a consectetur quam. Nulla ut consequat metus. Nunc molestie erat sit amet tortor faucibus elementum. Praesent eu luctus nulla.&lt;/p>
      &lt;p>Content 5 - Proin porttitor mattis erat eget ullamcorper. Lorem ipsum dolor sit amet, consectetur adipiscing elit.&lt;/p>
     &lt;/div>
</pre>
<p>As you can see, the HTML is only 14 lines long: a container element, an unordered list, and paragraph elements (one for each tab).  This is a far cry from the 47 lines of HTML with divs nested 3 deep the previous developer was using.  Additionally, the container has an id as well as each tab, plus a class for the active tab and paragraph and that&#8217;s it.  This can be done without the id&#8217;s, I have them in there for <a href="http://www.poundbangwhack.com/2009/05/15/decrease-your-web-site-load-times-using-css-sprites/">CSS sprite</a> functionality.  The active_tab class is not required, again it&#8217;s something I use for my sprites.</p>
<h3>The CSS</h3>
<p>Here is the pertinent CSS to making this work.  I have a bunch extra for my sprites, but that&#8217;s beside the point:</p>
<pre name="code" class="css">
#main_middle ul li {
 display: -moz-inline-stack;
 display: inline-block;
 zoom: 1;
 *display: inline;
 text-align: center;
 vertical-align: text-top;
}

#main_middle ul li a {
 display: block;
 width: 100%;
 height: 100%;
}

#main_middle p {
 background: url(../images/tab_content_bg.png) 50% 0 no-repeat transparent;
 display: none;
}

#main_middle .active_tab_content {
 display: -moz-inline-stack;
 display: inline-block;
 zoom: 1;
 *display: inline;
}

#main_middle ul #tab-2 a { /* Example of Sprite Usage */
 background-position: -95px 0;
}

#main_middle ul #tab-2 .active_tab { /* Example of Sprite Usage  */
 background-position: -95px -79px;
</pre>
<p>The display/zoom lines is for <a href="http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/"  target="_blank">cross-browser inline-block display</a>.  The code for the anchor elements simply sets them to a block the full size of the list item parent.  Next, all paragraph elements are hidden and only the one with the &#8220;active_tab_content&#8221; class is displayed.  The background is set for all the paragraph elements, although I could&#8217;ve just as easily set it for just the display content only.</p>
<p>Here is my sprite so you get the idea of what I&#8217;m doing with that code:<br />
<img src="http://www.poundbangwhack.com/wp-content/uploads/mid_icons.jpg" alt="" title="mid_icons" width="475" height="158" class="aligncenter size-full wp-image-1330" /></p>
<h3>The jQuery</h3>
<p>The biggest problem I was encountering while writing the jQuery was that when the user stops mousing over the tabs, the last tab moused over should remain visible, and not revert back to the &#8220;active_tab&#8221; and &#8220;active_tab_content&#8221; tab.</p>
<pre name="code" class="js">
$(function() {
 $("#main_middle ul li a").each(function(index) {
  $(this).hover(function() {
   $("#main_middle ul li a").each(function() { $(this).removeClass("active_tab"); });
   $("#main_middle p").each(function() { $(this).removeClass("active_tab_content"); });
   $(this).addClass("active_tab");
   $("#main_middle p:eq("+index+")").addClass("active_tab_content");
  });
 });
});
</pre>
<p>The jQuery code loops through each of the anchor elements and assigns a hover function to them.  The first thing this hover function does is loops through all anchors (tabs) and all paragraphs (tab content) and removes the classes.  It then adds the &#8220;active_tab&#8221; class to the current tab and the &#8220;active_tab_content&#8221; class to the respective paragraph.  It does this through the use of indexes.  One each pass through the anchors, the current element index is passed through the function and then used to select the paragraph with the equivalent index via the <a href="http://api.jquery.com/eq-selector/" target="_blank">eq selector.</a>  And that&#8217;s it.  My mistake that I kept running into, was assigning second function to the hover() to activate on mouseout.  This function was removing the classes that were being added.  This was my moment of <del>brilliance</del> luck when I removed that code by chance and everything worked.</p>
<h3><a href="http://www.poundbangwhack.com/scripts_source/tabbed_content_switcher/demo.html">See the code in action here</a></h3>
<p></p>
<p>You can use this code to make as many tabs as you need.  Just make sure you have as many paragraph elements as you do list elements and that the content for list item 1 corresponds with the content for paragraph 1.  I used inline tabs, but this can easily be done with vertical tabs as well, the logic is still the same.  Feel free to copy/use this code for your own purposes.  Share a link to your implementations in the comments below and/or how you would have done this differently.  Comments are welcome and enjoyed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.poundbangwhack.com/2010/06/27/jquery-tabbed-content-switcher/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New GreaseMonkey Script: Highlight your Domain in Search Results</title>
		<link>http://www.poundbangwhack.com/2009/06/17/new-greasemonkey-script-highlight-your-domain-in-search-results/</link>
		<comments>http://www.poundbangwhack.com/2009/06/17/new-greasemonkey-script-highlight-your-domain-in-search-results/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 05:21:35 +0000</pubDate>
		<dc:creator>Mark Stoecker</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[GreaseMonkey Scripts]]></category>
		<category><![CDATA[JavaScript Scripts]]></category>
		<category><![CDATA[Search Engines]]></category>
		<category><![CDATA[Add-Ons]]></category>
		<category><![CDATA[Bing]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[GreaseMonkey]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[SERPs]]></category>
		<category><![CDATA[Yahoo]]></category>

		<guid isPermaLink="false">http://www.poundbangwhack.com/?p=711</guid>
		<description><![CDATA[The concept for my script came from the fact that my Google Webmaster tools either don't report properly, or I'm not understanding them.  One of the features of the Webmaster Tools is to show your site's <strong>Top Search Queries</strong> and your site's ranking.  Well needless to say, when it claims I rank 7 for a specific phrase and I actually rank 146 for that phrase, it's a bit misleading.  The problem is I would search for that phrase and it would take me forever to find my domain in the search results.  

With this GreaseMonkey Script, you set the domain you wish to locate and a highlight color (default is light red) and when you search in Google, Bing, or Yahoo!, results for your website will be highlighted.]]></description>
			<content:encoded><![CDATA[<p>I completed my first <a href="https://addons.mozilla.org/en-US/firefox/addon/748" target="_blank">GreaseMonkey</a> script for public release tonight.  For those who don&#8217;t use it, or have not heard of it, <strong><a href="https://addons.mozilla.org/en-US/firefox/addon/748" target="_blank">GreaseMonkey</a> is a Firefox Add-on that allows users to write or install custom javascripts to alter the way a website functions</strong>.  It is one of Firefox&#8217;s most popular add-ons with over 20 million downloads.  Literally thousands of <a href="http://userscripts.org" target="_blank">GreaseMonkey scripts are available at userscripts.org</a> and new scripts are added constantly.<br />
<span id="more-711"></span><br />
The concept for my script came from the fact that my Google Webmaster tools either don&#8217;t report properly, or I&#8217;m not understanding them.  One of the features of the Webmaster Tools is to show your site&#8217;s <strong>Top Search Queries</strong> and your site&#8217;s ranking.  Well needless to say, when it claims I rank 7 for a specific phrase and I actually rank 146 for that phrase, it&#8217;s a bit misleading.  The problem is I would search for that phrase and it would take me forever to find my domain in the search results.  </p>
<p>With this GreaseMonkey Script, you set the domain you wish to locate and a highlight color (default is light red) and when you search in Google, Bing, or Yahoo!, results for your website will be highlighted.</p>
<p><a href="http://www.poundbangwhack.com/greasemonkey/highlight-domain-in-search-results/">Click here to visit the home page for this script</a><br />
<a href="https://addons.mozilla.org/en-US/firefox/downloads/latest/748/addon-748-latest.xpi">Click here to Install GreaseMonkey</a><br />
<a href="http://www.poundbangwhack.com/scripts_source/greasemonkey/locate_domain_in_search_.user.js" onclick="javascript: pageTracker._trackPageview('/downloads/gm/highlight-domain-in-search');">Click here to Install Script</a><br />
<a href="http://userscripts.org/scripts/show/51837" target="_blank">Click here to visit the UserScripts.org page for this script.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.poundbangwhack.com/2009/06/17/new-greasemonkey-script-highlight-your-domain-in-search-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
