a1b93f256d
completes #64
25 lines
626 B
JavaScript
25 lines
626 B
JavaScript
$.fn.extend({
|
|
characterLimiter: function(limit, $label) {
|
|
$(this).on("keyup focus show", function() {
|
|
setCount(this, $label);
|
|
});
|
|
|
|
// TODO: append label container after $this, instead of hard codeing
|
|
function setCount(src, $label) {
|
|
if(src !== undefined) {
|
|
var chars = src.value.length;
|
|
if (chars >= limit) {
|
|
src.value = src.value.substr(0, limit);
|
|
chars = limit;
|
|
}
|
|
$label.html(limit - chars);
|
|
}
|
|
}
|
|
setCount($(this)[0], $label);
|
|
}
|
|
});
|
|
|
|
$(document).ready(function() {
|
|
$('textarea').characterLimiter(1000, $(".chars span"));
|
|
});
|