From 8772981d92c7281feb553492f6aa35115416111d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 29 Jan 2013 22:15:20 +0100 Subject: [PATCH] Use proper coffeescript for jCounter --- file/js/jCounter.jQuery.coffee | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/file/js/jCounter.jQuery.coffee b/file/js/jCounter.jQuery.coffee index 6927f83..ccc9ce0 100644 --- a/file/js/jCounter.jQuery.coffee +++ b/file/js/jCounter.jQuery.coffee @@ -15,44 +15,36 @@ width: '100%' , options - if @.attr('maxlength') - max = @.attr('maxlength') - else max = options.max + max = if @.attr('maxlength')? then @.attr 'maxlength' else options.max - if !container - if !@.hasClass('jCounterInput') - @.addClass('jCounterInput') - @.wrap('
').parent().append('
' + max + '
'); - jCounterContainer = $(@).parent().children('.' + options.counterClass) + if not container? + @.addClass 'jCounterInput' + + @.wrap("""
""").parent().append """
#{max}
""" + jCounterContainer = $(@).parent().children ".#{options.counterClass}" else - if typeof container is 'object' - jCounterContainer = container - else - jCounterContainer = $ container + jCounterContainer = if typeof container is 'object' then container else $ container @.on 'keypress keyup', $.proxy () -> - if options.countUp - length = @.val().length - else - length = max - @.val().length + length = if options.countUp then @.val().length else max - @.val().length if options.countUp && max > 0 if length < max / 2 color = 1 - else if length >= max / 2 and length <= max / 1.2 + else if max / 2 < length <= max / 1.2 color = 2 else color = 3 else if options.countUp color = 1 else - if length > max / 2 + if max / 2 < length color = 1 - else if length <= max / 2 and length >= max / 6 + else if max / 6 <= length <= max / 2 color = 2 else color = 3 - jCounterContainer.text(length).attr('class', '').addClass(options.counterClass + ' color-'+color) + jCounterContainer.text(length).removeClass().addClass "#{options.counterClass} color-#{color}" , @ )(jQuery) \ No newline at end of file