Sha256: 2e3eabe8f4c48c3aa3733da936fe959d2e014a2f5c6574d4d8679565f710a92b

Contents?: true

Size: 1.78 KB

Versions: 8

Compression:

Stored size: 1.78 KB

Contents

/*
 * 	Character Count Plugin - jQuery plugin
 * 	Dynamic character count for text areas and input fields
 *	written by Alen Grakalic
 *	http://cssglobe.com/post/7161/jquery-plugin-simplest-twitterlike-dynamic-character-count-for-textareas
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */

(function($) {

    $.fn.charCount = function(options){

        // default configuration properties
        var defaults = {
            allowed: 140,
            warning: 25,
            css: 'counter',
            counterElement: 'span',
            cssWarning: 'warning',
            cssExceeded: 'exceeded',
            counterText: ''
        };

        var options = $.extend(defaults, options);

        function calculate(obj){
            var count = $(obj).val().length;
            var available = options.allowed - count;
            if(available <= options.warning && available >= 0){
                $(obj).next().addClass(options.cssWarning);
            } else {
                $(obj).next().removeClass(options.cssWarning);
            }
            if(available < 0){
                $(obj).next().addClass(options.cssExceeded);
            } else {
                $(obj).next().removeClass(options.cssExceeded);
            }
            $(obj).next().html(options.counterText + available);
        };

        this.each(function() {
            $(this).after('<'+ options.counterElement +' class="' + options.css + '">'+ options.counterText +'</'+ options.counterElement +'>');
            calculate(this);
            $(this).keyup(function(){calculate(this)});
            $(this).change(function(){calculate(this)});
        });

    };

})(jQuery);

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cg_app_base-1.1.1 app/assets/javascripts/flatty/plugins/charCount/charCount.js
cg_app_base-1.0.78 app/assets/javascripts/flatty/plugins/charCount/charCount.js
cg_app_base-1.0.62 app/assets/javascripts/flatty/plugins/charCount/charCount.js
cg_app_base-1.0.56 app/assets/javascripts/flatty/plugins/charCount/charCount.js
cg_app_base-1.0.55 app/assets/javascripts/flatty/plugins/charCount/charCount.js
cg_app_base-1.0.54 app/assets/javascripts/flatty/plugins/charCount/charCount.js
cg_app_base-1.0.52 app/assets/javascripts/flatty/plugins/charCount/charCount.js
cg_app_base-1.0.51 app/assets/javascripts/flatty/plugins/charCount/charCount.js