| 571 | |
| 572 | //keypad for boxes |
| 573 | function addKeypadFunctionality() { |
| 574 | //if no keypad return |
| 575 | for (var i = 0; i < 81; i++) { |
| 576 | (function(j) { |
| 577 | var domSpot = board.board[j].dom, |
| 578 | eraseEvent = false; |
| 579 | |
| 580 | domSpot.addEventListener('touchstart', function() { |
| 581 | if (domSpot.classList.contains('noDrop')) { |
| 582 | return |
| 583 | } |
| 584 | var stillPressed = true; |
| 585 | domSpot.addEventListener('touchend', function() { |
| 586 | stillPressed = false; |
| 587 | }); |
| 588 | window.setTimeout(function() { |
| 589 | if (stillPressed) { |
| 590 | domSpot.innerHTML = ' '; |
| 591 | eraseEvent = true; |
| 592 | } |
| 593 | }, 700); |
| 594 | }); |
| 595 | |
| 596 | domSpot.addEventListener('click', function() { |
| 597 | if (domSpot.classList.contains('noDrop') || document.getElementsByClassName('keypad').length > 1 || eraseEvent) { |
| 598 | eraseEvent = false; |
| 599 | return |
| 600 | }; |
| 601 | var spotCoor = domSpot.getBoundingClientRect(); |
| 602 | var keypad = document.getElementsByClassName('keypad')[0].cloneNode(true); |
| 603 | var keypadCoor = document.getElementsByClassName('keypad')[0].getBoundingClientRect(); |
| 604 | var keys; |
| 605 | var pX, pY; |
| 606 | |
| 607 | document.body.appendChild(keypad); |
| 608 | |
| 609 | keypad.style.visibility = 'visible'; |
| 610 | pY = (spotCoor.top - keypadCoor.height / 2 + spotCoor.height / 2) + document.body.scrollTop; |
| 611 | // if (pY > document.body.getBoundingClientRect().height) {pY = document.body.getBoundingClientRect().height - keypadCoor.height} |
| 612 | pX = (spotCoor.left - keypadCoor.width / 2 + spotCoor.width / 2) + document.body.scrollLeft; |
| 613 | keypad.style.top = pY + 'px'; |
| 614 | keypad.style.left = pX + 'px'; |
| 615 | |
| 616 | keys = keypad.getElementsByTagName('div');//needs to be assigned here rather than at var declaration or breaks in ie |
| 617 | for (var v = 0; v < keys.length; v++) { |
| 618 | |
| 619 | (function(x) { |
| 620 | keys[x].addEventListener('click', function() { |
| 621 | if (!keys[x].classList.contains('close')) { |
| 622 | domSpot.innerHTML = keys[x].innerHTML; |
| 623 | keyboardInputPosition = j; |
| 624 | } |
| 625 | keypad.parentNode.removeChild(keypad); |
| 626 | }); |
| 627 | })(v); |
| 628 | }; |
| 629 | |
| 630 | keyboardInputPosition = j; |