Skip to content

Commit a4af465

Browse files
committed
Merge pull request #276 from mathiasbynens/gh-pages
Fixes
2 parents 1837aea + 73d1590 commit a4af465

6 files changed

+165
-37
lines changed

index.html

+17-12
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
<title>HTML5 placeholder jQuery Plugin</title>
66
<style>
77
body { font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; }
8-
input, textarea { font-size: 1em; }
8+
input, textarea { font-size: 1em; font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;}
9+
input { width: 250px; }
10+
input[type="radio"], input[type="checkbox"] { width: auto }
911
label code { display: inline-block; width: 200px; }
1012
textarea { height: 2em; width: 20em;, font-family: sans-serif; }
11-
form div { border-bottom: 1px solid #ccc; padding: 5px; }
1213
.my-placeholder { color: #aaa; }
1314
.note { border: 1px solid orange; font-size: 13px; padding: 1em; background: #ffffe0; }
1415
</style>
@@ -19,16 +20,14 @@ <h1>HTML5 Placeholder jQuery Plugin</h1>
1920

2021
<a href="https://github.com/mathiasbynens/jquery-placeholder"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
2122

22-
<form>
23-
<input type="radio" name="color" placeholder="This can't be seen"> Red
24-
<input type="radio" name="color" placeholder="This can't be seen"> Green
25-
<input type="radio" name="color" placeholder="This can't be seen"> Blue
23+
<form method="GET" action="">
24+
<input type="radio" name="color" value="red" placeholder="This can't be seen"> Red
25+
<input type="radio" name="color" value="green" placeholder="This can't be seen"> Green
2626

2727
<br />
2828

29-
<input type="checkbox" name="fruits" placeholder="This can't be seen"> Apple
30-
<input type="checkbox" name="fruits" placeholder="This can't be seen"> Banana
31-
<input type="checkbox" name="fruits" placeholder="This can't be seen"> Pear
29+
<input type="checkbox" name="fruits" value="apple" placeholder="This can't be seen"> Apple
30+
<input type="checkbox" name="fruits" value="banana" placeholder="This can't be seen"> Banana
3231

3332
<br />
3433

@@ -46,12 +45,12 @@ <h1>HTML5 Placeholder jQuery Plugin</h1>
4645
<br />
4746
<br />
4847

49-
<input type="email" name="email" placeholder="type=email">
48+
<input type="email" name="email" placeholder="type=email" value="prefilled@example.com">
5049

5150
<br />
5251
<br />
5352

54-
<input type="url" name="url" placeholder="type=url">
53+
<input type="url" name="url" placeholder="type=url" value="http://prefilled.example.com">
5554

5655
<br />
5756
<br />
@@ -83,11 +82,17 @@ <h1>HTML5 Placeholder jQuery Plugin</h1>
8382
<br />
8483
<br />
8584

86-
<label for="p">Click me to focus password field</label>
85+
<label for="p">A Label: Click me to focus password field up above</label>
8786

8887
<br />
8988
<br />
9089

90+
<div class="wrapped">
91+
<input type="password" name="password2" placeholder="type=password 2">
92+
</div>
93+
94+
<br />
95+
9196
<input type="submit" value="type=submit">
9297
<input type="reset" value="type=reset">
9398
</form>

jquery.placeholder.js

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery Placeholder Plugin v2.1.3
2+
* jQuery Placeholder Plugin v2.2.0
33
* https://github.com/mathiasbynens/jquery-placeholder
44
*
55
* Copyright 2011, 2015 Mathias Bynens
@@ -17,10 +17,17 @@
1717
}
1818
}(function($) {
1919

20+
/****
21+
* Allows plugin behavior simulation in modern browsers for easier debugging.
22+
* When setting to true, use attribute "placeholder-x" rather than the usual "placeholder" in your inputs/textareas
23+
* i.e. <input type="text" placeholder-x="my placeholder text" />
24+
*/
25+
var debugMode = false;
26+
2027
// Opera Mini v7 doesn't support placeholder although its DOM seems to indicate so
2128
var isOperaMini = Object.prototype.toString.call(window.operamini) === '[object OperaMini]';
22-
var isInputSupported = 'placeholder' in document.createElement('input') && !isOperaMini;
23-
var isTextareaSupported = 'placeholder' in document.createElement('textarea') && !isOperaMini;
29+
var isInputSupported = 'placeholder' in document.createElement('input') && !isOperaMini && !debugMode;
30+
var isTextareaSupported = 'placeholder' in document.createElement('textarea') && !isOperaMini && !debugMode;
2431
var valHooks = $.valHooks;
2532
var propHooks = $.propHooks;
2633
var hooks;
@@ -43,8 +50,9 @@
4350
var defaults = {customClass: 'placeholder'};
4451
settings = $.extend({}, defaults, options);
4552

46-
return this.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
53+
return this.filter((isInputSupported ? 'textarea' : ':input') + '[' + (debugMode ? 'placeholder-x' : 'placeholder') + ']')
4754
.not('.'+settings.customClass)
55+
.not(':radio, :checkbox, :hidden')
4856
.bind({
4957
'focus.placeholder': clearPlaceholder,
5058
'blur.placeholder': setPlaceholder
@@ -167,9 +175,9 @@
167175
function clearPlaceholder(event, value) {
168176

169177
var input = this;
170-
var $input = $(input);
178+
var $input = $(this);
171179

172-
if (input.value === $input.attr('placeholder') && $input.hasClass(settings.customClass)) {
180+
if (input.value === $input.attr((debugMode ? 'placeholder-x' : 'placeholder')) && $input.hasClass(settings.customClass)) {
173181

174182
input.value = '';
175183
$input.removeClass(settings.customClass);
@@ -196,22 +204,12 @@
196204
function setPlaceholder(event) {
197205
var $replacement;
198206
var input = this;
199-
var $input = $(input);
207+
var $input = $(this);
200208
var id = input.id;
201209

202210
// If the placeholder is activated, triggering blur event (`$input.trigger('blur')`) should do nothing.
203-
if (event && event.type === 'blur') {
204-
205-
if ($input.hasClass(settings.customClass)) {
206-
return;
207-
}
208-
209-
if (input.type === 'password') {
210-
$replacement = $input.prevAll('input[type="text"]:first');
211-
if ($replacement.length > 0 && $replacement.is(':visible')) {
212-
return;
213-
}
214-
}
211+
if (event && event.type === 'blur' && $input.hasClass(settings.customClass)) {
212+
return;
215213
}
216214

217215
if (input.value === '') {
@@ -255,7 +253,7 @@
255253
}
256254

257255
$input.addClass(settings.customClass);
258-
$input[0].value = $input.attr('placeholder');
256+
$input[0].value = $input.attr((debugMode ? 'placeholder-x' : 'placeholder'));
259257

260258
} else {
261259
$input.removeClass(settings.customClass);

jquery.placeholder.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)