[英]Rails 4 turbolinks page:load with JS
I have the following basic JavaScript ( CoffeeScript ) in my app 我的应用程序中具有以下基本JavaScript(CoffeeScript)
window.onload = ->
menu = document.getElementById("menu")
wrapper = document.getElementById("wrapper")
toggleMenu = false
menu.onclick = ->
if toggleMenu is false
wrapper.style.left = "278px"
toggleMenu = true
else
wrapper.style.left = "0px"
toggleMenu = false
When you click on something with turbolinks, it stops working. 当您单击带有Turbolink的内容时,它将停止工作。
I found this solution on SO, but don't know how to implement it in JavaScript: 我在SO上找到了此解决方案,但不知道如何在JavaScript中实现它:
$(document).on('page:change', function () {
// Actions to do
});
I did try document.onchange with no success. 我确实尝试了document.onchange,但没有成功。 What would be the pure JavaScript solution for this? 为此,纯JavaScript解决方案是什么?
document.addEventListener('page:change', function(){
console.log('called')
});
# page reloaded, no clicks yet
=> called
# click turbolinks link
=> called
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.