Use node querystring module to parse query string like name value pairs from fragment

This commit is contained in:
Steven Hammerton 2015-10-12 10:11:02 +01:00
parent 353af6c647
commit f5039ac9af
1 changed files with 11 additions and 12 deletions

View File

@ -21,21 +21,20 @@ var sdk = require("matrix-react-sdk");
sdk.loadSkin(require('../skins/vector/skindex')); sdk.loadSkin(require('../skins/vector/skindex'));
sdk.loadModule(require('../modules/VectorConferenceHandler')); sdk.loadModule(require('../modules/VectorConferenceHandler'));
var qs = require("querystring");
var lastLocationHashSet = null; var lastLocationHashSet = null;
function parseQueryParams(location) { // We want to support some name / value pairs in the fragment
// so we're re-using query string ike format
function parseQsFromFragment(location) {
var hashparts = location.hash.split('?'); var hashparts = location.hash.split('?');
var params = {}; if (hashparts.length > 1) {
if (hashparts.length == 2) { console.log(qs.parse(hashparts[1]));
var pairs = hashparts[1].split('&'); return qs.parse(hashparts[1]);
for (var i = 0; i < pairs.length; ++i) {
var parts = pairs[i].split('=');
if (parts.length != 2) continue;
params[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
}
} }
return params return {};
} }
// Here, we do some crude URL analysis to allow // Here, we do some crude URL analysis to allow
@ -43,9 +42,9 @@ function parseQueryParams(location) {
// deep-links in this example. // deep-links in this example.
function routeUrl(location) { function routeUrl(location) {
if (location.hash.indexOf('#/register') == 0) { if (location.hash.indexOf('#/register') == 0) {
window.matrixChat.showScreen('register', parseQueryParams(location)); window.matrixChat.showScreen('register', parseQsFromFragment(location));
} else if (location.hash.indexOf('#/login/cas') == 0) { } else if (location.hash.indexOf('#/login/cas') == 0) {
window.matrixChat.showScreen('cas_login', parseQueryParams(location)); window.matrixChat.showScreen('cas_login', parseQsFromFragment(location));
} else { } else {
window.matrixChat.showScreen(location.hash.substring(2)); window.matrixChat.showScreen(location.hash.substring(2));
} }