Hello,
I am currently working on an upgrade from Roots Sage 8.5.2 to Sage 10 (latest version).
Everything was going well until I started working on the JS.
The structure of the main script and dependencies produces errors (old js) and I cannot afford to rewrite everything.
Ex :
app.js
(function($) {
// Use this variable to set up the common and page specific functions. If you
// rename this variable, you will also need to rename the namespace below.
var Sage = {
// All pages
‘common’: {
init: function() {
// Breakpoint
window.bp = new Breakpoint();
window.cache = {
$window: $(window),
$document: $(document),
$body: $('body'),
};
//---------
// Header
//---------
var $header = $('[data-module="header"]');
if ($header.length > 0) {
new Header({
$el: $header
});
}
//---------
// Init components
//---------
var $components = $(“[data-component]”);
$components.each(function(index){
var $el = $(this);
var comp = $el.data(‘component’);
//Check if component exist
if(typeof window.Components[comp] !== 'function') {
return;
}
// Component instantiation
var obj = new window.Components[comp]($el);
// Store instance in data
$el.data('comp', obj);
});
},
finalize: function() {
// JavaScript to be fired on all pages, after page specific JS is fired
}
},
};
})(jQuery); // Fully reference jQuery after this point.
breakpoint.js for example:
(function($) {
‘use strict’;
function Breakpoint() {
…
/* Namespace declaration */
window.Breakpoint = Breakpoint;
}(jQuery));
How would it be possible to keep the code almost the same and succeed to make it work with Roots Sage 10?
Would you please have any idea?
I tried several solutions but it implies to rewrite function as classes and it would not be possible.
Thank you