Created
October 4, 2010 09:39
-
-
Save livingston/609456 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Simple tabs with Book-markable urls | |
var handleTabs = (function (tabHandles) { | |
if (!tabHandles || !(/[\s]*hasTabs[\s]*/.test(tabHandles.className))) { | |
return function () {} | |
} | |
var tabHandleParent = $(tabHandles.parentNode), | |
activeClass = 'active', | |
activateTab = function activateTab(tab) { | |
var currentTab = $(tab ? document.getElementById(tab) : tabHandles.getElementsByTagName('a')[0]); | |
if (!currentTab.length) { return } | |
tabHandleParent.find('.' + activeClass).removeClass(activeClass); | |
currentTab.parent().addClass(activeClass); | |
$(document.getElementById(currentTab[0].id + '_content')).addClass(activeClass); | |
}, | |
handleTabs = function handleTabs() { | |
var hash = location.hash, | |
hashString = hash.match(/#\!\/([\S]+)\//), | |
tabName = (hashString && hashString.length == 2) ? hashString[1] : null; | |
if (tabName) { | |
activateTab(tabName); | |
} | |
}; | |
handleTabs(); | |
$(window).bind('hashchange', handleTabs); | |
return handleTabs; | |
}(document.getElementById('tab-handles'))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment