Skip to content

Instantly share code, notes, and snippets.

@dave1010
Created October 1, 2010 18:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dave1010/606600 to your computer and use it in GitHub Desktop.
Save dave1010/606600 to your computer and use it in GitHub Desktop.
jQuery.fn.twtShrt
/**
* Make a form field shorten text as you type
* Made for keeping tweets < 140 chrs
* Usage: $('textarea').twtShrt();
* @author dave1010
*/
jQuery.fn.twtShrt = function() {
var o = [
"seriously","have to", "what is", "done", "oh my god", "oh my gosh", "face to face", "for the win", "for the loss", "in real life", "your mileage may vary", "best regards", "joint venture", "let me know", "not safe for work", "are you ok", "tomorrow", "as soon as possible", "be right back", "be back later", "be back soon", "at the moment", "by the way", "in my honest opinion", "tata for now", "as known as", "also known as", "see you later", "see you", "for your information", "in my opinion", "too good to be true", "best friends forever", "best friend forever", "best friends", "best friend", "definitely", "been", "hello", "i am", "night", "when", "some", "to", "speak", "you", "your", "for", "friend", "people", "see", "be", "and", "&", "anyone", "because", "are", "bate", "date", "fate", "great", "hate", "late", "mate", "rate", "why", "week", "thinking", "true", "thanks", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "could", "click", "check", "favourite", "fabulous", "forward", "it is", "should", "would", "what", "birthday", "overheard", "right", "that", "what", "christmas", "year"
],
n = [
"srsly", "hav2", "wats", "dun", "omg", "omg", "F2F", "FTW", "FTL", "IRL", "YMMV", "BR", "JV", "LMK", "NSFW", "ruok", "2moro", "ASAP", "brb", "bbl", "bbs", "atm", "BTW", "IMHO", "TTFN", "AKA", "AKA", "CUL8R", "CU", "FYI", "IMO", "TGTBT", "bff", "bff", "bf", "bf", "deffo", "bin", "hi", "i'm", "nite", "wen", "sum", "2", "spk", "u", "ur", "4", "frnd", "ppl", "C", "B", "n", "n", "ne1", "cos", "r", "b8", "d8", "f8", "gr8", "h8", "l8", "m8", "r8", "y", "wk", "thinkin", "tru", "thanx", "1", "2", "3", "4", "5", "6", "7", "8", "9", "cld", "clk", "chk", "fave", "fab", "fwd", "its", "shld", "wld", "wat", "bday", "OH", "rite", "dat", "wat", "xmas", "yr"
];
return this.each(function() {
jQuery(this).keyup(function(e) {
var t = jQuery(this);
if (e.keyCode == 32) { // todo: add other keyCodes
var v = t.val();
for (var i in o) {
v = v.replace(o[i], n[i]); // todo: regex \b
}
t.val(v);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment