-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathie-placeholder.js
50 lines (49 loc) · 1.74 KB
/
ie-placeholder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//IE placeholder;
$(function (){
if (/MSIE 9|MSIE 8|MSIE 7|MSIE 6/g.test(navigator.userAgent)) {
function resetPlaceholder() {
if ($(this).val() === '') {
$(this).val($(this).attr('placeholder'))
.attr('data-placeholder', true)
.addClass('ie-placeholder');
if ($(this).is(':password')) {
var field = $('<input />');
$.each(this.attributes, function (i, attr) {
if (attr.name !== 'type') {
field.attr(attr.name, attr.value);
}
});
field.attr({
'type': 'text',
'data-input-password': true,
'value': $(this).val()
});
$(this).replaceWith(field);
}
}
}
$('[placeholder]').each(function () {
//ie user refresh don't reset input values workaround
if ($(this).attr('placeholder') !== '' && $(this).attr('placeholder') === $(this).val()){
$(this).val('');
}
resetPlaceholder.call(this);
});
$(document).on('focus', '[placeholder]', function () {
if ($(this).attr('data-placeholder')) {
$(this).val('').removeAttr('data-placeholder').removeClass('ie-placeholder');
}
}).on('blur', '[placeholder]', function () { resetPlaceholder.call(this); });
$(document).on('focus', '[data-input-password]', function () {
var field = $('<input />');
$.each(this.attributes, function (i, attr) {
if (['type','data-placeholder','data-input-password','value'].indexOf(attr.name) === -1) {
field.attr(attr.name, attr.value);
}
});
field.attr('type', 'password').on('focus', function () { this.select(); });
$(this).replaceWith(field);
field.trigger('focus');
});
}
});