mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2025-01-09 00:20:08 +00:00
Fixed and changed counter a bit.
Now a counter can be created like this: $('INPUT').jCounter(<null, options>); The element input element will be wrapped in two divs, the counterContainer div and a second div (display table and table-row ;) ). Then the counter will be appended to the new created parent of the Input (the second div). And it can be called like this: $('INPUT').jCounter(either an id, a class or an object ($('bla')) <, options>);
This commit is contained in:
parent
2d8724854b
commit
f67405866b
@ -7,28 +7,38 @@
|
|||||||
# @package jQuery.jCounter
|
# @package jQuery.jCounter
|
||||||
###
|
###
|
||||||
(($) ->
|
(($) ->
|
||||||
$.fn.jCounter = (max, options) ->
|
$.fn.jCounter = (container, options) ->
|
||||||
max ?= 140
|
|
||||||
options = $.extend
|
options = $.extend
|
||||||
container: '<span></span>'
|
max: 0
|
||||||
counterClass: 'counter'
|
counterClass: 'counter'
|
||||||
countUp: false
|
countUp: false
|
||||||
, options
|
, options
|
||||||
|
|
||||||
jCounterContainer = $ options.container
|
if this.attr('maxlength')
|
||||||
|
max = this.attr('maxlength')
|
||||||
|
else max = options.max
|
||||||
|
|
||||||
this.on 'keypress keydown keyup', $.proxy () ->
|
if !container
|
||||||
|
this.wrap('<div class="counterContainer"><div></div></div>').parent().append('<div class="' + options.counterClass + ' color-1">' + max + '</div>');
|
||||||
|
jCounterContainer = $(this).parent().children('.' + options.counterClass)
|
||||||
|
else
|
||||||
|
if `typeof container == "object"`
|
||||||
|
jCounterContainer = container
|
||||||
|
else
|
||||||
|
jCounterContainer = $ container
|
||||||
|
|
||||||
|
this.on 'keypress keyup', $.proxy () ->
|
||||||
if options.countUp
|
if options.countUp
|
||||||
length = this.val().length
|
length = this.val().length
|
||||||
else
|
else
|
||||||
length = maxChars - this.val().length
|
length = max - this.val().length
|
||||||
|
|
||||||
if options.countUp
|
if options.countUp
|
||||||
color = 1
|
color = 1
|
||||||
else
|
else
|
||||||
if length > maxChars / 2
|
if length > max / 2
|
||||||
color = 1
|
color = 1
|
||||||
else if length <= maxChars / 2 and length >= maxChars / 6
|
else if length <= max / 2 and length >= max / 6
|
||||||
color = 2
|
color = 2
|
||||||
else
|
else
|
||||||
color = 3
|
color = 3
|
||||||
|
Loading…
Reference in New Issue
Block a user