Created
September 26, 2012 04:55
-
-
Save optikalefx/3786163 to your computer and use it in GitHub Desktop.
Gist Tabs by Sean Clark
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
// each gist | |
$(".gist").each(function() { | |
// reference to this | |
var $gist = $(this); | |
// hide all gist file but the first one | |
$gist.find(".gist-file:not(:first)").hide(); | |
// create the gist header | |
var $header = $("<header class='gist-header'><div style='float:right;padding:.5em .5em'>Gist Tabs by Sean Clark</div></header>"); | |
// loop through each of the gist-files | |
$gist.find(".gist-file").each(function() { | |
// get some variables | |
var $block = $(this); | |
var fname = $block.find(".gist-meta a:eq(1)").text(); | |
var $tab = $("<div class='gist-tab'>"+fname+"</div>"); | |
// create event for tab switching | |
$tab.on("click",function() { | |
$gist.find(".gist-file").hide(); | |
$block.show(); | |
}); | |
// add tab to header | |
$header.append($tab); | |
}); | |
// add header to the top of the gist | |
$gist.prepend($header); | |
}); |
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
.gist .gist-tab { | |
float: left; | |
padding: 0.5em 0.8em; | |
margin-right: 1; | |
cursor: pointer; | |
border-right: 1px solid #979797; | |
} | |
.gist .gist-tab:hover { | |
background: #fff; | |
} | |
.gist .gist-header { | |
overflow: hidden; | |
font-size: 85%; | |
color: #666; | |
background: #eaeaea; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment