Created
July 2, 2014 12:32
-
-
Save gongo/248e0bd29de9af9663a1 to your computer and use it in GitHub Desktop.
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
new Vue({ | |
el: '#main', | |
created: function() { | |
var vm = this; | |
superagent.get('https://api.github.com/emojis', function(response) { | |
vm.emojis = response.body; | |
}); | |
}, | |
methods: { | |
search: function() { | |
var vm = this; | |
var keywords = this.searchText.split(' '); | |
vm.searchedEmojis.length = 0; | |
keywords.forEach(function(name) { | |
var emojiUrl = vm.emojis[name]; | |
var data; | |
if (emojiUrl) { | |
data = { name: name, url: emojiUrl }; | |
} else { | |
data = { name: null, url: null }; | |
} | |
vm.searchedEmojis.push(data); | |
}); | |
} | |
}, | |
data: { | |
emojis: [], | |
searchText: '', | |
searchedEmojis: [] | |
} | |
}); |
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
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/0.10.5/vue.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/superagent/0.15.7/superagent.min.js"></script> | |
</head> | |
<body> | |
<div id="main" class="container"> | |
<div class="page-header"> | |
<h1>Search Emoji</h1> | |
</div> | |
<p> | |
Input search emoji name: | |
<input type="text" v-model="searchText" v-on="keyup:search" /> | |
</p> | |
<label> | |
<input type="checkbox" v-model="isShowImage" checked="checked"> Image | |
</label> | |
<label> | |
<input type="checkbox" v-model="isShowName" checked="checked"> Name | |
</label> | |
<label> | |
<input type="checkbox" v-model="isShowUrl" checked="checked"> URL | |
</label> | |
<table class="table"> | |
<tbody> | |
<tr v-repeat="searchedEmojis"> | |
<td v-show="isShowImage"><img v-attr="src:url" /></td> | |
<td v-show="isShowName">{{ name }}</td> | |
<td v-show="isShowUrl">{{ url }}</td> | |
</tr> | |
</tbody> | |
</table> | |
</div> | |
<script src="./app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment