From a8145d6fa24d646cef42a09c14c5ed0fa769cfd7 Mon Sep 17 00:00:00 2001 From: rillke Date: Thu, 18 Jul 2013 11:42:40 +0200 Subject: [PATCH] jquery.placeholder: Take placeholder text as parameter After this change, it will be possible to supply the text to be used as a placeholder to the plugIn. Instead of doing: $('').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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/resources/jquery/jquery.placeholder.js b/resources/jquery/jquery.placeholder.js index 7badb11ae8..73f701b507 100644 --- a/resources/jquery/jquery.placeholder.js +++ b/resources/jquery/jquery.placeholder.js @@ -10,17 +10,23 @@ */ ( 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 -- 2.20.1