Created
October 1, 2010 18:07
-
-
Save dave1010/606600 to your computer and use it in GitHub Desktop.
jQuery.fn.twtShrt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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