| 61 | var shift = false; |
| 62 | |
| 63 | function View(calcModel) { |
| 64 | this.calcElement = $('#calc'); |
| 65 | this.buttonsElement = $('#buttons'); |
| 66 | this.displayElement = $('#display'); |
| 67 | this.lastDisplayElement = null; |
| 68 | this.BuildWidgets(); |
| 69 | var calc = this; |
| 70 | |
| 71 | Array.prototype.forEach.call(document.querySelectorAll('.calc-button'), |
| 72 | function(button) { |
| 73 | var handler = function(e) { |
| 74 | e.preventDefault(); |
| 75 | var clicked = values[e.target.classList[1]]; |
| 76 | var result = calcModel.HandleButtonClick(clicked); |
| 77 | calc.buttonClicked(clicked, result); |
| 78 | }; |
| 79 | button.addEventListener('touchstart', handler); |
| 80 | button.addEventListener('click', handler); |
| 81 | button.addEventListener('touchstart', function(e) { |
| 82 | e.target.classList.add('active'); |
| 83 | }); |
| 84 | button.addEventListener('touchend', function(e) { |
| 85 | e.target.classList.remove('active'); |
| 86 | }); |
| 87 | }); |
| 88 | |
| 89 | window.addEventListener("copy", function(e) { |
| 90 | var result = calcModel.accumulator; |
| 91 | e.preventDefault(); |
| 92 | e.clipboardData.setData("text/plain",result); |
| 93 | }); |
| 94 | |
| 95 | $(document).keydown(function(event) { |
| 96 | if (event.ctrlKey && event.keyCode == 67) { |
| 97 | return; |
| 98 | } |
| 99 | var clicked = null; |
| 100 | if (event.which == 16) |
| 101 | shift = true; |
| 102 | else if (shift && event.which in shiftKeyboard) |
| 103 | clicked = shiftKeyboard[event.which]; |
| 104 | else if (!shift && event.which in keyboard) |
| 105 | clicked = keyboard[event.which]; |
| 106 | if (clicked != null) { |
| 107 | var result = calcModel.HandleButtonClick(clicked); |
| 108 | calc.buttonClicked(clicked, result); |
| 109 | } |
| 110 | }); |
| 111 | |
| 112 | $(document).keyup(function(event) { |
| 113 | if (event.which == 16) |
| 114 | shift = false; |
| 115 | }); |
| 116 | } |
| 117 | |
| 118 | function displayNumber(number) { |
| 119 | var digits = (number + '').length; |