/** * Global */ var ktane = ktane || {}; $('h2').on('dblclick', function () { $(this).closest('section').toggleClass('collapsed'); }).attr('title', 'Double-click to expand/collapse'); /** Reset inputs */ ktane.resetInputs = function ($container) { $container.find('textarea').val(''); $container.find('.selected').removeClass('selected'); return $container.find('input').each(function () { if (this.type === 'text') { $(this).val('').trigger('keyup'); } else if (this.type === 'checkbox') { this.checked = false; } else if (this.type === 'radio' && !this.value) { this.checked = true; } }); } ktane.resetInputs($('body')); $('.jsResetSection').on('click', function () { ktane.resetInputs($(this).closest('section')).filter('[type="text"]').first().focus(); }); /** Navigation */ $('section').each(function () { var $section = $(this), id = $section.attr('id'), $a = $('' + $(this).find('h2').first().text() + '').on('click', function () { $section.removeClass('collapsed'); }); id && $('#navList').append($('
').append($a)); }); (function () { /** * Wires */ var count = { red: 0, yellow: 0, blue: 0, white: 0, black: 0 }, $wireList = $('#wireList'); $('#wireOptions button').on('click', function () { var colour = this.getAttribute('data-colour'), letter = this.getAttribute('data-letter'), $li = $(''); $wireList.append($li); count[colour]++; checkWireToCut(); }); $wireList.on('click', 'button', function () { var deleteIndex = $(this).parent().index(); $wireList.children('li:eq(' + deleteIndex + '), li:gt(' + deleteIndex + ')').each(function () { var button = this.firstChild; count[button.getAttribute('data-colour')]--; $(this).remove(); }); checkWireToCut(); }); function checkWireToCut() { var lastColour = $wireList.children(':last-child').children().first().data('colour'), oddPossible; $wireList.find('.wireToCut').removeClass('wireToCut odd even'); switch ($wireList.children().length) { case 3: oddPossible = false; if (!count['red']) { addWireToCut(2); } else if (lastColour === 'white') { addWireToCut(); } else if (count['blue'] > 1) { $wireList.find('[data-colour="blue"]').last().parent().addClass('wireToCut'); } else { addWireToCut(); } break; case 4: oddPossible = count['red'] > 1; if (oddPossible) { $wireList.find('[data-colour="red"]').parent().last().addClass('wireToCut odd'); } if (lastColour === 'yellow' && !count['red'] || count['blue'] === 1) { addWireToCut(1); } else if (count['yellow'] > 1) { addWireToCut(); } else { addWireToCut(2); } break; case 5: oddPossible = lastColour === 'black'; if (oddPossible) { addWireToCut(4, 'odd'); } if (count['red'] === 1 && count['yellow'] > 1) { addWireToCut(1); } else if (!count['black']) { addWireToCut(2); } else { addWireToCut(1); } break; case 6: oddPossible = !count['yellow']; if (oddPossible) { addWireToCut(3, 'odd'); } if (count['yellow'] === 1 && count['white'] > 1) { addWireToCut(4); } else if (!count['red']) { addWireToCut(); } else { addWireToCut(4); } break; default: break; } function addWireToCut(child, className) { if (typeof className === 'undefined') { className = 'even'; } $wireList.children(isNaN(child) ? ':last-child' : ':nth-child(' + child + ')') .addClass('wireToCut' + (className !== 'even' || oddPossible ? ' ' + className : '')); } } })(); (function () { /** * Button */ var $section = $('#sectionButton'), $instruction = $section.find('.instruction'), instruction; $section.find('input').on('click', function () { var colour = $('input[name="buttonColour"]:checked').val(), text = $('input[name="buttonText"]:checked').val(); if (text === 'Detonate') { instruction = 'If 2+ \ud83d\udd0b, press and release.
');
$column.append($('').append($img));
name in $imageLists
? $imageLists[name].push($img)
: $imageLists[name] = [$img];
});
});
$section.on('click', 'img', function () {
var $img = $(this),
name = $img.data('name'),
endState = !$img.hasClass('selected'),
offset = endState ? 1 : -1;
$.each($imageLists[name], function (i, $img) {
var $column = $img.parent().parent();
$img.toggleClass('selected', endState);
$column.attr('data-count', parseInt($column.attr('data-count'), 10) + offset);
});
});
$section.find('.jsResetSection').on('click', function () {
// Also need to reset the indices after removing .selected
$section.find('ul').attr('data-count', 0);
});
})();
(function () {
/**
* Simon
*/
var $checkbox = $('#simonVowel'),
$strikeButtons = $('#sectionSimon input[name="simonStrikes"]'),
$arrows = [],
mappings = [ // (hasVowel, strikes) -> list of visible arrows by ID
// No vowel
[
['RB', 'BY', 'YR'],
['GY', 'YG'],
['RY', 'BG', 'GB', 'YR']
],
// Vowel
[
['RB', 'BR', 'GY', 'YG'],
['RY', 'BG', 'GB', 'YR'],
['RG', 'BR', 'GY', 'YB']
]
];
$('#simonBoard').find('.arrow').each(function (i, arrow) {
$arrows[arrow.id.replace(/^.*(?=..$)/, '')] = $(arrow);
});
$('#sectionSimon input').on('change', function () {
var hasVowel = +$checkbox.prop('checked'),
strikes = $strikeButtons.filter(':checked').val();
for (var id in $arrows) {
$arrows[id].removeClass('active');
}
$.each(mappings[hasVowel][strikes], function (i, id) {
$arrows[id].addClass('active');
});
}).first().trigger('change');
})();
(function () {
/**
* Who's on First
*/
var TL = 'top-left',
TR = 'top-right',
ML = 'middle-left',
MR = 'middle-right',
BL = 'bottom-left',
BR = 'bottom-right',
displays = {
'\u00a0': BL,
'BLANK': MR,
'C': TR,
'CEE': BR,
'DISPLAY': BR,
'FIRST': TR,
'HOLD ON': BR,
'LEAD': BR,
'LED': ML,
'LEED': BL,
'NO': BR,
'NOTHING': ML,
'OKAY': TR,
'READ': MR,
'RED': MR,
'REED': BL,
'SAYS': BR,
'SEE': BR,
'U': TL,
'UR': TL,
'THEIR': MR,
'THERE': BR,
'THEY ARE': ML,
'THEY\'RE': BL,
'YES': ML,
'YOU': MR,
'YOU ARE': BR,
'YOUR': MR,
'YOU\'RE': MR
},
sequence = {
'BLANK': 'WAIT, RIGHT, OKAY, MIDDLE, BLANK',
'DONE': 'SURE, UH HUH, NEXT, WHAT?, YOUR, UR, YOU\'RE, HOLD, LIKE, YOU, U, YOU ARE, UH UH, DONE',
'FIRST': 'LEFT, OKAY, YES, MIDDLE, NO, RIGHT, NOTHING, UHHH, WAIT, READY, BLANK, WHAT, PRESS, FIRST',
'HOLD': 'YOU ARE, U, DONE, UH UH, YOU, UR, SURE, WHAT?, YOU\'RE, NEXT, HOLD',
'LEFT': 'RIGHT, LEFT',
'LIKE': 'YOU\'RE, NEXT, U, UR, HOLD, DONE, UH UH, WHAT?, UH HUH, YOU, LIKE',
'MIDDLE': 'BLANK, READY, OKAY, WHAT, NOTHING, PRESS, NO, WAIT, LEFT, MIDDLE',
'NEXT': 'WHAT?, UH HUH, UH UH, YOUR, HOLD, SURE, NEXT',
'NO': 'BLANK, UHHH, WAIT, FIRST, WHAT, READY, RIGHT, YES, NOTHING, LEFT, PRESS, OKAY, NO',
'NOTHING': 'UHHH, RIGHT, OKAY, MIDDLE, YES, BLANK, NO, PRESS, LEFT, WHAT, WAIT, FIRST, NOTHING',
'OKAY': 'MIDDLE, NO, FIRST, YES, UHHH, NOTHING, WAIT, OKAY',
'PRESS': 'RIGHT, MIDDLE, YES, READY, PRESS',
'READY': 'YES, OKAY, WHAT, MIDDLE, LEFT, PRESS, RIGHT, BLANK, READY',
'RIGHT': 'YES, NOTHING, READY, PRESS, NO, WAIT, WHAT, RIGHT',
'SURE': 'YOU ARE, DONE, LIKE, YOU\'RE, YOU, HOLD, UH HUH, UR, SURE',
'U': 'UH HUH, SURE, NEXT, WHAT?, YOU\'RE, UR, UH UH, DONE, U',
'UH HUH': 'UH HUH',
'UH UH': 'UR, U, YOU ARE, YOU\'RE, NEXT, UH UH',
'UHHH': 'READY, NOTHING, LEFT, WHAT, OKAY, YES, RIGHT, NO, PRESS, BLANK, UHHH',
'UR': 'DONE, U, UR',
'WAIT': 'UHHH, NO, BLANK, OKAY, YES, LEFT, FIRST, PRESS, WHAT, WAIT',
'WHAT': 'UHHH, WHAT',
'WHAT?': 'YOU, HOLD, YOU\'RE, YOUR, U, DONE, UH UH, LIKE, YOU ARE, UH HUH, UR, NEXT, WHAT?',
'YES': 'OKAY, RIGHT, UHHH, MIDDLE, FIRST, WHAT, PRESS, READY, NOTHING, YES',
'YOU ARE': 'YOUR, NEXT, LIKE, UH HUH, WHAT?, DONE, UH UH, HOLD, YOU, U, YOU\'RE, SURE, UR',
'YOU': 'SURE, YOU ARE, YOUR, YOU\'RE, NEXT, UH HUH, UR, HOLD, WHAT?, YOU',
'YOU\'RE': 'YOU, YOU\'RE',
'YOUR': 'UH UH, YOU ARE, UH HUH, YOUR'
},
$list = $('#wofList'),
$table = $('#wofTable'),
$displays = {},
$rows = {};
$.each(displays, function (word, location) {
var $dt = $('