-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
138 lines (129 loc) · 3.46 KB
/
script.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*global $, document, window, setTimeout, navigator, console, location*/
$(document).ready(function () {
"use strict";
var usernameError = true,
emailError = true,
passwordError = true,
passConfirm = true;
// Detect browser for css purpose
if (navigator.userAgent.toLowerCase().indexOf("firefox") > -1) {
$(".form form label").addClass("fontSwitch");
}
// Label effect
$("input").focus(function () {
$(this).siblings("label").addClass("active");
});
// Form validation
$("input").blur(function () {
// User Name
if ($(this).hasClass("name")) {
if ($(this).val().length === 0) {
$(this)
.siblings("span.error")
.text("Please type your full name")
.fadeIn()
.parent(".form-group")
.addClass("hasError");
usernameError = true;
} else if ($(this).val().length > 1 && $(this).val().length <= 6) {
$(this)
.siblings("span.error")
.text("Please type at least 6 characters")
.fadeIn()
.parent(".form-group")
.addClass("hasError");
usernameError = true;
} else {
$(this)
.siblings(".error")
.text("")
.fadeOut()
.parent(".form-group")
.removeClass("hasError");
usernameError = false;
}
}
// Email
if ($(this).hasClass("email")) {
if ($(this).val().length == "") {
$(this)
.siblings("span.error")
.text("Please type your email address")
.fadeIn()
.parent(".form-group")
.addClass("hasError");
emailError = true;
} else {
$(this)
.siblings(".error")
.text("")
.fadeOut()
.parent(".form-group")
.removeClass("hasError");
emailError = false;
}
}
// PassWord
if ($(this).hasClass("pass")) {
if ($(this).val().length < 8) {
$(this)
.siblings("span.error")
.text("Please type at least 8 charcters")
.fadeIn()
.parent(".form-group")
.addClass("hasError");
passwordError = true;
} else {
$(this)
.siblings(".error")
.text("")
.fadeOut()
.parent(".form-group")
.removeClass("hasError");
passwordError = false;
}
}
// PassWord confirmation
if ($(".pass").val() !== $(".passConfirm").val()) {
$(".passConfirm")
.siblings(".error")
.text("Passwords don't match")
.fadeIn()
.parent(".form-group")
.addClass("hasError");
passConfirm = false;
} else {
$(".passConfirm")
.siblings(".error")
.text("")
.fadeOut()
.parent(".form-group")
.removeClass("hasError");
passConfirm = false;
}
// label effect
if ($(this).val().length > 0) {
$(this).siblings("label").addClass("active");
} else {
$(this).siblings("label").removeClass("active");
}
});
// form switch
$("a.switch").click(function (e) {
$(this).toggleClass("active");
e.preventDefault();
if ($("a.switch").hasClass("active")) {
$(this)
.parents(".form-peice")
.addClass("switched")
.siblings(".form-peice")
.removeClass("switched");
} else {
$(this)
.parents(".form-peice")
.removeClass("switched")
.siblings(".form-peice")
.addClass("switched");
}
});
});