3

smoothstate.js requires that the links that trigger the ajax call are located inside the #main div that houses the content to be updated. However, I need the header and the links housed inside to remain omitted from the content swap, preferably only reloading the content in a specified .content div.

Is there any way, using smoothstate.js, to prevent the header links from being reloaded despite the requirement that they are located inside the #main div that is refreshed?

I had the idea to separate out the content div from the $newContent object returned in the onReady function. However, though I am able to separate out the specified div, passing the returned object into the html fails.

(function header_init() {

    $('#main').smoothState({
        anchors: 'a',
        blacklist: '.no-ajax',
        prefetch: true,
        cacheLength: 4,
        repeatDelay: 500,

        onStart: {
            duration: 300,
            render: function ($container) {
                $('html').addClass('animate-page-out');
                $('html').removeClass('animate-page-in');
            }
        },
        onReady: {
            duration: 300,
            // `$container` is a `jQuery Object` of the current smoothState container
            // `$newContent` is a `jQuery Object` of the HTML that should replace the existing container's HTML.
            render: function ($container, $newContent) {

                // Update the HTML on the page
                var content = $($newContent).find('.main-content');
                console.log($newContent);
                console.log($(content));
                // $container.html($newContent);
                $('.main-content').html($(content));
            }
        },
        onAfter: function ($container, $newContent) {
            // after page loads, all scripts must be re-initialize to account for any new DOM items
            $('html').addClass('animate-page-in');
            $('html').removeClass('animate-page-out');
        }
    });
}());
Daniel Bernardi
  • 487
  • 2
  • 7

0 Answers0