Skip to content

Instantly share code, notes, and snippets.

@Sfshaza
Last active June 27, 2018 15:08
Show Gist options
  • Save Sfshaza/8640071ecb67b1309938 to your computer and use it in GitHub Desktop.
Save Sfshaza/8640071ecb67b1309938 to your computer and use it in GitHub Desktop.
portmanteaux_simple
<!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>Portmanteaux</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>Portmanteaux</h1>
<button id="getWords">Get portmanteaux</button>
<ul id="wordList">
</ul>
</body>
</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.
import 'dart:async';
import 'dart:convert';
import 'dart:html';
var wordList;
void main() {
querySelector('#getWords').onClick.listen(makeRequest);
wordList = querySelector('#wordList');
}
Future makeRequest(Event e) async {
var path = 'https://www.dartlang.org/f/portmanteaux.json';
try {
processString(await HttpRequest.getString(path));
} catch (e) {
print('Couldn\'t open $path');
handleError(e);
}
}
processString(String jsonString) {
List<String> portmanteaux = JSON.decode(jsonString);
for (int i = 0; i < portmanteaux.length; i++) {
wordList.children.add(new LIElement()..text = portmanteaux[i]);
}
}
handleError(Object error) {
wordList.children.add(new LIElement()..text = 'Request failed.');
}
body {
background-color: #F8F8F8;
font-family: 'Open Sans', sans-serif;
font-size: 14px;
font-weight: normal;
line-height: 1.2em;
margin: 15px;
}
h1, p, li {
color: #333;
}
#sample_container_id {
width: 100%;
height: 400px;
position: relative;
border: 1px solid #ccc;
background-color: #fff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment