Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LiveZilla Compatability #87

Open
AwakenTheJaken opened this issue Apr 19, 2019 · 0 comments
Open

LiveZilla Compatability #87

AwakenTheJaken opened this issue Apr 19, 2019 · 0 comments

Comments

@AwakenTheJaken
Copy link

AwakenTheJaken commented Apr 19, 2019

Dropping this information here in case someone else has trouble integrating LiveZilla into their Turbolinks 5 based Rails application.

Official Documentation:
<!-- livezilla.net PLACE SOMEWHERE IN BODY --><script type="text/javascript" id="lzdefsc" src="//yourdomain.com/script.php?id=lzdefsc" defer></script><!-- livezilla.net PLACE SOMEWHERE IN BODY -->

Turbolinks 5 Implementation:

<!-- livezilla.net PLACE SOMEWHERE IN HEAD --><script type="text/javascript" id="lzdefsc" src="//yourdomain.com/script.php?id=lzdefsc" defer></script><!-- livezilla.net PLACE SOMEWHERE IN HEAD -->

your.js

document.addEventListener("turbolinks:before-cache", function() {
  LiveZillaElements = findandgrabLiveZillaDomElements();
});

function findandgrabLiveZillaDomElements(){
  elements = []
  if(document.getElementById("lz_overlay_chat")){
    elements.push(document.getElementById("lz_overlay_chat"));
  }
  if(document.getElementById("lz_overlay_wm")){
    elements.push(document.getElementById("lz_overlay_wm"));
  }
  if(document.getElementById("lz_overlay_preview")){
    elements.push(document.getElementById("lz_overlay_preview"));
  }
  return elements
}

document.addEventListener('turbolinks:load', function() {
  if(LiveZillaElements.length){
    var body = document.getElementsByTagName("body")[0]
    for(var i=0;i<LiveZillaElements.length;i++){
      body.appendChild(LiveZillaElements[i]);
    }
  }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant