(function(b) { b.fn.extend({ counter: function(a) { a = b.extend({}, { type: "char", count: "down", goal: 140 }, a); var d = false; return this.each(function() { function e(c) { if (typeof a.type === "string") switch (a.type) { case "char": if (a.count === "down") { g = " kalan karakter "; return a.goal - c } else if (a.count === "up") { g = " character (" + a.goal + " maximum)"; return c } break; case "word": if (a.count === "down") { g = " word(s) left"; return a.goal - c } else if (a.count === "up") { g = " words (" + a.goal + " max)"; return c } break; default: } } var g, f = b(this); b('
' + e(b(f).val().length) + "" + g + "
").insertAfter(f); var i = b("#" + this.id + "_counter span"); f.bind("keyup click blur focus change paste", function(c) { switch (a.type) { case "char": c = b(f).val().length; break; case "word": c = f.val() === "" ? 0 : b.trim(f.val()).replace(/\s+/g, " ").split(" ").length; break; default: } switch (a.count) { case "up": if (e(c) >= a.goal && a.type === "char") { b(this).val(b(this).val().substring(0, a.goal)); d = true; break } if (e(c) === a.goal && a.type === "word") { d = true; break } else if (e(c) > a.goal && a.type === "word") { b(this).val(""); i.text("0"); d = true; break } break; case "down": if (e(c) <= 0 && a.type === "char") { b(this).val(b(this).val().substring(0, a.goal)); d = true; break } if (e(c) === 0 && a.type === "word") d = true; else if (e(c) < 0 && a.type === "word") { b(this).val(""); d = true; break } break; default: } f.keydown(function(h) { if (d) { this.focus(); if (h.keyCode !== 46 && h.keyCode !== 8) if (b(this).val().length > a.goal && a.type === "char") { b(this).val(b(this).val().substring(0, a.goal)); return false } else return h.keyCode !== 32 && h.keyCode !== 8 && a.type === "word" ? true : false; else { d = false; return true } } }); i.text(e(c)) }) }) } }) })(jQuery);