2016-09-01 10:37:49 -05:00
|
|
|
$.fn.extend({
|
|
|
|
characterLimiter: function(limit, $label) {
|
|
|
|
$(this).on("keyup focus show", function() {
|
|
|
|
setCount(this, $label);
|
|
|
|
});
|
2016-07-29 08:57:28 -05:00
|
|
|
|
2016-09-01 10:37:49 -05:00
|
|
|
// 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;
|
2016-08-09 11:36:52 -05:00
|
|
|
}
|
2016-09-01 10:37:49 -05:00
|
|
|
$label.html(limit - chars);
|
2016-08-09 11:36:52 -05:00
|
|
|
}
|
2016-09-01 10:37:49 -05:00
|
|
|
}
|
|
|
|
setCount($(this)[0], $label);
|
2016-08-09 11:36:52 -05:00
|
|
|
}
|
|
|
|
});
|
2016-09-01 10:37:49 -05:00
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
$('textarea').characterLimiter(1000, $(".chars span"));
|
|
|
|
});
|