This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/debounce.js.coffee
2013-02-05 14:16:51 -05:00

21 lines
452 B
CoffeeScript

window.Discourse.debounce = (func, wait, trickle) ->
timeout = null
return ->
context = @
args = arguments
later = ->
timeout = null
func.apply(context, args)
if timeout != null && trickle
# already queued, let it through
return
if typeof wait == "function"
currentWait = wait()
else
currentWait = wait
clearTimeout(timeout) if timeout
timeout = setTimeout(later, currentWait)