Skip to content

Commit

Permalink
Expose jQuery.fn.placeholder.input and `jQuery.fn.placeholder.texta…
Browse files Browse the repository at this point in the history
…rea`. Fixes mathiasbynens#15.
  • Loading branch information
mathiasbynens committed Feb 23, 2011
1 parent ce625cd commit 9d25f91
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ The plugin automatically adds `class="placeholder"` to the elements who are curr

* Works in all A-grade browsers, including IE6.
* The plugin automatically checks if the browser natively supports the HTML5 `placeholder` attribute for `input` and `textarea` elements. If this is the case, the plugin won’t do anything. If `@placeholder` is only supported for `input` elements, the plugin will leave those alone and apply to `textarea`s exclusively. (This is the case for Safari 4, Opera 11.00, and possibly other browsers.)
* The plugin will cache the results of its two feature tests in `jQuery.fn.placeholder.input` and `jQuery.fn.placeholder.placeholder`. For example, if `@placeholder` is natively supported for `input` elements, `jQuery.fn.placeholder.input` will be `true`. After loading the plugin, you can re-use these properties in your own code.

## License

This plugin is dual licensed under the MIT and GPL licenses, just like jQuery itself.

## Credits

Kudos to [Paul Irish](http://paulirish.com/) for his inspiring snippet in [jQuery 1.4 Hawtness #1](http://jquery14.com/day-05/jquery-1-4-hawtness-1-with-paul-irish) and everyone from [#jquery](http://webchat.freenode.net/?channels=jquery) for the tips, ideas and patches.
Kudos to [Paul Irish](http://paulirish.com/) for his inspiring snippet in [jQuery 1.4 Hawtness #1](http://jquery14.com/day-05/jquery-1-4-hawtness-1-with-paul-irish) and everyone from [#jquery](http://webchat.freenode.net/?channels=jquery) for the tips, ideas and patches. Much ♥ to temp01 for his major contributions.

_[Mathias](http://mathiasbynens.be/)_
8 changes: 3 additions & 5 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ <h1>HTML5 Placeholder jQuery Plugin</h1>
$('input, textarea').placeholder();
// That’s it, really.
// Now display a message if the browser supports placeholder natively
var isInputSupported = 'placeholder' in document.createElement('input'),
isTextareaSupported = 'placeholder' in document.createElement('textarea'),
html;
if (isInputSupported && isTextareaSupported) {
var html;
if ($.fn.placeholder.input && $.fn.placeholder.textarea) {
html = '<strong>Your current browser natively supports <code>placeholder</code> for <code>input</code> and <code>textarea</code> elements.</strong> The plugin won’t run in this case, since it’s not needed. If you want to test the plugin, use an older browser ;)';
} else if (isInputSupported) {
} else if ($.fn.placeholder.input) {
html = '<strong>Your current browser natively supports <code>placeholder</code> for <code>input</code> elements, but not for <code>textarea</code> elements.</strong> The plugin will only do its thang on the <code>textarea</code>s.';
}
if (html) {
Expand Down
5 changes: 4 additions & 1 deletion jquery.placeholder.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* HTML5 Placeholder jQuery Plugin v1.8
* HTML5 Placeholder jQuery Plugin v1.8.1
* @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin
* @author Mathias Bynens <http://mathiasbynens.be/>
*/
Expand All @@ -11,13 +11,16 @@
$.fn.placeholder = function() {
return this;
};
$.fn.placeholder.input = $.fn.placeholder.textarea = true;
} else {
$.fn.placeholder = function() {
return this.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
.bind('focus.placeholder', clearPlaceholder)
.bind('blur.placeholder', setPlaceholder)
.trigger('blur.placeholder').end();
};
$.fn.placeholder.input = isInputSupported;
$.fn.placeholder.textarea = isTextareaSupported;
}

function args(elem) {
Expand Down
4 changes: 2 additions & 2 deletions jquery.placeholder.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9d25f91

Please sign in to comment.