I'm finding that I need to write some javascript to do media queries and find that the Modernizr library, which is included in core, is available to intelligently let me check the user's window size, etc. Usually when I try to learn a new library, I go to the browser console after reading some docs but find I cannot do so.

Modernizr.load is not a function

nor

Modernizr.mq() is not a function. I see the library loaded in the Resources of the browser and find Modernizr inside but I cannot instantiate it in console to work out what I can do. I do this with jQuery all the time, so what am I doing wrong? thx, sam

Comments

rupl’s picture

For almost three years Modernizr builds no longer have the Modernizr.load() command available, nor do they offer to bundle yepnope.js along with the Modernizr build.

You can read more here in the D7 issue queue for Modernizr module: #2568311: Make Modernizr.load optional.

Additionally, the D8 default build of Modernizr lacks the Modernizr.mq() test, although that test is still possible to select within a custom build. The default build seems to be v3.3.1 and the following test are included (based on a search of the D8 git history with this commit being the latest update):

  • details
  • inputtypes
  • touchevents

It also includes the following methods to extend it with other tests:

  • addtest
  • prefixes
  • teststyles

Having a D8 contrib module for Modernizr would help solve your problem by allowing you to swap core's Modernizr out with a custom build of your choice. Alas, I have never done any work to port Modernizr module to D8.

Maybe one day I will make a port. Until then, patches are welcome to help move the D8 branch of the module towards release.

sam452’s picture

While not immediate good news, this could help others looking for why it's not working as of now. Thx!