• Resolved apexdigitalro

    (@apexdigitalro)


    Hello! I am trying to implement Barba.js transitions, according to the documentation provided on their repo.

    I’ve added the barba wrapper to the header template of the website, and closed it in the footer template.

    Then, I’ve added the barba container as part of the single.php template in the Hello elementor theme. Added some javascript, as well as some CSS taken from here , just to test the functionality.

    The issue is that the website does not seem to undergo a correct transition, if it undergoes one at all. The CSS, at the very least, does not take effect in what concerns the barba.js transition.

    I am also getting a console error related to the barba.js import:
    Uncaught SyntaxError: import declarations may only appear at top level of a module

    Side note: your plugin returns this error:

    The resource from “https://apexdigital.ro/wp-content/plugins/ooohboi-steroids-for-elementor/lib/scroll_to/ScrollToPlugin.min” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).

    Across my website.

    I would appreciate any help! ?? thank you for your amazing work.

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Oooh Boi

    (@ooohboi)

    Barba is a “single page application” where the header and footer of your page never reload. That’s totally opposed to the Elementor concept, and the majority of page builders as well. Why? Because with every page, the CSS of that very page is loaded in the header. The same goes for the custom JS (enqueued in the footer).

    So you’ll need to load both of these with every page, with the help of JavaScript.
    Here’s the example that I made a while ago: https://ooohboi.space/barba/barba-main-page
    You can take a look at the source code of this page to study the required JavaScript (around the line 370).
    Please note that I’m using the “Hello Elementor” child theme because I had to modify Header and Footer templates in order to meet Barba’s requirements. Just look up for data-barba=”wrapper” and class=”ob-barba-loader” to find the modifications.
    As a side note, I’m also using the GSAP to animate the page transition. You’ll see how exactly in the JS code.

    My plan is to make a video tutorial on how Barba can work with Elementor in the near future.

    Hope it helps!

    Thread Starter apexdigitalro

    (@apexdigitalro)

    Hello @ooohboi ! Your reply is incredibly helpful.

    Yup, I did all the required tweaking (added the wrapper from the end of the head, to before the footer).

    I am going to take a look at your code and see how exactly you’ve implemented it. I am also planning on using GSAP for the animation, which is absolutely perfect!

    Thank you again for the amazing plugin and the reply. You deserve the best reviews!

    Thread Starter apexdigitalro

    (@apexdigitalro)

    Hey @ooohboi I still have a question, if possible!

    I am also using the Hello Elementor theme, but a child. Thing is, I am using ElementsKit in oder to create a custom header and footer. I noticed that you’ve added data-barba=”wrapper” and ob-barba-loader as classes within the body. How did you manage that? And how would I go about doing it in my situation, with ElementsKit? Any suggestions?

    Thank you very much! ?? I am still a noob so any help is greatly appreciated.

    Plugin Contributor Oooh Boi

    (@ooohboi)

    That’s why the child theme is used for! Copy-paste “header.php” and “footer.php” files from the parent theme (“Hello Elementor”) to the root of the child theme (“Hello Elementor child”), and then edit these two files by adding the required DIV elements and the data-attribute – data-barba=”wrapper”.
    Here’s why using the child theme: https://codeable.io/blog/what-is-a-child-theme-wordpress/

    It doesn’t matter which plugin you use to create a custom header/footer, it can be “Header Footer & Blocks”, it can be the “ElementsKit”, the Elementor itself – it doesn’t make the difference.

    Thread Starter apexdigitalro

    (@apexdigitalro)

    Hello! Thank you for your patience. I am indeed using the Hello Elementor child theme. By looking at your example, all I had to do was insert the specific code and wrap it up into a div that starts after the header, and ends before the footer, such that both the header and the footer remain loaded.

    I understand it now, it’s perfect!

    @apexdigitalro i have similar issue my CSS file is not loading, so can you be more specific about what code you have inserted?

    The reason why your CSS would not load is because you did not adapt the link that represents the path to your elementor CSS files.

    This is the script that is on the website from Oooh Boi:

    <script>
        ;
        (function() {
    
            document.addEventListener("DOMContentLoaded", () => {
    
                gsap.set('.ob-barba-loader', {
                    scaleX: 0,
                    rotation: 30,
                    xPercent: -5,
                    yPercent: -50,
                    transformOrigin: 'left center',
                    autoAlpha: 1
                });
    
                barba.hooks.beforeEnter(({current, next}) => {
    
                    // Set <body> classes for the 'next' page
                    if (current.container) {
                        // // only run during a page transition - not initial load
                        let nextHtml = next.html;
                        let response = nextHtml.replace(/(<\/?)body( .+?)?>/gi, "$1notbody$2>", nextHtml);
    
                        let bodyClasses = jQuery(response).filter("notbody").attr("class");
                        jQuery("body").attr("class", bodyClasses);
    
                        // ELEMENTOR
                        // Where the magic happens - this loads the new Elementor styles and removes the old styles
                        if (bodyClasses.includes("elementor-page")) {
                            let currentPageId = current.container.querySelector(".elementor").getAttribute("data-elementor-id");
                            let nextPageId = next.container.querySelector(".elementor").getAttribute("data-elementor-id");
                            let oldScriptURL = "https://ooohboi.space/barba/wp-content/uploads/sites/8/elementor/css/post-" + currentPageId + ".css";
                            let newScriptURL = "https://ooohboi.space/barba/wp-content/uploads/sites/8/elementor/css/post-" + nextPageId + ".css"; // Add this for cache fix: ?cachebuster=' + new Date().getTime()
    
                            console.log('Old css: ' + oldScriptURL);
                            console.log('New css: ' + newScriptURL);
                            console.log(current.container);
    
                            const oldElementorScript = document.querySelector('link[src="' + oldScriptURL + '"]');
                            if (oldElementorScript) {
                                oldElementorScript.remove();
                            }
                            loadjscssfile(newScriptURL, "css");
                        }
                    }
    
                });
    
                barba.init({
                    debug: true,
                    timeout: 5000,
                    transitions: [{
                        async leave() {
                            await loaderIn();
                        },
                        enter() {
                            window.scrollTo(0, 0);
                            loaderAway();
                        }
                    }]
                });
    
            });
    
            loaderIn = function() {
                // GSAP tween to stretch the loading screen across the whole screen
                return gsap.fromTo('.ob-barba-loader',
                {
                    rotation: 10,
                    scaleX: 0,
                    xPercent: -5
                },
                {
                    duration: 0.4,
                    xPercent: 0,
                    scaleX: 1,
                    rotation: 0,
                    ease: 'power4.inOut',
                    transformOrigin: 'left center'
                });
            }
    
            loaderAway = function() {
                // GSAP tween to hide loading screen
                return gsap.to('.ob-barba-loader', {
                    duration: 0.4,
                    scaleX: 0,
                    xPercent: 5,
                    rotation: -10,
                    transformOrigin: 'right center',
                    ease: 'power4.inOut'
                });
            }
            // This function helps add and remove js and css files during a page transition
            loadjscssfile = function(filename, filetype) {
                if (filetype == "js") {
                    //if filename is a external JavaScript file
                    const existingScript = document.querySelector('script[src="${filename}"]');
                    if (existingScript) {
                        existingScript.remove();
                    }
                    var fileref = document.createElement("script");
                    fileref.setAttribute("type", "text/javascript");
                    fileref.setAttribute("src", filename);
                } else if (filetype == "css") {
                    //if filename is an external CSS file
                    const existingCSS = document.querySelector(<code>link[href='${filename}']</code>);
                    if (existingCSS) {
                        existingCSS.remove();
                    }
                    var fileref = document.createElement("link");
                    fileref.setAttribute("rel", "stylesheet");
                    fileref.setAttribute("type", "text/css");
                    fileref.setAttribute("href", filename);
                }
                if (typeof fileref != "undefined")
                    document.getElementsByTagName("head")[0].appendChild(fileref);
            }
    
        })();
        </script>

    if you just copied this code it is obvious that your css will not load because the code includes the individual path of his website.

    It’s actually this part of the code that has to be adapted

    // ELEMENTOR
                        // Where the magic happens - this loads the new Elementor styles and removes the old styles
                        if (bodyClasses.includes("elementor-page")) {
                            let currentPageId = current.container.querySelector(".elementor").getAttribute("data-elementor-id");
                            let nextPageId = next.container.querySelector(".elementor").getAttribute("data-elementor-id");
                            let oldScriptURL = "https://ooohboi.space/barba/wp-content/uploads/sites/8/elementor/css/post-" + currentPageId + ".css";
                            let newScriptURL = "https://ooohboi.space/barba/wp-content/uploads/sites/8/elementor/css/post-" + nextPageId + ".css"; // Add this for cache fix: ?cachebuster=' + new Date().getTime()

    You would have to copy your individual CSS path of your elementor page css folder

    in my case it was the following path:

    “/wp-content/uploads/elementor/css/post-“

    • This reply was modified 3 years, 4 months ago by melo1551.

    Hey @ooohboi Looks like Elementor is now loading inline CSS for Pages instead of the post-id.css file. Any awesome tips as to How could we comply with these changes for Barba?

    Context: https://elementor.com/help/conditional-and-inline-css-load-experiment/

    Thank you! Really love what you do! )

    • This reply was modified 3 years, 2 months ago by Abhinav Jain.
    Plugin Contributor Oooh Boi

    (@ooohboi)

    CSS Print Method should be set to “External file”, see
    Elementor > Settings > Advanced (tab) :: CSS Print Method

    Keep “Improved CSS Loading” (under Experiments tab) to Default or Inactive.

    That’s awesome! Thank you so much for your quick reply. )

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Barba.js implementation?’ is closed to new replies.