OLD | NEW |
---|---|
1 var operators = ['+', '-', '/', '*']; | 1 var operators = ['+', '-', '/', '*']; |
2 | 2 |
3 var values = { 'one' : 1, | 3 var values = { 'one' : 1, |
4 'two' : 2, | 4 'two' : 2, |
5 'three' : 3, | 5 'three' : 3, |
6 'four' : 4, | 6 'four' : 4, |
7 'five' : 5, | 7 'five' : 5, |
8 'six' : 6, | 8 'six' : 6, |
9 'seven' : 7, | 9 'seven' : 7, |
10 'eight' : 8, | 10 'eight' : 8, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 var result = calcModel.HandleButtonClick(clicked); | 70 var result = calcModel.HandleButtonClick(clicked); |
71 calc.buttonClicked(clicked, result); | 71 calc.buttonClicked(clicked, result); |
72 } | 72 } |
73 }); | 73 }); |
74 | 74 |
75 $(document).keyup(function(event) { | 75 $(document).keyup(function(event) { |
76 if (event.which == 16) | 76 if (event.which == 16) |
77 shift = false; | 77 shift = false; |
78 }); | 78 }); |
79 | 79 |
80 this.displayElement.attr('role', 'log'); | |
81 this.displayElement.attr('aria-live', 'polite'); | |
dharcourt
2012/10/17 04:22:44
Most of the HTML in newer versions of the calculat
| |
80 } | 82 } |
81 | 83 |
82 | 84 |
83 function displayNumber(number) { | 85 function displayNumber(number) { |
84 var digits = (number + '').length; | 86 var digits = (number + '').length; |
85 if ((number >= 0 && digits > 8) || (number < 0 && digits > 9)) { | 87 if ((number >= 0 && digits > 8) || (number < 0 && digits > 9)) { |
86 if (number % 1 != 0) { | 88 if (number % 1 != 0) { |
87 number = parseFloat((number + '').slice(0, 8)); | 89 number = parseFloat((number + '').slice(0, 8)); |
88 if (number % 1 != 0) return number; | 90 if (number % 1 != 0) return number; |
89 } | 91 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 this.AddDisplayEquation('', 0, ''); | 139 this.AddDisplayEquation('', 0, ''); |
138 } | 140 } |
139 | 141 |
140 View.prototype.UpdateTotal = function(accumulator) { | 142 View.prototype.UpdateTotal = function(accumulator) { |
141 $(this.lastDisplayElement).children('.accumulator').text(accumulator); | 143 $(this.lastDisplayElement).children('.accumulator').text(accumulator); |
142 } | 144 } |
143 | 145 |
144 View.prototype.AddDisplayEquation = function(operator, operand, accumulator) { | 146 View.prototype.AddDisplayEquation = function(operator, operand, accumulator) { |
145 this.displayElement.append( | 147 this.displayElement.append( |
146 '<div class="equation">' | 148 '<div class="equation">' |
147 + '<div class="operand">' + operand + '</div>' | 149 + '<div class="operand_wrapper">' |
148 + '<div class="operator">' + operator + '</div>' | 150 + '<span class="operator">' + operator + '</span>' |
149 + '<div class="accumulator">' + accumulator + '</div' | 151 + '<span class="operand">' + operand + '</span>' |
152 + '</div>' | |
153 + '<div class="accumulator" aria-hidden="true">' + accumulator + '</div' | |
150 + '</div>'); | 154 + '</div>'); |
151 this.lastDisplayElement = $('.equation').last(); | 155 this.lastDisplayElement = $('.equation').last(); |
152 this.displayElement.scrollTop(this.displayElement[0].scrollHeight); | 156 this.displayElement.scrollTop(this.displayElement[0].scrollHeight); |
153 } | 157 } |
dharcourt
2012/10/17 04:22:44
This will need to be done just a bit differently i
| |
154 | 158 |
155 View.prototype.UpdateDisplayEquation = function(operator, operand, accumulator) { | 159 View.prototype.UpdateDisplayEquation = function(operator, operand, accumulator) { |
156 $(this.lastDisplayElement).children('.operator').text(operator); | 160 $(this.lastDisplayElement).find('.operator').text(operator); |
157 $(this.lastDisplayElement).children('.operand').text(operand); | 161 $(this.lastDisplayElement).find('.operand').text(operand); |
dharcourt
2012/10/17 04:22:44
JQuery has been removed from the newer Calculator
| |
158 $(this.lastDisplayElement).children('.accumulator').text(accumulator); | 162 $(this.lastDisplayElement).children('.accumulator').text(accumulator); |
159 this.displayElement.scrollTop(this.displayElement[0].scrollHeight); | 163 this.displayElement.scrollTop(this.displayElement[0].scrollHeight); |
160 } | 164 } |
161 | 165 |
162 View.prototype.AddButtons = function() { | 166 View.prototype.AddButtons = function() { |
163 var row; | 167 var row; |
164 | 168 |
165 row = this.AddRow(); | 169 row = this.AddRow(); |
166 this.AddButton(row, 'AC', 'AC'); | 170 this.AddButton(row, 'AC', 'AC'); |
167 this.AddButton(row, 'plus-minus', 'plus-minus'); | 171 this.AddButton(row, 'plus-minus', 'plus-minus'); |
(...skipping 23 matching lines...) Expand all Loading... | |
191 this.AddButton(row, 'point', 'point') | 195 this.AddButton(row, 'point', 'point') |
192 } | 196 } |
193 | 197 |
194 View.prototype.AddRow = function() { | 198 View.prototype.AddRow = function() { |
195 var row = $('<div/>'); | 199 var row = $('<div/>'); |
196 this.buttonsElement.append(row); | 200 this.buttonsElement.append(row); |
197 return row; | 201 return row; |
198 } | 202 } |
199 | 203 |
200 View.prototype.AddButton = function(row, value, button_value) { | 204 View.prototype.AddButton = function(row, value, button_value) { |
201 row.append('<div class="calc-button ' + button_value + '">' + '</div>'); | 205 row.append('<button aria-label="' + button_value + '" class="calc-button ' + |
206 button_value + '">' + '</button>'); | |
dharcourt
2012/10/17 04:22:44
This can now be encoded directly in the HTML.
| |
202 } | 207 } |
OLD | NEW |