stage 2: text field counter
[edumed.git] / stage2 / static / js / checktext.js
diff --git a/stage2/static/js/checktext.js b/stage2/static/js/checktext.js
new file mode 100644 (file)
index 0000000..d589f15
--- /dev/null
@@ -0,0 +1,14 @@
+$(function() {
+    "use strict";
+    var textarea = $("*[data-max-length]");
+    textarea.before('<p class="counter">PozostaƂo: <span id="count"></span></p>');
+    function updateCount(){
+        var max_chars = this.getAttribute('data-max-length');
+        var $this = $(this);
+        var remaining = max_chars - $this.val().length;
+        $("#count").text(remaining);
+        $this.prev().toggleClass('negative', remaining < 0);
+    }
+    textarea.on('input', updateCount);
+    textarea.trigger('input');
+});