Google Maps API的库JS文件分析(2)
在Google Maps API提供的JS文件中,引用了一个后台的JS库文件,该文件针对不同的浏览器有三个版本,这几天因为我想给我的Google Map扩展一些功能,所以研究了这个文件,我现在正打算陆续将我注释过的该文件放在网上,该文件一共有7000多行,我会分段渐渐的注释出来,我是按照分类注释的,所以并不会按照该JS文件顺序。
该文件Google作了处理,所有的变量名都被处理成了简单的a,b,c,d之类,所以理解起来比较费劲。
该JS文件是以IE版本的http://maps.google.com/mapfiles/maps.21.js来分析的,其他的几个我觉得基本的架构也应该差不多,所以我没有仔细看,实际上,这个文件Google也会不停的更新(在我写这个文章的时候,我发现Google已经更新到maps.25.js了),不过我想架构上也不会有太大的变动吧。
由于该文件是在比较复杂,所以难免会出现理解错误的情况,请谅解!
下面是第二个(这个主要是文件最开始的时候的一些公用函数的定义):
1
//用来记录浏览器型号、版本和操作系统类型的对象
2
function Jb(a,b,c)
3
{
4
this.type=a;
5
this.version=b;
6
this.os=c
7
};
8
//下面的代码生成一个浏览器信息的实例
9
var t=new Jb(0,0,null);
10
var fa=navigator.userAgent.toLowerCase();
11
if(fa.indexOf("opera")!=-1)
12
{
13
t.type=4;
14
if(fa.indexOf("opera/7")!=-1||fa.indexOf("opera 7")!=-1)
15
{
16
t.version=7
17
}
18
else if(fa.indexOf("opera/8")!=-1||fa.indexOf("opera 8")!=-1)
19
{
20
t.version=8
21
}
22
}
23
else if(fa.indexOf("msie")!=-1&&document.all)
24
{
25
t.type=1;
26
if(fa.indexOf("msie 5"))
27
{
28
t.version=5
29
}
30
}
31
else if(fa.indexOf("safari")!=-1)
32
{
33
t.type=3
34
}
35
else if(fa.indexOf("mozilla")!=-1)
36
{
37
t.type=2
38
}
39
if(fa.indexOf("x11;")!=-1)
40
{
41
t.os=1
42
}
43
else if(fa.indexOf("macintosh")!=-1)
44
{
45
t.os=2
46
};
47
var aa=Number.MAX_VALUE;
48
//在C毫秒之后,以a为对象的实例执行方法b,返回对象句柄
49
function qa(a,b,c)
50
{
51
var d=window.setTimeout(function(){b.apply(a)},c);
52
return d
53
}
54
//每隔c毫秒,以a为对象的实例执行方法b,返回对象句柄
55
function Cb(a,b,c)
56
{
57
var d=window.setInterval(function(){b.apply(a)},c);
58
return d
59
}
60
//将html转化为文本
61
function ra(a)
62
{
63
return a.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")
64
}
65
//将"替换为"
66
function qd(a)
67
{
68
return ra(a).replace(/\"/g,""")
69
}
70
//清空数组a
71
function Zc(a)
72
{
73
a.length=0
74
}
75
//将控件a的鼠标样式设置为b
76
function G(a,b)
77
{
78
try
79
{
80
a.style.cursor=b
81
}
82
catch(c)
83
{
84
if(b=="pointer")
85
{
86
G(a,"hand")
87
}
88
}
89
}
90
//中止事件a的执行,并返回false
91
function B(a)
92
{
93
if(t.type==1)
94
{
95
window.event.cancelBubble=true;
96
window.event.returnValue=false
97
}
98
else
99
{
100
a.cancelBubble=true;
101
a.preventDefault();
102
a.stopPropagation()
103
}
104
}
105
//终止事件的执行
106
function $a(a)
107
{
108
if(t.type==1)
109
{
110
window.event.cancelBubble=true
111
}
112
else
113
{
114
a.stopPropagation()
115
}
116
}
117
//如果浏览器JS不支持数组的push方法,则使用自定义的Push方法
118
if(!Array.prototype.push)
119
{
120
Array.prototype.push=function(a)
121
{
122
this[this.length]=a
123
}
124
}
125
//返回id为a的对象
126
function vb(a)
127
{
128
return document.getElementById(a)
129
}
130
//将数字a转化为一个象素值
131
function k(a)
132
{
133
return Math.round(a)+"px"
134
}
135
//返回a对象左上角相对于页面左上角的距离
136
function Na(a)
137
{
138
var b=
139
{
140
"x":0,"y":0
141
};
142
while(a)
143
{
144
b.x+=a.offsetLeft;
145
b.y+=a.offsetTop;
146
a=a.offsetParent
147
}
148
return b
149
}
150
//返回双击事件a的发生点相对控件b左上角的距离
151
function za(a,b)
152
{
153
if(typeof a.offsetX!="undefined")
154
{
155
var c=a.target||a.srcElement;
156
var d=jd(c,b);
157
return new r(a.offsetX+d.x,a.offsetY+d.y)
158
}
159
else if(typeof a.pageX!="undefined")
160
{
161
var e=Na(b);
162
return new r(a.pageX-e.x,a.pageY-e.y)
163
}
164
else
165
{
166
z.incompatible("dblclick"); //返回浏览器不兼容双击的提示
167
return new r()
168
}
169
}
170
//返回控件a左上角相对于控件b左上角的距离
171
function jd(a,b)
172
{
173
var c={"x":0,"y":0};
174
while(a&&a!=b)
175
{
176
c.x+=a.offsetLeft;
177
c.y+=a.offsetTop;
178
a=a.offsetParent
179
}
180
return c
181
}
182
//空函数,用来置空事件处理过程
183
function _nullFunction()
184
{
185
}
186
//删除a节点
187
function Ma(a)
188
{
189
if(a&&a.parentNode)
190
{
191
a.parentNode.removeChild(a)
192
}
193
};
//用来记录浏览器型号、版本和操作系统类型的对象2
function Jb(a,b,c)3
{4
this.type=a;5
this.version=b;6
this.os=c7
};8
//下面的代码生成一个浏览器信息的实例9
var t=new Jb(0,0,null);10
var fa=navigator.userAgent.toLowerCase();11
if(fa.indexOf("opera")!=-1)12
{13
t.type=4;14
if(fa.indexOf("opera/7")!=-1||fa.indexOf("opera 7")!=-1)15
{16
t.version=717
}18
else if(fa.indexOf("opera/8")!=-1||fa.indexOf("opera 8")!=-1)19
{20
t.version=821
}22
}23
else if(fa.indexOf("msie")!=-1&&document.all)24
{25
t.type=1;26
if(fa.indexOf("msie 5"))27
{28
t.version=529
}30
}31
else if(fa.indexOf("safari")!=-1)32
{33
t.type=334
}35
else if(fa.indexOf("mozilla")!=-1)36
{37
t.type=238
}39
if(fa.indexOf("x11;")!=-1)40
{41
t.os=142
}43
else if(fa.indexOf("macintosh")!=-1)44
{45
t.os=246
};47
var aa=Number.MAX_VALUE;48
//在C毫秒之后,以a为对象的实例执行方法b,返回对象句柄49
function qa(a,b,c)50
{51
var d=window.setTimeout(function(){b.apply(a)},c);52
return d53
}54
//每隔c毫秒,以a为对象的实例执行方法b,返回对象句柄55
function Cb(a,b,c)56
{57
var d=window.setInterval(function(){b.apply(a)},c);58
return d59
}60
//将html转化为文本61
function ra(a)62
{63
return a.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")64
}65
//将"替换为"66
function qd(a)67
{68
return ra(a).replace(/\"/g,""")69
}70
//清空数组a71
function Zc(a)72
{73
a.length=074
}75
//将控件a的鼠标样式设置为b76
function G(a,b)77
{78
try79
{80
a.style.cursor=b81
}82
catch(c)83
{84
if(b=="pointer")85
{86
G(a,"hand")87
}88
}89
}90
//中止事件a的执行,并返回false91
function B(a)92
{93
if(t.type==1)94
{95
window.event.cancelBubble=true;96
window.event.returnValue=false97
}98
else99
{100
a.cancelBubble=true;101
a.preventDefault();102
a.stopPropagation()103
}104
}105
//终止事件的执行106
function $a(a)107
{108
if(t.type==1)109
{110
window.event.cancelBubble=true111
}112
else113
{114
a.stopPropagation()115
}116
}117
//如果浏览器JS不支持数组的push方法,则使用自定义的Push方法118
if(!Array.prototype.push)119
{120
Array.prototype.push=function(a)121
{122
this[this.length]=a123
}124
}125
//返回id为a的对象126
function vb(a)127
{128
return document.getElementById(a)129
}130
//将数字a转化为一个象素值131
function k(a)132
{133
return Math.round(a)+"px"134
}135
//返回a对象左上角相对于页面左上角的距离136
function Na(a)137
{138
var b=139
{140
"x":0,"y":0141
};142
while(a)143
{144
b.x+=a.offsetLeft;145
b.y+=a.offsetTop;146
a=a.offsetParent147
}148
return b149
}150
//返回双击事件a的发生点相对控件b左上角的距离151
function za(a,b)152
{153
if(typeof a.offsetX!="undefined")154
{155
var c=a.target||a.srcElement;156
var d=jd(c,b);157
return new r(a.offsetX+d.x,a.offsetY+d.y)158
}159
else if(typeof a.pageX!="undefined")160
{161
var e=Na(b);162
return new r(a.pageX-e.x,a.pageY-e.y)163
}164
else165
{166
z.incompatible("dblclick"); //返回浏览器不兼容双击的提示167
return new r()168
}169
}170
//返回控件a左上角相对于控件b左上角的距离171
function jd(a,b)172
{173
var c={"x":0,"y":0};174
while(a&&a!=b)175
{176
c.x+=a.offsetLeft;177
c.y+=a.offsetTop;178
a=a.offsetParent179
}180
return c181
}182
//空函数,用来置空事件处理过程183
function _nullFunction()184
{185
}186
//删除a节点187
function Ma(a)188
{189
if(a&&a.parentNode)190
{191
a.parentNode.removeChild(a)192
}193
};posted on 2005-10-19 09:34 K_Reverter 阅读(405) 评论(0) 收藏 举报

浙公网安备 33010602011771号