From 2d8724854bf093fc50b3fa4c745e73d0f43de3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 19 Dec 2011 17:36:05 +0100 Subject: [PATCH] Porting counter to coffeescript --- file/js/jCounter.jQuery.coffee | 38 ++++++++++++++++++++++++++++++++++ file/js/jCounter.jQuery.js | 35 ------------------------------- 2 files changed, 38 insertions(+), 35 deletions(-) create mode 100644 file/js/jCounter.jQuery.coffee delete mode 100644 file/js/jCounter.jQuery.js diff --git a/file/js/jCounter.jQuery.coffee b/file/js/jCounter.jQuery.coffee new file mode 100644 index 0000000..bc30d03 --- /dev/null +++ b/file/js/jCounter.jQuery.coffee @@ -0,0 +1,38 @@ +### +# jCounter - a simple character counter +# +# @author Maximilian Mader +# @copyright 2011 Maximilian Mader +# @license Creative Commons Attribution-NonCommercial-ShareAlike +# @package jQuery.jCounter +### +(($) -> + $.fn.jCounter = (max, options) -> + max ?= 140 + options = $.extend + container: '' + counterClass: 'counter' + countUp: false + , options + + jCounterContainer = $ options.container + + this.on 'keypress keydown keyup', $.proxy () -> + if options.countUp + length = this.val().length + else + length = maxChars - this.val().length + + if options.countUp + color = 1 + else + if length > maxChars / 2 + color = 1 + else if length <= maxChars / 2 and length >= maxChars / 6 + color = 2 + else + color = 3 + + jCounterContainer.text(length).attr('class', '').addClass(options.counterClass + ' color-'+color) + , this +)(jQuery) \ No newline at end of file diff --git a/file/js/jCounter.jQuery.js b/file/js/jCounter.jQuery.js deleted file mode 100644 index 0ddea83..0000000 --- a/file/js/jCounter.jQuery.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * jCounter - a simple character counter - * - * @author Maximilian Mader - * @copyright 2011 Maximilian Mader - * @license Creative Commons Attribution-NonCommercial-ShareAlike - * @package jQuery.jCounter - */ -(function($){ - $.fn.jCounter = function(max, options) { - maxChars = max || 140; - options = $.extend({ - container: '', - counterClass: 'counter', - countUp: false - }, options); - var timeout; - - jCounterContainer = $(options.container); - - this.on('keypress keydown keyup', $.proxy(function() { - if(options.countUp) length = this.val().length; - else length = maxChars - this.val().length; - - if(options.countUp) color = 1; - else { - if (length > maxChars / 2) color = 1; - else if (length <= maxChars / 2 && length >= maxChars / 6) color = 2; - else color = 3; - } - - jCounterContainer.text(length).attr('class', '').addClass(options.counterClass + ' color-'+color); - }, this)); - } -})(jQuery); \ No newline at end of file