summaryrefslogtreecommitdiff
path: root/app/views/game/finish_activity.js.erb
blob: f281986f725c0409e04b583a4f1b3f4128a8f501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var resultOutputDiv = document.getElementById("result_output");
var resultControlsDiv = document.getElementById("activity_controls");

var outputHTML = "<%= j render(partial: "application/results", locals: { results: @results }) %>"

if (resultOutputDiv) {
  // If scrolled to the bottom or near the bottom, then smooth scroll to the bottom.
  //  (Check before adding output, because a large output could prevent the scroll when it shouldn't.)
  var shouldScroll = false;
  if ((resultOutputDiv.scrollTop + 100) >= (resultOutputDiv.scrollHeight - resultOutputDiv.offsetHeight)) {
    shouldScroll = true;
  }

  resultOutputDiv.innerHTML += outputHTML;

  if (shouldScroll) {
    resultOutputDiv.scrollTo({
      top: resultOutputDiv.scrollHeight, left: 0, behavior: 'smooth'
    });
  }
}

if (resultControlsDiv) {
  resultControlsDiv.innerHTML = "<%= j render(partial: "application/timer") %>"
}