Skip to content

Commit

Permalink
fix(search): fetch "Cannot read property 'top' of undefined
Browse files Browse the repository at this point in the history
When a search has no result and one presses the "arrow down" key on the keyboard, a javascript error

Cannot read property 'top' of undefined

occurs

This PR also fixes dead, unused and unnecessary code of the affected function "ensureVisible"
  • Loading branch information
lubber-de authored May 16, 2021
1 parent 750a192 commit 2d69a7c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/definitions/modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,16 @@ $.fn.search = function(parameters) {
}
}
},
ensureVisible: function ensureVisible($el) {
ensureVisible: function($el) {
var elTop, elBottom, resultsScrollTop, resultsHeight;

if($el.length === 0) {
return;
}
elTop = $el.position().top;
elBottom = elTop + $el.outerHeight(true);

resultsScrollTop = $results.scrollTop();
resultsHeight = $results.height()
parseInt($results.css('paddingTop'), 0) +
parseInt($results.css('paddingBottom'), 0);
resultsHeight = $results.height();

if (elTop < 0) {
$results.scrollTop(resultsScrollTop + elTop);
Expand Down Expand Up @@ -980,9 +980,7 @@ $.fn.search = function(parameters) {
duration : settings.duration,
onShow : function() {
var $firstResult = $module.find(selector.result).eq(0);
if($firstResult.length > 0) {
module.ensureVisible($firstResult);
}
module.ensureVisible($firstResult);
},
onComplete : function() {
callback();
Expand Down

0 comments on commit 2d69a7c

Please sign in to comment.