Skip to content

Commit e2c71ac

Browse files
committed
Update dist files.
1 parent 903441a commit e2c71ac

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

dist/ping.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* ping.js - v0.1.2
2+
* ping.js - v0.1.3
33
* Ping Utilities in Javascript
44
* http://github.com/alfg/ping.js
55
*
@@ -11,42 +11,42 @@
1111
* @returns {Ping}
1212
* @constructor
1313
*/
14-
var Ping = function() {};
14+
var Ping = function(opt) {
15+
this.opt = opt || {};
16+
this.favicon = this.opt.favicon || "/favicon.ico";
17+
this.timeout = this.opt.timeout || 0;
18+
};
1519

1620
/**
1721
* Pings source and triggers a callback when completed.
1822
* @param source Source of the website or server, including protocol and port.
19-
* @param callback Callback function to trigger when completed.
23+
* @param callback Callback function to trigger when completed. Returns error and ping value.
2024
* @param timeout Optional number of milliseconds to wait before aborting.
2125
*/
22-
Ping.prototype.ping = function(source, callback, timeout) {
26+
Ping.prototype.ping = function(source, callback) {
2327
this.img = new Image();
24-
timeout = timeout || 0;
2528
var timer;
2629

2730
var start = new Date();
2831
this.img.onload = pingCheck;
29-
this.img.onerror = pingError;
30-
if (timeout) { timer = setTimeout(pingCheck, timeout); }
32+
this.img.onerror = pingCheck;
33+
if (this.timeout) { timer = setTimeout(pingCheck, this.timeout); }
3134

32-
/**
33-
* Does not resolve.
34-
*/
35-
function pingError() {
36-
callback("Error");
37-
}
38-
3935
/**
4036
* Times ping and triggers callback.
4137
*/
42-
function pingCheck() {
38+
function pingCheck(e) {
4339
if (timer) { clearTimeout(timer); }
4440
var pong = new Date() - start;
4541

4642
if (typeof callback === "function") {
47-
callback(pong);
43+
if (e.type === "error") {
44+
console.error("error loading resource");
45+
return callback("error", pong);
46+
}
47+
return callback(null, pong);
4848
}
4949
}
5050

51-
this.img.src = source + "/favicon.ico?" + (+new Date()); // Trigger image load with cache buster
51+
this.img.src = source + this.favicon + "?" + (+new Date()); // Trigger image load with cache buster
5252
};

dist/ping.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)