Skip to content

Commit

Permalink
added click on image to get current details
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Sep 29, 2012
1 parent 83e39d1 commit 4e3fdbf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
11 changes: 11 additions & 0 deletions frontend/routes/home.js
@@ -1,3 +1,4 @@
var request = require('request');


module.exports = function (app, nconf, serviceBusService) { module.exports = function (app, nconf, serviceBusService) {


Expand All @@ -11,4 +12,14 @@ module.exports = function (app, nconf, serviceBusService) {
console.log(req.params.city); console.log(req.params.city);
res.render('images.html'); 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);
});
});
} }
19 changes: 16 additions & 3 deletions frontend/views/images.html
Expand Up @@ -8,6 +8,7 @@
<script> <script>
$(function () { $(function () {
var socket = io.connect(); var socket = io.connect();

socket.on('connect', function () { socket.on('connect', function () {
var city = ''; var city = '';
var urlParts = window.location.href.split("/"); var urlParts = window.location.href.split("/");
Expand All @@ -24,15 +25,27 @@
socket.emit('setCity', { city: city }); socket.emit('setCity', { city: city });
} }
}); });

socket.on('newPic', function (pic) { socket.on('newPic', function (pic) {
console.log('got a new pic!!!') console.log('got a new pic!!!')
var p = JSON.parse(pic); var p = JSON.parse(pic);
console.log(p); console.log(p);
for (var i = 0; i< p.data.length; i++ ) { for (var i = 0; i < p.data.length; i++) {
$("#pics").append($("<img src=\"" + p.data[i].images.low_resolution.url + "\">")); $("#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> </script>
</head> </head>
<body> <body>
Expand Down

0 comments on commit 4e3fdbf

Please sign in to comment.