Merge pull request #547 from pigshell/hashargs

Add hash fragment as an optional method to supply config variables.

Closes #544
This commit is contained in:
Solly Ross
2016-01-06 14:22:24 -05:00
4 changed files with 43 additions and 16 deletions

View File

@@ -97,7 +97,7 @@ var UI;
UI.initSetting('path', 'websockify');
UI.initSetting('repeaterID', '');
var autoconnect = WebUtil.getQueryVar('autoconnect', false);
var autoconnect = WebUtil.getConfigVar('autoconnect', false);
if (autoconnect === 'true' || autoconnect == '1') {
autoconnect = true;
UI.connect();
@@ -355,7 +355,7 @@ var UI;
// Initial page load read/initialization of settings
initSetting: function(name, defVal) {
// Check Query string followed by cookie
var val = WebUtil.getQueryVar(name);
var val = WebUtil.getConfigVar(name);
if (val === null) {
val = WebUtil.readSetting(name, defVal);
}

View File

@@ -90,6 +90,29 @@ WebUtil.getQueryVar = function (name, defVal) {
}
};
// Read a hash fragment variable
WebUtil.getHashVar = function (name, defVal) {
"use strict";
var re = new RegExp('.*[&#]' + name + '=([^&]*)'),
match = document.location.hash.match(re);
if (typeof defVal === 'undefined') { defVal = null; }
if (match) {
return decodeURIComponent(match[1]);
} else {
return defVal;
}
};
// Read a variable from the fragment or the query string
// Fragment takes precedence
WebUtil.getConfigVar = function (name, defVal) {
"use strict";
var val = WebUtil.getHashVar(name);
if (val === null) {
val = WebUtil.getQueryVar(name, defVal);
}
return val;
};
/*
* Cookie handling. Dervied from: http://www.quirksmode.org/js/cookies.html