3

I use Foundation.MediaQuery.current to determine current breakpoint. Every time I call console.log(Foundation.MediaQuery.current) for the first time (n=0) I get nothing.

For all next calls (n>0) I always get correct breakpoint, let's say large.

This is my function:

_calculateLimit = function () {
    var postsInjectedCount = container.find('.post-appended').length;

    console.log(Foundation.MediaQuery.current);

    if (Foundation.MediaQuery.current === 'large') { // gives nothing on first iteration :/
        return postsInjectedCount % 3 !== 0 ? 2 : 3;
    }

    return postsInjectedCount % 2 !== 0 ? 1 : 2;
},

Below picture shows a screen from my Chrome Dev Tools.

enter image description here

Helpful info 1: There is no difference in terms of business logic between first call and next calls.

Helpful info 2: I use Foundation For Sites ~6.2.1

What am I doing wrong?

Matt Komarnicki
  • 5,198
  • 7
  • 40
  • 92

2 Answers2

3

It looks like you are running the code before Foundation has initialized. It is a good practice to put the init code at the top of JavaScript file.

Shoaib Iqbal
  • 1,208
  • 11
  • 21
  • Thanks Shoaib. That helped me. I was indeed calling my function before initiating Foundation. However I left that in footer, I just moved my method after `$(document).foundation();` and now everything works. Thank you very much. – Matt Komarnicki Jun 06 '16 at 12:20
0

You will see it better if put the console.log at the end of the function. So try it and just tell the results.

It will clarify where the error is.

Luis Gar
  • 457
  • 1
  • 4
  • 18