Skip to content

Commit

Permalink
Don’t do anything on DOMContentLoaded if placeholder is natively supp…
Browse files Browse the repository at this point in the history
…orted anyway.
  • Loading branch information
mathiasbynens committed Jun 6, 2011
1 parent 0b01340 commit 0db4369
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</head>
<body>
<h1>HTML5 Placeholder jQuery Plugin</h1>
<p>Check out <a href="http://github.com/mathiasbynens/Placeholder-jQuery-Plugin">the HTML5 Placeholder jQuery Plugin project page on GitHub</a>.</p>
<p>Check out <a href="https://github.com/mathiasbynens/Placeholder-jQuery-Plugin">the HTML5 Placeholder jQuery Plugin project page on GitHub</a>.</p>
<pre><code>$(function() {<br> $('input, textarea').placeholder();<br>});</code></pre>
<form>
<p><label><code>type=search</code> <input type="search" name="search" placeholder="Search this site…"></label></p>
Expand Down
45 changes: 26 additions & 19 deletions jquery.placeholder.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
/*!
* HTML5 Placeholder jQuery Plugin v1.8.2
* @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin
* HTML5 Placeholder jQuery Plugin v1.8.3
* @link http://mths.be/placeholder
* @author Mathias Bynens <http://mathiasbynens.be/>
*/
;(function($) {

var isInputSupported = 'placeholder' in document.createElement('input'),
isTextareaSupported = 'placeholder' in document.createElement('textarea');

if (isInputSupported && isTextareaSupported) {

$.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();
.trigger('blur.placeholder').end();
};

$.fn.placeholder.input = isInputSupported;
$.fn.placeholder.textarea = isTextareaSupported;

$(function() {
// Look for forms
$('form').bind('submit.placeholder', function() {
// Clear the placeholder values so they don’t get submitted
var $inputs = $('.placeholder', this).each(clearPlaceholder);
setTimeout(function() {
$inputs.each(setPlaceholder);
}, 10);
});
});

// Clear placeholder values upon page reload
$(window).bind('unload.placeholder', function() {
$('.placeholder').val('');
});

}

function args(elem) {
Expand Down Expand Up @@ -78,20 +101,4 @@
}
}

$(function() {
// Look for forms
$('form').bind('submit.placeholder', function() {
// Clear the placeholder values so they don’t get submitted
var $inputs = $('.placeholder', this).each(clearPlaceholder);
setTimeout(function() {
$inputs.each(setPlaceholder);
}, 10);
});
});

// Clear placeholder values upon page reload
$(window).bind('unload.placeholder', function() {
$('.placeholder').val('');
});

}(jQuery));
6 changes: 3 additions & 3 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 0db4369

Please sign in to comment.