Permalink
Browse files

add hash support to webconsole

  • Loading branch information...
davepacheco committed Apr 20, 2012
1 parent a6d278b commit f8eaf605c647c57c0896fb29fe4ecf26e636bf9a
Showing with 27 additions and 0 deletions.
  1. +27 −0 examples/webconsole/resources/js/console.js
@@ -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();
}
@@ -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();
@@ -232,6 +258,7 @@ function kRefresh()
});
kSnapshot = data;
+ kSaveHash();
kRedrawWorld();
});

0 comments on commit f8eaf60

Please sign in to comment.