This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addressBook.js
85 lines (85 loc) · 3.75 KB
/
addressBook.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
var addressBook = {
myConn: false,
body: false,
control: false,
target: false,
loader: false,
init: function( controlId, sbmtBtnId, targetId ){
if( !document.getElementById ||
!document.getElementsByTagName ||
!document.getElementById( controlId ) ||
!document.getElementById( sbmtBtnId ) ||
!document.getElementById( targetId ) ) return;
addressBook.myConn = new XHConn();
if( !addressBook.myConn ) return;
addressBook.body = document.getElementsByTagName( 'body' )[0];
addressBook.control = document.getElementById( controlId );
var sbmtBtn = document.getElementById( sbmtBtnId );
sbmtBtn.parentNode.removeChild( sbmtBtn );
addressBook.target = document.getElementById( targetId );
addressBook.addEvent( addressBook.control,
'change',
function(){
if( this.value != '' ){
addressBook.getAddress( this.value );
} else {
addressBook.target.removeChild( addressBook.target.firstChild );
}
} );
},
getAddress: function( id ){
addressBook.buildLoader();
var fnWhenDone = function(oXML) {
addressBook.killLoader();
if( addressBook.target.hasChildNodes() ){
addressBook.target.removeChild( addressBook.target.firstChild );
}
xml = oXML.responseXML;
var name = addressBook.getNodeValue( xml, 'first' ) + ' ' +
addressBook.getNodeValue( xml, 'last' );
var address = addressBook.getNodeValue( xml, 'street' );
var csz = addressBook.getNodeValue( xml, 'city' ) + ', ' +
addressBook.getNodeValue( xml, 'state' ) + ' ' +
addressBook.getNodeValue( xml, 'zip' );
var txt = document.createTextNode( name+"\n"+address+"\n"+csz );
addressBook.target.appendChild( txt );
};
addressBook.myConn.connect("index.php", "POST", "id="+id, fnWhenDone);
},
getNodeValue: function( scope, node ){
return scope.getElementsByTagName( node )[0].firstChild.nodeValue;
},
buildLoader: function(){
addressBook.loader = document.createElement( 'div' );
addressBook.loader.setAttribute( 'id', 'loading' );
addressBook.loader.style.position = 'absolute';
addressBook.loader.style.top = '50%';
addressBook.loader.style.left = '50%';
addressBook.loader.style.width = '300px';
addressBook.loader.style.lineHeight = '100px';
addressBook.loader.style.margin = '-50px 0 0 -150px';
addressBook.loader.style.textAlign = 'center';
addressBook.loader.style.border = '1px solid #870108';
addressBook.loader.style.background = '#fff';
addressBook.loader.appendChild( document.createTextNode( 'Loading Data, please wait\u2026' ) );
addressBook.body.appendChild( addressBook.loader );
},
killLoader: function(){
addressBook.body.removeChild( addressBook.loader );
},
addEvent: function( obj, type, fn ){ // the add event function
if (obj.addEventListener) obj.addEventListener( type, fn, false );
else if (obj.attachEvent) {
obj["e"+type+fn] = fn;
obj[type+fn] = function() {
obj["e"+type+fn]( window.event );
};
obj.attachEvent( "on"+type, obj[type+fn] );
}
}
};
addressBook.addEvent( window, 'load', function(){
addressBook.init( 'person',
'submit',
'address' );
} );