Created
January 9, 2012 16:40
-
-
Save momolog/1583767 to your computer and use it in GitHub Desktop.
Aljoschas simply countable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // show tipsy with remaining characters | |
| $('[data-maxlen]') | |
| .tipsy({gravity: 'e', trigger: 'focus', html: true}) | |
| .each(function(){ | |
| var el = $(this); | |
| el.data('doUpdateTitle', function(){ | |
| var len = el.val().length; | |
| var remaining = el.data('maxlen')-len; | |
| el.attr('title', '<span class="'+(remaining<0 ? 'red' : '')+'">Verbleibende Zeichen: '+remaining+'</span>').tipsy('hide').tipsy('show');· | |
| return len; | |
| }); | |
| }) | |
| .keydown(function(event){ | |
| var el = $(this); | |
| var len = el.data('doUpdateTitle')(); | |
| if ((len >= el.data('maxlen')) && ($.inArray(event.which, [8,37,38,39,40]) < 0)) { | |
| return false; | |
| }· | |
| }) | |
| .keyup(function(){ | |
| $(this).data('doUpdateTitle')() | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment