Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #536 from kleintom/dup_results
Browse files Browse the repository at this point in the history
Correctly set 'limit' in JS doQuery when a queryString exists.
  • Loading branch information
kleintom committed May 10, 2016
2 parents 79fa513 + 1f691fe commit 6165314
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions dxr/static_unhashed/js/dxr.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ $(function() {

// If no data is returned, inform the user.
if (!data.results.length) {
resultsLineCount = 0;
if (!append) {
contentContainer
.empty()
Expand Down Expand Up @@ -343,14 +344,22 @@ $(function() {
*/
function doQuery(redirect, queryString, appendResults) {
query = $.trim(queryField.val());
var myRequestNumber = nextRequestNumber,
lineHeight = parseInt(contentContainer.css('line-height'), 10),
limit = Math.floor((window.innerHeight / lineHeight) + 25);
var myRequestNumber = nextRequestNumber, limit, match, lineHeight;

redirect = redirect || false;
// Turn into a boolean if it was undefined.
appendResults = !!appendResults;
queryString = queryString || buildAjaxURL(query, caseSensitiveBox.prop('checked'), limit, 0, redirect);
if (queryString) {
// Normally there will be no explicit limit set in this case, but
// there's nothing stopping a user from setting it by hand in the
// url, so I guess we should check:
match = /[?&]limit=([0-9]+)/.exec(queryString);
limit = match ? match[1] : defaultDataLimit;
} else {
lineHeight = parseInt(contentContainer.css('line-height'), 10);
limit = Math.floor((window.innerHeight / lineHeight) + 25);
queryString = buildAjaxURL(query, caseSensitiveBox.prop('checked'), limit, 0, redirect);
}
function oneMoreRequest() {
if (requestsInFlight === 0) {
$('#search-box').addClass('in-progress');
Expand Down Expand Up @@ -406,15 +415,18 @@ $(function() {
else if (!appendResults)
// Update the history state if we're not appending: this is a new search.
historyWaiter = setTimeout(pushHistory, timeouts.history);
if (!appendResults) {
previousDataLimit = limit;
dataOffset = 0;
}
// If there were no results this time then we shouldn't turn
// infinite scroll (back) on (otherwise if the number of
// results exactly equals the limit we can end up sending a
// query returning 0 results everytime we scroll).
if (resultsLineCount)
pollScrollPosition();
}

if (!appendResults) {
previousDataLimit = limit;
dataOffset = 0;
}

// Start the scroll pos poller.
pollScrollPosition();
oneFewerRequest();
}
})
Expand Down

0 comments on commit 6165314

Please sign in to comment.