Question

I am trying to use turbolinks in a rails 3 app. Everything is fine, except that Alertify stops working after a page change.

I have installed the jquery-turbolinks gem to patch it up, but this has had no effect.

I have also tried wrapping the alertify function and triggering it on page:change, but again no joy.

Anyone have issues with turbolinks?

Was it helpful?

Solution

Anyone who encounters this with Alertify 0.4.0 (currently RC1) can solve this by reseting the Alertify elements you're using. In my case, it was Alertify.dialog:

Alertify.dialog.el = false
// Do your normal JS stuff

In my crude understanding of this, Alertify thinks that a dialog element has been created, but when Turbolinks loads a page, it destroys that element. We need to tell Alertify it has been destroyed and Alertify will recreate it.

If you need any help with specifics, let me know.

OTHER TIPS

As far as I can tell, Turbolinks messes with the global scope, which prevents the alerts being properly connected with the DOM.

My work around is thus:

   //Keep global reference to alertify init() function
    $(document).on('ready',function(){
     window alertifyInit = alertify.init;
    });
    //re-initialise on page change/load
    $(document).on('page:change page:load',function(){
        alertifyInit();
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top