Debouncing things

This commit is contained in:
Will Marshall
2014-04-18 16:53:43 +10:00
parent 99d743f7cf
commit 35a792b3ca
2 changed files with 28 additions and 1 deletions

View File

@@ -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

View File

@@ -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