Skip to content

Instantly share code, notes, and snippets.

@momolog
Created January 9, 2012 16:40
Show Gist options
  • Select an option

  • Save momolog/1583767 to your computer and use it in GitHub Desktop.

Select an option

Save momolog/1583767 to your computer and use it in GitHub Desktop.
Aljoschas simply countable
// 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