Enabling Xeno to work with Turbolinks

Enabling Xeno to work with Turbolinks

Last update: Tuesday, Oct 17, 2017

When using Xeno with Turbolinks, the widget disappears each time the user moves from one page to another. You can bypass this issue by adding the following code in a <script> tag:  

document.addEventListener('xeno.ready', function() {
  var xenoDOM = [];
  for (var i = 0 ; i < document.body.children.length ; i++) {
    if (/^slaask-/.test(document.body.children[i].id))
      xenoDOM.push(document.body.children[i]);
  }
  function reAppend() {
    for (var id in xenoDOM) {
      document.body.appendChild(xenoDOM[id]);
    }
  }
  document.addEventListener("turbolinks:load", reAppend);
  document.addEventListener("page:load", reAppend);
});

Javascript API

12 articles in this category.