<!doctype html>
<html><head><meta charset="utf-8"><title>Second step</title></head>
<body>
<h1 id="sco-title">Second step</h1>
<p id="sco-api">api-missing</p>
<p id="sco-value">no-value</p>
<p id="sco-dyn">dyn-missing</p>
<p id="sco-xhr">xhr-missing</p>
<a id="sco-next" href="sco1.html">other step</a>
<script>
// Real runtimes (Captivate) fetch their own code this way: a script element
// created at run time, and an XMLHttpRequest for data — both with paths
// relative to the package, which only a virtual filesystem can answer.
(function () {
  var s = document.createElement('script')
  s.src = 'dyn.js'
  document.head.appendChild(s)
  var x = new XMLHttpRequest()
  x.open('GET', 'data.json')
  x.onload = function () {
    document.getElementById('sco-xhr').textContent = JSON.parse(x.responseText).marker
  }
  x.send()
})()
</script>
<script>
(function () {
  function findAPI(win) {
    var depth = 0
    // Real ADL wrappers walk up the opener/parent chain. Reaching a
    // cross-origin parent throws, which is exactly what happens when the API
    // is not on the SCO's own window, so the walk is guarded.
    try {
      while (win && !win.API && win.parent && win.parent !== win && depth < 10) {
        depth++
        win = win.parent
      }
      return win ? win.API : null
    } catch (err) {
      return null
    }
  }
  var api = findAPI(window)
  if (!api) return
  document.getElementById('sco-api').textContent = 'api-found'
  api.LMSInitialize('')
  api.LMSSetValue('cmi.core.lesson_status', 'completed')
  document.getElementById('sco-value').textContent =
    api.LMSGetValue('cmi.core.lesson_status')
})()
</script>
</body></html>
