/*
* jQuery Textarea Counter Plugin
* Copyright (c) 2010 Roy Jin
* Copyright (c) 2013 LeadSift
* Version: 3.0 (11-APR-2013)
* http://www.opensource.org/licenses/mit-license.php
* Requires: jQuery v1.4.2 or later
*/
(function($) {
$.fn.textareaCount = function(options, fn) {
var defaults = {
maxCharacterSize: -1
, truncate: true
, charCounter: 'standard'
, originalStyle: 'originalTextareaInfo'
, warningStyle: 'warningTextareaInfo'
, errorStyle: 'errorTextareaInfo'
, warningNumber: 20
, displayFormat: '#input characters | #words words'
}
, container = $(this)
, charLeftInfo
, numInput = 0
, maxCharacters = options.maxCharacterSize
, numLeft = 0
, numWords = 0
, charCounters = {}
;
charCounters.standard = function(content){
return content.length;
};
charCounters.twitter = function(content){
// function that counts urls as 22 chars
// regex to match various urls ... from http://stackoverflow.com/a/6427654
var url_length = 22
, replacement = Array(url_length+1).join("*")
, regex_str = "(https?:\/\/)?" + // SCHEME
"([a-z0-9+!*(),;?&=$_.-]+(:[a-z0-9+!*(),;?&=$_.-]+)?@)?" + // User and Pass
"([a-z0-9-.]*)\\.(travel|museum|[a-z]{2,4})" + // Host or IP
"(:[0-9]{2,5})?" + // Port
"(\/([a-z0-9+$_-]\\.?)+)*\/?" + // Path
"(\\?[a-z+&$_.-][a-z0-9;:@&%=+\/$_.-]*)?" + // GET Query
"(#[a-z_.-][a-z0-9+$_.-]*)?" // Anchor
, regex = new RegExp(regex_str, 'gi')
;
return content.replace(regex, replacement).length;
};
function getNewlineCount(content){
var newlineCount = 0
, i;
for(i=0; i