Created
October 11, 2012 17:38
-
-
Save joeoravec/3874177 to your computer and use it in GitHub Desktop.
jQuery, handlebars, and quote bubble styling
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 { | |
| font-family: Arial, Helvetica, sans-serif; | |
| font-size: 1em; | |
| } | |
| img { float: left; padding: 0.5em 0.5em 0 0; } | |
| a { text-decoration: none; color: #fff; } | |
| blockquote { | |
| position: relative; | |
| margin: 0; | |
| padding: 10px; | |
| width: 300px; | |
| background: #00acee; | |
| background: -webkit-gradient(linear, 0 0, 20% 100%, from(#00acee), to(#0184b6)); | |
| background: -moz-linear-gradient(#00acee, #0184b6); | |
| background: -o-linear-gradient(#00acee, #0184b6); | |
| background: linear-gradient(#00acee, #0184b6); | |
| -webkit-border-radius: 20px; | |
| -moz-border-radius: 20px; | |
| border-radius: 20px; | |
| border: 2px solid #0184b6; | |
| } | |
| blockquote p { | |
| font-size: 1.0em; | |
| color: #fff; | |
| margin: 5px; | |
| z-index: 10; | |
| position: relative; | |
| } | |
| blockquote + cite { | |
| font-size: 0.8em; | |
| display: block; | |
| margin: 0.5em 0 1em 5em; | |
| } | |
| blockquote:after { | |
| content: ""; | |
| position: absolute; | |
| z-index: 1; | |
| bottom: -20px; | |
| left: 30px; | |
| border-width: 0 30px 20px 0px; | |
| border-style: solid; | |
| border-color: transparent #0184b6; | |
| display: block; | |
| width: 0; | |
| } |
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> | |
| <link rel="stylesheet" href="quote.css"> | |
| </head> | |
| <body> | |
| <p>A sample combining a few pieces:</p> | |
| <ul> | |
| <li>jQuery access of Twitter API (adapted from Tuts+ 30 Days to Learn jQuery);</li> | |
| <li>Basic templating using Handlebars.js (adapted from same source); and </li> | |
| <li>Quote bubble styling (adapted from book Web Development Recipes)</li> | |
| </ul> | |
| <p>ToDo: convert jquery code to plugin</p> | |
| <div id="container-tweets"> | |
| <script id="tweets-template" type="text/x-handlebars-template"> | |
| {{#each this}} | |
| <blockquote> | |
| <img src="{{thumb}}" alt="{{author}}"> | |
| <p><a href="{{url}}">{{tweet}}</a></p> | |
| </blockquote> | |
| <cite>@{{author}}</cite> | |
| {{/each}} | |
| </script> | |
| </div> | |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
| <script src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js"></script> | |
| <script src="quote.js"></script> | |
| </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
| (function() { | |
| var Twitter = { | |
| init: function(config) { | |
| this.url = 'http://search.twitter.com/search.json?q=' + config.query + '&rpp=' + config.rpp + '&callback=?'; | |
| this.template = config.template; | |
| this.container = config.container; | |
| this.fetch(); | |
| }, | |
| attachTemplate: function() { | |
| var template = Handlebars.compile(this.template); | |
| this.container.append(template(this.tweets)); | |
| }, | |
| fetch: function() { | |
| var self = this; | |
| $.getJSON(this.url, function(data) { | |
| self.tweets = $.map(data.results, function(tweet) { | |
| return { | |
| author: tweet.from_user, | |
| tweet: tweet.text, | |
| thumb: tweet.profile_image_url, | |
| url: 'http://twitter.com/' + tweet.from_user + '/status/' + tweet.id_str | |
| }; | |
| }); | |
| self.attachTemplate(); | |
| }); | |
| } | |
| }; | |
| Twitter.init({ | |
| template: $('#tweets-template').html(), | |
| container: $('#container-tweets'), | |
| query: 'backbone.js', | |
| rpp: '5' | |
| }); | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A sample combining a few pieces:
ToDo: convert jquery code to plugin