1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| function installButtonHandlers(stitle,title)
{
// the direct message to @user callback
$(stitle + " .directMsgButton").click( function(){
if( title == 'DirectMessages') // if we are already displaying direct messages, ignore this
return;
if( title == 'Timeline'){ // Display all direct messages sent to and from current user
twttr.anywhere(function (T) {
displayPageLoadingIndicator();
T.User.current().directMessages( {count:50, success:function(receiveDMs){
T.User.current().sentMessages( {count:50, success:function(sentDMs){
$.mobile.pageLoading(true);
var myReceiveDMs = receiveDMs.array;
var newArray = myReceiveDMs.concat(sentDMs.array);
var nowDate = new Date();
newArray.sort( function (a,b) {
var createdDateA = new Date(a.createdAt);
var createdDateB = new Date(b.createdAt);
var diffA = nowDate - createdDateA;
var diffB = nowDate - createdDateB;
return diffA - diffB;
});
updateStatusPage(T, newArray, "DirectMessages");
}});
}});
});
return false;
}
else { // send a Direct message to this user
sendMessage("Direct Message to " + $(this).attr("status_id"), $(this).attr("status_id"), function(id,msg){
twttr.anywhere(function (T) {
T.DirectMessage.send( id.substr(1,id.length - 1), msg, {success: function(){
goBack();
}, error:function(){
alert("Error sending message to " + id);
goBack();
}});
});
return false;
});
return false;
}
});
// the public reply to @user callback
$(stitle + " .publicReplyButton").click( function(){
sendMessage("Reply to " + $(this).attr("status_id"), $(this).attr("status_id"), function(id,msg){
twttr.anywhere(function (T) {
T.Status.reply( 0, msg, {success: function(){
goBack();
}, error:function(){
alert("Error sending message to " + id);
goBack();
}});
});
return false;
}, $(this).attr("status_id") + " ");
return false;
});
// the user's profile callback
$(stitle + " .profileButton").click( function(){
profile($(this).attr("status_id"));
return false;
});
// the tweet button callback
$(stitle + " .sendTweetButton").click( function(){
alert("Appel fonction d'envoi de tweets");
sendMessage("Tweet about open days 2011 or about a demo", $(this).attr("status_id"), function(id,msg){
twttr.anywhere(function (T) {
T.Status.update( msg, {success: function(){alert("Your tweet has been sent ;)");
}, error:function(){
alert("Error sending tweet");
}});
});
return false;
});
return false;
});
// logout button callback
$(stitle + " .logoutButton").click( function(){
twttr.anywhere.signOut();
return false;
});
} |
Partager