making the app navigatable by #hash
This commit is contained in:
+34
-17
@@ -258,6 +258,35 @@
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse hash as in http://www.example.com/path#hash as if it were
|
||||||
|
// path and arguments.
|
||||||
|
function parseUrlHash(hash) {
|
||||||
|
var parser = document.createElement('a');
|
||||||
|
parser.href = '/' + location.hash.substr(1);
|
||||||
|
var params = {};
|
||||||
|
parser.search.substr(1).split("&").forEach(function(part) {
|
||||||
|
var item = part.split("=");
|
||||||
|
if (item[0]) {
|
||||||
|
params[decodeURIComponent(item[0])] = decodeURIComponent(item[1]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return {path: parser.pathname, params: params};
|
||||||
|
}
|
||||||
|
|
||||||
|
function composeUrlHash(path, params) {
|
||||||
|
var url = path;
|
||||||
|
var args = [];
|
||||||
|
for (var key in params) {
|
||||||
|
if (params.hasOwnProperty(key)) {
|
||||||
|
args.push(key + "=" + params[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (args.length > 0) {
|
||||||
|
url += "?" + args.join("&");
|
||||||
|
}
|
||||||
|
return url.
|
||||||
|
}
|
||||||
|
|
||||||
// Detect server address from the URL
|
// Detect server address from the URL
|
||||||
function detectServerAddress() {
|
function detectServerAddress() {
|
||||||
var host = DEFAULT_HOST;
|
var host = DEFAULT_HOST;
|
||||||
@@ -289,18 +318,6 @@
|
|||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct a user discovery tag
|
|
||||||
function to_tags(tagsObj) {
|
|
||||||
if (tagsObj && Object.keys(tagsObj).length > 0) {
|
|
||||||
var tags = [];
|
|
||||||
for (var key in tagsObj) {
|
|
||||||
tags.push(key + ":" + tagsObj[key]);
|
|
||||||
}
|
|
||||||
return tags;
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deep-shallow compare two arrays.
|
// Deep-shallow compare two arrays.
|
||||||
function arrayEqual(a, b) {
|
function arrayEqual(a, b) {
|
||||||
// Compare lengths first.
|
// Compare lengths first.
|
||||||
@@ -3755,7 +3772,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleHashRoute: function(e) {
|
handleHashRoute: function(e) {
|
||||||
console.log("hashchange", location.hash, e.oldURL, e.newURL);
|
console.log("hashchange", location.hash);
|
||||||
},
|
},
|
||||||
handleOnline: function(online) {
|
handleOnline: function(online) {
|
||||||
var newState = {liveConnection: online};
|
var newState = {liveConnection: online};
|
||||||
@@ -3937,6 +3954,7 @@
|
|||||||
handleTopicSelected: function(topicName, unused_index, online, acs) {
|
handleTopicSelected: function(topicName, unused_index, online, acs) {
|
||||||
if (topicName) {
|
if (topicName) {
|
||||||
// Contact selected
|
// Contact selected
|
||||||
|
location.hash = topicName;
|
||||||
this.setState({
|
this.setState({
|
||||||
topicSelected: topicName,
|
topicSelected: topicName,
|
||||||
mobilePanel: 'topic-view',
|
mobilePanel: 'topic-view',
|
||||||
@@ -3947,6 +3965,7 @@
|
|||||||
infoPanelShowMembers: Tinode.getTopicType(topicName) === "grp"
|
infoPanelShowMembers: Tinode.getTopicType(topicName) === "grp"
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
location.hash = null;
|
||||||
// Currently selected contact deleted
|
// Currently selected contact deleted
|
||||||
this.setState({
|
this.setState({
|
||||||
topicSelected: null,
|
topicSelected: null,
|
||||||
@@ -4126,10 +4145,8 @@
|
|||||||
|
|
||||||
handleLogout: function() {
|
handleLogout: function() {
|
||||||
localStorage.removeItem("auth-token");
|
localStorage.removeItem("auth-token");
|
||||||
// Tell Tinode to close connection and clear the caches.
|
this.setState(this.getInitialState());
|
||||||
// Re-initialize state.
|
this.tnSetup(this.state.serverAddress, this.state.transport);
|
||||||
// Re-initialize Tinode.
|
|
||||||
console.log("Logout not fully implemented");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
handleLeaveUnsubRequest: function(topicName) {
|
handleLeaveUnsubRequest: function(topicName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user