Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: src/site/articles/trydart/examples/6-piratebadge/piratebadge.dart

Issue 35913002: Try Dart 1 hour experience first draft (Closed) Base URL: https://github.com/dart-lang/dartlang.org.git@master
Patch Set: trying again to upload chnages. still getting an error Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 bool useRandomName = false;
12
13 RadioButtonInputElement captainRadioElement;
14 RadioButtonInputElement scallywagRadioElement;
15
16 void main() {
17 inputNameElement = query('#inputName');
18 inputNameElement.onChange.listen(generateBadge);
19
20 genButtonElement = query('#generateButton');
21 genButtonElement.onClick.listen(generateBadge);
22
23 query('#useRandomName').onClick.listen(useRandomNameClickHandler);
24
25 captainRadioElement = query('#captain');
26 scallywagRadioElement = query('#scallywag');
27 }
28
29 void generateBadge(Event event) {
30 if (!useRandomName) {
31 query('#badgeName').text = new PirateName(firstName: inputNameElement.value) .name;
32 } else if ((query('#captain') as RadioButtonInputElement).checked) {
33 query('#badgeName').text = new PirateName.captain().name;
34 } else {
35 query('#badgeName').text = new PirateName.scallywag().name;
36 }
37 }
38
39 void useRandomNameClickHandler(MouseEvent e) {
40 if ((e.target as CheckboxInputElement).checked) {
41 genButtonElement.disabled = false;
42 captainRadioElement.disabled = false;
43 scallywagRadioElement.disabled = false;
44 inputNameElement
45 ..disabled = true
46 ..value = ''
47 ..placeholder = '';
48 useRandomName = true;
49 } else {
50 genButtonElement.disabled = true;
51 captainRadioElement.disabled = true;
52 scallywagRadioElement.disabled = true;
53 inputNameElement
54 ..disabled = false
55 ..placeholder = 'Your name here';
56 useRandomName = false;
57 }
58 }
59
60 class PirateName {
61
62 Random indexGen = new Random();
63
64 String _pirateName;
65
66 String get name => _pirateName;
67 set name(String value) => _pirateName = value;
68
69 String toString() => name;
70
71 PirateName({String firstName}) {
72 if (firstName == null) {
73 firstName = names[indexGen.nextInt(names.length)];
74 }
75 _pirateName = '$firstName';
76 }
77
78 PirateName.captain() {
79 String firstName = names[indexGen.nextInt(names.length)];
80 String appellation = captains[indexGen.nextInt(captains.length)];
81 _pirateName = '$firstName the $appellation';
82 }
83
84 PirateName.scallywag() {
85 String firstName = names[indexGen.nextInt(names.length)];
86 String appellation = scallywags[indexGen.nextInt(scallywags.length)];
87 _pirateName = '$firstName the $appellation';
88 }
89
90 List names = const [ 'Anne', 'Bette', 'Cate', 'Dawn',
91 'Elise', 'Faye', 'Ginger', 'Harriot',
92 'Izzy', 'Jane', 'Kaye', 'Liz',
93 'Maria', 'Nell', 'Olive', 'Pat',
94 'Queenie', 'Rae', 'Sal', 'Tam',
95 'Uma', 'Violet', 'Wilma', 'Xana',
96 'Yvonne', 'Zelda',
97 'Abe', 'Billy', 'Caleb', 'Davie',
98 'Eb', 'Frank', 'Gabe', 'House',
99 'Icarus', 'Jack', 'Kurt', 'Larry',
100 'Mike', 'Nolan', 'Oliver', 'Pat',
101 'Quib', 'Roy', 'Sal', 'Tom',
102 'Ube', 'Val', 'Walt', 'Xavier',
103 'Yvan', 'Zeb'];
104 List captains = const [ 'Awesome', 'Black', 'Captain', 'Damned',
105 'Even', 'Fighter', 'Great', 'Hearty',
106 'Irate', 'Jackal', 'King', 'Lord',
107 'Mighty', 'Noble', 'Old', 'Powerful',
108 'Quick', 'Red', 'Stalwart', 'Tank',
109 'Ultimate', 'Vicious', 'Wily', 'aXe', 'Young', 'Zeal ot'];
110 List scallywags = const [ 'Angry', 'Brave', 'Crazy', 'Damned',
111 'Eager', 'Fool', 'Greedy', 'Hated',
112 'Idiot', 'Jinxed', 'Kind', 'Lame',
113 'Maimed', 'Naked', 'Old', 'Pale',
114 'Queasy', 'Rat', 'Sandy', 'Tired',
115 'Ugly', 'Vile', 'Weak', 'Xeric', 'Yellow', 'Zesty'];
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698