| Index: src/site/articles/trydart/examples/6-piratebadge/piratebadge.dart
|
| diff --git a/src/site/articles/trydart/examples/6-piratebadge/piratebadge.dart b/src/site/articles/trydart/examples/6-piratebadge/piratebadge.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0de68aacb9cf4547e092b4fcf11d1ed8f4158f2b
|
| --- /dev/null
|
| +++ b/src/site/articles/trydart/examples/6-piratebadge/piratebadge.dart
|
| @@ -0,0 +1,116 @@
|
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +import 'dart:html';
|
| +import 'dart:math';
|
| +
|
| +InputElement inputNameElement;
|
| +ButtonElement genButtonElement;
|
| +
|
| +bool useRandomName = false;
|
| +
|
| +RadioButtonInputElement captainRadioElement;
|
| +RadioButtonInputElement scallywagRadioElement;
|
| +
|
| +void main() {
|
| + inputNameElement = query('#inputName');
|
| + inputNameElement.onChange.listen(generateBadge);
|
| +
|
| + genButtonElement = query('#generateButton');
|
| + genButtonElement.onClick.listen(generateBadge);
|
| +
|
| + query('#useRandomName').onClick.listen(useRandomNameClickHandler);
|
| +
|
| + captainRadioElement = query('#captain');
|
| + scallywagRadioElement = query('#scallywag');
|
| +}
|
| +
|
| +void generateBadge(Event event) {
|
| + if (!useRandomName) {
|
| + query('#badgeName').text = new PirateName(firstName: inputNameElement.value).name;
|
| + } else if ((query('#captain') as RadioButtonInputElement).checked) {
|
| + query('#badgeName').text = new PirateName.captain().name;
|
| + } else {
|
| + query('#badgeName').text = new PirateName.scallywag().name;
|
| + }
|
| +}
|
| +
|
| +void useRandomNameClickHandler(MouseEvent e) {
|
| + if ((e.target as CheckboxInputElement).checked) {
|
| + genButtonElement.disabled = false;
|
| + captainRadioElement.disabled = false;
|
| + scallywagRadioElement.disabled = false;
|
| + inputNameElement
|
| + ..disabled = true
|
| + ..value = ''
|
| + ..placeholder = '';
|
| + useRandomName = true;
|
| + } else {
|
| + genButtonElement.disabled = true;
|
| + captainRadioElement.disabled = true;
|
| + scallywagRadioElement.disabled = true;
|
| + inputNameElement
|
| + ..disabled = false
|
| + ..placeholder = 'Your name here';
|
| + useRandomName = false;
|
| + }
|
| +}
|
| +
|
| +class PirateName {
|
| +
|
| + Random indexGen = new Random();
|
| +
|
| + String _pirateName;
|
| +
|
| + String get name => _pirateName;
|
| + set name(String value) => _pirateName = value;
|
| +
|
| + String toString() => name;
|
| +
|
| + PirateName({String firstName}) {
|
| + if (firstName == null) {
|
| + firstName = names[indexGen.nextInt(names.length)];
|
| + }
|
| + _pirateName = '$firstName';
|
| + }
|
| +
|
| + PirateName.captain() {
|
| + String firstName = names[indexGen.nextInt(names.length)];
|
| + String appellation = captains[indexGen.nextInt(captains.length)];
|
| + _pirateName = '$firstName the $appellation';
|
| + }
|
| +
|
| + PirateName.scallywag() {
|
| + String firstName = names[indexGen.nextInt(names.length)];
|
| + String appellation = scallywags[indexGen.nextInt(scallywags.length)];
|
| + _pirateName = '$firstName the $appellation';
|
| + }
|
| +
|
| + List names = const [ 'Anne', 'Bette', 'Cate', 'Dawn',
|
| + 'Elise', 'Faye', 'Ginger', 'Harriot',
|
| + 'Izzy', 'Jane', 'Kaye', 'Liz',
|
| + 'Maria', 'Nell', 'Olive', 'Pat',
|
| + 'Queenie', 'Rae', 'Sal', 'Tam',
|
| + 'Uma', 'Violet', 'Wilma', 'Xana',
|
| + 'Yvonne', 'Zelda',
|
| + 'Abe', 'Billy', 'Caleb', 'Davie',
|
| + 'Eb', 'Frank', 'Gabe', 'House',
|
| + 'Icarus', 'Jack', 'Kurt', 'Larry',
|
| + 'Mike', 'Nolan', 'Oliver', 'Pat',
|
| + 'Quib', 'Roy', 'Sal', 'Tom',
|
| + 'Ube', 'Val', 'Walt', 'Xavier',
|
| + 'Yvan', 'Zeb'];
|
| + List captains = const [ 'Awesome', 'Black', 'Captain', 'Damned',
|
| + 'Even', 'Fighter', 'Great', 'Hearty',
|
| + 'Irate', 'Jackal', 'King', 'Lord',
|
| + 'Mighty', 'Noble', 'Old', 'Powerful',
|
| + 'Quick', 'Red', 'Stalwart', 'Tank',
|
| + 'Ultimate', 'Vicious', 'Wily', 'aXe', 'Young', 'Zealot'];
|
| + List scallywags = const [ 'Angry', 'Brave', 'Crazy', 'Damned',
|
| + 'Eager', 'Fool', 'Greedy', 'Hated',
|
| + 'Idiot', 'Jinxed', 'Kind', 'Lame',
|
| + 'Maimed', 'Naked', 'Old', 'Pale',
|
| + 'Queasy', 'Rat', 'Sandy', 'Tired',
|
| + 'Ugly', 'Vile', 'Weak', 'Xeric', 'Yellow', 'Zesty'];
|
| +}
|
|
|