Team:TU Delft/fb display

From 2010.igem.org

(Difference between revisions)
 
(23 intermediate revisions not shown)
Line 1: Line 1:
-
<html>
+
<noinclude>
-
<div id="fb_scriptload"></div>
+
-
<div id="photobox"></div>
+
-
<script type="text/javascript">
+
This is a template page that displays random pictures from a facebook album.
 +
You can get the album ID by using [[Team:TU_Delft/fb_listalbums|fb_listalbums]]
-
var albumID = "</html>{{{album|133985909951582}}}<html>";
+
Either use this template or give credits to the TU Delft team!
 +
If you have questions, contact me: [[User:jcnossen|Jelmer Cnossen]]
-
function fb_photos(response) {
+
<br>
-
  var n = 10; // select 6 random pictures
+
<nowiki>{{:Team:TU_Delft/fb_display|album=ID|count=Number of images|css=CSS class}}</nowiki>
-
  var imghtml = "";
+
Parameters:
-
  var done={}, j=0, und;
+
album: Facebook album ID
 +
count: Number of pictures to display
 +
css: CSS class for each image
-
  while(j<n) {
+
</noinclude>
-
    var x = Math.round( Math.random()*response.data.length );
+
<html>
-
    if (und === done[x])
+
<div id="fb_scriptload</html>{{{album|135033906513449}}}<html>"></div>
-
      continue;
+
<div id="photobox</html>{{{album|135033906513449}}}<html>">loading facebook photo's...</div>
-
    done[x] = 1;
+
-
    var imgSmall = response.data[x].picture;
+
<style>
-
    imghtml += '<img src=\"'+imgSmall+'">';
+
.fb_photo</html>{{{album|135033906513449}}}<html> {
-
    j++;
+
margin: 4px 4px 4px 4px;
-
  }
+
-
  $("#photobox").html(imghtml);
+
}
}
 +
</style>
 +
<script type="text/javascript">
 +
 +
// needs to be global for jsonp invoke
 +
var fb_photos</html>{{{album|135033906513449}}}<html>;
$(function() {
$(function() {
 +
var albumID = "</html>{{{album|135033906513449}}}<html>";
var baseurl = "https://graph.facebook.com/";
var baseurl = "https://graph.facebook.com/";
 +
function addScript(url) {
function addScript(url) {
   var html = '<script src="'+ url + '" type="text/javascript"></scr'+'ipt>';
   var html = '<script src="'+ url + '" type="text/javascript"></scr'+'ipt>';
-
   $("#fb_scriptload").html(html);
+
   $("#fb_scriptload" + albumID).html(html);
}
}
function fetchPhotos() {
function fetchPhotos() {
-
   addScript(baseurl + "/" + albumID + "/photos?callback=fb_photos");
+
   addScript(baseurl + "/" + albumID + "/photos?callback=fb_photos"+albumID);
 +
}
 +
 
 +
fb_photos</html>{{{album|135033906513449}}}<html> = function (response) {
 +
  var n = </html>{{{count|6}}}<html>;
 +
  var imghtml = "";
 +
  var done={}, j=0, und;
 +
 
 +
  if(response.error) {
 +
    $("#photobox" + albumID).html("Facebook returned an error: " + response.error.message);
 +
    return;
 +
  }
 +
 
 +
  try {
 +
 
 +
  var remaining=response.data;
 +
  if (n>response.data.length)
 +
    n=response.data.length;
 +
 
 +
  while(j<n) {
 +
    var x = Math.floor( Math.random()*remaining.length );
 +
    x = Math.min(Math.max(0,x),remaining.length-1);
 +
 
 +
    var item = remaining.splice(x, 1)[0];
 +
    var imgSmall = item.picture;
 +
    imghtml += '<a href="'+ item.link +'"><img class="</html>{{{css|fb_photo135033906513449}}}<html>" src=\"'+imgSmall+'"></a>';
 +
    j++;
 +
  }
 +
  $("#photobox" + albumID).html(imghtml);
 +
  }
 +
  catch (err) {
 +
//    $("#photobox" + albumID).html("Error: " + err.description);
 +
    $("#photobox" + albumID).delay(400).queue(fetchPhotos);
 +
  }
}
}
-
fetchPhotos();
 
 +
$("#photobox" + albumID).click(fetchPhotos).delay(300).queue(fetchPhotos);
});
});
</script>
</script>
</html>
</html>

Latest revision as of 10:57, 7 October 2010


This is a template page that displays random pictures from a facebook album. You can get the album ID by using fb_listalbums

Either use this template or give credits to the TU Delft team! If you have questions, contact me: Jelmer Cnossen


{{:Team:TU_Delft/fb_display|album=ID|count=Number of images|css=CSS class}}
Parameters: 
album: Facebook album ID
count: Number of pictures to display
css: CSS class for each image


loading facebook photo's...