mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +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
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
|
||||
.row
|
||||
.large-9.columns
|
||||
%input{type: :text, "ng-model" => "query", placeholder: "Search postcode, suburb or hub name...",
|
||||
%input{type: :text, "ng-model" => "query",
|
||||
placeholder: "Search postcode, suburb or hub name...",
|
||||
"ng-debounce" => "150",
|
||||
"ofn-disable-enter" => true}
|
||||
.large-3.columns
|
||||
Advanced search
|
||||
|
||||
Reference in New Issue
Block a user