jquery.placeholder: Take placeholder text as parameter
authorrillke <rainerrillke@hotmail.com>
Thu, 18 Jul 2013 09:42:40 +0000 (11:42 +0200)
committerHoo man <hoo@online.de>
Fri, 26 Jul 2013 17:03:20 +0000 (17:03 +0000)
After this change, it will be possible to supply the text to be used as
a placeholder to the plugIn. Instead of doing:
$('<input type="text" />').attr({
        placeholder: "Placeholder text"
}).placeholder();

you can now simply do:
$('input#myInput')
.placeholder("Placeholder text");

after loading the plug-in.

Bug: 40430
Change-Id: I25255b2ef657f3215e64895d7905b984a1e9d59a

resources/jquery/jquery.placeholder.js

index 7badb11..73f701b 100644 (file)
  */
 ( function ( $ ) {
 
-       $.fn.placeholder = function () {
+       $.fn.placeholder = function ( text ) {
+               // Check whether supplied argument is a string
+               var textIsValid = ( typeof text === 'string' );
 
                return this.each( function () {
                        var placeholder, $input;
 
+
                        // If the HTML5 placeholder attribute is supported, use it
                        if ( this.placeholder && 'placeholder' in document.createElement( this.tagName ) ) {
+                               if ( textIsValid ) {
+                                       this.setAttribute( 'placeholder', text );
+                               }
                                return;
                        }
 
-                       placeholder = this.getAttribute( 'placeholder' );
+                       placeholder = textIsValid ? text : this.getAttribute( 'placeholder' );
                        $input = $(this);
 
                        // Show initially, if empty