mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-22 21:40:08 +00:00
Use proper coffeescript for jCounter
This commit is contained in:
parent
cad8fee417
commit
8772981d92
@ -15,44 +15,36 @@
|
|||||||
width: '100%'
|
width: '100%'
|
||||||
, options
|
, options
|
||||||
|
|
||||||
if @.attr('maxlength')
|
max = if @.attr('maxlength')? then @.attr 'maxlength' else options.max
|
||||||
max = @.attr('maxlength')
|
|
||||||
else max = options.max
|
|
||||||
|
|
||||||
if !container
|
if not container?
|
||||||
if !@.hasClass('jCounterInput')
|
@.addClass 'jCounterInput'
|
||||||
@.addClass('jCounterInput')
|
|
||||||
@.wrap('<div class="jCounterContainer" style="width: ' + options.width + '"><div></div></div>').parent().append('<div class="' + options.counterClass + ' color-1">' + max + '</div>');
|
@.wrap("""<div class="jCounterContainer" style="width: #{options.width}"><div></div></div>""").parent().append """<div class="#{options.counterClass} color-1">#{max}</div>"""
|
||||||
jCounterContainer = $(@).parent().children('.' + options.counterClass)
|
jCounterContainer = $(@).parent().children ".#{options.counterClass}"
|
||||||
else
|
else
|
||||||
if typeof container is 'object'
|
jCounterContainer = if typeof container is 'object' then container else $ container
|
||||||
jCounterContainer = container
|
|
||||||
else
|
|
||||||
jCounterContainer = $ container
|
|
||||||
|
|
||||||
@.on 'keypress keyup', $.proxy () ->
|
@.on 'keypress keyup', $.proxy () ->
|
||||||
if options.countUp
|
length = if options.countUp then @.val().length else max - @.val().length
|
||||||
length = @.val().length
|
|
||||||
else
|
|
||||||
length = max - @.val().length
|
|
||||||
|
|
||||||
if options.countUp && max > 0
|
if options.countUp && max > 0
|
||||||
if length < max / 2
|
if length < max / 2
|
||||||
color = 1
|
color = 1
|
||||||
else if length >= max / 2 and length <= max / 1.2
|
else if max / 2 < length <= max / 1.2
|
||||||
color = 2
|
color = 2
|
||||||
else
|
else
|
||||||
color = 3
|
color = 3
|
||||||
else if options.countUp
|
else if options.countUp
|
||||||
color = 1
|
color = 1
|
||||||
else
|
else
|
||||||
if length > max / 2
|
if max / 2 < length
|
||||||
color = 1
|
color = 1
|
||||||
else if length <= max / 2 and length >= max / 6
|
else if max / 6 <= length <= max / 2
|
||||||
color = 2
|
color = 2
|
||||||
else
|
else
|
||||||
color = 3
|
color = 3
|
||||||
|
|
||||||
jCounterContainer.text(length).attr('class', '').addClass(options.counterClass + ' color-'+color)
|
jCounterContainer.text(length).removeClass().addClass "#{options.counterClass} color-#{color}"
|
||||||
, @
|
, @
|
||||||
)(jQuery)
|
)(jQuery)
|
Loading…
Reference in New Issue
Block a user