1

I'm trying to use jQuery camera inside a page block, but I'm doing something wrong.

I added the camera.min.js into my custom theme folder Theme_folder/Magento_Theme/web/js/camera.min.js

Here's my requirejs-config.js in Theme_folder/Magento_Theme/web/js/requirejs-config.js

var config = {
    map: {
        '*': {
            'camera': './js/camera.min'
        }
    },
    shim: {
        'camera': {
            deps: ['jquery'],
            exports: 'jQuery.camera'
        }
    }
};

And here's the js in the block:

require(['jquery', 'camera'], function(jQuery) {
    jQuery(function(){
        jQuery('#camera_wrap').camera({
            alignmen: 'topCenter',
            height: '36.341%',
            minHeight: '134px',
            loader : false,
            pagination: false,
            fx: 'simpleFade',
            navigationHover:false,
            thumbnails: false,
            playPause: false
        });
    });
});
1

Your requirejs-config.js file is in the wrong directory. It should go directly in your theme directory. If you want to make sure your requirejs-config file is being read properly, you can open the sources tab in your chrome inspector, navigate to pub/static/_requirejs/{area}/{vendor}/{theme}/{locale}/requirejs-config.js. You will see a merged document of all the requirejs-config.js files in magento including yours. If you do a search for "camera" you should see your mapping if everything worked properly.

You should change your js to this

require(['jquery', 'camera'], function(jQuery) {
    return function(){
        jQuery('#camera_wrap').camera({
            alignmen: 'topCenter',
            height: '36.341%',
            minHeight: '134px',
            loader : false,
            pagination: false,
            fx: 'simpleFade',
            navigationHover:false,
            thumbnails: false,
            playPause: false
        });
    });
});
  • Thanks, Magento 2 documentation is very confusing regarding where each file should be. I moved the requirejs-config.js and now it's loading, but I got this error: jQuery is not defined – Federico Resnizky Jan 14 '16 at 23:23
  • Thank you for letting us know. Can you point us to any topic in particular that confused you? Where should we add more detail? – Steve Johnson Jan 16 '16 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.