@ -1,28 +1,24 @@
|
||||
$(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);
|
||||
}
|
||||
$.fn.extend({
|
||||
characterLimiter: function(limit, $label) {
|
||||
$(this).on("keyup focus show", function() {
|
||||
setCount(this, $label);
|
||||
});
|
||||
|
||||
var elem = $(".chars span");
|
||||
$('textarea').limiter(1000, elem);
|
||||
// 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"));
|
||||
});
|
||||
|
Reference in New Issue
Block a user