Skip to content

Commit

Permalink
Add Emoji Info and Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
azenla committed Aug 24, 2014
1 parent 305d1bc commit 9ac77b3
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
42 changes: 42 additions & 0 deletions example/emoji.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import "dart:html";

import "package:github/browser.dart";
import "common.dart";

GitHub github;
DivElement $emoji;

void main() {
initGitHub();
init("emoji.dart", onReady: () {
$emoji = querySelector("#emojis");
loadEmojis();
});
}

void loadEmojis() {
var token = "5fdec2b77527eae85f188b7b2bfeeda170f26883";
var url = window.location.href;

if (url.contains("?")) {
var params = Uri.splitQueryString(url.substring(url.indexOf('?') + 1));

if (params.containsKey("token")) {
token = params["token"];
}
}

github = new GitHub(auth: new Authentication.withToken(token));

github.emojis().then((info) {
info.forEach((name, url) {
var h = new DivElement();
h.classes.add("box");
h.classes.add("emoji-box");
h.style.textAlign = "center";
h.append(new ImageElement(src: url, width: 64, height: 64)..classes.add("emoji"));
h.append(new ParagraphElement()..text = name);
$emoji.append(h);
});
});
}
43 changes: 43 additions & 0 deletions example/emoji.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>

<head>
<title>GitHub Emoji</title>

<style>
.line {
border-top: 1px;
border-style: solid;
}

.box {
border: 2px solid;
}

.emoji-box {
display: inline-block;
margin-top: 5px;
margin-left: 5px;
width: 256px;
}

.emoji {
margin-top: 5px;
}
</style>
</head>

<body>
<div class="header">
<h1>GitHub Emoji</h1>
<button id="view-source">View the Source</button>
<p></p>
</div>

<div id="emojis"></div>

<script type="application/dart" src="emoji.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>

</html>
9 changes: 9 additions & 0 deletions lib/src/common/github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,15 @@ class GitHub {
return input.map((it) => User.fromJSON(github, it));
});
}

/**
* Fetches all emojis available on GitHub
*
* Returns a map of the name to a url of the image.
*/
Future<Map<String, String>> emojis() {
return getJSON("/emojis", statusCode: 200);
}

/**
* Fetches repositories that the current user is watching. If [user] is specified, it will get the watched repositories for that user.
Expand Down

0 comments on commit 9ac77b3

Please sign in to comment.