My project needs to redraw in Javascript in a set order and I'm trying implement Require to speed it up and organize the code. What I want to do is simply the following:
define([
'jquery',
'app/fader', // used to hide the screen on resize
'app/variables', // this is where my window width and height are gathered for all the other modules
'app/mobileNavigationMenu', // setup menu on mobile or desktop
'app/dividerAnimationSetup', // set up animations
'app/initializeSkrollr', // set up skrollr
'app/travelExcursions'], function ($, fader, variables, mobileNavigationMenu, dividerAnimationSetup, initializeSkrollr, navigationLinkHighlighting, travelExcursions) {
return function() {
var redraw = function() {
fader.show(function() {
var previousScrollPosition = $(window).scrollTop(),
skrollrInstance;
if(typeof skrollrInstance !== 'undefined') {
skrollrInstance.destroy();
}
// Run all functions requiring window width and height
mobileNavigationMenu();
dividerAnimationSetup();
skrollrInstance = initializeSkrollr();
navigationLinkHighlighting();
travelExcursions();
skrollrInstance.setScrollTop(previousScrollPosition);
fader.hide();
});
}();
$(window).resize(redraw);
};
});
I call it in my main file in the following way:
requirejs(['domReady', 'app/homeBackgroundSlider', 'app/aboutTitleEmphasis', 'app/draw'], function (domReady, homeBackgroundSlider, aboutTitleEmphasis, draw) {
domReady(function () {
homeBackgroundSlider();
aboutTitleEmphasis();
draw();
// $(window).resize(function() { Tried this but it didn't work
// draw();
// });
});
});
Perhaps require doesn't work this way but is there a method that will work for this project?