public
Last active

How to make custom tweetboxes

  • Download Gist
custom-tweetbox.html
HTML
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
<div>
<h1>Tweetbox</h1>
<form id="my-tweetbox">
<p><textarea name="tweet">Write your tweet...</textarea></p>
<p><input type="submit" name="submit" value="Tweet!" /></p>
</form>
</div>
 
<div>
<h1>County Tweetbox</h1>
<form id="my-county-tweetbox">
<p><textarea name="tweet">Write your tweet...</textarea></p>
<p><input type="submit" name="submit" value="Tweet!" /></p>
<p id="county"></p>
</form>
</div>
 
<div>
<h1>Tweetbox w/ Reply</h1>
<form id="my-replyto-tweetbox">
<p><textarea name="tweet">Write your reply tweet...</textarea></p>
<p>Reply to: <input type="text" name="replyto" value="1234" /></p>
<p><input type="submit" name="submit" value="Reply" /></p>
</form>
</div>
 
<div>
<h1>Skinny</h1>
<form id="my-skinny-tweetbox">
<input type="text" name="tweet"/>
<input type="submit" name="submit" value="Tweet it" />
</form>
</div>
 
<div>
<h1>Tweet Button</h1>
<form id="my-tweetbutton">
<input type="hidden" name="tweet" value="Thank you @robcolburn for this script" />
<input type="submit" name="submit" value="Tweet 'Thank you @robcolburn for this script'" />
</form>
</div>
 
 
<!-- Fill in your App ID!! -->
<!-- We'll borrow Pet Monster's for now -->
<script src="//platform.twitter.com/anywhere.js?id=4MefUUvPXcQdIm30HhQ&v=1"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
// Careful, when trolling Anywhere source twttr !== window.twttr
 
// The twttr.anywhere does similar to FB.init, but you use it like jQuery.ready
twttr.anywhere(function(T) {
// The T object seems to be a subset of jQuery (or Ender)
// Includes Sizzle, Ajax, and some custom
$('#my-tweetbox').submit(function () {
var tweet = $(this).find('input[name=tweet]').val();
// T.requireConnect is similar to FB.login
// may spawn a pop-up, so be sure to fire from user-event
T.requireConnect(function() {
T.Status.update(tweet, {
success: function (tweet) {
// (-:
},
error: function (error) {
// )-:
}
});
});
return false;
});
$('#my-replyto-tweetbox').submit(function () {
var tweet = $(this).find('input[name=tweet]').val();
var replyto = $(this).find('input[name=replyto]').val();
T.requireConnect(function() {
T.Status.update(tweet, {
in_reply_to_status_id: replyto,
success: function (tweet) {
// (-:
},
error: function (error) {
// )-:
}
});
});
return false;
});
 
$('#my-skinny-tweetbox').submit(function () {
var tweet = $(this).find('input[name=tweet]').val();
// T.requireConnect is similar to FB.login
// may spawn a pop-up, so be sure to fire from user-event
T.requireConnect(function() {
T.Status.update(tweet, {
success: function (tweet) {
// (-:
},
error: function (error) {
// )-:
}
});
});
return false;
});
 
$('#my-county-tweetbox').submit(function () {
var tweet = $(this).find('input[name=tweet]').val();
// T.requireConnect is similar to FB.login
// may spawn a pop-up, so be sure to fire from user-event
T.requireConnect(function() {
T.Status.update(tweet, {
success: function (tweet) {
// (-:
},
error: function (error) {
// )-:
}
});
});
return false;
});
$('#my-county-tweetbox input[name=tweet]').keyup(function () {
var characters = $(this).val().length;
var left = 140 - characters;
if (left < 0) {
$('#county').val(MAX - characters).css('color', '#f00');
} else if (left < 20) {
$('#county').val(MAX - characters).css('color', '#fa0');
} else {
$('#county').val(MAX - characters).css('color', '#000');
}
});
$('#my-tweetbutton').submit(function () {
var tweet = $(this).find('input[name=tweet]').val();
T.requireConnect(function() {
T.Status.update(tweet, {
success: function (tweet) {
// (-:
},
error: function (error) {
// )-:
}
});
});
return false;
});
});
</script>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.