// Default limit to current attribute value
if ( limit === undefined ) {
limit = this.attr( 'maxLength' );
+ }
- // If limit passed, update/set attribute value instead
- } else {
+ // Update/set attribute value, but only if there is no callback set.
+ // If there's a callback set, it's possible that the limit being enforced
+ // is too low (ie. if the callback would return "Foo" for "User:Foo").
+ // Usually this isn't a problem since browsers ignore maxLength when setting
+ // the value property through JavaScript, but Safari 4 violates that rule, so
+ // we have to remove or not set the property if we have a callback.
+ if ( fn === undefined ) {
this.attr( 'maxLength', limit );
+ } else {
+ this.removeAttr( 'maxLength' );
}
// Nothing passed and/or empty attribute, return without binding an event.