[Fix] Fixed bugs in setQueryParamValue() and isEmptyString()
- isEmptyString() didn't check for null - setQueryParamValue() set null query parameter, instead of removing the query parameter
This commit is contained in:
parent
b0acea9aea
commit
59c1344059
29
Strolch.js
29
Strolch.js
|
@ -221,12 +221,16 @@ Strolch = {
|
|||
var hash = document.location.hash;
|
||||
var hashParts = hash.split('?');
|
||||
if (hashParts.length !== 2) {
|
||||
document.location.hash = hash + '/?' + paramName + '=' + paramValue;
|
||||
if (Strolch.isNotEmptyString(paramValue)) {
|
||||
document.location.hash = hash + '/?' + paramName + '=' + paramValue;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Strolch.isEmptyString(hashParts[1])) {
|
||||
document.location.hash = hashParts[0] + '?' + paramName + '=' + paramValue;
|
||||
if (Strolch.isNotEmptyString(paramValue)) {
|
||||
document.location.hash = hashParts[0] + '?' + paramName + '=' + paramValue;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -239,22 +243,27 @@ Strolch = {
|
|||
var query = queryArr[i];
|
||||
var queryParam = query.split('=');
|
||||
if (queryParam.length !== 2 || queryParam[0] !== paramName) {
|
||||
hash += query;
|
||||
if (i + 1 < queryArr.length) {
|
||||
if (i != 0) {
|
||||
hash += '&';
|
||||
}
|
||||
hash += query;
|
||||
continue;
|
||||
}
|
||||
|
||||
hash += paramName + '=' + paramValue;
|
||||
if (i + 1 < queryArr.length) {
|
||||
hash += '&';
|
||||
if (Strolch.isNotEmptyString(paramValue)) {
|
||||
if (i != 0) {
|
||||
hash += '&';
|
||||
}
|
||||
hash += paramName + '=' + paramValue;
|
||||
}
|
||||
set = true;
|
||||
}
|
||||
|
||||
if (!set) {
|
||||
hash += '&' + paramName + '=' + paramValue;
|
||||
if (!set && Strolch.isNotEmptyString(paramValue)) {
|
||||
if (i != 0) {
|
||||
hash += '&';
|
||||
}
|
||||
hash += paramName + '=' + paramValue;
|
||||
}
|
||||
|
||||
document.location.hash = hash
|
||||
|
@ -271,7 +280,7 @@ Strolch = {
|
|||
},
|
||||
|
||||
isEmptyString: function (val) {
|
||||
return typeof val == 'undefined' || val == '';
|
||||
return typeof val == 'undefined' || val == null || val == '';
|
||||
},
|
||||
isNotEmptyString: function (val) {
|
||||
return !this.isEmptyString(val);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "strolchjs",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"main": "strolch.js",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
|
|
Loading…
Reference in New Issue