Skip to content

Commit

Permalink
add hash support to webconsole
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Pacheco committed Apr 20, 2012
1 parent a6d278b commit f8eaf60
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/webconsole/resources/js/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ function kInit()
kDump, false);

kRedrawWorld();

kLoadHash();

if (kServiceUrls.length > 0)
kRefresh();
}

function kFormAddService()
{
if (kServiceField.value.length > 0)
kServiceUrls.push(kServiceField.value);
kServiceField.value = '';
kSaveHash();
kRefresh();
}

Expand All @@ -47,6 +53,26 @@ function kFormRefreshAll()
kRefresh();
}

function kSaveHash()
{
window.location.hash = kServiceUrls.map(function (url) {
return ('host=' + encodeURIComponent(url));
}).join('&');
}

function kLoadHash()
{
var entries = window.location.hash.substr(1).split('&');

entries.forEach(function (entry) {
if (entry.substr(0, 'host='.length) != 'host=')
return;

kServiceUrls.push(decodeURIComponent(
entry.substr('host='.length)));
});
}

function kRedrawWorld()
{
kRedrawServices();
Expand Down Expand Up @@ -232,6 +258,7 @@ function kRefresh()
});

kSnapshot = data;
kSaveHash();
kRedrawWorld();
});

Expand Down

0 comments on commit f8eaf60

Please sign in to comment.