OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:html'; |
| 6 import 'dart:math'; |
| 7 |
| 8 InputElement inputNameElement; |
| 9 ButtonElement genButtonElement; |
| 10 |
| 11 void main() { |
| 12 inputNameElement = query('#inputName'); |
| 13 inputNameElement.onChange.listen(generateBadge); |
| 14 |
| 15 genButtonElement = query('#generateButton'); |
| 16 genButtonElement.onClick.listen(generateBadge); |
| 17 } |
| 18 |
| 19 void generateBadge(Event event) { |
| 20 if (event.target == inputNameElement) { |
| 21 query('#badgeName').text = new PirateName(firstName: inputNameElement.value)
.name; |
| 22 } else { |
| 23 query('#badgeName').text = new PirateName().name; |
| 24 } |
| 25 } |
| 26 |
| 27 class PirateName { |
| 28 |
| 29 Random indexGen = new Random(); |
| 30 |
| 31 String _pirateName; |
| 32 |
| 33 String get name => _pirateName; |
| 34 set name(String value) => _pirateName = value; |
| 35 |
| 36 String toString() => name; |
| 37 |
| 38 PirateName({String firstName}) { |
| 39 if (firstName == null) { |
| 40 firstName = names[indexGen.nextInt(names.length)]; |
| 41 } |
| 42 _pirateName = '$firstName'; |
| 43 } |
| 44 |
| 45 List names = const [ 'Anne', 'Bette', 'Cate', 'Dawn', |
| 46 'Elise', 'Faye', 'Ginger', 'Harriot', |
| 47 'Izzy', 'Jane', 'Kaye', 'Liz', |
| 48 'Maria', 'Nell', 'Olive', 'Pat', |
| 49 'Queenie', 'Rae', 'Sal', 'Tam', |
| 50 'Uma', 'Violet', 'Wilma', 'Xana', |
| 51 'Yvonne', 'Zelda', |
| 52 'Abe', 'Billy', 'Caleb', 'Davie', |
| 53 'Eb', 'Frank', 'Gabe', 'House', |
| 54 'Icarus', 'Jack', 'Kurt', 'Larry', |
| 55 'Mike', 'Nolan', 'Oliver', 'Pat', |
| 56 'Quib', 'Roy', 'Sal', 'Tom', |
| 57 'Ube', 'Val', 'Walt', 'Xavier', |
| 58 'Yvan', 'Zeb']; |
| 59 } |
OLD | NEW |