What happens if you use next code in Page - Function and Global Variable Declaration:
(function(){
$(apex.gPageContext$).on("apexreadyend", function(jQueryEvent) {
let tbGroup$ = $('#IG_STATIC_ID_ig_toolbar').find('.a-Toolbar-group').last();
if (tbGroup$.length)
{
tbGroup$.addClass('a-IRR-buttons');
}
apex.theme42.page.init();
});
})();
IG_STATIC_ID to be replaced
your code in "Initialization JavaScript Function" to be disabled
'show maximize button' to be checked on the template options: