diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2013-05-15 02:46:51 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-05-15 02:46:51 +0200 |
commit | 469b56ed8f9885b7bc7a18723b14f4690c8d5df4 (patch) | |
tree | 3b62e3fe981bc9d8edaf46e6b9459b54a5f04a42 | |
parent | d674fcb0b13a187af863505b521859880fba6131 (diff) | |
download | www-469b56ed8f9885b7bc7a18723b14f4690c8d5df4.tar.gz www-469b56ed8f9885b7bc7a18723b14f4690c8d5df4.tar.bz2 www-469b56ed8f9885b7bc7a18723b14f4690c8d5df4.zip |
js: move all the js code for the page into own file
-rw-r--r-- | index.html | 89 | ||||
-rw-r--r-- | js/page.js | 84 |
2 files changed, 86 insertions, 87 deletions
@@ -16,94 +16,9 @@ <script src="js/bootstrap.min.js"></script> <script src="js/mustache.js"></script> <script src="js/underscore.min.js"></script> - <script type="text/javascript"> - - var strip = function(data) { return data.split('.')[0] }; - - render = { - 'index' : function() { - jQuery.get('data/metadata/hosts', function(raw) { - var data = jsyaml.load(raw), - hosts = []; - - for(var i=0; i < data.hosts.length; i++) { - var entry = data.hosts[i]; - hosts.push({ - 'name' : strip(entry), - 'uri' : entry - }); - } - - $.Mustache.load('./templates/index.html').done(function () { - $('#content').mustache('hosts', {'hosts':hosts}, {method: 'html'}); - - $("#hosts a").click("hover", function(event){ - var uri = $(this).attr('data-uri'); - render.host(uri); - History.pushState({host: uri}, 'Hostinfo: ' + uri, 'index.html?'+uri); - return false; - }); - }); - }); - }, - - 'host' : function(uri) { - jQuery.get('data/'+uri, function(raw) { - var data = jsyaml.load(raw); - - data.name = strip(data.hostname); - data.interfaces = _.map( - _.groupBy( - _.filter(data.addresses, function(x) { - return typeof x.vserver == 'undefined'; - }), - function(x) { - return x.interface; - }), - function(obj, key) { - obj.device = key; - return obj; - }); - - $.Mustache.load('./templates/host.html').done(function () { - $('#content').mustache('hostinfo', data, {method: 'html'}); - - $("#index").click("hover", function(event){ - render.index(); - History.pushState({host: undefined}, 'Hostinfo: Overview', 'index.html'); - return false; - }); - }); - }); - } - }; - - $(document).ready(function() { - var History = window.History; - if (History.enabled) { - History.Adapter.bind(window,'statechange',function(){ - var State = History.getState(); - if (State.data.host) { - render.host(State.data.host); - } - else { - render.index(); - } - }); - } - - var host = window.location.search.split('?')[1] || undefined; - if (host) { - render.host(host); - document.title = 'Hostinfo: ' + host; - History.replaceState({host: host}, 'Hostinfo: ' + host, 'index.html?' + host); - } - else { - render.index(); - } - }); - </script> + <script src="js/page.js"></script> </head> + <body> <div class="container"> <div class="row"> diff --git a/js/page.js b/js/page.js new file mode 100644 index 0000000..6177e41 --- /dev/null +++ b/js/page.js @@ -0,0 +1,84 @@ +var strip = function(data) { return data.split('.')[0] }; + +render = { + 'index' : function() { + jQuery.get('data/metadata/hosts', function(raw) { + var data = jsyaml.load(raw), + hosts = []; + + for(var i=0; i < data.hosts.length; i++) { + var entry = data.hosts[i]; + hosts.push({ + 'name' : strip(entry), + 'uri' : entry + }); + } + + $.Mustache.load('./templates/index.html').done(function () { + $('#content').mustache('hosts', {'hosts':hosts}, {method: 'html'}); + + $("#hosts a").click("hover", function(event){ + var uri = $(this).attr('data-uri'); + render.host(uri); + History.pushState({host: uri}, 'Hostinfo: ' + uri, 'index.html?'+uri); + return false; + }); + }); + }); + }, + + 'host' : function(uri) { + jQuery.get('data/'+uri, function(raw) { + var data = jsyaml.load(raw); + + data.name = strip(data.hostname); + data.interfaces = _.map( + _.groupBy( + _.filter(data.addresses, function(x) { + return typeof x.vserver == 'undefined'; + }), + function(x) { + return x.interface; + }), + function(obj, key) { + obj.device = key; + return obj; + }); + + $.Mustache.load('./templates/host.html').done(function () { + $('#content').mustache('hostinfo', data, {method: 'html'}); + + $("#index").click("hover", function(event){ + render.index(); + History.pushState({host: undefined}, 'Hostinfo: Overview', 'index.html'); + return false; + }); + }); + }); + } +}; + +$(document).ready(function() { + var History = window.History; + if (History.enabled) { + History.Adapter.bind(window,'statechange',function(){ + var State = History.getState(); + if (State.data.host) { + render.host(State.data.host); + } + else { + render.index(); + } + }); + } + + var host = window.location.search.split('?')[1] || undefined; + if (host) { + render.host(host); + document.title = 'Hostinfo: ' + host; + History.replaceState({host: host}, 'Hostinfo: ' + host, 'index.html?' + host); + } + else { + render.index(); + } +}); |