[Fix] Fixes in get and set of query params

This commit is contained in:
Robert von Burg 2017-02-07 10:30:42 +01:00
parent fb17ad8b34
commit 94e7280b49
3 changed files with 43 additions and 28 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Created by .ignore support plugin (hsz.mobi)
.gitignore
.idea/

View File

@ -4,7 +4,7 @@
Strolch = { Strolch = {
props: { props: {
strolch_js: '0.1.1', strolch_js: '0.1.2',
version: null, version: null,
revision: null, revision: null,
userConfig: null, userConfig: null,
@ -83,8 +83,7 @@ Strolch = {
$.ajax({ $.ajax({
async: false, async: false,
url: that.urls.version url: that.urls.version
} }).done(function (data) {
).done(function (data) {
if (data != null) { if (data != null) {
var ver = data.appVersion.artifactVersion; var ver = data.appVersion.artifactVersion;
var rev = data.appVersion.scmRevision; var rev = data.appVersion.scmRevision;
@ -109,8 +108,7 @@ Strolch = {
$.ajax({ $.ajax({
async: false, async: false,
url: that.urls.version url: that.urls.version
} }).done(function (data) {
).done(function (data) {
if (data != null) { if (data != null) {
var rev = data.appVersion.scmRevision; var rev = data.appVersion.scmRevision;
if (rev != '${buildNumber}') { if (rev != '${buildNumber}') {
@ -188,12 +186,20 @@ Strolch = {
/* /*
* Utils * Utils
*/ */
getQueryParamsAsString: function () {
var hash = document.location.hash;
var hashParts = hash.split('?');
if (hashParts.length !== 2)
return '';
return hashParts[1];
},
getQueryParamValue: function (paramName) { getQueryParamValue: function (paramName) {
var hash = document.location.hash; var hash = document.location.hash;
var hashParts = hash.split('?'); var hashParts = hash.split('?');
if (hashParts.length !== 2) if (hashParts.length !== 2)
return ''; return null;
var queryParams = hashParts[1]; var queryParams = hashParts[1];
var queryArr = queryParams.split('&'); var queryArr = queryParams.split('&');
@ -208,7 +214,7 @@ Strolch = {
} }
} }
return ''; return null;
}, },
setQueryParamValue: function (paramName, paramValue) { setQueryParamValue: function (paramName, paramValue) {
@ -219,8 +225,14 @@ Strolch = {
return; return;
} }
if (Strolch.isEmptyString(hashParts[1])) {
document.location.hash = hashParts[0] + '?' + paramName + '=' + paramValue;
return;
}
hash = hashParts[0] + '?'; hash = hashParts[0] + '?';
var set = false;
var queryParams = hashParts[1]; var queryParams = hashParts[1];
var queryArr = queryParams.split('&'); var queryArr = queryParams.split('&');
for (var i = 0; i < queryArr.length; i++) { for (var i = 0; i < queryArr.length; i++) {
@ -228,15 +240,22 @@ Strolch = {
var queryParam = query.split('='); var queryParam = query.split('=');
if (queryParam.length !== 2 || queryParam[0] !== paramName) { if (queryParam.length !== 2 || queryParam[0] !== paramName) {
hash += query; hash += query;
if (i + 1 < queryArr.length) if (i + 1 < queryArr.length) {
hash += '&'; hash += '&';
}
continue; continue;
} }
hash += paramName + '=' + paramValue; hash += paramName + '=' + paramValue;
if (i + 1 < queryArr.length) if (i + 1 < queryArr.length) {
hash += '&'; hash += '&';
} }
set = true;
}
if (!set) {
hash += '&' + paramName + '=' + paramValue;
}
document.location.hash = hash document.location.hash = hash
}, },
@ -343,8 +362,7 @@ Strolch = {
}, },
next: function () { next: function () {
var index = this.values.indexOf(this.current) + 1; var index = this.values.indexOf(this.current) + 1;
if (index == this.values.length) if (index == this.values.length) index = 0;
index = 0;
this.current = this.values[index]; this.current = this.values[index];
return this.current; return this.current;
}, },
@ -425,13 +443,10 @@ Strolch = {
if (locale != null) { if (locale != null) {
locales.push(locale); locales.push(locale);
var sepIndex = locale.indexOf("-", 0); var sepIndex = locale.indexOf("-", 0);
if (sepIndex == -1) if (sepIndex == -1) sepIndex = locale.indexOf("_", 0);
sepIndex = locale.indexOf("_", 0); if (sepIndex != -1) locales.push(locale.substring(0, sepIndex));
if (sepIndex != -1)
locales.push(locale.substring(0, sepIndex));
} }
if (locale.indexOf("en") != 0) if (locale.indexOf("en") != 0) locales.push("en");
locales.push("en");
var bundle = null; var bundle = null;
for (var i = 0; i < locales.length; ++i) { for (var i = 0; i < locales.length; ++i) {
@ -448,17 +463,14 @@ Strolch = {
}, },
init: function () { init: function () {
if (this.locale == null) if (this.locale == null) this.locale = this.detectLocale();
this.locale = this.detectLocale(); if (this.bundle == null) this.bundle = this.load18n(this.path, this.locale, this.resource);
if (this.bundle == null)
this.bundle = this.load18n(this.path, this.locale, this.resource);
}, },
t: function (key, properties) { t: function (key, properties) {
this.init(); this.init();
var msg = this.bundle[key]; var msg = this.bundle[key];
if (msg == null) if (msg == null) msg = key;
msg = key;
if (properties) { if (properties) {
$.each(properties, function (key, value) { $.each(properties, function (key, value) {

View File

@ -1,6 +1,6 @@
{ {
"name": "strolchjs", "name": "strolchjs",
"version": "0.1.1", "version": "0.1.2",
"main": "strolch.js", "main": "strolch.js",
"ignore": [ "ignore": [
"**/.*", "**/.*",