Use .prop instead of .attr where appropriate
[lhc/web/wiklou.git] / resources / jquery / jquery.byteLimit.js
index dd7242a..64ccb5c 100644 (file)
 
                // Default limit to current attribute value
                if ( limit === undefined ) {
-                       limit = this.attr( 'maxLength' );
+                       limit = this.prop( 'maxLength' );
+               }
 
-               // If limit passed, update/set attribute value instead
+               // 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.prop( 'maxLength', limit );
                } else {
-                       this.attr( 'maxLength', limit );
+                       this.removeProp( 'maxLength' );
                }
 
                // Nothing passed and/or empty attribute, return without binding an event.