Index: src/site/articles/trydart/examples/3-buttonbadge/piratebadge.dart |
diff --git a/src/site/articles/trydart/examples/3-buttonbadge/piratebadge.dart b/src/site/articles/trydart/examples/3-buttonbadge/piratebadge.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f9c59f65d9e9c3d80cbc0db1edb4c9bc141733a6 |
--- /dev/null |
+++ b/src/site/articles/trydart/examples/3-buttonbadge/piratebadge.dart |
@@ -0,0 +1,34 @@ |
+// 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'; |
+ |
+ButtonElement genButton; |
+ |
+void main() { |
+ query('#inputName').onInput.listen(updateBadge); |
+ genButton = query('#generateButton') |
+ ..onClick.listen(generateBadge); |
+} |
+ |
+void updateBadge(Event e) { |
+ String inputName = (e.target as InputElement).value; |
+ |
+ badgeName = inputName; |
+ if (inputName.trim().isEmpty) { |
+ genButton..disabled = false |
+ ..text = 'Generate badge'; |
+ } else { |
+ genButton..disabled = true |
+ ..text = 'Arrr! Remove the text!'; |
+ } |
+} |
+ |
+void generateBadge(Event e) { |
+ badgeName = 'Anne Bonney'; |
+} |
+ |
+set badgeName(String newName) { |
+ query('#badgeName').text = newName; |
+} |