JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
// min screen width should be 950px
.tournament
html, body, .tournament
height: 100%
font-family: sans-serif
font-size: 10px
.hidden-bracket
display: none !important
.bracket
position: relative
display: flex
height: 100%
padding-top: 38px
&:before
position: absolute
content: ""
width: 50%
height: 2px
top: 38px
left: 50%
transform: translateX(-50%)
background-color: black
li
position: relative
width: 50%
flex: 1
height: 100%
padding-top: 8px
/* border: 1px solid black */
text-align: center
&:before
position: absolute
content: ""
width: 2px
height: 9px
top: 0
left: 50%
transform: translateX(-50%)
background-color: black
&.winner
position: absolute
top: 0
left: -1px
height: 30px
width: 100%
&:before
top: 30px
var $tournament = $('.tournament'),
$bracket = $('<ul class="bracket"><li></li><li></li></ul>');
var participants = ['Adam', 'Matt', 'Evan', 'Abby', 'Heather', 'Christina', 'Ryan', 'Tyler', 'Steve', 'Steph', 'Jenna', 'Derek', 'Mike', 'Sam'];
function buildBracket($el, p1, p2) {
if(!p1 && !p2) {
$el.append($bracket.clone());
}
}
buildBracket($tournament);
var level = 0,
section = 0,
$brackets,
$previousBrackets;
while(level < 4) {
$brackets = $('.bracket');
$brackets = $brackets.filter(function(i, el) {
if($previousBrackets) {
if($.inArray(el, $previousBrackets) >= 0) {
return false;
}
}
return true;
});
if(!$previousBrackets) {
$previousBrackets = $brackets;
}
else {
$previousBrackets = $.merge($previousBrackets, $brackets);
}
$brackets.each(function() {
$(this).find('li:empty').each(function() {
buildBracket($(this));
});
});
level++;
}
function getRivals() {
var p1i = Math.floor(participants.length * Math.random()),
p1 = participants[p1i];
participants.splice(p1i, 1);
var p2i = Math.floor(participants.length * Math.random()),
p2 = participants[p2i];
participants.splice(p2i, 1);
return [p1, p2];
}
function cleanUp() {
var $brackets = $('.bracket'),
removed = false;
for(var i = 0; i < $brackets.length; i++) {
// break before there aren't enough spots
if($('li:empty').length === participants.length) break;
var empty = true;
$brackets.eq(i).find('li').each(function() {
if(!$(this).is(':empty')) {
empty = false;
}
});
if(empty) {
$brackets.eq(i).remove();
removed = true;
}
}
return removed;
}
// just do it over and over
while(cleanUp()) { }
var $empty = $('li:empty');
for(var i = 0; i < participants.length; i++) {
$empty.eq(i).html('<button>' + participants[i] + '</button>');
}
function changeToButtons() {
$('.bracket').each(function() {
var $winner = $(this).children('.winner');
if($winner.length === 0) {
var $winners = $(this).children('li').children('ul').children('.winner');
if($winners.length === 2) {
$winners.each(function() {
$(this).html('<button class="winner">' + $(this).text() + '</button>');
});
}
}
});
}
$(document).on('click', 'button', function() {
var $ul;
if(!$(this).hasClass('winner')) {
$ul = $(this).parent().parent();
}
else {
$ul = $(this).parent().parent().parent().parent();
console.log($ul);
}
$ul.append($('<li class="winner">' + $(this).text() + '</li>'));
$ul.find('button').each(function() {
$(this).replaceWith($(this).text());
});
changeToButtons();
});
Also see: Tab Triggers