iliabylich/capybara-async-runner

View on GitHub
examples/indexeddb/templates/wrapper/inject.js.erb

Summary

Maintainability
Test Coverage
function isWrapperReady() {
  return (typeof(Dexie) !== 'undefined');
}

function injectScript(src) {
  var fileref = document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", src);
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

if (isWrapperReady()) {
  <%= success %>
} else {
  injectScript("<%= data[:url] %>");

  setInterval(function() {
    if (isWrapperReady()) {
      <%= success %>
    }
  }, 100);

  setTimeout(function () {
    if (typeof(Dexie) === 'undefined') {
      <%= error %>
    }
  }, 3000);
}