dom-update.html 514 B

12345678910111213141516171819
  1. <script>
  2. const runWhenDOMLoaded = cb => {
  3. if (document.readyState != 'loading') {
  4. cb()
  5. } else if (document.addEventListener) {
  6. document.addEventListener('DOMContentLoaded', cb)
  7. } else {
  8. document.attachEvent('onreadystatechange', function() {
  9. if (document.readyState == 'complete') cb()
  10. })
  11. }
  12. }
  13. // Helper function to init things quickly
  14. initFunction = function(myfunc) {
  15. runWhenDOMLoaded(myfunc);
  16. document.addEventListener('turbolinks:load', myfunc);
  17. };
  18. </script>