Last active
December 14, 2015 16:59
-
-
Save trak3r/5118724 to your computer and use it in GitHub Desktop.
This file contains 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
root = exports ? this | |
root.TedTabs ?= {} | |
TedTabs.activateFirstNestedTabRecursively = (href, depth = 1) -> | |
if wrapper = $(document).find(href) | |
# | |
# activate the first nested tab link | |
# | |
if firstTab = wrapper.find("a[data-toggle=\"tab\"]").first() | |
firstTab.tab "show" | |
# | |
# recurse any tab links nested under this tab | |
# | |
if nestedHref = $(firstTab).attr "href" | |
TedTabs.activateFirstNestedTabRecursively nestedHref, 1 + depth | |
TedTabs.deactivateNestedTabsRecursively = (href, depth = 1) -> | |
if wrapper = $(document).find(href) | |
# | |
# deactivate this tab's content | |
# | |
wrapper.removeClass "active" | |
# | |
# deactivate any active nested tab links | |
# | |
wrapper.find("ul.nav-tabs li.active").each (index, element) -> | |
$(element).removeClass "active" | |
# | |
# recurse any tab links nested under this tab | |
# | |
wrapper.find("a[data-toggle=\"tab\"]").each (index, element) -> | |
if nestedHref = $(element).attr "href" | |
TedTabs.deactivateNestedTabsRecursively nestedHref, 1 + depth | |
$(document).ready -> | |
$("a[data-toggle=\"tab\"]").on "shown", (e) -> | |
if formerTab = $(e.relatedTarget) | |
if formerHref = formerTab.attr "href" | |
TedTabs.deactivateNestedTabsRecursively formerHref | |
if newHref = $(e.target).attr "href" | |
TedTabs.activateFirstNestedTabRecursively(newHref) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment