mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-07 03:01:33 +00:00
Debouncing things
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
Darkswarm.directive "ngDebounce", ($timeout) ->
|
||||
restrict: "A"
|
||||
require: "ngModel"
|
||||
priority: 99
|
||||
link: (scope, elm, attr, ngModelCtrl) ->
|
||||
return if attr.type is "radio" or attr.type is "checkbox"
|
||||
elm.unbind "input"
|
||||
debounce = undefined
|
||||
elm.bind "keyup paste", ->
|
||||
$timeout.cancel debounce
|
||||
debounce = $timeout(->
|
||||
scope.$apply ->
|
||||
ngModelCtrl.$setViewValue elm.val()
|
||||
return
|
||||
return
|
||||
, attr.ngDebounce or 1000)
|
||||
return
|
||||
|
||||
elm.bind "blur", ->
|
||||
scope.$apply ->
|
||||
ngModelCtrl.$setViewValue elm.val()
|
||||
return
|
||||
return
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user