Skip to content

Commit

Permalink
Redirect to first page after changing product_list_limit to value h…
Browse files Browse the repository at this point in the history
…igher than current.
  • Loading branch information
lbajsarowicz committed Feb 28, 2020
1 parent d7cdd7b commit 05f1a2b
Showing 1 changed file with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,49 @@ define([
);
},

/**
* @param {String} paramName
* @param {*} paramValue
* @param {*} defaultValue
*/
changeUrl: function (paramName, paramValue, defaultValue) {
getUrlParams: function() {
var decode = window.decodeURIComponent,
urlPaths = this.options.url.split('?'),
baseUrl = urlPaths[0],
urlParams = urlPaths[1] ? urlPaths[1].split('&') : [],
paramData = {},
parameters, i, form, params, key, input, formKey;
params = {}, parameters, i;

for (i = 0; i < urlParams.length; i++) {
parameters = urlParams[i].split('=');
paramData[decode(parameters[0])] = parameters[1] !== undefined ?
params[decode(parameters[0])] = parameters[1] !== undefined ?
decode(parameters[1].replace(/\+/g, '%20')) :
'';
}

return params;
},

getCurrentLimit: function()
{
var currentLimit = this.getUrlParams()[this.options.limit];

if (currentLimit === undefined) {
currentLimit = this.options.limitDefault;
}

return currentLimit;
},


/**
* @param {String} paramName
* @param {*} paramValue
* @param {*} defaultValue
*/
changeUrl: function (paramName, paramValue, defaultValue) {
var urlPaths = this.options.url.split('?'),
baseUrl = urlPaths[0],
paramData = this.getUrlParams(),
form, params, key, input, formKey;

if (paramName === this.options.limit && paramValue > this.getCurrentLimit()) {
delete paramData['p'];
}

paramData[paramName] = paramValue;

if (this.options.post) {
Expand Down Expand Up @@ -130,6 +154,7 @@ define([
if (paramValue == defaultValue) { //eslint-disable-line eqeqeq
delete paramData[paramName];
}

paramData = $.param(paramData);
location.href = baseUrl + (paramData.length ? '?' + paramData : '');
}
Expand Down

0 comments on commit 05f1a2b

Please sign in to comment.