skill-assessment-app/app/assets/javascripts/textarea-limit.js
2016-08-09 12:25:07 -05:00

29 lines
684 B
JavaScript

$(document).ready(function() {
setTextAreaLimit();
function setTextAreaLimit() {
$.fn.extend({
limiter: function(limit, elem) {
$('textarea').on("keyup focus show", function() {
setCount(this, elem);
});
function setCount(src, elem) {
if(src !== undefined) {
var chars = src.value.length;
if (chars > limit) {
src.value = src.value.substr(0, limit);
chars = limit;
}
elem.html(limit - chars);
}
}
setCount($(this)[0], elem);
}
});
var elem = $(".chars span");
$('textarea').limiter(1000, elem);
}
});