3

I'm trying to load fotorama on a cms page and some category pages which are custom.

The JS doesn't load on it's own so I thought I was being clever and added this to one of my theme's js files.

// my-custom-theme-script.js
requirejs([
    'jquery',
    'fotorama/fotorama'
], function($, fotorama){
});

This almost worked. I see my code is causing fotorama to load on the page, but strangely, I'm getting this error in console:

Uncaught Fotorama requires jQuery 1.8 or later and will not run without it.

So to further debug I changed my theme js to this

// my-custom-theme-script.js
requirejs([
    'jquery',
    'fotorama/fotorama'
], function($, fotorama){
    console.log($.fn.jquery); //-> 1.11.0
});

So now I'm thinking this is a requiredjs configuration issue on my part. If I add something to the fotorama.js file on about line 98 where the above error comes from, I see that $ is false.

// fotorama.js
var JQUERY_VERSION = $ && $.fn.jquery.split('.');

if (!JQUERY_VERSION
    || JQUERY_VERSION[0] < 1
    || (JQUERY_VERSION[0] == 1 && JQUERY_VERSION[1] < 8)) {

    console.log($); //-> false
    throw 'Fotorama requires jQuery 1.8 or later and will not run without it.';

How exactly am I suppose to add a custom fotorama gallery to a cms page or block outside of where fotorama is already loading? I'm guessing I'm way off here.

From what I can tell I need to manually define jquery as a dependency in my requirejs-config, however this seems counter intuitive for a js resource that Magento 2 natively includes. Any suggestions?

1
  • Let me know Jamil if you find any answer
    – Yogesh
    Commented Sep 20, 2019 at 19:17

0

Your Answer

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

Browse other questions tagged or ask your own question.