client/player/test/emission_fichiers/fc_widget_twitter.js
author wakimd
Tue, 16 Nov 2010 14:15:07 +0100
changeset 9 22ab430e9b64
permissions -rw-r--r--
Corrections on models and general structure
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     1
function twitterCallback2(twitters) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     2
  var statusHTML = [];
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     3
  var username = "";
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     4
  for (var i=0; i<twitters.length; i++){  
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     5
	username = twitters[i].user.screen_name;
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     6
    var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     7
      return '<a href="'+url+'">'+url+'</a>';
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     8
    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
     9
      return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    10
    });
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    11
    statusHTML.push('<li><span>'+status+'</span><a style="font-size:85%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id+'">'+relative_time(twitters[i].created_at)+'</a></li>');
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    12
  }
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    13
  document.getElementById('twitter_update_list_'+username).innerHTML = statusHTML.join('');
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    14
}
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    15
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    16
function relative_time(time_value) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    17
	  var values = time_value.split(" ");
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    18
	  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    19
	  var parsed_date = Date.parse(time_value);
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    20
	  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    21
	  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    22
	  delta = delta + (relative_to.getTimezoneOffset() * 60);
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    23
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    24
	  if (delta < 60) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    25
	    return " il y a moins d'une minute";
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    26
	  } else if(delta < 120) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    27
	    return ' il y a une minute';
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    28
	  } else if(delta < (60*60)) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    29
	    return ' il y a '+(parseInt(delta / 60)).toString() + ' minutes ';
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    30
	  } else if(delta < (120*60)) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    31
	    return ' il y a une heure';
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    32
	  } else if(delta < (24*60*60)) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    33
	    return ' il y a ' + (parseInt(delta / 3600)).toString() + ' heures';
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    34
	  } else if(delta < (48*60*60)) {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    35
	    return ' il y a un jour';
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    36
	  } else {
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    37
	    return ' il y a '+(parseInt(delta / 86400)).toString() + ' jours';
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    38
	  }
22ab430e9b64 Corrections on models and general structure
wakimd
parents:
diff changeset
    39
	}