Skip to content

Commit fb99591

Browse files
committed
tab空格
1 parent 20b589f commit fb99591

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

online.js

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
;(function(w){
22
var xmlhttp = new XMLHttpRequest(),
3-
time=2000,//设置轮询时间
4-
url="http://********.com/online.php";
5-
//当 `url`为空的时候 默认所有浏览器使用 onLine 和 offline事件
3+
time=2000,//设置轮询时间
4+
url="http://********.com/online.php";
5+
//当 `url`为空的时候 默认所有浏览器使用 onLine 和 offline事件
66

77
w.onlinenetwork = w.onlinenetwork || {};
8-
w.onlinenetwork = {
9-
setStatus:function (newStatus) {
10-
this.eventStatus(newStatus);
11-
w.onLine = newStatus;
12-
},
13-
//状态改变执行事件
14-
eventStatus: function (newStatus) {
15-
if (newStatus === true && w.onLineHandler !== undefined && (w.onLine !== true || this.handlerFired === false)) {
16-
w.onLineHandler();
17-
}
18-
if (newStatus === false && w.offLineHandler !== undefined && (w.onLine !== false || this.handlerFired === false)) {
19-
w.offLineHandler();
20-
}
21-
this.handlerFired = true;
22-
},
23-
//http请求
24-
XMLHttpLogic:function (async) {
25-
var url = this.getOnLineCheckURL(),
8+
w.onlinenetwork = {
9+
setStatus:function (newStatus) {
10+
this.eventStatus(newStatus);
11+
w.onLine = newStatus;
12+
},
13+
//状态改变执行事件
14+
eventStatus: function (newStatus) {
15+
if (newStatus === true && w.onLineHandler !== undefined && (w.onLine !== true || this.handlerFired === false)) {
16+
w.onLineHandler();
17+
}
18+
if (newStatus === false && w.offLineHandler !== undefined && (w.onLine !== false || this.handlerFired === false)) {
19+
w.offLineHandler();
20+
}
21+
this.handlerFired = true;
22+
},
23+
//http请求
24+
XMLHttpLogic:function (async) {
25+
var url = this.getOnLineCheckURL(),
2626
self = this;
2727
if(async){
2828
xmlhttp.onreadystatechange = function () {
@@ -37,9 +37,9 @@
3737
}else{
3838
xmlhttp.onreadystatechange = undefined;
3939
}
40-
xmlhttp.open("HEAD", url, async)
40+
xmlhttp.open("HEAD", url, async)
4141
this.tryToSend(xmlhttp);
42-
},
42+
},
4343
processXmlhttpStatus: function () {
4444
var tempOnLine = w.onlinenetwork.verifyStatus(xmlhttp.status);
4545
this.setStatus(tempOnLine);
@@ -56,14 +56,14 @@
5656
verifyStatus:function (status) {
5757
return status === 200;
5858
},
59-
//url加上随机数
60-
getOnLineCheckURL: function () {
61-
return url + '?' + Math.floor(Math.random() * 1000000);
62-
},
63-
//非 chrome 和 Safari 浏览器不停的检查,嘿嘿
64-
startCheck:function(){
65-
setInterval("window.onlinenetwork.XMLHttpLogic(true)",time);
66-
},
59+
//url加上随机数
60+
getOnLineCheckURL: function () {
61+
return url + '?' + Math.floor(Math.random() * 1000000);
62+
},
63+
//非 chrome 和 Safari 浏览器不停的检查,嘿嘿
64+
startCheck:function(){
65+
setInterval("window.onlinenetwork.XMLHttpLogic(true)",time);
66+
},
6767
//第一次检查是否在线
6868
checkOnLine:function(){
6969
this.XMLHttpLogic(false)
@@ -75,43 +75,43 @@
7575
this.setStatus(true);
7676
}
7777
},
78-
//判断浏览器
79-
getExplorer: function(newStatus){
80-
var explorer = window.navigator.userAgent;
78+
//判断浏览器
79+
getExplorer: function(newStatus){
80+
var explorer = window.navigator.userAgent;
8181
this.setStatus(newStatus)
82-
if((explorer.indexOf('Firefox') >= 0 || explorer.indexOf('MSIE') >= 0)&&url){
83-
console.log("test:1")
82+
if((explorer.indexOf('Firefox') >= 0 || explorer.indexOf('MSIE') >= 0)&&url){
83+
console.log("test:1")
8484
this.checkOnLine()
8585
this.setStatus(newStatus)
8686
this.startCheck(newStatus)
8787
}else{
88-
console.log("test:2")
88+
console.log("test:2")
8989
this.eventStatus(newStatus)
90-
}
91-
},
92-
//绑定事件
93-
addEvent: function (obj, type, callback) {
94-
if (window.attachEvent) obj.attachEvent('on' + type, callback);
95-
else obj.addEventListener(type, callback);
96-
},
97-
init:function(){
90+
}
91+
},
92+
//绑定事件
93+
addEvent: function (obj, type, callback) {
94+
if (window.attachEvent) obj.attachEvent('on' + type, callback);
95+
else obj.addEventListener(type, callback);
96+
},
97+
init:function(){
9898

99-
var self = this
99+
var self = this
100100
//获取当前状态
101-
this.addEvent(w, 'load', function () {
101+
this.addEvent(w, 'load', function () {
102102
self.eventStatus(w.onLine);
103103
});
104104

105-
//侦听 online 事件
106-
this.addEvent(w, 'online', function () { self.getExplorer(true) });
105+
//侦听 online 事件
106+
this.addEvent(w, 'online', function () { self.getExplorer(true) });
107107

108-
//侦听 offline 事件
109-
this.addEvent(w, 'offline', function () { self.getExplorer(false) });
108+
//侦听 offline 事件
109+
this.addEvent(w, 'offline', function () { self.getExplorer(false) });
110110

111111
self.getExplorer(true)
112-
this.handlerFired = false;
113-
}
114-
}
115-
w.onlinenetwork.init()
116-
112+
this.handlerFired = false;
113+
}
114+
}
115+
w.onlinenetwork.init()
116+
117117
})(window);

0 commit comments

Comments
 (0)