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'; | |
9 | 8 |
10 Set numberKeyPresses; | 9 Set numberKeyPresses; |
11 Set operatorKeyPresses; | 10 Set operatorKeyPresses; |
12 Set equalKeyPresses; | 11 Set equalKeyPresses; |
13 Set clearKeyPresses; | 12 Set clearKeyPresses; |
14 Set dotKeyPresses; | 13 Set dotKeyPresses; |
15 Set backspacePresses; | 14 Set backspacePresses; |
16 List eventSubscriptions = []; | 15 List eventSubscriptions = []; |
17 | 16 |
18 void setupEvents() { | 17 void setupEvents() { |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // Only Change classes with 1 hyphen that's the main class for an element | 317 // Only Change classes with 1 hyphen that's the main class for an element |
319 // to handle hover and active. | 318 // to handle hover and active. |
320 String theClass; | 319 String theClass; |
321 for (final String cls in key.classes) { | 320 for (final String cls in key.classes) { |
322 if (cls.split('-').length == 2) { | 321 if (cls.split('-').length == 2) { |
323 theClass = cls; | 322 theClass = cls; |
324 } | 323 } |
325 } | 324 } |
326 key.classes.add('${theClass}${postfix}'); | 325 key.classes.add('${theClass}${postfix}'); |
327 final String nextPostfix = (postfix == '-error') ? '-error' : '-press'; | 326 final String nextPostfix = (postfix == '-error') ? '-error' : '-press'; |
328 new Timer(const Duration(milliseconds: 80), | 327 window.setTimeout(() => resetKey(key, '${theClass}${postfix}', |
329 () => resetKey(key, '${theClass}${postfix}', | 328 '${theClass}${nextPostfix}'), 80); |
330 '${theClass}${nextPostfix}')); | |
331 } | 329 } |
332 | 330 |
333 void resetKey(Element key, String classToRemove, [String classToAdd = ""]) { | 331 void resetKey(Element key, String classToRemove, [String classToAdd = ""]) { |
334 if (key != null) { | 332 if (key != null) { |
335 key.classes.remove(classToRemove); | 333 key.classes.remove(classToRemove); |
336 if (classToAdd.length > 0) { | 334 if (classToAdd.length > 0) { |
337 key.classes.add(classToAdd); | 335 key.classes.add(classToAdd); |
338 new Timer(const Duration(milliseconds: 80), | 336 window.setTimeout(() => resetKey(key, classToAdd), 80); |
339 () => resetKey(key, classToAdd)); | |
340 } | 337 } |
341 } | 338 } |
342 } | 339 } |
343 | 340 |
344 void main() { | 341 void main() { |
345 final Element element = new Element.tag('div'); | 342 final Element element = new Element.tag('div'); |
346 | 343 |
347 // Create our Tape UI. | 344 // Create our Tape UI. |
348 tapeUI = new TapeUI(); | 345 tapeUI = new TapeUI(); |
349 element.children.add(tapeUI.root); // Render the UI | 346 element.children.add(tapeUI.root); // Render the UI |
350 | 347 |
351 // Create our tape controller. | 348 // Create our tape controller. |
352 tape = new Tape(); | 349 tape = new Tape(); |
353 | 350 |
354 renderPad(element); | 351 renderPad(element); |
355 | 352 |
356 // Render the UI. | 353 // Render the UI. |
357 document.body.children.add(element); | 354 document.body.children.add(element); |
358 | 355 |
359 currentRegister = ""; | 356 currentRegister = ""; |
360 total = 0.0; | 357 total = 0.0; |
361 | 358 |
362 setupEvents(); | 359 setupEvents(); |
363 } | 360 } |
OLD | NEW |