Skip to content

Commit

Permalink
Merge pull request #130 from renderedtext/run-code-after-document-loaded
Browse files Browse the repository at this point in the history
Set up control events after document loaded
  • Loading branch information
nikolalsvk authored Oct 24, 2020
2 parents b33fd38 + 37c6f42 commit e1bfc90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions app/views/render_async/_request_jquery.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,17 @@ if (window.jQuery) {
}
}

var container = $("#<%= container_id %>");
function _setUpControlEvents() {
var container = $("#<%= container_id %>");

// Register a stop polling event on the container
$(container).on('async-stop', _clearRenderAsyncInterval)
// Register a stop polling event on the container
$(container).on('async-stop', _clearRenderAsyncInterval)

// Register a start polling event on the container
$(container).on('async-start', _renderAsyncFunction)
// Register a start polling event on the container
$(container).on('async-start', _renderAsyncFunction)
}

_runAfterDocumentLoaded(_setUpControlEvents)

<% if turbolinks %>
$(document).one('turbolinks:visit', _clearRenderAsyncInterval);
Expand Down
14 changes: 9 additions & 5 deletions app/views/render_async/_request_vanilla.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,17 @@
}
}

var container = document.getElementById('<%= container_id %>');
function _setUpControlEvents() {
var container = document.getElementById('<%= container_id %>');

// Register a polling stop event on the container
container.addEventListener("async-stop", _clearRenderAsyncInterval)
// Register a polling stop event on the container
container.addEventListener("async-stop", _clearRenderAsyncInterval)

// Register a start polling event on the container
container.addEventListener("async-start", _renderAsyncFunction)
// Register a start polling event on the container
container.addEventListener("async-start", _renderAsyncFunction)
}

_runAfterDocumentLoaded(_setUpControlEvents)

<% if turbolinks %>
document.addEventListener("turbolinks:visit", _clearRenderAsyncInterval)
Expand Down

0 comments on commit e1bfc90

Please sign in to comment.