jquery.placeholder: Fixup for 7ec7d879ee
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 27 Jul 2013 05:59:48 +0000 (07:59 +0200)
committerTimo Tijhof <krinklemail@gmail.com>
Sat, 27 Jul 2013 05:59:48 +0000 (07:59 +0200)
Check for 'arguments.length' was done in the wrong scope.
It checked for arguments to .each() which is always 2 (i, el).

This caused a regression where any call to .placeholder() without
arguments resulted in the string 'undefined' to be displayed as
placeholder (since it was doing setAttribute and passing it `text`
which is undefined, and then further using that undefined variable).

Until 7ec7d879ee / a8145d6fa2 this was the only way .placeholder
could be called, so this is a major regression affecting all use
of it.

Change-Id: I862b0f72548ec2122dad9c5d013149ac57688dab

resources/jquery/jquery.placeholder.js

index f7c9ae0..8044d88 100644 (file)
 ( function ( $ ) {
 
        $.fn.placeholder = function ( text ) {
+               var hasArg = arguments.length;
 
                return this.each( function () {
                        var placeholder, $input;
 
-                       if ( arguments.length ) {
+                       if ( hasArg ) {
                                this.setAttribute( 'placeholder', text );
                        }
 
@@ -24,7 +25,7 @@
                                return;
                        }
 
-                       placeholder = arguments.length ? text : this.getAttribute( 'placeholder' );
+                       placeholder = hasArg ? text : this.getAttribute( 'placeholder' );
                        $input = $(this);
 
                        // Show initially, if empty