Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #71 from LearnBoost/tabs-refactor

Tabs refactor
  • Loading branch information...
commit 94ce27001d218208eac0f9af998d8775c0513ad4 2 parents a05d0c7 + bc178a5
@dhg authored
Showing with 27 additions and 27 deletions.
  1. +27 −27 javascripts/tabs.js
View
54 javascripts/tabs.js
@@ -1,29 +1,29 @@
-/*
-* Skeleton V1.1
-* Copyright 2011, Dave Gamache
-* www.getskeleton.com
-* Free to use under the MIT license.
-* http://www.opensource.org/licenses/mit-license.php
-* 8/17/2011
-*/
-
-
-$('body').on('click', 'ul.tabs > li > a', function(e) {
-
- //Get Location of tab's content
- var contentLocation = $(this).attr('href');
-
- //Let go if not a hashed one
- if(contentLocation.charAt(0)=="#") {
-
- e.preventDefault();
-
- //Make Tab Active
- $(this).parent().siblings().children('a').removeClass('active');
- $(this).addClass('active');
-
- //Show Tab Content & add active class
- $(contentLocation).show().addClass('active').siblings().hide().removeClass('active');
+/**
+ * Skeleton V1.1
+ * Copyright 2011, Dave Gamache
+ * www.getskeleton.com
+ * Free to use under the MIT license.
+ * http://www.opensource.org/licenses/mit-license.php
+ * 8/17/2011
+ */
+
+(function ($) {
+ // hash change handler
+ function hashchange () {
+ var hash = window.location.hash
+ , el = $('ul.tabs [href*="' + hash + '"]')
+ , content = $(hash)
+
+ if (el.length && !el.hasClass('active') && content.length) {
+ el.closest('.tabs').find('.active').removeClass('active');
+ el.addClass('active');
+ content.show().addClass('active').siblings().hide().removeClass('active');
}
-});
+ }
+
+ // listen on event and fire right away
+ $(window).on('hashchange.skeleton', hashchange);
+ hashchange();
+ $(hashchange);
+})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.