summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2017-02-22 21:52:56 (GMT)
committerChristian Pointner <equinox@helsinki.at>2017-02-22 21:52:56 (GMT)
commit610dc51f74d4cee975ba575e012d447f84dcbb4c (patch)
treeb3be44637a67fec9ed04c9b12f90234852f7ce90
parente3a0067426b0c9dae443c579f7baaef0ef3bdd96 (diff)
make site independent of the url
-rw-r--r--www/js/utils.js56
1 files changed, 54 insertions, 2 deletions
diff --git a/www/js/utils.js b/www/js/utils.js
index 6140254..1022ab5 100644
--- a/www/js/utils.js
+++ b/www/js/utils.js
@@ -116,9 +116,61 @@ function get_rd_week(msEpoch) {
return week;
}
+function parseLocationHref() {
+ var matches = window.location.href.match(/(https?):\/\/(.*)/);
+ if(matches === null) {
+ return null;
+ }
+
+ var uri = {};
+ uri.scheme = matches[1];
+ uri.servername = '';
+ uri.path = [];
+ uri.query = [];
+ uri.fragment = '';
+
+ if(matches[2].indexOf('/') < 0) {
+ uri.servername = parts[2];
+ return uri;
+ }
+
+ var parts = matches[2].split('/');
+ uri.servername = parts[0];
+ uri.path = parts.slice(1);
+
+ var tmp = uri.path[uri.path.length-1];
+ if(tmp.length > 0) {
+ var qidx = tmp.indexOf('?');
+ var fidx = tmp.indexOf('#');
+
+ var query = '';
+ if(qidx >= 0 && fidx >= 0) {
+ uri.path[uri.path.length-1] = tmp.substring(0, qidx);
+ if(qidx < fidx) {
+ query = tmp.substring(qidx+1, fidx);
+ }
+ uri.fragment = tmp.substring(fidx+1);
+ } else if (qidx >= 0 && fidx < 0) {
+ uri.path[uri.path.length-1] = tmp.substring(0, qidx);
+ query = tmp.substring(qidx+1);
+ } else if (qidx < 0 && fidx >= 0) {
+ uri.path[uri.path.length-1] = tmp.substring(0, fidx);
+ uri.fragment = tmp.substring(fidx+1);
+ }
+ if(query.length > 0) {
+ uri.query = query.split('&');
+ }
+ }
+
+ return uri
+}
+
function locationHrefValue() {
- var value = window.location.href.match(/import.helsinki.at\/([a-z]+)\/?([a-z0-9]+)?\/?.*/);
- return value ? value : '';
+ var url = parseLocationHref();
+ if (url.path.length > 1) {
+ return [url.path[0] + '/' + url.path[1], url.path[0], url.path[1]]
+ }
+ return (url.path.length > 0) ? [url.path[0], url.path[0]] : '';
}
/*