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
*/
( 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