OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:html'; | 5 import 'dart:html'; |
6 import 'dart:math' as Math; | 6 import 'dart:math' as Math; |
7 import 'calcui.dart'; | 7 import 'calcui.dart'; |
| 8 import 'dart:async'; |
8 | 9 |
9 Set numberKeyPresses; | 10 Set numberKeyPresses; |
10 Set operatorKeyPresses; | 11 Set operatorKeyPresses; |
11 Set equalKeyPresses; | 12 Set equalKeyPresses; |
12 Set clearKeyPresses; | 13 Set clearKeyPresses; |
13 Set dotKeyPresses; | 14 Set dotKeyPresses; |
14 Set backspacePresses; | 15 Set backspacePresses; |
15 List eventSubscriptions = []; | 16 List eventSubscriptions = []; |
16 | 17 |
17 void setupEvents() { | 18 void setupEvents() { |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 // Only Change classes with 1 hyphen that's the main class for an element | 318 // Only Change classes with 1 hyphen that's the main class for an element |
318 // to handle hover and active. | 319 // to handle hover and active. |
319 String theClass; | 320 String theClass; |
320 for (final String cls in key.classes) { | 321 for (final String cls in key.classes) { |
321 if (cls.split('-').length == 2) { | 322 if (cls.split('-').length == 2) { |
322 theClass = cls; | 323 theClass = cls; |
323 } | 324 } |
324 } | 325 } |
325 key.classes.add('${theClass}${postfix}'); | 326 key.classes.add('${theClass}${postfix}'); |
326 final String nextPostfix = (postfix == '-error') ? '-error' : '-press'; | 327 final String nextPostfix = (postfix == '-error') ? '-error' : '-press'; |
327 window.setTimeout(() => resetKey(key, '${theClass}${postfix}', | 328 new Timer(const Duration(milliseconds: 80), |
328 '${theClass}${nextPostfix}'), 80); | 329 () => resetKey(key, '${theClass}${postfix}', |
| 330 '${theClass}${nextPostfix}')); |
329 } | 331 } |
330 | 332 |
331 void resetKey(Element key, String classToRemove, [String classToAdd = ""]) { | 333 void resetKey(Element key, String classToRemove, [String classToAdd = ""]) { |
332 if (key != null) { | 334 if (key != null) { |
333 key.classes.remove(classToRemove); | 335 key.classes.remove(classToRemove); |
334 if (classToAdd.length > 0) { | 336 if (classToAdd.length > 0) { |
335 key.classes.add(classToAdd); | 337 key.classes.add(classToAdd); |
336 window.setTimeout(() => resetKey(key, classToAdd), 80); | 338 new Timer(const Duration(milliseconds: 80), |
| 339 () => resetKey(key, classToAdd)); |
337 } | 340 } |
338 } | 341 } |
339 } | 342 } |
340 | 343 |
341 void main() { | 344 void main() { |
342 final Element element = new Element.tag('div'); | 345 final Element element = new Element.tag('div'); |
343 | 346 |
344 // Create our Tape UI. | 347 // Create our Tape UI. |
345 tapeUI = new TapeUI(); | 348 tapeUI = new TapeUI(); |
346 element.children.add(tapeUI.root); // Render the UI | 349 element.children.add(tapeUI.root); // Render the UI |
347 | 350 |
348 // Create our tape controller. | 351 // Create our tape controller. |
349 tape = new Tape(); | 352 tape = new Tape(); |
350 | 353 |
351 renderPad(element); | 354 renderPad(element); |
352 | 355 |
353 // Render the UI. | 356 // Render the UI. |
354 document.body.children.add(element); | 357 document.body.children.add(element); |
355 | 358 |
356 currentRegister = ""; | 359 currentRegister = ""; |
357 total = 0.0; | 360 total = 0.0; |
358 | 361 |
359 setupEvents(); | 362 setupEvents(); |
360 } | 363 } |
OLD | NEW |