From bf51125c3bbed47e6fa040f1f726fa0ea8627299 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 13 May 2013 02:19:14 +0200 Subject: add html5 history --- index.html | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'index.html') diff --git a/index.html b/index.html index 390a354..b75d6b1 100644 --- a/index.html +++ b/index.html @@ -44,6 +44,7 @@ + @@ -67,11 +68,13 @@ } $.Mustache.load('./templates/index.html').done(function () { - $('#content').mustache('hosts', {'hosts':hosts}); + $('#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}, $(this).attr('innerHtml'), 'index.html?'+uri); + return false; }); }); }); @@ -88,20 +91,40 @@ }), function(obj, key) { obj.device = key; return obj; }); $.Mustache.load('./templates/host.html').done(function () { - $('#content').mustache('hostinfo', data, {method:'html'}); - }); + $('#content').mustache('hostinfo', data, {method: 'html'}); - $("#index").click("hover", function(event){ - render.index(); + $("#index").click("hover", function(event){ + render.index(); + History.pushState({host: undefined}, 'Overview', 'index.html'); + return false; + }); }); }); } }; $(document).ready(function() { - render.index(); - }); + 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); + } + else { + render.index(); + } + }); -- cgit v1.2.3-1-g7c22