forked from wchaowu/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3 - Wrappers for page specific code.js
More file actions
76 lines (55 loc) · 1.77 KB
/
Copy path3 - Wrappers for page specific code.js
File metadata and controls
76 lines (55 loc) · 1.77 KB
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
/* Generic Page Object. */
Namespace.PageName = {
// Page constants.
CONSTANT_1: true,
CONSTANT_2: 10,
// Page methods.
method1: function() {
},
method2: function() {
},
// Initialization method.
init: function() {
}
}
// Invoke the initialization method after the page loads.
addLoadEvent(Namespace.PageName.init);
var GiantCorp = window.GiantCorp || {};
/* RegPage singleton, page handler object. */
GiantCorp.RegPage = {
// Constants.
FORM_ID: 'reg-form',
OUTPUT_ID: 'reg-results',
// Form handling methods.
handleSubmit: function(e) {
e.preventDefault(); // Stop the normal form submission.
var data = {};
var inputs = GiantCorp.RegPage.formEl.getElementsByTagName('input');
// Collect the values of the input fields in the form.
for(var i = 0, len = inputs.length; i < len; i++) {
data[inputs[i].name] = inputs[i].value;
}
// Send the form values back to the server.
GiantCorp.RegPage.sendRegistration(data);
},
sendRegistration: function(data) {
// Make an XHR request and call displayResult() when the response is
// received.
//todo ...
},
displayResult: function(response) {
// Output the response directly into the output element. We are
// assuming the server will send back formatted HTML.
GiantCorp.RegPage.outputEl.innerHTML = response;
},
// Initialization method.
init: function() {
// Get the form and output elements.
GiantCorp.RegPage.formEl = $(GiantCorp.RegPage.FORM_ID);
GiantCorp.RegPage.outputEl = $(GiantCorp.RegPage.OUTPUT_ID);
// Hijack the form submission.
addEvent(GiantCorp.RegPage.formEl, 'submit', GiantCorp.RegPage.handleSubmit);
}
};
// Invoke the initialization method after the page loads.
addLoadEvent(GiantCorp.RegPage.init);