-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtweetable.js
25 lines (22 loc) · 926 Bytes
/
tweetable.js
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
$(document).ready(function() {
function doCallback() {
var user = $(this).data('user');
var text = "\"" + ($(this).data('message') || $(this).text()) + "\" " + window.location.href + (user ? " via @" + $(this).data('user') : '');
var original_start = new Date();
var lag = 1250;
var deeplink_url = "twitter://post?message=" + encodeURIComponent(text);
window.location.href = deeplink_url;
setTimeout(function() {
var time_spent_waiting = (new Date() - original_start);
if (time_spent_waiting > (2.0 * lag)) {
// We can assume they have the app, so do nothing.
} else {
// That was too fast so we can assume they don't have the app.
var intent_url = "https://twitter.com/intent/tweet?text=" + encodeURIComponent(text);
window.open(intent_url, "_blank");
}
}, lag);
return false;
}
$(".tweetable").on("click", doCallback);
});