/* http://keith-wood.name/maxlength.html
Textarea Max Length for jQuery v1.0.1.
Written by Keith Wood (kwood{at}iinet.com.au) May 2009.
Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and
MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses.
Please attribute the author if you use it. */
(function($) { // Hide scope, no $ conflict
var PROP_NAME = 'maxlength';
/* Max length manager. */
function MaxLength() {
this._defaults = {
max: 200, // Maximum length
showFeedback: true, // True to show user feedback
feedbackText: '{r} characters remaining ({m} maximum)'
// Display text for feedback message, use {r} for remaining characters,
// {c} for characters entered, {m} for maximum
};
}
$.extend(MaxLength.prototype, {
/* Class name added to elements to indicate already configured with max length. */
markerClassName: 'hasMaxLength',
/* Class name for the feedback section. */
_feedbackClass: 'maxlength-feedback',
/* Override the default settings for all max length instances.
@param settings (object) the new settings to use as defaults
@return (MaxLength) this object */
setDefaults: function(settings) {
$.extend(this._defaults, settings || {});
return this;
},
/* Attach the max length functionality to a textarea.
@param target (element) the control to affect
@param settings (object) the custom options for this instance */
_attachMaxLength: function(target, settings) {
target = $(target);
if (target.hasClass(this.markerClassName)) {
return;
}
target.addClass(this.markerClassName).
bind('keypress.maxlength', function(event) {
var ch = String.fromCharCode(
event.charCode == undefined ? event.keyCode : event.charCode);
return (ch == '\u0000' ||...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.