Coder Social home page Coder Social logo

jquery-textareacounter's Introduction

jQuery TextareaCounter

https://travis-ci.org/LeadSift/jquery-textareaCounter.png https://coveralls.io/repos/LeadSift/jquery-textareaCounter/badge.png?branch=master

Forked from http://roy-jin.appspot.com/jsp/textareaCounter.jsp

Examples

Examples of usage can be seen in example/index.html.

Config Options

Options Description
maxCharacterSize Define the maximum number of characters. Default is -1. Limit characters only when maxCharacterSize > 0 default: -1
truncate Truncate the chars if maxCharachterSize exceeded default: true
originalStyle Set original class style default: 'originalTextareaInfo'
warningStyle Set warning class style If number of characters of user input is over the warning default: 'warningTextareaInfo'
errorStyle Set error class style, triggers if truncate is false and there are more than max chars in the text area default: 'errorTextareaInfo'
warningNumber char remaining before warningStyle is applied default: 20
displayFormat

keywords: #input, #max, #left, #words.

  • #input: current number of input chars
  • #max: represents your predefined max
  • #left: #max - #input
  • #words: represents your current number of words

default: '#input characters and #words words', note: #max and #left does work only when maxCharacterSize > 0

charCounter

a function or string naming a builtin charCounter func that will be used to count characters ... the func should accept a single parameter which is the content string.

the current builtins are:

'twitter'
counts each url in the input as 22 chars
'standard'
standard content.length count

default: 'standard'

Display Callback

You may pass a callback as follows to display custom information:

$('#testTextarea3').textareaCount(options3, function(data){
    var result = 'Characters Input: ' + data.input + '<br />';
    result += 'Words Input: ' + data.words + '<br />';
    result += 'Left Characters: ' + data.left + '<br />';
    result += 'Characters Limitation: ' + data.max + '<br />';
    $('#textareaCallBack').html(result);
});

You can pass user defined function as an argument after options. Function data is an object, which contains four values:

data.input
current number of input characters
data.max
max character size
data.left
how many left characters
data.words
current number of input words

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.