buttons for clicking, better text handling, fix no not working

This commit is contained in:
Bernhard Tittelbach 2017-03-03 23:58:26 +01:00
parent 38e0834a0f
commit f31a2576f3

View File

@ -29,7 +29,7 @@ function addButtons(element) {
var keyN = document.createElement("a"); var keyN = document.createElement("a");
keyN.setAttribute("class","key"); keyN.setAttribute("class","key");
keyN.append(document.createTextNode("N")); keyN.append(document.createTextNode("N"));
$(keyY).click(chooseNo); $(keyN).click(chooseNo);
keydiv.append(keyY); keydiv.append(keyY);
keydiv.append(keyN); keydiv.append(keyN);
element.append(keydiv); element.append(keydiv);
@ -59,9 +59,10 @@ function overwriteLine(element, text, delay) {
} }
function chooseYes($body) { function chooseYes() {
clearInterval(blinkIntervalId); clearInterval(blinkIntervalId);
$body.off('keypress touchstart'); $('body').off('keypress touchstart');
removeButtons();
$output = $('.output4'); $output = $('.output4');
printLine($output, ' Great! We\'ll see you at the party then.'); printLine($output, ' Great! We\'ll see you at the party then.');
printLine($output, ' expect DJ Music, Food, Tschunk, Games and more'); printLine($output, ' expect DJ Music, Food, Tschunk, Games and more');
@ -85,9 +86,10 @@ function chooseYes($body) {
printLine($output, ''); printLine($output, '');
} }
function chooseNo($body) { function chooseNo() {
clearInterval(blinkIntervalId); clearInterval(blinkIntervalId);
$body.off('keypress'); $('body').off('keypress');
removeButtons();
$output = $('.output4'); $output = $('.output4');
globalDelay = 0; globalDelay = 0;
printLine($output, ' Sorry to hear! You\'re missing out on a great experience.'); printLine($output, ' Sorry to hear! You\'re missing out on a great experience.');
@ -97,7 +99,7 @@ function chooseNo($body) {
printLine($output, ''); printLine($output, '');
} }
var blinkIntervalId;
$(function () { $(function () {
var logoBW72 = [ var logoBW72 = [
@ -175,7 +177,7 @@ $(function () {
} }
$output = $('.output3'); $output = $('.output3');
printLine($output, ' are you coming? <span id="underscore">_</span>'); printLine($output, ' are you coming? <span id="textinput"></span><span id="underscore">_</span>');
addButtons($output); addButtons($output);
var $body = $('body'); var $body = $('body');
@ -190,20 +192,22 @@ $(function () {
globalDelay = 0; globalDelay = 0;
var underscore = true; var underscore = true;
var blinkIntervalId = setInterval(function () { blinkIntervalId = setInterval(function () {
globalDelay = 0; globalDelay = 0;
//console.log('interval!'); var underscorelem = document.getElementById("underscore");
if (underscore) { if (underscorelem){
document.getElementById("underscore").style="visibility:hidden;"; //console.log('interval!');
underscore = false; if (underscore) {
} else { underscorelem.style="visibility:hidden;";
document.getElementById("underscore").style="visibility:visible;"; underscore = false;
underscore = true; } else {
underscorelem.style="visibility:visible;";
underscore = true;
}
} }
}, 500); }, 500);
$body.on('keypress', function (event) { $body.on('keypress', function (event) {
globalDelay = 0; globalDelay = 0;
//console.log(event); //console.log(event);
@ -223,15 +227,15 @@ $(function () {
if (event.which === 111 && input === 'n') { if (event.which === 111 && input === 'n') {
input += 'o'; input += 'o';
} }
if (event.type == 'touchstart') { if (event.which === 8 && input.length > 0) {
input = 'yes'; input = input.substring(0,input.length-1);
} }
overwriteLine($output, ' are you coming? ' + input + '_'); $("#textinput").text(input);
if ((event.which === 13 || event.type == 'touchstart') && (input === 'y' || input === 'yes')) { if ((event.which === 13) && (input === 'y' || input === 'yes')) {
chooseYes($body); chooseYes();
} }
if (event.which === 13 && (input === 'n' || input === 'no')) { if (event.which === 13 && (input === 'n' || input === 'no')) {
chooseNo($body); chooseNo();
} }
}); });
}, },