Hi,
i got some (thanks a ot!) help in another
thread with putting together a facebook picture function.
Now a have a function that gets x-amount of instagram pictures + x amount of tweets. id like to shuffle these 2 before i output them in my container. So in other words i think that combining all functions might be the best solution (I THINK), which i dont manage to do my self.
When i output them now they are all in a fixed structure.
like this:
instagram
twitter
id like it to be random:
instagram
twitter
twitter
twitter
- /*******************************
- Instagram J
- ******************************/
- $.ajax({
- type: "GET",
- dataType: "jsonp",
- cache: false,
- url: "https://api.instagram.com/v1/users/178173879/media/recent/?access_token=178173879.e651f2a.16d3f37736f24149b6cca8b03e2ace79",
- success: function(data) {
-
- for (var i = 0; i < 10; i++) {
- maxWidth = Math.floor(10 + (Math.random() * 250));
- $("#container_content").append("<div class='instagram jakob item'> <img src='" + data.data[i].images.low_resolution.url +"' width='" + maxWidth + "' /></img></div>");
- }
- }
- });
- /*******************************
- Twitter
- ******************************/
-
- var user = 'tesla';
-
- $.getJSON('http://twitter.com/statuses/user_timeline.json?screen_name=' + user + '&count=5&callback=?', function(data) {
-
-
- var tweet = "";
- for (i = 0; i < data.length; i++) {
- maxWidth = Math.floor(10 + (Math.random() * 250));
- tweet += "<div class='tweet item' width="+ maxWidth +">" + data[i].text + "</div>";
- }
-
-
- tweet = tweet.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, function(url) {
- return '<a target="_blank" href="'+url+'">'+url+'</a>';
- }).replace(/B@([_a-z0-9]+)/ig, function(reply) {
- return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
- });
-
-
- $("#container_content").append(tweet);
- });
- /*******************************
- shuffle
- ******************************/
- function shuffle(arr) {
- for(
- var j, x, i = arr.length;
- i;
- j = Math.floor(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x
- );
- return arr;
- }
- $(function(){
- var the_divs = $('.item').get() // gets you an array of divs.
- shuffle(the_divs)
- $.each(the_divs,function(i,v){
- $(v).appendTo("#container_content") // or wherever you want them to go!
- })
- })