From: rillke Date: Thu, 18 Jul 2013 09:42:40 +0000 (+0200) Subject: jquery.placeholder: Take placeholder text as parameter X-Git-Tag: 1.31.0-rc.0~19109^2 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=a8145d6fa24d646cef42a09c14c5ed0fa769cfd7;p=lhc%2Fweb%2Fwiklou.git 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 --- 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