Skip to content

Commit 724d1b2

Browse files
author
Sachin Maheshwari
committed
making provision for github first and last name, and making dynamic form submit
1 parent 139ec3d commit 724d1b2

File tree

2 files changed

+132
-104
lines changed

2 files changed

+132
-104
lines changed

web-assets/js/signup.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
2+
var apiServerUrl = "https://api.topcoder-dev.com/v3/users";
3+
var qs = (function (a) {
4+
if (a == "") return {};
5+
var b = {};
6+
for (var i = 0; i < a.length; ++i) {
7+
var p = a[i].split("=", 2);
8+
if (p.length == 1) b[p[0]] = "";
9+
else b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
10+
}
11+
return b;
12+
})(window.location.search.substr(1).split("&"));
13+
$(document).ready(function () {
14+
$.each(countryObjs, function () {
15+
$("#country").append(
16+
$("<option></option>").text(this.name).val(JSON.stringify(this))
17+
);
18+
});
19+
//first name & last name div
20+
var firstname = qs['firstName'];
21+
if (firstname !== 'undefined') {
22+
$("#firstName").val(firstname);
23+
$("#fn").hide();
24+
}
25+
var lastname = qs['lastName'];
26+
if (lastname !== 'undefined') {
27+
$("#lastName").val(lastname);
28+
$("#ln").hide();
29+
}
30+
$("#continueBtn").click(function () {
31+
var handle = $("#handle").val();
32+
var country = $("#country").val();
33+
$.ajax({
34+
url: apiServerUrl + "/validateHandle?handle=" + handle,
35+
xhrFields: {
36+
withCredentials: true,
37+
},
38+
success: function (result) {
39+
if (
40+
result.result.status === 200 &&
41+
!result.result.content.valid
42+
) {
43+
$("#error").html("Error: " + result.result.content.reason);
44+
$("#error").closest(".message").fadeIn();
45+
}
46+
if (result.result.status === 200 && result.result.content.valid) {
47+
$("#error").closest(".message").fadeOut();
48+
$("#error").html("");
49+
document.getElementById("signup").action = qs["formAction"];
50+
document.getElementById("state").value = qs["state"];
51+
document.getElementById("source").value = qs["source"] || null;
52+
document.getElementById("signup").submit();
53+
}
54+
},
55+
});
56+
return false;
57+
});
58+
59+
/**
60+
* Script for field placeholder
61+
**/
62+
$(".messages .close-error").on("click", function () {
63+
$(this).closest(".message").fadeOut();
64+
});
65+
var inputObj = $(".input-field .input-text"),
66+
continueBtnDisable = false;
67+
inputObj
68+
.on("focus", function () {
69+
$(this).parent().addClass("active focussed");
70+
})
71+
.on("blur", function () {
72+
var parentObj = $(this).parent();
73+
if ($(this).val() === "") {
74+
parentObj.removeClass("active");
75+
}
76+
parentObj.removeClass("focussed");
77+
})
78+
.on("change", function () {
79+
var disableStatus = false;
80+
inputObj.each(function (index, element) {
81+
if ($(element).val() === "") {
82+
disableStatus = true;
83+
return;
84+
}
85+
});
86+
setContinueButtonDisabledStatus(disableStatus);
87+
})
88+
.each(function (index, element) {
89+
var parentObj = $(element).parent();
90+
if ($(element).val() !== "") {
91+
parentObj.addClass("active");
92+
} else {
93+
parentObj.removeClass("active");
94+
}
95+
96+
if ($(element).val() === "" && continueBtnDisable === false) {
97+
continueBtnDisable = true;
98+
}
99+
100+
setContinueButtonDisabledStatus(continueBtnDisable);
101+
});
102+
});
103+
function setContinueButtonDisabledStatus(status) {
104+
var continueBtnObj = $("#continueBtn");
105+
if (status) {
106+
continueBtnObj.attr("disabled", true);
107+
} else {
108+
continueBtnObj.removeAttr("disabled");
109+
}
110+
}

web-assets/static-pages/signup.html

Lines changed: 22 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -18,111 +18,8 @@
1818
crossorigin="anonymous"
1919
></script>
2020
<script src="https://authlib.topcoder-dev.com/country.js"></script>
21-
<script>
22-
var formAction = "https://topcoder-dev.auth0.com/continue";
23-
var apiServerUrl = "https://api.topcoder-dev.com/v3/users";
24-
var qs = (function (a) {
25-
if (a == "") return {};
26-
var b = {};
27-
for (var i = 0; i < a.length; ++i) {
28-
var p = a[i].split("=", 2);
29-
if (p.length == 1) b[p[0]] = "";
30-
else b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
31-
}
32-
return b;
33-
})(window.location.search.substr(1).split("&"));
34-
</script>
35-
<script>
36-
$(document).ready(function () {
37-
$.each(countryObjs, function () {
38-
$("#country").append(
39-
$("<option></option>").text(this.name).val(JSON.stringify(this))
40-
);
41-
});
42-
$("#continueBtn").click(function () {
43-
var handle = $("#handle").val();
44-
var country = $("#country").val();
45-
$.ajax({
46-
url: apiServerUrl + "/validateHandle?handle=" + handle,
47-
xhrFields: {
48-
withCredentials: true,
49-
},
50-
success: function (result) {
51-
if (
52-
result.result.status === 200 &&
53-
!result.result.content.valid
54-
) {
55-
$("#error").html("Error: " + result.result.content.reason);
56-
$("#error").closest(".message").fadeIn();
57-
}
58-
if (result.result.status === 200 && result.result.content.valid) {
59-
$("#error").closest(".message").fadeOut();
60-
$("#error").html("");
61-
document.getElementById("signup").action = formAction;
62-
document.getElementById("state").value = qs["state"];
63-
document.getElementById("source").value = qs["source"] || null;
64-
document.getElementById("signup").submit();
65-
}
66-
},
67-
});
68-
return false;
69-
});
70-
71-
/**
72-
* Script for field placeholder
73-
**/
74-
$(".messages .close-error").on("click", function () {
75-
$(this).closest(".message").fadeOut();
76-
});
77-
var inputObj = $(".input-field .input-text"),
78-
continueBtnDisable = false;
79-
inputObj
80-
.on("focus", function () {
81-
$(this).parent().addClass("active focussed");
82-
})
83-
.on("blur", function () {
84-
var parentObj = $(this).parent();
85-
if ($(this).val() === "") {
86-
parentObj.removeClass("active");
87-
}
88-
parentObj.removeClass("focussed");
89-
})
90-
.on("change", function () {
91-
var disableStatus = false;
92-
inputObj.each(function (index, element) {
93-
if ($(element).val() === "") {
94-
disableStatus = true;
95-
return;
96-
}
97-
});
98-
setContinueButtonDisabledStatus(disableStatus);
99-
})
100-
.each(function (index, element) {
101-
var parentObj = $(element).parent();
102-
if ($(element).val() !== "") {
103-
parentObj.addClass("active");
104-
} else {
105-
parentObj.removeClass("active");
106-
}
107-
108-
if ($(element).val() === "" && continueBtnDisable === false) {
109-
continueBtnDisable = true;
110-
}
111-
112-
setContinueButtonDisabledStatus(continueBtnDisable);
113-
});
114-
});
115-
function setContinueButtonDisabledStatus(status) {
116-
var continueBtnObj = $("#continueBtn");
117-
if (status) {
118-
continueBtnObj.attr("disabled", true);
119-
} else {
120-
continueBtnObj.removeAttr("disabled");
121-
}
122-
}
123-
</script>
21+
<script type="text/javascript" src="signup.js"></script>
12422
</head>
125-
12623
<body class="center-align-card">
12724
<!-- Page Wrapper -->
12825
<div class="page-wrapper">
@@ -166,6 +63,26 @@ <h1 id="page-title-heading" class="page-title-heading clip-me">
16663
autocomplete="off"
16764
/>
16865
</div>
66+
<div id="fn" class="input-field active">
67+
<label for="firstName">Enter your First Name</label>
68+
<input
69+
id="firstName"
70+
name="firstName"
71+
size="43"
72+
class="input-text"
73+
autocomplete="off"
74+
/>
75+
</div>
76+
<div id="ln" class="input-field active">
77+
<label for="lastName">Enter your Last Name</label>
78+
<input
79+
id="lastName"
80+
name="lastName"
81+
size="43"
82+
class="input-text"
83+
autocomplete="off"
84+
/>
85+
</div>
16986
<div id="cc" class="input-field active custom-dropdowm-arrow">
17087
<label for="country">Select your country </label>
17188
<select id="country" name="country" class="input-text"></select>
@@ -194,5 +111,6 @@ <h1 id="page-title-heading" class="page-title-heading clip-me">
194111
>
195112
</footer>
196113
</div>
114+
197115
</body>
198116
</html>

0 commit comments

Comments
 (0)