Skip to content

Instantly share code, notes, and snippets.

@desmondmorris
Created February 3, 2014 17:13
Show Gist options
  • Save desmondmorris/8788013 to your computer and use it in GitHub Desktop.
Save desmondmorris/8788013 to your computer and use it in GitHub Desktop.
Adds char counter to text fields in node edit form
commit 79990460f682445209ea2b449915941c99ea8c4c
tree 4ea2d17e83bfc8579508b46735075c741559ceeb
parent 42a7ffbdb86aa95b64b43d61e9383bbb0b33a4d3
author Desmond Morris <hi@desmondmorris.com> 1386018037 -0500
committer Desmond Morris <hi@desmondmorris.com> 1386018037 -0500
Adds char counter to text fields in node edit form
diff --git a/sites/all/themes/micro/micro.info b/sites/all/themes/micro/micro.info
index e91e43d..c4a6268 100644
--- a/sites/all/themes/micro/micro.info
+++ b/sites/all/themes/micro/micro.info
@@ -6,6 +6,8 @@ base theme = bartik
stylesheets[all][] = micro.css
+scripts[] = micro.js
+
regions[header] = Header
regions[help] = Help
regions[page_top] = Page top
diff --git a/sites/all/themes/micro/micro.js b/sites/all/themes/micro/micro.js
new file mode 100644
index 0000000..d35ba8e
--- /dev/null
+++ b/sites/all/themes/micro/micro.js
@@ -0,0 +1,20 @@
+(function ($) {
+ $(document).ready(function(){
+ $('.node-form [type=text], .node-form textarea').keyup(function(){
+ charCount($(this));
+ });
+ $('.node-form [type=text], .node-form textarea').change(function(){
+ charCount($(this));
+ });
+ });
+
+ function charCount(field) {
+ if( field.parent('div').find('.char_count').length == 0 ) {
+ field.parent('div').append('<span class="char_count"></span>');
+ }
+ field.parent('div').find('.char_count').html(
+ field.val().length
+ );
+ }
+
+}(jQuery));
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment