jQuery Plugin: textarea max length

by nickadeemus2002

HTML

<textarea id="mainText" name="mainText" rows="3" cols="25"/>

JavaScript

/* 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' ||...