0

I have the following code:

function isVisible(selector) {
 $(selector).is(':visible');
}
var isMapVisible;
var initialWindowWidth = window.innerWidth;
/* Window Resize Helper */
function handleWindowResize() {
 isMapVisible = isVisible('.search__map');
 if (window.innerWidth > 768) {
 var windowHeight = window.innerHeight,
 searchResultsHeight = windowHeight - $('.search__results').position().top,
 searchMapHeight = windowHeight - $('.search__map').position().top;
 $('.search__results').height(searchResultsHeight);
 $('.search__map').height(searchMapHeight);
 if (initialWindowWidth < 769) {
 /* 
 This is a hack to trigger the map to show up if initial windowWidth causes the map to hide. 
 it only triggers once.
 */
 resizeMap();
 map.setZoom(map.getZoom() - 1);
 initialWindowWidth = 1000;
 }
 } else {
 $('.search__results').height('auto');
 }
}

And in the function handleWindowResize(), I had a variable that I set globally as isMapVisible. and is calling another function isVisible(). I found out that when I replace that line of code with isMapVisible = $('.search__map').is(':visible'), I am able to get the correct result, but if my code is as copied above, I would get undefined. Any idea why?

asked Jul 26, 2015 at 12:48
2
  • 5
    You forget return in isVisible function. Commented Jul 26, 2015 at 12:49
  • thanks! very rookie. Commented Jul 26, 2015 at 13:03

1 Answer 1

1

That is because you are not returning anything in your function:

function isVisible(selector) {
 return $(selector).is(':visible');
}
answered Jul 26, 2015 at 12:50
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.