added favicon

compute default url
This commit is contained in:
longsleep 2012-12-13 16:10:49 +00:00
parent 24033fc3ee
commit 37c0263b51
4 changed files with 36 additions and 23 deletions

BIN
client/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

View File

@ -2,6 +2,7 @@
<html class="no-js">
<head>
<title>Realtime traffic monitor</title>
<link href="favicon.ico" rel="icon" type="image/x-icon"/>
<link type="text/css" rel="stylesheet" href="css/base.css">
<link type="text/css" rel="stylesheet" href="css/graph.css">
<link type="text/css" rel="stylesheet" href="css/legend.css">

View File

@ -1,14 +1,14 @@
(function() {
var RealtimeTraffic = function() {
this.tv = 500;
this.last_data = null;
this.connection = null;
this.initialize();
}
RealtimeTraffic.prototype.initialize = function() {
var graph = this.graph = new Rickshaw.Graph( {
@ -21,7 +21,7 @@
timeInterval: this.tv,
maxDataPoints: 200,
timeBase: new Date().getTime() / 1000
})
})
} );
var xAxis = new Rickshaw.Graph.Axis.Time({
@ -57,13 +57,13 @@
};
RealtimeTraffic.prototype.disconnect = function() {
if (this.connection) {
this.connection.close();
this.connection = this.last_data = null;
this.needsReset = true;
}
};
RealtimeTraffic.prototype.connect = function(url, interf) {
@ -71,13 +71,13 @@
var ws_url = url+'?if='+interf;
this.disconnect();
if (this.needsReset) {
$("#chart").empty();
$("#legend").empty();
this.initialize();
}
var connection;
var that = this;
@ -125,7 +125,7 @@
that.last_data = interface_data;
}
};
};
$(document).ready(function() {
@ -148,7 +148,19 @@ $(document).ready(function() {
url = localStorage.getItem("org.longsleep.realtimetraffic.defaults.url");
interf = localStorage.getItem("org.longsleep.realtimetraffic.defaults.interf");
}
// compute default URL based on current URL.
if (!url) {
if (/^((http|https):\/\/)/i.test(window.location.href)) {
if (/^(https:\/\/)/i.test(window.location.href)) {
url = "wss://"+window.location.host+"/realtimetraffic";
} else {
url = "ws://"+window.location.host+"/realtimetraffic";
}
}
}
if (url) {
input_url.val(url);
}
@ -169,18 +181,18 @@ $(document).ready(function() {
$(realtimetraffic).on("close", function() {
control.removeClass("connected");
});
button_start.on("click", function() {
url = $.trim(input_url.val());
interf = $.trim(input_interf.val());
if (!url || !interf) {
return;
}
realtimetraffic.connect(url, interf);
if (Modernizr.localstorage) {
try {
localStorage.setItem("org.longsleep.realtimetraffic.defaults.url", url);
@ -189,15 +201,15 @@ $(document).ready(function() {
console.warn("Failed to store settings into localStorage with error " + e);
}
}
});
button_stop.on("click", function() {
realtimetraffic.disconnect();
});
if (params.autostart === "1") {
button_start.click();
}

View File

@ -141,7 +141,7 @@ class ClientHandler(tornado.web.RequestHandler):
def main(listen="127.0.0.1:8088"):
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-l", "--listen", dest="listen", help="listen address (default: [%s])" % listen, default=listen)
parser.add_option("--ssl_keyfile", dest="ssl_keyfile", help="SSL key file", metavar="FILE")
@ -159,7 +159,7 @@ def main(listen="127.0.0.1:8088"):
listen = "%s:%s" % (address, port)
application = tornado.web.Application([
(r'^/ws$', WSHandler),
(r'^/realtimetraffic$', WSHandler),
(r'^/css/(.*)$', tornado.web.StaticFileHandler, {'path': os.path.join(CLIENT_ROOT, 'css')}),
(r'^/scripts/(.*)$', tornado.web.StaticFileHandler, {'path': os.path.join(CLIENT_ROOT, 'scripts')}),
(r'^/img/(.*)$', tornado.web.StaticFileHandler, {'path': os.path.join(CLIENT_ROOT, 'img')}),
@ -194,5 +194,5 @@ def main(listen="127.0.0.1:8088"):
if __name__ == "__main__":
status = main()
sys.exit(status)