I have implemented some coffeescript in users.js.coffee which successfully triggers a Twitter Bootstrap popover when hovering over a username. However, I am now looking to add a timeout functionality to automatically hide the popover if a user doesn't interact with it.
The issue arises when trying to implement the timeoutObj variable in my code. Upon scrolling over the popover, I receive an Uncaught ReferenceError stating that the timeoutObj is not defined. It seems like the problem lies within setting the variable in the mouseleave method.
$ ->
let timeoutObj = undefined
$(".comment-user-name").popover({
trigger: "manual",
placement: 'top',
template: '<div class="popover" onmouseover="clearTimeout(timeoutObj);$(this).mouseleave(function() {$(this).hide(); });"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'
})
$(".comment-user-name").mouseenter((event, ui) ->
$(".comment-user-name").popover('show')
)
$(".comment-user-name").mouseleave((event, ui) ->
timeoutObj = setTimeout (-> $(".comment-user-name").popover('hide') ), 3000
)