Created
September 3, 2014 23:39
-
-
Save tnylea/c3694da98b1981fe251d to your computer and use it in GitHub Desktop.
Polymer Imgur Gallery Element
This file contains 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
<link rel="import" href="../bower_components/polymer/polymer.html"> | |
<link rel="import" href="../bower_components/core-ajax/core-ajax.html"> | |
<polymer-element name="app-imgur" noscript> | |
<template> | |
<style> | |
:host { | |
* { | |
padding: 0; | |
margin: 0; | |
float: left; | |
} | |
} | |
.imgur { | |
float: left; | |
height: 100%; | |
width: 100%; | |
margin-bottom: 50px; | |
} | |
.item { | |
float: left; | |
margin: 0; | |
padding: 0; | |
width:18%; | |
margin:0.5%; | |
padding:0.5%; | |
background:#eee; | |
max-height:220px; | |
min-height:220px; | |
overflow:hidden; | |
} | |
.item img { | |
float: left; | |
width: 100%; | |
max-width: 100%; | |
} | |
</style> | |
<core-ajax url="https://api.imgur.com/3/gallery/{{section}}/{{sort}}/{{window}}/{{page}}?showViral={{showViral}}" | |
id="imgur" | |
handleAs="json" | |
on-core-response="{{handleResponse}}"></core-ajax> | |
<div class="imgur"> | |
<template id="image" repeat="{{item in images}}" index="i"> | |
<template bind if="{{ !item.is_album }}"> | |
<div class="item"> | |
<a href="http://imgur.com/gallery/{{item.id}}" target="_blank"> | |
<img src="{{item.link}}" /> | |
</a> | |
</div> | |
</template> | |
</template> | |
</div> | |
</template> | |
<script> | |
Polymer('app-imgur', { | |
publish: { | |
section: { value: 'hot', reflect: true }, | |
sort: { value: 'viral', reflect: true }, | |
page: { value: '1', reflect: true }, | |
window: { value: '', reflect: true }, | |
showViral: { value: 'true', reflect: true }, | |
clientId: { value: '', reflect: true } | |
}, | |
ready: function() { | |
this.$.imgur.headers = { "Authorization": "Client-ID " + this.clientId }; | |
this.$.imgur.go(); | |
}, | |
handleResponse: function(evt, res){ | |
this.images = res.response.data; | |
} | |
}); | |
</script> | |
</polymer-element> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment