Skip to content

Plax + Turbolinks [It worcks] #74

@Golgarud

Description

@Golgarud

Hello,
First of all, thanks so much for this awesome plugin.
(Im really sad about the support ending).

This is not realy an issue but I have try to run plax with Turbolinks.
I cant find any explanation of how to do it.
So I found it myself and I want to post the solution here :3

( function() {
	Turbolinks.start();
	var ready = function()
	{
		console.log( "🦄 TurboLinks Ready -> " + window.location.href + " width: " + $(window).width());
		// PLAX
		if( $('.yourPlaxSelector').length )
		{
			$('.yourPlaxSelector').plaxify();
			$.plax.enable();
		}
	}
	var cache = function()
	{
		console.log( "🦄 TurboLinks CacheLoad" );
		// Allow plax function `inViewport` to worck properly.
		// Without it Plax will only worck on the first call of `ready`.
		$.plax.disable( { "clearLayers": true } );
	}
	// Turbolink tracker
	var change = function()
	{
		console.log( "🦄 TurboLinks Change" );
		window['referer'] = window.location.href;
	}
	ready();
	document.addEventListener("turbolinks:before-cache", cache);
	document.addEventListener("turbolinks:load", ready);
	document.addEventListener("page:change", change);
} )( jQuery );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions