-
Notifications
You must be signed in to change notification settings - Fork 1
/
login.js
108 lines (89 loc) · 2.46 KB
/
login.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
(function($) {
function switchType(source) {
var type = source.attr('type');
var options = {
type: type == 'password' ? 'text' : 'password',
placeholder: source.placeholder(),
focusout: function() {
$(this).presentPlaceholder();
},
focusin: function() {
$(this).removePlaceholder();
},
required: source.attr('required'),
name: source.attr('name'),
id: source.attr('id')
};
var dupe = $('<input>', options);
dupe.data('isPassword', type == 'password');
return dupe;
}
$.fn.extend({
placeholder: function() {
return this.attr('placeholder');
},
isEmpty: function(orPlaceholder) {
var value = this.val();
var blank = value == "";
if(orPlaceholder) {
return blank || (this.placeholder() == value);
}
return blank;
},
presentPlaceholder: function() {
var element = this;
if(this.isEmpty(true)) {
if(this.attr('type') == 'password') {
var dupe = switchType(this);
this.replaceWith(dupe);
element = dupe;
}
element.val(this.placeholder()).addClass('with_placeholder');
}
},
removePlaceholder: function() {
var element = this;
if(this.data('isPassword')) {
var dupe = switchType(this);
this.replaceWith(dupe);
dupe.focus();
element = dupe;
}
if(element.isEmpty(true)) {
element.removeClass('with_placeholder');
element.val('');
}
}
});
$(document).ready(function() {
var selector = 'input[placeholder]';
// Safari 4 already supports the HTML5 attributes
if(!$.browser.webkit) {
$(selector).each(function() {
var input = $(this);
input.presentPlaceholder();
});
$(selector).focusin(function() {
$(this).removePlaceholder();
}).focusout(function() {
$(this).presentPlaceholder();
});
$('input[autofocus]').first().trigger('focus');
}
// $('label').hide();
$('#login').submit(function() {
var element;
$(this).find('input[required]').each(function() {
var input = $(this);
if(input.isEmpty(true)) {
element = input;
return false;
}
});
if(element) {
element.focus();
return false;
}
});
});
})(jQuery);