RequireJS newbie here. Trying to convert some JQuery code I had working fine in the old way to work w/ RequireJS.
Header of my page loads three JS files via script tags
In our particular case we had RequireJS included and configured in our main template, but wanted to include Masonry/ImagesLoaded on one particular page.
We kept our code in the template:
Then we included a JavaScript file after this, on the page that used Masonry, that triggered Masonry/ImagesLoaded:
requirejs(['jquery', 'https://unpkg.com/masonry-layout@4.2.2/dist/masonry.pkgd.min.js', 'https://unpkg.com/imagesloaded@4.1.4/imagesloaded.pkgd.min.js'],
function ($, Masonry, ImagesLoaded) {
$(document).ready(function () {
ImagesLoaded('.js-masonry', function () {
new Masonry('.js-masonry', {
// This was required for us, but from what I can tell shouldn't need to be/may need to be updated per-usage.
itemSelector: '.item'
});
});
});
}
);
I'm sure this could be further optimized, but it resolved the errors and didn't require any new packages to be included.