Browse Source

fix app load

main
Christoph Marzell 8 hours ago
parent
commit
dd6e7f8181
  1. 3
      app/assets/javascript/application.js
  2. 8
      app/javascript/controllers/application.js
  3. 33
      app/views/layouts/application.html.erb

3
app/assets/javascript/application.js

@ -3,11 +3,8 @@
import "@hotwired/turbo-rails"
import { Application } from "@hotwired/stimulus"
import { definitionsFromContext } from "@hotwired/stimulus-loading"
const application = Application.start()
const context = require.context("controllers", true, /\.js$/)
application.load(definitionsFromContext(context))
import $ from "jquery"
window.$ = $

8
app/javascript/controllers/application.js

@ -1,8 +0,0 @@
import { Application } from "@hotwired/stimulus"
import { definitionsFromContext } from "@hotwired/stimulus-loading"
const application = Application.start()
const context = require.context("./", true, /\.js$/)
application.load(definitionsFromContext(context))
export { application }

33
app/views/layouts/application.html.erb

@ -60,17 +60,16 @@
</style>
<script>
$(document).ready(ready);
$(document).on('turbo:load', ready); // falls Turbo/Rails UJS verwendet wird
function clearNotice() {
$("#alert-notice").animate({opacity: '0'}, 1500);
}
var ready = function () {
setTimeout(clearNotice, 1000); //Flash fade
};
$(document).on('turbolinks:load', function() {
console.log("HI");
const alert = $(".alert");
if (alert.length > 0) {
alert.delay(2000).slideUp(500, function() {
$(this).alert('close');
});
}
});
</script>
<%= javascript_importmap_tags %>
</head>
@ -173,6 +172,20 @@
</body>
</html>
<script>
document.addEventListener("turbo:load", function() {
console.log("🚀 Turbo geladen");
const alerts = document.querySelectorAll(".alert");
alerts.forEach(function(alert) {
setTimeout(function() {
alert.classList.add("fade");
setTimeout(() => alert.remove(), 500); // Clean removal
}, 2000);
});
});
</script>
Loading…
Cancel
Save