Permalink
Browse files

added click on image to get current details

  • Loading branch information...
1 parent 83e39d1 commit 4e3fdbfe04f6ed4d1951950c5b31f21d3f1339dd @JustinBeckwith committed Sep 29, 2012
Showing with 27 additions and 3 deletions.
  1. +11 −0 frontend/routes/home.js
  2. +16 −3 frontend/views/images.html
View
@@ -1,3 +1,4 @@
+var request = require('request');
module.exports = function (app, nconf, serviceBusService) {
@@ -11,4 +12,14 @@ module.exports = function (app, nconf, serviceBusService) {
console.log(req.params.city);
res.render('images.html');
});
+
+ // service calls to get media details
+ app.get('/media/:id', function (req, res) {
+ console.log('request for media: ' + req.params.id);
+ var url = "https://api.instagram.com/v1/media/" + req.params.id + "/?client_id=" + nconf.get('instagramClientId');
+ console.log(url);
+ request(url, function (e, r, b) {
+ res.end(b);
+ });
+ });
}
View
@@ -8,6 +8,7 @@
<script>
$(function () {
var socket = io.connect();
+
socket.on('connect', function () {
var city = '';
var urlParts = window.location.href.split("/");
@@ -24,15 +25,27 @@
socket.emit('setCity', { city: city });
}
});
+
socket.on('newPic', function (pic) {
console.log('got a new pic!!!')
var p = JSON.parse(pic);
console.log(p);
- for (var i = 0; i< p.data.length; i++ ) {
- $("#pics").append($("<img src=\"" + p.data[i].images.low_resolution.url + "\">"));
+ for (var i = 0; i < p.data.length; i++) {
+ $("#pics").prepend($("<img data-id=\"" + p.data[i].id + "\" src=\"" + p.data[i].images.low_resolution.url + "\">"));
}
});
- })
+
+
+ $("#pics").on("click", "img", function () {
+
+ var id = $(this).data("id");
+ console.log(id);
+ $.ajax("/media/" + id).done(function (data) {
+ console.log(data);
+ });
+ });
+
+ });
</script>
</head>
<body>

0 comments on commit 4e3fdbf

Please sign in to comment.