diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2016-06-22 19:13:43 +0800 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2016-06-22 19:13:43 +0800 |
commit | 841eca04429a69d74904ffc210c2d0845be1c455 (patch) | |
tree | b913cd71b4c4d3f25df5bb8ecf97c5c3ffd1edb4 | |
parent | 8de33f4a4cc1543d973b28ee05fd5670d453736e (diff) | |
download | mywatch-841eca04429a69d74904ffc210c2d0845be1c455.tar.gz |
Use location hash for server name
-rw-r--r-- | static/mywatch.js | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/static/mywatch.js b/static/mywatch.js index d648764..ec9400f 100644 --- a/static/mywatch.js +++ b/static/mywatch.js @@ -1,9 +1,10 @@ $(function() { var info = $('#info'); - var infoHead = $('#info>h1'); var infoAlert = $('#info>div'); + var infoHead = $('#info>h1'); var main = $('#main'); var plBody = $('#processList>tbody'); + var serverList = $('#serverList>ul'); var interval = null; @@ -22,6 +23,27 @@ $(function() { info.show(); } + function switchServer(server) { + clearInterval(interval); + if ('' !== server) { + document.title = server + ' — ' + 'MyWatch'; + serverList.find('.active').removeClass('active'); + var s = $('a[href="#' + server + '"]'); + if (s) { + s.parent().addClass('active'); + getProcessList(server); + interval = setInterval(getProcessList, 60 * 1000, server); + } + } else { + document.title = 'MyWatch'; + } + } + + function onHash() { + switchServer(location.hash.substring(1)); + }; + window.onhashchange = onHash; + function getProcessList(server) { $.ajax({ url: "server/" + server + "/processlist.json", @@ -52,8 +74,8 @@ $(function() { }; $.ajax({ - url: "serverlist.json", - method: "GET", + url: 'serverlist.json', + method: 'GET', error: commonError, success: function(servers) { var total = servers.length; @@ -61,32 +83,29 @@ $(function() { var checked = 0; $.each(servers, function(i, s) { $.ajax({ - url: "server/" + s + "/processlist.json", - method: "HEAD", + url: 'server/' + s + '/processlist.json', + method: 'HEAD', success: function() { available.push(s); }, complete: function() { - var menu = $('#serverList>ul'); checked++; if (checked === total) { $.each(available.sort(), function(i, s) { - menu.append('<li><a href="#">' + s + '</a></li>') + serverList.append('<li><a href="#' + s + '">' + s + '</a></li>') }); - $("#serverList a").on("click", function() { - var server = $(this).text(); - document.title = server + ' — ' + 'MyWatch'; - $(this).parent().parent().find('.active').removeClass('active'); - $(this).parent().addClass('active'); - clearInterval(interval); - getProcessList(server); - interval = setInterval(getProcessList, 60 * 1000, server); + serverList.find('a').on('click', function() { + var s = $(this).text(); + if ('#' + s === location.hash) { + getProcessList(s); + } }); info.hide(); + onHash(); } } }); }); } }); -}); +});
\ No newline at end of file |