Added search query minifying
Seeing 'page=1' and 'query=' in every other link was tiresome. I changed the rules so that such keys are appended only if they hold nontrivial values.
This commit is contained in:
parent
970b9bf06d
commit
1897297127
5 changed files with 30 additions and 9 deletions
|
@ -82,11 +82,12 @@ App.Presenters.PagerPresenter = function(
|
|||
function getUrl(options) {
|
||||
return util.appendComplexRouteParam(
|
||||
baseUri,
|
||||
_.extend(
|
||||
{},
|
||||
pager.getSearchParams(),
|
||||
{page: pager.getPage()},
|
||||
options));
|
||||
util.simplifySearchQuery(
|
||||
_.extend(
|
||||
{},
|
||||
pager.getSearchParams(),
|
||||
{page: pager.getPage()},
|
||||
options)));
|
||||
}
|
||||
|
||||
function syncUrl(options) {
|
||||
|
|
|
@ -41,7 +41,11 @@ App.Services.PostsAroundCalculator = function(_, promise, util, pager) {
|
|||
if (position + direction >= 0 && position + direction < postIds.length) {
|
||||
var url = util.appendComplexRouteParam(
|
||||
'#/post/' + postIds[position + direction],
|
||||
_.extend({page: page}, pager.getSearchParams()));
|
||||
util.simplifySearchQuery(
|
||||
_.extend(
|
||||
{page: page},
|
||||
pager.getSearchParams())));
|
||||
|
||||
resolve(url);
|
||||
} else if (page + direction >= 1) {
|
||||
pager.setPage(page + direction);
|
||||
|
@ -54,7 +58,11 @@ App.Services.PostsAroundCalculator = function(_, promise, util, pager) {
|
|||
|
||||
var url = util.appendComplexRouteParam(
|
||||
'#/post/' + post.id,
|
||||
_.extend({page: page + direction}, pager.getSearchParams()));
|
||||
util.simplifySearchQuery(
|
||||
_.extend(
|
||||
{page: page + direction},
|
||||
pager.getSearchParams())));
|
||||
|
||||
resolve(url);
|
||||
} else {
|
||||
resolve(null);
|
||||
|
|
|
@ -237,6 +237,17 @@ App.Util.Misc = function(_, jQuery, marked, promise) {
|
|||
return result.slice(0, -1);
|
||||
}
|
||||
|
||||
function simplifySearchQuery(query) {
|
||||
if (typeof(query) === 'undefined') {
|
||||
return {};
|
||||
}
|
||||
if (query.page === 1) {
|
||||
delete query.page;
|
||||
}
|
||||
query = _.pick(query, _.identity); //remove falsy values
|
||||
return query;
|
||||
}
|
||||
|
||||
return {
|
||||
promiseTemplate: promiseTemplate,
|
||||
formatRelativeTime: formatRelativeTime,
|
||||
|
@ -249,6 +260,7 @@ App.Util.Misc = function(_, jQuery, marked, promise) {
|
|||
transparentPixel: transparentPixel,
|
||||
loadImagesNicely: loadImagesNicely,
|
||||
appendComplexRouteParam: appendComplexRouteParam,
|
||||
simplifySearchQuery: simplifySearchQuery,
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<% if (canViewPosts) { %>
|
||||
<a class="link"
|
||||
href="<%= util.appendComplexRouteParam('#/post/' + post.id, typeof(query) !== 'undefined' ? query : {}) %>"
|
||||
href="<%= util.appendComplexRouteParam('#/post/' + post.id, util.simplifySearchQuery(query)) %>"
|
||||
title="<%= _.map(post.tags, function(tag) { return '#' + tag.name; }).join(', ') %>">
|
||||
<% } else { %>
|
||||
<span class="link">
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
</div>
|
||||
|
||||
<div class="search">
|
||||
<a class="enabled" href="<%= util.appendComplexRouteParam('#/posts', {query: query.query, order: query.order}) %>">
|
||||
<a class="enabled" href="<%= util.appendComplexRouteParam('#/posts', util.simplifySearchQuery({query: query.query, order: query.order})) %>">
|
||||
Current search: <%= query.query || '-' %>
|
||||
</a>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue