Guest User

limit BuddyPress status update box

a guest
Jun 10th, 2011
333
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;(function(jQuery){
  2. jQuery.fn.clearTextLimit = function() {
  3. return this.each(function() {
  4. this.onkeydown = this.onkeyup = null;
  5. });
  6. };
  7. jQuery.fn.textLimit = function( limit , callback ) {
  8. if ( typeof callback !== 'function' ) var callback = function() {};
  9. return this.each(function() {
  10. this.limit = limit;
  11. this.callback = callback;
  12. this.onkeydown = this.onkeyup = function() {
  13. this.value = this.value.substr(0,this.limit);
  14. this.reached = this.limit - this.value.length;
  15. this.reached = ( this.reached == 0 ) ? true : false;
  16. return this.callback( this.value.length, this.limit, this.reached );
  17. }
  18. });
  19. };
  20. })(jQuery);
  21.  
  22. jQuery('textarea').textLimit(100,function( length, limit ){
  23. jQuery(this).next().text( limit - length );
  24. });
RAW Paste Data