Last active
August 29, 2015 14:26
-
-
Save Sfshaza/445dcc541fd4dedf1b4c to your computer and use it in GitHub Desktop.
darrrt/4-classbadge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<!-- | |
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. | |
--> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Pirate badge</title> | |
<script async type="application/dart" src="main.dart"></script> | |
<script async src="packages/browser/dart.js"></script> | |
<link rel="stylesheet" href="styles.css"> | |
</head> | |
<body> | |
<h1>Pirate badge</h1> | |
<div class="widgets"> | |
<div> | |
<input type="text" id="inputName" maxlength="15"> | |
</div> | |
<div> | |
<button id="generateButton">Aye! Gimme a name!</button> | |
</div> | |
</div> | |
<div class="badge"> | |
<div class="greeting"> | |
Arrr! Me name is | |
</div> | |
<div class="name"> | |
<span id="badgeName"> </span> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. | |
// In Step 4 of the code lab (dartlang.org/codelabs/darrrt/), | |
// you created a PirateName class. | |
import 'dart:html'; | |
import 'dart:math' show Random; | |
ButtonElement genButton; | |
void main() { | |
querySelector('#inputName').onInput.listen(updateBadge); | |
genButton = querySelector('#generateButton'); | |
genButton.onClick.listen(generateBadge); | |
} | |
void updateBadge(Event e) { | |
String inputName = (e.target as InputElement).value; | |
setBadgeName(new PirateName(firstName: inputName)); | |
if (inputName.trim().isEmpty) { | |
genButton | |
..disabled = false | |
..text = 'Aye! Gimme a name!'; | |
} else { | |
genButton | |
..disabled = true | |
..text = 'Arrr! Write yer name!'; | |
} | |
} | |
void generateBadge(Event e) { | |
setBadgeName(new PirateName()); | |
} | |
void setBadgeName(PirateName newName) { | |
querySelector('#badgeName').text = newName.pirateName; | |
} | |
class PirateName { | |
static final Random indexGen = new Random(); | |
String _firstName; | |
String _appellation; | |
PirateName({String firstName, String appellation}) { | |
if (firstName == null) { | |
_firstName = names[indexGen.nextInt(names.length)]; | |
} else { | |
_firstName = firstName; | |
} | |
if (appellation == null) { | |
_appellation = | |
appellations[indexGen.nextInt(appellations.length)]; | |
} else { | |
_appellation = appellation; | |
} | |
} | |
String toString() => pirateName; | |
String get pirateName => | |
_firstName.isEmpty ? '' : '$_firstName the $_appellation'; | |
static final List names = [ | |
'Anne', 'Mary', 'Jack', 'Morgan', 'Roger', | |
'Bill', 'Ragnar', 'Ed', 'John', 'Jane' ]; | |
static final List appellations = [ | |
'Jackal', 'King', 'Red', 'Stalwart', 'Axe', | |
'Young', 'Brave', 'Eager', 'Wily', 'Zesty']; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
background-color: #F8F8F8; | |
font-family: 'Open Sans', sans-serif; | |
font-size: 14px; | |
font-weight: normal; | |
line-height: 1.2em; | |
margin: 15px; | |
} | |
h1, p { | |
color: #333; | |
} | |
.widgets { | |
padding-bottom: 20pt; | |
float: left; | |
} | |
.badge { | |
border: 2px solid brown; | |
border-radius: 1em; | |
background: red; | |
font-size: 14pt; | |
width: 14em; | |
height: 7em; | |
text-align: center; | |
float: left; | |
margin-left: 20px; | |
white-space: nowrap; | |
overflow: hidden; | |
} | |
.greeting { | |
color: white; | |
font-family: sans-serif; | |
padding: 0.5em; | |
} | |
.name { | |
color: black; | |
background: white; | |
font-family: "Marker Felt", cursive; | |
font-size: 25pt; | |
padding-top: 1.0em; | |
padding-bottom: 0.7em; | |
height: 16px; | |
} | |
#generateButton { | |
font-size: 12pt; | |
margin-top: 20px; | |
} | |
input[type="text"] { | |
font-size: 12pt; | |
margin-top: 10pt; | |
margin-bottom: 10pt; | |
width: 12em; | |
} | |
@media all and (max-width: 500px) { | |
.badge { | |
margin-left: 0px; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment