imsky / holder

:city_sunrise: Client-side image placeholders.
http://holderjs.com
MIT License
5.84k stars 593 forks source link

Support Turbolinks 5 #208

Open btrewern opened 7 years ago

btrewern commented 7 years ago

Hi, I was hoping you could support Turbolinks 5.

I think I've found what code needs to be changed but don't do much Javascript and don't understand how this code is packaged.

I think what needs to be changed is here in index.js:

if (typeof global.Turbolinks == 'object') {
  global.document.addEventListener('page:change', function() {
    Holder.run();
  });
}

to

if (typeof global.Turbolinks.controller == 'object') { // Turbolinks 5
  global.document.addEventListener('turbolinks:load', function() {
    Holder.run();
  });
} else if (typeof global.Turbolinks == 'object') { // Turbolinks Classic
  global.document.addEventListener('page:change', function() {
    Holder.run();
  });
}

I hope this makes sense.

imsky commented 7 years ago

nice, thanks for the tip